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);
1251 QPointF mousePoint =
event->localPos();
1342 yAxis->range().upper);
1344 yAxis->range().lower);
1409 yAxis->range().upper);
1411 yAxis->range().lower);
1529 qDebug() <<
"Another possibility.";
1561 double x_delta_pixel =
1565 if(x_delta_pixel > 3)
1596 [[maybe_unused]] QCPAxis::SelectablePart part,
1644 QCPLayoutElement *layoutElement = layoutElementAt(mousePoint);
1647 layoutElement ==
dynamic_cast<QCPLayoutElement *
>(axisRect()))
1654 QCPAxis::SelectablePart selectablePart;
1656 selectablePart = xAxis->getPartAt(mousePoint);
1658 if(selectablePart == QCPAxis::spAxisLabel ||
1659 selectablePart == QCPAxis::spAxis ||
1660 selectablePart == QCPAxis::spTickLabels)
1671 QCPLayoutElement *layoutElement = layoutElementAt(mousePoint);
1674 layoutElement ==
dynamic_cast<QCPLayoutElement *
>(axisRect()))
1681 QCPAxis::SelectablePart selectablePart;
1683 selectablePart = yAxis->getPartAt(mousePoint);
1685 if(selectablePart == QCPAxis::spAxisLabel ||
1686 selectablePart == QCPAxis::spAxis ||
1687 selectablePart == QCPAxis::spTickLabels)
1712 double x_delta_pixel =
1716 double y_delta_pixel =
1720 if(x_delta_pixel > y_delta_pixel)
1721 return Qt::Horizontal;
1723 return Qt::Vertical;
1732 QPointF pixels_coordinates(xAxis->coordToPixel(graph_coordinates.x()),
1733 yAxis->coordToPixel(graph_coordinates.y()));
1743 QCursor::setPos(mapToGlobal(pixel_coordinates.toPoint()));
1752 QPointF pixel_coord(xAxis->coordToPixel(graph_coord.x()),
1753 yAxis->coordToPixel(graph_coord.y()));
1766 QPointF pixel_coordinates(
1772 QPointF graph_coordinates(xAxis->pixelToCoord(pixel_coordinates.x()),
1773 yAxis->pixelToCoord(pixel_coordinates.y()));
1775 return graph_coordinates;
1785 QPointF pixel_coord(xAxis->coordToPixel(graph_coord.x()),
1786 yAxis->coordToPixel(graph_coord.y()));
1799 QPointF pixel_coordinates(
1805 QPointF graph_coordinates(xAxis->pixelToCoord(pixel_coordinates.x()),
1806 yAxis->pixelToCoord(pixel_coordinates.y()));
1808 return graph_coordinates;
1819 QCPGraph *graph_p = graph(index);
1821 if(graph_p ==
nullptr)
1822 qFatal(
"Programming error.");
1824 return graph_p->getKeyRange(found_range);
1831 QCPGraph *graph_p = graph(index);
1833 if(graph_p ==
nullptr)
1834 qFatal(
"Programming error.");
1836 return graph_p->getValueRange(found_range);
1843 bool &found_range)
const
1852 found_range =
false;
1854 return QCPRange(0, 1);
1857 if(graphCount() == 1)
1858 return graph()->getKeyRange(found_range);
1860 bool found_at_least_one_range =
false;
1863 QCPRange result_range(QCPRange::minRange + 1, QCPRange::maxRange + 1);
1865 for(
int iter = 0; iter < graphCount(); ++iter)
1867 QCPRange temp_range;
1869 bool found_range_for_iter =
false;
1871 QCPGraph *graph_p = graph(iter);
1876 temp_range = graph_p->getKeyRange(found_range_for_iter);
1878 temp_range = graph_p->getValueRange(found_range_for_iter);
1880 qFatal(
"Cannot reach this point. Programming error.");
1885 if(!found_range_for_iter)
1891 if(!QCPRange::validRange(result_range))
1892 qFatal(
"The obtained range is invalid !");
1895 result_range = temp_range;
1898 found_at_least_one_range =
true;
1905 if(temp_range.lower > result_range.lower)
1906 result_range.lower = temp_range.lower;
1907 if(temp_range.upper < result_range.upper)
1908 result_range.upper = temp_range.upper;
1912 if(temp_range.lower < result_range.lower)
1913 result_range.lower = temp_range.lower;
1914 if(temp_range.upper > result_range.upper)
1915 result_range.upper = temp_range.upper;
1918 qFatal(
"Cannot reach this point. Programming error.");
1926 found_range = found_at_least_one_range;
1928 return result_range;
1972 double xLower = xAxis->range().lower;
1973 double xUpper = xAxis->range().upper;
1977 double yLower = yAxis->range().lower;
1978 double yUpper = yAxis->range().upper;
2005 xAxis->setRange(xLower, xUpper - xDelta);
2019 yAxis->setRange(yLower, yUpper - yDelta);
2069 yAxis->setRange(xAxis->range().lower,
2116 "This function can only be called if the mouse click was on one of the "
2151 QCPRange yAxisRange,
2154 if(
static_cast<int>(axis) &
static_cast<int>(
Axis::x))
2156 xAxis->setRange(xAxisRange.lower, xAxisRange.upper);
2159 if(
static_cast<int>(axis) &
static_cast<int>(
Axis::y))
2161 yAxis->setRange(yAxisRange.lower, yAxisRange.upper);
2178 xAxis->setRange(lower, upper);
2189 yAxis->setRange(lower, upper);
2252 bool for_integration)
2307 double x_axis_center_position =
2308 leftmost_point.x() + (rightmost_point.x() - leftmost_point.x()) / 2;
2318 QPointF pixel_coordinates;
2322 int pixels_away_from_line = 15;
2336 pixels_away_from_line *= -1;
2339 double y_axis_pixel_coordinate =
2342 double y_axis_modified_pixel_coordinate =
2343 y_axis_pixel_coordinate + pixels_away_from_line;
2345 pixel_coordinates.setX(x_axis_center_position);
2346 pixel_coordinates.setY(y_axis_modified_pixel_coordinate);
2350 QPointF graph_coordinates(xAxis->pixelToCoord(pixel_coordinates.x()),
2351 yAxis->pixelToCoord(pixel_coordinates.y()));
2353 graph_coordinates.y());
2403 double x_axis_center_position =
2404 leftmost_point.x() + (rightmost_point.x() - leftmost_point.x()) / 2;
2406 double y_axis_center_position =
2407 bottommost_point.y() + (topmost_point.y() - bottommost_point.y()) / 2;
2412 y_axis_center_position);
2458 double plotHeight = yAxis->range().upper - yAxis->range().lower;
2463 double heightDiffRatio = (heightDiff / plotHeight) * 100;
2465 if(heightDiffRatio > 10)
2496 double x_range_start =
2498 double x_range_end =
2507 QPointF(x_range_start, y_position));
2532 QPointF(x_range_start, y_position));
2993 bool for_integration)
3109 return static_cast<PolygonType>(current_selection_polygon);
3136 QCustomPlot::setFocus();
3148 if(focusedPlotWidget ==
nullptr)
3150 "baseplotwidget.cpp @ redrawPlotBackground(QWidget *focusedPlotWidget "
3152 "ERROR focusedPlotWidget cannot be nullptr.");
3154 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...