libpappsomspp
Library for mass spectrometry
Loading...
Searching...
No Matches
baseplotcontext.cpp
Go to the documentation of this file.
1// Copyright 2021 Filippo Rusconi
2// GPL3+
3
4#include "baseplotcontext.h"
8
9namespace pappso
10{
11
12std::map<Qt::MouseButton, QString> qtMouseButtonMap{
13 {Qt::NoButton, "NoButton"},
14 {Qt::LeftButton, "LeftButton"},
15 {Qt::RightButton, "RightButton"},
16 {Qt::MiddleButton, "MiddleButton"}};
17
18std::map<Qt::MouseButtons, QString> qtMouseButtonsMap{
19 {Qt::NoButton, "NoButton"},
20 {Qt::AllButtons, "AllButtons"},
21 {Qt::LeftButton, "LeftButton"},
22 {Qt::RightButton, "RightButton"},
23 {Qt::MiddleButton, "MiddleButton"},
24 {Qt::LeftButton | Qt::RightButton, "LeftRightButtons"},
25 {Qt::LeftButton | Qt::MiddleButton, "LeftMiddleButtons"},
26 {Qt::RightButton | Qt::MiddleButton, "RightMiddleButtons"},
27};
28
29std::map<Qt::KeyboardModifier, QString> qtKeyboardModifierMap{
30 {Qt::NoModifier, "No modifier"},
31 {Qt::ShiftModifier, "A Shift key"},
32 {Qt::ControlModifier, "A Ctrl key"},
33 {Qt::AltModifier, "An Alt key"},
34 {Qt::MetaModifier, "A Meta key"},
35 {Qt::KeypadModifier, "A keypad button"},
36 {Qt::GroupSwitchModifier, "A Mode_switch key"}};
37
38BasePlotContext::BasePlotContext(QObject *parent): QObject(parent)
39{
40 // So we know it is never nullptr.
41 msp_integrationScope = std::make_shared<IntegrationScopeBase>();
42}
43
44// BasePlotContext::BasePlotContext(const BasePlotContext &other)
45// {
46// // qDebug() << "Constructing BasePlotContext by copy.";
47//
48// m_dataKind = other.m_dataKind;
49//
50// m_isMouseDragging = other.m_isMouseDragging;
51// m_wasMouseDragging = other.m_wasMouseDragging;
52//
53// m_isKeyBoardDragging = other.m_isKeyBoardDragging;
54// m_isLeftPseudoButtonKeyPressed = other.m_isLeftPseudoButtonKeyPressed;
55// m_isRightPseudoButtonKeyPressed = other.m_isRightPseudoButtonKeyPressed;
56// m_wasKeyBoardDragging = other.m_wasKeyBoardDragging;
57//
58// m_startDragPoint = other.m_startDragPoint;
59// m_currentDragPoint = other.m_currentDragPoint;
60// m_lastCursorHoveredPoint = other.m_lastCursorHoveredPoint;
61//
62// m_selectionPolygon = other.m_selectionPolygon;
63// msp_integrationScope = other.msp_integrationScope;
64// m_integrationScopeRhombWidth = other.m_integrationScopeRhombWidth;
65// m_integrationScopeRhombHeight = other.m_integrationScopeRhombHeight;
66//
67// // The effective range of the axes.
68// m_xRange = other.m_xRange;
69// m_yRange = other.m_yRange;
70//
71// // Tell if the mouse move was started onto either axis, because that will
72// // condition if some calculations needs to be performed or not (for
73// example,
74// // if the mouse cursor motion was started on an axis, there is no point to
75// // perform deconvolutions).
76// m_wasClickOnXAxis = other.m_wasClickOnXAxis;
77// m_wasClickOnYAxis = other.m_wasClickOnYAxis;
78//
79// m_isMeasuringDistance = other.m_isMeasuringDistance;
80//
81// // The user-selected region over the plot.
82// // Note that we cannot use QCPRange structures because these are normalized
83// by
84// // QCustomPlot in such a manner that lower is actually < upper. But we need
85// // for a number of our calculations (specifically for the deconvolutions)
86// to
87// // actually have the lower value be start drag point.x even if the drag
88// // direction was from right to left.
89// m_xRegionRangeStart = other.m_xRegionRangeStart;
90// m_xRegionRangeEnd = other.m_xRegionRangeEnd;
91//
92// m_yRegionRangeStart = other.m_yRegionRangeStart;
93// m_yRegionRangeEnd = other.m_yRegionRangeEnd;
94//
95// m_xDelta = other.m_xDelta;
96// m_yDelta = other.m_yDelta;
97//
98// m_pressedKeyCode = other.m_pressedKeyCode;
99// m_pressedKeyText = other.m_pressedKeyText;
100// m_releasedKeyCode = other.m_releasedKeyCode;
101// m_releasedKeyText = other.m_releasedKeyText;
102//
103// m_keyboardModifiers = other.m_keyboardModifiers;
104//
105// m_lastPressedMouseButton = other.m_lastPressedMouseButton;
106// m_lastReleasedMouseButton = other.m_lastReleasedMouseButton;
107//
108// m_pressedMouseButtons = other.m_pressedMouseButtons;
109//
110// m_mouseButtonsAtMousePress = other.m_mouseButtonsAtMousePress;
111// m_mouseButtonsAtMouseRelease = other.m_mouseButtonsAtMouseRelease;
112// }
113
117
120{
121 BasePlotContext *copy_p = new BasePlotContext(parent);
122
123 // copy_p->m_dataKind = m_dataKind;
124
128
133
137
142
143 // The effective range of the axes.
144 copy_p->m_xRange = m_xRange;
145 copy_p->m_yRange = m_yRange;
146
147 // Tell if the mouse move was started onto either axis, because that will
148 // condition if some calculations needs to be performed or not (for example,
149 // if the mouse cursor motion was started on an axis, there is no point to
150 // perform deconvolutions).
153
155
156 // The user-selected region over the plot.
157 // Note that we cannot use QCPRange structures because these are normalized by
158 // QCustomPlot in such a manner that lower is actually < upper. But we need
159 // for a number of our calculations (specifically for the deconvolutions) to
160 // actually have the lower value be start drag point.x even if the drag
161 // direction was from right to left.
164
167
168 copy_p->m_xDelta = m_xDelta;
169 copy_p->m_yDelta = m_yDelta;
170
175
177
180
182
185
186 return copy_p;
187}
188
189void
191{
192 m_dataKind = other.m_dataKind;
193
197
202
206
211
212 // The effective range of the axes.
213 m_xRange = other.m_xRange;
214 m_yRange = other.m_yRange;
215
216 // Tell if the mouse move was started onto either axis, because that will
217 // condition if some calculations needs to be performed or not (for example,
218 // if the mouse cursor motion was started on an axis, there is no point to
219 // perform deconvolutions).
222
224
225 // The user-selected region over the plot.
226 // Note that we cannot use QCPRange structures because these are normalized by
227 // QCustomPlot in such a manner that lower is actually < upper. But we need
228 // for a number of our calculations (specifically for the deconvolutions) to
229 // actually have the lower value be start drag point.x even if the drag
230 // direction was from right to left.
233
236
237 m_xDelta = other.m_xDelta;
238 m_yDelta = other.m_yDelta;
239
244
246
249
251
254}
255
256void
258{
259 // qDebug();
260
261 // By essence, IntegrationScope is 1D scope. The point of the scope is the
262 // left bottom point, and then we document the width.
263
264 double x_range_start = std::min(m_currentDragPoint.x(), m_startDragPoint.x());
265 double x_range_end = std::max(m_currentDragPoint.x(), m_startDragPoint.x());
266
267 double y_position = m_startDragPoint.y();
268
269 QPointF point(x_range_start, y_position);
270 double width = x_range_end - x_range_start;
271
272 // qDebug() << "Going to create an integration scope with point:" << point
273 // << "and width:" << width;
274 msp_integrationScope = std::make_shared<IntegrationScope>(point, width);
275 // qDebug() << "Created integration scope:" <<
276 // msp_integrationScope->toString();
277}
278
279void
281{
282 // qDebug();
283
284 // By essence, IntegrationScopeRect is a squared rectangle scope. The point of
285 // the scope is the left bottom point, and then we document the width and the
286 // height.
287
288 /* Like this:
289*
290+---------------------------+ -
291| | |
292| | |
293| | m_height
294| | |
295| | |
296P---------------------------+ -
297
298|--------- m_width ---------|
299
300*/
301
302 // We need to find the point that is actually the left bottom point.
303
304 QPointF point;
305 double width = 0;
306 double height = 0;
307
308 if(static_cast<int>(m_dragDirections) &
309 static_cast<int>(DragDirections::LEFT_TO_RIGHT) &&
310 static_cast<int>(m_dragDirections) &
311 static_cast<int>(DragDirections::BOTTOM_TO_TOP))
312 {
313 point.rx() = m_startDragPoint.x();
314 point.ry() = m_startDragPoint.y();
315 width = m_currentDragPoint.x() - point.rx();
316 height = m_currentDragPoint.y() - point.ry();
317 // qDebug() << "left to right - bottom to top";
318 }
319
320 if(static_cast<int>(m_dragDirections) &
321 static_cast<int>(DragDirections::RIGHT_TO_LEFT) &&
322 static_cast<int>(m_dragDirections) &
323 static_cast<int>(DragDirections::BOTTOM_TO_TOP))
324 {
325 point.rx() = m_currentDragPoint.x();
326 point.ry() = m_currentDragPoint.y();
327 width = m_startDragPoint.x() - m_currentDragPoint.x();
328 height = m_startDragPoint.y() - m_currentDragPoint.y();
329 // qDebug() << "right to left - bottom to top";
330 }
331
332 if(static_cast<int>(m_dragDirections) &
333 static_cast<int>(DragDirections::LEFT_TO_RIGHT) &&
334 static_cast<int>(m_dragDirections) &
335 static_cast<int>(DragDirections::TOP_TO_BOTTOM))
336 {
337 point.rx() = m_startDragPoint.x();
338 point.ry() = m_currentDragPoint.y();
339 width = m_currentDragPoint.x() - m_startDragPoint.x();
340 height = m_startDragPoint.y() - m_currentDragPoint.y();
341 // qDebug() << "left to right - top to bottom";
342 }
343
344 if(static_cast<int>(m_dragDirections) &
345 static_cast<int>(DragDirections::RIGHT_TO_LEFT) &&
346 static_cast<int>(m_dragDirections) &
347 static_cast<int>(DragDirections::TOP_TO_BOTTOM))
348 {
349 point.rx() = m_currentDragPoint.x();
350 point.ry() = m_currentDragPoint.y();
351 width = m_startDragPoint.x() - m_currentDragPoint.x();
352 height = m_startDragPoint.y() - m_currentDragPoint.y();
353 // qDebug() << "right to left - top to bottom";
354 }
355
356 // qDebug() << "The data used to update the integration scope:";
357 // qDebug() << "Point:" << point << "width:" << width << "height:" << height;
358 //
359 // qDebug() << "The integration scope before update:" << mpa_integrationScope;
360 //
361 // qDebug() << "Will update IntegrationScopeRect with:" << point << "width"
362 // << width << "height" << height;
364 std::make_shared<IntegrationScopeRect>(point, width, height);
365
366 // if(typeid(*mpa_integrationScope) == typeid(IntegrationScopeInterface))
367 // qDebug() << "The pointer is of type IntegrationScopeInterface";
368 // if(typeid(*mpa_integrationScope) == typeid(IntegrationScope))
369 // qDebug() << "The pointer is of type IntegrationScope";
370 // if(typeid(*mpa_integrationScope) == typeid(IntegrationScopeRect))
371 // qDebug() << "The pointer is of type IntegrationScopeRect";
372 // if(typeid(*mpa_integrationScope) == typeid(IntegrationScopeRhomb))
373 // qDebug() << "The pointer is of type IntegrationScopeRhomb";
374 //
375 // qDebug() << "The integration scope right after update:"
376 // << mpa_integrationScope;
377 //
378 // if(!mpa_integrationScope->getPoint(point))
379 // qFatal("Could not get point.");
380 // qDebug() << "The point:" << point;
381 // if(!mpa_integrationScope->getWidth(width))
382 // qFatal("Oh no!!!! width");
383 // if(!mpa_integrationScope->getWidth(height))
384 // qFatal("Oh no!!!! height");
385}
386
387void
389{
390 // qDebug() << toString();
391
392 /*
393 4+----------+3
394 | |
395 | |
396 | |
397 | |
398 | |
399 | |
400 | |
401 1+----------+2
402 ----width---
403*/
404
405 // As visible here, the fixed size of the rhomboid (using the S key in the
406 // plot widget) is the horizontal side.
407
408 // The points are numbered in a counterclockwise manner, starting from the
409 // starting drag point. The width side is right of the start drag point if
410 // the user drags from left to right and left of the start drag point if
411 // the user drags from left to right. In the figure above, the user
412 // has dragged the mouse from point 1 and to the right and upwards.
413 // Thus the width side is right of point 1. Because the numbering
414 // is counterclockwise, that point happens to be numbered 2.
415
416 // If the user had draggged the mouse starting at point 3 and to the left
417 // and to the bottom, then point 3 above would be point 1, point 4
418 // would be point 2 because the width side is left of the start
419 // drag point; point 1 would be point 3 and finally the last point
420 // would be at point 2.
421
422 // Sanity check
424 qFatal(
425 "The m_integrationScopeRhombWidth of the fixed rhomboid side cannot be "
426 "0.");
427
428 QPointF point;
429 std::vector<QPointF> points;
430
431 // Fill-in the points in the vector in the order they are created
432 // while drawing the rhomboid shape. Thus, the first point (start of the
433 // mouse click & drag operation is always the same.
434
435 point.rx() = m_startDragPoint.x();
436 point.ry() = m_startDragPoint.y();
437 points.push_back(point);
438 // qDebug() << "Start point:" << point;
439
440 if(static_cast<int>(m_dragDirections) &
441 static_cast<int>(DragDirections::LEFT_TO_RIGHT) &&
442 static_cast<int>(m_dragDirections) &
443 static_cast<int>(DragDirections::BOTTOM_TO_TOP))
444 {
445 // Second point.
447 point.ry() = m_startDragPoint.y();
448 points.push_back(point);
449 // qDebug() << "Second point:" << point;
450
451 // Third point.
453 point.ry() = m_currentDragPoint.ry();
454 points.push_back(point);
455 // qDebug() << "Third point:" << point;
456
457 // Fourth point.
458 point.rx() = m_currentDragPoint.rx();
459 point.ry() = m_currentDragPoint.ry();
460 points.push_back(point);
461 // qDebug() << "Last point:" << point;
462 }
463
464 if(static_cast<int>(m_dragDirections) &
465 static_cast<int>(DragDirections::RIGHT_TO_LEFT) &&
466 static_cast<int>(m_dragDirections) &
467 static_cast<int>(DragDirections::BOTTOM_TO_TOP))
468 {
469 // Second point.
470 point.rx() = m_currentDragPoint.rx();
471 point.ry() = m_currentDragPoint.ry();
472 points.push_back(point);
473 // qDebug() << "Second point:" << point;
474
475 // Third point.
477 point.ry() = m_currentDragPoint.ry();
478 points.push_back(point);
479 // qDebug() << "Third point:" << point;
480
481 // Fourth point.
483 point.ry() = m_startDragPoint.ry();
484 points.push_back(point);
485 // qDebug() << "Last point:" << point;
486 }
487
488 if(static_cast<int>(m_dragDirections) &
489 static_cast<int>(DragDirections::LEFT_TO_RIGHT) &&
490 static_cast<int>(m_dragDirections) &
491 static_cast<int>(DragDirections::TOP_TO_BOTTOM))
492 {
493 // Second point.
494 point.rx() = m_currentDragPoint.rx();
495 point.ry() = m_currentDragPoint.ry();
496 points.push_back(point);
497 // qDebug() << "Second point:" << point;
498
499 // Third point.
501 point.ry() = m_currentDragPoint.ry();
502 points.push_back(point);
503 // qDebug() << "Third point:" << point;
504
505 // Fourth point.
507 point.ry() = m_startDragPoint.y();
508 points.push_back(point);
509 // qDebug() << "Last point:" << point;
510 }
511
512 if(static_cast<int>(m_dragDirections) &
513 static_cast<int>(DragDirections::RIGHT_TO_LEFT) &&
514 static_cast<int>(m_dragDirections) &
515 static_cast<int>(DragDirections::TOP_TO_BOTTOM))
516 {
517 // Second point.
519 point.ry() = m_startDragPoint.y();
520 points.push_back(point);
521 // qDebug() << "Second point:" << point;
522
523 // Third point.
525 point.ry() = m_currentDragPoint.ry();
526 points.push_back(point);
527 // qDebug() << "Third point:" << point;
528
529 // Fourth point.
530 point.rx() = m_currentDragPoint.rx();
531 point.ry() = m_currentDragPoint.ry();
532 points.push_back(point);
533 // qDebug() << "Last point:" << point;
534 }
535
536 msp_integrationScope = std::make_shared<IntegrationScopeRhomb>(points);
537
538 // qDebug() << "Created an integration scope horizontal rhomboid with"
539 // << points.size() << "points:" << msp_integrationScope->toString();
540}
541
542void
544{
545 // qDebug() << toString();
546
547 /*
548 * +3
549 * . |
550 * . |
551 * . |
552 * . +2
553 * . .
554 * . .
555 * . .
556 * 4+ .
557 * | | .
558 * height | | .
559 * | | .
560 * 1+
561 *
562 */
563
564 // As visible here, the fixed size of the rhomboid (using the S key in the
565 // plot widget) is the vertical side.
566
567 // The points are numbered in a counterclockwise manner, starting from the
568 // starting drag point. The height side is below the start drag point if
569 // the user drags from top to bottom and above the start drag point if
570 // the user drags from bottom to top. In the figure above, the user
571 // has dragged the mouse from point 1 and to the right and upwards.
572 // Thus the height side is above the point 1. Because the numbering
573 // is counterclockwise, that point happens to be numbered 4.
574
575 // If the user had draggged the mouse starting at point 3 and to the left
576 // and to the bottom, then point 3 above would be point 1, point 4
577 // would be ponit 2, point 1 would be point 3 and finally, because
578 // the dragging is from top to bottom, the last point would be at point 2
579 // above, because the height side of the rhomboid is below the start
580 // drag point.
581
582 // Sanity check
584 qFatal("The height of the fixed rhomboid side cannot be 0.");
585
586 QPointF point;
587 std::vector<QPointF> points;
588
589 // Fill-in the points in the vector in the order they are created
590 // while drawing the rhomboid shape. Thus, the first point (start of the
591 // mouse click & drag operation is always the same, the leftmost bottom point
592 // of the drawing above (point 1).
593
594 point.rx() = m_startDragPoint.x();
595 point.ry() = m_startDragPoint.y();
596 points.push_back(point);
597 // qDebug() << "Start point:" << point;
598
599 if(static_cast<int>(m_dragDirections) &
600 static_cast<int>(DragDirections::LEFT_TO_RIGHT) &&
601 static_cast<int>(m_dragDirections) &
602 static_cast<int>(DragDirections::BOTTOM_TO_TOP))
603 {
604 // Second point.
605 point.rx() = m_currentDragPoint.rx();
606 point.ry() = m_currentDragPoint.ry();
607 points.push_back(point);
608 // qDebug() << "Second point:" << point;
609
610 // Third point.
611 point.rx() = m_currentDragPoint.rx();
613 points.push_back(point);
614 // qDebug() << "Third point:" << point;
615
616 // Fourth point.
617 point.rx() = m_startDragPoint.x();
619 points.push_back(point);
620 // qDebug() << "Last point:" << point;
621 }
622
623 if(static_cast<int>(m_dragDirections) &
624 static_cast<int>(DragDirections::RIGHT_TO_LEFT) &&
625 static_cast<int>(m_dragDirections) &
626 static_cast<int>(DragDirections::BOTTOM_TO_TOP))
627 {
628 // Second point.
629 point.rx() = m_startDragPoint.rx();
631 points.push_back(point);
632 // qDebug() << "Second point:" << point;
633
634 // Third point.
635 point.rx() = m_currentDragPoint.rx();
637 points.push_back(point);
638 // qDebug() << "Third point:" << point;
639
640 // Fourth point.
641 point.rx() = m_currentDragPoint.x();
642 point.ry() = m_currentDragPoint.y();
643 points.push_back(point);
644 // qDebug() << "Last point:" << point;
645 }
646
647 if(static_cast<int>(m_dragDirections) &
648 static_cast<int>(DragDirections::LEFT_TO_RIGHT) &&
649 static_cast<int>(m_dragDirections) &
650 static_cast<int>(DragDirections::TOP_TO_BOTTOM))
651 {
652 // Second point.
653 point.rx() = m_startDragPoint.x();
655 points.push_back(point);
656 // qDebug() << "Second point:" << point;
657
658 // Third point.
659 point.rx() = m_currentDragPoint.rx();
661 points.push_back(point);
662 // qDebug() << "Third point:" << point;
663
664 // Fourth point.
665 point.rx() = m_currentDragPoint.rx();
666 point.ry() = m_currentDragPoint.ry();
667 points.push_back(point);
668 // qDebug() << "Last point:" << point;
669 }
670
671 if(static_cast<int>(m_dragDirections) &
672 static_cast<int>(DragDirections::RIGHT_TO_LEFT) &&
673 static_cast<int>(m_dragDirections) &
674 static_cast<int>(DragDirections::TOP_TO_BOTTOM))
675 {
676 // Second point.
677 point.rx() = m_currentDragPoint.rx();
678 point.ry() = m_currentDragPoint.ry();
679 points.push_back(point);
680 // qDebug() << "Second point:" << point;
681
682 // Third point.
683 point.rx() = m_currentDragPoint.rx();
685 points.push_back(point);
686 // qDebug() << "Third point:" << point;
687
688 // Fourth point.
689 point.rx() = m_startDragPoint.rx();
691 points.push_back(point);
692 // qDebug() << "Last point:" << point;
693 }
694
695 msp_integrationScope = std::make_shared<IntegrationScopeRhomb>(points);
696
697 // qDebug() << "Created an integration scope vertical rhomboid with"
698 // << points.size() << "points:" << msp_integrationScope->toString();
699}
700
701void
703{
704 // qDebug() << toString();
705
706 // By essence, IntegrationScopeRhomb is a rhomboid polygon. Just set the
707 // points. There are two kinds of rhomboid integration scopes: horizontal and
708 // vertical.
709
710 /*
711 +----------+
712 | |
713 | |
714 | |
715 | |
716 | |
717 | |
718 | |
719 +----------+
720 ----width---
721*/
722
723 // As visible here, the fixed size of the rhomboid (using the S key in the
724 // plot widget) is the *horizontal* side (that is, the rhomboid has a non-0
725 // width)..
726
727 // However, it might be useful to be able to draw rhomboid integration scopes
728 // like this, that would correspond to the rhomboid above after a transpose
729 // operation.
730
731 /*
732 +
733 . |
734 . |
735 . |
736 . +
737 . .
738 . .
739 . .
740 + .
741 | | .
742 height | | .
743 | | .
744 +
745
746*/
747
748 // As visible here, the fixed size of the rhomboid (using the S key in the
749 // plot widget) is the vertical side (that is, the rhomboid has a non-0
750 // height).
751
752 // The general rule is thus that when the m_integrationScopeRhombWidth is
753 // not-0, then the first shape is considered, while when the
754 // m_integrationScopeRhombHeight is non-0, then the second shape is
755 // considered.
756
757 // This function is called when the user has dragged the cursor (left or right
758 // button, not for or for integration, respectively) with the 'Alt' modifier
759 // key pressed, so that they want to perform a rhomboid integration scope
760 // calculation.
761
762 // Of course, the integration scope in the context might not be a rhomboid
763 // scope, because we might enter this function as a very firt switch from
764 // scope or scopeRect to scopeRhomb. The only indication we have to direct the
765 // creation of a horizontal or vertical rhomboid is the
766 // m_integrationScopeRhombWidth/m_integrationScopeRhombHeight recorded in the
767 // plot widget that owns this plot context.
768
769 // qDebug() << "In updateIntegrationScopeRhomb, m_integrationScopeRhombWidth:"
770 // << m_integrationScopeRhombWidth
771 // << "and m_integrationScopeRhombHeight:"
772 // << m_integrationScopeRhombHeight;
773
775 qFatal(
776 "Both m_integrationScopeRhombWidth and m_integrationScopeRhombHeight of "
777 "rhomboid integration scope cannot be 0.");
778
783}
784
785// BasePlotContext &
786// BasePlotContext::operator=(const BasePlotContext &other)
787// {
788// if(this == &other)
789// return *this;
790//
791// m_dataKind = other.m_dataKind;
792//
793// m_isMouseDragging = other.m_isMouseDragging;
794// m_wasMouseDragging = other.m_wasMouseDragging;
795//
796// m_isKeyBoardDragging = other.m_isKeyBoardDragging;
797// m_isLeftPseudoButtonKeyPressed = other.m_isLeftPseudoButtonKeyPressed;
798// m_isRightPseudoButtonKeyPressed = other.m_isRightPseudoButtonKeyPressed;
799// m_wasKeyBoardDragging = other.m_wasKeyBoardDragging;
800//
801// m_startDragPoint = other.m_startDragPoint;
802// m_currentDragPoint = other.m_currentDragPoint;
803// m_lastCursorHoveredPoint = other.m_lastCursorHoveredPoint;
804//
805// m_selectionPolygon = other.m_selectionPolygon;
806// msp_integrationScope = other.msp_integrationScope;
807// m_integrationScopeRhombWidth = other.m_integrationScopeRhombWidth;
808// m_integrationScopeRhombHeight = other.m_integrationScopeRhombHeight;
809//
810// // The effective range of the axes.
811// m_xRange = other.m_xRange;
812// m_yRange = other.m_yRange;
813//
814// // Tell if the mouse move was started onto either axis, because that will
815// // condition if some calculations needs to be performed or not (for
816// example,
817// // if the mouse cursor motion was started on an axis, there is no point to
818// // perform deconvolutions).
819// m_wasClickOnXAxis = other.m_wasClickOnXAxis;
820// m_wasClickOnYAxis = other.m_wasClickOnYAxis;
821//
822// m_isMeasuringDistance = other.m_isMeasuringDistance;
823//
824// // The user-selected region over the plot.
825// // Note that we cannot use QCPRange structures because these are normalized
826// by
827// // QCustomPlot in such a manner that lower is actually < upper. But we need
828// // for a number of our calculations (specifically for the deconvolutions)
829// to
830// // actually have the lower value be start drag point.x even if the drag
831// // direction was from right to left.
832// m_xRegionRangeStart = other.m_xRegionRangeStart;
833// m_xRegionRangeEnd = other.m_xRegionRangeEnd;
834//
835// m_yRegionRangeStart = other.m_yRegionRangeStart;
836// m_yRegionRangeEnd = other.m_yRegionRangeEnd;
837//
838// m_xDelta = other.m_xDelta;
839// m_yDelta = other.m_yDelta;
840//
841// m_pressedKeyCode = other.m_pressedKeyCode;
842// m_pressedKeyText = other.m_pressedKeyText;
843// m_releasedKeyCode = other.m_releasedKeyCode;
844// m_releasedKeyText = other.m_releasedKeyText;
845//
846// m_keyboardModifiers = other.m_keyboardModifiers;
847//
848// m_lastPressedMouseButton = other.m_lastPressedMouseButton;
849// m_lastReleasedMouseButton = other.m_lastReleasedMouseButton;
850//
851// m_pressedMouseButtons = other.m_pressedMouseButtons;
852//
853// m_mouseButtonsAtMousePress = other.m_mouseButtonsAtMousePress;
854// m_mouseButtonsAtMouseRelease = other.m_mouseButtonsAtMouseRelease;
855//
856// return *this;
857// }
858
861{
862 int drag_directions = static_cast<int>(DragDirections::NOT_SET);
863
865 drag_directions |= static_cast<int>(DragDirections::LEFT_TO_RIGHT);
866 else
867 drag_directions |= static_cast<int>(DragDirections::RIGHT_TO_LEFT);
868
870 drag_directions |= static_cast<int>(DragDirections::BOTTOM_TO_TOP);
871 else
872 drag_directions |= static_cast<int>(DragDirections::TOP_TO_BOTTOM);
873
874 // qDebug() << "DragDirections:" << drag_directions;
875
876 m_dragDirections = static_cast<DragDirections>(drag_directions);
877
878 return static_cast<DragDirections>(drag_directions);
879}
880
881QString
883{
884 QString text("Context:");
885
886 text += QString(" data kind: %1").arg(static_cast<int>(m_dataKind));
887
888 text += QString(" -- isMouseDragging: %1 -- wasMouseDragging: %2")
889 .arg(m_isMouseDragging ? "true" : "false")
890 .arg(m_wasMouseDragging ? "true" : "false");
891
892 text += QString(" -- startDragPoint : (%1, %2)")
893 .arg(m_startDragPoint.x())
894 .arg(m_startDragPoint.y());
895
896 text += QString(" -- currentDragPoint : (%1, %2)")
897 .arg(m_currentDragPoint.x())
898 .arg(m_currentDragPoint.y());
899
900 text += QString(" -- lastCursorHoveredPoint : (%1, %2)")
902 .arg(m_lastCursorHoveredPoint.y());
903
904 text += dragDirectionsToString();
905
906 // The integration scope
907 text += " -- Integration scope: ";
908 text += msp_integrationScope->toString();
909 text += " -- ";
910
911 text +=
912 QString(" -- xRange: (%1, %2)").arg(m_xRange.lower).arg(m_xRange.upper);
913
914 text +=
915 QString(" -- yRange: (%1, %2)").arg(m_yRange.lower).arg(m_yRange.upper);
916
917 text += QString(" -- wasClickOnXAxis: %1")
918 .arg(m_wasClickOnXAxis ? "true" : "false");
919 text += QString(" -- wasClickOnYAxis: %1")
920 .arg(m_wasClickOnYAxis ? "true" : "false");
921 text += QString(" -- isMeasuringDistance: %1")
922 .arg(m_isMeasuringDistance ? "true" : "false");
923
924 text += QString(" -- xRegionRangeStart: %1 -- xRegionRangeEnd: %2")
926 .arg(m_xRegionRangeStop);
927
928 text += QString(" -- yRegionRangeStart: %1 -- yRegionRangeEnd: %2")
930 .arg(m_yRegionRangeStop);
931
932 text += QString(" -- xDelta: %1 -- yDelta: %2").arg(m_xDelta).arg(m_yDelta);
933
934 text += QString(" -- pressedKeyCode: %1").arg(m_pressedKeyCode);
935
936 // Qt::NoModifier0x00000000No modifier key is pressed.
937 // Qt::ShiftModifier0x02000000A Shift key on the keyboard is pressed.
938 // Qt::ControlModifier0x04000000A Ctrl key on the keyboard is pressed.
939 // Qt::AltModifier0x08000000An Alt key on the keyboard is pressed.
940 // Qt::MetaModifier0x10000000A Meta key on the keyboard is pressed.
941 // Qt::KeypadModifier0x20000000A keypad button is pressed.
942 // Qt::GroupSwitchModifier0x40000000X11 only (unless activated on Windows by a
943 // command line argument).
944 // A Mode_switch key on the keyboard is
945 // pressed.
946
947 text += QString(" -- keyboardModifiers: ");
948
949 if(m_keyboardModifiers == Qt::NoModifier)
950 text += QString("%1 - ").arg(qtKeyboardModifierMap[Qt::NoModifier]);
951
952 if(static_cast<int>(m_keyboardModifiers) & Qt::ShiftModifier)
953 text += QString("%1 - ").arg(qtKeyboardModifierMap[Qt::ShiftModifier]);
954
955 if(static_cast<int>(m_keyboardModifiers) & Qt::ControlModifier)
956 text += QString("%1 - ").arg(qtKeyboardModifierMap[Qt::ControlModifier]);
957
958 if(static_cast<int>(m_keyboardModifiers) & Qt::AltModifier)
959 text += QString("%1 - ").arg(qtKeyboardModifierMap[Qt::AltModifier]);
960
961 if(static_cast<int>(m_keyboardModifiers) & Qt::MetaModifier)
962 text += QString("%1 - ").arg(qtKeyboardModifierMap[Qt::MetaModifier]);
963
964 if(static_cast<int>(m_keyboardModifiers) & Qt::KeypadModifier)
965 text += QString("%1 - ").arg(qtKeyboardModifierMap[Qt::KeypadModifier]);
966
967 if(static_cast<int>(m_keyboardModifiers) & Qt::GroupSwitchModifier)
968 text +=
969 QString("%1 - ").arg(qtKeyboardModifierMap[Qt::GroupSwitchModifier]);
970
971 text += QString(" -- lastPressedMouseButton: %1")
973
974 text += QString(" -- lastReleasedMouseButton: %1")
976
977 text += QString(" -- pressedMouseButtons: %1")
979
980 text += QString(" -- mouseButtonsAtMousePress: %1")
982
983 text += QString(" -- mouseButtonsAtMouseRelease: %1")
985
986 return text;
987}
988
989QString
991{
992 QString text;
993
994 // Document how the mouse cursor is being dragged.
996 {
997 if(static_cast<int>(m_dragDirections) &
998 static_cast<int>(DragDirections::LEFT_TO_RIGHT))
999 text += " -- dragging from left to right";
1000 else if(static_cast<int>(m_dragDirections) &
1001 static_cast<int>(DragDirections::RIGHT_TO_LEFT))
1002 text += " -- dragging from right to left";
1003 if(static_cast<int>(m_dragDirections) &
1004 static_cast<int>(DragDirections::TOP_TO_BOTTOM))
1005 text += " -- dragging from top to bottom";
1006 if(static_cast<int>(m_dragDirections) &
1007 static_cast<int>(DragDirections::BOTTOM_TO_TOP))
1008 text += " -- dragging from bottom to top";
1009 }
1010
1011 return text;
1012}
1013
1014void
1016{
1017 // qDebug() << "Now registering the JS constructor for BasePlotContext.";
1018
1019 if(!engine)
1020 {
1021 qFatal() << "Cannot register class: engine is null";
1022 return;
1023 }
1024
1025 // Register the meta object as a constructor
1026 QJSValue jsMetaObject =
1027 engine->newQMetaObject(&BasePlotContext::staticMetaObject);
1028 engine->globalObject().setProperty("BasePlotContext", jsMetaObject);
1029
1030 QJSValue enumObject = engine->newObject();
1031 enumObject.setProperty("NOT_SET",
1032 static_cast<int>(pappso::DragDirections::NOT_SET));
1033 enumObject.setProperty(
1034 "LEFT_TO_RIGHT", static_cast<int>(pappso::DragDirections::LEFT_TO_RIGHT));
1035 enumObject.setProperty(
1036 "RIGHT_TO_LEFT", static_cast<int>(pappso::DragDirections::RIGHT_TO_LEFT));
1037 enumObject.setProperty(
1038 "TOP_TO_BOTTOM", static_cast<int>(pappso::DragDirections::TOP_TO_BOTTOM));
1039 enumObject.setProperty(
1040 "BOTTOM_TO_TOP", static_cast<int>(pappso::DragDirections::BOTTOM_TO_TOP));
1041
1042 // Make it available in the global JS scope
1043 engine->globalObject().setProperty("DragDirections", enumObject);
1044}
1045
1046} // namespace pappso
static void registerJsConstructor(QJSEngine *engine)
Qt::MouseButtons m_mouseButtonsAtMousePress
SelectionPolygon m_selectionPolygon
Q_INVOKABLE BasePlotContext(QObject *parent=nullptr)
Q_INVOKABLE QString dragDirectionsToString() const
IntegrationScopeBaseCstSPtr msp_integrationScope
DragDirections recordDragDirections()
Enums::DataKind m_dataKind
Q_INVOKABLE BasePlotContext * clone(QObject *parent=nullptr)
Qt::KeyboardModifiers m_keyboardModifiers
Qt::MouseButtons m_lastPressedMouseButton
DragDirections m_dragDirections
Q_INVOKABLE void initialize(const BasePlotContext &other)
Qt::MouseButtons m_pressedMouseButtons
Qt::MouseButtons m_mouseButtonsAtMouseRelease
Qt::MouseButtons m_lastReleasedMouseButton
Q_INVOKABLE QString toString() const
tries to keep as much as possible monoisotopes, removing any possible C13 peaks and changes multichar...
Definition aa.cpp:39
std::map< Qt::MouseButton, QString > qtMouseButtonMap
std::map< Qt::MouseButtons, QString > qtMouseButtonsMap
std::map< Qt::KeyboardModifier, QString > qtKeyboardModifierMap