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)
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)
183 text += 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)
234 pen.setColor(QColor(
"steelblue"));
259 pen.setColor(QColor(
"green"));
270 pen.setColor(QColor(
"red"));
301 pen.setColor(
"steelblue");
366 addLayer(
"plotsLayer", layer(
"background"), QCustomPlot::LayerInsertMode::limAbove);
371 setFocusPolicy(Qt::StrongFocus);
372 setInteractions(QCP::iRangeZoom | QCP::iSelectPlottables | QCP::iMultiSelect);
406 if(plottable_p ==
nullptr)
407 qFatal(
"Pointer cannot be nullptr.");
412 pen = plottable_p->pen();
413 pen.setColor(new_color);
414 plottable_p->setPen(pen);
423 if(!new_color.isValid())
426 QCPGraph *graph_p = graph(index);
428 if(graph_p ==
nullptr)
429 qFatal(
"Programming error.");
438 if(plottable_p ==
nullptr)
439 qFatal(
"Programming error.");
441 return plottable_p->pen().color();
448 QCPGraph *graph_p = graph(index);
450 if(graph_p ==
nullptr)
451 qFatal(
"Programming error.");
460 xAxis->setLabel(label);
467 yAxis->setLabel(label);
569 qFatal(
"Programming error.");
612 m_context.m_pressedKeyCode =
event->key();
613 m_context.m_keyboardModifiers = QGuiApplication::queryKeyboardModifiers();
615 if(event->key() == Qt::Key_Left || event->key() == Qt::Key_Right || event->key() == Qt::Key_Up ||
616 event->key() == Qt::Key_Down)
637 m_context.m_releasedKeyCode =
event->key();
642 m_context.m_keyboardModifiers = QGuiApplication::queryKeyboardModifiers();
645 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)
748 else if(event->key() == Qt::Key_S)
766 m_context.m_integrationScopeRhombWidth = 0;
767 m_context.m_integrationScopeRhombHeight =
781 m_context.m_integrationScopeRhombHeight = 0;
820 int pixel_increment = 0;
822 if(
m_context.m_keyboardModifiers == Qt::NoModifier)
824 else if(
m_context.m_keyboardModifiers == Qt::AltModifier)
825 pixel_increment = 50;
831 if(event->key() == Qt::Key_Left)
833 else if(event->key() == Qt::Key_Right)
835 else if(event->key() == Qt::Key_Up)
837 else if(event->key() == Qt::Key_Down)
863 QPointF pixel_coordinates(xAxis->coordToPixel(
m_context.m_lastCursorHoveredPoint.x()),
864 yAxis->coordToPixel(
m_context.m_lastCursorHoveredPoint.y()));
866 Qt::MouseButton button = Qt::NoButton;
867 QEvent::Type q_event_type = QEvent::MouseButtonPress;
873 button = Qt::LeftButton;
877 if(
m_context.m_isLeftPseudoButtonKeyPressed)
878 q_event_type = QEvent::MouseButtonPress;
880 q_event_type = QEvent::MouseButtonRelease;
886 button = Qt::RightButton;
888 m_context.m_isRightPseudoButtonKeyPressed = !
m_context.m_isRightPseudoButtonKeyPressed;
890 if(
m_context.m_isRightPseudoButtonKeyPressed)
891 q_event_type = QEvent::MouseButtonPress;
893 q_event_type = QEvent::MouseButtonRelease;
901 QMouseEvent *mouse_event_p =
new QMouseEvent(q_event_type,
903 mapToGlobal(pixel_coordinates.toPoint()),
904 mapToGlobal(pixel_coordinates.toPoint()),
908 Qt::MouseEventSynthesizedByApplication);
910 if(q_event_type == QEvent::MouseButtonPress)
941#if QT_VERSION < 0x060000
942 QPointF mousePoint =
event->localPos();
944 QPointF mousePoint =
event->position();
948 m_context.m_lastCursorHoveredPoint.setX(xAxis->pixelToCoord(mousePoint.x()));
949 m_context.m_lastCursorHoveredPoint.setY(yAxis->pixelToCoord(mousePoint.y()));
959 if(
m_context.m_pressedMouseButtons & Qt::LeftButton ||
960 m_context.m_pressedMouseButtons & Qt::RightButton)
1007 m_context.m_lastCursorHoveredPoint.y());
1009 m_context.m_lastCursorHoveredPoint.y());
1020 yAxis->range().upper);
1022 yAxis->range().lower);
1043 m_context.m_keyboardModifiers = QGuiApplication::queryKeyboardModifiers();
1101 if(
m_context.m_mouseButtonsAtMousePress & Qt::LeftButton)
1105 else if(
m_context.m_mouseButtonsAtMousePress & Qt::RightButton)
1124 m_context.m_isMeasuringDistance =
false;
1133 if(
m_context.m_keyboardModifiers & Qt::ControlModifier)
1155 if(
m_context.m_pressedKeyCode == Qt::Key_Q)
1258 m_context.m_isMeasuringDistance =
false;
1309#if QT_VERSION < 0x060000
1310 QPointF mousePoint =
event->localPos();
1312 QPointF mousePoint =
event->position();
1315 m_context.m_lastPressedMouseButton =
event->button();
1316 m_context.m_mouseButtonsAtMousePress =
event->buttons();
1320 m_context.m_pressedMouseButtons |=
event->button();
1395 m_context.m_startDragPoint.setX(xAxis->pixelToCoord(mousePoint.x()));
1396 m_context.m_startDragPoint.setY(yAxis->pixelToCoord(mousePoint.y()));
1406 yAxis->range().upper);
1408 yAxis->range().lower);
1427 m_context.m_lastReleasedMouseButton =
event->button();
1432 m_context.m_mouseButtonsAtMouseRelease =
event->buttons();
1436 m_context.m_pressedMouseButtons ^=
event->button();
1442 m_context.m_keyboardModifiers = QGuiApplication::keyboardModifiers();
1501 if(
m_context.m_lastReleasedMouseButton == Qt::LeftButton)
1505 else if(
m_context.m_lastReleasedMouseButton == Qt::RightButton)
1595 if(
m_context.m_keyboardModifiers & Qt::ControlModifier)
1633 double x_delta_pixel = fabs(xAxis->coordToPixel(
m_context.m_currentDragPoint.x()) -
1634 xAxis->coordToPixel(
m_context.m_startDragPoint.x()));
1636 if(x_delta_pixel > 3)
1652 m_context.m_xRange = QCPRange(xAxis->range());
1653 m_context.m_yRange = QCPRange(yAxis->range());
1669 [[maybe_unused]] QCPAxis::SelectablePart part,
1674 m_context.m_keyboardModifiers = QGuiApplication::queryKeyboardModifiers();
1676 if(
m_context.m_keyboardModifiers & Qt::ControlModifier)
1705 m_context.m_pressedMouseButtons ^=
event->button();
1718 QCPLayoutElement *layoutElement = layoutElementAt(mousePoint);
1720 if(layoutElement && layoutElement ==
dynamic_cast<QCPLayoutElement *
>(axisRect()))
1726 QCPAxis::SelectablePart selectablePart;
1728 selectablePart = xAxis->getPartAt(mousePoint);
1730 if(selectablePart == QCPAxis::spAxisLabel || selectablePart == QCPAxis::spAxis ||
1731 selectablePart == QCPAxis::spTickLabels)
1742 QCPLayoutElement *layoutElement = layoutElementAt(mousePoint);
1744 if(layoutElement && layoutElement ==
dynamic_cast<QCPLayoutElement *
>(axisRect()))
1750 QCPAxis::SelectablePart selectablePart;
1752 selectablePart = yAxis->getPartAt(mousePoint);
1754 if(selectablePart == QCPAxis::spAxisLabel || selectablePart == QCPAxis::spAxis ||
1755 selectablePart == QCPAxis::spTickLabels)
1780 double x_delta_pixel = fabs(xAxis->coordToPixel(
m_context.m_currentDragPoint.x()) -
1781 xAxis->coordToPixel(
m_context.m_startDragPoint.x()));
1783 double y_delta_pixel = fabs(yAxis->coordToPixel(
m_context.m_currentDragPoint.y()) -
1784 yAxis->coordToPixel(
m_context.m_startDragPoint.y()));
1786 if(x_delta_pixel > y_delta_pixel)
1787 return Qt::Horizontal;
1789 return Qt::Vertical;
1798 QPointF pixels_coordinates(xAxis->coordToPixel(graph_coordinates.x()),
1799 yAxis->coordToPixel(graph_coordinates.y()));
1809 QCursor::setPos(mapToGlobal(pixel_coordinates.toPoint()));
1818 QPointF pixel_coord(xAxis->coordToPixel(graph_coord.x()), yAxis->coordToPixel(graph_coord.y()));
1831 QPointF pixel_coordinates(xAxis->coordToPixel(
m_context.m_lastCursorHoveredPoint.x()) +
1833 yAxis->coordToPixel(
m_context.m_lastCursorHoveredPoint.y()));
1837 QPointF graph_coordinates(xAxis->pixelToCoord(pixel_coordinates.x()),
1838 yAxis->pixelToCoord(pixel_coordinates.y()));
1840 return graph_coordinates;
1850 QPointF pixel_coord(xAxis->coordToPixel(graph_coord.x()), yAxis->coordToPixel(graph_coord.y()));
1863 QPointF pixel_coordinates(xAxis->coordToPixel(
m_context.m_lastCursorHoveredPoint.x()),
1864 yAxis->coordToPixel(
m_context.m_lastCursorHoveredPoint.y()) +
1869 QPointF graph_coordinates(xAxis->pixelToCoord(pixel_coordinates.x()),
1870 yAxis->pixelToCoord(pixel_coordinates.y()));
1872 return graph_coordinates;
1883 QCPGraph *graph_p = graph(index);
1885 if(graph_p ==
nullptr)
1886 qFatal(
"Programming error.");
1888 return graph_p->getKeyRange(found_range);
1895 QCPGraph *graph_p = graph(index);
1897 if(graph_p ==
nullptr)
1898 qFatal(
"Programming error.");
1900 return graph_p->getValueRange(found_range);
1914 found_range =
false;
1916 return QCPRange(0, 1);
1919 if(graphCount() == 1)
1920 return graph()->getKeyRange(found_range);
1922 bool found_at_least_one_range =
false;
1925 QCPRange result_range(QCPRange::minRange + 1, QCPRange::maxRange + 1);
1927 for(
int iter = 0; iter < graphCount(); ++iter)
1929 QCPRange temp_range;
1931 bool found_range_for_iter =
false;
1933 QCPGraph *graph_p = graph(iter);
1938 temp_range = graph_p->getKeyRange(found_range_for_iter);
1940 temp_range = graph_p->getValueRange(found_range_for_iter);
1942 qFatal(
"Cannot reach this point. Programming error.");
1947 if(!found_range_for_iter)
1953 if(!QCPRange::validRange(result_range))
1954 qFatal(
"The obtained range is invalid !");
1957 result_range = temp_range;
1960 found_at_least_one_range =
true;
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;
1974 if(temp_range.lower < result_range.lower)
1975 result_range.lower = temp_range.lower;
1976 if(temp_range.upper > result_range.upper)
1977 result_range.upper = temp_range.upper;
1980 qFatal(
"Cannot reach this point. Programming error.");
1988 found_range = found_at_least_one_range;
1990 return result_range;
2034 double xLower = xAxis->range().lower;
2035 double xUpper = xAxis->range().upper;
2039 double yLower = yAxis->range().lower;
2040 double yUpper = yAxis->range().upper;
2060 xAxis->setRange(xLower, xUpper -
m_context.m_xDelta);
2070 yAxis->setRange(yLower, yUpper -
m_context.m_yDelta);
2096 xAxis->setRange(QCPRange(
m_context.m_xRegionRangeStart,
m_context.m_xRegionRangeEnd));
2102 yAxis->setRange(xAxis->range().lower,
2127 xAxis->setRange(QCPRange(
m_context.m_xRegionRangeStart,
m_context.m_xRegionRangeEnd));
2129 yAxis->setRange(QCPRange(
m_context.m_yRegionRangeStart,
m_context.m_yRegionRangeEnd));
2146 "This function can only be called if the mouse click was on one of the "
2187 xAxis->setRange(xAxisRange.lower, xAxisRange.upper);
2192 yAxis->setRange(yAxisRange.lower, yAxisRange.upper);
2209 xAxis->setRange(lower, upper);
2220 yAxis->setRange(lower, upper);
2302 m_context.m_isMeasuringDistance =
false;
2348 QPointF leftmost_point;
2349 if(!
m_context.msp_integrationScope->getLeftMostPoint(leftmost_point))
2350 qFatal(
"Could not get the left-most point.");
2353 if(!
m_context.msp_integrationScope->getWidth(width))
2354 qFatal(
"Could not get width.");
2357 double x_axis_center_position = leftmost_point.x() + width / 2;
2367 int pixels_away_from_line = 15;
2369 QPointF reference_point_for_y_axis_label_position;
2382 pixels_away_from_line *= -1;
2384 if(!
m_context.msp_integrationScope->getTopMostPoint(
2385 reference_point_for_y_axis_label_position))
2386 qFatal(
"Failed to get top most point.");
2390 if(!
m_context.msp_integrationScope->getBottomMostPoint(
2391 reference_point_for_y_axis_label_position))
2392 qFatal(
"Failed to get bottom most point.");
2397 double y_axis_pixel_coordinate =
2398 yAxis->coordToPixel(reference_point_for_y_axis_label_position.y());
2402 double y_axis_modified_pixel_coordinate = y_axis_pixel_coordinate + pixels_away_from_line;
2405 QPointF pixel_coordinates;
2407 pixel_coordinates.setX(x_axis_center_position);
2408 pixel_coordinates.setY(y_axis_modified_pixel_coordinate);
2411 QPointF graph_coordinates(xAxis->pixelToCoord(pixel_coordinates.x()),
2412 yAxis->pixelToCoord(pixel_coordinates.y()));
2418 mp_xDeltaTextItem->position->setCoords(x_axis_center_position, graph_coordinates.y());
2429 QString label_text = QString(
"full x span %1 -- x drag delta %2")
2430 .arg(width, 0,
'f', decimals)
2431 .arg(fabs(
m_context.m_xDelta), 0,
'f', decimals);
2459 if(!
m_context.msp_integrationScope->getHeight(height))
2460 qFatal(
"Could not get height.");
2477 QPointF bottom_most_point;
2478 if(!
m_context.msp_integrationScope->getBottomMostPoint(bottom_most_point))
2479 qFatal(
"Could not get the bottom-most bottom point.");
2481 double y_axis_center_position = bottom_most_point.y() + height / 2;
2491 int pixels_away_from_line = 15;
2492 double x_axis_coordinate;
2493 double x_axis_pixel_coordinate;
2497 QPointF left_most_point;
2499 if(!
m_context.msp_integrationScope->getLeftMostPoint(left_most_point))
2500 qFatal(
"Failed to get left most point.");
2502 x_axis_coordinate = left_most_point.x();
2504 pixels_away_from_line *= -1;
2508 QPointF right_most_point;
2510 if(!
m_context.msp_integrationScope->getRightMostPoint(right_most_point))
2511 qFatal(
"Failed to get right most point.");
2513 x_axis_coordinate = right_most_point.x();
2515 x_axis_pixel_coordinate = xAxis->coordToPixel(x_axis_coordinate);
2517 double x_axis_modified_pixel_coordinate = x_axis_pixel_coordinate + pixels_away_from_line;
2520 QPointF pixel_coordinates;
2522 pixel_coordinates.setX(x_axis_modified_pixel_coordinate);
2523 pixel_coordinates.setY(y_axis_center_position);
2527 QPointF graph_coordinates(xAxis->pixelToCoord(pixel_coordinates.x()),
2528 yAxis->pixelToCoord(pixel_coordinates.y()));
2530 mp_yDeltaTextItem->position->setCoords(graph_coordinates.x(), y_axis_center_position);
2534 QString label_text = QString(
"full y span %1 -- y drag delta %2")
2535 .arg(height, 0,
'f', decimals)
2536 .arg(fabs(
m_context.m_yDelta), 0,
'f', decimals);
2578 double plotHeight = yAxis->range().upper - yAxis->range().lower;
2580 double heightDiff = fabs(
m_context.m_startDragPoint.y() -
m_context.m_currentDragPoint.y());
2582 double heightDiffRatio = (heightDiff / plotHeight) * 100;
2584 if(heightDiffRatio > 10)
2604 double x_range_start = std::min(
m_context.m_currentDragPoint.x(),
m_context.m_startDragPoint.x());
2605 double x_range_end = std::max(
m_context.m_currentDragPoint.x(),
m_context.m_startDragPoint.x());
2609 double y_position =
m_context.m_startDragPoint.y();
2670 QPointF bottom_left_point;
2671 if(!
m_context.msp_integrationScope->getPoint(bottom_left_point))
2672 qFatal(
"Failed to get point.");
2676 if(!
m_context.msp_integrationScope->getWidth(width))
2677 qFatal(
"Failed to get width.");
2681 if(!
m_context.msp_integrationScope->getHeight(height))
2682 qFatal(
"Failed to get height.");
2685 QPointF bottom_right_point(bottom_left_point.x() + width, bottom_left_point.y());
2688 QPointF top_right_point(bottom_left_point.x() + width, bottom_left_point.y() + height);
2691 QPointF top_left_point(bottom_left_point.x(), bottom_left_point.y() + height);
2763 scope_features =
m_context.msp_integrationScope->getLeftMostTopPoint(point_1);
2783 qFatal(
"The rhomboid should be horizontal!");
2787 if(!
m_context.msp_integrationScope->getLeftMostTopPoint(point_1))
2788 qFatal(
"Failed to getLeftMostTopPoint.");
2790 if(!
m_context.msp_integrationScope->getRightMostTopPoint(point_2))
2791 qFatal(
"Failed to getRightMostTopPoint.");
2814 if(!
m_context.msp_integrationScope->getRightMostBottomPoint(point_1))
2815 qFatal(
"Failed to getRightMostBottomPoint.");
2823 if(!
m_context.msp_integrationScope->getLeftMostBottomPoint(point_2))
2824 qFatal(
"Failed to getLeftMostBottomPoint.");
2832 if(!
m_context.msp_integrationScope->getLeftMostTopPoint(point_1))
2833 qFatal(
"Failed to getLeftMostTopPoint.");
2876 scope_features =
m_context.msp_integrationScope->getLeftMostTopPoint(point_1);
2896 qFatal(
"The rhomboid should be vertical!");
2901 if(!
m_context.msp_integrationScope->getLeftMostBottomPoint(point_2))
2902 qFatal(
"Failed to getLeftMostBottomPoint.");
2926 if(!
m_context.msp_integrationScope->getRightMostBottomPoint(point_1))
2927 qFatal(
"Failed to getRightMostBottomPoint.");
2936 if(!
m_context.msp_integrationScope->getRightMostTopPoint(point_2))
2937 qFatal(
"Failed to getRightMostTopPoint.");
2946 if(!
m_context.msp_integrationScope->getLeftMostTopPoint(point_1))
2947 qFatal(
"Failed to get the LeftMostTopPoint.");
3017 m_context.updateIntegrationScopeRhomb();
3035 if(
m_context.m_integrationScopeRhombWidth > 0)
3038 else if(
m_context.m_integrationScopeRhombHeight > 0)
3042 qFatal(
"Cannot be both the width or height of rhomboid scope be 0.");
3072 if(!(
m_context.m_keyboardModifiers & Qt::AltModifier))
3078 else if(
m_context.m_keyboardModifiers & Qt::AltModifier)
3084 if(!
m_context.m_integrationScopeRhombHeight && !
m_context.m_integrationScopeRhombWidth)
3100 std::vector<QPointF> points;
3102 if(
m_context.msp_integrationScope->getPoints(points))
3106 if(!
m_context.msp_integrationScope->getLeftMostPoint(point))
3107 qFatal(
"Failed to get LeftMost point.");
3108 m_context.m_xRegionRangeStart = point.x();
3110 if(!
m_context.msp_integrationScope->getRightMostPoint(point))
3111 qFatal(
"Failed to get RightMost point.");
3112 m_context.m_xRegionRangeEnd = point.x();
3114 else if(
m_context.msp_integrationScope->getHeight(height))
3118 if(!
m_context.msp_integrationScope->getPoint(point))
3119 qFatal(
"Failed to get point.");
3120 m_context.m_xRegionRangeStart = point.x();
3124 if(!
m_context.msp_integrationScope->getWidth(width))
3125 qFatal(
"Failed to get width.");
3129 m_context.m_yRegionRangeStart = point.y();
3131 m_context.m_yRegionRangeEnd = point.y() + height;
3137 if(!
m_context.msp_integrationScope->getPoint(point))
3138 qFatal(
"Failed to get point.");
3139 m_context.m_xRegionRangeStart = point.x();
3143 if(!
m_context.msp_integrationScope->getWidth(width))
3144 qFatal(
"Failed to get width.");
3175 std::const_pointer_cast<IntegrationScopeBase>(
m_context.msp_integrationScope)->reset();
3240 QCustomPlot::setFocus();
3252 if(focusedPlotWidget ==
nullptr)
3254 "baseplotwidget.cpp @ redrawPlotBackground(QWidget *focusedPlotWidget "
3256 "ERROR focusedPlotWidget cannot be nullptr.");
3258 if(
dynamic_cast<QWidget *
>(
this) != focusedPlotWidget)
3278 m_context.m_xRange = QCPRange(xAxis->range().lower, xAxis->range().upper);
3279 m_context.m_yRange = QCPRange(yAxis->range().lower, yAxis->range().upper);
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...