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.");
620 if(event->key() == Qt::Key_Left || event->key() == Qt::Key_Right ||
621 event->key() == Qt::Key_Up || event->key() == Qt::Key_Down)
655 if(event->key() == Qt::Key_Backspace)
664 else if(event->key() == Qt::Key_Space)
668 else if(event->key() == Qt::Key_Delete)
681 int graph_count = plottableCount();
704 QList<QCPGraph *> selected_graph_list;
706 selected_graph_list = selectedGraphs();
708 if(!selected_graph_list.size())
717 for(
int iter = 0; iter < selected_graph_list.size(); ++iter)
724 this, selected_graph_list.at(iter),
m_context);
737 else if(event->key() == Qt::Key_T)
749 else if(event->key() == Qt::Key_Left || event->key() == Qt::Key_Right ||
750 event->key() == Qt::Key_Up || event->key() == Qt::Key_Down)
759 else if(event->key() == Qt::Key_S)
829 int pixel_increment = 0;
834 pixel_increment = 50;
840 if(event->key() == Qt::Key_Left)
842 else if(event->key() == Qt::Key_Right)
844 else if(event->key() == Qt::Key_Up)
846 else if(event->key() == Qt::Key_Down)
861 [[maybe_unused]] QKeyEvent *event)
870 QPointF pixel_coordinates(
874 Qt::MouseButton button = Qt::NoButton;
875 QEvent::Type q_event_type = QEvent::MouseButtonPress;
881 button = Qt::LeftButton;
887 q_event_type = QEvent::MouseButtonPress;
889 q_event_type = QEvent::MouseButtonRelease;
895 button = Qt::RightButton;
901 q_event_type = QEvent::MouseButtonPress;
903 q_event_type = QEvent::MouseButtonRelease;
911 QMouseEvent *mouse_event_p =
912 new QMouseEvent(q_event_type,
914 mapToGlobal(pixel_coordinates.toPoint()),
915 mapToGlobal(pixel_coordinates.toPoint()),
919 Qt::MouseEventSynthesizedByApplication);
921 if(q_event_type == QEvent::MouseButtonPress)
926 delete mouse_event_p;
953 QPointF mousePoint =
event->position();
972 qDebug() <<
"Emitting mouseMoveDraggingCursorSignal";
1074 yAxis->range().upper);
1077 yAxis->range().lower);
1326 QPointF mousePoint =
event->position();
1494 yAxis->range().upper);
1496 yAxis->range().lower);
1653 double x_delta_pixel =
1657 if(x_delta_pixel > 3)
1689 [[maybe_unused]] QCPAxis::SelectablePart part,
1737 QCPLayoutElement *layoutElement = layoutElementAt(mousePoint);
1740 layoutElement ==
dynamic_cast<QCPLayoutElement *
>(axisRect()))
1746 QCPAxis::SelectablePart selectablePart;
1748 selectablePart = xAxis->getPartAt(mousePoint);
1750 if(selectablePart == QCPAxis::spAxisLabel ||
1751 selectablePart == QCPAxis::spAxis ||
1752 selectablePart == QCPAxis::spTickLabels)
1762 QCPLayoutElement *layoutElement = layoutElementAt(mousePoint);
1765 layoutElement ==
dynamic_cast<QCPLayoutElement *
>(axisRect()))
1771 QCPAxis::SelectablePart selectablePart;
1773 selectablePart = yAxis->getPartAt(mousePoint);
1775 if(selectablePart == QCPAxis::spAxisLabel ||
1776 selectablePart == QCPAxis::spAxis ||
1777 selectablePart == QCPAxis::spTickLabels)
1802 double x_delta_pixel =
1806 double y_delta_pixel =
1810 if(x_delta_pixel > y_delta_pixel)
1811 return Qt::Horizontal;
1813 return Qt::Vertical;
1821 QPointF pixels_coordinates(xAxis->coordToPixel(graph_coordinates.x()),
1822 yAxis->coordToPixel(graph_coordinates.y()));
1831 QCursor::setPos(mapToGlobal(pixel_coordinates.toPoint()));
1839 QPointF pixel_coord(xAxis->coordToPixel(graph_coord.x()),
1840 yAxis->coordToPixel(graph_coord.y()));
1852 QPointF pixel_coordinates(
1858 QPointF graph_coordinates(xAxis->pixelToCoord(pixel_coordinates.x()),
1859 yAxis->pixelToCoord(pixel_coordinates.y()));
1861 return graph_coordinates;
1870 QPointF pixel_coord(xAxis->coordToPixel(graph_coord.x()),
1871 yAxis->coordToPixel(graph_coord.y()));
1883 QPointF pixel_coordinates(
1889 QPointF graph_coordinates(xAxis->pixelToCoord(pixel_coordinates.x()),
1890 yAxis->pixelToCoord(pixel_coordinates.y()));
1892 return graph_coordinates;
1903 QCPGraph *graph_p = graph(index);
1905 if(graph_p ==
nullptr)
1906 qFatal(
"Programming error.");
1908 return graph_p->getKeyRange(found_range);
1914 QCPGraph *graph_p = graph(index);
1916 if(graph_p ==
nullptr)
1917 qFatal(
"Programming error.");
1919 return graph_p->getValueRange(found_range);
1925 bool &found_range)
const
1934 found_range =
false;
1936 return QCPRange(0, 1);
1939 if(graphCount() == 1)
1940 return graph()->getKeyRange(found_range);
1942 bool found_at_least_one_range =
false;
1945 QCPRange result_range(QCPRange::minRange + 1, QCPRange::maxRange + 1);
1947 for(
int iter = 0; iter < graphCount(); ++iter)
1949 QCPRange temp_range;
1951 bool found_range_for_iter =
false;
1953 QCPGraph *graph_p = graph(iter);
1958 temp_range = graph_p->getKeyRange(found_range_for_iter);
1960 temp_range = graph_p->getValueRange(found_range_for_iter);
1962 qFatal(
"Cannot reach this point. Programming error.");
1967 if(!found_range_for_iter)
1973 if(!QCPRange::validRange(result_range))
1974 qFatal(
"The obtained range is invalid !");
1977 result_range = temp_range;
1980 found_at_least_one_range =
true;
1987 if(temp_range.lower > result_range.lower)
1988 result_range.lower = temp_range.lower;
1989 if(temp_range.upper < result_range.upper)
1990 result_range.upper = temp_range.upper;
1994 if(temp_range.lower < result_range.lower)
1995 result_range.lower = temp_range.lower;
1996 if(temp_range.upper > result_range.upper)
1997 result_range.upper = temp_range.upper;
2000 qFatal(
"Cannot reach this point. Programming error.");
2008 found_range = found_at_least_one_range;
2010 return result_range;
2049 double xLower = xAxis->range().lower;
2050 double xUpper = xAxis->range().upper;
2054 double yLower = yAxis->range().lower;
2055 double yUpper = yAxis->range().upper;
2116 yAxis->setRange(xAxis->range().lower,
2158 "This function can only be called if the mouse click was on one of the "
2193 QCPRange yAxisRange,
2200 xAxis->setRange(xAxisRange.lower, xAxisRange.upper);
2205 yAxis->setRange(yAxisRange.lower, yAxisRange.upper);
2221 xAxis->setRange(lower, upper);
2231 yAxis->setRange(lower, upper);
2291 bool for_integration)
2356 QPointF leftmost_point;
2358 qFatal(
"Could not get the left-most point.");
2362 qFatal(
"Could not get width.");
2365 double x_axis_center_position = leftmost_point.x() + width / 2;
2375 int pixels_away_from_line = 15;
2377 QPointF reference_point_for_y_axis_label_position;
2391 pixels_away_from_line *= -1;
2394 reference_point_for_y_axis_label_position))
2395 qFatal(
"Failed to get top most point.");
2400 reference_point_for_y_axis_label_position))
2401 qFatal(
"Failed to get bottom most point.");
2406 double y_axis_pixel_coordinate =
2407 yAxis->coordToPixel(reference_point_for_y_axis_label_position.y());
2411 double y_axis_modified_pixel_coordinate =
2412 y_axis_pixel_coordinate + pixels_away_from_line;
2415 QPointF pixel_coordinates;
2417 pixel_coordinates.setX(x_axis_center_position);
2418 pixel_coordinates.setY(y_axis_modified_pixel_coordinate);
2421 QPointF graph_coordinates(xAxis->pixelToCoord(pixel_coordinates.x()),
2422 yAxis->pixelToCoord(pixel_coordinates.y()));
2429 graph_coordinates.y());
2440 QString label_text = QString(
"full x span %1 -- x drag delta %2")
2441 .arg(width, 0,
'f', decimals)
2471 qFatal(
"Could not get height.");
2488 QPointF bottom_most_point;
2490 qFatal(
"Could not get the bottom-most bottom point.");
2492 double y_axis_center_position = bottom_most_point.y() + height / 2;
2502 int pixels_away_from_line = 15;
2503 double x_axis_coordinate;
2504 double x_axis_pixel_coordinate;
2509 QPointF left_most_point;
2512 qFatal(
"Failed to get left most point.");
2514 x_axis_coordinate = left_most_point.x();
2516 pixels_away_from_line *= -1;
2520 QPointF right_most_point;
2523 qFatal(
"Failed to get right most point.");
2525 x_axis_coordinate = right_most_point.x();
2527 x_axis_pixel_coordinate = xAxis->coordToPixel(x_axis_coordinate);
2529 double x_axis_modified_pixel_coordinate =
2530 x_axis_pixel_coordinate + pixels_away_from_line;
2533 QPointF pixel_coordinates;
2535 pixel_coordinates.setX(x_axis_modified_pixel_coordinate);
2536 pixel_coordinates.setY(y_axis_center_position);
2540 QPointF graph_coordinates(xAxis->pixelToCoord(pixel_coordinates.x()),
2541 yAxis->pixelToCoord(pixel_coordinates.y()));
2544 y_axis_center_position);
2548 QString label_text = QString(
"full y span %1 -- y drag delta %2")
2549 .arg(height, 0,
'f', decimals)
2592 double plotHeight = yAxis->range().upper - yAxis->range().lower;
2597 double heightDiffRatio = (heightDiff / plotHeight) * 100;
2599 if(heightDiffRatio > 10)
2618 double x_range_start =
2620 double x_range_end =
2632 QPointF(x_range_start, y_position));
2657 QPointF(x_range_start, y_position));
2688 QPointF bottom_left_point;
2690 qFatal(
"Failed to get point.");
2695 qFatal(
"Failed to get width.");
2700 qFatal(
"Failed to get height.");
2703 QPointF bottom_right_point(bottom_left_point.x() + width,
2704 bottom_left_point.y());
2707 QPointF top_right_point(bottom_left_point.x() + width,
2708 bottom_left_point.y() + height);
2711 QPointF top_left_point(bottom_left_point.x(), bottom_left_point.y() + height);
2802 qFatal(
"The rhomboid should be horizontal!");
2807 qFatal(
"Failed to getLeftMostTopPoint.");
2810 qFatal(
"Failed to getRightMostTopPoint.");
2834 qFatal(
"Failed to getRightMostBottomPoint.");
2843 qFatal(
"Failed to getLeftMostBottomPoint.");
2852 qFatal(
"Failed to getLeftMostTopPoint.");
2914 qFatal(
"The rhomboid should be vertical!");
2920 qFatal(
"Failed to getLeftMostBottomPoint.");
2945 qFatal(
"Failed to getRightMostBottomPoint.");
2955 qFatal(
"Failed to getRightMostTopPoint.");
2965 qFatal(
"Failed to get the LeftMostTopPoint.");
3059 qFatal(
"Cannot be both the width or height of rhomboid scope be 0.");
3064 bool for_integration)
3119 std::vector<QPointF> points;
3132 qFatal(
"Failed to get LeftMost point.");
3136 qFatal(
"Failed to get RightMost point.");
3144 qFatal(
"Failed to get point.");
3150 qFatal(
"Failed to get width.");
3163 qFatal(
"Failed to get point.");
3169 qFatal(
"Failed to get width.");
3209 int current_selection_polygon =
3214 current_selection_polygon |=
3221 current_selection_polygon |=
3228 current_selection_polygon |=
3235 current_selection_polygon |=
3268 QCustomPlot::setFocus();
3279 if(focusedPlotWidget ==
nullptr)
3281 "baseplotwidget.cpp @ redrawPlotBackground(QWidget *focusedPlotWidget "
3283 "ERROR focusedPlotWidget cannot be nullptr.");
3285 if(
dynamic_cast<QWidget *
>(
this) != focusedPlotWidget)
double m_xRegionRangeStart
Qt::MouseButtons m_mouseButtonsAtMousePress
double m_yRegionRangeStop
IntegrationScopeBaseCstSPtr msp_integrationScope
DragDirections recordDragDirections()
Qt::KeyboardModifiers m_keyboardModifiers
double m_xRegionRangeStop
void updateIntegrationScope()
Qt::MouseButtons m_lastPressedMouseButton
bool m_isMeasuringDistance
DragDirections m_dragDirections
double m_integrationScopeRhombHeight
QPointF m_lastCursorHoveredPoint
QPointF m_currentDragPoint
QString m_releasedKeyText
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...