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)
910 delete mouse_event_p;
937 QPointF mousePoint =
event->position();
941 m_context.m_lastCursorHoveredPoint.setX(xAxis->pixelToCoord(mousePoint.x()));
942 m_context.m_lastCursorHoveredPoint.setY(yAxis->pixelToCoord(mousePoint.y()));
952 if(
m_context.m_pressedMouseButtons & Qt::LeftButton ||
953 m_context.m_pressedMouseButtons & Qt::RightButton)
999 xAxis->range().lower,
m_context.m_lastCursorHoveredPoint.y());
1001 xAxis->range().upper,
m_context.m_lastCursorHoveredPoint.y());
1012 m_context.m_lastCursorHoveredPoint.x(), yAxis->range().upper);
1014 m_context.m_lastCursorHoveredPoint.x(), yAxis->range().lower);
1035 m_context.m_keyboardModifiers = QGuiApplication::queryKeyboardModifiers();
1053 yAxis->range().upper);
1056 yAxis->range().lower);
1099 if(
m_context.m_mouseButtonsAtMousePress & Qt::LeftButton)
1103 else if(
m_context.m_mouseButtonsAtMousePress & Qt::RightButton)
1121 m_context.m_isMeasuringDistance =
false;
1130 if(
m_context.m_keyboardModifiers & Qt::ControlModifier)
1152 if(
m_context.m_pressedKeyCode == Qt::Key_Q)
1255 m_context.m_isMeasuringDistance =
false;
1302 QPointF mousePoint =
event->position();
1304 m_context.m_lastPressedMouseButton =
event->button();
1305 m_context.m_mouseButtonsAtMousePress =
event->buttons();
1309 m_context.m_pressedMouseButtons |=
event->button();
1384 m_context.m_startDragPoint.setX(xAxis->pixelToCoord(mousePoint.x()));
1385 m_context.m_startDragPoint.setY(yAxis->pixelToCoord(mousePoint.y()));
1395 m_context.m_lastCursorHoveredPoint.x(), yAxis->range().upper);
1397 m_context.m_lastCursorHoveredPoint.x(), yAxis->range().lower);
1416 m_context.m_lastReleasedMouseButton =
event->button();
1421 m_context.m_mouseButtonsAtMouseRelease =
event->buttons();
1425 m_context.m_pressedMouseButtons ^=
event->button();
1431 m_context.m_keyboardModifiers = QGuiApplication::keyboardModifiers();
1461 m_context.m_lastCursorHoveredPoint.y());
1463 m_context.m_lastCursorHoveredPoint.y());
1470 yAxis->range().upper);
1472 yAxis->range().lower);
1494 if(
m_context.m_lastReleasedMouseButton == Qt::LeftButton)
1498 else if(
m_context.m_lastReleasedMouseButton == Qt::RightButton)
1589 if(
m_context.m_keyboardModifiers & Qt::ControlModifier)
1626 double x_delta_pixel =
1627 fabs(xAxis->coordToPixel(
m_context.m_currentDragPoint.x()) -
1628 xAxis->coordToPixel(
m_context.m_startDragPoint.x()));
1630 if(x_delta_pixel > 3)
1645 m_context.m_xRange = QCPRange(xAxis->range());
1646 m_context.m_yRange = QCPRange(yAxis->range());
1662 [[maybe_unused]] QCPAxis::SelectablePart part,
1667 m_context.m_keyboardModifiers = QGuiApplication::queryKeyboardModifiers();
1669 if(
m_context.m_keyboardModifiers & Qt::ControlModifier)
1698 m_context.m_pressedMouseButtons ^=
event->button();
1710 QCPLayoutElement *layoutElement = layoutElementAt(mousePoint);
1713 layoutElement ==
dynamic_cast<QCPLayoutElement *
>(axisRect()))
1719 QCPAxis::SelectablePart selectablePart;
1721 selectablePart = xAxis->getPartAt(mousePoint);
1723 if(selectablePart == QCPAxis::spAxisLabel ||
1724 selectablePart == QCPAxis::spAxis ||
1725 selectablePart == QCPAxis::spTickLabels)
1735 QCPLayoutElement *layoutElement = layoutElementAt(mousePoint);
1738 layoutElement ==
dynamic_cast<QCPLayoutElement *
>(axisRect()))
1744 QCPAxis::SelectablePart selectablePart;
1746 selectablePart = yAxis->getPartAt(mousePoint);
1748 if(selectablePart == QCPAxis::spAxisLabel ||
1749 selectablePart == QCPAxis::spAxis ||
1750 selectablePart == QCPAxis::spTickLabels)
1775 double x_delta_pixel =
1776 fabs(xAxis->coordToPixel(
m_context.m_currentDragPoint.x()) -
1777 xAxis->coordToPixel(
m_context.m_startDragPoint.x()));
1779 double y_delta_pixel =
1780 fabs(yAxis->coordToPixel(
m_context.m_currentDragPoint.y()) -
1781 yAxis->coordToPixel(
m_context.m_startDragPoint.y()));
1783 if(x_delta_pixel > y_delta_pixel)
1784 return Qt::Horizontal;
1786 return Qt::Vertical;
1794 QPointF pixels_coordinates(xAxis->coordToPixel(graph_coordinates.x()),
1795 yAxis->coordToPixel(graph_coordinates.y()));
1804 QCursor::setPos(mapToGlobal(pixel_coordinates.toPoint()));
1812 QPointF pixel_coord(xAxis->coordToPixel(graph_coord.x()),
1813 yAxis->coordToPixel(graph_coord.y()));
1825 QPointF pixel_coordinates(
1826 xAxis->coordToPixel(
m_context.m_lastCursorHoveredPoint.x()) + pixel_count,
1827 yAxis->coordToPixel(
m_context.m_lastCursorHoveredPoint.y()));
1831 QPointF graph_coordinates(xAxis->pixelToCoord(pixel_coordinates.x()),
1832 yAxis->pixelToCoord(pixel_coordinates.y()));
1834 return graph_coordinates;
1843 QPointF pixel_coord(xAxis->coordToPixel(graph_coord.x()),
1844 yAxis->coordToPixel(graph_coord.y()));
1856 QPointF pixel_coordinates(
1857 xAxis->coordToPixel(
m_context.m_lastCursorHoveredPoint.x()),
1858 yAxis->coordToPixel(
m_context.m_lastCursorHoveredPoint.y()) + pixel_count);
1862 QPointF graph_coordinates(xAxis->pixelToCoord(pixel_coordinates.x()),
1863 yAxis->pixelToCoord(pixel_coordinates.y()));
1865 return graph_coordinates;
1876 QCPGraph *graph_p = graph(index);
1878 if(graph_p ==
nullptr)
1879 qFatal(
"Programming error.");
1881 return graph_p->getKeyRange(found_range);
1887 QCPGraph *graph_p = graph(index);
1889 if(graph_p ==
nullptr)
1890 qFatal(
"Programming error.");
1892 return graph_p->getValueRange(found_range);
1898 bool &found_range)
const
1907 found_range =
false;
1909 return QCPRange(0, 1);
1912 if(graphCount() == 1)
1913 return graph()->getKeyRange(found_range);
1915 bool found_at_least_one_range =
false;
1918 QCPRange result_range(QCPRange::minRange + 1, QCPRange::maxRange + 1);
1920 for(
int iter = 0; iter < graphCount(); ++iter)
1922 QCPRange temp_range;
1924 bool found_range_for_iter =
false;
1926 QCPGraph *graph_p = graph(iter);
1931 temp_range = graph_p->getKeyRange(found_range_for_iter);
1933 temp_range = graph_p->getValueRange(found_range_for_iter);
1935 qFatal(
"Cannot reach this point. Programming error.");
1940 if(!found_range_for_iter)
1946 if(!QCPRange::validRange(result_range))
1947 qFatal(
"The obtained range is invalid !");
1950 result_range = temp_range;
1953 found_at_least_one_range =
true;
1960 if(temp_range.lower > result_range.lower)
1961 result_range.lower = temp_range.lower;
1962 if(temp_range.upper < result_range.upper)
1963 result_range.upper = temp_range.upper;
1967 if(temp_range.lower < result_range.lower)
1968 result_range.lower = temp_range.lower;
1969 if(temp_range.upper > result_range.upper)
1970 result_range.upper = temp_range.upper;
1973 qFatal(
"Cannot reach this point. Programming error.");
1981 found_range = found_at_least_one_range;
1983 return result_range;
2022 double xLower = xAxis->range().lower;
2023 double xUpper = xAxis->range().upper;
2027 double yLower = yAxis->range().lower;
2028 double yUpper = yAxis->range().upper;
2048 xAxis->setRange(xLower, xUpper -
m_context.m_xDelta);
2058 yAxis->setRange(yLower, yUpper -
m_context.m_yDelta);
2090 yAxis->setRange(xAxis->range().lower,
2091 std::max<double>(
m_context.m_yRegionRangeStart,
2135 "This function can only be called if the mouse click was on one of the "
2170 QCPRange yAxisRange,
2177 xAxis->setRange(xAxisRange.lower, xAxisRange.upper);
2182 yAxis->setRange(yAxisRange.lower, yAxisRange.upper);
2198 xAxis->setRange(lower, upper);
2208 yAxis->setRange(lower, upper);
2268 bool for_integration)
2288 m_context.m_isMeasuringDistance =
false;
2333 QPointF leftmost_point;
2334 if(!
m_context.msp_integrationScope->getLeftMostPoint(leftmost_point))
2335 qFatal(
"Could not get the left-most point.");
2338 if(!
m_context.msp_integrationScope->getWidth(width))
2339 qFatal(
"Could not get width.");
2342 double x_axis_center_position = leftmost_point.x() + width / 2;
2352 int pixels_away_from_line = 15;
2354 QPointF reference_point_for_y_axis_label_position;
2359 if(
static_cast<int>(
m_context.m_dragDirections) &
2368 pixels_away_from_line *= -1;
2370 if(!
m_context.msp_integrationScope->getTopMostPoint(
2371 reference_point_for_y_axis_label_position))
2372 qFatal(
"Failed to get top most point.");
2376 if(!
m_context.msp_integrationScope->getBottomMostPoint(
2377 reference_point_for_y_axis_label_position))
2378 qFatal(
"Failed to get bottom most point.");
2383 double y_axis_pixel_coordinate =
2384 yAxis->coordToPixel(reference_point_for_y_axis_label_position.y());
2388 double y_axis_modified_pixel_coordinate =
2389 y_axis_pixel_coordinate + pixels_away_from_line;
2392 QPointF pixel_coordinates;
2394 pixel_coordinates.setX(x_axis_center_position);
2395 pixel_coordinates.setY(y_axis_modified_pixel_coordinate);
2398 QPointF graph_coordinates(xAxis->pixelToCoord(pixel_coordinates.x()),
2399 yAxis->pixelToCoord(pixel_coordinates.y()));
2406 graph_coordinates.y());
2417 QString label_text = QString(
"full x span %1 -- x drag delta %2")
2418 .arg(width, 0,
'f', decimals)
2419 .arg(fabs(
m_context.m_xDelta), 0,
'f', decimals);
2447 if(!
m_context.msp_integrationScope->getHeight(height))
2448 qFatal(
"Could not get height.");
2465 QPointF bottom_most_point;
2466 if(!
m_context.msp_integrationScope->getBottomMostPoint(bottom_most_point))
2467 qFatal(
"Could not get the bottom-most bottom point.");
2469 double y_axis_center_position = bottom_most_point.y() + height / 2;
2479 int pixels_away_from_line = 15;
2480 double x_axis_coordinate;
2481 double x_axis_pixel_coordinate;
2483 if(
static_cast<int>(
m_context.m_dragDirections) &
2486 QPointF left_most_point;
2488 if(!
m_context.msp_integrationScope->getLeftMostPoint(left_most_point))
2489 qFatal(
"Failed to get left most point.");
2491 x_axis_coordinate = left_most_point.x();
2493 pixels_away_from_line *= -1;
2497 QPointF right_most_point;
2499 if(!
m_context.msp_integrationScope->getRightMostPoint(right_most_point))
2500 qFatal(
"Failed to get right most point.");
2502 x_axis_coordinate = right_most_point.x();
2504 x_axis_pixel_coordinate = xAxis->coordToPixel(x_axis_coordinate);
2506 double x_axis_modified_pixel_coordinate =
2507 x_axis_pixel_coordinate + pixels_away_from_line;
2510 QPointF pixel_coordinates;
2512 pixel_coordinates.setX(x_axis_modified_pixel_coordinate);
2513 pixel_coordinates.setY(y_axis_center_position);
2517 QPointF graph_coordinates(xAxis->pixelToCoord(pixel_coordinates.x()),
2518 yAxis->pixelToCoord(pixel_coordinates.y()));
2521 y_axis_center_position);
2525 QString label_text = QString(
"full y span %1 -- y drag delta %2")
2526 .arg(height, 0,
'f', decimals)
2527 .arg(fabs(
m_context.m_yDelta), 0,
'f', decimals);
2569 double plotHeight = yAxis->range().upper - yAxis->range().lower;
2574 double heightDiffRatio = (heightDiff / plotHeight) * 100;
2576 if(heightDiffRatio > 10)
2595 double x_range_start =
2597 double x_range_end =
2603 double y_position =
m_context.m_startDragPoint.y();
2609 QPointF(x_range_start, y_position));
2634 QPointF(x_range_start, y_position));
2665 QPointF bottom_left_point;
2666 if(!
m_context.msp_integrationScope->getPoint(bottom_left_point))
2667 qFatal(
"Failed to get point.");
2671 if(!
m_context.msp_integrationScope->getWidth(width))
2672 qFatal(
"Failed to get width.");
2676 if(!
m_context.msp_integrationScope->getHeight(height))
2677 qFatal(
"Failed to get height.");
2680 QPointF bottom_right_point(bottom_left_point.x() + width,
2681 bottom_left_point.y());
2684 QPointF top_right_point(bottom_left_point.x() + width,
2685 bottom_left_point.y() + height);
2688 QPointF top_left_point(bottom_left_point.x(), bottom_left_point.y() + height);
2759 scope_features =
m_context.msp_integrationScope->getLeftMostTopPoint(point_1);
2779 qFatal(
"The rhomboid should be horizontal!");
2783 if(!
m_context.msp_integrationScope->getLeftMostTopPoint(point_1))
2784 qFatal(
"Failed to getLeftMostTopPoint.");
2786 if(!
m_context.msp_integrationScope->getRightMostTopPoint(point_2))
2787 qFatal(
"Failed to getRightMostTopPoint.");
2810 if(!
m_context.msp_integrationScope->getRightMostBottomPoint(point_1))
2811 qFatal(
"Failed to getRightMostBottomPoint.");
2819 if(!
m_context.msp_integrationScope->getLeftMostBottomPoint(point_2))
2820 qFatal(
"Failed to getLeftMostBottomPoint.");
2828 if(!
m_context.msp_integrationScope->getLeftMostTopPoint(point_1))
2829 qFatal(
"Failed to getLeftMostTopPoint.");
2871 scope_features =
m_context.msp_integrationScope->getLeftMostTopPoint(point_1);
2891 qFatal(
"The rhomboid should be vertical!");
2896 if(!
m_context.msp_integrationScope->getLeftMostBottomPoint(point_2))
2897 qFatal(
"Failed to getLeftMostBottomPoint.");
2921 if(!
m_context.msp_integrationScope->getRightMostBottomPoint(point_1))
2922 qFatal(
"Failed to getRightMostBottomPoint.");
2931 if(!
m_context.msp_integrationScope->getRightMostTopPoint(point_2))
2932 qFatal(
"Failed to getRightMostTopPoint.");
2941 if(!
m_context.msp_integrationScope->getLeftMostTopPoint(point_1))
2942 qFatal(
"Failed to get the LeftMostTopPoint.");
3011 m_context.updateIntegrationScopeRhomb();
3029 if(
m_context.m_integrationScopeRhombWidth > 0)
3032 else if(
m_context.m_integrationScopeRhombHeight > 0)
3036 qFatal(
"Cannot be both the width or height of rhomboid scope be 0.");
3041 bool for_integration)
3067 if(!(
m_context.m_keyboardModifiers & Qt::AltModifier))
3073 else if(
m_context.m_keyboardModifiers & Qt::AltModifier)
3079 if(!
m_context.m_integrationScopeRhombHeight &&
3080 !
m_context.m_integrationScopeRhombWidth)
3096 std::vector<QPointF> points;
3104 if(
m_context.msp_integrationScope->getPoints(points))
3108 if(!
m_context.msp_integrationScope->getLeftMostPoint(point))
3109 qFatal(
"Failed to get LeftMost point.");
3110 m_context.m_xRegionRangeStart = point.x();
3112 if(!
m_context.msp_integrationScope->getRightMostPoint(point))
3113 qFatal(
"Failed to get RightMost point.");
3114 m_context.m_xRegionRangeEnd = point.x();
3116 else if(
m_context.msp_integrationScope->getHeight(height))
3120 if(!
m_context.msp_integrationScope->getPoint(point))
3121 qFatal(
"Failed to get point.");
3122 m_context.m_xRegionRangeStart = point.x();
3126 if(!
m_context.msp_integrationScope->getWidth(width))
3127 qFatal(
"Failed to get width.");
3131 m_context.m_yRegionRangeStart = point.y();
3133 m_context.m_yRegionRangeEnd = point.y() + height;
3139 if(!
m_context.msp_integrationScope->getPoint(point))
3140 qFatal(
"Failed to get point.");
3141 m_context.m_xRegionRangeStart = point.x();
3145 if(!
m_context.msp_integrationScope->getWidth(width))
3146 qFatal(
"Failed to get width.");
3176 std::const_pointer_cast<IntegrationScopeBase>(
m_context.msp_integrationScope)
3186 int current_selection_polygon =
3191 current_selection_polygon |=
3198 current_selection_polygon |=
3205 current_selection_polygon |=
3212 current_selection_polygon |=
3245 QCustomPlot::setFocus();
3256 if(focusedPlotWidget ==
nullptr)
3258 "baseplotwidget.cpp @ redrawPlotBackground(QWidget *focusedPlotWidget "
3260 "ERROR focusedPlotWidget cannot be nullptr.");
3262 if(
dynamic_cast<QWidget *
>(
this) != focusedPlotWidget)
3281 m_context.m_xRange = QCPRange(xAxis->range().lower, xAxis->range().upper);
3282 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...