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
177
179
182
184
187
188 return copy_p;
189}
190
191void
193{
194 m_dataKind = other.m_dataKind;
195
199
204
208
213
214 // The effective range of the axes.
215 m_xRange = other.m_xRange;
216 m_yRange = other.m_yRange;
217
218 // Tell if the mouse move was started onto either axis, because that will
219 // condition if some calculations needs to be performed or not (for example,
220 // if the mouse cursor motion was started on an axis, there is no point to
221 // perform deconvolutions).
224
226
227 // The user-selected region over the plot.
228 // Note that we cannot use QCPRange structures because these are normalized by
229 // QCustomPlot in such a manner that lower is actually < upper. But we need
230 // for a number of our calculations (specifically for the deconvolutions) to
231 // actually have the lower value be start drag point.x even if the drag
232 // direction was from right to left.
235
238
239 m_xDelta = other.m_xDelta;
240 m_yDelta = other.m_yDelta;
241
248
250
253
255
258}
259
260void
262{
263 // qDebug();
264
265 // By essence, IntegrationScope is 1D scope. The point of the scope is the
266 // left bottom point, and then we document the width.
267
268 double x_range_start = std::min(m_currentDragPoint.x(), m_startDragPoint.x());
269 double x_range_end = std::max(m_currentDragPoint.x(), m_startDragPoint.x());
270
271 double y_position = m_startDragPoint.y();
272
273 QPointF point(x_range_start, y_position);
274 double width = x_range_end - x_range_start;
275
276 // qDebug() << "Going to create an integration scope with point:" << point
277 // << "and width:" << width;
278 msp_integrationScope = std::make_shared<IntegrationScope>(point, width);
279 // qDebug() << "Created integration scope:" <<
280 // msp_integrationScope->toString();
281}
282
283void
285{
286 // qDebug();
287
288 // By essence, IntegrationScopeRect is a squared rectangle scope. The point of
289 // the scope is the left bottom point, and then we document the width and the
290 // height.
291
292 /* Like this:
293*
294+---------------------------+ -
295| | |
296| | |
297| | m_height
298| | |
299| | |
300P---------------------------+ -
301
302|--------- m_width ---------|
303
304*/
305
306 // We need to find the point that is actually the left bottom point.
307
308 QPointF point;
309 double width = 0;
310 double height = 0;
311
312 if(static_cast<int>(m_dragDirections) &
313 static_cast<int>(DragDirections::LEFT_TO_RIGHT) &&
314 static_cast<int>(m_dragDirections) &
315 static_cast<int>(DragDirections::BOTTOM_TO_TOP))
316 {
317 point.rx() = m_startDragPoint.x();
318 point.ry() = m_startDragPoint.y();
319 width = m_currentDragPoint.x() - point.rx();
320 height = m_currentDragPoint.y() - point.ry();
321 // qDebug() << "left to right - bottom to top";
322 }
323
324 if(static_cast<int>(m_dragDirections) &
325 static_cast<int>(DragDirections::RIGHT_TO_LEFT) &&
326 static_cast<int>(m_dragDirections) &
327 static_cast<int>(DragDirections::BOTTOM_TO_TOP))
328 {
329 point.rx() = m_currentDragPoint.x();
330 point.ry() = m_currentDragPoint.y();
331 width = m_startDragPoint.x() - m_currentDragPoint.x();
332 height = m_startDragPoint.y() - m_currentDragPoint.y();
333 // qDebug() << "right to left - bottom to top";
334 }
335
336 if(static_cast<int>(m_dragDirections) &
337 static_cast<int>(DragDirections::LEFT_TO_RIGHT) &&
338 static_cast<int>(m_dragDirections) &
339 static_cast<int>(DragDirections::TOP_TO_BOTTOM))
340 {
341 point.rx() = m_startDragPoint.x();
342 point.ry() = m_currentDragPoint.y();
343 width = m_currentDragPoint.x() - m_startDragPoint.x();
344 height = m_startDragPoint.y() - m_currentDragPoint.y();
345 // qDebug() << "left to right - top to bottom";
346 }
347
348 if(static_cast<int>(m_dragDirections) &
349 static_cast<int>(DragDirections::RIGHT_TO_LEFT) &&
350 static_cast<int>(m_dragDirections) &
351 static_cast<int>(DragDirections::TOP_TO_BOTTOM))
352 {
353 point.rx() = m_currentDragPoint.x();
354 point.ry() = m_currentDragPoint.y();
355 width = m_startDragPoint.x() - m_currentDragPoint.x();
356 height = m_startDragPoint.y() - m_currentDragPoint.y();
357 // qDebug() << "right to left - top to bottom";
358 }
359
360 // qDebug() << "The data used to update the integration scope:";
361 // qDebug() << "Point:" << point << "width:" << width << "height:" << height;
362 //
363 // qDebug() << "The integration scope before update:" << mpa_integrationScope;
364 //
365 // qDebug() << "Will update IntegrationScopeRect with:" << point << "width"
366 // << width << "height" << height;
368 std::make_shared<IntegrationScopeRect>(point, width, height);
369
370 // if(typeid(*mpa_integrationScope) == typeid(IntegrationScopeInterface))
371 // qDebug() << "The pointer is of type IntegrationScopeInterface";
372 // if(typeid(*mpa_integrationScope) == typeid(IntegrationScope))
373 // qDebug() << "The pointer is of type IntegrationScope";
374 // if(typeid(*mpa_integrationScope) == typeid(IntegrationScopeRect))
375 // qDebug() << "The pointer is of type IntegrationScopeRect";
376 // if(typeid(*mpa_integrationScope) == typeid(IntegrationScopeRhomb))
377 // qDebug() << "The pointer is of type IntegrationScopeRhomb";
378 //
379 // qDebug() << "The integration scope right after update:"
380 // << mpa_integrationScope;
381 //
382 // if(!mpa_integrationScope->getPoint(point))
383 // qFatal("Could not get point.");
384 // qDebug() << "The point:" << point;
385 // if(!mpa_integrationScope->getWidth(width))
386 // qFatal("Oh no!!!! width");
387 // if(!mpa_integrationScope->getWidth(height))
388 // qFatal("Oh no!!!! height");
389}
390
391void
393{
394 // qDebug() << toString();
395
396 /*
397 4+----------+3
398 | |
399 | |
400 | |
401 | |
402 | |
403 | |
404 | |
405 1+----------+2
406 ----width---
407*/
408
409 // As visible here, the fixed size of the rhomboid (using the S key in the
410 // plot widget) is the horizontal side.
411
412 // The points are numbered in a counterclockwise manner, starting from the
413 // starting drag point. The width side is right of the start drag point if
414 // the user drags from left to right and left of the start drag point if
415 // the user drags from left to right. In the figure above, the user
416 // has dragged the mouse from point 1 and to the right and upwards.
417 // Thus the width side is right of point 1. Because the numbering
418 // is counterclockwise, that point happens to be numbered 2.
419
420 // If the user had draggged the mouse starting at point 3 and to the left
421 // and to the bottom, then point 3 above would be point 1, point 4
422 // would be point 2 because the width side is left of the start
423 // drag point; point 1 would be point 3 and finally the last point
424 // would be at point 2.
425
426 // Sanity check
428 qFatal(
429 "The m_integrationScopeRhombWidth of the fixed rhomboid side cannot be "
430 "0.");
431
432 QPointF point;
433 std::vector<QPointF> points;
434
435 // Fill-in the points in the vector in the order they are created
436 // while drawing the rhomboid shape. Thus, the first point (start of the
437 // mouse click & drag operation is always the same.
438
439 point.rx() = m_startDragPoint.x();
440 point.ry() = m_startDragPoint.y();
441 points.push_back(point);
442 // qDebug() << "Start point:" << point;
443
444 if(static_cast<int>(m_dragDirections) &
445 static_cast<int>(DragDirections::LEFT_TO_RIGHT) &&
446 static_cast<int>(m_dragDirections) &
447 static_cast<int>(DragDirections::BOTTOM_TO_TOP))
448 {
449 // Second point.
451 point.ry() = m_startDragPoint.y();
452 points.push_back(point);
453 // qDebug() << "Second point:" << point;
454
455 // Third point.
457 point.ry() = m_currentDragPoint.ry();
458 points.push_back(point);
459 // qDebug() << "Third point:" << point;
460
461 // Fourth point.
462 point.rx() = m_currentDragPoint.rx();
463 point.ry() = m_currentDragPoint.ry();
464 points.push_back(point);
465 // qDebug() << "Last point:" << point;
466 }
467
468 if(static_cast<int>(m_dragDirections) &
469 static_cast<int>(DragDirections::RIGHT_TO_LEFT) &&
470 static_cast<int>(m_dragDirections) &
471 static_cast<int>(DragDirections::BOTTOM_TO_TOP))
472 {
473 // Second point.
474 point.rx() = m_currentDragPoint.rx();
475 point.ry() = m_currentDragPoint.ry();
476 points.push_back(point);
477 // qDebug() << "Second point:" << point;
478
479 // Third point.
481 point.ry() = m_currentDragPoint.ry();
482 points.push_back(point);
483 // qDebug() << "Third point:" << point;
484
485 // Fourth point.
487 point.ry() = m_startDragPoint.ry();
488 points.push_back(point);
489 // qDebug() << "Last point:" << point;
490 }
491
492 if(static_cast<int>(m_dragDirections) &
493 static_cast<int>(DragDirections::LEFT_TO_RIGHT) &&
494 static_cast<int>(m_dragDirections) &
495 static_cast<int>(DragDirections::TOP_TO_BOTTOM))
496 {
497 // Second point.
498 point.rx() = m_currentDragPoint.rx();
499 point.ry() = m_currentDragPoint.ry();
500 points.push_back(point);
501 // qDebug() << "Second point:" << point;
502
503 // Third point.
505 point.ry() = m_currentDragPoint.ry();
506 points.push_back(point);
507 // qDebug() << "Third point:" << point;
508
509 // Fourth point.
511 point.ry() = m_startDragPoint.y();
512 points.push_back(point);
513 // qDebug() << "Last point:" << point;
514 }
515
516 if(static_cast<int>(m_dragDirections) &
517 static_cast<int>(DragDirections::RIGHT_TO_LEFT) &&
518 static_cast<int>(m_dragDirections) &
519 static_cast<int>(DragDirections::TOP_TO_BOTTOM))
520 {
521 // Second point.
523 point.ry() = m_startDragPoint.y();
524 points.push_back(point);
525 // qDebug() << "Second point:" << point;
526
527 // Third point.
529 point.ry() = m_currentDragPoint.ry();
530 points.push_back(point);
531 // qDebug() << "Third point:" << point;
532
533 // Fourth point.
534 point.rx() = m_currentDragPoint.rx();
535 point.ry() = m_currentDragPoint.ry();
536 points.push_back(point);
537 // qDebug() << "Last point:" << point;
538 }
539
540 msp_integrationScope = std::make_shared<IntegrationScopeRhomb>(points);
541
542 // qDebug() << "Created an integration scope horizontal rhomboid with"
543 // << points.size() << "points:" << msp_integrationScope->toString();
544}
545
546void
548{
549 // qDebug() << toString();
550
551 /*
552 * +3
553 * . |
554 * . |
555 * . |
556 * . +2
557 * . .
558 * . .
559 * . .
560 * 4+ .
561 * | | .
562 * height | | .
563 * | | .
564 * 1+
565 *
566 */
567
568 // As visible here, the fixed size of the rhomboid (using the S key in the
569 // plot widget) is the vertical side.
570
571 // The points are numbered in a counterclockwise manner, starting from the
572 // starting drag point. The height side is below the start drag point if
573 // the user drags from top to bottom and above the start drag point if
574 // the user drags from bottom to top. In the figure above, the user
575 // has dragged the mouse from point 1 and to the right and upwards.
576 // Thus the height side is above the point 1. Because the numbering
577 // is counterclockwise, that point happens to be numbered 4.
578
579 // If the user had draggged the mouse starting at point 3 and to the left
580 // and to the bottom, then point 3 above would be point 1, point 4
581 // would be ponit 2, point 1 would be point 3 and finally, because
582 // the dragging is from top to bottom, the last point would be at point 2
583 // above, because the height side of the rhomboid is below the start
584 // drag point.
585
586 // Sanity check
588 qFatal("The height of the fixed rhomboid side cannot be 0.");
589
590 QPointF point;
591 std::vector<QPointF> points;
592
593 // Fill-in the points in the vector in the order they are created
594 // while drawing the rhomboid shape. Thus, the first point (start of the
595 // mouse click & drag operation is always the same, the leftmost bottom point
596 // of the drawing above (point 1).
597
598 point.rx() = m_startDragPoint.x();
599 point.ry() = m_startDragPoint.y();
600 points.push_back(point);
601 // qDebug() << "Start point:" << point;
602
603 if(static_cast<int>(m_dragDirections) &
604 static_cast<int>(DragDirections::LEFT_TO_RIGHT) &&
605 static_cast<int>(m_dragDirections) &
606 static_cast<int>(DragDirections::BOTTOM_TO_TOP))
607 {
608 // Second point.
609 point.rx() = m_currentDragPoint.rx();
610 point.ry() = m_currentDragPoint.ry();
611 points.push_back(point);
612 // qDebug() << "Second point:" << point;
613
614 // Third point.
615 point.rx() = m_currentDragPoint.rx();
617 points.push_back(point);
618 // qDebug() << "Third point:" << point;
619
620 // Fourth point.
621 point.rx() = m_startDragPoint.x();
623 points.push_back(point);
624 // qDebug() << "Last point:" << point;
625 }
626
627 if(static_cast<int>(m_dragDirections) &
628 static_cast<int>(DragDirections::RIGHT_TO_LEFT) &&
629 static_cast<int>(m_dragDirections) &
630 static_cast<int>(DragDirections::BOTTOM_TO_TOP))
631 {
632 // Second point.
633 point.rx() = m_startDragPoint.rx();
635 points.push_back(point);
636 // qDebug() << "Second point:" << point;
637
638 // Third point.
639 point.rx() = m_currentDragPoint.rx();
641 points.push_back(point);
642 // qDebug() << "Third point:" << point;
643
644 // Fourth point.
645 point.rx() = m_currentDragPoint.x();
646 point.ry() = m_currentDragPoint.y();
647 points.push_back(point);
648 // qDebug() << "Last point:" << point;
649 }
650
651 if(static_cast<int>(m_dragDirections) &
652 static_cast<int>(DragDirections::LEFT_TO_RIGHT) &&
653 static_cast<int>(m_dragDirections) &
654 static_cast<int>(DragDirections::TOP_TO_BOTTOM))
655 {
656 // Second point.
657 point.rx() = m_startDragPoint.x();
659 points.push_back(point);
660 // qDebug() << "Second point:" << point;
661
662 // Third point.
663 point.rx() = m_currentDragPoint.rx();
665 points.push_back(point);
666 // qDebug() << "Third point:" << point;
667
668 // Fourth point.
669 point.rx() = m_currentDragPoint.rx();
670 point.ry() = m_currentDragPoint.ry();
671 points.push_back(point);
672 // qDebug() << "Last point:" << point;
673 }
674
675 if(static_cast<int>(m_dragDirections) &
676 static_cast<int>(DragDirections::RIGHT_TO_LEFT) &&
677 static_cast<int>(m_dragDirections) &
678 static_cast<int>(DragDirections::TOP_TO_BOTTOM))
679 {
680 // Second point.
681 point.rx() = m_currentDragPoint.rx();
682 point.ry() = m_currentDragPoint.ry();
683 points.push_back(point);
684 // qDebug() << "Second point:" << point;
685
686 // Third point.
687 point.rx() = m_currentDragPoint.rx();
689 points.push_back(point);
690 // qDebug() << "Third point:" << point;
691
692 // Fourth point.
693 point.rx() = m_startDragPoint.rx();
695 points.push_back(point);
696 // qDebug() << "Last point:" << point;
697 }
698
699 msp_integrationScope = std::make_shared<IntegrationScopeRhomb>(points);
700
701 // qDebug() << "Created an integration scope vertical rhomboid with"
702 // << points.size() << "points:" << msp_integrationScope->toString();
703}
704
705void
707{
708 // qDebug() << toString();
709
710 // By essence, IntegrationScopeRhomb is a rhomboid polygon. Just set the
711 // points. There are two kinds of rhomboid integration scopes: horizontal and
712 // vertical.
713
714 /*
715 +----------+
716 | |
717 | |
718 | |
719 | |
720 | |
721 | |
722 | |
723 +----------+
724 ----width---
725*/
726
727 // As visible here, the fixed size of the rhomboid (using the S key in the
728 // plot widget) is the *horizontal* side (that is, the rhomboid has a non-0
729 // width)..
730
731 // However, it might be useful to be able to draw rhomboid integration scopes
732 // like this, that would correspond to the rhomboid above after a transpose
733 // operation.
734
735 /*
736 +
737 . |
738 . |
739 . |
740 . +
741 . .
742 . .
743 . .
744 + .
745 | | .
746 height | | .
747 | | .
748 +
749
750*/
751
752 // As visible here, the fixed size of the rhomboid (using the S key in the
753 // plot widget) is the vertical side (that is, the rhomboid has a non-0
754 // height).
755
756 // The general rule is thus that when the m_integrationScopeRhombWidth is
757 // not-0, then the first shape is considered, while when the
758 // m_integrationScopeRhombHeight is non-0, then the second shape is
759 // considered.
760
761 // This function is called when the user has dragged the cursor (left or right
762 // button, not for or for integration, respectively) with the 'Alt' modifier
763 // key pressed, so that they want to perform a rhomboid integration scope
764 // calculation.
765
766 // Of course, the integration scope in the context might not be a rhomboid
767 // scope, because we might enter this function as a very firt switch from
768 // scope or scopeRect to scopeRhomb. The only indication we have to direct the
769 // creation of a horizontal or vertical rhomboid is the
770 // m_integrationScopeRhombWidth/m_integrationScopeRhombHeight recorded in the
771 // plot widget that owns this plot context.
772
773 // qDebug() << "In updateIntegrationScopeRhomb, m_integrationScopeRhombWidth:"
774 // << m_integrationScopeRhombWidth
775 // << "and m_integrationScopeRhombHeight:"
776 // << m_integrationScopeRhombHeight;
777
779 qFatal(
780 "Both m_integrationScopeRhombWidth and m_integrationScopeRhombHeight of "
781 "rhomboid integration scope cannot be 0.");
782
787}
788
789// BasePlotContext &
790// BasePlotContext::operator=(const BasePlotContext &other)
791// {
792// if(this == &other)
793// return *this;
794//
795// m_dataKind = other.m_dataKind;
796//
797// m_isMouseDragging = other.m_isMouseDragging;
798// m_wasMouseDragging = other.m_wasMouseDragging;
799//
800// m_isKeyBoardDragging = other.m_isKeyBoardDragging;
801// m_isLeftPseudoButtonKeyPressed = other.m_isLeftPseudoButtonKeyPressed;
802// m_isRightPseudoButtonKeyPressed = other.m_isRightPseudoButtonKeyPressed;
803// m_wasKeyBoardDragging = other.m_wasKeyBoardDragging;
804//
805// m_startDragPoint = other.m_startDragPoint;
806// m_currentDragPoint = other.m_currentDragPoint;
807// m_lastCursorHoveredPoint = other.m_lastCursorHoveredPoint;
808//
809// m_selectionPolygon = other.m_selectionPolygon;
810// msp_integrationScope = other.msp_integrationScope;
811// m_integrationScopeRhombWidth = other.m_integrationScopeRhombWidth;
812// m_integrationScopeRhombHeight = other.m_integrationScopeRhombHeight;
813//
814// // The effective range of the axes.
815// m_xRange = other.m_xRange;
816// m_yRange = other.m_yRange;
817//
818// // Tell if the mouse move was started onto either axis, because that will
819// // condition if some calculations needs to be performed or not (for
820// example,
821// // if the mouse cursor motion was started on an axis, there is no point to
822// // perform deconvolutions).
823// m_wasClickOnXAxis = other.m_wasClickOnXAxis;
824// m_wasClickOnYAxis = other.m_wasClickOnYAxis;
825//
826// m_isMeasuringDistance = other.m_isMeasuringDistance;
827//
828// // The user-selected region over the plot.
829// // Note that we cannot use QCPRange structures because these are normalized
830// by
831// // QCustomPlot in such a manner that lower is actually < upper. But we need
832// // for a number of our calculations (specifically for the deconvolutions)
833// to
834// // actually have the lower value be start drag point.x even if the drag
835// // direction was from right to left.
836// m_xRegionRangeStart = other.m_xRegionRangeStart;
837// m_xRegionRangeEnd = other.m_xRegionRangeEnd;
838//
839// m_yRegionRangeStart = other.m_yRegionRangeStart;
840// m_yRegionRangeEnd = other.m_yRegionRangeEnd;
841//
842// m_xDelta = other.m_xDelta;
843// m_yDelta = other.m_yDelta;
844//
845// m_pressedKeyCode = other.m_pressedKeyCode;
846// m_pressedKeyText = other.m_pressedKeyText;
847// m_releasedKeyCode = other.m_releasedKeyCode;
848// m_releasedKeyText = other.m_releasedKeyText;
849//
850// m_keyboardModifiers = other.m_keyboardModifiers;
851//
852// m_lastPressedMouseButton = other.m_lastPressedMouseButton;
853// m_lastReleasedMouseButton = other.m_lastReleasedMouseButton;
854//
855// m_pressedMouseButtons = other.m_pressedMouseButtons;
856//
857// m_mouseButtonsAtMousePress = other.m_mouseButtonsAtMousePress;
858// m_mouseButtonsAtMouseRelease = other.m_mouseButtonsAtMouseRelease;
859//
860// return *this;
861// }
862
865{
866 int drag_directions = static_cast<int>(DragDirections::NOT_SET);
867
869 drag_directions |= static_cast<int>(DragDirections::LEFT_TO_RIGHT);
870 else
871 drag_directions |= static_cast<int>(DragDirections::RIGHT_TO_LEFT);
872
874 drag_directions |= static_cast<int>(DragDirections::BOTTOM_TO_TOP);
875 else
876 drag_directions |= static_cast<int>(DragDirections::TOP_TO_BOTTOM);
877
878 // qDebug() << "DragDirections:" << drag_directions;
879
880 m_dragDirections = static_cast<DragDirections>(drag_directions);
881
882 return static_cast<DragDirections>(drag_directions);
883}
884
885QString
887{
888 QString text("Context:");
889
890 text += QString(" data kind: %1").arg(static_cast<int>(m_dataKind));
891
892 text += QString(" -- isMouseDragging: %1 -- wasMouseDragging: %2")
893 .arg(m_isMouseDragging ? "true" : "false")
894 .arg(m_wasMouseDragging ? "true" : "false");
895
896 text += QString(" -- startDragPoint : (%1, %2)")
897 .arg(m_startDragPoint.x())
898 .arg(m_startDragPoint.y());
899
900 text += QString(" -- currentDragPoint : (%1, %2)")
901 .arg(m_currentDragPoint.x())
902 .arg(m_currentDragPoint.y());
903
904 text += QString(" -- lastCursorHoveredPoint : (%1, %2)")
906 .arg(m_lastCursorHoveredPoint.y());
907
908 text += dragDirectionsToString();
909
910 // The integration scope
911 text += " -- Integration scope: ";
912 text += msp_integrationScope->toString();
913 text += " -- ";
914
915 text +=
916 QString(" -- xRange: (%1, %2)").arg(m_xRange.lower).arg(m_xRange.upper);
917
918 text +=
919 QString(" -- yRange: (%1, %2)").arg(m_yRange.lower).arg(m_yRange.upper);
920
921 text += QString(" -- wasClickOnXAxis: %1")
922 .arg(m_wasClickOnXAxis ? "true" : "false");
923 text += QString(" -- wasClickOnYAxis: %1")
924 .arg(m_wasClickOnYAxis ? "true" : "false");
925 text += QString(" -- isMeasuringDistance: %1")
926 .arg(m_isMeasuringDistance ? "true" : "false");
927
928 text += QString(" -- xRegionRangeStart: %1 -- xRegionRangeEnd: %2")
930 .arg(m_xRegionRangeStop);
931
932 text += QString(" -- yRegionRangeStart: %1 -- yRegionRangeEnd: %2")
934 .arg(m_yRegionRangeStop);
935
936 text += QString(" -- xDelta: %1 -- yDelta: %2").arg(m_xDelta).arg(m_yDelta);
937
938 text += QString(" -- pressedKeyCode: %1").arg(m_pressedKeyCode);
939
940 if(m_pressedKeyCodes.size())
941 {
942 for(int key : m_pressedKeyCodes)
943 text += QString(" -- pressedKeyCodes key: %1").arg(key);
944 }
945
946 text += QString(" -- releasedKeyCode: %1").arg(m_releasedKeyCode);
947
948 if(m_releasedKeyCodes.size())
949 {
950 for(int key : m_releasedKeyCodes)
951 text += QString(" -- releasedKeyCodes key: %1").arg(key);
952 }
953
954 // Qt::NoModifier0x00000000No modifier key is pressed.
955 // Qt::ShiftModifier0x02000000A Shift key on the keyboard is pressed.
956 // Qt::ControlModifier0x04000000A Ctrl key on the keyboard is pressed.
957 // Qt::AltModifier0x08000000An Alt key on the keyboard is pressed.
958 // Qt::MetaModifier0x10000000A Meta key on the keyboard is pressed.
959 // Qt::KeypadModifier0x20000000A keypad button is pressed.
960 // Qt::GroupSwitchModifier0x40000000X11 only (unless activated on Windows by a
961 // command line argument).
962 // A Mode_switch key on the keyboard is
963 // pressed.
964
965 text += QString(" -- keyboardModifiers: ");
966
967 if(m_keyboardModifiers == Qt::NoModifier)
968 text += QString("%1 - ").arg(qtKeyboardModifierMap[Qt::NoModifier]);
969
970 if(static_cast<int>(m_keyboardModifiers) & Qt::ShiftModifier)
971 text += QString("%1 - ").arg(qtKeyboardModifierMap[Qt::ShiftModifier]);
972
973 if(static_cast<int>(m_keyboardModifiers) & Qt::ControlModifier)
974 text += QString("%1 - ").arg(qtKeyboardModifierMap[Qt::ControlModifier]);
975
976 if(static_cast<int>(m_keyboardModifiers) & Qt::AltModifier)
977 text += QString("%1 - ").arg(qtKeyboardModifierMap[Qt::AltModifier]);
978
979 if(static_cast<int>(m_keyboardModifiers) & Qt::MetaModifier)
980 text += QString("%1 - ").arg(qtKeyboardModifierMap[Qt::MetaModifier]);
981
982 if(static_cast<int>(m_keyboardModifiers) & Qt::KeypadModifier)
983 text += QString("%1 - ").arg(qtKeyboardModifierMap[Qt::KeypadModifier]);
984
985 if(static_cast<int>(m_keyboardModifiers) & Qt::GroupSwitchModifier)
986 text +=
987 QString("%1 - ").arg(qtKeyboardModifierMap[Qt::GroupSwitchModifier]);
988
989 text += QString(" -- lastPressedMouseButton: %1")
991
992 text += QString(" -- lastReleasedMouseButton: %1")
994
995 text += QString(" -- pressedMouseButtons: %1")
997
998 text += QString(" -- mouseButtonsAtMousePress: %1")
1000
1001 text += QString(" -- mouseButtonsAtMouseRelease: %1")
1003
1004 return text;
1005}
1006
1007QString
1009{
1010 QString text;
1011
1012 // Document how the mouse cursor is being dragged.
1014 {
1015 if(static_cast<int>(m_dragDirections) &
1016 static_cast<int>(DragDirections::LEFT_TO_RIGHT))
1017 text += " -- dragging from left to right";
1018 else if(static_cast<int>(m_dragDirections) &
1019 static_cast<int>(DragDirections::RIGHT_TO_LEFT))
1020 text += " -- dragging from right to left";
1021 if(static_cast<int>(m_dragDirections) &
1022 static_cast<int>(DragDirections::TOP_TO_BOTTOM))
1023 text += " -- dragging from top to bottom";
1024 if(static_cast<int>(m_dragDirections) &
1025 static_cast<int>(DragDirections::BOTTOM_TO_TOP))
1026 text += " -- dragging from bottom to top";
1027 }
1028
1029 return text;
1030}
1031
1032void
1034{
1035 // qDebug() << "Now registering the JS constructor for BasePlotContext.";
1036
1037 if(!engine)
1038 {
1039 qFatal() << "Cannot register class: engine is null";
1040 return;
1041 }
1042
1043 // Register the meta object as a constructor
1044 QJSValue jsMetaObject =
1045 engine->newQMetaObject(&BasePlotContext::staticMetaObject);
1046 engine->globalObject().setProperty("BasePlotContext", jsMetaObject);
1047
1048 QJSValue enumObject = engine->newObject();
1049 enumObject.setProperty("NOT_SET",
1050 static_cast<int>(pappso::DragDirections::NOT_SET));
1051 enumObject.setProperty(
1052 "LEFT_TO_RIGHT", static_cast<int>(pappso::DragDirections::LEFT_TO_RIGHT));
1053 enumObject.setProperty(
1054 "RIGHT_TO_LEFT", static_cast<int>(pappso::DragDirections::RIGHT_TO_LEFT));
1055 enumObject.setProperty(
1056 "TOP_TO_BOTTOM", static_cast<int>(pappso::DragDirections::TOP_TO_BOTTOM));
1057 enumObject.setProperty(
1058 "BOTTOM_TO_TOP", static_cast<int>(pappso::DragDirections::BOTTOM_TO_TOP));
1059
1060 // Make it available in the global JS scope
1061 engine->globalObject().setProperty("DragDirections", enumObject);
1062}
1063
1064} // 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