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