35#include "../../core/types.h"
43 qRegisterMetaType<pappso::BasePlotContext>(
"pappso::BasePlotContext");
45 qRegisterMetaType<pappso::BasePlotContext *>(
"pappso::BasePlotContext *");
52 qFatal(
"Programming error.");
55 m_pen.setStyle(Qt::SolidLine);
56 m_pen.setBrush(Qt::black);
76 qFatal(
"Programming error.");
110 const QString &x_axis_label,
111 const QString &y_axis_label)
112 : QCustomPlot(parent), m_axisLabelX(x_axis_label), m_axisLabelY(y_axis_label)
116 if(parent ==
nullptr)
117 qFatal(
"Programming error.");
120 m_pen.setStyle(Qt::SolidLine);
121 m_pen.setBrush(Qt::black);
124 xAxis->setLabel(x_axis_label);
125 yAxis->setLabel(y_axis_label);
144 qFatal(
"Programming error.");
177 for(
int iter = 0; iter < layerCount(); ++iter)
180 QString(
"Layer index %1: %2\n").arg(iter).arg(layer(iter)->name());
189 if(layerable_p ==
nullptr)
190 qFatal(
"Programming error.");
192 QCPLayer *layer_p = layerable_p->layer();
194 return layer_p->name();
200 if(layerable_p ==
nullptr)
201 qFatal(
"Programming error.");
203 QCPLayer *layer_p = layerable_p->layer();
205 for(
int iter = 0; iter < layerCount(); ++iter)
207 if(layer(iter) == layer_p)
229 pen.setColor(QColor(
"steelblue"));
254 pen.setColor(QColor(
"green"));
265 pen.setColor(QColor(
"red"));
296 pen.setColor(
"steelblue");
361 "plotsLayer", layer(
"background"), QCustomPlot::LayerInsertMode::limAbove);
363 addLayer(
"labelsLayer", layer(
"background"), QCustomPlot::LayerInsertMode::limAbove);
368 setFocusPolicy(Qt::StrongFocus);
369 setInteractions(QCP::iRangeZoom | QCP::iSelectPlottables | QCP::iMultiSelect);
379 &QCustomPlot::mouseRelease,
387 &QCustomPlot::axisDoubleClick,
391 connect(
this, &QCustomPlot::beforeReplot,
this, [&]() { emit
beforeReplotSignal(); });
392 connect(
this, &QCustomPlot::afterLayout,
this, [&]() { emit
afterLayoutSignal(); });
393 connect(
this, &QCustomPlot::afterReplot,
this, [&]() { emit
afterReplotSignal(); });
412 const QColor &new_color)
414 if(plottable_p ==
nullptr)
415 qFatal(
"Pointer cannot be nullptr.");
420 pen = plottable_p->pen();
421 pen.setColor(new_color);
422 plottable_p->setPen(pen);
430 if(!new_color.isValid())
433 QCPGraph *graph_p = graph(index);
435 if(graph_p ==
nullptr)
436 qFatal(
"Programming error.");
444 if(plottable_p ==
nullptr)
445 qFatal(
"Programming error.");
447 return plottable_p->pen().color();
453 QCPGraph *graph_p = graph(index);
455 if(graph_p ==
nullptr)
456 qFatal(
"Programming error.");
464 xAxis->setLabel(label);
470 yAxis->setLabel(label);
568 qFatal(
"Programming error.");
626 if(event->key() == Qt::Key_Left || event->key() == Qt::Key_Right ||
627 event->key() == Qt::Key_Up || event->key() == Qt::Key_Down)
666 if(event->key() == Qt::Key_Backspace)
675 else if(event->key() == Qt::Key_Space)
679 else if(event->key() == Qt::Key_Delete)
692 int graph_count = plottableCount();
715 QList<QCPGraph *> selected_graph_list;
717 selected_graph_list = selectedGraphs();
719 if(!selected_graph_list.size())
728 for(
int iter = 0; iter < selected_graph_list.size(); ++iter)
735 this, selected_graph_list.at(iter),
m_context);
748 else if(event->key() == Qt::Key_T)
760 else if(event->key() == Qt::Key_Left || event->key() == Qt::Key_Right ||
761 event->key() == Qt::Key_Up || event->key() == Qt::Key_Down)
770 else if(event->key() == Qt::Key_S)
840 int pixel_increment = 0;
845 pixel_increment = 50;
851 if(event->key() == Qt::Key_Left)
853 else if(event->key() == Qt::Key_Right)
855 else if(event->key() == Qt::Key_Up)
857 else if(event->key() == Qt::Key_Down)
872 [[maybe_unused]] QKeyEvent *event)
881 QPointF pixel_coordinates(
885 Qt::MouseButton button = Qt::NoButton;
886 QEvent::Type q_event_type = QEvent::MouseButtonPress;
892 button = Qt::LeftButton;
898 q_event_type = QEvent::MouseButtonPress;
900 q_event_type = QEvent::MouseButtonRelease;
906 button = Qt::RightButton;
912 q_event_type = QEvent::MouseButtonPress;
914 q_event_type = QEvent::MouseButtonRelease;
922 QMouseEvent *mouse_event_p =
923 new QMouseEvent(q_event_type,
925 mapToGlobal(pixel_coordinates.toPoint()),
926 mapToGlobal(pixel_coordinates.toPoint()),
930 Qt::MouseEventSynthesizedByApplication);
932 if(q_event_type == QEvent::MouseButtonPress)
937 delete mouse_event_p;
964 QPointF mousePoint =
event->position();
1085 yAxis->range().upper);
1088 yAxis->range().lower);
1337 QPointF mousePoint =
event->position();
1505 yAxis->range().upper);
1507 yAxis->range().lower);
1664 double x_delta_pixel =
1668 if(x_delta_pixel > 3)
1700 [[maybe_unused]] QCPAxis::SelectablePart part,
1748 QCPLayoutElement *layoutElement = layoutElementAt(mousePoint);
1751 layoutElement ==
dynamic_cast<QCPLayoutElement *
>(axisRect()))
1757 QCPAxis::SelectablePart selectablePart;
1759 selectablePart = xAxis->getPartAt(mousePoint);
1761 if(selectablePart == QCPAxis::spAxisLabel ||
1762 selectablePart == QCPAxis::spAxis ||
1763 selectablePart == QCPAxis::spTickLabels)
1773 QCPLayoutElement *layoutElement = layoutElementAt(mousePoint);
1776 layoutElement ==
dynamic_cast<QCPLayoutElement *
>(axisRect()))
1782 QCPAxis::SelectablePart selectablePart;
1784 selectablePart = yAxis->getPartAt(mousePoint);
1786 if(selectablePart == QCPAxis::spAxisLabel ||
1787 selectablePart == QCPAxis::spAxis ||
1788 selectablePart == QCPAxis::spTickLabels)
1813 double x_delta_pixel =
1817 double y_delta_pixel =
1821 if(x_delta_pixel > y_delta_pixel)
1822 return Qt::Horizontal;
1824 return Qt::Vertical;
1832 QPointF pixels_coordinates(xAxis->coordToPixel(graph_coordinates.x()),
1833 yAxis->coordToPixel(graph_coordinates.y()));
1842 QCursor::setPos(mapToGlobal(pixel_coordinates.toPoint()));
1850 QPointF pixel_coord(xAxis->coordToPixel(graph_coord.x()),
1851 yAxis->coordToPixel(graph_coord.y()));
1863 QPointF pixel_coordinates(
1869 QPointF graph_coordinates(xAxis->pixelToCoord(pixel_coordinates.x()),
1870 yAxis->pixelToCoord(pixel_coordinates.y()));
1872 return graph_coordinates;
1881 QPointF pixel_coord(xAxis->coordToPixel(graph_coord.x()),
1882 yAxis->coordToPixel(graph_coord.y()));
1894 QPointF pixel_coordinates(
1900 QPointF graph_coordinates(xAxis->pixelToCoord(pixel_coordinates.x()),
1901 yAxis->pixelToCoord(pixel_coordinates.y()));
1903 return graph_coordinates;
1914 QCPGraph *graph_p = graph(index);
1916 if(graph_p ==
nullptr)
1917 qFatal(
"Programming error.");
1920 return graph_p->getKeyRange(found_range);
1925 return graph_p->keyAxis()->range();
1928 qFatal(
"Programming error.");
1935 bool &found_range,
int index,
RangeType range_type,
double &start,
double &stop)
const
1937 QCPRange range =
getRangeX(found_range, index, range_type);
1939 start = range.lower;
1947 std::pair<double, double> &start_stop_pair)
const
1949 QCPRange range =
getRangeX(found_range, index, range_type);
1951 start_stop_pair.first = range.lower;
1952 start_stop_pair.second = range.upper;
1958 QCPGraph *graph_p = graph(index);
1960 if(graph_p ==
nullptr)
1961 qFatal(
"Programming error.");
1964 return graph_p->getValueRange(found_range);
1968 return graph_p->valueAxis()->range();
1971 qFatal(
"Programming error.");
1978 bool &found_range,
int index,
RangeType range_type,
double &start,
double &stop)
const
1980 QCPRange range =
getRangeY(found_range, index, range_type);
1982 start = range.lower;
1990 std::pair<double, double> &start_stop_pair)
const
1992 QCPRange range =
getRangeY(found_range, index, range_type);
1994 start_stop_pair.first = range.lower;
1995 start_stop_pair.second = range.upper;
2001 bool &found_range)
const
2009 found_range =
false;
2011 return QCPRange(0, 1);
2014 if(graphCount() == 1)
2015 return graph()->getKeyRange(found_range);
2017 bool found_at_least_one_range =
false;
2020 QCPRange result_range(QCPRange::minRange + 1, QCPRange::maxRange + 1);
2022 for(
int iter = 0; iter < graphCount(); ++iter)
2024 QCPRange temp_range;
2026 bool found_range_for_iter =
false;
2028 QCPGraph *graph_p = graph(iter);
2033 temp_range = graph_p->getKeyRange(found_range_for_iter);
2035 temp_range = graph_p->getValueRange(found_range_for_iter);
2037 qFatal(
"Cannot reach this point. Programming error.");
2042 if(!found_range_for_iter)
2048 if(!QCPRange::validRange(result_range))
2049 qFatal(
"The obtained range is invalid !");
2052 result_range = temp_range;
2055 found_at_least_one_range =
true;
2062 if(temp_range.lower > result_range.lower)
2063 result_range.lower = temp_range.lower;
2064 if(temp_range.upper < result_range.upper)
2065 result_range.upper = temp_range.upper;
2069 if(temp_range.lower < result_range.lower)
2070 result_range.lower = temp_range.lower;
2071 if(temp_range.upper > result_range.upper)
2072 result_range.upper = temp_range.upper;
2075 qFatal(
"Cannot reach this point. Programming error.");
2083 found_range = found_at_least_one_range;
2085 return result_range;
2124 double xLower = xAxis->range().lower;
2125 double xUpper = xAxis->range().upper;
2129 double yLower = yAxis->range().lower;
2130 double yUpper = yAxis->range().upper;
2191 yAxis->setRange(xAxis->range().lower,
2233 "This function can only be called if the mouse click was on one of the "
2268 QCPRange yAxisRange,
2275 xAxis->setRange(xAxisRange.lower, xAxisRange.upper);
2280 yAxis->setRange(yAxisRange.lower, yAxisRange.upper);
2296 xAxis->setRange(lower, upper);
2306 yAxis->setRange(lower, upper);
2366 bool for_integration)
2431 QPointF leftmost_point;
2433 qFatal(
"Could not get the left-most point.");
2437 qFatal(
"Could not get width.");
2440 double x_axis_center_position = leftmost_point.x() + width / 2;
2450 int pixels_away_from_line = 15;
2452 QPointF reference_point_for_y_axis_label_position;
2466 pixels_away_from_line *= -1;
2469 reference_point_for_y_axis_label_position))
2470 qFatal(
"Failed to get top most point.");
2475 reference_point_for_y_axis_label_position))
2476 qFatal(
"Failed to get bottom most point.");
2481 double y_axis_pixel_coordinate =
2482 yAxis->coordToPixel(reference_point_for_y_axis_label_position.y());
2486 double y_axis_modified_pixel_coordinate =
2487 y_axis_pixel_coordinate + pixels_away_from_line;
2490 QPointF pixel_coordinates;
2492 pixel_coordinates.setX(x_axis_center_position);
2493 pixel_coordinates.setY(y_axis_modified_pixel_coordinate);
2496 QPointF graph_coordinates(xAxis->pixelToCoord(pixel_coordinates.x()),
2497 yAxis->pixelToCoord(pixel_coordinates.y()));
2504 graph_coordinates.y());
2515 QString label_text = QString(
"full x span %1 -- x drag delta %2")
2516 .arg(width, 0,
'f', decimals)
2546 qFatal(
"Could not get height.");
2563 QPointF bottom_most_point;
2565 qFatal(
"Could not get the bottom-most bottom point.");
2567 double y_axis_center_position = bottom_most_point.y() + height / 2;
2577 int pixels_away_from_line = 15;
2578 double x_axis_coordinate;
2579 double x_axis_pixel_coordinate;
2584 QPointF left_most_point;
2587 qFatal(
"Failed to get left most point.");
2589 x_axis_coordinate = left_most_point.x();
2591 pixels_away_from_line *= -1;
2595 QPointF right_most_point;
2598 qFatal(
"Failed to get right most point.");
2600 x_axis_coordinate = right_most_point.x();
2602 x_axis_pixel_coordinate = xAxis->coordToPixel(x_axis_coordinate);
2604 double x_axis_modified_pixel_coordinate =
2605 x_axis_pixel_coordinate + pixels_away_from_line;
2608 QPointF pixel_coordinates;
2610 pixel_coordinates.setX(x_axis_modified_pixel_coordinate);
2611 pixel_coordinates.setY(y_axis_center_position);
2615 QPointF graph_coordinates(xAxis->pixelToCoord(pixel_coordinates.x()),
2616 yAxis->pixelToCoord(pixel_coordinates.y()));
2619 y_axis_center_position);
2623 QString label_text = QString(
"full y span %1 -- y drag delta %2")
2624 .arg(height, 0,
'f', decimals)
2667 double plotHeight = yAxis->range().upper - yAxis->range().lower;
2672 double heightDiffRatio = (heightDiff / plotHeight) * 100;
2674 if(heightDiffRatio > 10)
2693 double x_range_start =
2695 double x_range_end =
2707 QPointF(x_range_start, y_position));
2732 QPointF(x_range_start, y_position));
2763 QPointF bottom_left_point;
2765 qFatal(
"Failed to get point.");
2770 qFatal(
"Failed to get width.");
2775 qFatal(
"Failed to get height.");
2778 QPointF bottom_right_point(bottom_left_point.x() + width,
2779 bottom_left_point.y());
2782 QPointF top_right_point(bottom_left_point.x() + width,
2783 bottom_left_point.y() + height);
2786 QPointF top_left_point(bottom_left_point.x(), bottom_left_point.y() + height);
2877 qFatal(
"The rhomboid should be horizontal!");
2882 qFatal(
"Failed to getLeftMostTopPoint.");
2885 qFatal(
"Failed to getRightMostTopPoint.");
2909 qFatal(
"Failed to getRightMostBottomPoint.");
2918 qFatal(
"Failed to getLeftMostBottomPoint.");
2927 qFatal(
"Failed to getLeftMostTopPoint.");
2989 qFatal(
"The rhomboid should be vertical!");
2995 qFatal(
"Failed to getLeftMostBottomPoint.");
3020 qFatal(
"Failed to getRightMostBottomPoint.");
3030 qFatal(
"Failed to getRightMostTopPoint.");
3040 qFatal(
"Failed to get the LeftMostTopPoint.");
3134 qFatal(
"Cannot be both the width or height of rhomboid scope be 0.");
3139 bool for_integration)
3194 std::vector<QPointF> points;
3207 qFatal(
"Failed to get LeftMost point.");
3211 qFatal(
"Failed to get RightMost point.");
3219 qFatal(
"Failed to get point.");
3225 qFatal(
"Failed to get width.");
3238 qFatal(
"Failed to get point.");
3244 qFatal(
"Failed to get width.");
3283 int current_selection_polygon =
3288 current_selection_polygon |=
3295 current_selection_polygon |=
3302 current_selection_polygon |=
3309 current_selection_polygon |=
3342 QCustomPlot::setFocus();
3353 if(focusedPlotWidget ==
nullptr)
3355 "baseplotwidget.cpp @ redrawPlotBackground(QWidget *focusedPlotWidget "
3357 "ERROR focusedPlotWidget cannot be nullptr.");
3359 if(
dynamic_cast<QWidget *
>(
this) != focusedPlotWidget)
3394 int plottable_count = plottableCount();
3396 for(
int iter = 0; iter < plottable_count; ++iter)
3397 if(plottable(iter) == plottable_p)
double m_xRegionRangeStart
Qt::MouseButtons m_mouseButtonsAtMousePress
double m_yRegionRangeStop
DragDirections recordDragDirections()
Qt::KeyboardModifiers m_keyboardModifiers
double m_xRegionRangeStop
void updateIntegrationScope()
Qt::MouseButtons m_lastPressedMouseButton
QSet< int > m_releasedKeyCodes
bool m_isMeasuringDistance
DragDirections m_dragDirections
double m_integrationScopeRhombHeight
QPointF m_lastCursorHoveredPoint
QPointF m_currentDragPoint
QString m_releasedKeyText
QSet< int > m_pressedKeyCodes
void updateIntegrationScopeRect()
IntegrationScopeBase * mpa_integrationScope
double m_yRegionRangeStart
void updateIntegrationScopeRhomb()
bool m_isRightPseudoButtonKeyPressed
Qt::MouseButtons m_pressedMouseButtons
Qt::MouseButtons m_mouseButtonsAtMouseRelease
bool m_isLeftPseudoButtonKeyPressed
double m_integrationScopeRhombWidth
Qt::MouseButtons m_lastReleasedMouseButton
virtual IntegrationScopeFeatures getBottomMostPoint(QPointF &point) const
virtual IntegrationScopeFeatures getWidth(double &width) const
virtual IntegrationScopeFeatures getLeftMostPoint(QPointF &point) const
virtual IntegrationScopeFeatures getHeight(double &height) const
virtual IntegrationScopeFeatures getRightMostTopPoint(QPointF &point) const
virtual IntegrationScopeFeatures getRightMostPoint(QPointF &point) const
virtual IntegrationScopeFeatures getTopMostPoint(QPointF &point) const
virtual bool getPoints(std::vector< QPointF > &points) const
virtual IntegrationScopeFeatures getRightMostBottomPoint(QPointF &point) const
virtual IntegrationScopeFeatures getLeftMostBottomPoint(QPointF &point) const
virtual bool getPoint(QPointF &point) const
virtual IntegrationScopeFeatures getLeftMostTopPoint(QPointF &point) const
static int zeroDecimalsInValue(pappso_double value)
0.11 would return 0 (no empty decimal) 2.001 would return 2 1000.0001254 would return 3
tries to keep as much as possible monoisotopes, removing any possible C13 peaks and changes multichar...