35#include "../../types.h"
36#include "../../utils.h"
38#include "../../pappsoexception.h"
39#include "../../exception/exceptionnotpossible.h"
43 qRegisterMetaType<pappso::BasePlotContext>(
"pappso::BasePlotContext");
45 qRegisterMetaType<pappso::BasePlotContext *>(
"pappso::BasePlotContext *");
53 qFatal(
"Programming error.");
56 m_pen.setStyle(Qt::SolidLine);
57 m_pen.setBrush(Qt::black);
77 qFatal(
"Programming error.");
112 const QString &x_axis_label,
113 const QString &y_axis_label)
114 : QCustomPlot(parent), m_axisLabelX(x_axis_label), m_axisLabelY(y_axis_label)
118 if(parent ==
nullptr)
119 qFatal(
"Programming error.");
122 m_pen.setStyle(Qt::SolidLine);
123 m_pen.setBrush(Qt::black);
126 xAxis->setLabel(x_axis_label);
127 yAxis->setLabel(y_axis_label);
146 qFatal(
"Programming error.");
181 for(
int iter = 0; iter < layerCount(); ++iter)
184 QString(
"Layer index %1: %2\n").arg(iter).arg(layer(iter)->name());
194 if(layerable_p ==
nullptr)
195 qFatal(
"Programming error.");
197 QCPLayer *layer_p = layerable_p->layer();
199 return layer_p->name();
206 if(layerable_p ==
nullptr)
207 qFatal(
"Programming error.");
209 QCPLayer *layer_p = layerable_p->layer();
211 for(
int iter = 0; iter < layerCount(); ++iter)
213 if(layer(iter) == layer_p)
235 pen.setColor(QColor(
"steelblue"));
260 pen.setColor(QColor(
"green"));
271 pen.setColor(QColor(
"red"));
302 pen.setColor(
"steelblue");
368 "plotsLayer", layer(
"background"), QCustomPlot::LayerInsertMode::limAbove);
373 setFocusPolicy(Qt::StrongFocus);
374 setInteractions(QCP::iRangeZoom | QCP::iSelectPlottables | QCP::iMultiSelect);
384 &QCustomPlot::mouseRelease,
392 &QCustomPlot::axisDoubleClick,
416 const QColor &new_color)
418 if(plottable_p ==
nullptr)
419 qFatal(
"Pointer cannot be nullptr.");
424 pen = plottable_p->pen();
425 pen.setColor(new_color);
426 plottable_p->setPen(pen);
435 if(!new_color.isValid())
438 QCPGraph *graph_p = graph(index);
440 if(graph_p ==
nullptr)
441 qFatal(
"Programming error.");
450 if(plottable_p ==
nullptr)
451 qFatal(
"Programming error.");
453 return plottable_p->pen().color();
460 QCPGraph *graph_p = graph(index);
462 if(graph_p ==
nullptr)
463 qFatal(
"Programming error.");
472 xAxis->setLabel(label);
479 yAxis->setLabel(label);
581 qFatal(
"Programming error.");
627 if(event->key() == Qt::Key_Left || event->key() == Qt::Key_Right ||
628 event->key() == Qt::Key_Up || event->key() == Qt::Key_Down)
658 if(event->key() == Qt::Key_Backspace)
667 else if(event->key() == Qt::Key_Space)
671 else if(event->key() == Qt::Key_Delete)
684 int graph_count = plottableCount();
707 QList<QCPGraph *> selected_graph_list;
709 selected_graph_list = selectedGraphs();
711 if(!selected_graph_list.size())
720 for(
int iter = 0; iter < selected_graph_list.size(); ++iter)
727 this, selected_graph_list.at(iter),
m_context);
740 else if(event->key() == Qt::Key_T)
752 else if(event->key() == Qt::Key_Left || event->key() == Qt::Key_Right ||
753 event->key() == Qt::Key_Up || event->key() == Qt::Key_Down)
762 else if(event->key() == Qt::Key_S)
834 int pixel_increment = 0;
839 pixel_increment = 50;
845 if(event->key() == Qt::Key_Left)
847 else if(event->key() == Qt::Key_Right)
849 else if(event->key() == Qt::Key_Up)
851 else if(event->key() == Qt::Key_Down)
868 [[maybe_unused]] QKeyEvent *event)
878 QPointF pixel_coordinates(
882 Qt::MouseButton button = Qt::NoButton;
883 QEvent::Type q_event_type = QEvent::MouseButtonPress;
889 button = Qt::LeftButton;
895 q_event_type = QEvent::MouseButtonPress;
897 q_event_type = QEvent::MouseButtonRelease;
903 button = Qt::RightButton;
909 q_event_type = QEvent::MouseButtonPress;
911 q_event_type = QEvent::MouseButtonRelease;
919 QMouseEvent *mouse_event_p =
920 new QMouseEvent(q_event_type,
922 mapToGlobal(pixel_coordinates.toPoint()),
923 mapToGlobal(pixel_coordinates.toPoint()),
927 Qt::MouseEventSynthesizedByApplication);
929 if(q_event_type == QEvent::MouseButtonPress)
960#if QT_VERSION < 0x060000
961 QPointF mousePoint =
event->localPos();
963 QPointF mousePoint =
event->position();
1080 yAxis->range().upper);
1083 yAxis->range().lower);
1330#if QT_VERSION < 0x060000
1331 QPointF mousePoint =
event->localPos();
1333 QPointF mousePoint =
event->position();
1502 yAxis->range().upper);
1504 yAxis->range().lower);
1659 double x_delta_pixel =
1663 if(x_delta_pixel > 3)
1697 [[maybe_unused]] QCPAxis::SelectablePart part,
1746 QCPLayoutElement *layoutElement = layoutElementAt(mousePoint);
1749 layoutElement ==
dynamic_cast<QCPLayoutElement *
>(axisRect()))
1755 QCPAxis::SelectablePart selectablePart;
1757 selectablePart = xAxis->getPartAt(mousePoint);
1759 if(selectablePart == QCPAxis::spAxisLabel ||
1760 selectablePart == QCPAxis::spAxis ||
1761 selectablePart == QCPAxis::spTickLabels)
1772 QCPLayoutElement *layoutElement = layoutElementAt(mousePoint);
1775 layoutElement ==
dynamic_cast<QCPLayoutElement *
>(axisRect()))
1781 QCPAxis::SelectablePart selectablePart;
1783 selectablePart = yAxis->getPartAt(mousePoint);
1785 if(selectablePart == QCPAxis::spAxisLabel ||
1786 selectablePart == QCPAxis::spAxis ||
1787 selectablePart == QCPAxis::spTickLabels)
1812 double x_delta_pixel =
1816 double y_delta_pixel =
1820 if(x_delta_pixel > y_delta_pixel)
1821 return Qt::Horizontal;
1823 return Qt::Vertical;
1832 QPointF pixels_coordinates(xAxis->coordToPixel(graph_coordinates.x()),
1833 yAxis->coordToPixel(graph_coordinates.y()));
1843 QCursor::setPos(mapToGlobal(pixel_coordinates.toPoint()));
1852 QPointF pixel_coord(xAxis->coordToPixel(graph_coord.x()),
1853 yAxis->coordToPixel(graph_coord.y()));
1866 QPointF pixel_coordinates(
1872 QPointF graph_coordinates(xAxis->pixelToCoord(pixel_coordinates.x()),
1873 yAxis->pixelToCoord(pixel_coordinates.y()));
1875 return graph_coordinates;
1885 QPointF pixel_coord(xAxis->coordToPixel(graph_coord.x()),
1886 yAxis->coordToPixel(graph_coord.y()));
1899 QPointF pixel_coordinates(
1905 QPointF graph_coordinates(xAxis->pixelToCoord(pixel_coordinates.x()),
1906 yAxis->pixelToCoord(pixel_coordinates.y()));
1908 return graph_coordinates;
1919 QCPGraph *graph_p = graph(index);
1921 if(graph_p ==
nullptr)
1922 qFatal(
"Programming error.");
1924 return graph_p->getKeyRange(found_range);
1931 QCPGraph *graph_p = graph(index);
1933 if(graph_p ==
nullptr)
1934 qFatal(
"Programming error.");
1936 return graph_p->getValueRange(found_range);
1943 bool &found_range)
const
1952 found_range =
false;
1954 return QCPRange(0, 1);
1957 if(graphCount() == 1)
1958 return graph()->getKeyRange(found_range);
1960 bool found_at_least_one_range =
false;
1963 QCPRange result_range(QCPRange::minRange + 1, QCPRange::maxRange + 1);
1965 for(
int iter = 0; iter < graphCount(); ++iter)
1967 QCPRange temp_range;
1969 bool found_range_for_iter =
false;
1971 QCPGraph *graph_p = graph(iter);
1976 temp_range = graph_p->getKeyRange(found_range_for_iter);
1978 temp_range = graph_p->getValueRange(found_range_for_iter);
1980 qFatal(
"Cannot reach this point. Programming error.");
1985 if(!found_range_for_iter)
1991 if(!QCPRange::validRange(result_range))
1992 qFatal(
"The obtained range is invalid !");
1995 result_range = temp_range;
1998 found_at_least_one_range =
true;
2005 if(temp_range.lower > result_range.lower)
2006 result_range.lower = temp_range.lower;
2007 if(temp_range.upper < result_range.upper)
2008 result_range.upper = temp_range.upper;
2012 if(temp_range.lower < result_range.lower)
2013 result_range.lower = temp_range.lower;
2014 if(temp_range.upper > result_range.upper)
2015 result_range.upper = temp_range.upper;
2018 qFatal(
"Cannot reach this point. Programming error.");
2026 found_range = found_at_least_one_range;
2028 return result_range;
2072 double xLower = xAxis->range().lower;
2073 double xUpper = xAxis->range().upper;
2077 double yLower = yAxis->range().lower;
2078 double yUpper = yAxis->range().upper;
2141 yAxis->setRange(xAxis->range().lower,
2188 "This function can only be called if the mouse click was on one of the "
2224 QCPRange yAxisRange,
2229 if(
static_cast<int>(axis) &
static_cast<int>(
Axis::x))
2231 xAxis->setRange(xAxisRange.lower, xAxisRange.upper);
2234 if(
static_cast<int>(axis) &
static_cast<int>(
Axis::y))
2236 yAxis->setRange(yAxisRange.lower, yAxisRange.upper);
2253 xAxis->setRange(lower, upper);
2264 yAxis->setRange(lower, upper);
2327 bool for_integration)
2393 QPointF leftmost_point;
2395 qFatal(
"Could not get the left-most point.");
2399 qFatal(
"Could not get width.");
2402 double x_axis_center_position = leftmost_point.x() + width / 2;
2412 int pixels_away_from_line = 15;
2414 QPointF reference_point_for_y_axis_label_position;
2428 pixels_away_from_line *= -1;
2431 reference_point_for_y_axis_label_position))
2432 qFatal(
"Failed to get top most point.");
2437 reference_point_for_y_axis_label_position))
2438 qFatal(
"Failed to get bottom most point.");
2443 double y_axis_pixel_coordinate =
2444 yAxis->coordToPixel(reference_point_for_y_axis_label_position.y());
2448 double y_axis_modified_pixel_coordinate =
2449 y_axis_pixel_coordinate + pixels_away_from_line;
2452 QPointF pixel_coordinates;
2454 pixel_coordinates.setX(x_axis_center_position);
2455 pixel_coordinates.setY(y_axis_modified_pixel_coordinate);
2458 QPointF graph_coordinates(xAxis->pixelToCoord(pixel_coordinates.x()),
2459 yAxis->pixelToCoord(pixel_coordinates.y()));
2466 graph_coordinates.y());
2477 QString label_text = QString(
"full x span %1 -- x drag delta %2")
2478 .arg(width, 0,
'f', decimals)
2508 qFatal(
"Could not get height.");
2525 QPointF bottom_most_point;
2527 qFatal(
"Could not get the bottom-most bottom point.");
2529 double y_axis_center_position = bottom_most_point.y() + height / 2;
2539 int pixels_away_from_line = 15;
2540 double x_axis_coordinate;
2541 double x_axis_pixel_coordinate;
2546 QPointF left_most_point;
2549 qFatal(
"Failed to get left most point.");
2551 x_axis_coordinate = left_most_point.x();
2553 pixels_away_from_line *= -1;
2557 QPointF right_most_point;
2560 qFatal(
"Failed to get right most point.");
2562 x_axis_coordinate = right_most_point.x();
2564 x_axis_pixel_coordinate = xAxis->coordToPixel(x_axis_coordinate);
2566 double x_axis_modified_pixel_coordinate =
2567 x_axis_pixel_coordinate + pixels_away_from_line;
2570 QPointF pixel_coordinates;
2572 pixel_coordinates.setX(x_axis_modified_pixel_coordinate);
2573 pixel_coordinates.setY(y_axis_center_position);
2577 QPointF graph_coordinates(xAxis->pixelToCoord(pixel_coordinates.x()),
2578 yAxis->pixelToCoord(pixel_coordinates.y()));
2581 y_axis_center_position);
2585 QString label_text = QString(
"full y span %1 -- y drag delta %2")
2586 .arg(height, 0,
'f', decimals)
2631 double plotHeight = yAxis->range().upper - yAxis->range().lower;
2636 double heightDiffRatio = (heightDiff / plotHeight) * 100;
2638 if(heightDiffRatio > 10)
2658 double x_range_start =
2660 double x_range_end =
2669 QPointF(x_range_start, y_position));
2694 QPointF(x_range_start, y_position));
2726 QPointF bottom_left_point;
2728 qFatal(
"Failed to get point.");
2733 qFatal(
"Failed to get width.");
2738 qFatal(
"Failed to get height.");
2741 QPointF bottom_right_point(bottom_left_point.x() + width,
2742 bottom_left_point.y());
2745 QPointF top_right_point(bottom_left_point.x() + width,
2746 bottom_left_point.y() + height);
2749 QPointF top_left_point(bottom_left_point.x(), bottom_left_point.y() + height);
2841 qFatal(
"The rhomboid should be horizontal!");
2846 qFatal(
"Failed to getLeftMostTopPoint.");
2849 qFatal(
"Failed to getRightMostTopPoint.");
2873 qFatal(
"Failed to getRightMostBottomPoint.");
2882 qFatal(
"Failed to getLeftMostBottomPoint.");
2891 qFatal(
"Failed to getLeftMostTopPoint.");
2954 qFatal(
"The rhomboid should be vertical!");
2960 qFatal(
"Failed to getLeftMostBottomPoint.");
2985 qFatal(
"Failed to getRightMostBottomPoint.");
2995 qFatal(
"Failed to getRightMostTopPoint.");
3005 qFatal(
"Failed to get the LeftMostTopPoint.");
3100 qFatal(
"Cannot be both the width or height of rhomboid scope be 0.");
3105 bool for_integration)
3160 std::vector<QPointF> points;
3167 qFatal(
"Failed to get LeftMost point.");
3171 qFatal(
"Failed to get RightMost point.");
3179 qFatal(
"Failed to get point.");
3185 qFatal(
"Failed to get width.");
3198 qFatal(
"Failed to get point.");
3204 qFatal(
"Failed to get width.");
3245 int current_selection_polygon =
3250 current_selection_polygon |=
3257 current_selection_polygon |=
3264 current_selection_polygon |=
3271 current_selection_polygon |=
3306 QCustomPlot::setFocus();
3318 if(focusedPlotWidget ==
nullptr)
3320 "baseplotwidget.cpp @ redrawPlotBackground(QWidget *focusedPlotWidget "
3322 "ERROR focusedPlotWidget cannot be nullptr.");
3324 if(
dynamic_cast<QWidget *
>(
this) != focusedPlotWidget)
double m_xRegionRangeStart
Qt::MouseButtons m_mouseButtonsAtMousePress
IntegrationScopeBaseCstSPtr msp_integrationScope
DragDirections recordDragDirections()
Qt::KeyboardModifiers m_keyboardModifiers
void updateIntegrationScope()
Qt::MouseButtons m_lastPressedMouseButton
bool m_isMeasuringDistance
DragDirections m_dragDirections
double m_integrationScopeRhombHeight
QPointF m_lastCursorHoveredPoint
QPointF m_currentDragPoint
void updateIntegrationScopeRect()
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
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...