35#include "../../types.h"
36#include "../../utils.h"
38#include "../../pappsoexception.h"
39#include "../../exception/exceptionnotpossible.h"
43 qRegisterMetaType<pappso::BasePlotContext>(
"pappso::BasePlotContext");
45 qRegisterMetaType<pappso::BasePlotContext *>(
"pappso::BasePlotContext *");
53 qFatal(
"Programming error.");
56 m_pen.setStyle(Qt::SolidLine);
57 m_pen.setBrush(Qt::black);
77 qFatal(
"Programming error.");
112 const QString &x_axis_label,
113 const QString &y_axis_label)
114 : QCustomPlot(parent), m_axisLabelX(x_axis_label), m_axisLabelY(y_axis_label)
118 if(parent ==
nullptr)
119 qFatal(
"Programming error.");
122 m_pen.setStyle(Qt::SolidLine);
123 m_pen.setBrush(Qt::black);
126 xAxis->setLabel(x_axis_label);
127 yAxis->setLabel(y_axis_label);
146 qFatal(
"Programming error.");
181 for(
int iter = 0; iter < layerCount(); ++iter)
184 QString(
"Layer index %1: %2\n").arg(iter).arg(layer(iter)->name());
194 if(layerable_p ==
nullptr)
195 qFatal(
"Programming error.");
197 QCPLayer *layer_p = layerable_p->layer();
199 return layer_p->name();
206 if(layerable_p ==
nullptr)
207 qFatal(
"Programming error.");
209 QCPLayer *layer_p = layerable_p->layer();
211 for(
int iter = 0; iter < layerCount(); ++iter)
213 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)
784 qDebug() <<
"Set m_context.m_integrationScopePolyHeight to"
786 <<
"upon release of S key";
797 qDebug() <<
"Set m_context.m_integrationScopePolyWidth to"
799 <<
"upon release of S key";
834 int pixel_increment = 0;
839 pixel_increment = 50;
845 if(event->key() == Qt::Key_Left)
847 else if(event->key() == Qt::Key_Right)
849 else if(event->key() == Qt::Key_Up)
851 else if(event->key() == Qt::Key_Down)
868 [[maybe_unused]] QKeyEvent *event)
878 QPointF pixel_coordinates(
882 Qt::MouseButton button = Qt::NoButton;
883 QEvent::Type q_event_type = QEvent::MouseButtonPress;
889 button = Qt::LeftButton;
895 q_event_type = QEvent::MouseButtonPress;
897 q_event_type = QEvent::MouseButtonRelease;
903 button = Qt::RightButton;
909 q_event_type = QEvent::MouseButtonPress;
911 q_event_type = QEvent::MouseButtonRelease;
919 QMouseEvent *mouse_event_p =
920 new QMouseEvent(q_event_type,
922 mapToGlobal(pixel_coordinates.toPoint()),
923 mapToGlobal(pixel_coordinates.toPoint()),
927 Qt::MouseEventSynthesizedByApplication);
929 if(q_event_type == QEvent::MouseButtonPress)
960#if QT_VERSION < 0x060000
961 QPointF mousePoint =
event->localPos();
963 QPointF mousePoint =
event->position();
1080 yAxis->range().upper);
1083 yAxis->range().lower);
1218 qDebug() <<
"Apparently the selection is two-dimensional.";
1270 qDebug() <<
"The right button is dragging.";
1283 qDebug() <<
"Apparently the selection has height.";
1307 qDebug() <<
"Apparently the selection is a not a rectangle.";
1328#if QT_VERSION < 0x060000
1329 QPointF mousePoint =
event->localPos();
1331 QPointF mousePoint =
event->position();
1493 yAxis->range().upper);
1495 yAxis->range().lower);
1639 double x_delta_pixel =
1643 if(x_delta_pixel > 3)
1674 [[maybe_unused]] QCPAxis::SelectablePart part,
1723 QCPLayoutElement *layoutElement = layoutElementAt(mousePoint);
1726 layoutElement ==
dynamic_cast<QCPLayoutElement *
>(axisRect()))
1732 QCPAxis::SelectablePart selectablePart;
1734 selectablePart = xAxis->getPartAt(mousePoint);
1736 if(selectablePart == QCPAxis::spAxisLabel ||
1737 selectablePart == QCPAxis::spAxis ||
1738 selectablePart == QCPAxis::spTickLabels)
1749 QCPLayoutElement *layoutElement = layoutElementAt(mousePoint);
1752 layoutElement ==
dynamic_cast<QCPLayoutElement *
>(axisRect()))
1758 QCPAxis::SelectablePart selectablePart;
1760 selectablePart = yAxis->getPartAt(mousePoint);
1762 if(selectablePart == QCPAxis::spAxisLabel ||
1763 selectablePart == QCPAxis::spAxis ||
1764 selectablePart == QCPAxis::spTickLabels)
1789 double x_delta_pixel =
1793 double y_delta_pixel =
1797 if(x_delta_pixel > y_delta_pixel)
1798 return Qt::Horizontal;
1800 return Qt::Vertical;
1809 QPointF pixels_coordinates(xAxis->coordToPixel(graph_coordinates.x()),
1810 yAxis->coordToPixel(graph_coordinates.y()));
1820 QCursor::setPos(mapToGlobal(pixel_coordinates.toPoint()));
1829 QPointF pixel_coord(xAxis->coordToPixel(graph_coord.x()),
1830 yAxis->coordToPixel(graph_coord.y()));
1843 QPointF pixel_coordinates(
1849 QPointF graph_coordinates(xAxis->pixelToCoord(pixel_coordinates.x()),
1850 yAxis->pixelToCoord(pixel_coordinates.y()));
1852 return graph_coordinates;
1862 QPointF pixel_coord(xAxis->coordToPixel(graph_coord.x()),
1863 yAxis->coordToPixel(graph_coord.y()));
1876 QPointF pixel_coordinates(
1882 QPointF graph_coordinates(xAxis->pixelToCoord(pixel_coordinates.x()),
1883 yAxis->pixelToCoord(pixel_coordinates.y()));
1885 return graph_coordinates;
1896 QCPGraph *graph_p = graph(index);
1898 if(graph_p ==
nullptr)
1899 qFatal(
"Programming error.");
1901 return graph_p->getKeyRange(found_range);
1908 QCPGraph *graph_p = graph(index);
1910 if(graph_p ==
nullptr)
1911 qFatal(
"Programming error.");
1913 return graph_p->getValueRange(found_range);
1920 bool &found_range)
const
1929 found_range =
false;
1931 return QCPRange(0, 1);
1934 if(graphCount() == 1)
1935 return graph()->getKeyRange(found_range);
1937 bool found_at_least_one_range =
false;
1940 QCPRange result_range(QCPRange::minRange + 1, QCPRange::maxRange + 1);
1942 for(
int iter = 0; iter < graphCount(); ++iter)
1944 QCPRange temp_range;
1946 bool found_range_for_iter =
false;
1948 QCPGraph *graph_p = graph(iter);
1953 temp_range = graph_p->getKeyRange(found_range_for_iter);
1955 temp_range = graph_p->getValueRange(found_range_for_iter);
1957 qFatal(
"Cannot reach this point. Programming error.");
1962 if(!found_range_for_iter)
1968 if(!QCPRange::validRange(result_range))
1969 qFatal(
"The obtained range is invalid !");
1972 result_range = temp_range;
1975 found_at_least_one_range =
true;
1982 if(temp_range.lower > result_range.lower)
1983 result_range.lower = temp_range.lower;
1984 if(temp_range.upper < result_range.upper)
1985 result_range.upper = temp_range.upper;
1989 if(temp_range.lower < result_range.lower)
1990 result_range.lower = temp_range.lower;
1991 if(temp_range.upper > result_range.upper)
1992 result_range.upper = temp_range.upper;
1995 qFatal(
"Cannot reach this point. Programming error.");
2003 found_range = found_at_least_one_range;
2005 return result_range;
2049 double xLower = xAxis->range().lower;
2050 double xUpper = xAxis->range().upper;
2054 double yLower = yAxis->range().lower;
2055 double yUpper = yAxis->range().upper;
2118 yAxis->setRange(xAxis->range().lower,
2165 "This function can only be called if the mouse click was on one of the "
2201 QCPRange yAxisRange,
2206 if(
static_cast<int>(axis) &
static_cast<int>(
Axis::x))
2208 xAxis->setRange(xAxisRange.lower, xAxisRange.upper);
2211 if(
static_cast<int>(axis) &
static_cast<int>(
Axis::y))
2213 yAxis->setRange(yAxisRange.lower, yAxisRange.upper);
2230 xAxis->setRange(lower, upper);
2241 yAxis->setRange(lower, upper);
2304 bool for_integration)
2370 QPointF leftmost_point;
2372 qFatal(
"Could not get the left-most point.");
2376 qFatal(
"Could not get width.");
2379 double x_axis_center_position = leftmost_point.x() + width / 2;
2389 int pixels_away_from_line = 15;
2391 QPointF reference_point_for_y_axis_label_position;
2405 pixels_away_from_line *= -1;
2408 reference_point_for_y_axis_label_position))
2409 qFatal(
"Failed to get top most point.");
2414 reference_point_for_y_axis_label_position))
2415 qFatal(
"Failed to get bottom most point.");
2420 double y_axis_pixel_coordinate =
2421 yAxis->coordToPixel(reference_point_for_y_axis_label_position.y());
2425 double y_axis_modified_pixel_coordinate =
2426 y_axis_pixel_coordinate + pixels_away_from_line;
2429 QPointF pixel_coordinates;
2431 pixel_coordinates.setX(x_axis_center_position);
2432 pixel_coordinates.setY(y_axis_modified_pixel_coordinate);
2435 QPointF graph_coordinates(xAxis->pixelToCoord(pixel_coordinates.x()),
2436 yAxis->pixelToCoord(pixel_coordinates.y()));
2438 qDebug() <<
"Should print the label at point:" << graph_coordinates;
2443 graph_coordinates.y());
2454 QString label_text = QString(
"full x span %1 -- x drag delta %2")
2455 .arg(width, 0,
'f', decimals)
2485 qFatal(
"Could not get height.");
2490 qDebug() <<
"height:" << height;
2502 QPointF bottom_most_point;
2504 qFatal(
"Could not get the bottom-most bottom point.");
2506 double y_axis_center_position = bottom_most_point.y() + height / 2;
2516 int pixels_away_from_line = 15;
2517 double x_axis_coordinate;
2518 double x_axis_pixel_coordinate;
2523 QPointF left_most_point;
2526 qFatal(
"Failed to get left most point.");
2528 x_axis_coordinate = left_most_point.x();
2530 pixels_away_from_line *= -1;
2534 QPointF right_most_point;
2537 qFatal(
"Failed to get right most point.");
2539 x_axis_coordinate = right_most_point.x();
2541 x_axis_pixel_coordinate = xAxis->coordToPixel(x_axis_coordinate);
2543 double x_axis_modified_pixel_coordinate =
2544 x_axis_pixel_coordinate + pixels_away_from_line;
2547 QPointF pixel_coordinates;
2549 pixel_coordinates.setX(x_axis_modified_pixel_coordinate);
2550 pixel_coordinates.setY(y_axis_center_position);
2554 QPointF graph_coordinates(xAxis->pixelToCoord(pixel_coordinates.x()),
2555 yAxis->pixelToCoord(pixel_coordinates.y()));
2558 y_axis_center_position);
2562 QString label_text = QString(
"full y span %1 -- y drag delta %2")
2563 .arg(height, 0,
'f', decimals)
2608 double plotHeight = yAxis->range().upper - yAxis->range().lower;
2613 double heightDiffRatio = (heightDiff / plotHeight) * 100;
2615 if(heightDiffRatio > 10)
2635 double x_range_start =
2637 double x_range_end =
2646 QPointF(x_range_start, y_position));
2671 QPointF(x_range_start, y_position));
2703 QPointF bottom_left_point;
2705 qFatal(
"Failed to get point.");
2706 qDebug() <<
"Starting point is left bottom point:" << bottom_left_point;
2710 qFatal(
"Failed to get width.");
2711 qDebug() <<
"Width:" << width;
2715 qFatal(
"Failed to get height.");
2716 qDebug() <<
"Height:" << height;
2718 QPointF bottom_right_point(bottom_left_point.x() + width,
2719 bottom_left_point.y());
2720 qDebug() <<
"bottom_right_point:" << bottom_right_point;
2722 QPointF top_right_point(bottom_left_point.x() + width,
2723 bottom_left_point.y() + height);
2724 qDebug() <<
"top_right_point:" << top_right_point;
2726 QPointF top_left_point(bottom_left_point.x(), bottom_left_point.y() + height);
2728 qDebug() <<
"top_left_point:" << top_left_point;
2807 qDebug() <<
"The horizontal rhomboid is flattened on the x axis.";
2818 qFatal(
"The rhomboid should be horizontal!");
2823 qFatal(
"Failed to getLeftMostTopPoint.");
2826 qFatal(
"Failed to getRightMostTopPoint.");
2828 qDebug() <<
"For top line, two points:" << point_1 <<
"--" << point_2;
2850 qFatal(
"Failed to getRightMostBottomPoint.");
2855 qDebug() <<
"For right line, two points:" << point_2 <<
"--" << point_1;
2859 qFatal(
"Failed to getLeftMostBottomPoint.");
2864 qDebug() <<
"For bottom line, two points:" << point_1 <<
"--" << point_2;
2868 qFatal(
"Failed to getLeftMostTopPoint.");
2873 qDebug() <<
"For left line, two points:" << point_2 <<
"--" << point_1;
2920 qDebug() <<
"The vertical rhomboid is flattened on the y axis.";
2931 qFatal(
"The rhomboid should be vertical!");
2937 qFatal(
"Failed to getLeftMostBottomPoint.");
2939 qDebug() <<
"For left vertical line, two points:" << point_1 <<
"--"
2962 qFatal(
"Failed to getRightMostBottomPoint.");
2967 qDebug() <<
"For lower oblique line, two points:" << point_2 <<
"--"
2972 qFatal(
"Failed to getRightMostTopPoint.");
2977 qDebug() <<
"For right vertical line, two points:" << point_1 <<
"--"
2982 qFatal(
"Failed to get the LeftMostTopPoint.");
2987 qDebug() <<
"For upper oblique line, two points:" << point_2 <<
"--"
3046 qDebug() <<
"Before calling updateIntegrationScopeRhomb(), "
3047 "m_integrationScopeRhombWidth:"
3049 <<
"and m_integrationScopeRhombHeight:"
3054 qDebug() <<
"After, m_integrationScopeRhombWidth:"
3056 <<
"and m_integrationScopeRhombHeight:"
3077 qFatal(
"Cannot be both the width or height of rhomboid scope be 0.");
3082 bool for_integration)
3103 qDebug() <<
"Updating the integration scope to an IntegrationScope.";
3111 <<
"Updating the integration scope to an IntegrationScopeRect.";
3117 <<
"Updating the integration scope to an IntegrationScopeRhomb.";
3128 std::vector<QPointF> points;
3135 qFatal(
"Failed to get LeftMost point.");
3139 qFatal(
"Failed to get RightMost point.");
3147 qFatal(
"Failed to get point.");
3153 qFatal(
"Failed to get width.");
3166 qFatal(
"Failed to get point.");
3172 qFatal(
"Failed to get width.");
3213 int current_selection_polygon =
3218 current_selection_polygon |=
3225 current_selection_polygon |=
3232 current_selection_polygon |=
3239 current_selection_polygon |=
3274 QCustomPlot::setFocus();
3286 if(focusedPlotWidget ==
nullptr)
3288 "baseplotwidget.cpp @ redrawPlotBackground(QWidget *focusedPlotWidget "
3290 "ERROR focusedPlotWidget cannot be nullptr.");
3292 if(
dynamic_cast<QWidget *
>(
this) != focusedPlotWidget)
double m_xRegionRangeStart
Qt::MouseButtons m_mouseButtonsAtMousePress
IntegrationScopeBaseCstSPtr msp_integrationScope
DragDirections recordDragDirections()
Qt::KeyboardModifiers m_keyboardModifiers
void updateIntegrationScope()
Qt::MouseButtons m_lastPressedMouseButton
bool m_isMeasuringDistance
DragDirections m_dragDirections
double m_integrationScopeRhombHeight
QPointF m_lastCursorHoveredPoint
QPointF m_currentDragPoint
void updateIntegrationScopeRect()
double m_yRegionRangeStart
void updateIntegrationScopeRhomb()
bool m_isRightPseudoButtonKeyPressed
Qt::MouseButtons m_pressedMouseButtons
Qt::MouseButtons m_mouseButtonsAtMouseRelease
bool m_isLeftPseudoButtonKeyPressed
double m_integrationScopeRhombWidth
Qt::MouseButtons m_lastReleasedMouseButton
static int zeroDecimalsInValue(pappso_double value)
0.11 would return 0 (no empty decimal) 2.001 would return 2 1000.0001254 would return 3
tries to keep as much as possible monoisotopes, removing any possible C13 peaks and changes multichar...