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");
351 QCPLayer *layer_p = graph(0)->layer();
352 qDebug() <<
"The graph was on layer:" << layer_p->name();
368 "plotsLayer", layer(
"background"), QCustomPlot::LayerInsertMode::limAbove);
373 setFocusPolicy(Qt::StrongFocus);
374 setInteractions(QCP::iRangeZoom | QCP::iSelectPlottables | QCP::iMultiSelect);
384 &QCustomPlot::mouseRelease,
389 &QCustomPlot::axisDoubleClick,
413 const QColor &new_color)
415 if(plottable_p ==
nullptr)
416 qFatal(
"Pointer cannot be nullptr.");
421 pen = plottable_p->pen();
422 pen.setColor(new_color);
423 plottable_p->setPen(pen);
432 if(!new_color.isValid())
435 QCPGraph *graph_p = graph(index);
437 if(graph_p ==
nullptr)
438 qFatal(
"Programming error.");
447 if(plottable_p ==
nullptr)
448 qFatal(
"Programming error.");
450 return plottable_p->pen().color();
457 QCPGraph *graph_p = graph(index);
459 if(graph_p ==
nullptr)
460 qFatal(
"Programming error.");
469 xAxis->setLabel(label);
476 yAxis->setLabel(label);
616 if(event->key() == Qt::Key_Left || event->key() == Qt::Key_Right ||
617 event->key() == Qt::Key_Up || event->key() == Qt::Key_Down)
647 if(event->key() == Qt::Key_Backspace)
654 else if(event->key() == Qt::Key_Space)
658 else if(event->key() == Qt::Key_Delete)
671 int graph_count = plottableCount();
694 QList<QCPGraph *> selected_graph_list;
696 selected_graph_list = selectedGraphs();
698 if(!selected_graph_list.size())
707 for(
int iter = 0; iter < selected_graph_list.size(); ++iter)
714 this, selected_graph_list.at(iter),
m_context);
727 else if(event->key() == Qt::Key_T)
739 else if(event->key() == Qt::Key_Left || event->key() == Qt::Key_Right ||
740 event->key() == Qt::Key_Up || event->key() == Qt::Key_Down)
749 else if(event->key() == Qt::Key_S)
794 int pixel_increment = 0;
799 pixel_increment = 50;
805 if(event->key() == Qt::Key_Left)
807 else if(event->key() == Qt::Key_Right)
809 else if(event->key() == Qt::Key_Up)
811 else if(event->key() == Qt::Key_Down)
828 [[maybe_unused]] QKeyEvent *event)
838 QPointF pixel_coordinates(
842 Qt::MouseButton button = Qt::NoButton;
843 QEvent::Type q_event_type = QEvent::MouseButtonPress;
849 button = Qt::LeftButton;
855 q_event_type = QEvent::MouseButtonPress;
857 q_event_type = QEvent::MouseButtonRelease;
863 button = Qt::RightButton;
869 q_event_type = QEvent::MouseButtonPress;
871 q_event_type = QEvent::MouseButtonRelease;
879 QMouseEvent *mouse_event_p =
880 new QMouseEvent(q_event_type,
882 mapToGlobal(pixel_coordinates.toPoint()),
883 mapToGlobal(pixel_coordinates.toPoint()),
887 Qt::MouseEventSynthesizedByApplication);
889 if(q_event_type == QEvent::MouseButtonPress)
915 QPointF mousePoint =
event->localPos();
977 yAxis->range().lower);
1010 yAxis->range().upper);
1013 yAxis->range().lower);
1239 QPointF mousePoint =
event->localPos();
1330 yAxis->range().upper);
1332 yAxis->range().lower);
1397 yAxis->range().upper);
1399 yAxis->range().lower);
1517 qDebug() <<
"Another possibility.";
1549 double x_delta_pixel =
1553 if(x_delta_pixel > 3)
1563 [[maybe_unused]] QCPAxis::SelectablePart part,
1611 QCPLayoutElement *layoutElement = layoutElementAt(mousePoint);
1614 layoutElement ==
dynamic_cast<QCPLayoutElement *
>(axisRect()))
1621 QCPAxis::SelectablePart selectablePart;
1623 selectablePart = xAxis->getPartAt(mousePoint);
1625 if(selectablePart == QCPAxis::spAxisLabel ||
1626 selectablePart == QCPAxis::spAxis ||
1627 selectablePart == QCPAxis::spTickLabels)
1638 QCPLayoutElement *layoutElement = layoutElementAt(mousePoint);
1641 layoutElement ==
dynamic_cast<QCPLayoutElement *
>(axisRect()))
1648 QCPAxis::SelectablePart selectablePart;
1650 selectablePart = yAxis->getPartAt(mousePoint);
1652 if(selectablePart == QCPAxis::spAxisLabel ||
1653 selectablePart == QCPAxis::spAxis ||
1654 selectablePart == QCPAxis::spTickLabels)
1679 double x_delta_pixel =
1683 double y_delta_pixel =
1687 if(x_delta_pixel > y_delta_pixel)
1688 return Qt::Horizontal;
1690 return Qt::Vertical;
1699 QPointF pixels_coordinates(xAxis->coordToPixel(graph_coordinates.x()),
1700 yAxis->coordToPixel(graph_coordinates.y()));
1710 QCursor::setPos(mapToGlobal(pixel_coordinates.toPoint()));
1719 QPointF pixel_coord(xAxis->coordToPixel(graph_coord.x()),
1720 yAxis->coordToPixel(graph_coord.y()));
1733 QPointF pixel_coordinates(
1739 QPointF graph_coordinates(xAxis->pixelToCoord(pixel_coordinates.x()),
1740 yAxis->pixelToCoord(pixel_coordinates.y()));
1742 return graph_coordinates;
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;
1786 QCPGraph *graph_p = graph(index);
1788 if(graph_p ==
nullptr)
1789 qFatal(
"Programming error.");
1791 return graph_p->getKeyRange(found_range);
1798 QCPGraph *graph_p = graph(index);
1800 if(graph_p ==
nullptr)
1801 qFatal(
"Programming error.");
1803 return graph_p->getValueRange(found_range);
1810 bool &found_range)
const
1819 found_range =
false;
1821 return QCPRange(0, 1);
1824 if(graphCount() == 1)
1825 return graph()->getKeyRange(found_range);
1827 bool found_at_least_one_range =
false;
1830 QCPRange result_range(QCPRange::minRange + 1, QCPRange::maxRange + 1);
1832 for(
int iter = 0; iter < graphCount(); ++iter)
1834 QCPRange temp_range;
1836 bool found_range_for_iter =
false;
1838 QCPGraph *graph_p = graph(iter);
1843 temp_range = graph_p->getKeyRange(found_range_for_iter);
1845 temp_range = graph_p->getValueRange(found_range_for_iter);
1847 qFatal(
"Cannot reach this point. Programming error.");
1852 if(!found_range_for_iter)
1858 if(!QCPRange::validRange(result_range))
1859 qFatal(
"The obtained range is invalid !");
1862 result_range = temp_range;
1865 found_at_least_one_range =
true;
1872 if(temp_range.lower > result_range.lower)
1873 result_range.lower = temp_range.lower;
1874 if(temp_range.upper < result_range.upper)
1875 result_range.upper = temp_range.upper;
1879 if(temp_range.lower < result_range.lower)
1880 result_range.lower = temp_range.lower;
1881 if(temp_range.upper > result_range.upper)
1882 result_range.upper = temp_range.upper;
1885 qFatal(
"Cannot reach this point. Programming error.");
1893 found_range = found_at_least_one_range;
1895 return result_range;
1939 double xLower = xAxis->range().lower;
1940 double xUpper = xAxis->range().upper;
1944 double yLower = yAxis->range().lower;
1945 double yUpper = yAxis->range().upper;
1972 xAxis->setRange(xLower, xUpper - xDelta);
1986 yAxis->setRange(yLower, yUpper - yDelta);
2036 yAxis->setRange(xAxis->range().lower,
2083 "This function can only be called if the mouse click was on one of the "
2118 QCPRange yAxisRange,
2121 if(
static_cast<int>(axis) &
static_cast<int>(
Axis::x))
2123 xAxis->setRange(xAxisRange.lower, xAxisRange.upper);
2126 if(
static_cast<int>(axis) &
static_cast<int>(
Axis::y))
2128 yAxis->setRange(yAxisRange.lower, yAxisRange.upper);
2145 xAxis->setRange(lower, upper);
2156 yAxis->setRange(lower, upper);
2219 bool for_integration)
2274 double x_axis_center_position =
2275 leftmost_point.x() + (rightmost_point.x() - leftmost_point.x()) / 2;
2285 QPointF pixel_coordinates;
2289 int pixels_away_from_line = 15;
2303 pixels_away_from_line *= -1;
2306 double y_axis_pixel_coordinate =
2309 double y_axis_modified_pixel_coordinate =
2310 y_axis_pixel_coordinate + pixels_away_from_line;
2312 pixel_coordinates.setX(x_axis_center_position);
2313 pixel_coordinates.setY(y_axis_modified_pixel_coordinate);
2317 QPointF graph_coordinates(xAxis->pixelToCoord(pixel_coordinates.x()),
2318 yAxis->pixelToCoord(pixel_coordinates.y()));
2320 graph_coordinates.y());
2370 double x_axis_center_position =
2371 leftmost_point.x() + (rightmost_point.x() - leftmost_point.x()) / 2;
2373 double y_axis_center_position =
2374 bottommost_point.y() + (topmost_point.y() - bottommost_point.y()) / 2;
2379 y_axis_center_position);
2425 double plotHeight = yAxis->range().upper - yAxis->range().lower;
2430 double heightDiffRatio = (heightDiff / plotHeight) * 100;
2432 if(heightDiffRatio > 10)
2463 double x_range_start =
2465 double x_range_end =
2474 QPointF(x_range_start, y_position));
2499 QPointF(x_range_start, y_position));
2960 bool for_integration)
3076 return static_cast<PolygonType>(current_selection_polygon);
3103 QCustomPlot::setFocus();
3115 if(focusedPlotWidget ==
nullptr)
3117 "baseplotwidget.cpp @ redrawPlotBackground(QWidget *focusedPlotWidget "
3119 "ERROR focusedPlotWidget cannot be nullptr.");
3121 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...