File indexing completed on 2025-01-26 03:34:18
0001 /* 0002 File : XYCurve.h 0003 Project : LabPlot 0004 Description : A xy-curve 0005 -------------------------------------------------------------------- 0006 SPDX-FileCopyrightText: 2010-2024 Alexander Semke <alexander.semke@web.de> 0007 SPDX-FileCopyrightText: 2013-2020 Stefan Gerlach <stefan.gerlach@uni.kn> 0008 SPDX-License-Identifier: GPL-2.0-or-later 0009 */ 0010 0011 #ifndef XYCURVE_H 0012 #define XYCURVE_H 0013 0014 #include "Plot.h" 0015 #include "backend/worksheet/plots/cartesian/ErrorBar.h" 0016 #include <QFont> 0017 0018 class AbstractColumn; 0019 class Background; 0020 class ErrorBar; 0021 class ErrorBarStyle; 0022 class Line; 0023 class Symbol; 0024 class XYCurvePrivate; 0025 0026 #ifdef SDK 0027 #include "labplot_export.h" 0028 class LABPLOT_EXPORT XYCurve : public Plot { 0029 #else 0030 class XYCurve : public Plot { 0031 #endif 0032 Q_OBJECT 0033 0034 public: 0035 friend class XYCurveSetXColumnCmd; 0036 friend class XYCurveSetYColumnCmd; 0037 friend class XYCurveSetXErrorPlusColumnCmd; 0038 friend class XYCurveSetXErrorMinusColumnCmd; 0039 friend class XYCurveSetYErrorPlusColumnCmd; 0040 friend class XYCurveSetYErrorMinusColumnCmd; 0041 friend class XYCurveSetValuesColumnCmd; 0042 enum class LineType { 0043 NoLine, 0044 Line, 0045 StartHorizontal, 0046 StartVertical, 0047 MidpointHorizontal, 0048 MidpointVertical, 0049 Segments2, 0050 Segments3, 0051 SplineCubicNatural, 0052 SplineCubicPeriodic, 0053 SplineAkimaNatural, 0054 SplineAkimaPeriodic 0055 }; 0056 enum class DropLineType { NoDropLine, X, Y, XY, XZeroBaseline, XMinBaseline, XMaxBaseline }; 0057 enum class ValuesType { NoValues, X, Y, XY, XYBracketed, CustomColumn }; 0058 enum class ValuesPosition { Above, Under, Left, Right }; 0059 0060 explicit XYCurve(const QString& name, AspectType type = AspectType::XYCurve); 0061 ~XYCurve() override; 0062 0063 QIcon icon() const override; 0064 QMenu* createContextMenu() override; 0065 void save(QXmlStreamWriter*) const override; 0066 bool load(XmlStreamReader*, bool preview) override; 0067 void loadThemeConfig(const KConfig&) override; 0068 void saveThemeConfig(const KConfig&) override; 0069 double y(double x, bool& valueFound) const; 0070 QDateTime yDateTime(double x, bool& valueFound) const; 0071 0072 bool minMax(const CartesianCoordinateSystem::Dimension dim, const Range<int>& indexRange, Range<double>& r, bool includeErrorBars = true) const override; 0073 double minimum(CartesianCoordinateSystem::Dimension dim) const override; 0074 double maximum(CartesianCoordinateSystem::Dimension dim) const override; 0075 bool hasData() const override; 0076 bool usingColumn(const Column*) const override; 0077 void updateColumnDependencies(const AbstractColumn*) override; 0078 QColor color() const override; 0079 0080 const AbstractColumn* column(CartesianCoordinateSystem::Dimension dim) const; 0081 POINTER_D_ACCESSOR_DECL(const AbstractColumn, xColumn, XColumn) 0082 POINTER_D_ACCESSOR_DECL(const AbstractColumn, yColumn, YColumn) 0083 CLASS_D_ACCESSOR_DECL(QString, xColumnPath, XColumnPath) 0084 CLASS_D_ACCESSOR_DECL(QString, yColumnPath, YColumnPath) 0085 0086 BASIC_D_ACCESSOR_DECL(LineType, lineType, LineType) 0087 BASIC_D_ACCESSOR_DECL(bool, lineSkipGaps, LineSkipGaps) 0088 BASIC_D_ACCESSOR_DECL(bool, lineIncreasingXOnly, LineIncreasingXOnly) 0089 BASIC_D_ACCESSOR_DECL(int, lineInterpolationPointsCount, LineInterpolationPointsCount) 0090 Line* line() const; 0091 Line* dropLine() const; 0092 0093 Symbol* symbol() const; 0094 Background* background() const; 0095 0096 BASIC_D_ACCESSOR_DECL(ValuesType, valuesType, ValuesType) 0097 POINTER_D_ACCESSOR_DECL(const AbstractColumn, valuesColumn, ValuesColumn) 0098 CLASS_D_ACCESSOR_DECL(QString, valuesColumnPath, ValuesColumnPath) 0099 BASIC_D_ACCESSOR_DECL(ValuesPosition, valuesPosition, ValuesPosition) 0100 BASIC_D_ACCESSOR_DECL(qreal, valuesDistance, ValuesDistance) 0101 BASIC_D_ACCESSOR_DECL(qreal, valuesRotationAngle, ValuesRotationAngle) 0102 BASIC_D_ACCESSOR_DECL(qreal, valuesOpacity, ValuesOpacity) 0103 BASIC_D_ACCESSOR_DECL(char, valuesNumericFormat, ValuesNumericFormat) 0104 BASIC_D_ACCESSOR_DECL(int, valuesPrecision, ValuesPrecision) 0105 CLASS_D_ACCESSOR_DECL(QString, valuesDateTimeFormat, ValuesDateTimeFormat) 0106 CLASS_D_ACCESSOR_DECL(QString, valuesPrefix, ValuesPrefix) 0107 CLASS_D_ACCESSOR_DECL(QString, valuesSuffix, ValuesSuffix) 0108 CLASS_D_ACCESSOR_DECL(QColor, valuesColor, ValuesColor) 0109 CLASS_D_ACCESSOR_DECL(QFont, valuesFont, ValuesFont) 0110 0111 ErrorBar* xErrorBar() const; 0112 ErrorBar* yErrorBar() const; 0113 ErrorBarStyle* errorBarStyle() const; 0114 0115 // margin plots 0116 BASIC_D_ACCESSOR_DECL(bool, rugEnabled, RugEnabled) 0117 BASIC_D_ACCESSOR_DECL(WorksheetElement::Orientation, rugOrientation, RugOrientation) 0118 BASIC_D_ACCESSOR_DECL(double, rugOffset, RugOffset) 0119 BASIC_D_ACCESSOR_DECL(double, rugLength, RugLength) 0120 BASIC_D_ACCESSOR_DECL(double, rugWidth, RugWidth) 0121 0122 bool isSourceDataChangedSinceLastRecalc() const; 0123 0124 typedef XYCurvePrivate Private; 0125 0126 void retransform() override; 0127 void recalcLogicalPoints(); 0128 void handleResize(double horizontalRatio, double verticalRatio, bool pageResize) override; 0129 double y(double x, double& x_new, bool& valueFound) const; 0130 int getNextValue(double xpos, int index, double& x, double& y, bool& valueFound) const; 0131 0132 private Q_SLOTS: 0133 void updateValues(); 0134 void updateErrorBars(); 0135 void xColumnAboutToBeRemoved(const AbstractAspect*); 0136 void yColumnAboutToBeRemoved(const AbstractAspect*); 0137 void valuesColumnAboutToBeRemoved(const AbstractAspect*); 0138 0139 // SLOTs for changes triggered via QActions in the context menu 0140 void navigateTo(); 0141 0142 protected: 0143 XYCurve(const QString& name, XYCurvePrivate* dd, AspectType type); 0144 0145 private: 0146 Q_DECLARE_PRIVATE(XYCurve) 0147 void init(); 0148 void initActions(); 0149 void connectXColumn(const AbstractColumn*); 0150 void connectYColumn(const AbstractColumn*); 0151 void connectValuesColumn(const AbstractColumn*); 0152 0153 bool minMax(const AbstractColumn* column1, 0154 const AbstractColumn* column2, 0155 const ErrorBar::Type errorType, 0156 const AbstractColumn* errorPlusColumn, 0157 const AbstractColumn* errorMinusColumn, 0158 const Range<int>& indexRange, 0159 Range<double>& yRange, 0160 bool includeErrorBars) const; 0161 0162 QAction* navigateToAction{nullptr}; 0163 bool m_menusInitialized{false}; 0164 0165 Q_SIGNALS: 0166 void linesUpdated(const XYCurve*, const QVector<QLineF>&); 0167 0168 // General-Tab 0169 void xDataChanged(); 0170 void yDataChanged(); 0171 void valuesDataChanged(); 0172 void selected(double pos); 0173 0174 void xColumnChanged(const AbstractColumn*); 0175 void yColumnChanged(const AbstractColumn*); 0176 0177 // Line-Tab 0178 void lineTypeChanged(XYCurve::LineType); 0179 void lineSkipGapsChanged(bool); 0180 void lineIncreasingXOnlyChanged(bool); 0181 void lineInterpolationPointsCountChanged(int); 0182 void dropLineTypeChanged(XYCurve::DropLineType); 0183 0184 // Values-Tab 0185 void valuesTypeChanged(XYCurve::ValuesType); 0186 void valuesColumnChanged(const AbstractColumn*); 0187 void valuesPositionChanged(XYCurve::ValuesPosition); 0188 void valuesDistanceChanged(qreal); 0189 void valuesRotationAngleChanged(qreal); 0190 void valuesOpacityChanged(qreal); 0191 void valuesNumericFormatChanged(char); 0192 void valuesPrecisionChanged(int); 0193 void valuesDateTimeFormatChanged(QString); 0194 void valuesPrefixChanged(QString); 0195 void valuesSuffixChanged(QString); 0196 void valuesFontChanged(QFont); 0197 void valuesColorChanged(QColor); 0198 0199 // Margin Plots 0200 void rugEnabledChanged(bool); 0201 void rugOrientationChanged(WorksheetElement::Orientation); 0202 void rugLengthChanged(double); 0203 void rugWidthChanged(double); 0204 void rugOffsetChanged(double); 0205 0206 friend class RetransformTest; 0207 friend class XYCurveTest; 0208 }; 0209 0210 #endif