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);
1328#if QT_VERSION < 0x060000
1329 QPointF mousePoint =
event->localPos();
1331 QPointF mousePoint =
event->position();
1495 yAxis->range().upper);
1497 yAxis->range().lower);
1646 double x_delta_pixel =
1650 if(x_delta_pixel > 3)
1681 [[maybe_unused]] QCPAxis::SelectablePart part,
1730 QCPLayoutElement *layoutElement = layoutElementAt(mousePoint);
1733 layoutElement ==
dynamic_cast<QCPLayoutElement *
>(axisRect()))
1739 QCPAxis::SelectablePart selectablePart;
1741 selectablePart = xAxis->getPartAt(mousePoint);
1743 if(selectablePart == QCPAxis::spAxisLabel ||
1744 selectablePart == QCPAxis::spAxis ||
1745 selectablePart == QCPAxis::spTickLabels)
1756 QCPLayoutElement *layoutElement = layoutElementAt(mousePoint);
1759 layoutElement ==
dynamic_cast<QCPLayoutElement *
>(axisRect()))
1765 QCPAxis::SelectablePart selectablePart;
1767 selectablePart = yAxis->getPartAt(mousePoint);
1769 if(selectablePart == QCPAxis::spAxisLabel ||
1770 selectablePart == QCPAxis::spAxis ||
1771 selectablePart == QCPAxis::spTickLabels)
1796 double x_delta_pixel =
1800 double y_delta_pixel =
1804 if(x_delta_pixel > y_delta_pixel)
1805 return Qt::Horizontal;
1807 return Qt::Vertical;
1816 QPointF pixels_coordinates(xAxis->coordToPixel(graph_coordinates.x()),
1817 yAxis->coordToPixel(graph_coordinates.y()));
1827 QCursor::setPos(mapToGlobal(pixel_coordinates.toPoint()));
1836 QPointF pixel_coord(xAxis->coordToPixel(graph_coord.x()),
1837 yAxis->coordToPixel(graph_coord.y()));
1850 QPointF pixel_coordinates(
1856 QPointF graph_coordinates(xAxis->pixelToCoord(pixel_coordinates.x()),
1857 yAxis->pixelToCoord(pixel_coordinates.y()));
1859 return graph_coordinates;
1869 QPointF pixel_coord(xAxis->coordToPixel(graph_coord.x()),
1870 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);
1915 QCPGraph *graph_p = graph(index);
1917 if(graph_p ==
nullptr)
1918 qFatal(
"Programming error.");
1920 return graph_p->getValueRange(found_range);
1927 bool &found_range)
const
1936 found_range =
false;
1938 return QCPRange(0, 1);
1941 if(graphCount() == 1)
1942 return graph()->getKeyRange(found_range);
1944 bool found_at_least_one_range =
false;
1947 QCPRange result_range(QCPRange::minRange + 1, QCPRange::maxRange + 1);
1949 for(
int iter = 0; iter < graphCount(); ++iter)
1951 QCPRange temp_range;
1953 bool found_range_for_iter =
false;
1955 QCPGraph *graph_p = graph(iter);
1960 temp_range = graph_p->getKeyRange(found_range_for_iter);
1962 temp_range = graph_p->getValueRange(found_range_for_iter);
1964 qFatal(
"Cannot reach this point. Programming error.");
1969 if(!found_range_for_iter)
1975 if(!QCPRange::validRange(result_range))
1976 qFatal(
"The obtained range is invalid !");
1979 result_range = temp_range;
1982 found_at_least_one_range =
true;
1989 if(temp_range.lower > result_range.lower)
1990 result_range.lower = temp_range.lower;
1991 if(temp_range.upper < result_range.upper)
1992 result_range.upper = temp_range.upper;
1996 if(temp_range.lower < result_range.lower)
1997 result_range.lower = temp_range.lower;
1998 if(temp_range.upper > result_range.upper)
1999 result_range.upper = temp_range.upper;
2002 qFatal(
"Cannot reach this point. Programming error.");
2010 found_range = found_at_least_one_range;
2012 return result_range;
2056 double xLower = xAxis->range().lower;
2057 double xUpper = xAxis->range().upper;
2061 double yLower = yAxis->range().lower;
2062 double yUpper = yAxis->range().upper;
2125 yAxis->setRange(xAxis->range().lower,
2172 "This function can only be called if the mouse click was on one of the "
2208 QCPRange yAxisRange,
2213 if(
static_cast<int>(axis) &
static_cast<int>(
Axis::x))
2215 xAxis->setRange(xAxisRange.lower, xAxisRange.upper);
2218 if(
static_cast<int>(axis) &
static_cast<int>(
Axis::y))
2220 yAxis->setRange(yAxisRange.lower, yAxisRange.upper);
2237 xAxis->setRange(lower, upper);
2248 yAxis->setRange(lower, upper);
2311 bool for_integration)
2377 QPointF leftmost_point;
2379 qFatal(
"Could not get the left-most point.");
2383 qFatal(
"Could not get width.");
2386 double x_axis_center_position = leftmost_point.x() + width / 2;
2396 int pixels_away_from_line = 15;
2398 QPointF reference_point_for_y_axis_label_position;
2412 pixels_away_from_line *= -1;
2415 reference_point_for_y_axis_label_position))
2416 qFatal(
"Failed to get top most point.");
2421 reference_point_for_y_axis_label_position))
2422 qFatal(
"Failed to get bottom most point.");
2427 double y_axis_pixel_coordinate =
2428 yAxis->coordToPixel(reference_point_for_y_axis_label_position.y());
2432 double y_axis_modified_pixel_coordinate =
2433 y_axis_pixel_coordinate + pixels_away_from_line;
2436 QPointF pixel_coordinates;
2438 pixel_coordinates.setX(x_axis_center_position);
2439 pixel_coordinates.setY(y_axis_modified_pixel_coordinate);
2442 QPointF graph_coordinates(xAxis->pixelToCoord(pixel_coordinates.x()),
2443 yAxis->pixelToCoord(pixel_coordinates.y()));
2450 graph_coordinates.y());
2461 QString label_text = QString(
"full x span %1 -- x drag delta %2")
2462 .arg(width, 0,
'f', decimals)
2492 qFatal(
"Could not get height.");
2509 QPointF bottom_most_point;
2511 qFatal(
"Could not get the bottom-most bottom point.");
2513 double y_axis_center_position = bottom_most_point.y() + height / 2;
2523 int pixels_away_from_line = 15;
2524 double x_axis_coordinate;
2525 double x_axis_pixel_coordinate;
2530 QPointF left_most_point;
2533 qFatal(
"Failed to get left most point.");
2535 x_axis_coordinate = left_most_point.x();
2537 pixels_away_from_line *= -1;
2541 QPointF right_most_point;
2544 qFatal(
"Failed to get right most point.");
2546 x_axis_coordinate = right_most_point.x();
2548 x_axis_pixel_coordinate = xAxis->coordToPixel(x_axis_coordinate);
2550 double x_axis_modified_pixel_coordinate =
2551 x_axis_pixel_coordinate + pixels_away_from_line;
2554 QPointF pixel_coordinates;
2556 pixel_coordinates.setX(x_axis_modified_pixel_coordinate);
2557 pixel_coordinates.setY(y_axis_center_position);
2561 QPointF graph_coordinates(xAxis->pixelToCoord(pixel_coordinates.x()),
2562 yAxis->pixelToCoord(pixel_coordinates.y()));
2565 y_axis_center_position);
2569 QString label_text = QString(
"full y span %1 -- y drag delta %2")
2570 .arg(height, 0,
'f', decimals)
2615 double plotHeight = yAxis->range().upper - yAxis->range().lower;
2620 double heightDiffRatio = (heightDiff / plotHeight) * 100;
2622 if(heightDiffRatio > 10)
2642 double x_range_start =
2644 double x_range_end =
2653 QPointF(x_range_start, y_position));
2678 QPointF(x_range_start, y_position));
2710 QPointF bottom_left_point;
2712 qFatal(
"Failed to get point.");
2717 qFatal(
"Failed to get width.");
2722 qFatal(
"Failed to get height.");
2725 QPointF bottom_right_point(bottom_left_point.x() + width,
2726 bottom_left_point.y());
2729 QPointF top_right_point(bottom_left_point.x() + width,
2730 bottom_left_point.y() + height);
2733 QPointF top_left_point(bottom_left_point.x(), bottom_left_point.y() + height);
2825 qFatal(
"The rhomboid should be horizontal!");
2830 qFatal(
"Failed to getLeftMostTopPoint.");
2833 qFatal(
"Failed to getRightMostTopPoint.");
2857 qFatal(
"Failed to getRightMostBottomPoint.");
2866 qFatal(
"Failed to getLeftMostBottomPoint.");
2875 qFatal(
"Failed to getLeftMostTopPoint.");
2938 qFatal(
"The rhomboid should be vertical!");
2944 qFatal(
"Failed to getLeftMostBottomPoint.");
2969 qFatal(
"Failed to getRightMostBottomPoint.");
2979 qFatal(
"Failed to getRightMostTopPoint.");
2989 qFatal(
"Failed to get the LeftMostTopPoint.");
3084 qFatal(
"Cannot be both the width or height of rhomboid scope be 0.");
3089 bool for_integration)
3144 std::vector<QPointF> points;
3151 qFatal(
"Failed to get LeftMost point.");
3155 qFatal(
"Failed to get RightMost point.");
3163 qFatal(
"Failed to get point.");
3169 qFatal(
"Failed to get width.");
3182 qFatal(
"Failed to get point.");
3188 qFatal(
"Failed to get width.");
3229 int current_selection_polygon =
3234 current_selection_polygon |=
3241 current_selection_polygon |=
3248 current_selection_polygon |=
3255 current_selection_polygon |=
3290 QCustomPlot::setFocus();
3302 if(focusedPlotWidget ==
nullptr)
3304 "baseplotwidget.cpp @ redrawPlotBackground(QWidget *focusedPlotWidget "
3306 "ERROR focusedPlotWidget cannot be nullptr.");
3308 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...