43 qRegisterMetaType<pappso::BasePlotContext>(
"pappso::BasePlotContext");
45 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.");
110 const QString &x_axis_label,
111 const QString &y_axis_label)
116 if(parent ==
nullptr)
117 qFatal(
"Programming error.");
120 m_pen.setStyle(Qt::SolidLine);
121 m_pen.setBrush(Qt::black);
124 xAxis->setLabel(x_axis_label);
125 yAxis->setLabel(y_axis_label);
144 qFatal(
"Programming error.");
177 for(
int iter = 0; iter < layerCount(); ++iter)
180 QString(
"Layer index %1: %2\n").arg(iter).arg(layer(iter)->name());
189 if(layerable_p ==
nullptr)
190 qFatal(
"Programming error.");
192 QCPLayer *layer_p = layerable_p->layer();
194 return layer_p->name();
200 if(layerable_p ==
nullptr)
201 qFatal(
"Programming error.");
203 QCPLayer *layer_p = layerable_p->layer();
205 for(
int iter = 0; iter < layerCount(); ++iter)
207 if(layer(iter) == layer_p)
229 pen.setColor(QColor(
"steelblue"));
254 pen.setColor(QColor(
"green"));
265 pen.setColor(QColor(
"red"));
296 pen.setColor(
"steelblue");
361 "plotsLayer", layer(
"background"), QCustomPlot::LayerInsertMode::limAbove);
366 setFocusPolicy(Qt::StrongFocus);
367 setInteractions(QCP::iRangeZoom | QCP::iSelectPlottables | QCP::iMultiSelect);
377 &QCustomPlot::mouseRelease,
385 &QCustomPlot::axisDoubleClick,
406 const QColor &new_color)
408 if(plottable_p ==
nullptr)
409 qFatal(
"Pointer cannot be nullptr.");
414 pen = plottable_p->pen();
415 pen.setColor(new_color);
416 plottable_p->setPen(pen);
424 if(!new_color.isValid())
427 QCPGraph *graph_p = graph(index);
429 if(graph_p ==
nullptr)
430 qFatal(
"Programming error.");
438 if(plottable_p ==
nullptr)
439 qFatal(
"Programming error.");
441 return plottable_p->pen().color();
447 QCPGraph *graph_p = graph(index);
449 if(graph_p ==
nullptr)
450 qFatal(
"Programming error.");
458 xAxis->setLabel(label);
464 yAxis->setLabel(label);
562 qFatal(
"Programming error.");
606 m_context.m_pressedKeyCode =
event->key();
607 m_context.m_keyboardModifiers = QGuiApplication::queryKeyboardModifiers();
609 if(event->key() == Qt::Key_Left || event->key() == Qt::Key_Right ||
610 event->key() == Qt::Key_Up || event->key() == Qt::Key_Down)
631 m_context.m_releasedKeyCode =
event->key();
636 m_context.m_keyboardModifiers = QGuiApplication::queryKeyboardModifiers();
639 if(event->key() == Qt::Key_Backspace)
648 else if(event->key() == Qt::Key_Space)
652 else if(event->key() == Qt::Key_Delete)
665 int graph_count = plottableCount();
688 QList<QCPGraph *> selected_graph_list;
690 selected_graph_list = selectedGraphs();
692 if(!selected_graph_list.size())
701 for(
int iter = 0; iter < selected_graph_list.size(); ++iter)
708 this, selected_graph_list.at(iter),
m_context);
721 else if(event->key() == Qt::Key_T)
733 else if(event->key() == Qt::Key_Left || event->key() == Qt::Key_Right ||
734 event->key() == Qt::Key_Up || event->key() == Qt::Key_Down)
743 else if(event->key() == Qt::Key_S)
761 m_context.m_integrationScopeRhombWidth = 0;
762 m_context.m_integrationScopeRhombHeight = abs(
774 m_context.m_integrationScopeRhombWidth = abs(
776 m_context.m_integrationScopeRhombHeight = 0;
813 int pixel_increment = 0;
815 if(
m_context.m_keyboardModifiers == Qt::NoModifier)
817 else if(
m_context.m_keyboardModifiers == Qt::AltModifier)
818 pixel_increment = 50;
824 if(event->key() == Qt::Key_Left)
826 else if(event->key() == Qt::Key_Right)
828 else if(event->key() == Qt::Key_Up)
830 else if(event->key() == Qt::Key_Down)
845 [[maybe_unused]] QKeyEvent *event)
854 QPointF pixel_coordinates(
855 xAxis->coordToPixel(
m_context.m_lastCursorHoveredPoint.x()),
856 yAxis->coordToPixel(
m_context.m_lastCursorHoveredPoint.y()));
858 Qt::MouseButton button = Qt::NoButton;
859 QEvent::Type q_event_type = QEvent::MouseButtonPress;
865 button = Qt::LeftButton;
867 m_context.m_isLeftPseudoButtonKeyPressed =
868 !
m_context.m_isLeftPseudoButtonKeyPressed;
870 if(
m_context.m_isLeftPseudoButtonKeyPressed)
871 q_event_type = QEvent::MouseButtonPress;
873 q_event_type = QEvent::MouseButtonRelease;
879 button = Qt::RightButton;
881 m_context.m_isRightPseudoButtonKeyPressed =
882 !
m_context.m_isRightPseudoButtonKeyPressed;
884 if(
m_context.m_isRightPseudoButtonKeyPressed)
885 q_event_type = QEvent::MouseButtonPress;
887 q_event_type = QEvent::MouseButtonRelease;
895 QMouseEvent *mouse_event_p =
896 new QMouseEvent(q_event_type,
898 mapToGlobal(pixel_coordinates.toPoint()),
899 mapToGlobal(pixel_coordinates.toPoint()),
903 Qt::MouseEventSynthesizedByApplication);
905 if(q_event_type == QEvent::MouseButtonPress)
936 QPointF mousePoint =
event->position();
940 m_context.m_lastCursorHoveredPoint.setX(xAxis->pixelToCoord(mousePoint.x()));
941 m_context.m_lastCursorHoveredPoint.setY(yAxis->pixelToCoord(mousePoint.y()));
951 if(
m_context.m_pressedMouseButtons & Qt::LeftButton ||
952 m_context.m_pressedMouseButtons & Qt::RightButton)
998 xAxis->range().lower,
m_context.m_lastCursorHoveredPoint.y());
1000 xAxis->range().upper,
m_context.m_lastCursorHoveredPoint.y());
1011 m_context.m_lastCursorHoveredPoint.x(), yAxis->range().upper);
1013 m_context.m_lastCursorHoveredPoint.x(), yAxis->range().lower);
1034 m_context.m_keyboardModifiers = QGuiApplication::queryKeyboardModifiers();
1052 yAxis->range().upper);
1055 yAxis->range().lower);
1098 if(
m_context.m_mouseButtonsAtMousePress & Qt::LeftButton)
1102 else if(
m_context.m_mouseButtonsAtMousePress & Qt::RightButton)
1120 m_context.m_isMeasuringDistance =
false;
1129 if(
m_context.m_keyboardModifiers & Qt::ControlModifier)
1151 if(
m_context.m_pressedKeyCode == Qt::Key_Q)
1254 m_context.m_isMeasuringDistance =
false;
1301 QPointF mousePoint =
event->position();
1303 m_context.m_lastPressedMouseButton =
event->button();
1304 m_context.m_mouseButtonsAtMousePress =
event->buttons();
1308 m_context.m_pressedMouseButtons |=
event->button();
1383 m_context.m_startDragPoint.setX(xAxis->pixelToCoord(mousePoint.x()));
1384 m_context.m_startDragPoint.setY(yAxis->pixelToCoord(mousePoint.y()));
1394 m_context.m_lastCursorHoveredPoint.x(), yAxis->range().upper);
1396 m_context.m_lastCursorHoveredPoint.x(), yAxis->range().lower);
1415 m_context.m_lastReleasedMouseButton =
event->button();
1420 m_context.m_mouseButtonsAtMouseRelease =
event->buttons();
1424 m_context.m_pressedMouseButtons ^=
event->button();
1430 m_context.m_keyboardModifiers = QGuiApplication::keyboardModifiers();
1460 m_context.m_lastCursorHoveredPoint.y());
1462 m_context.m_lastCursorHoveredPoint.y());
1469 yAxis->range().upper);
1471 yAxis->range().lower);
1493 if(
m_context.m_lastReleasedMouseButton == Qt::LeftButton)
1497 else if(
m_context.m_lastReleasedMouseButton == Qt::RightButton)
1588 if(
m_context.m_keyboardModifiers & Qt::ControlModifier)
1625 double x_delta_pixel =
1626 fabs(xAxis->coordToPixel(
m_context.m_currentDragPoint.x()) -
1627 xAxis->coordToPixel(
m_context.m_startDragPoint.x()));
1629 if(x_delta_pixel > 3)
1644 m_context.m_xRange = QCPRange(xAxis->range());
1645 m_context.m_yRange = QCPRange(yAxis->range());
1661 [[maybe_unused]] QCPAxis::SelectablePart part,
1666 m_context.m_keyboardModifiers = QGuiApplication::queryKeyboardModifiers();
1668 if(
m_context.m_keyboardModifiers & Qt::ControlModifier)
1697 m_context.m_pressedMouseButtons ^=
event->button();
1709 QCPLayoutElement *layoutElement = layoutElementAt(mousePoint);
1712 layoutElement ==
dynamic_cast<QCPLayoutElement *
>(axisRect()))
1718 QCPAxis::SelectablePart selectablePart;
1720 selectablePart = xAxis->getPartAt(mousePoint);
1722 if(selectablePart == QCPAxis::spAxisLabel ||
1723 selectablePart == QCPAxis::spAxis ||
1724 selectablePart == QCPAxis::spTickLabels)
1734 QCPLayoutElement *layoutElement = layoutElementAt(mousePoint);
1737 layoutElement ==
dynamic_cast<QCPLayoutElement *
>(axisRect()))
1743 QCPAxis::SelectablePart selectablePart;
1745 selectablePart = yAxis->getPartAt(mousePoint);
1747 if(selectablePart == QCPAxis::spAxisLabel ||
1748 selectablePart == QCPAxis::spAxis ||
1749 selectablePart == QCPAxis::spTickLabels)
1774 double x_delta_pixel =
1775 fabs(xAxis->coordToPixel(
m_context.m_currentDragPoint.x()) -
1776 xAxis->coordToPixel(
m_context.m_startDragPoint.x()));
1778 double y_delta_pixel =
1779 fabs(yAxis->coordToPixel(
m_context.m_currentDragPoint.y()) -
1780 yAxis->coordToPixel(
m_context.m_startDragPoint.y()));
1782 if(x_delta_pixel > y_delta_pixel)
1783 return Qt::Horizontal;
1785 return Qt::Vertical;
1793 QPointF pixels_coordinates(xAxis->coordToPixel(graph_coordinates.x()),
1794 yAxis->coordToPixel(graph_coordinates.y()));
1803 QCursor::setPos(mapToGlobal(pixel_coordinates.toPoint()));
1811 QPointF pixel_coord(xAxis->coordToPixel(graph_coord.x()),
1812 yAxis->coordToPixel(graph_coord.y()));
1824 QPointF pixel_coordinates(
1825 xAxis->coordToPixel(
m_context.m_lastCursorHoveredPoint.x()) + pixel_count,
1826 yAxis->coordToPixel(
m_context.m_lastCursorHoveredPoint.y()));
1830 QPointF graph_coordinates(xAxis->pixelToCoord(pixel_coordinates.x()),
1831 yAxis->pixelToCoord(pixel_coordinates.y()));
1833 return graph_coordinates;
1842 QPointF pixel_coord(xAxis->coordToPixel(graph_coord.x()),
1843 yAxis->coordToPixel(graph_coord.y()));
1855 QPointF pixel_coordinates(
1856 xAxis->coordToPixel(
m_context.m_lastCursorHoveredPoint.x()),
1857 yAxis->coordToPixel(
m_context.m_lastCursorHoveredPoint.y()) + pixel_count);
1861 QPointF graph_coordinates(xAxis->pixelToCoord(pixel_coordinates.x()),
1862 yAxis->pixelToCoord(pixel_coordinates.y()));
1864 return graph_coordinates;
1875 QCPGraph *graph_p = graph(index);
1877 if(graph_p ==
nullptr)
1878 qFatal(
"Programming error.");
1880 return graph_p->getKeyRange(found_range);
1886 QCPGraph *graph_p = graph(index);
1888 if(graph_p ==
nullptr)
1889 qFatal(
"Programming error.");
1891 return graph_p->getValueRange(found_range);
1897 bool &found_range)
const
1906 found_range =
false;
1908 return QCPRange(0, 1);
1911 if(graphCount() == 1)
1912 return graph()->getKeyRange(found_range);
1914 bool found_at_least_one_range =
false;
1917 QCPRange result_range(QCPRange::minRange + 1, QCPRange::maxRange + 1);
1919 for(
int iter = 0; iter < graphCount(); ++iter)
1921 QCPRange temp_range;
1923 bool found_range_for_iter =
false;
1925 QCPGraph *graph_p = graph(iter);
1930 temp_range = graph_p->getKeyRange(found_range_for_iter);
1932 temp_range = graph_p->getValueRange(found_range_for_iter);
1934 qFatal(
"Cannot reach this point. Programming error.");
1939 if(!found_range_for_iter)
1945 if(!QCPRange::validRange(result_range))
1946 qFatal(
"The obtained range is invalid !");
1949 result_range = temp_range;
1952 found_at_least_one_range =
true;
1959 if(temp_range.lower > result_range.lower)
1960 result_range.lower = temp_range.lower;
1961 if(temp_range.upper < result_range.upper)
1962 result_range.upper = temp_range.upper;
1966 if(temp_range.lower < result_range.lower)
1967 result_range.lower = temp_range.lower;
1968 if(temp_range.upper > result_range.upper)
1969 result_range.upper = temp_range.upper;
1972 qFatal(
"Cannot reach this point. Programming error.");
1980 found_range = found_at_least_one_range;
1982 return result_range;
2021 double xLower = xAxis->range().lower;
2022 double xUpper = xAxis->range().upper;
2026 double yLower = yAxis->range().lower;
2027 double yUpper = yAxis->range().upper;
2047 xAxis->setRange(xLower, xUpper -
m_context.m_xDelta);
2057 yAxis->setRange(yLower, yUpper -
m_context.m_yDelta);
2089 yAxis->setRange(xAxis->range().lower,
2090 std::max<double>(
m_context.m_yRegionRangeStart,
2134 "This function can only be called if the mouse click was on one of the "
2169 QCPRange yAxisRange,
2176 xAxis->setRange(xAxisRange.lower, xAxisRange.upper);
2181 yAxis->setRange(yAxisRange.lower, yAxisRange.upper);
2197 xAxis->setRange(lower, upper);
2207 yAxis->setRange(lower, upper);
2267 bool for_integration)
2287 m_context.m_isMeasuringDistance =
false;
2332 QPointF leftmost_point;
2333 if(!
m_context.msp_integrationScope->getLeftMostPoint(leftmost_point))
2334 qFatal(
"Could not get the left-most point.");
2337 if(!
m_context.msp_integrationScope->getWidth(width))
2338 qFatal(
"Could not get width.");
2341 double x_axis_center_position = leftmost_point.x() + width / 2;
2351 int pixels_away_from_line = 15;
2353 QPointF reference_point_for_y_axis_label_position;
2358 if(
static_cast<int>(
m_context.m_dragDirections) &
2367 pixels_away_from_line *= -1;
2369 if(!
m_context.msp_integrationScope->getTopMostPoint(
2370 reference_point_for_y_axis_label_position))
2371 qFatal(
"Failed to get top most point.");
2375 if(!
m_context.msp_integrationScope->getBottomMostPoint(
2376 reference_point_for_y_axis_label_position))
2377 qFatal(
"Failed to get bottom most point.");
2382 double y_axis_pixel_coordinate =
2383 yAxis->coordToPixel(reference_point_for_y_axis_label_position.y());
2387 double y_axis_modified_pixel_coordinate =
2388 y_axis_pixel_coordinate + pixels_away_from_line;
2391 QPointF pixel_coordinates;
2393 pixel_coordinates.setX(x_axis_center_position);
2394 pixel_coordinates.setY(y_axis_modified_pixel_coordinate);
2397 QPointF graph_coordinates(xAxis->pixelToCoord(pixel_coordinates.x()),
2398 yAxis->pixelToCoord(pixel_coordinates.y()));
2405 graph_coordinates.y());
2416 QString label_text = QString(
"full x span %1 -- x drag delta %2")
2417 .arg(width, 0,
'f', decimals)
2418 .arg(fabs(
m_context.m_xDelta), 0,
'f', decimals);
2446 if(!
m_context.msp_integrationScope->getHeight(height))
2447 qFatal(
"Could not get height.");
2464 QPointF bottom_most_point;
2465 if(!
m_context.msp_integrationScope->getBottomMostPoint(bottom_most_point))
2466 qFatal(
"Could not get the bottom-most bottom point.");
2468 double y_axis_center_position = bottom_most_point.y() + height / 2;
2478 int pixels_away_from_line = 15;
2479 double x_axis_coordinate;
2480 double x_axis_pixel_coordinate;
2482 if(
static_cast<int>(
m_context.m_dragDirections) &
2485 QPointF left_most_point;
2487 if(!
m_context.msp_integrationScope->getLeftMostPoint(left_most_point))
2488 qFatal(
"Failed to get left most point.");
2490 x_axis_coordinate = left_most_point.x();
2492 pixels_away_from_line *= -1;
2496 QPointF right_most_point;
2498 if(!
m_context.msp_integrationScope->getRightMostPoint(right_most_point))
2499 qFatal(
"Failed to get right most point.");
2501 x_axis_coordinate = right_most_point.x();
2503 x_axis_pixel_coordinate = xAxis->coordToPixel(x_axis_coordinate);
2505 double x_axis_modified_pixel_coordinate =
2506 x_axis_pixel_coordinate + pixels_away_from_line;
2509 QPointF pixel_coordinates;
2511 pixel_coordinates.setX(x_axis_modified_pixel_coordinate);
2512 pixel_coordinates.setY(y_axis_center_position);
2516 QPointF graph_coordinates(xAxis->pixelToCoord(pixel_coordinates.x()),
2517 yAxis->pixelToCoord(pixel_coordinates.y()));
2520 y_axis_center_position);
2524 QString label_text = QString(
"full y span %1 -- y drag delta %2")
2525 .arg(height, 0,
'f', decimals)
2526 .arg(fabs(
m_context.m_yDelta), 0,
'f', decimals);
2568 double plotHeight = yAxis->range().upper - yAxis->range().lower;
2573 double heightDiffRatio = (heightDiff / plotHeight) * 100;
2575 if(heightDiffRatio > 10)
2594 double x_range_start =
2596 double x_range_end =
2602 double y_position =
m_context.m_startDragPoint.y();
2608 QPointF(x_range_start, y_position));
2633 QPointF(x_range_start, y_position));
2664 QPointF bottom_left_point;
2665 if(!
m_context.msp_integrationScope->getPoint(bottom_left_point))
2666 qFatal(
"Failed to get point.");
2670 if(!
m_context.msp_integrationScope->getWidth(width))
2671 qFatal(
"Failed to get width.");
2675 if(!
m_context.msp_integrationScope->getHeight(height))
2676 qFatal(
"Failed to get height.");
2679 QPointF bottom_right_point(bottom_left_point.x() + width,
2680 bottom_left_point.y());
2683 QPointF top_right_point(bottom_left_point.x() + width,
2684 bottom_left_point.y() + height);
2687 QPointF top_left_point(bottom_left_point.x(), bottom_left_point.y() + height);
2758 scope_features =
m_context.msp_integrationScope->getLeftMostTopPoint(point_1);
2778 qFatal(
"The rhomboid should be horizontal!");
2782 if(!
m_context.msp_integrationScope->getLeftMostTopPoint(point_1))
2783 qFatal(
"Failed to getLeftMostTopPoint.");
2785 if(!
m_context.msp_integrationScope->getRightMostTopPoint(point_2))
2786 qFatal(
"Failed to getRightMostTopPoint.");
2809 if(!
m_context.msp_integrationScope->getRightMostBottomPoint(point_1))
2810 qFatal(
"Failed to getRightMostBottomPoint.");
2818 if(!
m_context.msp_integrationScope->getLeftMostBottomPoint(point_2))
2819 qFatal(
"Failed to getLeftMostBottomPoint.");
2827 if(!
m_context.msp_integrationScope->getLeftMostTopPoint(point_1))
2828 qFatal(
"Failed to getLeftMostTopPoint.");
2870 scope_features =
m_context.msp_integrationScope->getLeftMostTopPoint(point_1);
2890 qFatal(
"The rhomboid should be vertical!");
2895 if(!
m_context.msp_integrationScope->getLeftMostBottomPoint(point_2))
2896 qFatal(
"Failed to getLeftMostBottomPoint.");
2920 if(!
m_context.msp_integrationScope->getRightMostBottomPoint(point_1))
2921 qFatal(
"Failed to getRightMostBottomPoint.");
2930 if(!
m_context.msp_integrationScope->getRightMostTopPoint(point_2))
2931 qFatal(
"Failed to getRightMostTopPoint.");
2940 if(!
m_context.msp_integrationScope->getLeftMostTopPoint(point_1))
2941 qFatal(
"Failed to get the LeftMostTopPoint.");
3010 m_context.updateIntegrationScopeRhomb();
3028 if(
m_context.m_integrationScopeRhombWidth > 0)
3031 else if(
m_context.m_integrationScopeRhombHeight > 0)
3035 qFatal(
"Cannot be both the width or height of rhomboid scope be 0.");
3040 bool for_integration)
3066 if(!(
m_context.m_keyboardModifiers & Qt::AltModifier))
3072 else if(
m_context.m_keyboardModifiers & Qt::AltModifier)
3078 if(!
m_context.m_integrationScopeRhombHeight &&
3079 !
m_context.m_integrationScopeRhombWidth)
3095 std::vector<QPointF> points;
3103 if(
m_context.msp_integrationScope->getPoints(points))
3107 if(!
m_context.msp_integrationScope->getLeftMostPoint(point))
3108 qFatal(
"Failed to get LeftMost point.");
3109 m_context.m_xRegionRangeStart = point.x();
3111 if(!
m_context.msp_integrationScope->getRightMostPoint(point))
3112 qFatal(
"Failed to get RightMost point.");
3113 m_context.m_xRegionRangeEnd = point.x();
3115 else if(
m_context.msp_integrationScope->getHeight(height))
3119 if(!
m_context.msp_integrationScope->getPoint(point))
3120 qFatal(
"Failed to get point.");
3121 m_context.m_xRegionRangeStart = point.x();
3125 if(!
m_context.msp_integrationScope->getWidth(width))
3126 qFatal(
"Failed to get width.");
3130 m_context.m_yRegionRangeStart = point.y();
3132 m_context.m_yRegionRangeEnd = point.y() + height;
3138 if(!
m_context.msp_integrationScope->getPoint(point))
3139 qFatal(
"Failed to get point.");
3140 m_context.m_xRegionRangeStart = point.x();
3144 if(!
m_context.msp_integrationScope->getWidth(width))
3145 qFatal(
"Failed to get width.");
3175 std::const_pointer_cast<IntegrationScopeBase>(
m_context.msp_integrationScope)
3185 int current_selection_polygon =
3190 current_selection_polygon |=
3197 current_selection_polygon |=
3204 current_selection_polygon |=
3211 current_selection_polygon |=
3244 QCustomPlot::setFocus();
3255 if(focusedPlotWidget ==
nullptr)
3257 "baseplotwidget.cpp @ redrawPlotBackground(QWidget *focusedPlotWidget "
3259 "ERROR focusedPlotWidget cannot be nullptr.");
3261 if(
dynamic_cast<QWidget *
>(
this) != focusedPlotWidget)
3280 m_context.m_xRange = QCPRange(xAxis->range().lower, xAxis->range().upper);
3281 m_context.m_yRange = QCPRange(yAxis->range().lower, yAxis->range().upper);
static int zeroDecimalsInValue(pappso_double value)
Determine the number of zero decimals between the decimal point and the first non-zero decimal.
tries to keep as much as possible monoisotopes, removing any possible C13 peaks and changes multichar...