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)
941#if QT_VERSION < 0x060000
942 QPointF mousePoint =
event->localPos();
944 QPointF mousePoint =
event->position();
1020 yAxis->range().upper);
1022 yAxis->range().lower);
1309#if QT_VERSION < 0x060000
1310 QPointF mousePoint =
event->localPos();
1312 QPointF mousePoint =
event->position();
1406 yAxis->range().upper);
1408 yAxis->range().lower);
1636 if(x_delta_pixel > 3)
1669 [[maybe_unused]] QCPAxis::SelectablePart part,
1718 QCPLayoutElement *layoutElement = layoutElementAt(mousePoint);
1720 if(layoutElement && layoutElement ==
dynamic_cast<QCPLayoutElement *
>(axisRect()))
1726 QCPAxis::SelectablePart selectablePart;
1728 selectablePart = xAxis->getPartAt(mousePoint);
1730 if(selectablePart == QCPAxis::spAxisLabel || selectablePart == QCPAxis::spAxis ||
1731 selectablePart == QCPAxis::spTickLabels)
1742 QCPLayoutElement *layoutElement = layoutElementAt(mousePoint);
1744 if(layoutElement && layoutElement ==
dynamic_cast<QCPLayoutElement *
>(axisRect()))
1750 QCPAxis::SelectablePart selectablePart;
1752 selectablePart = yAxis->getPartAt(mousePoint);
1754 if(selectablePart == QCPAxis::spAxisLabel || selectablePart == QCPAxis::spAxis ||
1755 selectablePart == QCPAxis::spTickLabels)
1786 if(x_delta_pixel > y_delta_pixel)
1787 return Qt::Horizontal;
1789 return Qt::Vertical;
1798 QPointF pixels_coordinates(xAxis->coordToPixel(graph_coordinates.x()),
1799 yAxis->coordToPixel(graph_coordinates.y()));
1809 QCursor::setPos(mapToGlobal(pixel_coordinates.toPoint()));
1818 QPointF pixel_coord(xAxis->coordToPixel(graph_coord.x()), yAxis->coordToPixel(graph_coord.y()));
1837 QPointF graph_coordinates(xAxis->pixelToCoord(pixel_coordinates.x()),
1838 yAxis->pixelToCoord(pixel_coordinates.y()));
1840 return graph_coordinates;
1850 QPointF pixel_coord(xAxis->coordToPixel(graph_coord.x()), yAxis->coordToPixel(graph_coord.y()));
1869 QPointF graph_coordinates(xAxis->pixelToCoord(pixel_coordinates.x()),
1870 yAxis->pixelToCoord(pixel_coordinates.y()));
1872 return graph_coordinates;
1883 QCPGraph *graph_p = graph(index);
1885 if(graph_p ==
nullptr)
1886 qFatal(
"Programming error.");
1888 return graph_p->getKeyRange(found_range);
1895 QCPGraph *graph_p = graph(index);
1897 if(graph_p ==
nullptr)
1898 qFatal(
"Programming error.");
1900 return graph_p->getValueRange(found_range);
1914 found_range =
false;
1916 return QCPRange(0, 1);
1919 if(graphCount() == 1)
1920 return graph()->getKeyRange(found_range);
1922 bool found_at_least_one_range =
false;
1925 QCPRange result_range(QCPRange::minRange + 1, QCPRange::maxRange + 1);
1927 for(
int iter = 0; iter < graphCount(); ++iter)
1929 QCPRange temp_range;
1931 bool found_range_for_iter =
false;
1933 QCPGraph *graph_p = graph(iter);
1938 temp_range = graph_p->getKeyRange(found_range_for_iter);
1940 temp_range = graph_p->getValueRange(found_range_for_iter);
1942 qFatal(
"Cannot reach this point. Programming error.");
1947 if(!found_range_for_iter)
1953 if(!QCPRange::validRange(result_range))
1954 qFatal(
"The obtained range is invalid !");
1957 result_range = temp_range;
1960 found_at_least_one_range =
true;
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;
1974 if(temp_range.lower < result_range.lower)
1975 result_range.lower = temp_range.lower;
1976 if(temp_range.upper > result_range.upper)
1977 result_range.upper = temp_range.upper;
1980 qFatal(
"Cannot reach this point. Programming error.");
1988 found_range = found_at_least_one_range;
1990 return result_range;
2034 double xLower = xAxis->range().lower;
2035 double xUpper = xAxis->range().upper;
2039 double yLower = yAxis->range().lower;
2040 double yUpper = yAxis->range().upper;
2102 yAxis->setRange(xAxis->range().lower,
2146 "This function can only be called if the mouse click was on one of the "
2187 xAxis->setRange(xAxisRange.lower, xAxisRange.upper);
2192 yAxis->setRange(yAxisRange.lower, yAxisRange.upper);
2209 xAxis->setRange(lower, upper);
2220 yAxis->setRange(lower, upper);
2348 QPointF leftmost_point;
2350 qFatal(
"Could not get the left-most point.");
2354 qFatal(
"Could not get width.");
2357 double x_axis_center_position = leftmost_point.x() + width / 2;
2367 int pixels_away_from_line = 15;
2369 QPointF reference_point_for_y_axis_label_position;
2382 pixels_away_from_line *= -1;
2385 reference_point_for_y_axis_label_position))
2386 qFatal(
"Failed to get top most point.");
2391 reference_point_for_y_axis_label_position))
2392 qFatal(
"Failed to get bottom most point.");
2397 double y_axis_pixel_coordinate =
2398 yAxis->coordToPixel(reference_point_for_y_axis_label_position.y());
2402 double y_axis_modified_pixel_coordinate = y_axis_pixel_coordinate + pixels_away_from_line;
2405 QPointF pixel_coordinates;
2407 pixel_coordinates.setX(x_axis_center_position);
2408 pixel_coordinates.setY(y_axis_modified_pixel_coordinate);
2411 QPointF graph_coordinates(xAxis->pixelToCoord(pixel_coordinates.x()),
2412 yAxis->pixelToCoord(pixel_coordinates.y()));
2418 mp_xDeltaTextItem->position->setCoords(x_axis_center_position, graph_coordinates.y());
2429 QString label_text = QString(
"full x span %1 -- x drag delta %2")
2430 .arg(width, 0,
'f', decimals)
2460 qFatal(
"Could not get height.");
2477 QPointF bottom_most_point;
2479 qFatal(
"Could not get the bottom-most bottom point.");
2481 double y_axis_center_position = bottom_most_point.y() + height / 2;
2491 int pixels_away_from_line = 15;
2492 double x_axis_coordinate;
2493 double x_axis_pixel_coordinate;
2497 QPointF left_most_point;
2500 qFatal(
"Failed to get left most point.");
2502 x_axis_coordinate = left_most_point.x();
2504 pixels_away_from_line *= -1;
2508 QPointF right_most_point;
2511 qFatal(
"Failed to get right most point.");
2513 x_axis_coordinate = right_most_point.x();
2515 x_axis_pixel_coordinate = xAxis->coordToPixel(x_axis_coordinate);
2517 double x_axis_modified_pixel_coordinate = x_axis_pixel_coordinate + pixels_away_from_line;
2520 QPointF pixel_coordinates;
2522 pixel_coordinates.setX(x_axis_modified_pixel_coordinate);
2523 pixel_coordinates.setY(y_axis_center_position);
2527 QPointF graph_coordinates(xAxis->pixelToCoord(pixel_coordinates.x()),
2528 yAxis->pixelToCoord(pixel_coordinates.y()));
2530 mp_yDeltaTextItem->position->setCoords(graph_coordinates.x(), y_axis_center_position);
2534 QString label_text = QString(
"full y span %1 -- y drag delta %2")
2535 .arg(height, 0,
'f', decimals)
2578 double plotHeight = yAxis->range().upper - yAxis->range().lower;
2582 double heightDiffRatio = (heightDiff / plotHeight) * 100;
2584 if(heightDiffRatio > 10)
2670 QPointF bottom_left_point;
2672 qFatal(
"Failed to get point.");
2677 qFatal(
"Failed to get width.");
2682 qFatal(
"Failed to get height.");
2685 QPointF bottom_right_point(bottom_left_point.x() + width, bottom_left_point.y());
2688 QPointF top_right_point(bottom_left_point.x() + width, bottom_left_point.y() + height);
2691 QPointF top_left_point(bottom_left_point.x(), bottom_left_point.y() + height);
2783 qFatal(
"The rhomboid should be horizontal!");
2788 qFatal(
"Failed to getLeftMostTopPoint.");
2791 qFatal(
"Failed to getRightMostTopPoint.");
2815 qFatal(
"Failed to getRightMostBottomPoint.");
2824 qFatal(
"Failed to getLeftMostBottomPoint.");
2833 qFatal(
"Failed to getLeftMostTopPoint.");
2896 qFatal(
"The rhomboid should be vertical!");
2902 qFatal(
"Failed to getLeftMostBottomPoint.");
2927 qFatal(
"Failed to getRightMostBottomPoint.");
2937 qFatal(
"Failed to getRightMostTopPoint.");
2947 qFatal(
"Failed to get the LeftMostTopPoint.");
3042 qFatal(
"Cannot be both the width or height of rhomboid scope be 0.");
3100 std::vector<QPointF> points;
3107 qFatal(
"Failed to get LeftMost point.");
3111 qFatal(
"Failed to get RightMost point.");
3119 qFatal(
"Failed to get point.");
3125 qFatal(
"Failed to get width.");
3138 qFatal(
"Failed to get point.");
3144 qFatal(
"Failed to get width.");
3240 QCustomPlot::setFocus();
3252 if(focusedPlotWidget ==
nullptr)
3254 "baseplotwidget.cpp @ redrawPlotBackground(QWidget *focusedPlotWidget "
3256 "ERROR focusedPlotWidget cannot be nullptr.");
3258 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...