File indexing completed on 2024-05-12 03:48:19
0001 /* 0002 File : InfoElement.h 0003 Project : LabPlot 0004 Description : Marker which can highlight points of curves and 0005 show their values 0006 -------------------------------------------------------------------- 0007 SPDX-FileCopyrightText: 2020 Martin Marmsoler <martin.marmsoler@gmail.com> 0008 SPDX-FileCopyrightText: 2020-2022 Alexander Semke <alexander.semke@web.de> 0009 0010 SPDX-License-Identifier: GPL-2.0-or-later 0011 */ 0012 0013 #ifndef INFOELEMENT_H 0014 #define INFOELEMENT_H 0015 0016 #include "WorksheetElement.h" 0017 #include "backend/worksheet/TextLabel.h" 0018 0019 class CartesianPlot; 0020 class CustomPoint; 0021 class InfoElementPrivate; 0022 class Line; 0023 class QAction; 0024 class QGraphicsItem; 0025 class QMenu; 0026 class XYCurve; 0027 0028 class InfoElement : public WorksheetElement { 0029 Q_OBJECT 0030 0031 public: 0032 InfoElement(const QString& name, CartesianPlot*); 0033 InfoElement(const QString& name, CartesianPlot*, const XYCurve*, double logicalPos); 0034 virtual void setParentGraphicsItem(QGraphicsItem* item) override; 0035 ~InfoElement(); 0036 0037 struct MarkerPoints_T { 0038 MarkerPoints_T() = default; 0039 MarkerPoints_T(CustomPoint* custompoint, const XYCurve* curve, QString curvePath) 0040 : customPoint(custompoint) 0041 , curve(curve) 0042 , curvePath(curvePath) { 0043 } 0044 CustomPoint* customPoint{nullptr}; 0045 const XYCurve* curve{nullptr}; 0046 QString curvePath; 0047 }; 0048 0049 void save(QXmlStreamWriter*) const override; 0050 bool load(XmlStreamReader*, bool preview) override; 0051 void loadThemeConfig(const KConfig&) override; 0052 0053 TextLabel* title(); 0054 void addCurve(const XYCurve*, CustomPoint* = nullptr); 0055 void addCurvePath(QString& curvePath, CustomPoint* = nullptr); 0056 bool assignCurve(const QVector<XYCurve*>&); 0057 void removeCurve(const XYCurve*); 0058 void setZValue(qreal) override; 0059 int markerPointsCount(); 0060 MarkerPoints_T markerPointAt(int index); 0061 int gluePointsCount(); 0062 TextLabel::GluePoint gluePoint(int index); 0063 TextLabel::TextWrapper createTextLabelText(); 0064 QMenu* createContextMenu() override; 0065 0066 bool isTextLabel() const; 0067 double setMarkerpointPosition(double x); 0068 int currentIndex(double new_x, double* found_x = nullptr); 0069 0070 void retransform() override; 0071 void handleResize(double horizontalRatio, double verticalRatio, bool pageResize) override; 0072 0073 BASIC_D_ACCESSOR_DECL(double, positionLogical, PositionLogical) 0074 BASIC_D_ACCESSOR_DECL(int, gluePointIndex, GluePointIndex) 0075 CLASS_D_ACCESSOR_DECL(QString, connectionLineCurveName, ConnectionLineCurveName) 0076 Line* verticalLine() const; 0077 Line* connectionLine() const; 0078 0079 virtual void setVisible(bool on) override; 0080 0081 typedef InfoElementPrivate Private; 0082 0083 public Q_SLOTS: 0084 void labelPositionChanged(TextLabel::PositionWrapper); 0085 void labelVisibleChanged(bool); 0086 void pointPositionChanged(const PositionWrapper&); 0087 void childRemoved(const AbstractAspect* parent, const AbstractAspect* before, const AbstractAspect* child); 0088 void childAdded(const AbstractAspect*); 0089 void labelBorderShapeChanged(); 0090 void labelTextWrapperChanged(TextLabel::TextWrapper); 0091 void moveElementBegin(); 0092 void moveElementEnd(); 0093 void curveVisibilityChanged(); 0094 void curveDataChanged(); 0095 void curveCoordinateSystemIndexChanged(int); 0096 0097 private: 0098 Q_DECLARE_PRIVATE(InfoElement) 0099 TextLabel* m_title{nullptr}; 0100 QVector<struct MarkerPoints_T> markerpoints; 0101 bool m_menusInitialized{false}; 0102 bool m_suppressChildRemoved{false}; 0103 bool m_suppressChildPositionChanged{false}; 0104 bool m_setTextLabelText{false}; 0105 /*! 0106 * This variable is set when a curve is moved in the order, because there 0107 * the curve is removed and readded and we would like to ignore this remove and 0108 * add. Because of single thread it makes no problems. 0109 */ 0110 bool m_curveGetsMoved{false}; 0111 0112 void init(); 0113 void initActions(); 0114 void initMenus(); 0115 void initCurveConnections(const XYCurve*); 0116 0117 Q_SIGNALS: 0118 void gluePointIndexChanged(const int); 0119 void connectionLineCurveNameChanged(const QString&); 0120 void positionLogicalChanged(const double); 0121 void labelBorderShapeChangedSignal(); 0122 void curveRemoved(const QString&); 0123 }; 0124 0125 #endif // INFOELEMENT_H