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)
922 qDebug() << (graph() !=
nullptr);
933 QPointF mousePoint =
event->position();
935 qDebug() <<
"local mousePoint position in pixels:" << mousePoint;
1051 yAxis->range().upper);
1054 yAxis->range().lower);
1114 qDebug() <<
"the left button is dragging.";
1130 qDebug() <<
"Click was on one of the axes.";
1167 qDebug() <<
"Asking that the axes be rescaled.";
1177 qDebug() <<
"Asking that the axes be panned.";
1196 qDebug() <<
"Apparently the selection is a real rectangle.";
1223 qDebug() <<
"Apparently we are measuring a delta.";
1254 qDebug() <<
"the right button is dragging.";
1313 QPointF mousePoint =
event->position();
1475 yAxis->range().upper);
1477 yAxis->range().lower);
1627 double x_delta_pixel =
1631 if(x_delta_pixel > 3)
1634 qDebug() <<
"Not asking for integration.";
1662 [[maybe_unused]] QCPAxis::SelectablePart part,
1711 QCPLayoutElement *layoutElement = layoutElementAt(mousePoint);
1714 layoutElement ==
dynamic_cast<QCPLayoutElement *
>(axisRect()))
1721 QCPAxis::SelectablePart selectablePart;
1723 selectablePart = xAxis->getPartAt(mousePoint);
1725 if(selectablePart == QCPAxis::spAxisLabel ||
1726 selectablePart == QCPAxis::spAxis ||
1727 selectablePart == QCPAxis::spTickLabels)
1738 QCPLayoutElement *layoutElement = layoutElementAt(mousePoint);
1741 layoutElement ==
dynamic_cast<QCPLayoutElement *
>(axisRect()))
1748 QCPAxis::SelectablePart selectablePart;
1750 selectablePart = yAxis->getPartAt(mousePoint);
1752 if(selectablePart == QCPAxis::spAxisLabel ||
1753 selectablePart == QCPAxis::spAxis ||
1754 selectablePart == QCPAxis::spTickLabels)
1779 double x_delta_pixel =
1783 double y_delta_pixel =
1787 if(x_delta_pixel > y_delta_pixel)
1788 return Qt::Horizontal;
1790 return Qt::Vertical;
1799 QPointF pixels_coordinates(xAxis->coordToPixel(graph_coordinates.x()),
1800 yAxis->coordToPixel(graph_coordinates.y()));
1810 QCursor::setPos(mapToGlobal(pixel_coordinates.toPoint()));
1819 QPointF pixel_coord(xAxis->coordToPixel(graph_coord.x()),
1820 yAxis->coordToPixel(graph_coord.y()));
1833 QPointF pixel_coordinates(
1839 QPointF graph_coordinates(xAxis->pixelToCoord(pixel_coordinates.x()),
1840 yAxis->pixelToCoord(pixel_coordinates.y()));
1842 return graph_coordinates;
1852 QPointF pixel_coord(xAxis->coordToPixel(graph_coord.x()),
1853 yAxis->coordToPixel(graph_coord.y()));
1866 QPointF pixel_coordinates(
1872 QPointF graph_coordinates(xAxis->pixelToCoord(pixel_coordinates.x()),
1873 yAxis->pixelToCoord(pixel_coordinates.y()));
1875 return graph_coordinates;
1886 QCPGraph *graph_p = graph(index);
1888 if(graph_p ==
nullptr)
1889 qFatal(
"Programming error.");
1891 return graph_p->getKeyRange(found_range);
1898 QCPGraph *graph_p = graph(index);
1900 if(graph_p ==
nullptr)
1901 qFatal(
"Programming error.");
1903 return graph_p->getValueRange(found_range);
1910 bool &found_range)
const
1919 found_range =
false;
1921 return QCPRange(0, 1);
1924 if(graphCount() == 1)
1925 return graph()->getKeyRange(found_range);
1927 bool found_at_least_one_range =
false;
1930 QCPRange result_range(QCPRange::minRange + 1, QCPRange::maxRange + 1);
1932 for(
int iter = 0; iter < graphCount(); ++iter)
1934 QCPRange temp_range;
1936 bool found_range_for_iter =
false;
1938 QCPGraph *graph_p = graph(iter);
1943 temp_range = graph_p->getKeyRange(found_range_for_iter);
1945 temp_range = graph_p->getValueRange(found_range_for_iter);
1947 qFatal(
"Cannot reach this point. Programming error.");
1952 if(!found_range_for_iter)
1958 if(!QCPRange::validRange(result_range))
1959 qFatal(
"The obtained range is invalid !");
1962 result_range = temp_range;
1965 found_at_least_one_range =
true;
1972 if(temp_range.lower > result_range.lower)
1973 result_range.lower = temp_range.lower;
1974 if(temp_range.upper < result_range.upper)
1975 result_range.upper = temp_range.upper;
1979 if(temp_range.lower < result_range.lower)
1980 result_range.lower = temp_range.lower;
1981 if(temp_range.upper > result_range.upper)
1982 result_range.upper = temp_range.upper;
1985 qFatal(
"Cannot reach this point. Programming error.");
1993 found_range = found_at_least_one_range;
1995 return result_range;
2039 double xLower = xAxis->range().lower;
2040 double xUpper = xAxis->range().upper;
2044 double yLower = yAxis->range().lower;
2045 double yUpper = yAxis->range().upper;
2072 xAxis->setRange(xLower, xUpper - xDelta);
2086 yAxis->setRange(yLower, yUpper - yDelta);
2136 yAxis->setRange(xAxis->range().lower,
2185 "This function can only be called if the mouse click was on one of the "
2221 QCPRange yAxisRange,
2226 if(
static_cast<int>(axis) &
static_cast<int>(
Axis::x))
2228 xAxis->setRange(xAxisRange.lower, xAxisRange.upper);
2231 if(
static_cast<int>(axis) &
static_cast<int>(
Axis::y))
2233 yAxis->setRange(yAxisRange.lower, yAxisRange.upper);
2250 xAxis->setRange(lower, upper);
2261 yAxis->setRange(lower, upper);
2324 bool for_integration)
2383 double x_axis_center_position =
2384 leftmost_point.x() + (rightmost_point.x() - leftmost_point.x()) / 2;
2394 QPointF pixel_coordinates;
2398 int pixels_away_from_line = 15;
2412 pixels_away_from_line *= -1;
2415 double y_axis_pixel_coordinate =
2418 double y_axis_modified_pixel_coordinate =
2419 y_axis_pixel_coordinate + pixels_away_from_line;
2421 pixel_coordinates.setX(x_axis_center_position);
2422 pixel_coordinates.setY(y_axis_modified_pixel_coordinate);
2426 QPointF graph_coordinates(xAxis->pixelToCoord(pixel_coordinates.x()),
2427 yAxis->pixelToCoord(pixel_coordinates.y()));
2431 graph_coordinates.y());
2483 double x_axis_center_position =
2484 leftmost_point.x() + (rightmost_point.x() - leftmost_point.x()) / 2;
2486 double y_axis_center_position =
2487 bottommost_point.y() + (topmost_point.y() - bottommost_point.y()) / 2;
2492 y_axis_center_position);
2538 double plotHeight = yAxis->range().upper - yAxis->range().lower;
2543 double heightDiffRatio = (heightDiff / plotHeight) * 100;
2545 if(heightDiffRatio > 10)
2576 double x_range_start =
2578 double x_range_end =
2587 QPointF(x_range_start, y_position));
2612 QPointF(x_range_start, y_position));
3073 bool for_integration)
3189 return static_cast<PolygonType>(current_selection_polygon);
3216 QCustomPlot::setFocus();
3228 if(focusedPlotWidget ==
nullptr)
3230 "baseplotwidget.cpp @ redrawPlotBackground(QWidget *focusedPlotWidget "
3232 "ERROR focusedPlotWidget cannot be nullptr.");
3234 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...