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)
236 pen.setColor(QColor(
"steelblue"));
261 pen.setColor(QColor(
"green"));
272 pen.setColor(QColor(
"red"));
303 pen.setColor(
"steelblue");
369 "plotsLayer", layer(
"background"), QCustomPlot::LayerInsertMode::limAbove);
374 setFocusPolicy(Qt::StrongFocus);
375 setInteractions(QCP::iRangeZoom | QCP::iSelectPlottables | QCP::iMultiSelect);
385 &QCustomPlot::mouseRelease,
393 &QCustomPlot::axisDoubleClick,
417 const QColor &new_color)
419 if(plottable_p ==
nullptr)
420 qFatal(
"Pointer cannot be nullptr.");
425 pen = plottable_p->pen();
426 pen.setColor(new_color);
427 plottable_p->setPen(pen);
436 if(!new_color.isValid())
439 QCPGraph *graph_p = graph(index);
441 if(graph_p ==
nullptr)
442 qFatal(
"Programming error.");
451 if(plottable_p ==
nullptr)
452 qFatal(
"Programming error.");
454 return plottable_p->pen().color();
461 QCPGraph *graph_p = graph(index);
463 if(graph_p ==
nullptr)
464 qFatal(
"Programming error.");
473 xAxis->setLabel(label);
480 yAxis->setLabel(label);
582 qFatal(
"Programming error.");
628 if(event->key() == Qt::Key_Left || event->key() == Qt::Key_Right ||
629 event->key() == Qt::Key_Up || event->key() == Qt::Key_Down)
659 if(event->key() == Qt::Key_Backspace)
668 else if(event->key() == Qt::Key_Space)
672 else if(event->key() == Qt::Key_Delete)
685 int graph_count = plottableCount();
708 QList<QCPGraph *> selected_graph_list;
710 selected_graph_list = selectedGraphs();
712 if(!selected_graph_list.size())
721 for(
int iter = 0; iter < selected_graph_list.size(); ++iter)
728 this, selected_graph_list.at(iter),
m_context);
741 else if(event->key() == Qt::Key_T)
753 else if(event->key() == Qt::Key_Left || event->key() == Qt::Key_Right ||
754 event->key() == Qt::Key_Up || event->key() == Qt::Key_Down)
763 else if(event->key() == Qt::Key_S)
807 int pixel_increment = 0;
812 pixel_increment = 50;
818 if(event->key() == Qt::Key_Left)
820 else if(event->key() == Qt::Key_Right)
822 else if(event->key() == Qt::Key_Up)
824 else if(event->key() == Qt::Key_Down)
841 [[maybe_unused]] QKeyEvent *event)
851 QPointF pixel_coordinates(
855 Qt::MouseButton button = Qt::NoButton;
856 QEvent::Type q_event_type = QEvent::MouseButtonPress;
862 button = Qt::LeftButton;
868 q_event_type = QEvent::MouseButtonPress;
870 q_event_type = QEvent::MouseButtonRelease;
876 button = Qt::RightButton;
882 q_event_type = QEvent::MouseButtonPress;
884 q_event_type = QEvent::MouseButtonRelease;
892 QMouseEvent *mouse_event_p =
893 new QMouseEvent(q_event_type,
895 mapToGlobal(pixel_coordinates.toPoint()),
896 mapToGlobal(pixel_coordinates.toPoint()),
900 Qt::MouseEventSynthesizedByApplication);
902 if(q_event_type == QEvent::MouseButtonPress)
933#if QT_VERSION < 0x060000
934 QPointF mousePoint =
event->localPos();
936 QPointF mousePoint =
event->position();
1053 yAxis->range().upper);
1056 yAxis->range().lower);
1308#if QT_VERSION < 0x060000
1309 QPointF mousePoint =
event->localPos();
1311 QPointF mousePoint =
event->position();
1473 yAxis->range().upper);
1475 yAxis->range().lower);
1625 double x_delta_pixel =
1629 if(x_delta_pixel > 3)
1660 [[maybe_unused]] QCPAxis::SelectablePart part,
1709 QCPLayoutElement *layoutElement = layoutElementAt(mousePoint);
1712 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)
1736 QCPLayoutElement *layoutElement = layoutElementAt(mousePoint);
1739 layoutElement ==
dynamic_cast<QCPLayoutElement *
>(axisRect()))
1746 QCPAxis::SelectablePart selectablePart;
1748 selectablePart = yAxis->getPartAt(mousePoint);
1750 if(selectablePart == QCPAxis::spAxisLabel ||
1751 selectablePart == QCPAxis::spAxis ||
1752 selectablePart == QCPAxis::spTickLabels)
1777 double x_delta_pixel =
1781 double y_delta_pixel =
1785 if(x_delta_pixel > y_delta_pixel)
1786 return Qt::Horizontal;
1788 return Qt::Vertical;
1797 QPointF pixels_coordinates(xAxis->coordToPixel(graph_coordinates.x()),
1798 yAxis->coordToPixel(graph_coordinates.y()));
1808 QCursor::setPos(mapToGlobal(pixel_coordinates.toPoint()));
1817 QPointF pixel_coord(xAxis->coordToPixel(graph_coord.x()),
1818 yAxis->coordToPixel(graph_coord.y()));
1831 QPointF pixel_coordinates(
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()),
1851 yAxis->coordToPixel(graph_coord.y()));
1864 QPointF pixel_coordinates(
1870 QPointF graph_coordinates(xAxis->pixelToCoord(pixel_coordinates.x()),
1871 yAxis->pixelToCoord(pixel_coordinates.y()));
1873 return graph_coordinates;
1884 QCPGraph *graph_p = graph(index);
1886 if(graph_p ==
nullptr)
1887 qFatal(
"Programming error.");
1889 return graph_p->getKeyRange(found_range);
1896 QCPGraph *graph_p = graph(index);
1898 if(graph_p ==
nullptr)
1899 qFatal(
"Programming error.");
1901 return graph_p->getValueRange(found_range);
1908 bool &found_range)
const
1917 found_range =
false;
1919 return QCPRange(0, 1);
1922 if(graphCount() == 1)
1923 return graph()->getKeyRange(found_range);
1925 bool found_at_least_one_range =
false;
1928 QCPRange result_range(QCPRange::minRange + 1, QCPRange::maxRange + 1);
1930 for(
int iter = 0; iter < graphCount(); ++iter)
1932 QCPRange temp_range;
1934 bool found_range_for_iter =
false;
1936 QCPGraph *graph_p = graph(iter);
1941 temp_range = graph_p->getKeyRange(found_range_for_iter);
1943 temp_range = graph_p->getValueRange(found_range_for_iter);
1945 qFatal(
"Cannot reach this point. Programming error.");
1950 if(!found_range_for_iter)
1956 if(!QCPRange::validRange(result_range))
1957 qFatal(
"The obtained range is invalid !");
1960 result_range = temp_range;
1963 found_at_least_one_range =
true;
1970 if(temp_range.lower > result_range.lower)
1971 result_range.lower = temp_range.lower;
1972 if(temp_range.upper < result_range.upper)
1973 result_range.upper = temp_range.upper;
1977 if(temp_range.lower < result_range.lower)
1978 result_range.lower = temp_range.lower;
1979 if(temp_range.upper > result_range.upper)
1980 result_range.upper = temp_range.upper;
1983 qFatal(
"Cannot reach this point. Programming error.");
1991 found_range = found_at_least_one_range;
1993 return result_range;
2037 double xLower = xAxis->range().lower;
2038 double xUpper = xAxis->range().upper;
2042 double yLower = yAxis->range().lower;
2043 double yUpper = yAxis->range().upper;
2070 xAxis->setRange(xLower, xUpper - xDelta);
2084 yAxis->setRange(yLower, yUpper - yDelta);
2134 yAxis->setRange(xAxis->range().lower,
2181 "This function can only be called if the mouse click was on one of the "
2217 QCPRange yAxisRange,
2222 if(
static_cast<int>(axis) &
static_cast<int>(
Axis::x))
2224 xAxis->setRange(xAxisRange.lower, xAxisRange.upper);
2227 if(
static_cast<int>(axis) &
static_cast<int>(
Axis::y))
2229 yAxis->setRange(yAxisRange.lower, yAxisRange.upper);
2246 xAxis->setRange(lower, upper);
2257 yAxis->setRange(lower, upper);
2320 bool for_integration)
2379 double x_axis_center_position =
2380 leftmost_point.x() + (rightmost_point.x() - leftmost_point.x()) / 2;
2390 QPointF pixel_coordinates;
2394 int pixels_away_from_line = 15;
2408 pixels_away_from_line *= -1;
2411 double y_axis_pixel_coordinate =
2414 double y_axis_modified_pixel_coordinate =
2415 y_axis_pixel_coordinate + pixels_away_from_line;
2417 pixel_coordinates.setX(x_axis_center_position);
2418 pixel_coordinates.setY(y_axis_modified_pixel_coordinate);
2422 QPointF graph_coordinates(xAxis->pixelToCoord(pixel_coordinates.x()),
2423 yAxis->pixelToCoord(pixel_coordinates.y()));
2427 graph_coordinates.y());
2452 QString label_text =
2508 double x_axis_center_position =
2509 leftmost_point.x() + (rightmost_point.x() - leftmost_point.x()) / 2;
2511 double y_axis_center_position =
2512 bottommost_point.y() + (topmost_point.y() - bottommost_point.y()) / 2;
2517 y_axis_center_position);
2563 double plotHeight = yAxis->range().upper - yAxis->range().lower;
2568 double heightDiffRatio = (heightDiff / plotHeight) * 100;
2570 if(heightDiffRatio > 10)
2601 double x_range_start =
2603 double x_range_end =
2612 QPointF(x_range_start, y_position));
2637 QPointF(x_range_start, y_position));
3098 bool for_integration)
3214 return static_cast<PolygonType>(current_selection_polygon);
3241 QCustomPlot::setFocus();
3253 if(focusedPlotWidget ==
nullptr)
3255 "baseplotwidget.cpp @ redrawPlotBackground(QWidget *focusedPlotWidget "
3257 "ERROR focusedPlotWidget cannot be nullptr.");
3259 if(
dynamic_cast<QWidget *
>(
this) != focusedPlotWidget)
double m_xRegionRangeStart
Qt::MouseButtons m_mouseButtonsAtMousePress
SelectionPolygon m_selectionPolygon
DragDirections recordDragDirections()
Qt::KeyboardModifiers m_keyboardModifiers
Qt::MouseButtons m_lastPressedMouseButton
bool m_isMeasuringDistance
DragDirections m_dragDirections
QPointF m_lastCursorHoveredPoint
QPointF m_currentDragPoint
double m_yRegionRangeStart
bool m_isRightPseudoButtonKeyPressed
Qt::MouseButtons m_pressedMouseButtons
Qt::MouseButtons m_mouseButtonsAtMouseRelease
bool m_isLeftPseudoButtonKeyPressed
Qt::MouseButtons m_lastReleasedMouseButton
double m_selectRectangleWidth
void setPoint(PointSpecs point_spec, double x, double y)
QPointF getTopMostPoint() const
QPointF getRightMostPoint() const
QPointF getLeftMostPoint() const
QPointF getBottomMostPoint() const
void set1D(double x_range_start, double x_range_end)
QPointF getPoint(PointSpecs point_spec) const
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...