· · ·
plottable-bars.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_BARS_H
27 #define QCP_PLOTTABLE_BARS_H
28
29 #include "../global.h"
30 #include "../range.h"
31 #include "../plottable.h"
32
33 class QCPPainter;
34 class QCPAxis;
35
36 class QCP_LIB_DECL QCPBarData
37 {
38 public:
39 QCPBarData();
40 QCPBarData(double key, double value);
41 double key, value;
42 };
43 Q_DECLARE_TYPEINFO(QCPBarData, Q_MOVABLE_TYPE);
44
52 typedef QMap<double, QCPBarData> QCPBarDataMap;
53 typedef QMapIterator<double, QCPBarData> QCPBarDataMapIterator;
54 typedef QMutableMapIterator<double, QCPBarData> QCPBarDataMutableMapIterator;
55
56
57 class QCP_LIB_DECL QCPBars : public QCPAbstractPlottable
58 {
59 Q_OBJECT
61 Q_PROPERTY(double width READ width WRITE setWidth)
62 Q_PROPERTY(QCPBars* barBelow READ barBelow)
63 Q_PROPERTY(QCPBars* barAbove READ barAbove)
65 public:
66 explicit QCPBars(QCPAxis *keyAxis, QCPAxis *valueAxis);
67 virtual ~QCPBars();
68
69 // getters:
70 double width() const { return mWidth; }
71 QCPBars *barBelow() const { return mBarBelow.data(); }
72 QCPBars *barAbove() const { return mBarAbove.data(); }
73 QCPBarDataMap *data() const { return mData; }
74
75 // setters:
76 void setWidth(double width);
77 void setData(QCPBarDataMap *data, bool copy=false);
78 void setData(const QVector<double> &key, const QVector<double> &value);
79
80 // non-property methods:
81 void moveBelow(QCPBars *bars);
82 void moveAbove(QCPBars *bars);
83 void addData(const QCPBarDataMap &dataMap);
84 void addData(const QCPBarData &data);
85 void addData(double key, double value);
86 void addData(const QVector<double> &keys, const QVector<double> &values);
87 void removeDataBefore(double key);
88 void removeDataAfter(double key);
89 void removeData(double fromKey, double toKey);
90 void removeData(double key);
91
92 // reimplemented virtual methods:
93 virtual void clearData();
94 virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const;
95
96 protected:
97 // property members:
98 QCPBarDataMap *mData;
99 double mWidth;
100 QPointer<QCPBars> mBarBelow, mBarAbove;
101
102 // reimplemented virtual methods:
103 virtual void draw(QCPPainter *painter);
104 virtual void drawLegendIcon(QCPPainter *painter, const QRectF &rect) const;
105 virtual QCPRange getKeyRange(bool &foundRange, SignDomain inSignDomain=sdBoth) const;
106 virtual QCPRange getValueRange(bool &foundRange, SignDomain inSignDomain=sdBoth) const;
107
108 // non-virtual methods:
109 QPolygonF getBarPolygon(double key, double value) const;
110 double getBaseValue(double key, bool positive) const;
111 static void connectBars(QCPBars* lower, QCPBars* upper);
112
113 friend class QCustomPlot;
114 friend class QCPLegend;
115 };
116
117 #endif // QCP_PLOTTABLE_BARS_H
Generated with Doxygen 1.8.1.2