src/plottables/plottable-graph.h Source File

· · ·
plottable-graph.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 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: 04.11.13 **
23 ** Version: 1.1.0 **
24 ****************************************************************************/
26 #ifndef QCP_PLOTTABLE_GRAPH_H
27 #define QCP_PLOTTABLE_GRAPH_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 QCPData
38 {
39 public:
40 QCPData();
41 QCPData(double key, double value);
42 double key, value;
43 double keyErrorPlus, keyErrorMinus;
44 double valueErrorPlus, valueErrorMinus;
45 };
46 Q_DECLARE_TYPEINFO(QCPData, Q_MOVABLE_TYPE);
47
55 typedef QMap<double, QCPData> QCPDataMap;
56 typedef QMapIterator<double, QCPData> QCPDataMapIterator;
57 typedef QMutableMapIterator<double, QCPData> QCPDataMutableMapIterator;
58
59
60 class QCP_LIB_DECL QCPGraph : public QCPAbstractPlottable
61 {
62 Q_OBJECT
64 Q_PROPERTY(LineStyle lineStyle READ lineStyle WRITE setLineStyle)
65 Q_PROPERTY(QCPScatterStyle scatterStyle READ scatterStyle WRITE setScatterStyle)
66 Q_PROPERTY(ErrorType errorType READ errorType WRITE setErrorType)
67 Q_PROPERTY(QPen errorPen READ errorPen WRITE setErrorPen)
68 Q_PROPERTY(double errorBarSize READ errorBarSize WRITE setErrorBarSize)
69 Q_PROPERTY(bool errorBarSkipSymbol READ errorBarSkipSymbol WRITE setErrorBarSkipSymbol)
70 Q_PROPERTY(QCPGraph* channelFillGraph READ channelFillGraph WRITE setChannelFillGraph)
72 public:
78 enum LineStyle { lsNone
79
80 ,lsLine
81 ,lsStepLeft
82 ,lsStepRight
83 ,lsStepCenter
84 ,lsImpulse
85 };
86 Q_ENUMS(LineStyle)
90 enum ErrorType { etNone
91 ,etKey
92 ,etValue
93 ,etBoth
94 };
95 Q_ENUMS(ErrorType)
96
97 explicit QCPGraph(QCPAxis *keyAxis, QCPAxis *valueAxis);
98 virtual ~QCPGraph();
99
100 // getters:
101 const QCPDataMap *data() const { return mData; }
102 LineStyle lineStyle() const { return mLineStyle; }
103 QCPScatterStyle scatterStyle() const { return mScatterStyle; }
104 ErrorType errorType() const { return mErrorType; }
105 QPen errorPen() const { return mErrorPen; }
106 double errorBarSize() const { return mErrorBarSize; }
107 bool errorBarSkipSymbol() const { return mErrorBarSkipSymbol; }
108 QCPGraph *channelFillGraph() const { return mChannelFillGraph.data(); }
109
110 // setters:
111 void setData(QCPDataMap *data, bool copy=false);
112 void setData(const QVector<double> &key, const QVector<double> &value);
113 void setDataKeyError(const QVector<double> &key, const QVector<double> &value, const QVector<double> &keyError);
114 void setDataKeyError(const QVector<double> &key, const QVector<double> &value, const QVector<double> &keyErrorMinus, const QVector<double> &keyErrorPlus);
115 void setDataValueError(const QVector<double> &key, const QVector<double> &value, const QVector<double> &valueError);
116 void setDataValueError(const QVector<double> &key, const QVector<double> &value, const QVector<double> &valueErrorMinus, const QVector<double> &valueErrorPlus);
117 void setDataBothError(const QVector<double> &key, const QVector<double> &value, const QVector<double> &keyError, const QVector<double> &valueError);
118 void setDataBothError(const QVector<double> &key, const QVector<double> &value, const QVector<double> &keyErrorMinus, const QVector<double> &keyErrorPlus, const QVector<double> &valueErrorMinus, const QVector<double> &valueErrorPlus);
119 void setLineStyle(LineStyle ls);
120 void setScatterStyle(const QCPScatterStyle &style);
121 void setErrorType(ErrorType errorType);
122 void setErrorPen(const QPen &pen);
123 void setErrorBarSize(double size);
124 void setErrorBarSkipSymbol(bool enabled);
125 void setChannelFillGraph(QCPGraph *targetGraph);
126
127 // non-property methods:
128 void addData(const QCPDataMap &dataMap);
129 void addData(const QCPData &data);
130 void addData(double key, double value);
131 void addData(const QVector<double> &keys, const QVector<double> &values);
132 void removeDataBefore(double key);
133 void removeDataAfter(double key);
134 void removeData(double fromKey, double toKey);
135 void removeData(double key);
136
137 // reimplemented virtual methods:
138 virtual void clearData();
139 virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const;
140 using QCPAbstractPlottable::rescaleAxes;
141 using QCPAbstractPlottable::rescaleKeyAxis;
142 using QCPAbstractPlottable::rescaleValueAxis;
143 void rescaleAxes(bool onlyEnlarge, bool includeErrorBars) const; // overloads base class interface
144 void rescaleKeyAxis(bool onlyEnlarge, bool includeErrorBars) const; // overloads base class interface
145 void rescaleValueAxis(bool onlyEnlarge, bool includeErrorBars) const; // overloads base class interface
146
147 protected:
148 // property members:
149 QCPDataMap *mData;
150 QPen mErrorPen;
151 LineStyle mLineStyle;
152 QCPScatterStyle mScatterStyle;
153 ErrorType mErrorType;
154 double mErrorBarSize;
155 bool mErrorBarSkipSymbol;
156 QPointer<QCPGraph> mChannelFillGraph;
157
158 // reimplemented virtual methods:
159 virtual void draw(QCPPainter *painter);
160 virtual void drawLegendIcon(QCPPainter *painter, const QRectF &rect) const;
161 virtual QCPRange getKeyRange(bool &validRange, SignDomain inSignDomain=sdBoth) const;
162 virtual QCPRange getValueRange(bool &validRange, SignDomain inSignDomain=sdBoth) const;
163 virtual QCPRange getKeyRange(bool &validRange, SignDomain inSignDomain, bool includeErrors) const; // overloads base class interface
164 virtual QCPRange getValueRange(bool &validRange, SignDomain inSignDomain, bool includeErrors) const; // overloads base class interface
165
166 // introduced virtual methods:
167 virtual void drawFill(QCPPainter *painter, QVector<QPointF> *lineData) const;
168 virtual void drawScatterPlot(QCPPainter *painter, QVector<QCPData> *pointData) const;
169 virtual void drawLinePlot(QCPPainter *painter, QVector<QPointF> *lineData) const;
170 virtual void drawImpulsePlot(QCPPainter *painter, QVector<QPointF> *lineData) const;
171
172 // non-virtual methods:
173 void getPlotData(QVector<QPointF> *lineData, QVector<QCPData> *pointData) const;
174 void getScatterPlotData(QVector<QCPData> *pointData) const;
175 void getLinePlotData(QVector<QPointF> *lineData, QVector<QCPData> *pointData) const;
176 void getStepLeftPlotData(QVector<QPointF> *lineData, QVector<QCPData> *pointData) const;
177 void getStepRightPlotData(QVector<QPointF> *lineData, QVector<QCPData> *pointData) const;
178 void getStepCenterPlotData(QVector<QPointF> *lineData, QVector<QCPData> *pointData) const;
179 void getImpulsePlotData(QVector<QPointF> *lineData, QVector<QCPData> *pointData) const;
180 void drawError(QCPPainter *painter, double x, double y, const QCPData &data) const;
181 void getVisibleDataBounds(QCPDataMap::const_iterator &lower, QCPDataMap::const_iterator &upper, int &count) const;
182 void addFillBasePoints(QVector<QPointF> *lineData) const;
183 void removeFillBasePoints(QVector<QPointF> *lineData) const;
184 QPointF lowerFillBasePoint(double lowerKey) const;
185 QPointF upperFillBasePoint(double upperKey) const;
186 const QPolygonF getChannelFillPolygon(const QVector<QPointF> *lineData) const;
187 int findIndexBelowX(const QVector<QPointF> *data, double x) const;
188 int findIndexAboveX(const QVector<QPointF> *data, double x) const;
189 int findIndexBelowY(const QVector<QPointF> *data, double y) const;
190 int findIndexAboveY(const QVector<QPointF> *data, double y) const;
191 double pointDistance(const QPointF &pixelPoint) const;
192
193 friend class QCustomPlot;
194 friend class QCPLegend;
195 };
196
197 #endif // QCP_PLOTTABLE_GRAPH_H
Generated with Doxygen 1.8.1.2