35#include "../../core/types.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)
183 text += QString(
"Layer index %1: %2\n").arg(iter).arg(layer(iter)->name());
193 if(layerable_p ==
nullptr)
194 qFatal(
"Programming error.");
196 QCPLayer *layer_p = layerable_p->layer();
198 return layer_p->name();
205 if(layerable_p ==
nullptr)
206 qFatal(
"Programming error.");
208 QCPLayer *layer_p = layerable_p->layer();
210 for(
int iter = 0; iter < layerCount(); ++iter)
212 if(layer(iter) == layer_p)
234 pen.setColor(QColor(
"steelblue"));
259 pen.setColor(QColor(
"green"));
270 pen.setColor(QColor(
"red"));
301 pen.setColor(
"steelblue");
366 addLayer(
"plotsLayer", layer(
"background"), QCustomPlot::LayerInsertMode::limAbove);
371 setFocusPolicy(Qt::StrongFocus);
372 setInteractions(QCP::iRangeZoom | QCP::iSelectPlottables | QCP::iMultiSelect);
406 if(plottable_p ==
nullptr)
407 qFatal(
"Pointer cannot be nullptr.");
412 pen = plottable_p->pen();
413 pen.setColor(new_color);
414 plottable_p->setPen(pen);
423 if(!new_color.isValid())
426 QCPGraph *graph_p = graph(index);
428 if(graph_p ==
nullptr)
429 qFatal(
"Programming error.");
438 if(plottable_p ==
nullptr)
439 qFatal(
"Programming error.");
441 return plottable_p->pen().color();
448 QCPGraph *graph_p = graph(index);
450 if(graph_p ==
nullptr)
451 qFatal(
"Programming error.");
460 xAxis->setLabel(label);
467 yAxis->setLabel(label);
569 qFatal(
"Programming error.");
615 if(event->key() == Qt::Key_Left || event->key() == Qt::Key_Right || event->key() == Qt::Key_Up ||
616 event->key() == Qt::Key_Down)
645 if(event->key() == Qt::Key_Backspace)
654 else if(event->key() == Qt::Key_Space)
658 else if(event->key() == Qt::Key_Delete)
671 int graph_count = plottableCount();
694 QList<QCPGraph *> selected_graph_list;
696 selected_graph_list = selectedGraphs();
698 if(!selected_graph_list.size())
707 for(
int iter = 0; iter < selected_graph_list.size(); ++iter)
714 this, selected_graph_list.at(iter),
m_context);
727 else if(event->key() == Qt::Key_T)
739 else if(event->key() == Qt::Key_Left || event->key() == Qt::Key_Right ||
740 event->key() == Qt::Key_Up || event->key() == Qt::Key_Down)
748 else if(event->key() == Qt::Key_S)
820 int pixel_increment = 0;
825 pixel_increment = 50;
831 if(event->key() == Qt::Key_Left)
833 else if(event->key() == Qt::Key_Right)
835 else if(event->key() == Qt::Key_Up)
837 else if(event->key() == Qt::Key_Down)
866 Qt::MouseButton button = Qt::NoButton;
867 QEvent::Type q_event_type = QEvent::MouseButtonPress;
873 button = Qt::LeftButton;
878 q_event_type = QEvent::MouseButtonPress;
880 q_event_type = QEvent::MouseButtonRelease;
886 button = Qt::RightButton;
891 q_event_type = QEvent::MouseButtonPress;
893 q_event_type = QEvent::MouseButtonRelease;
901 QMouseEvent *mouse_event_p =
new QMouseEvent(q_event_type,
903 mapToGlobal(pixel_coordinates.toPoint()),
904 mapToGlobal(pixel_coordinates.toPoint()),
908 Qt::MouseEventSynthesizedByApplication);
910 if(q_event_type == QEvent::MouseButtonPress)
940 QPointF mousePoint =
event->position();
1016 yAxis->range().upper);
1018 yAxis->range().lower);
1081 qDebug() <<
"Not moving the mouse cursor over any of the axes.";
1086 qDebug() <<
"Recording the drag direction(s).";
1115 qDebug() <<
"The left button is dragging.";
1193 qDebug() <<
"The mouse dragging did not originate on an axis.";
1306 QPointF mousePoint =
event->position();
1399 yAxis->range().upper);
1401 yAxis->range().lower);
1629 if(x_delta_pixel > 3)
1662 [[maybe_unused]] QCPAxis::SelectablePart part,
1711 QCPLayoutElement *layoutElement = layoutElementAt(mousePoint);
1713 if(layoutElement && layoutElement ==
dynamic_cast<QCPLayoutElement *
>(axisRect()))
1719 QCPAxis::SelectablePart selectablePart;
1721 selectablePart = xAxis->getPartAt(mousePoint);
1723 if(selectablePart == QCPAxis::spAxisLabel || selectablePart == QCPAxis::spAxis ||
1724 selectablePart == QCPAxis::spTickLabels)
1735 QCPLayoutElement *layoutElement = layoutElementAt(mousePoint);
1737 if(layoutElement && layoutElement ==
dynamic_cast<QCPLayoutElement *
>(axisRect()))
1743 QCPAxis::SelectablePart selectablePart;
1745 selectablePart = yAxis->getPartAt(mousePoint);
1747 if(selectablePart == QCPAxis::spAxisLabel || selectablePart == QCPAxis::spAxis ||
1748 selectablePart == QCPAxis::spTickLabels)
1779 if(x_delta_pixel > y_delta_pixel)
1780 return Qt::Horizontal;
1782 return Qt::Vertical;
1791 QPointF pixels_coordinates(xAxis->coordToPixel(graph_coordinates.x()),
1792 yAxis->coordToPixel(graph_coordinates.y()));
1802 QCursor::setPos(mapToGlobal(pixel_coordinates.toPoint()));
1811 QPointF pixel_coord(xAxis->coordToPixel(graph_coord.x()), yAxis->coordToPixel(graph_coord.y()));
1830 QPointF graph_coordinates(xAxis->pixelToCoord(pixel_coordinates.x()),
1831 yAxis->pixelToCoord(pixel_coordinates.y()));
1833 return graph_coordinates;
1843 QPointF pixel_coord(xAxis->coordToPixel(graph_coord.x()), yAxis->coordToPixel(graph_coord.y()));
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);
1888 QCPGraph *graph_p = graph(index);
1890 if(graph_p ==
nullptr)
1891 qFatal(
"Programming error.");
1893 return graph_p->getValueRange(found_range);
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;
2027 double xLower = xAxis->range().lower;
2028 double xUpper = xAxis->range().upper;
2032 double yLower = yAxis->range().lower;
2033 double yUpper = yAxis->range().upper;
2095 yAxis->setRange(xAxis->range().lower,
2139 "This function can only be called if the mouse click was on one of the "
2180 xAxis->setRange(xAxisRange.lower, xAxisRange.upper);
2185 yAxis->setRange(yAxisRange.lower, yAxisRange.upper);
2202 xAxis->setRange(lower, upper);
2213 yAxis->setRange(lower, upper);
2341 QPointF leftmost_point;
2343 qFatal(
"Could not get the left-most point.");
2347 qFatal(
"Could not get width.");
2350 double x_axis_center_position = leftmost_point.x() + width / 2;
2360 int pixels_away_from_line = 15;
2362 QPointF reference_point_for_y_axis_label_position;
2375 pixels_away_from_line *= -1;
2378 reference_point_for_y_axis_label_position))
2379 qFatal(
"Failed to get top most point.");
2384 reference_point_for_y_axis_label_position))
2385 qFatal(
"Failed to get bottom most point.");
2390 double y_axis_pixel_coordinate =
2391 yAxis->coordToPixel(reference_point_for_y_axis_label_position.y());
2395 double y_axis_modified_pixel_coordinate = y_axis_pixel_coordinate + pixels_away_from_line;
2398 QPointF pixel_coordinates;
2400 pixel_coordinates.setX(x_axis_center_position);
2401 pixel_coordinates.setY(y_axis_modified_pixel_coordinate);
2404 QPointF graph_coordinates(xAxis->pixelToCoord(pixel_coordinates.x()),
2405 yAxis->pixelToCoord(pixel_coordinates.y()));
2411 mp_xDeltaTextItem->position->setCoords(x_axis_center_position, graph_coordinates.y());
2422 QString label_text = QString(
"full x span %1 -- x drag delta %2")
2423 .arg(width, 0,
'f', decimals)
2453 qFatal(
"Could not get height.");
2470 QPointF bottom_most_point;
2472 qFatal(
"Could not get the bottom-most bottom point.");
2474 double y_axis_center_position = bottom_most_point.y() + height / 2;
2484 int pixels_away_from_line = 15;
2485 double x_axis_coordinate;
2486 double x_axis_pixel_coordinate;
2490 QPointF left_most_point;
2493 qFatal(
"Failed to get left most point.");
2495 x_axis_coordinate = left_most_point.x();
2497 pixels_away_from_line *= -1;
2501 QPointF right_most_point;
2504 qFatal(
"Failed to get right most point.");
2506 x_axis_coordinate = right_most_point.x();
2508 x_axis_pixel_coordinate = xAxis->coordToPixel(x_axis_coordinate);
2510 double x_axis_modified_pixel_coordinate = x_axis_pixel_coordinate + pixels_away_from_line;
2513 QPointF pixel_coordinates;
2515 pixel_coordinates.setX(x_axis_modified_pixel_coordinate);
2516 pixel_coordinates.setY(y_axis_center_position);
2520 QPointF graph_coordinates(xAxis->pixelToCoord(pixel_coordinates.x()),
2521 yAxis->pixelToCoord(pixel_coordinates.y()));
2523 mp_yDeltaTextItem->position->setCoords(graph_coordinates.x(), y_axis_center_position);
2527 QString label_text = QString(
"full y span %1 -- y drag delta %2")
2528 .arg(height, 0,
'f', decimals)
2571 double plotHeight = yAxis->range().upper - yAxis->range().lower;
2575 double heightDiffRatio = (heightDiff / plotHeight) * 100;
2577 if(heightDiffRatio > 10)
2663 QPointF bottom_left_point;
2665 qFatal(
"Failed to get point.");
2670 qFatal(
"Failed to get width.");
2675 qFatal(
"Failed to get height.");
2678 QPointF bottom_right_point(bottom_left_point.x() + width, bottom_left_point.y());
2681 QPointF top_right_point(bottom_left_point.x() + width, bottom_left_point.y() + height);
2684 QPointF top_left_point(bottom_left_point.x(), bottom_left_point.y() + height);
2776 qFatal(
"The rhomboid should be horizontal!");
2781 qFatal(
"Failed to getLeftMostTopPoint.");
2784 qFatal(
"Failed to getRightMostTopPoint.");
2808 qFatal(
"Failed to getRightMostBottomPoint.");
2817 qFatal(
"Failed to getLeftMostBottomPoint.");
2826 qFatal(
"Failed to getLeftMostTopPoint.");
2889 qFatal(
"The rhomboid should be vertical!");
2895 qFatal(
"Failed to getLeftMostBottomPoint.");
2920 qFatal(
"Failed to getRightMostBottomPoint.");
2930 qFatal(
"Failed to getRightMostTopPoint.");
2940 qFatal(
"Failed to get the LeftMostTopPoint.");
3035 qFatal(
"Cannot be both the width or height of rhomboid scope be 0.");
3093 std::vector<QPointF> points;
3106 qFatal(
"Failed to get LeftMost point.");
3110 qFatal(
"Failed to get RightMost point.");
3118 qFatal(
"Failed to get point.");
3124 qFatal(
"Failed to get width.");
3137 qFatal(
"Failed to get point.");
3143 qFatal(
"Failed to get width.");
3239 QCustomPlot::setFocus();
3251 if(focusedPlotWidget ==
nullptr)
3253 "baseplotwidget.cpp @ redrawPlotBackground(QWidget *focusedPlotWidget "
3255 "ERROR focusedPlotWidget cannot be nullptr.");
3257 if(
dynamic_cast<QWidget *
>(
this) != focusedPlotWidget)
double m_xRegionRangeStart
Qt::MouseButtons m_mouseButtonsAtMousePress
Q_INVOKABLE QString dragDirectionsToString() const
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...