· · ·
plottable-colormap.h
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 ****************************************************************************/
25
26 #ifndef QCP_PLOTTABLE_COLORMAP_H
27 #define QCP_PLOTTABLE_COLORMAP_H
28
29 #include "../global.h"
30 #include "../range.h"
31 #include "../plottable.h"
32 #include "../colorgradient.h"
33 #include "../layoutelements/layoutelement-colorscale.h"
34
35 class QCPPainter;
36 class QCPAxis;
37 class QCPColorMap;
38
39 class QCP_LIB_DECL QCPColorMapData
40 {
41 public:
42 QCPColorMapData(int keySize, int valueSize, const QCPRange &keyRange, const QCPRange &valueRange);
43 ~QCPColorMapData();
44 QCPColorMapData(const QCPColorMapData &other);
45 QCPColorMapData &operator=(const QCPColorMapData &other);
46
47 // getters:
48 int keySize() const { return mKeySize; }
49 int valueSize() const { return mValueSize; }
50 QCPRange keyRange() const { return mKeyRange; }
51 QCPRange valueRange() const { return mValueRange; }
52 QCPRange dataBounds() const { return mDataBounds; }
53 double data(double key, double value);
54 double cell(int keyIndex, int valueIndex);
55
56 // setters:
57 void setSize(int keySize, int valueSize);
58 void setKeySize(int keySize);
59 void setValueSize(int valueSize);
60 void setRange(const QCPRange &keyRange, const QCPRange &valueRange);
61 void setKeyRange(const QCPRange &keyRange);
62 void setValueRange(const QCPRange &valueRange);
63 void setData(double key, double value, double z);
64 void setCell(int keyIndex, int valueIndex, double z);
65
66 // non-property methods:
67 void recalculateDataBounds();
68 void clear();
69 void fill(double z);
70 bool isEmpty() const { return mIsEmpty; }
71 void coordToCell(double key, double value, int *keyIndex, int *valueIndex) const;
72 void cellToCoord(int keyIndex, int valueIndex, double *key, double *value) const;
73
74 protected:
75 // property members:
76 int mKeySize, mValueSize;
77 QCPRange mKeyRange, mValueRange;
78 bool mIsEmpty;
79 // non-property members:
80 double *mData;
81 QCPRange mDataBounds;
82 bool mDataModified;
83
84 friend class QCPColorMap;
85 };
86
87
88 class QCP_LIB_DECL QCPColorMap : public QCPAbstractPlottable
89 {
90 Q_OBJECT
92 Q_PROPERTY(QCPRange dataRange READ dataRange WRITE setDataRange NOTIFY dataRangeChanged)
93 Q_PROPERTY(QCPAxis::ScaleType dataScaleType READ dataScaleType WRITE setDataScaleType NOTIFY dataScaleTypeChanged)
94 Q_PROPERTY(QCPColorGradient gradient READ gradient WRITE setGradient NOTIFY gradientChanged)
95 Q_PROPERTY(bool interpolate READ interpolate WRITE setInterpolate)
96 Q_PROPERTY(bool tightBoundary READ tightBoundary WRITE setTightBoundary)
97 Q_PROPERTY(QCPColorScale* colorScale READ colorScale WRITE setColorScale)
99 public:
100 explicit QCPColorMap(QCPAxis *keyAxis, QCPAxis *valueAxis);
101 virtual ~QCPColorMap();
102
103 // getters:
104 QCPColorMapData *data() const { return mMapData; }
105 QCPRange dataRange() const { return mDataRange; }
106 QCPAxis::ScaleType dataScaleType() const { return mDataScaleType; }
107 bool interpolate() const { return mInterpolate; }
108 bool tightBoundary() const { return mTightBoundary; }
109 QCPColorGradient gradient() const { return mGradient; }
110 QCPColorScale *colorScale() const { return mColorScale.data(); }
111
112 // setters:
113 void setData(QCPColorMapData *data, bool copy=false);
114 Q_SLOT void setDataRange(const QCPRange &dataRange);
115 Q_SLOT void setDataScaleType(QCPAxis::ScaleType scaleType);
116 Q_SLOT void setGradient(const QCPColorGradient &gradient);
117 void setInterpolate(bool enabled);
118 void setTightBoundary(bool enabled);
119 void setColorScale(QCPColorScale *colorScale);
120
121 // non-property methods:
122 void rescaleDataRange(bool recalculateDataBounds=false);
123 Q_SLOT void updateLegendIcon(Qt::TransformationMode transformMode=Qt::SmoothTransformation, const QSize &thumbSize=QSize(32, 18));
124
125 // reimplemented virtual methods:
126 virtual void clearData();
127 virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const;
128
129 signals:
130 void dataRangeChanged(QCPRange newRange);
131 void dataScaleTypeChanged(QCPAxis::ScaleType scaleType);
132 void gradientChanged(QCPColorGradient newGradient);
133
134 protected:
135 // property members:
136 QCPRange mDataRange;
137 QCPAxis::ScaleType mDataScaleType;
138 QCPColorMapData *mMapData;
139 QCPColorGradient mGradient;
140 bool mInterpolate;
141 bool mTightBoundary;
142 QPointer<QCPColorScale> mColorScale;
143 // non-property members:
144 QImage mMapImage;
145 QPixmap mLegendIcon;
146 bool mMapImageInvalidated;
147
148 // introduced virtual methods:
149 virtual void updateMapImage();
150
151 // reimplemented virtual methods:
152 virtual void draw(QCPPainter *painter);
153 virtual void drawLegendIcon(QCPPainter *painter, const QRectF &rect) const;
154 virtual QCPRange getKeyRange(bool &foundRange, SignDomain inSignDomain=sdBoth) const;
155 virtual QCPRange getValueRange(bool &foundRange, SignDomain inSignDomain=sdBoth) const;
156
157 friend class QCustomPlot;
158 friend class QCPLegend;
159 };
160
161 #endif // QCP_PLOTTABLE_COLORMAP_H
162
Generated with Doxygen 1.8.1.2