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