@@ -0,0 +1,144 | |||
|
1 | #include "chartcolorbaraxisy_p.h" | |
|
2 | #include <QtCharts/QAbstractAxis> | |
|
3 | #include <private/chartpresenter_p.h> | |
|
4 | //#include <QtCharts/QColorBarAxis> | |
|
5 | #include "colorbaraxis/qcolorbaraxis.h" | |
|
6 | #include <private/abstractchartlayout_p.h> | |
|
7 | #include <QtWidgets/QGraphicsLayout> | |
|
8 | #include <QtCore/QtMath> | |
|
9 | #include <QtCore/QDebug> | |
|
10 | ||
|
11 | QT_CHARTS_BEGIN_NAMESPACE | |
|
12 | ||
|
13 | ChartColorBarAxisY::ChartColorBarAxisY(QColorBarAxis *axis, QLinearGradient gradient, QGraphicsItem *item) | |
|
14 | : VerticalAxis(axis, item), | |
|
15 | m_axis(axis), | |
|
16 | m_gradient(gradient) | |
|
17 | { | |
|
18 | QObject::connect(m_axis, SIGNAL(tickCountChanged(int)), this, SLOT(handleTickCountChanged(int))); | |
|
19 | QObject::connect(m_axis, SIGNAL(minorTickCountChanged(int)), | |
|
20 | this, SLOT(handleMinorTickCountChanged(int))); | |
|
21 | QObject::connect(m_axis, SIGNAL(labelFormatChanged(QString)), this, SLOT(handleLabelFormatChanged(QString))); | |
|
22 | ||
|
23 | createColorBar(); | |
|
24 | } | |
|
25 | ||
|
26 | ChartColorBarAxisY::~ChartColorBarAxisY() | |
|
27 | { | |
|
28 | } | |
|
29 | ||
|
30 | QVector<qreal> ChartColorBarAxisY::calculateLayout() const | |
|
31 | { | |
|
32 | int tickCount = m_axis->tickCount(); | |
|
33 | ||
|
34 | Q_ASSERT(tickCount >= 2); | |
|
35 | ||
|
36 | QVector<qreal> points; | |
|
37 | points.resize(tickCount); | |
|
38 | ||
|
39 | const QRectF &gridRect = gridGeometry(); | |
|
40 | ||
|
41 | const qreal deltaY = gridRect.height() / (qreal(tickCount) - 1.0); | |
|
42 | for (int i = 0; i < tickCount; ++i) | |
|
43 | points[i] = qreal(i) * -deltaY + gridRect.bottom(); | |
|
44 | ||
|
45 | return points; | |
|
46 | } | |
|
47 | ||
|
48 | void ChartColorBarAxisY::updateGeometry() | |
|
49 | { | |
|
50 | const QVector<qreal> &layout = ChartAxisElement::layout(); | |
|
51 | if (layout.isEmpty()) | |
|
52 | return; | |
|
53 | setLabels(createValueLabels(min(),max(),layout.size(),m_axis->labelFormat())); | |
|
54 | VerticalAxis::updateGeometry(); | |
|
55 | } | |
|
56 | ||
|
57 | void ChartColorBarAxisY::handleTickCountChanged(int tick) | |
|
58 | { | |
|
59 | Q_UNUSED(tick); | |
|
60 | QGraphicsLayoutItem::updateGeometry(); | |
|
61 | if (presenter()) presenter()->layout()->invalidate(); | |
|
62 | } | |
|
63 | ||
|
64 | void ChartColorBarAxisY::handleMinorTickCountChanged(int tick) | |
|
65 | { | |
|
66 | Q_UNUSED(tick); | |
|
67 | QGraphicsLayoutItem::updateGeometry(); | |
|
68 | if (presenter()) | |
|
69 | presenter()->layout()->invalidate(); | |
|
70 | } | |
|
71 | ||
|
72 | void ChartColorBarAxisY::handleLabelFormatChanged(const QString &format) | |
|
73 | { | |
|
74 | Q_UNUSED(format); | |
|
75 | QGraphicsLayoutItem::updateGeometry(); | |
|
76 | if(presenter()) presenter()->layout()->invalidate(); | |
|
77 | } | |
|
78 | ||
|
79 | QSizeF ChartColorBarAxisY::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const | |
|
80 | { | |
|
81 | Q_UNUSED(constraint) | |
|
82 | ||
|
83 | QSizeF sh; | |
|
84 | QSizeF base = VerticalAxis::sizeHint(which, constraint); | |
|
85 | QStringList ticksList = createValueLabels(min(),max(),m_axis->tickCount(),m_axis->labelFormat()); | |
|
86 | qreal width = 0; | |
|
87 | // Height of vertical axis sizeHint indicates the maximum distance labels can extend past | |
|
88 | // first and last ticks. Base height is irrelevant. | |
|
89 | qreal height = 0; | |
|
90 | ||
|
91 | switch (which) | |
|
92 | { | |
|
93 | case Qt::MinimumSize: { | |
|
94 | QRectF boundingRect = ChartPresenter::textBoundingRect(axis()->labelsFont(), | |
|
95 | QStringLiteral("..."), | |
|
96 | axis()->labelsAngle()); | |
|
97 | width = boundingRect.width() + labelPadding() + base.width() + 1.0; | |
|
98 | height = boundingRect.height() / 2.0; | |
|
99 | sh = QSizeF(width, height); | |
|
100 | break; | |
|
101 | } | |
|
102 | case Qt::PreferredSize: { | |
|
103 | qreal labelWidth = 0.0; | |
|
104 | qreal firstHeight = -1.0; | |
|
105 | foreach (const QString& s, ticksList) { | |
|
106 | QRectF rect = ChartPresenter::textBoundingRect(axis()->labelsFont(), s, axis()->labelsAngle()); | |
|
107 | labelWidth = qMax(rect.width(), labelWidth); | |
|
108 | height = rect.height(); | |
|
109 | if (firstHeight < 0.0) | |
|
110 | firstHeight = height; | |
|
111 | } | |
|
112 | width = labelWidth + labelPadding() + base.width() + 2.0; //two pixels of tolerance | |
|
113 | height = qMax(height, firstHeight) / 2.0; | |
|
114 | sh = QSizeF(width, height); | |
|
115 | break; | |
|
116 | } | |
|
117 | default: | |
|
118 | break; | |
|
119 | } | |
|
120 | return sh; | |
|
121 | } | |
|
122 | ||
|
123 | void ChartColorBarAxisY::createColorBar() | |
|
124 | { | |
|
125 | QGradientStops stops = m_gradient.stops(); | |
|
126 | ||
|
127 | QLinearGradient gradient(0,0,1,250); | |
|
128 | foreach(QGradientStop stop, stops) | |
|
129 | { | |
|
130 | gradient.setColorAt(1-stop.first,stop.second); | |
|
131 | } | |
|
132 | ||
|
133 | QPixmap image = QPixmap(50,250); | |
|
134 | QPainter painter(&image); | |
|
135 | QRectF rect(0,0,50,250); | |
|
136 | painter.fillRect(rect,gradient); | |
|
137 | ||
|
138 | QGraphicsRectItem *colorbar = new QGraphicsRectItem(rect, this); | |
|
139 | setGraphicsItem(colorbar); | |
|
140 | } | |
|
141 | ||
|
142 | #include "moc_chartcolorbaraxisy_p.cpp" | |
|
143 | ||
|
144 | QT_CHARTS_END_NAMESPACE |
@@ -0,0 +1,39 | |||
|
1 | #ifndef CHARTCOLORBARAXISY_H | |
|
2 | #define CHARTCOLORBARAXISY_H | |
|
3 | ||
|
4 | #include <private/verticalaxis_p.h> | |
|
5 | #include <QtGui> | |
|
6 | ||
|
7 | QT_CHARTS_BEGIN_NAMESPACE | |
|
8 | ||
|
9 | class QColorBarAxis; | |
|
10 | ||
|
11 | class ChartColorBarAxisY : public VerticalAxis | |
|
12 | { | |
|
13 | Q_OBJECT | |
|
14 | public: | |
|
15 | ChartColorBarAxisY(QColorBarAxis *axis, QLinearGradient gradient, QGraphicsItem *item = 0); | |
|
16 | ~ChartColorBarAxisY(); | |
|
17 | ||
|
18 | QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint) const; | |
|
19 | ||
|
20 | ||
|
21 | ||
|
22 | protected: | |
|
23 | QVector<qreal> calculateLayout() const; | |
|
24 | void updateGeometry(); | |
|
25 | private Q_SLOTS: | |
|
26 | void handleTickCountChanged(int tick); | |
|
27 | void handleMinorTickCountChanged(int tick); | |
|
28 | void handleLabelFormatChanged(const QString &format); | |
|
29 | void createColorBar(); | |
|
30 | ||
|
31 | ||
|
32 | private: | |
|
33 | QColorBarAxis *m_axis; | |
|
34 | QLinearGradient m_gradient; | |
|
35 | }; | |
|
36 | ||
|
37 | QT_CHARTS_END_NAMESPACE | |
|
38 | ||
|
39 | #endif // CHARTCOLORBARAXISY_H |
@@ -40,23 +40,24 int main(int argc, char *argv[]) | |||
|
40 | 40 | QApplication a(argc, argv); |
|
41 | 41 | |
|
42 | 42 | QVector<double> *xSeries = new QVector<double>(); |
|
43 | xSeries->append(5.0); | |
|
44 | xSeries->append(15.0); | |
|
45 |
xSeries->append( |
|
|
43 | for(int i=0;i<1028;i++) | |
|
44 | { | |
|
45 | xSeries->append(i*5.0); | |
|
46 | } | |
|
46 | 47 | QVector<double> *ySeries = new QVector<double>(); |
|
47 | ySeries->append(-1.0); | |
|
48 | ySeries->append(0.0); | |
|
49 | ySeries->append(1.0); | |
|
48 | for(int i=0;i<768;i++) | |
|
49 | { | |
|
50 | ySeries->append(i*10.0); | |
|
51 | } | |
|
50 | 52 | QVector<double> *zSeries = new QVector<double>(); |
|
51 | zSeries->append(0.0); | |
|
52 | zSeries->append(1.0); | |
|
53 | zSeries->append(2.0); | |
|
54 |
zSeries->append( |
|
|
55 | zSeries->append(4.0); | |
|
56 |
zSeries->append( |
|
|
57 |
zSeries->append( |
|
|
58 | zSeries->append(7.0); | |
|
59 | zSeries->append(8.0); | |
|
53 | for(int i=0;i<1028*768;i++) | |
|
54 | { | |
|
55 | // if(i%2 != 1) | |
|
56 | // zSeries->append(0); | |
|
57 | // else | |
|
58 | // zSeries->append(1); | |
|
59 | zSeries->append(i); | |
|
60 | } | |
|
60 | 61 | |
|
61 | 62 | ColorMapDataPart * data = new ColorMapDataPart(xSeries,ySeries,zSeries); |
|
62 | 63 |
@@ -32,7 +32,8 SOURCES += \ | |||
|
32 | 32 | $$PWD/logvalueaxis/chartlogvalueaxisx.cpp \ |
|
33 | 33 | $$PWD/logvalueaxis/chartlogvalueaxisy.cpp \ |
|
34 | 34 | $$PWD/logvalueaxis/qlogvalueaxis.cpp \ |
|
35 | $$PWD/colorbaraxis/qcolorbaraxis.cpp | |
|
35 | $$PWD/colorbaraxis/qcolorbaraxis.cpp \ | |
|
36 | $$PWD/colorbaraxis/chartcolorbaraxisy.cpp | |
|
36 | 37 | |
|
37 | 38 | PRIVATE_HEADERS += \ |
|
38 | 39 | $$PWD/chartaxiselement_p.h \ |
@@ -53,7 +54,7 PRIVATE_HEADERS += \ | |||
|
53 | 54 | $$PWD/logvalueaxis/chartlogvalueaxisx_p.h \ |
|
54 | 55 | $$PWD/logvalueaxis/chartlogvalueaxisy_p.h \ |
|
55 | 56 | $$PWD/logvalueaxis/qlogvalueaxis_p.h \ |
|
56 |
|
|
|
57 | $$PWD/colorbaraxis/qcolorbaraxis_p.h | |
|
57 | 58 | |
|
58 | 59 | PUBLIC_HEADERS += \ |
|
59 | 60 | $$PWD/qabstractaxis.h \ |
@@ -111,5 +112,5 PUBLIC_HEADERS += \ | |||
|
111 | 112 | $$PWD/datetimeaxis/qdatetimeaxis.h |
|
112 | 113 | } |
|
113 | 114 | |
|
114 | ||
|
115 | ||
|
115 | HEADERS += \ | |
|
116 | $$PWD/colorbaraxis/chartcolorbaraxisy_p.h |
@@ -7,6 +7,9 | |||
|
7 | 7 | #include <private/chartpresenter_p.h> |
|
8 | 8 | #include <private/charttheme_p.h> |
|
9 | 9 | |
|
10 | //#include <private/chartcolorbaraxisy_p.h> | |
|
11 | #include <chartcolorbaraxisy_p.h> | |
|
12 | ||
|
10 | 13 | #include <QtGui> |
|
11 | 14 | |
|
12 | 15 | QT_CHARTS_BEGIN_NAMESPACE |
@@ -40,48 +43,66 QColorBarAxis::~QColorBarAxis() | |||
|
40 | 43 | d->m_chart->removeAxis(this); |
|
41 | 44 | } |
|
42 | 45 | |
|
46 | void QColorBarAxis::setMin(qreal min) | |
|
47 | { | |
|
48 | Q_D(QColorBarAxis); | |
|
49 | setRange(min, qMax(d->m_max, min)); | |
|
50 | } | |
|
51 | ||
|
43 | 52 | qreal QColorBarAxis::min() const |
|
44 | 53 | { |
|
45 | 54 | Q_D(const QColorBarAxis); |
|
46 | 55 | return d->m_min; |
|
47 | 56 | } |
|
48 | 57 | |
|
58 | void QColorBarAxis::setMax(qreal max) | |
|
59 | { | |
|
60 | Q_D(QColorBarAxis); | |
|
61 | setRange(qMin(d->m_min, max), max); | |
|
62 | } | |
|
63 | ||
|
49 | 64 | qreal QColorBarAxis::max() const |
|
50 | 65 | { |
|
51 | 66 | Q_D(const QColorBarAxis); |
|
52 | 67 | return d->m_max; |
|
53 | 68 | } |
|
54 | 69 | |
|
70 | void QColorBarAxis::setRange(qreal min, qreal max) | |
|
71 | { | |
|
72 | Q_D(QColorBarAxis); | |
|
73 | d->setRange(min,max); | |
|
74 | } | |
|
55 | 75 | |
|
56 | //void QColorBarAxis::setTickCount(int count) | |
|
57 | //{ | |
|
58 | // Q_D(QColorBarAxis); | |
|
59 | // if (d->m_tickCount != count && count >= 2) { | |
|
60 |
|
|
|
61 |
|
|
|
62 | // } | |
|
63 | //} | |
|
76 | ||
|
77 | void QColorBarAxis::setTickCount(int count) | |
|
78 | { | |
|
79 | Q_D(QColorBarAxis); | |
|
80 | if (d->m_tickCount != count && count >= 2) { | |
|
81 | d->m_tickCount = count; | |
|
82 | emit tickCountChanged(count); | |
|
83 | } | |
|
84 | } | |
|
64 | 85 | |
|
65 |
|
|
|
66 | //{ | |
|
67 |
|
|
|
68 |
|
|
|
69 | //} | |
|
86 | int QColorBarAxis::tickCount() const | |
|
87 | { | |
|
88 | Q_D(const QColorBarAxis); | |
|
89 | return d->m_tickCount; | |
|
90 | } | |
|
70 | 91 | |
|
71 |
|
|
|
72 | //{ | |
|
73 |
|
|
|
74 |
|
|
|
75 |
|
|
|
76 |
|
|
|
77 |
|
|
|
78 | //} | |
|
92 | void QColorBarAxis::setMinorTickCount(int count) | |
|
93 | { | |
|
94 | Q_D(QColorBarAxis); | |
|
95 | if (d->m_minorTickCount != count && count >= 0) { | |
|
96 | d->m_minorTickCount = count; | |
|
97 | emit minorTickCountChanged(count); | |
|
98 | } | |
|
99 | } | |
|
79 | 100 | |
|
80 |
|
|
|
81 | //{ | |
|
82 |
|
|
|
83 |
|
|
|
84 | //} | |
|
101 | int QColorBarAxis::minorTickCount() const | |
|
102 | { | |
|
103 | Q_D(const QColorBarAxis); | |
|
104 | return d->m_minorTickCount; | |
|
105 | } | |
|
85 | 106 | |
|
86 | 107 | void QColorBarAxis::setLabelFormat(const QString &format) |
|
87 | 108 | { |
@@ -105,14 +126,16 QAbstractAxis::AxisType QColorBarAxis::t | |||
|
105 | 126 | //TODO : AxisTypeColorBar |
|
106 | 127 | } |
|
107 | 128 | |
|
129 | ||
|
130 | ||
|
108 | 131 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
109 | 132 | |
|
110 | 133 | QColorBarAxisPrivate::QColorBarAxisPrivate(QLinearGradient gradient, qreal min, qreal max, QColorBarAxis *q) |
|
111 | 134 | : QAbstractAxisPrivate(q), |
|
112 | 135 | m_min(min), |
|
113 | 136 | m_max(max), |
|
114 |
|
|
|
115 |
|
|
|
137 | m_tickCount(5), | |
|
138 | m_minorTickCount(0), | |
|
116 | 139 | m_format(QString::null), |
|
117 | 140 | // m_applying(false) |
|
118 | 141 | m_gradient(gradient) |
@@ -132,19 +155,9 void QColorBarAxisPrivate::initializeGra | |||
|
132 | 155 | |
|
133 | 156 | setAlignment(Qt::AlignRight); //also set orientation (Vertical in this case) |
|
134 | 157 | |
|
135 | QGradientStops stops = m_gradient.stops(); | |
|
158 | axis = new ChartColorBarAxisY(q, m_gradient, parent); | |
|
136 | 159 | |
|
137 | QLinearGradient gradient(0,0,1,250); | |
|
138 | foreach(QGradientStop stop, stops) | |
|
139 | { | |
|
140 | gradient.setColorAt(1-stop.first,stop.second); | |
|
141 | } | |
|
142 | ||
|
143 | QPixmap image = QPixmap(50,250); | |
|
144 | QPainter painter(&image); | |
|
145 | painter.fillRect(0,0,50,250,gradient); | |
|
146 | ||
|
147 | //m_item.reset(axis); | |
|
160 | m_item.reset(axis); | |
|
148 | 161 | QAbstractAxisPrivate::initializeGraphics(parent); |
|
149 | 162 | } |
|
150 | 163 | |
@@ -152,18 +165,79 void QColorBarAxisPrivate::initializeDom | |||
|
152 | 165 | { |
|
153 | 166 | //domain is not supposed to have a rangeZ |
|
154 | 167 | |
|
155 |
|
|
|
156 |
|
|
|
157 |
|
|
|
158 |
|
|
|
159 |
|
|
|
160 |
|
|
|
161 | // if (orientation() == Qt::Horizontal) { | |
|
162 | // if (!qFuzzyIsNull(m_max - m_min)) | |
|
163 | // domain->setRangeX(m_min, m_max); | |
|
164 | // else | |
|
165 | // setRange(domain->minX(), domain->maxX()); | |
|
166 | // } | |
|
168 | // if (orientation() == Qt::Vertical) { | |
|
169 | // if (!qFuzzyIsNull(m_max - m_min)) | |
|
170 | // domain->setRangeY(m_min, m_max); | |
|
171 | // else | |
|
172 | // setRange(domain->minY(), domain->maxY()); | |
|
173 | // } | |
|
174 | } | |
|
175 | ||
|
176 | void QColorBarAxisPrivate::setMin(const QVariant &min) | |
|
177 | { | |
|
178 | Q_Q(QColorBarAxis); | |
|
179 | bool ok; | |
|
180 | qreal value = min.toReal(&ok); | |
|
181 | if (ok) | |
|
182 | q->setMin(value); | |
|
183 | } | |
|
184 | ||
|
185 | void QColorBarAxisPrivate::setMax(const QVariant &max) | |
|
186 | { | |
|
187 | Q_Q(QColorBarAxis); | |
|
188 | bool ok; | |
|
189 | qreal value = max.toReal(&ok); | |
|
190 | if (ok) | |
|
191 | q->setMax(value); | |
|
192 | } | |
|
193 | ||
|
194 | void QColorBarAxisPrivate::setRange(const QVariant &min, const QVariant &max) | |
|
195 | { | |
|
196 | Q_Q(QColorBarAxis); | |
|
197 | bool ok1; | |
|
198 | bool ok2; | |
|
199 | qreal value1 = min.toReal(&ok1); | |
|
200 | qreal value2 = max.toReal(&ok2); | |
|
201 | if (ok1 && ok2) | |
|
202 | q->setRange(value1, value2); | |
|
203 | } | |
|
204 | ||
|
205 | void QColorBarAxisPrivate::setRange(qreal min,qreal max) | |
|
206 | { | |
|
207 | Q_Q(QColorBarAxis); | |
|
208 | bool changed = false; | |
|
209 | ||
|
210 | if (min > max) | |
|
211 | return; | |
|
212 | ||
|
213 | bool changeMin = false; | |
|
214 | if (m_min == 0 || min == 0) | |
|
215 | changeMin = !qFuzzyCompare(1 + m_min, 1 + min); | |
|
216 | else | |
|
217 | changeMin = !qFuzzyCompare(m_min, min); | |
|
218 | ||
|
219 | bool changeMax = false; | |
|
220 | if (m_max == 0 || max == 0) | |
|
221 | changeMax = !qFuzzyCompare(1 + m_max, 1 + max); | |
|
222 | else | |
|
223 | changeMax = !qFuzzyCompare(m_max, max); | |
|
224 | ||
|
225 | if (changeMin) { | |
|
226 | m_min = min; | |
|
227 | changed = true; | |
|
228 | emit q->minChanged(min); | |
|
229 | } | |
|
230 | ||
|
231 | if (changeMax) { | |
|
232 | m_max = max; | |
|
233 | changed = true; | |
|
234 | emit q->maxChanged(max); | |
|
235 | } | |
|
236 | ||
|
237 | if (changed) { | |
|
238 | emit rangeChanged(min,max); | |
|
239 | emit q->rangeChanged(min, max); | |
|
240 | } | |
|
167 | 241 | } |
|
168 | 242 | |
|
169 | 243 |
@@ -21,14 +21,17 public: | |||
|
21 | 21 | AxisType type() const; |
|
22 | 22 | |
|
23 | 23 | //range handling |
|
24 | void setMin(qreal min); | |
|
24 | 25 | qreal min() const; |
|
26 | void setMax(qreal max); | |
|
25 | 27 | qreal max() const; |
|
28 | void setRange(qreal min, qreal max); | |
|
26 | 29 | |
|
27 | 30 | //ticks handling |
|
28 |
|
|
|
29 |
|
|
|
30 |
|
|
|
31 |
|
|
|
31 | void setTickCount(int count); | |
|
32 | int tickCount() const; | |
|
33 | void setMinorTickCount(int count); | |
|
34 | int minorTickCount() const; | |
|
32 | 35 | |
|
33 | 36 | void setLabelFormat(const QString &format); |
|
34 | 37 | QString labelFormat() const; |
@@ -37,8 +40,8 Q_SIGNALS: | |||
|
37 | 40 | void minChanged(qreal min); |
|
38 | 41 | void maxChanged(qreal max); |
|
39 | 42 | void rangeChanged(qreal min, qreal max); |
|
40 |
|
|
|
41 |
|
|
|
43 | void tickCountChanged(int tickCount); | |
|
44 | void minorTickCountChanged(int tickCount); | |
|
42 | 45 | void labelFormatChanged(const QString &format); |
|
43 | 46 | |
|
44 | 47 | private: |
@@ -30,12 +30,14 protected: | |||
|
30 | 30 | private: |
|
31 | 31 | qreal m_min; |
|
32 | 32 | qreal m_max; |
|
33 |
|
|
|
34 |
|
|
|
33 | int m_tickCount; | |
|
34 | int m_minorTickCount; | |
|
35 | 35 | QString m_format; |
|
36 | 36 | // bool m_applying; |
|
37 | 37 | QLinearGradient m_gradient; |
|
38 | 38 | Q_DECLARE_PUBLIC(QColorBarAxis) |
|
39 | 39 | }; |
|
40 | 40 | |
|
41 | QT_CHARTS_END_NAMESPACE | |
|
42 | ||
|
41 | 43 | #endif // QCOLORBARAXIS_P_H |
@@ -20,7 +20,8 ColorMapChart::ColorMapChart(QColorMapSe | |||
|
20 | 20 | : ChartItem(series->d_func(), item), |
|
21 | 21 | m_series(series), |
|
22 | 22 | m_dirty(true), |
|
23 | m_gradientType(Rainbow) | |
|
23 | m_gradientType(Rainbow), | |
|
24 | m_colorbar(false) | |
|
24 | 25 | { |
|
25 | 26 | // QObject::connect(series, SIGNAL(pointReplaced(int)), this, SLOT(handlePointReplaced(int))); |
|
26 | 27 | // QObject::connect(series, SIGNAL(pointsReplaced()), this, SLOT(handlePointsReplaced())); |
@@ -79,12 +80,21 void ColorMapChart::paint(QPainter *pain | |||
|
79 | 80 | colorMapImage.setPixel(i,j,m_colorTable->at(indexInColorTable)); |
|
80 | 81 | } |
|
81 | 82 | } |
|
83 | ||
|
84 | if(!m_colorbar) | |
|
85 | addColorBar(); | |
|
86 | ||
|
82 | 87 | painter->drawImage(clipRect,colorMapImage); |
|
83 | 88 | update(); |
|
89 | } | |
|
84 | 90 | |
|
85 | QColorBarAxis *colorbar = new QColorBarAxis(createColorMapGradient(m_gradientType),minZ, maxZ,this); | |
|
86 | ||
|
91 | void ColorMapChart::addColorBar() | |
|
92 | { | |
|
93 | double maxZ = m_series->maxZ(); | |
|
94 | double minZ = m_series->minZ(); | |
|
95 | QColorBarAxis *colorbar = new QColorBarAxis(createColorMapGradient(m_gradientType),minZ, maxZ,this); | |
|
87 | 96 | m_series->chart()->addAxis(colorbar, Qt::AlignRight); |
|
97 | m_colorbar = true; | |
|
88 | 98 | } |
|
89 | 99 | |
|
90 | 100 | /*! |
@@ -56,6 +56,7 Q_SIGNALS: | |||
|
56 | 56 | |
|
57 | 57 | private: |
|
58 | 58 | inline bool isEmpty(); |
|
59 | void addColorBar(); | |
|
59 | 60 | QLinearGradient createColorMapGradient(GradientType gradientType); |
|
60 | 61 | void changeGradient(GradientType gradientType); |
|
61 | 62 | |
@@ -66,6 +67,7 protected: | |||
|
66 | 67 | bool m_dirty; |
|
67 | 68 | QVector<QRgb> *m_colorTable; |
|
68 | 69 | GradientType m_gradientType; |
|
70 | bool m_colorbar; | |
|
69 | 71 | }; |
|
70 | 72 | |
|
71 | 73 | //class PixmapMarker: public QGraphicsRectItem |
@@ -11,6 +11,8 | |||
|
11 | 11 | //#include <algorithm> |
|
12 | 12 | #include <cmath> |
|
13 | 13 | |
|
14 | #include "qcolorbaraxis.h" | |
|
15 | ||
|
14 | 16 | QT_CHARTS_BEGIN_NAMESPACE |
|
15 | 17 | |
|
16 | 18 | /*! |
@@ -124,6 +126,19 ColorMapDataPart *QColorMapSeries::getUn | |||
|
124 | 126 | return d->getUniformGrid(xpos, ypos,width,height, strategy); |
|
125 | 127 | } |
|
126 | 128 | |
|
129 | //void QColorMapSeries::attachAxis(QAbstractAxis *axis) | |
|
130 | //{ | |
|
131 | // axis = static_cast<QColorBarAxis*>(); | |
|
132 | // if(axis) | |
|
133 | // { | |
|
134 | ||
|
135 | // } | |
|
136 | // else | |
|
137 | // { | |
|
138 | // QAbstractSeries::attachAxis(axis); | |
|
139 | // } | |
|
140 | //} | |
|
141 | ||
|
127 | 142 | /*! |
|
128 | 143 | Sets \a pen used for drawing points on the chart. If the pen is not defined, the |
|
129 | 144 | pen from chart theme is used. |
@@ -134,11 +149,11 void QColorMapSeries::setPen(const QPen | |||
|
134 | 149 | Q_D(QColorMapSeries); |
|
135 | 150 | if (d->m_pen != pen) |
|
136 | 151 | { |
|
137 | bool emitColorChanged = d->m_pen.color() != pen.color(); | |
|
152 | //bool emitColorChanged = d->m_pen.color() != pen.color(); | |
|
138 | 153 | d->m_pen = pen; |
|
139 | 154 | emit d->updated(); |
|
140 |
|
|
|
141 |
|
|
|
155 | // if (emitColorChanged) | |
|
156 | // emit colorChanged(pen.color()); | |
|
142 | 157 | emit penChanged(pen); |
|
143 | 158 | } |
|
144 | 159 | } |
@@ -461,7 +476,6 ColorMapDataPart *QColorMapSeriesPrivate | |||
|
461 | 476 | |
|
462 | 477 | } |
|
463 | 478 | } |
|
464 | ||
|
465 | 479 | return grid; |
|
466 | 480 | } |
|
467 | 481 |
@@ -51,6 +51,8 public : | |||
|
51 | 51 | ColorMapDataPart* getUniformGrid(int xpos, int ypos,int width, int height, Strategy strategy); |
|
52 | 52 | //double getUniformGrid(int width, int height, Strategy lambda); |
|
53 | 53 | |
|
54 | // virtual void attachAxis(QAbstractAxis *axis); | |
|
55 | ||
|
54 | 56 | virtual void setPen(const QPen &pen); |
|
55 | 57 | QPen pen() const; |
|
56 | 58 |
General Comments 0
You need to be logged in to leave comments.
Login now