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);
366 setFocusPolicy(Qt::StrongFocus);
367 setInteractions(QCP::iRangeZoom | QCP::iSelectPlottables | QCP::iMultiSelect);
377 &QCustomPlot::mouseRelease,
385 &QCustomPlot::axisDoubleClick,
406 const QColor &new_color)
408 if(plottable_p ==
nullptr)
409 qFatal(
"Pointer cannot be nullptr.");
414 pen = plottable_p->pen();
415 pen.setColor(new_color);
416 plottable_p->setPen(pen);
424 if(!new_color.isValid())
427 QCPGraph *graph_p = graph(index);
429 if(graph_p ==
nullptr)
430 qFatal(
"Programming error.");
438 if(plottable_p ==
nullptr)
439 qFatal(
"Programming error.");
441 return plottable_p->pen().color();
447 QCPGraph *graph_p = graph(index);
449 if(graph_p ==
nullptr)
450 qFatal(
"Programming error.");
458 xAxis->setLabel(label);
464 yAxis->setLabel(label);
562 qFatal(
"Programming error.");
609 if(event->key() == Qt::Key_Left || event->key() == Qt::Key_Right ||
610 event->key() == Qt::Key_Up || event->key() == Qt::Key_Down)
639 if(event->key() == Qt::Key_Backspace)
648 else if(event->key() == Qt::Key_Space)
652 else if(event->key() == Qt::Key_Delete)
665 int graph_count = plottableCount();
688 QList<QCPGraph *> selected_graph_list;
690 selected_graph_list = selectedGraphs();
692 if(!selected_graph_list.size())
701 for(
int iter = 0; iter < selected_graph_list.size(); ++iter)
708 this, selected_graph_list.at(iter),
m_context);
721 else if(event->key() == Qt::Key_T)
733 else if(event->key() == Qt::Key_Left || event->key() == Qt::Key_Right ||
734 event->key() == Qt::Key_Up || event->key() == Qt::Key_Down)
743 else if(event->key() == Qt::Key_S)
813 int pixel_increment = 0;
818 pixel_increment = 50;
824 if(event->key() == Qt::Key_Left)
826 else if(event->key() == Qt::Key_Right)
828 else if(event->key() == Qt::Key_Up)
830 else if(event->key() == Qt::Key_Down)
845 [[maybe_unused]] QKeyEvent *event)
854 QPointF pixel_coordinates(
858 Qt::MouseButton button = Qt::NoButton;
859 QEvent::Type q_event_type = QEvent::MouseButtonPress;
865 button = Qt::LeftButton;
871 q_event_type = QEvent::MouseButtonPress;
873 q_event_type = QEvent::MouseButtonRelease;
879 button = Qt::RightButton;
885 q_event_type = QEvent::MouseButtonPress;
887 q_event_type = QEvent::MouseButtonRelease;
895 QMouseEvent *mouse_event_p =
896 new QMouseEvent(q_event_type,
898 mapToGlobal(pixel_coordinates.toPoint()),
899 mapToGlobal(pixel_coordinates.toPoint()),
903 Qt::MouseEventSynthesizedByApplication);
905 if(q_event_type == QEvent::MouseButtonPress)
910 delete mouse_event_p;
937 QPointF mousePoint =
event->position();
1053 yAxis->range().upper);
1056 yAxis->range().lower);
1302 QPointF mousePoint =
event->position();
1470 yAxis->range().upper);
1472 yAxis->range().lower);
1626 double x_delta_pixel =
1630 if(x_delta_pixel > 3)
1662 [[maybe_unused]] QCPAxis::SelectablePart part,
1710 QCPLayoutElement *layoutElement = layoutElementAt(mousePoint);
1713 layoutElement ==
dynamic_cast<QCPLayoutElement *
>(axisRect()))
1719 QCPAxis::SelectablePart selectablePart;
1721 selectablePart = xAxis->getPartAt(mousePoint);
1723 if(selectablePart == QCPAxis::spAxisLabel ||
1724 selectablePart == QCPAxis::spAxis ||
1725 selectablePart == QCPAxis::spTickLabels)
1735 QCPLayoutElement *layoutElement = layoutElementAt(mousePoint);
1738 layoutElement ==
dynamic_cast<QCPLayoutElement *
>(axisRect()))
1744 QCPAxis::SelectablePart selectablePart;
1746 selectablePart = yAxis->getPartAt(mousePoint);
1748 if(selectablePart == QCPAxis::spAxisLabel ||
1749 selectablePart == QCPAxis::spAxis ||
1750 selectablePart == QCPAxis::spTickLabels)
1775 double x_delta_pixel =
1779 double y_delta_pixel =
1783 if(x_delta_pixel > y_delta_pixel)
1784 return Qt::Horizontal;
1786 return Qt::Vertical;
1794 QPointF pixels_coordinates(xAxis->coordToPixel(graph_coordinates.x()),
1795 yAxis->coordToPixel(graph_coordinates.y()));
1804 QCursor::setPos(mapToGlobal(pixel_coordinates.toPoint()));
1812 QPointF pixel_coord(xAxis->coordToPixel(graph_coord.x()),
1813 yAxis->coordToPixel(graph_coord.y()));
1825 QPointF pixel_coordinates(
1831 QPointF graph_coordinates(xAxis->pixelToCoord(pixel_coordinates.x()),
1832 yAxis->pixelToCoord(pixel_coordinates.y()));
1834 return graph_coordinates;
1843 QPointF pixel_coord(xAxis->coordToPixel(graph_coord.x()),
1844 yAxis->coordToPixel(graph_coord.y()));
1856 QPointF pixel_coordinates(
1862 QPointF graph_coordinates(xAxis->pixelToCoord(pixel_coordinates.x()),
1863 yAxis->pixelToCoord(pixel_coordinates.y()));
1865 return graph_coordinates;
1876 QCPGraph *graph_p = graph(index);
1878 if(graph_p ==
nullptr)
1879 qFatal(
"Programming error.");
1881 return graph_p->getKeyRange(found_range);
1887 QCPGraph *graph_p = graph(index);
1889 if(graph_p ==
nullptr)
1890 qFatal(
"Programming error.");
1892 return graph_p->getValueRange(found_range);
1898 bool &found_range)
const
1907 found_range =
false;
1909 return QCPRange(0, 1);
1912 if(graphCount() == 1)
1913 return graph()->getKeyRange(found_range);
1915 bool found_at_least_one_range =
false;
1918 QCPRange result_range(QCPRange::minRange + 1, QCPRange::maxRange + 1);
1920 for(
int iter = 0; iter < graphCount(); ++iter)
1922 QCPRange temp_range;
1924 bool found_range_for_iter =
false;
1926 QCPGraph *graph_p = graph(iter);
1931 temp_range = graph_p->getKeyRange(found_range_for_iter);
1933 temp_range = graph_p->getValueRange(found_range_for_iter);
1935 qFatal(
"Cannot reach this point. Programming error.");
1940 if(!found_range_for_iter)
1946 if(!QCPRange::validRange(result_range))
1947 qFatal(
"The obtained range is invalid !");
1950 result_range = temp_range;
1953 found_at_least_one_range =
true;
1960 if(temp_range.lower > result_range.lower)
1961 result_range.lower = temp_range.lower;
1962 if(temp_range.upper < result_range.upper)
1963 result_range.upper = temp_range.upper;
1967 if(temp_range.lower < result_range.lower)
1968 result_range.lower = temp_range.lower;
1969 if(temp_range.upper > result_range.upper)
1970 result_range.upper = temp_range.upper;
1973 qFatal(
"Cannot reach this point. Programming error.");
1981 found_range = found_at_least_one_range;
1983 return result_range;
2022 double xLower = xAxis->range().lower;
2023 double xUpper = xAxis->range().upper;
2027 double yLower = yAxis->range().lower;
2028 double yUpper = yAxis->range().upper;
2090 yAxis->setRange(xAxis->range().lower,
2135 "This function can only be called if the mouse click was on one of the "
2170 QCPRange yAxisRange,
2177 xAxis->setRange(xAxisRange.lower, xAxisRange.upper);
2182 yAxis->setRange(yAxisRange.lower, yAxisRange.upper);
2198 xAxis->setRange(lower, upper);
2208 yAxis->setRange(lower, upper);
2268 bool for_integration)
2333 QPointF leftmost_point;
2335 qFatal(
"Could not get the left-most point.");
2339 qFatal(
"Could not get width.");
2342 double x_axis_center_position = leftmost_point.x() + width / 2;
2352 int pixels_away_from_line = 15;
2354 QPointF reference_point_for_y_axis_label_position;
2368 pixels_away_from_line *= -1;
2371 reference_point_for_y_axis_label_position))
2372 qFatal(
"Failed to get top most point.");
2377 reference_point_for_y_axis_label_position))
2378 qFatal(
"Failed to get bottom most point.");
2383 double y_axis_pixel_coordinate =
2384 yAxis->coordToPixel(reference_point_for_y_axis_label_position.y());
2388 double y_axis_modified_pixel_coordinate =
2389 y_axis_pixel_coordinate + pixels_away_from_line;
2392 QPointF pixel_coordinates;
2394 pixel_coordinates.setX(x_axis_center_position);
2395 pixel_coordinates.setY(y_axis_modified_pixel_coordinate);
2398 QPointF graph_coordinates(xAxis->pixelToCoord(pixel_coordinates.x()),
2399 yAxis->pixelToCoord(pixel_coordinates.y()));
2406 graph_coordinates.y());
2417 QString label_text = QString(
"full x span %1 -- x drag delta %2")
2418 .arg(width, 0,
'f', decimals)
2448 qFatal(
"Could not get height.");
2465 QPointF bottom_most_point;
2467 qFatal(
"Could not get the bottom-most bottom point.");
2469 double y_axis_center_position = bottom_most_point.y() + height / 2;
2479 int pixels_away_from_line = 15;
2480 double x_axis_coordinate;
2481 double x_axis_pixel_coordinate;
2486 QPointF left_most_point;
2489 qFatal(
"Failed to get left most point.");
2491 x_axis_coordinate = left_most_point.x();
2493 pixels_away_from_line *= -1;
2497 QPointF right_most_point;
2500 qFatal(
"Failed to get right most point.");
2502 x_axis_coordinate = right_most_point.x();
2504 x_axis_pixel_coordinate = xAxis->coordToPixel(x_axis_coordinate);
2506 double x_axis_modified_pixel_coordinate =
2507 x_axis_pixel_coordinate + pixels_away_from_line;
2510 QPointF pixel_coordinates;
2512 pixel_coordinates.setX(x_axis_modified_pixel_coordinate);
2513 pixel_coordinates.setY(y_axis_center_position);
2517 QPointF graph_coordinates(xAxis->pixelToCoord(pixel_coordinates.x()),
2518 yAxis->pixelToCoord(pixel_coordinates.y()));
2521 y_axis_center_position);
2525 QString label_text = QString(
"full y span %1 -- y drag delta %2")
2526 .arg(height, 0,
'f', decimals)
2569 double plotHeight = yAxis->range().upper - yAxis->range().lower;
2574 double heightDiffRatio = (heightDiff / plotHeight) * 100;
2576 if(heightDiffRatio > 10)
2595 double x_range_start =
2597 double x_range_end =
2609 QPointF(x_range_start, y_position));
2634 QPointF(x_range_start, y_position));
2665 QPointF bottom_left_point;
2667 qFatal(
"Failed to get point.");
2672 qFatal(
"Failed to get width.");
2677 qFatal(
"Failed to get height.");
2680 QPointF bottom_right_point(bottom_left_point.x() + width,
2681 bottom_left_point.y());
2684 QPointF top_right_point(bottom_left_point.x() + width,
2685 bottom_left_point.y() + height);
2688 QPointF top_left_point(bottom_left_point.x(), bottom_left_point.y() + height);
2779 qFatal(
"The rhomboid should be horizontal!");
2784 qFatal(
"Failed to getLeftMostTopPoint.");
2787 qFatal(
"Failed to getRightMostTopPoint.");
2811 qFatal(
"Failed to getRightMostBottomPoint.");
2820 qFatal(
"Failed to getLeftMostBottomPoint.");
2829 qFatal(
"Failed to getLeftMostTopPoint.");
2891 qFatal(
"The rhomboid should be vertical!");
2897 qFatal(
"Failed to getLeftMostBottomPoint.");
2922 qFatal(
"Failed to getRightMostBottomPoint.");
2932 qFatal(
"Failed to getRightMostTopPoint.");
2942 qFatal(
"Failed to get the LeftMostTopPoint.");
3036 qFatal(
"Cannot be both the width or height of rhomboid scope be 0.");
3041 bool for_integration)
3096 std::vector<QPointF> points;
3109 qFatal(
"Failed to get LeftMost point.");
3113 qFatal(
"Failed to get RightMost point.");
3121 qFatal(
"Failed to get point.");
3127 qFatal(
"Failed to get width.");
3140 qFatal(
"Failed to get point.");
3146 qFatal(
"Failed to get width.");
3186 int current_selection_polygon =
3191 current_selection_polygon |=
3198 current_selection_polygon |=
3205 current_selection_polygon |=
3212 current_selection_polygon |=
3245 QCustomPlot::setFocus();
3256 if(focusedPlotWidget ==
nullptr)
3258 "baseplotwidget.cpp @ redrawPlotBackground(QWidget *focusedPlotWidget "
3260 "ERROR focusedPlotWidget cannot be nullptr.");
3262 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...