35 #include "../../types.h"
37 #include "../../pappsoexception.h"
38 #include "../../exception/exceptionnotpossible.h"
42 qRegisterMetaType<pappso::BasePlotContext>(
"pappso::BasePlotContext");
44 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.");
111 const QString &x_axis_label,
112 const QString &y_axis_label)
113 : QCustomPlot(parent), m_axisLabelX(x_axis_label), m_axisLabelY(y_axis_label)
117 if(parent ==
nullptr)
118 qFatal(
"Programming error.");
121 m_pen.setStyle(Qt::SolidLine);
122 m_pen.setBrush(Qt::black);
125 xAxis->setLabel(x_axis_label);
126 yAxis->setLabel(y_axis_label);
145 qFatal(
"Programming error.");
180 for(
int iter = 0; iter < layerCount(); ++iter)
183 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)
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)
806 int pixel_increment = 0;
811 pixel_increment = 50;
817 if(event->key() == Qt::Key_Left)
819 else if(event->key() == Qt::Key_Right)
821 else if(event->key() == Qt::Key_Up)
823 else if(event->key() == Qt::Key_Down)
840 [[maybe_unused]] QKeyEvent *event)
850 QPointF pixel_coordinates(
854 Qt::MouseButton button = Qt::NoButton;
855 QEvent::Type q_event_type = QEvent::MouseButtonPress;
861 button = Qt::LeftButton;
867 q_event_type = QEvent::MouseButtonPress;
869 q_event_type = QEvent::MouseButtonRelease;
875 button = Qt::RightButton;
881 q_event_type = QEvent::MouseButtonPress;
883 q_event_type = QEvent::MouseButtonRelease;
891 QMouseEvent *mouse_event_p =
892 new QMouseEvent(q_event_type,
894 mapToGlobal(pixel_coordinates.toPoint()),
895 mapToGlobal(pixel_coordinates.toPoint()),
899 Qt::MouseEventSynthesizedByApplication);
901 if(q_event_type == QEvent::MouseButtonPress)
932 #if QT_VERSION < 0x060000
933 QPointF mousePoint =
event->localPos();
935 QPointF mousePoint =
event->position();
1052 yAxis->range().upper);
1055 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());
2479 double x_axis_center_position =
2480 leftmost_point.x() + (rightmost_point.x() - leftmost_point.x()) / 2;
2482 double y_axis_center_position =
2483 bottommost_point.y() + (topmost_point.y() - bottommost_point.y()) / 2;
2488 y_axis_center_position);
2534 double plotHeight = yAxis->range().upper - yAxis->range().lower;
2539 double heightDiffRatio = (heightDiff / plotHeight) * 100;
2541 if(heightDiffRatio > 10)
2572 double x_range_start =
2574 double x_range_end =
2583 QPointF(x_range_start, y_position));
2608 QPointF(x_range_start, y_position));
3069 bool for_integration)
3185 return static_cast<PolygonType>(current_selection_polygon);
3212 QCustomPlot::setFocus();
3224 if(focusedPlotWidget ==
nullptr)
3226 "baseplotwidget.cpp @ redrawPlotBackground(QWidget *focusedPlotWidget "
3228 "ERROR focusedPlotWidget cannot be nullptr.");
3230 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
tries to keep as much as possible monoisotopes, removing any possible C13 peaks and changes multichar...