· · ·
plottable-curve.h
Go to the documentation of this file.
1 /***************************************************************************
2 ** **
3 ** QCustomPlot, an easy to use, modern plotting widget for Qt **
4 ** Copyright (C) 2011, 2012, 2013, 2014 Emanuel Eichhammer **
5 ** **
6 ** This program is free software: you can redistribute it and/or modify **
7 ** it under the terms of the GNU General Public License as published by **
8 ** the Free Software Foundation, either version 3 of the License, or **
9 ** (at your option) any later version. **
10 ** **
11 ** This program is distributed in the hope that it will be useful, **
12 ** but WITHOUT ANY WARRANTY; without even the implied warranty of **
13 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the **
14 ** GNU General Public License for more details. **
15 ** **
16 ** You should have received a copy of the GNU General Public License **
17 ** along with this program. If not, see http://www.gnu.org/licenses/. **
18 ** **
19 ****************************************************************************
20 ** Author: Emanuel Eichhammer **
21 ** Website/Contact: http://www.qcustomplot.com/ **
22 ** Date: 07.04.14 **
23 ** Version: 1.2.1 **
24 ****************************************************************************/
26 #ifndef QCP_PLOTTABLE_CURVE_H
27 #define QCP_PLOTTABLE_CURVE_H
28
29 #include "../global.h"
30 #include "../range.h"
31 #include "../plottable.h"
32 #include "../painter.h"
33
34 class QCPPainter;
35 class QCPAxis;
36
37 class QCP_LIB_DECL QCPCurveData
38 {
39 public:
40 QCPCurveData();
41 QCPCurveData(double t, double key, double value);
42 double t, key, value;
43 };
44 Q_DECLARE_TYPEINFO(QCPCurveData, Q_MOVABLE_TYPE);
45
54 typedef QMap<double, QCPCurveData> QCPCurveDataMap;
55 typedef QMapIterator<double, QCPCurveData> QCPCurveDataMapIterator;
56 typedef QMutableMapIterator<double, QCPCurveData> QCPCurveDataMutableMapIterator;
57
58
59 class QCP_LIB_DECL QCPCurve : public QCPAbstractPlottable
60 {
61 Q_OBJECT
63 Q_PROPERTY(QCPScatterStyle scatterStyle READ scatterStyle WRITE setScatterStyle)
64 Q_PROPERTY(LineStyle lineStyle READ lineStyle WRITE setLineStyle)
66 public:
72 enum LineStyle { lsNone
73 ,lsLine
74 };
75 explicit QCPCurve(QCPAxis *keyAxis, QCPAxis *valueAxis);
76 virtual ~QCPCurve();
77
78 // getters:
79 QCPCurveDataMap *data() const { return mData; }
80 QCPScatterStyle scatterStyle() const { return mScatterStyle; }
81 LineStyle lineStyle() const { return mLineStyle; }
82
83 // setters:
84 void setData(QCPCurveDataMap *data, bool copy=false);
85 void setData(const QVector<double> &t, const QVector<double> &key, const QVector<double> &value);
86 void setData(const QVector<double> &key, const QVector<double> &value);
87 void setScatterStyle(const QCPScatterStyle &style);
88 void setLineStyle(LineStyle style);
89
90 // non-property methods:
91 void addData(const QCPCurveDataMap &dataMap);
92 void addData(const QCPCurveData &data);
93 void addData(double t, double key, double value);
94 void addData(double key, double value);
95 void addData(const QVector<double> &ts, const QVector<double> &keys, const QVector<double> &values);
96 void removeDataBefore(double t);
97 void removeDataAfter(double t);
98 void removeData(double fromt, double tot);
99 void removeData(double t);
100
101 // reimplemented virtual methods:
102 virtual void clearData();
103 virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const;
104
105 protected:
106 // property members:
107 QCPCurveDataMap *mData;
108 QCPScatterStyle mScatterStyle;
109 LineStyle mLineStyle;
110
111 // reimplemented virtual methods:
112 virtual void draw(QCPPainter *painter);
113 virtual void drawLegendIcon(QCPPainter *painter, const QRectF &rect) const;
114 virtual QCPRange getKeyRange(bool &foundRange, SignDomain inSignDomain=sdBoth) const;
115 virtual QCPRange getValueRange(bool &foundRange, SignDomain inSignDomain=sdBoth) const;
116
117 // introduced virtual methods:
118 virtual void drawScatterPlot(QCPPainter *painter, const QVector<QPointF> *pointData) const;
119
120 // non-virtual methods:
121 void getCurveData(QVector<QPointF> *lineData) const;
122 double pointDistance(const QPointF &pixelPoint) const;
123 QPointF outsideCoordsToPixels(double key, double value, int region, QRect axisRect) const;
124
125 friend class QCustomPlot;
126 friend class QCPLegend;
127 };
128
129 #endif // QCP_PLOTTABLE_CURVE_H
Generated with Doxygen 1.8.1.2