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)
927 QPointF mousePoint =
event->localPos();
989 yAxis->range().lower);
1022 yAxis->range().upper);
1025 yAxis->range().lower);
1253 QPointF mousePoint =
event->localPos();
1344 yAxis->range().upper);
1346 yAxis->range().lower);
1411 yAxis->range().upper);
1413 yAxis->range().lower);
1563 double x_delta_pixel =
1567 if(x_delta_pixel > 3)
1598 [[maybe_unused]] QCPAxis::SelectablePart part,
1647 QCPLayoutElement *layoutElement = layoutElementAt(mousePoint);
1650 layoutElement ==
dynamic_cast<QCPLayoutElement *
>(axisRect()))
1657 QCPAxis::SelectablePart selectablePart;
1659 selectablePart = xAxis->getPartAt(mousePoint);
1661 if(selectablePart == QCPAxis::spAxisLabel ||
1662 selectablePart == QCPAxis::spAxis ||
1663 selectablePart == QCPAxis::spTickLabels)
1674 QCPLayoutElement *layoutElement = layoutElementAt(mousePoint);
1677 layoutElement ==
dynamic_cast<QCPLayoutElement *
>(axisRect()))
1684 QCPAxis::SelectablePart selectablePart;
1686 selectablePart = yAxis->getPartAt(mousePoint);
1688 if(selectablePart == QCPAxis::spAxisLabel ||
1689 selectablePart == QCPAxis::spAxis ||
1690 selectablePart == QCPAxis::spTickLabels)
1715 double x_delta_pixel =
1719 double y_delta_pixel =
1723 if(x_delta_pixel > y_delta_pixel)
1724 return Qt::Horizontal;
1726 return Qt::Vertical;
1735 QPointF pixels_coordinates(xAxis->coordToPixel(graph_coordinates.x()),
1736 yAxis->coordToPixel(graph_coordinates.y()));
1746 QCursor::setPos(mapToGlobal(pixel_coordinates.toPoint()));
1755 QPointF pixel_coord(xAxis->coordToPixel(graph_coord.x()),
1756 yAxis->coordToPixel(graph_coord.y()));
1769 QPointF pixel_coordinates(
1775 QPointF graph_coordinates(xAxis->pixelToCoord(pixel_coordinates.x()),
1776 yAxis->pixelToCoord(pixel_coordinates.y()));
1778 return graph_coordinates;
1788 QPointF pixel_coord(xAxis->coordToPixel(graph_coord.x()),
1789 yAxis->coordToPixel(graph_coord.y()));
1802 QPointF pixel_coordinates(
1808 QPointF graph_coordinates(xAxis->pixelToCoord(pixel_coordinates.x()),
1809 yAxis->pixelToCoord(pixel_coordinates.y()));
1811 return graph_coordinates;
1822 QCPGraph *graph_p = graph(index);
1824 if(graph_p ==
nullptr)
1825 qFatal(
"Programming error.");
1827 return graph_p->getKeyRange(found_range);
1834 QCPGraph *graph_p = graph(index);
1836 if(graph_p ==
nullptr)
1837 qFatal(
"Programming error.");
1839 return graph_p->getValueRange(found_range);
1846 bool &found_range)
const
1855 found_range =
false;
1857 return QCPRange(0, 1);
1860 if(graphCount() == 1)
1861 return graph()->getKeyRange(found_range);
1863 bool found_at_least_one_range =
false;
1866 QCPRange result_range(QCPRange::minRange + 1, QCPRange::maxRange + 1);
1868 for(
int iter = 0; iter < graphCount(); ++iter)
1870 QCPRange temp_range;
1872 bool found_range_for_iter =
false;
1874 QCPGraph *graph_p = graph(iter);
1879 temp_range = graph_p->getKeyRange(found_range_for_iter);
1881 temp_range = graph_p->getValueRange(found_range_for_iter);
1883 qFatal(
"Cannot reach this point. Programming error.");
1888 if(!found_range_for_iter)
1894 if(!QCPRange::validRange(result_range))
1895 qFatal(
"The obtained range is invalid !");
1898 result_range = temp_range;
1901 found_at_least_one_range =
true;
1908 if(temp_range.lower > result_range.lower)
1909 result_range.lower = temp_range.lower;
1910 if(temp_range.upper < result_range.upper)
1911 result_range.upper = temp_range.upper;
1915 if(temp_range.lower < result_range.lower)
1916 result_range.lower = temp_range.lower;
1917 if(temp_range.upper > result_range.upper)
1918 result_range.upper = temp_range.upper;
1921 qFatal(
"Cannot reach this point. Programming error.");
1929 found_range = found_at_least_one_range;
1931 return result_range;
1975 double xLower = xAxis->range().lower;
1976 double xUpper = xAxis->range().upper;
1980 double yLower = yAxis->range().lower;
1981 double yUpper = yAxis->range().upper;
2008 xAxis->setRange(xLower, xUpper - xDelta);
2022 yAxis->setRange(yLower, yUpper - yDelta);
2072 yAxis->setRange(xAxis->range().lower,
2121 "This function can only be called if the mouse click was on one of the "
2157 QCPRange yAxisRange,
2162 if(
static_cast<int>(axis) &
static_cast<int>(
Axis::x))
2164 xAxis->setRange(xAxisRange.lower, xAxisRange.upper);
2167 if(
static_cast<int>(axis) &
static_cast<int>(
Axis::y))
2169 yAxis->setRange(yAxisRange.lower, yAxisRange.upper);
2186 xAxis->setRange(lower, upper);
2197 yAxis->setRange(lower, upper);
2260 bool for_integration)
2315 double x_axis_center_position =
2316 leftmost_point.x() + (rightmost_point.x() - leftmost_point.x()) / 2;
2326 QPointF pixel_coordinates;
2330 int pixels_away_from_line = 15;
2344 pixels_away_from_line *= -1;
2347 double y_axis_pixel_coordinate =
2350 double y_axis_modified_pixel_coordinate =
2351 y_axis_pixel_coordinate + pixels_away_from_line;
2353 pixel_coordinates.setX(x_axis_center_position);
2354 pixel_coordinates.setY(y_axis_modified_pixel_coordinate);
2358 QPointF graph_coordinates(xAxis->pixelToCoord(pixel_coordinates.x()),
2359 yAxis->pixelToCoord(pixel_coordinates.y()));
2361 graph_coordinates.y());
2411 double x_axis_center_position =
2412 leftmost_point.x() + (rightmost_point.x() - leftmost_point.x()) / 2;
2414 double y_axis_center_position =
2415 bottommost_point.y() + (topmost_point.y() - bottommost_point.y()) / 2;
2420 y_axis_center_position);
2466 double plotHeight = yAxis->range().upper - yAxis->range().lower;
2471 double heightDiffRatio = (heightDiff / plotHeight) * 100;
2473 if(heightDiffRatio > 10)
2504 double x_range_start =
2506 double x_range_end =
2515 QPointF(x_range_start, y_position));
2540 QPointF(x_range_start, y_position));
3001 bool for_integration)
3117 return static_cast<PolygonType>(current_selection_polygon);
3144 QCustomPlot::setFocus();
3156 if(focusedPlotWidget ==
nullptr)
3158 "baseplotwidget.cpp @ redrawPlotBackground(QWidget *focusedPlotWidget "
3160 "ERROR focusedPlotWidget cannot be nullptr.");
3162 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...