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