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