@@ -1,84 +1,86 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2016 The Qt Company Ltd. |
|
3 | ** Copyright (C) 2016 The Qt Company Ltd. | |
4 | ** Contact: https://www.qt.io/licensing/ |
|
4 | ** Contact: https://www.qt.io/licensing/ | |
5 | ** |
|
5 | ** | |
6 | ** This file is part of the Qt Charts module of the Qt Toolkit. |
|
6 | ** This file is part of the Qt Charts module of the Qt Toolkit. | |
7 | ** |
|
7 | ** | |
8 | ** $QT_BEGIN_LICENSE:GPL$ |
|
8 | ** $QT_BEGIN_LICENSE:GPL$ | |
9 | ** Commercial License Usage |
|
9 | ** Commercial License Usage | |
10 | ** Licensees holding valid commercial Qt licenses may use this file in |
|
10 | ** Licensees holding valid commercial Qt licenses may use this file in | |
11 | ** accordance with the commercial license agreement provided with the |
|
11 | ** accordance with the commercial license agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and The Qt Company. For licensing terms |
|
13 | ** a written agreement between you and The Qt Company. For licensing terms | |
14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
|
14 | ** and conditions see https://www.qt.io/terms-conditions. For further | |
15 | ** information use the contact form at https://www.qt.io/contact-us. |
|
15 | ** information use the contact form at https://www.qt.io/contact-us. | |
16 | ** |
|
16 | ** | |
17 | ** GNU General Public License Usage |
|
17 | ** GNU General Public License Usage | |
18 | ** Alternatively, this file may be used under the terms of the GNU |
|
18 | ** Alternatively, this file may be used under the terms of the GNU | |
19 | ** General Public License version 3 or (at your option) any later version |
|
19 | ** General Public License version 3 or (at your option) any later version | |
20 | ** approved by the KDE Free Qt Foundation. The licenses are as published by |
|
20 | ** approved by the KDE Free Qt Foundation. The licenses are as published by | |
21 | ** the Free Software Foundation and appearing in the file LICENSE.GPL3 |
|
21 | ** the Free Software Foundation and appearing in the file LICENSE.GPL3 | |
22 | ** included in the packaging of this file. Please review the following |
|
22 | ** included in the packaging of this file. Please review the following | |
23 | ** information to ensure the GNU General Public License requirements will |
|
23 | ** information to ensure the GNU General Public License requirements will | |
24 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. |
|
24 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. | |
25 | ** |
|
25 | ** | |
26 | ** $QT_END_LICENSE$ |
|
26 | ** $QT_END_LICENSE$ | |
27 | ** |
|
27 | ** | |
28 | ****************************************************************************/ |
|
28 | ****************************************************************************/ | |
29 |
|
29 | |||
30 | #include <QtWidgets/QApplication> |
|
30 | #include <QtWidgets/QApplication> | |
31 | #include <QtWidgets/QMainWindow> |
|
31 | #include <QtWidgets/QMainWindow> | |
32 | #include <QtCharts/QChartView> |
|
32 | #include <QtCharts/QChartView> | |
33 | #include <QtCharts/QColorMapSeries> |
|
33 | #include <QtCharts/QColorMapSeries> | |
34 | #include <QtCharts/colormapdatapart.h> |
|
34 | #include <QtCharts/colormapdatapart.h> | |
35 |
|
35 | |||
36 | QT_CHARTS_USE_NAMESPACE |
|
36 | QT_CHARTS_USE_NAMESPACE | |
37 |
|
37 | |||
38 | int main(int argc, char *argv[]) |
|
38 | int main(int argc, char *argv[]) | |
39 | { |
|
39 | { | |
40 | QApplication a(argc, argv); |
|
40 | QApplication a(argc, argv); | |
41 |
|
41 | |||
42 | QVector<double> *xSeries = new QVector<double>(); |
|
42 | QVector<double> *xSeries = new QVector<double>(); | |
|
43 | xSeries->reserve(1028); | |||
43 | for(int i=0;i<1028;i++) |
|
44 | for(int i=0;i<1028;i++) | |
44 | { |
|
45 | { | |
45 |
xSeries->append(i |
|
46 | xSeries->append(i); | |
46 | } |
|
47 | } | |
47 | QVector<double> *ySeries = new QVector<double>(); |
|
48 | QVector<double> *ySeries = new QVector<double>(); | |
|
49 | ySeries->reserve(768); | |||
48 | for(int i=0;i<768;i++) |
|
50 | for(int i=0;i<768;i++) | |
49 | { |
|
51 | { | |
50 |
ySeries->append(i |
|
52 | ySeries->append(i); | |
51 | } |
|
53 | } | |
52 | QVector<double> *zSeries = new QVector<double>(); |
|
54 | QVector<double> *zSeries = new QVector<double>(); | |
|
55 | zSeries->reserve(1028*768); | |||
53 | for(int i=0;i<1028*768;i++) |
|
56 | for(int i=0;i<1028*768;i++) | |
54 | { |
|
57 | { | |
55 |
|
|
58 | // if(i%2 != 1) | |
56 |
|
|
59 | // zSeries->append(0); | |
57 |
|
|
60 | // else | |
58 |
|
|
61 | // zSeries->append(1); | |
59 | zSeries->append(i); |
|
62 | zSeries->append(i); | |
60 | } |
|
63 | } | |
61 |
|
64 | |||
62 | ColorMapDataPart * data = new ColorMapDataPart(xSeries,ySeries,zSeries); |
|
65 | ColorMapDataPart * data = new ColorMapDataPart(xSeries,ySeries,zSeries); | |
63 |
|
66 | |||
64 | QColorMapSeries *series = new QColorMapSeries(); |
|
67 | QColorMapSeries *series = new QColorMapSeries(); | |
65 | series->append(data); |
|
68 | series->append(data); | |
66 |
|
69 | |||
67 | QChart *chart = new QChart(); |
|
70 | QChart *chart = new QChart(); | |
68 | chart->addSeries(series); |
|
71 | chart->addSeries(series); | |
69 | chart->setTitle("Simple colormap example"); |
|
72 | chart->setTitle("Simple colormap example"); | |
70 | chart->createDefaultAxes(); |
|
73 | chart->createDefaultAxes(); | |
71 | chart->axisX()->setGridLineVisible(false); |
|
74 | chart->axisX()->setGridLineVisible(false); | |
72 | chart->axisY()->setGridLineVisible(false); |
|
75 | chart->axisY()->setGridLineVisible(false); | |
73 |
|
76 | |||
74 | QChartView *chartView = new QChartView(chart); |
|
77 | QChartView *chartView = new QChartView(chart); | |
75 | chartView->setRenderHint(QPainter::Antialiasing); |
|
78 | chartView->setRenderHint(QPainter::Antialiasing); | |
76 |
|
79 | |||
77 | QMainWindow window; |
|
80 | QMainWindow window; | |
78 | window.setCentralWidget(chartView); |
|
81 | window.setCentralWidget(chartView); | |
79 | window.resize(100-77, 100-53); |
|
82 | window.resize(100-77, 100-53); | |
80 | window.show(); |
|
83 | window.show(); | |
81 |
|
84 | |||
82 |
|
||||
83 | return a.exec(); |
|
85 | return a.exec(); | |
84 | } |
|
86 | } |
@@ -1,144 +1,148 | |||||
1 | #include "chartcolorbaraxisy_p.h" |
|
1 | #include "chartcolorbaraxisy_p.h" | |
2 | #include <QtCharts/QAbstractAxis> |
|
2 | #include <QtCharts/QAbstractAxis> | |
3 | #include <private/chartpresenter_p.h> |
|
3 | #include <private/chartpresenter_p.h> | |
4 | //#include <QtCharts/QColorBarAxis> |
|
4 | //#include <QtCharts/QColorBarAxis> | |
5 | #include "colorbaraxis/qcolorbaraxis.h" |
|
5 | #include "colorbaraxis/qcolorbaraxis.h" | |
6 | #include <private/abstractchartlayout_p.h> |
|
6 | #include <private/abstractchartlayout_p.h> | |
7 | #include <QtWidgets/QGraphicsLayout> |
|
7 | #include <QtWidgets/QGraphicsLayout> | |
8 | #include <QtCore/QtMath> |
|
8 | #include <QtCore/QtMath> | |
9 | #include <QtCore/QDebug> |
|
9 | #include <QtCore/QDebug> | |
10 |
|
10 | |||
11 | QT_CHARTS_BEGIN_NAMESPACE |
|
11 | QT_CHARTS_BEGIN_NAMESPACE | |
12 |
|
12 | |||
13 | ChartColorBarAxisY::ChartColorBarAxisY(QColorBarAxis *axis, QLinearGradient gradient, QGraphicsItem *item) |
|
13 | ChartColorBarAxisY::ChartColorBarAxisY(QColorBarAxis *axis, QPoint pos, qreal height, QLinearGradient gradient, QGraphicsItem *item) | |
14 | : VerticalAxis(axis, item), |
|
14 | : VerticalAxis(axis, item), | |
15 | m_axis(axis), |
|
15 | m_axis(axis), | |
16 | m_gradient(gradient) |
|
16 | m_gradient(gradient), | |
|
17 | m_position(pos), | |||
|
18 | m_height(height) | |||
17 | { |
|
19 | { | |
18 | QObject::connect(m_axis, SIGNAL(tickCountChanged(int)), this, SLOT(handleTickCountChanged(int))); |
|
20 | QObject::connect(m_axis, SIGNAL(tickCountChanged(int)), this, SLOT(handleTickCountChanged(int))); | |
19 | QObject::connect(m_axis, SIGNAL(minorTickCountChanged(int)), |
|
21 | QObject::connect(m_axis, SIGNAL(minorTickCountChanged(int)), | |
20 | this, SLOT(handleMinorTickCountChanged(int))); |
|
22 | this, SLOT(handleMinorTickCountChanged(int))); | |
21 | QObject::connect(m_axis, SIGNAL(labelFormatChanged(QString)), this, SLOT(handleLabelFormatChanged(QString))); |
|
23 | QObject::connect(m_axis, SIGNAL(labelFormatChanged(QString)), this, SLOT(handleLabelFormatChanged(QString))); | |
22 |
|
24 | |||
23 | createColorBar(); |
|
25 | createColorBar(); | |
24 | } |
|
26 | } | |
25 |
|
27 | |||
26 | ChartColorBarAxisY::~ChartColorBarAxisY() |
|
28 | ChartColorBarAxisY::~ChartColorBarAxisY() | |
27 | { |
|
29 | { | |
28 | } |
|
30 | } | |
29 |
|
31 | |||
30 | QVector<qreal> ChartColorBarAxisY::calculateLayout() const |
|
32 | QVector<qreal> ChartColorBarAxisY::calculateLayout() const | |
31 | { |
|
33 | { | |
32 | int tickCount = m_axis->tickCount(); |
|
34 | int tickCount = m_axis->tickCount(); | |
33 |
|
35 | |||
34 | Q_ASSERT(tickCount >= 2); |
|
36 | Q_ASSERT(tickCount >= 2); | |
35 |
|
37 | |||
36 | QVector<qreal> points; |
|
38 | QVector<qreal> points; | |
37 | points.resize(tickCount); |
|
39 | points.resize(tickCount); | |
38 |
|
40 | |||
39 | const QRectF &gridRect = gridGeometry(); |
|
41 | const QRectF &gridRect = gridGeometry(); | |
40 |
|
42 | |||
41 | const qreal deltaY = gridRect.height() / (qreal(tickCount) - 1.0); |
|
43 | const qreal deltaY = gridRect.height() / (qreal(tickCount) - 1.0); | |
42 | for (int i = 0; i < tickCount; ++i) |
|
44 | for (int i = 0; i < tickCount; ++i) | |
43 | points[i] = qreal(i) * -deltaY + gridRect.bottom(); |
|
45 | points[i] = qreal(i) * -deltaY + gridRect.bottom(); | |
44 |
|
46 | |||
45 | return points; |
|
47 | return points; | |
46 | } |
|
48 | } | |
47 |
|
49 | |||
48 | void ChartColorBarAxisY::updateGeometry() |
|
50 | void ChartColorBarAxisY::updateGeometry() | |
49 | { |
|
51 | { | |
50 | const QVector<qreal> &layout = ChartAxisElement::layout(); |
|
52 | const QVector<qreal> &layout = ChartAxisElement::layout(); | |
51 | if (layout.isEmpty()) |
|
53 | if (layout.isEmpty()) | |
52 | return; |
|
54 | return; | |
53 | setLabels(createValueLabels(min(),max(),layout.size(),m_axis->labelFormat())); |
|
55 | setLabels(createValueLabels(min(),max(),layout.size(),m_axis->labelFormat())); | |
54 | VerticalAxis::updateGeometry(); |
|
56 | VerticalAxis::updateGeometry(); | |
55 | } |
|
57 | } | |
56 |
|
58 | |||
57 | void ChartColorBarAxisY::handleTickCountChanged(int tick) |
|
59 | void ChartColorBarAxisY::handleTickCountChanged(int tick) | |
58 | { |
|
60 | { | |
59 | Q_UNUSED(tick); |
|
61 | Q_UNUSED(tick); | |
60 | QGraphicsLayoutItem::updateGeometry(); |
|
62 | QGraphicsLayoutItem::updateGeometry(); | |
61 | if (presenter()) presenter()->layout()->invalidate(); |
|
63 | if (presenter()) presenter()->layout()->invalidate(); | |
62 | } |
|
64 | } | |
63 |
|
65 | |||
64 | void ChartColorBarAxisY::handleMinorTickCountChanged(int tick) |
|
66 | void ChartColorBarAxisY::handleMinorTickCountChanged(int tick) | |
65 | { |
|
67 | { | |
66 | Q_UNUSED(tick); |
|
68 | Q_UNUSED(tick); | |
67 | QGraphicsLayoutItem::updateGeometry(); |
|
69 | QGraphicsLayoutItem::updateGeometry(); | |
68 | if (presenter()) |
|
70 | if (presenter()) | |
69 | presenter()->layout()->invalidate(); |
|
71 | presenter()->layout()->invalidate(); | |
70 | } |
|
72 | } | |
71 |
|
73 | |||
72 | void ChartColorBarAxisY::handleLabelFormatChanged(const QString &format) |
|
74 | void ChartColorBarAxisY::handleLabelFormatChanged(const QString &format) | |
73 | { |
|
75 | { | |
74 | Q_UNUSED(format); |
|
76 | Q_UNUSED(format); | |
75 | QGraphicsLayoutItem::updateGeometry(); |
|
77 | QGraphicsLayoutItem::updateGeometry(); | |
76 | if(presenter()) presenter()->layout()->invalidate(); |
|
78 | if(presenter()) presenter()->layout()->invalidate(); | |
77 | } |
|
79 | } | |
78 |
|
80 | |||
79 | QSizeF ChartColorBarAxisY::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const |
|
81 | QSizeF ChartColorBarAxisY::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const | |
80 | { |
|
82 | { | |
81 | Q_UNUSED(constraint) |
|
83 | Q_UNUSED(constraint) | |
82 |
|
84 | |||
83 | QSizeF sh; |
|
85 | QSizeF sh; | |
84 | QSizeF base = VerticalAxis::sizeHint(which, constraint); |
|
86 | QSizeF base = VerticalAxis::sizeHint(which, constraint); | |
85 | QStringList ticksList = createValueLabels(min(),max(),m_axis->tickCount(),m_axis->labelFormat()); |
|
87 | QStringList ticksList = createValueLabels(min(),max(),m_axis->tickCount(),m_axis->labelFormat()); | |
86 | qreal width = 0; |
|
88 | qreal width = 0; | |
87 | // Height of vertical axis sizeHint indicates the maximum distance labels can extend past |
|
89 | // Height of vertical axis sizeHint indicates the maximum distance labels can extend past | |
88 | // first and last ticks. Base height is irrelevant. |
|
90 | // first and last ticks. Base height is irrelevant. | |
89 | qreal height = 0; |
|
91 | qreal height = 0; | |
90 |
|
92 | |||
91 | switch (which) |
|
93 | switch (which) | |
92 | { |
|
94 | { | |
93 | case Qt::MinimumSize: { |
|
95 | case Qt::MinimumSize: { | |
94 | QRectF boundingRect = ChartPresenter::textBoundingRect(axis()->labelsFont(), |
|
96 | QRectF boundingRect = ChartPresenter::textBoundingRect(axis()->labelsFont(), | |
95 | QStringLiteral("..."), |
|
97 | QStringLiteral("..."), | |
96 | axis()->labelsAngle()); |
|
98 | axis()->labelsAngle()); | |
97 | width = boundingRect.width() + labelPadding() + base.width() + 1.0; |
|
99 | width = boundingRect.width() + labelPadding() + base.width() + 61.0; //TODO : hint changed 1.0 to 61.0 | |
98 | height = boundingRect.height() / 2.0; |
|
100 | height = boundingRect.height() / 2.0; | |
99 | sh = QSizeF(width, height); |
|
101 | sh = QSizeF(width, height); | |
100 | break; |
|
102 | break; | |
101 | } |
|
103 | } | |
102 | case Qt::PreferredSize: { |
|
104 | case Qt::PreferredSize: { | |
103 | qreal labelWidth = 0.0; |
|
105 | qreal labelWidth = 0.0; | |
104 | qreal firstHeight = -1.0; |
|
106 | qreal firstHeight = -1.0; | |
105 | foreach (const QString& s, ticksList) { |
|
107 | foreach (const QString& s, ticksList) { | |
106 | QRectF rect = ChartPresenter::textBoundingRect(axis()->labelsFont(), s, axis()->labelsAngle()); |
|
108 | QRectF rect = ChartPresenter::textBoundingRect(axis()->labelsFont(), s, axis()->labelsAngle()); | |
107 | labelWidth = qMax(rect.width(), labelWidth); |
|
109 | labelWidth = qMax(rect.width(), labelWidth); | |
108 | height = rect.height(); |
|
110 | height = rect.height(); | |
109 | if (firstHeight < 0.0) |
|
111 | if (firstHeight < 0.0) | |
110 | firstHeight = height; |
|
112 | firstHeight = height; | |
111 | } |
|
113 | } | |
112 | width = labelWidth + labelPadding() + base.width() + 2.0; //two pixels of tolerance |
|
114 | width = labelWidth + labelPadding() + base.width() + 62.0; //two pixels of tolerance //TODO : hint changed 2.0 to 62.0 | |
113 | height = qMax(height, firstHeight) / 2.0; |
|
115 | height = qMax(height, firstHeight) / 2.0; | |
114 | sh = QSizeF(width, height); |
|
116 | sh = QSizeF(width, height); | |
115 | break; |
|
117 | break; | |
116 | } |
|
118 | } | |
117 | default: |
|
119 | default: | |
118 | break; |
|
120 | break; | |
119 | } |
|
121 | } | |
120 | return sh; |
|
122 | return sh; | |
121 | } |
|
123 | } | |
122 |
|
124 | |||
123 | void ChartColorBarAxisY::createColorBar() |
|
125 | void ChartColorBarAxisY::createColorBar() | |
124 | { |
|
126 | { | |
125 | QGradientStops stops = m_gradient.stops(); |
|
127 | //m_position.setX(80+m_position.x());// TODO : remove this when you know how to move labels | |
126 |
|
128 | |||
127 | QLinearGradient gradient(0,0,1,250); |
|
129 | //gradient | |
|
130 | QGradientStops stops = m_gradient.stops(); | |||
|
131 | QLinearGradient gradient(0,0,1,m_height); | |||
128 | foreach(QGradientStop stop, stops) |
|
132 | foreach(QGradientStop stop, stops) | |
129 | { |
|
133 | { | |
130 | gradient.setColorAt(1-stop.first,stop.second); |
|
134 | gradient.setColorAt(1-stop.first,stop.second); | |
131 | } |
|
135 | } | |
132 |
|
136 | |||
133 | QPixmap image = QPixmap(50,250); |
|
137 | //colorbar | |
134 | QPainter painter(&image); |
|
138 | QRectF rect(m_position.x(),m_position.y(),m_height/20,m_height); | |
135 | QRectF rect(0,0,50,250); |
|
|||
136 | painter.fillRect(rect,gradient); |
|
|||
137 |
|
139 | |||
138 | QGraphicsRectItem *colorbar = new QGraphicsRectItem(rect, this); |
|
140 | QGraphicsRectItem *colorbar = new QGraphicsRectItem(rect, this); | |
|
141 | colorbar->setZValue(ChartPresenter::AxisZValue); | |||
|
142 | colorbar->setBrush(gradient); | |||
139 | setGraphicsItem(colorbar); |
|
143 | setGraphicsItem(colorbar); | |
140 | } |
|
144 | } | |
141 |
|
145 | |||
142 | #include "moc_chartcolorbaraxisy_p.cpp" |
|
146 | #include "moc_chartcolorbaraxisy_p.cpp" | |
143 |
|
147 | |||
144 | QT_CHARTS_END_NAMESPACE |
|
148 | QT_CHARTS_END_NAMESPACE |
@@ -1,39 +1,41 | |||||
1 | #ifndef CHARTCOLORBARAXISY_H |
|
1 | #ifndef CHARTCOLORBARAXISY_H | |
2 | #define CHARTCOLORBARAXISY_H |
|
2 | #define CHARTCOLORBARAXISY_H | |
3 |
|
3 | |||
4 | #include <private/verticalaxis_p.h> |
|
4 | #include <private/verticalaxis_p.h> | |
5 | #include <QtGui> |
|
5 | #include <QtGui> | |
6 |
|
6 | |||
7 | QT_CHARTS_BEGIN_NAMESPACE |
|
7 | QT_CHARTS_BEGIN_NAMESPACE | |
8 |
|
8 | |||
9 | class QColorBarAxis; |
|
9 | class QColorBarAxis; | |
10 |
|
10 | |||
11 | class ChartColorBarAxisY : public VerticalAxis |
|
11 | class ChartColorBarAxisY : public VerticalAxis | |
12 | { |
|
12 | { | |
13 | Q_OBJECT |
|
13 | Q_OBJECT | |
14 | public: |
|
14 | public: | |
15 | ChartColorBarAxisY(QColorBarAxis *axis, QLinearGradient gradient, QGraphicsItem *item = 0); |
|
15 | ChartColorBarAxisY(QColorBarAxis *axis, QPoint pos, qreal height, QLinearGradient gradient, QGraphicsItem *item = 0); | |
16 | ~ChartColorBarAxisY(); |
|
16 | ~ChartColorBarAxisY(); | |
17 |
|
17 | |||
18 | QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint) const; |
|
18 | QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint) const; | |
19 |
|
19 | |||
20 |
|
20 | |||
21 |
|
21 | |||
22 | protected: |
|
22 | protected: | |
23 | QVector<qreal> calculateLayout() const; |
|
23 | QVector<qreal> calculateLayout() const; | |
24 | void updateGeometry(); |
|
24 | void updateGeometry(); | |
25 | private Q_SLOTS: |
|
25 | private Q_SLOTS: | |
26 | void handleTickCountChanged(int tick); |
|
26 | void handleTickCountChanged(int tick); | |
27 | void handleMinorTickCountChanged(int tick); |
|
27 | void handleMinorTickCountChanged(int tick); | |
28 | void handleLabelFormatChanged(const QString &format); |
|
28 | void handleLabelFormatChanged(const QString &format); | |
29 | void createColorBar(); |
|
29 | void createColorBar(); | |
30 |
|
30 | |||
31 |
|
31 | |||
32 | private: |
|
32 | private: | |
33 | QColorBarAxis *m_axis; |
|
33 | QColorBarAxis *m_axis; | |
34 | QLinearGradient m_gradient; |
|
34 | QLinearGradient m_gradient; | |
|
35 | QPoint m_position; | |||
|
36 | qreal m_height; | |||
35 | }; |
|
37 | }; | |
36 |
|
38 | |||
37 | QT_CHARTS_END_NAMESPACE |
|
39 | QT_CHARTS_END_NAMESPACE | |
38 |
|
40 | |||
39 | #endif // CHARTCOLORBARAXISY_H |
|
41 | #endif // CHARTCOLORBARAXISY_H |
@@ -1,247 +1,255 | |||||
1 | //#include <QtCharts/QColorBarAxis> // TODO : fix this |
|
1 | //#include <QtCharts/QColorBarAxis> // TODO : fix this | |
2 | #include "colorbaraxis/qcolorbaraxis.h" |
|
2 | #include "colorbaraxis/qcolorbaraxis.h" | |
3 | //#include <private/qcolorbaraxis_p.h> |
|
3 | //#include <private/qcolorbaraxis_p.h> | |
4 | #include "colorbaraxis/qcolorbaraxis_p.h" |
|
4 | #include "colorbaraxis/qcolorbaraxis_p.h" | |
5 | #include <private/abstractdomain_p.h> |
|
5 | #include <private/abstractdomain_p.h> | |
6 | #include <private/chartdataset_p.h> |
|
6 | #include <private/chartdataset_p.h> | |
7 | #include <private/chartpresenter_p.h> |
|
7 | #include <private/chartpresenter_p.h> | |
8 | #include <private/charttheme_p.h> |
|
8 | #include <private/charttheme_p.h> | |
9 |
|
9 | |||
10 | //#include <private/chartcolorbaraxisy_p.h> |
|
10 | //#include <private/chartcolorbaraxisy_p.h> | |
11 | #include <chartcolorbaraxisy_p.h> |
|
11 | #include <chartcolorbaraxisy_p.h> | |
12 |
|
12 | |||
13 | #include <QtGui> |
|
13 | #include <QtGui> | |
14 |
|
14 | |||
15 | QT_CHARTS_BEGIN_NAMESPACE |
|
15 | QT_CHARTS_BEGIN_NAMESPACE | |
16 |
|
16 | |||
17 |
|
17 | |||
18 | /*! |
|
18 | /*! | |
19 | Constructs an axis object which is a child of \a parent. |
|
19 | Constructs an axis object which is a child of \a parent. | |
20 | */ |
|
20 | */ | |
21 | QColorBarAxis::QColorBarAxis(QLinearGradient gradient, qreal min, qreal max,QObject *parent) : |
|
21 | QColorBarAxis::QColorBarAxis(QRectF plotArea, QLinearGradient gradient, qreal min, qreal max, QObject *parent) : | |
22 | QAbstractAxis(*new QColorBarAxisPrivate(gradient, min, max, this), parent) |
|
22 | QAbstractAxis(*new QColorBarAxisPrivate(plotArea, gradient, min, max, this), parent) | |
23 | { |
|
23 | { | |
24 |
|
24 | setGridLineVisible(false); | ||
25 | } |
|
25 | } | |
26 |
|
26 | |||
27 | /*! |
|
27 | /*! | |
28 | \internal |
|
28 | \internal | |
29 | */ |
|
29 | */ | |
30 | QColorBarAxis::QColorBarAxis(QColorBarAxisPrivate &d, QObject *parent) |
|
30 | QColorBarAxis::QColorBarAxis(QColorBarAxisPrivate &d, QObject *parent) | |
31 | : QAbstractAxis(d, parent) |
|
31 | : QAbstractAxis(d, parent) | |
32 | { |
|
32 | { | |
33 |
|
33 | |||
34 | } |
|
34 | } | |
35 |
|
35 | |||
36 | /*! |
|
36 | /*! | |
37 | Destroys the object |
|
37 | Destroys the object | |
38 | */ |
|
38 | */ | |
39 | QColorBarAxis::~QColorBarAxis() |
|
39 | QColorBarAxis::~QColorBarAxis() | |
40 | { |
|
40 | { | |
41 | Q_D(QColorBarAxis); |
|
41 | Q_D(QColorBarAxis); | |
42 | if (d->m_chart) |
|
42 | if (d->m_chart) | |
43 | d->m_chart->removeAxis(this); |
|
43 | d->m_chart->removeAxis(this); | |
44 | } |
|
44 | } | |
45 |
|
45 | |||
46 | void QColorBarAxis::setMin(qreal min) |
|
46 | void QColorBarAxis::setMin(qreal min) | |
47 | { |
|
47 | { | |
48 | Q_D(QColorBarAxis); |
|
48 | Q_D(QColorBarAxis); | |
49 | setRange(min, qMax(d->m_max, min)); |
|
49 | setRange(min, qMax(d->m_max, min)); | |
50 | } |
|
50 | } | |
51 |
|
51 | |||
52 | qreal QColorBarAxis::min() const |
|
52 | qreal QColorBarAxis::min() const | |
53 | { |
|
53 | { | |
54 | Q_D(const QColorBarAxis); |
|
54 | Q_D(const QColorBarAxis); | |
55 | return d->m_min; |
|
55 | return d->m_min; | |
56 | } |
|
56 | } | |
57 |
|
57 | |||
58 | void QColorBarAxis::setMax(qreal max) |
|
58 | void QColorBarAxis::setMax(qreal max) | |
59 | { |
|
59 | { | |
60 | Q_D(QColorBarAxis); |
|
60 | Q_D(QColorBarAxis); | |
61 | setRange(qMin(d->m_min, max), max); |
|
61 | setRange(qMin(d->m_min, max), max); | |
62 | } |
|
62 | } | |
63 |
|
63 | |||
64 | qreal QColorBarAxis::max() const |
|
64 | qreal QColorBarAxis::max() const | |
65 | { |
|
65 | { | |
66 | Q_D(const QColorBarAxis); |
|
66 | Q_D(const QColorBarAxis); | |
67 | return d->m_max; |
|
67 | return d->m_max; | |
68 | } |
|
68 | } | |
69 |
|
69 | |||
70 | void QColorBarAxis::setRange(qreal min, qreal max) |
|
70 | void QColorBarAxis::setRange(qreal min, qreal max) | |
71 | { |
|
71 | { | |
72 | Q_D(QColorBarAxis); |
|
72 | Q_D(QColorBarAxis); | |
73 | d->setRange(min,max); |
|
73 | d->setRange(min,max); | |
74 | } |
|
74 | } | |
75 |
|
75 | |||
76 |
|
76 | |||
77 | void QColorBarAxis::setTickCount(int count) |
|
77 | void QColorBarAxis::setTickCount(int count) | |
78 | { |
|
78 | { | |
79 | Q_D(QColorBarAxis); |
|
79 | Q_D(QColorBarAxis); | |
80 | if (d->m_tickCount != count && count >= 2) { |
|
80 | if (d->m_tickCount != count && count >= 2) { | |
81 | d->m_tickCount = count; |
|
81 | d->m_tickCount = count; | |
82 | emit tickCountChanged(count); |
|
82 | emit tickCountChanged(count); | |
83 | } |
|
83 | } | |
84 | } |
|
84 | } | |
85 |
|
85 | |||
86 | int QColorBarAxis::tickCount() const |
|
86 | int QColorBarAxis::tickCount() const | |
87 | { |
|
87 | { | |
88 | Q_D(const QColorBarAxis); |
|
88 | Q_D(const QColorBarAxis); | |
89 | return d->m_tickCount; |
|
89 | return d->m_tickCount; | |
90 | } |
|
90 | } | |
91 |
|
91 | |||
92 | void QColorBarAxis::setMinorTickCount(int count) |
|
92 | void QColorBarAxis::setMinorTickCount(int count) | |
93 | { |
|
93 | { | |
94 | Q_D(QColorBarAxis); |
|
94 | Q_D(QColorBarAxis); | |
95 | if (d->m_minorTickCount != count && count >= 0) { |
|
95 | if (d->m_minorTickCount != count && count >= 0) { | |
96 | d->m_minorTickCount = count; |
|
96 | d->m_minorTickCount = count; | |
97 | emit minorTickCountChanged(count); |
|
97 | emit minorTickCountChanged(count); | |
98 | } |
|
98 | } | |
99 | } |
|
99 | } | |
100 |
|
100 | |||
101 | int QColorBarAxis::minorTickCount() const |
|
101 | int QColorBarAxis::minorTickCount() const | |
102 | { |
|
102 | { | |
103 | Q_D(const QColorBarAxis); |
|
103 | Q_D(const QColorBarAxis); | |
104 | return d->m_minorTickCount; |
|
104 | return d->m_minorTickCount; | |
105 | } |
|
105 | } | |
106 |
|
106 | |||
107 | void QColorBarAxis::setLabelFormat(const QString &format) |
|
107 | void QColorBarAxis::setLabelFormat(const QString &format) | |
108 | { |
|
108 | { | |
109 | Q_D(QColorBarAxis); |
|
109 | Q_D(QColorBarAxis); | |
110 | d->m_format = format; |
|
110 | d->m_format = format; | |
111 | emit labelFormatChanged(format); |
|
111 | emit labelFormatChanged(format); | |
112 | } |
|
112 | } | |
113 |
|
113 | |||
114 | QString QColorBarAxis::labelFormat() const |
|
114 | QString QColorBarAxis::labelFormat() const | |
115 | { |
|
115 | { | |
116 | Q_D(const QColorBarAxis); |
|
116 | Q_D(const QColorBarAxis); | |
117 | return d->m_format; |
|
117 | return d->m_format; | |
118 | } |
|
118 | } | |
119 |
|
119 | |||
120 | /*! |
|
120 | /*! | |
121 | Returns the type of the axis |
|
121 | Returns the type of the axis | |
122 | */ |
|
122 | */ | |
123 | QAbstractAxis::AxisType QColorBarAxis::type() const |
|
123 | QAbstractAxis::AxisType QColorBarAxis::type() const | |
124 | { |
|
124 | { | |
125 | return AxisTypeValue; |
|
125 | return AxisTypeValue; | |
126 | //TODO : AxisTypeColorBar |
|
126 | //TODO : AxisTypeColorBar | |
127 | } |
|
127 | } | |
128 |
|
128 | |||
129 |
|
129 | |||
130 |
|
130 | |||
131 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
131 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
132 |
|
132 | |||
133 | QColorBarAxisPrivate::QColorBarAxisPrivate(QLinearGradient gradient, qreal min, qreal max, QColorBarAxis *q) |
|
133 | QColorBarAxisPrivate::QColorBarAxisPrivate(QRectF plotArea, QLinearGradient gradient, qreal min, qreal max, QColorBarAxis *q) | |
134 | : QAbstractAxisPrivate(q), |
|
134 | : QAbstractAxisPrivate(q), | |
|
135 | m_plotArea(plotArea), | |||
135 | m_min(min), |
|
136 | m_min(min), | |
136 | m_max(max), |
|
137 | m_max(max), | |
137 |
|
|
138 | m_tickCount(5), | |
138 |
|
|
139 | m_minorTickCount(0), | |
139 | m_format(QString::null), |
|
140 | m_format(QString::null), | |
140 | // m_applying(false) |
|
141 | // m_applying(false) | |
141 | m_gradient(gradient) |
|
142 | m_gradient(gradient) | |
142 | { |
|
143 | { | |
143 |
|
144 | |||
144 | } |
|
145 | } | |
145 |
|
146 | |||
146 | QColorBarAxisPrivate::~QColorBarAxisPrivate() |
|
147 | QColorBarAxisPrivate::~QColorBarAxisPrivate() | |
147 | { |
|
148 | { | |
148 |
|
149 | |||
149 | } |
|
150 | } | |
150 |
|
151 | |||
151 | void QColorBarAxisPrivate::initializeGraphics(QGraphicsItem *parent) |
|
152 | void QColorBarAxisPrivate::initializeGraphics(QGraphicsItem *parent) | |
152 | { |
|
153 | { | |
153 | Q_Q(QColorBarAxis); |
|
154 | Q_Q(QColorBarAxis); | |
154 | ChartAxisElement *axis(0); |
|
155 | ChartAxisElement *axis(0); | |
155 |
|
156 | |||
156 | setAlignment(Qt::AlignRight); //also set orientation (Vertical in this case) |
|
157 | setAlignment(Qt::AlignRight); //also set orientation (Vertical in this case) | |
157 |
|
158 | |||
158 | axis = new ChartColorBarAxisY(q, m_gradient, parent); |
|
159 | //TODO : change this position | |
|
160 | qreal x1; | |||
|
161 | qreal y1; | |||
|
162 | qreal x2; | |||
|
163 | qreal y2; | |||
|
164 | m_plotArea.getCoords(&x1,&y1,&x2,&y2); | |||
|
165 | QPoint pos(x2+5,y1); | |||
|
166 | axis = new ChartColorBarAxisY(q, pos, m_plotArea.height(),m_gradient, parent); | |||
159 |
|
167 | |||
160 | m_item.reset(axis); |
|
168 | m_item.reset(axis); | |
161 | QAbstractAxisPrivate::initializeGraphics(parent); |
|
169 | QAbstractAxisPrivate::initializeGraphics(parent); | |
162 | } |
|
170 | } | |
163 |
|
171 | |||
164 | void QColorBarAxisPrivate::initializeDomain(AbstractDomain *domain) |
|
172 | void QColorBarAxisPrivate::initializeDomain(AbstractDomain *domain) | |
165 | { |
|
173 | { | |
166 | //domain is not supposed to have a rangeZ |
|
174 | //domain is not supposed to have a rangeZ | |
167 |
|
175 | |||
168 | // if (orientation() == Qt::Vertical) { |
|
176 | // if (orientation() == Qt::Vertical) { | |
169 | // if (!qFuzzyIsNull(m_max - m_min)) |
|
177 | // if (!qFuzzyIsNull(m_max - m_min)) | |
170 | // domain->setRangeY(m_min, m_max); |
|
178 | // domain->setRangeY(m_min, m_max); | |
171 | // else |
|
179 | // else | |
172 | // setRange(domain->minY(), domain->maxY()); |
|
180 | // setRange(domain->minY(), domain->maxY()); | |
173 | // } |
|
181 | // } | |
174 | } |
|
182 | } | |
175 |
|
183 | |||
176 | void QColorBarAxisPrivate::setMin(const QVariant &min) |
|
184 | void QColorBarAxisPrivate::setMin(const QVariant &min) | |
177 | { |
|
185 | { | |
178 | Q_Q(QColorBarAxis); |
|
186 | Q_Q(QColorBarAxis); | |
179 | bool ok; |
|
187 | bool ok; | |
180 | qreal value = min.toReal(&ok); |
|
188 | qreal value = min.toReal(&ok); | |
181 | if (ok) |
|
189 | if (ok) | |
182 | q->setMin(value); |
|
190 | q->setMin(value); | |
183 | } |
|
191 | } | |
184 |
|
192 | |||
185 | void QColorBarAxisPrivate::setMax(const QVariant &max) |
|
193 | void QColorBarAxisPrivate::setMax(const QVariant &max) | |
186 | { |
|
194 | { | |
187 | Q_Q(QColorBarAxis); |
|
195 | Q_Q(QColorBarAxis); | |
188 | bool ok; |
|
196 | bool ok; | |
189 | qreal value = max.toReal(&ok); |
|
197 | qreal value = max.toReal(&ok); | |
190 | if (ok) |
|
198 | if (ok) | |
191 | q->setMax(value); |
|
199 | q->setMax(value); | |
192 | } |
|
200 | } | |
193 |
|
201 | |||
194 | void QColorBarAxisPrivate::setRange(const QVariant &min, const QVariant &max) |
|
202 | void QColorBarAxisPrivate::setRange(const QVariant &min, const QVariant &max) | |
195 | { |
|
203 | { | |
196 | Q_Q(QColorBarAxis); |
|
204 | Q_Q(QColorBarAxis); | |
197 | bool ok1; |
|
205 | bool ok1; | |
198 | bool ok2; |
|
206 | bool ok2; | |
199 | qreal value1 = min.toReal(&ok1); |
|
207 | qreal value1 = min.toReal(&ok1); | |
200 | qreal value2 = max.toReal(&ok2); |
|
208 | qreal value2 = max.toReal(&ok2); | |
201 | if (ok1 && ok2) |
|
209 | if (ok1 && ok2) | |
202 | q->setRange(value1, value2); |
|
210 | q->setRange(value1, value2); | |
203 | } |
|
211 | } | |
204 |
|
212 | |||
205 | void QColorBarAxisPrivate::setRange(qreal min,qreal max) |
|
213 | void QColorBarAxisPrivate::setRange(qreal min,qreal max) | |
206 | { |
|
214 | { | |
207 | Q_Q(QColorBarAxis); |
|
215 | Q_Q(QColorBarAxis); | |
208 | bool changed = false; |
|
216 | bool changed = false; | |
209 |
|
217 | |||
210 | if (min > max) |
|
218 | if (min > max) | |
211 | return; |
|
219 | return; | |
212 |
|
220 | |||
213 | bool changeMin = false; |
|
221 | bool changeMin = false; | |
214 | if (m_min == 0 || min == 0) |
|
222 | if (m_min == 0 || min == 0) | |
215 | changeMin = !qFuzzyCompare(1 + m_min, 1 + min); |
|
223 | changeMin = !qFuzzyCompare(1 + m_min, 1 + min); | |
216 | else |
|
224 | else | |
217 | changeMin = !qFuzzyCompare(m_min, min); |
|
225 | changeMin = !qFuzzyCompare(m_min, min); | |
218 |
|
226 | |||
219 | bool changeMax = false; |
|
227 | bool changeMax = false; | |
220 | if (m_max == 0 || max == 0) |
|
228 | if (m_max == 0 || max == 0) | |
221 | changeMax = !qFuzzyCompare(1 + m_max, 1 + max); |
|
229 | changeMax = !qFuzzyCompare(1 + m_max, 1 + max); | |
222 | else |
|
230 | else | |
223 | changeMax = !qFuzzyCompare(m_max, max); |
|
231 | changeMax = !qFuzzyCompare(m_max, max); | |
224 |
|
232 | |||
225 | if (changeMin) { |
|
233 | if (changeMin) { | |
226 | m_min = min; |
|
234 | m_min = min; | |
227 | changed = true; |
|
235 | changed = true; | |
228 | emit q->minChanged(min); |
|
236 | emit q->minChanged(min); | |
229 | } |
|
237 | } | |
230 |
|
238 | |||
231 | if (changeMax) { |
|
239 | if (changeMax) { | |
232 | m_max = max; |
|
240 | m_max = max; | |
233 | changed = true; |
|
241 | changed = true; | |
234 | emit q->maxChanged(max); |
|
242 | emit q->maxChanged(max); | |
235 | } |
|
243 | } | |
236 |
|
244 | |||
237 | if (changed) { |
|
245 | if (changed) { | |
238 | emit rangeChanged(min,max); |
|
246 | emit rangeChanged(min,max); | |
239 | emit q->rangeChanged(min, max); |
|
247 | emit q->rangeChanged(min, max); | |
240 | } |
|
248 | } | |
241 | } |
|
249 | } | |
242 |
|
250 | |||
243 |
|
251 | |||
244 | #include "moc_qcolorbaraxis.cpp" |
|
252 | #include "moc_qcolorbaraxis.cpp" | |
245 | #include "moc_qcolorbaraxis_p.cpp" |
|
253 | #include "moc_qcolorbaraxis_p.cpp" | |
246 |
|
254 | |||
247 | QT_CHARTS_END_NAMESPACE |
|
255 | QT_CHARTS_END_NAMESPACE |
@@ -1,54 +1,54 | |||||
1 | #ifndef QCOLORBARAXIS_H |
|
1 | #ifndef QCOLORBARAXIS_H | |
2 | #define QCOLORBARAXIS_H |
|
2 | #define QCOLORBARAXIS_H | |
3 |
|
3 | |||
4 | #include <QtCharts/QAbstractAxis> |
|
4 | #include <QtCharts/QAbstractAxis> | |
5 |
|
5 | |||
6 | QT_CHARTS_BEGIN_NAMESPACE |
|
6 | QT_CHARTS_BEGIN_NAMESPACE | |
7 |
|
7 | |||
8 | class QColorBarAxisPrivate; |
|
8 | class QColorBarAxisPrivate; | |
9 |
|
9 | |||
10 | class QT_CHARTS_EXPORT QColorBarAxis : public QAbstractAxis |
|
10 | class QT_CHARTS_EXPORT QColorBarAxis : public QAbstractAxis | |
11 | { |
|
11 | { | |
12 | Q_OBJECT |
|
12 | Q_OBJECT | |
13 | public: |
|
13 | public: | |
14 | explicit QColorBarAxis(QLinearGradient gradient, qreal min, qreal max,QObject *parent = 0); |
|
14 | explicit QColorBarAxis(QRectF plotArea,QLinearGradient gradient, qreal min, qreal max,QObject *parent = 0); | |
15 | ~QColorBarAxis(); |
|
15 | ~QColorBarAxis(); | |
16 |
|
16 | |||
17 | protected: |
|
17 | protected: | |
18 | QColorBarAxis(QColorBarAxisPrivate &d, QObject *parent = 0); |
|
18 | QColorBarAxis(QColorBarAxisPrivate &d, QObject *parent = 0); | |
19 |
|
19 | |||
20 | public: |
|
20 | public: | |
21 | AxisType type() const; |
|
21 | AxisType type() const; | |
22 |
|
22 | |||
23 | //range handling |
|
23 | //range handling | |
24 | void setMin(qreal min); |
|
24 | void setMin(qreal min); | |
25 | qreal min() const; |
|
25 | qreal min() const; | |
26 | void setMax(qreal max); |
|
26 | void setMax(qreal max); | |
27 | qreal max() const; |
|
27 | qreal max() const; | |
28 | void setRange(qreal min, qreal max); |
|
28 | void setRange(qreal min, qreal max); | |
29 |
|
29 | |||
30 | //ticks handling |
|
30 | //ticks handling | |
31 | void setTickCount(int count); |
|
31 | void setTickCount(int count); | |
32 | int tickCount() const; |
|
32 | int tickCount() const; | |
33 | void setMinorTickCount(int count); |
|
33 | void setMinorTickCount(int count); | |
34 | int minorTickCount() const; |
|
34 | int minorTickCount() const; | |
35 |
|
35 | |||
36 | void setLabelFormat(const QString &format); |
|
36 | void setLabelFormat(const QString &format); | |
37 | QString labelFormat() const; |
|
37 | QString labelFormat() const; | |
38 |
|
38 | |||
39 | Q_SIGNALS: |
|
39 | Q_SIGNALS: | |
40 | void minChanged(qreal min); |
|
40 | void minChanged(qreal min); | |
41 | void maxChanged(qreal max); |
|
41 | void maxChanged(qreal max); | |
42 | void rangeChanged(qreal min, qreal max); |
|
42 | void rangeChanged(qreal min, qreal max); | |
43 | void tickCountChanged(int tickCount); |
|
43 | void tickCountChanged(int tickCount); | |
44 | void minorTickCountChanged(int tickCount); |
|
44 | void minorTickCountChanged(int tickCount); | |
45 | void labelFormatChanged(const QString &format); |
|
45 | void labelFormatChanged(const QString &format); | |
46 |
|
46 | |||
47 | private: |
|
47 | private: | |
48 | Q_DECLARE_PRIVATE(QColorBarAxis) |
|
48 | Q_DECLARE_PRIVATE(QColorBarAxis) | |
49 | Q_DISABLE_COPY(QColorBarAxis) |
|
49 | Q_DISABLE_COPY(QColorBarAxis) | |
50 | }; |
|
50 | }; | |
51 |
|
51 | |||
52 | QT_CHARTS_END_NAMESPACE |
|
52 | QT_CHARTS_END_NAMESPACE | |
53 |
|
53 | |||
54 | #endif // QCOLORBARAXIS_H |
|
54 | #endif // QCOLORBARAXIS_H |
@@ -1,43 +1,44 | |||||
1 | #ifndef QCOLORBARAXIS_P_H |
|
1 | #ifndef QCOLORBARAXIS_P_H | |
2 | #define QCOLORBARAXIS_P_H |
|
2 | #define QCOLORBARAXIS_P_H | |
3 |
|
3 | |||
4 | //#include <QtCharts/QColorBarAxis> //TODO : fix this |
|
4 | //#include <QtCharts/QColorBarAxis> //TODO : fix this | |
5 | #include "colorbaraxis/qcolorbaraxis.h" |
|
5 | #include "colorbaraxis/qcolorbaraxis.h" | |
6 | #include <private/qabstractaxis_p.h> |
|
6 | #include <private/qabstractaxis_p.h> | |
7 |
|
7 | |||
8 | QT_CHARTS_BEGIN_NAMESPACE |
|
8 | QT_CHARTS_BEGIN_NAMESPACE | |
9 |
|
9 | |||
10 | class QColorBarAxisPrivate : public QAbstractAxisPrivate |
|
10 | class QColorBarAxisPrivate : public QAbstractAxisPrivate | |
11 | { |
|
11 | { | |
12 | Q_OBJECT |
|
12 | Q_OBJECT | |
13 | public: |
|
13 | public: | |
14 | QColorBarAxisPrivate(QLinearGradient gradient, qreal min, qreal max,QColorBarAxis *q); |
|
14 | QColorBarAxisPrivate(QRectF plotArea, QLinearGradient gradient, qreal min, qreal max,QColorBarAxis *q); | |
15 | ~QColorBarAxisPrivate(); |
|
15 | ~QColorBarAxisPrivate(); | |
16 |
|
16 | |||
17 | public: |
|
17 | public: | |
18 | void initializeGraphics(QGraphicsItem* parent); |
|
18 | void initializeGraphics(QGraphicsItem* parent); | |
19 | void initializeDomain(AbstractDomain *domain); |
|
19 | void initializeDomain(AbstractDomain *domain); | |
20 |
|
20 | |||
21 | qreal min() { return m_min; } |
|
21 | qreal min() { return m_min; } | |
22 | qreal max() { return m_max; } |
|
22 | qreal max() { return m_max; } | |
23 | void setRange(qreal min,qreal max); |
|
23 | void setRange(qreal min,qreal max); | |
24 |
|
24 | |||
25 | protected: |
|
25 | protected: | |
26 | void setMin(const QVariant &min); |
|
26 | void setMin(const QVariant &min); | |
27 | void setMax(const QVariant &max); |
|
27 | void setMax(const QVariant &max); | |
28 | void setRange(const QVariant &min, const QVariant &max); |
|
28 | void setRange(const QVariant &min, const QVariant &max); | |
29 |
|
29 | |||
30 | private: |
|
30 | private: | |
31 | qreal m_min; |
|
31 | qreal m_min; | |
32 | qreal m_max; |
|
32 | qreal m_max; | |
33 | int m_tickCount; |
|
33 | int m_tickCount; | |
34 | int m_minorTickCount; |
|
34 | int m_minorTickCount; | |
35 | QString m_format; |
|
35 | QString m_format; | |
36 | // bool m_applying; |
|
36 | // bool m_applying; | |
37 | QLinearGradient m_gradient; |
|
37 | QLinearGradient m_gradient; | |
|
38 | QRectF m_plotArea; | |||
38 | Q_DECLARE_PUBLIC(QColorBarAxis) |
|
39 | Q_DECLARE_PUBLIC(QColorBarAxis) | |
39 | }; |
|
40 | }; | |
40 |
|
41 | |||
41 | QT_CHARTS_END_NAMESPACE |
|
42 | QT_CHARTS_END_NAMESPACE | |
42 |
|
43 | |||
43 | #endif // QCOLORBARAXIS_P_H |
|
44 | #endif // QCOLORBARAXIS_P_H |
@@ -1,226 +1,244 | |||||
1 | #include <private/colormapchart_p.h> |
|
1 | #include <private/colormapchart_p.h> | |
2 | #include <QtCharts/QColorMapSeries> |
|
2 | #include <QtCharts/QColorMapSeries> | |
3 | #include <private/qcolormapseries_p.h> |
|
3 | #include <private/qcolormapseries_p.h> | |
4 | #include <private/chartpresenter_p.h> |
|
4 | #include <private/chartpresenter_p.h> | |
5 | #include <private/abstractdomain_p.h> |
|
5 | #include <private/abstractdomain_p.h> | |
6 | #include <private/chartdataset_p.h> |
|
6 | #include <private/chartdataset_p.h> | |
7 | #include <private/qabstractaxis_p.h> |
|
7 | #include <private/qabstractaxis_p.h> | |
8 | #include <QtGui/QPainter> |
|
8 | #include <QtGui/QPainter> | |
9 |
|
9 | |||
10 | //#include <QtCharts/QColorBarAxis> TODO : fix this |
|
|||
11 | #include "qcolorbaraxis.h" |
|
|||
12 |
|
||||
13 | #include <QRgb> |
|
10 | #include <QRgb> | |
14 |
|
11 | |||
15 | #define nbOfColors 65000 |
|
12 | #define nbOfColors 65000 | |
16 |
|
13 | |||
17 | QT_CHARTS_BEGIN_NAMESPACE |
|
14 | QT_CHARTS_BEGIN_NAMESPACE | |
18 |
|
15 | |||
19 | ColorMapChart::ColorMapChart(QColorMapSeries *series, QGraphicsItem *item) |
|
16 | ColorMapChart::ColorMapChart(QColorMapSeries *series, QGraphicsItem *item) | |
20 | : ChartItem(series->d_func(), item), |
|
17 | : ChartItem(series->d_func(), item), | |
21 | m_series(series), |
|
18 | m_series(series), | |
22 | m_dirty(true), |
|
19 | m_dirty(true), | |
23 | m_gradientType(Rainbow), |
|
20 | m_gradientType(Rainbow), | |
24 | m_colorbar(false) |
|
21 | m_colorbar(false) | |
25 | { |
|
22 | { | |
26 | // QObject::connect(series, SIGNAL(pointReplaced(int)), this, SLOT(handlePointReplaced(int))); |
|
23 | // QObject::connect(series, SIGNAL(pointReplaced(int)), this, SLOT(handlePointReplaced(int))); | |
27 | // QObject::connect(series, SIGNAL(pointsReplaced()), this, SLOT(handlePointsReplaced())); |
|
24 | // QObject::connect(series, SIGNAL(pointsReplaced()), this, SLOT(handlePointsReplaced())); | |
28 | // QObject::connect(series, SIGNAL(pointAdded(int)), this, SLOT(handlePointAdded(int))); |
|
25 | // QObject::connect(series, SIGNAL(pointAdded(int)), this, SLOT(handlePointAdded(int))); | |
29 | // QObject::connect(series, SIGNAL(pointRemoved(int)), this, SLOT(handlePointRemoved(int))); |
|
26 | // QObject::connect(series, SIGNAL(pointRemoved(int)), this, SLOT(handlePointRemoved(int))); | |
30 | // QObject::connect(series, SIGNAL(pointsRemoved(int, int)), this, SLOT(handlePointsRemoved(int, int))); |
|
27 | // QObject::connect(series, SIGNAL(pointsRemoved(int, int)), this, SLOT(handlePointsRemoved(int, int))); | |
31 | // QObject::connect(this, SIGNAL(clicked(Point3D)), series, SIGNAL(clicked(Point3D))); |
|
28 | // QObject::connect(this, SIGNAL(clicked(Point3D)), series, SIGNAL(clicked(Point3D))); | |
32 | // QObject::connect(this, SIGNAL(hovered(Point3D,bool)), series, SIGNAL(hovered(Point3D,bool))); |
|
29 | // QObject::connect(this, SIGNAL(hovered(Point3D,bool)), series, SIGNAL(hovered(Point3D,bool))); | |
33 | // QObject::connect(this, SIGNAL(pressed(Point3D)), series, SIGNAL(pressed(Point3D))); |
|
30 | // QObject::connect(this, SIGNAL(pressed(Point3D)), series, SIGNAL(pressed(Point3D))); | |
34 | // QObject::connect(this, SIGNAL(released(Point3D)), series, SIGNAL(released(Point3D))); |
|
31 | // QObject::connect(this, SIGNAL(released(Point3D)), series, SIGNAL(released(Point3D))); | |
35 | // QObject::connect(this, SIGNAL(doubleClicked(Point3D)), series, SIGNAL(doubleClicked(Point3D))); |
|
32 | // QObject::connect(this, SIGNAL(doubleClicked(Point3D)), series, SIGNAL(doubleClicked(Point3D))); | |
36 |
|
33 | |||
37 | connect(this,SIGNAL(gradientTypeChanged()), this, SLOT(populateColorTable())); |
|
34 | connect(this,SIGNAL(gradientTypeChanged()), this, SLOT(populateColorTable())); | |
38 |
|
35 | |||
39 | m_colorTable = new QVector<QRgb>(); |
|
36 | m_colorTable = new QVector<QRgb>(); | |
40 | m_colorTable->reserve(nbOfColors); |
|
37 | m_colorTable->reserve(nbOfColors); | |
41 | populateColorTable(); |
|
38 | populateColorTable(); | |
42 | } |
|
39 | } | |
43 |
|
40 | |||
44 | void ColorMapChart::setDirty(bool dirty) |
|
41 | void ColorMapChart::setDirty(bool dirty) | |
45 | { |
|
42 | { | |
46 | m_dirty = dirty; |
|
43 | m_dirty = dirty; | |
47 | } |
|
44 | } | |
48 |
|
45 | |||
49 | QRectF ColorMapChart::boundingRect() const |
|
46 | QRectF ColorMapChart::boundingRect() const | |
50 | { |
|
47 | { | |
51 | return m_rect; |
|
48 | return m_rect; | |
52 | } |
|
49 | } | |
53 |
|
50 | |||
54 | void ColorMapChart::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
|
51 | void ColorMapChart::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) | |
55 | { |
|
52 | { | |
56 | Q_UNUSED(widget) |
|
53 | Q_UNUSED(widget) | |
57 | Q_UNUSED(option) |
|
54 | Q_UNUSED(option) | |
58 |
|
55 | |||
|
56 | m_series->setUseOpenGL(); | |||
|
57 | ||||
|
58 | painter->save(); | |||
|
59 | ||||
59 | QRectF clipRect = QRectF(QPointF(0, 0), domain()->size()); |
|
60 | QRectF clipRect = QRectF(QPointF(0, 0), domain()->size()); | |
60 | painter->setClipRect(clipRect); |
|
61 | painter->setClipRect(clipRect); | |
61 |
|
62 | |||
62 | QRectF plotAreaRect = m_series->chart()->plotArea(); |
|
63 | QRectF plotAreaRect = m_series->chart()->plotArea(); | |
63 | QImage colorMapImage(plotAreaRect.width(),plotAreaRect.height(),QImage::Format_RGB32); |
|
64 | QImage colorMapImage(plotAreaRect.width(),plotAreaRect.height(),QImage::Format_RGB32); | |
64 | //http://doc.qt.io/qt-4.8/qimage.html#details :Warning: This will create a QImage with uninitialized data. Call fill() to fill the image with an appropriate pixel value before drawing onto it with QPainter. |
|
65 | //http://doc.qt.io/qt-4.8/qimage.html#details :Warning: This will create a QImage with uninitialized data. Call fill() to fill the image with an appropriate pixel value before drawing onto it with QPainter. | |
65 | colorMapImage.fill(QColor(Qt::white).rgb()); |
|
66 | colorMapImage.fill(QColor(Qt::white).rgb()); | |
66 |
|
67 | |||
67 | ColorMapDataPart * grid = m_series->getUniformGrid(0,0,plotAreaRect.width(),plotAreaRect.height(),QColorMapSeries::LastPixel); |
|
68 | QElapsedTimer timer; | |
|
69 | timer.start(); | |||
|
70 | ||||
|
71 | QVector<double> * grid = m_series->getUniformGrid(0,0,plotAreaRect.width(),plotAreaRect.height(),QColorMapSeries::LastPixel); | |||
|
72 | ||||
|
73 | int msec = timer.elapsed(); | |||
|
74 | int msec2 = 0+msec; | |||
68 |
|
75 | |||
69 | double maxZ = m_series->maxZ(); |
|
76 | double maxZ = m_series->maxZ(); | |
70 | double minZ = m_series->minZ(); |
|
77 | double minZ = m_series->minZ(); | |
71 | double rangeZ = maxZ - minZ; |
|
78 | double rangeZ = maxZ - minZ; | |
72 |
|
79 | |||
73 |
|
|
80 | int imageWidth = colorMapImage.width(); | |
|
81 | int imageHeight = colorMapImage.height(); | |||
|
82 | ||||
|
83 | for(int i=0;i<imageWidth;i++) | |||
74 | { |
|
84 | { | |
75 |
for(int j=0;j< |
|
85 | for(int j=0;j<imageHeight;j++) | |
76 | { |
|
86 | { | |
77 |
double value = grid-> |
|
87 | double value = grid->at(i+j*(imageWidth)); | |
78 | double pix=((value-minZ)/rangeZ); |
|
88 | double pix=((value-minZ)/rangeZ); | |
79 | int indexInColorTable = pix*(nbOfColors-1); |
|
89 | int indexInColorTable = pix*(nbOfColors-1); | |
80 | colorMapImage.setPixel(i,j,m_colorTable->at(indexInColorTable)); |
|
90 | colorMapImage.setPixel(i,j,m_colorTable->at(indexInColorTable)); | |
81 | } |
|
91 | } | |
82 | } |
|
92 | } | |
83 |
|
93 | |||
84 | if(!m_colorbar) |
|
94 | addColorBar(plotAreaRect); | |
85 | addColorBar(); |
|
95 | ||
86 |
|
96 | |||
87 | painter->drawImage(clipRect,colorMapImage); |
|
97 | painter->drawImage(clipRect,colorMapImage); | |
88 | update(); |
|
98 | update();//Qt docs: Warning: If you call repaint() in a function which may itself be called from paintEvent(), you may get infinite recursion. The update() function never causes recursion | |
|
99 | ||||
|
100 | painter->restore(); | |||
|
101 | ||||
|
102 | ||||
89 | } |
|
103 | } | |
90 |
|
104 | |||
91 | void ColorMapChart::addColorBar() |
|
105 | void ColorMapChart::addColorBar(QRectF plotAreaRect) | |
92 | { |
|
106 | { | |
93 | double maxZ = m_series->maxZ(); |
|
107 | double maxZ = m_series->maxZ(); | |
94 | double minZ = m_series->minZ(); |
|
108 | double minZ = m_series->minZ(); | |
95 | QColorBarAxis *colorbar = new QColorBarAxis(createColorMapGradient(m_gradientType),minZ, maxZ,this); |
|
109 | ||
96 | m_series->chart()->addAxis(colorbar, Qt::AlignRight); |
|
110 | if(m_isColorBarDrawn) | |
97 | m_colorbar = true; |
|
111 | m_series->chart()->removeAxis(m_colorbar); | |
|
112 | ||||
|
113 | m_colorbar = new QColorBarAxis(plotAreaRect,createColorMapGradient(m_gradientType),minZ, maxZ,this); | |||
|
114 | m_series->chart()->addAxis(m_colorbar, Qt::AlignRight); | |||
|
115 | m_isColorBarDrawn = true; | |||
98 | } |
|
116 | } | |
99 |
|
117 | |||
100 | /*! |
|
118 | /*! | |
101 | Returns the predefined QLinearGradient corresponding to the \a gradientType passed as argument. |
|
119 | Returns the predefined QLinearGradient corresponding to the \a gradientType passed as argument. | |
102 | */ |
|
120 | */ | |
103 | QLinearGradient ColorMapChart::createColorMapGradient(GradientType gradientType) |
|
121 | QLinearGradient ColorMapChart::createColorMapGradient(GradientType gradientType) | |
104 | { |
|
122 | { | |
105 | QLinearGradient gradient(0,0,1,100); |
|
123 | QLinearGradient gradient(0,0,1,100); | |
106 | switch(gradientType) |
|
124 | switch(gradientType) | |
107 | { |
|
125 | { | |
108 | case Rainbow : |
|
126 | case Rainbow : | |
109 | gradient.setColorAt(1.0,Qt::darkRed); |
|
127 | gradient.setColorAt(1.0,Qt::darkRed); | |
110 | gradient.setColorAt(0.8,Qt::red); |
|
128 | gradient.setColorAt(0.8,Qt::red); | |
111 | gradient.setColorAt(0.6,Qt::yellow); |
|
129 | gradient.setColorAt(0.6,Qt::yellow); | |
112 | gradient.setColorAt(0.4,Qt::green); |
|
130 | gradient.setColorAt(0.4,Qt::green); | |
113 | gradient.setColorAt(0.2,Qt::cyan); |
|
131 | gradient.setColorAt(0.2,Qt::cyan); | |
114 | gradient.setColorAt(0.0,Qt::blue); |
|
132 | gradient.setColorAt(0.0,Qt::blue); | |
115 | break; |
|
133 | break; | |
116 | case CyclingRainbow : |
|
134 | case CyclingRainbow : | |
117 | gradient.setColorAt(1.0,Qt::red); |
|
135 | gradient.setColorAt(1.0,Qt::red); | |
118 | gradient.setColorAt(0.8,Qt::yellow); |
|
136 | gradient.setColorAt(0.8,Qt::yellow); | |
119 | gradient.setColorAt(0.6,Qt::green); |
|
137 | gradient.setColorAt(0.6,Qt::green); | |
120 | gradient.setColorAt(0.4,Qt::cyan); |
|
138 | gradient.setColorAt(0.4,Qt::cyan); | |
121 | gradient.setColorAt(0.2,Qt::blue); |
|
139 | gradient.setColorAt(0.2,Qt::blue); | |
122 | gradient.setColorAt(0.0,Qt::magenta); |
|
140 | gradient.setColorAt(0.0,Qt::magenta); | |
123 | break; |
|
141 | break; | |
124 | case BlackAndWhite : |
|
142 | case BlackAndWhite : | |
125 | gradient.setColorAt(1.0, Qt::black); |
|
143 | gradient.setColorAt(1.0, Qt::black); | |
126 | gradient.setColorAt(0.0, Qt::white); |
|
144 | gradient.setColorAt(0.0, Qt::white); | |
127 | break; |
|
145 | break; | |
128 | case ReverseBlackAndWhite : |
|
146 | case ReverseBlackAndWhite : | |
129 | gradient.setColorAt(1.0, Qt::white); |
|
147 | gradient.setColorAt(1.0, Qt::white); | |
130 | gradient.setColorAt(0.0, Qt::black); |
|
148 | gradient.setColorAt(0.0, Qt::black); | |
131 | break; |
|
149 | break; | |
132 | default: |
|
150 | default: | |
133 | break; |
|
151 | break; | |
134 | } |
|
152 | } | |
135 | return gradient; |
|
153 | return gradient; | |
136 | } |
|
154 | } | |
137 |
|
155 | |||
138 | /*! |
|
156 | /*! | |
139 | Changes the type of gradient used to paint the ColorMap. |
|
157 | Changes the type of gradient used to paint the ColorMap. | |
140 | */ |
|
158 | */ | |
141 | void ColorMapChart::changeGradient(GradientType gradientType) |
|
159 | void ColorMapChart::changeGradient(GradientType gradientType) | |
142 | { |
|
160 | { | |
143 | if(m_gradientType == gradientType) |
|
161 | if(m_gradientType == gradientType) | |
144 | return; |
|
162 | return; | |
145 | else |
|
163 | else | |
146 | m_gradientType = gradientType; |
|
164 | m_gradientType = gradientType; | |
147 | emit gradientTypeChanged(); |
|
165 | emit gradientTypeChanged(); | |
148 | } |
|
166 | } | |
149 |
|
167 | |||
150 | /*! |
|
168 | /*! | |
151 | Creates a color table corresponding to the gradient type currently selected. |
|
169 | Creates a color table corresponding to the gradient type currently selected. | |
152 | */ |
|
170 | */ | |
153 | void ColorMapChart::populateColorTable() |
|
171 | void ColorMapChart::populateColorTable() | |
154 | { |
|
172 | { | |
155 | QLinearGradient gradient = createColorMapGradient(m_gradientType); |
|
173 | QLinearGradient gradient = createColorMapGradient(m_gradientType); | |
156 | QGradientStops colorStops = gradient.stops(); |
|
174 | QGradientStops colorStops = gradient.stops(); | |
157 |
|
175 | |||
158 | for(int i=0;i<nbOfColors;i++) |
|
176 | for(int i=0;i<nbOfColors;i++) | |
159 | { |
|
177 | { | |
160 | double colorIndex = (double)i/nbOfColors; |
|
178 | double colorIndex = (double)i/nbOfColors; | |
161 | for(int k =0;k<colorStops.size()-1;k++) |
|
179 | for(int k =0;k<colorStops.size()-1;k++) | |
162 | { |
|
180 | { | |
163 | QGradientStop lowerBound = colorStops.at(k); |
|
181 | QGradientStop lowerBound = colorStops.at(k); | |
164 | QGradientStop upperBound = colorStops.at(k+1); |
|
182 | QGradientStop upperBound = colorStops.at(k+1); | |
165 | if(colorIndex >= lowerBound.first && colorIndex < upperBound.first) |
|
183 | if(colorIndex >= lowerBound.first && colorIndex < upperBound.first) | |
166 | { |
|
184 | { | |
167 | double ratio = (colorIndex-lowerBound.first)/(upperBound.first - lowerBound.first); |
|
185 | double ratio = (colorIndex-lowerBound.first)/(upperBound.first - lowerBound.first); | |
168 | int red = (int)((1-ratio)*lowerBound.second.red() + ratio*upperBound.second.red()); |
|
186 | int red = (int)((1-ratio)*lowerBound.second.red() + ratio*upperBound.second.red()); | |
169 | int green = (int)((1-ratio)*lowerBound.second.green() + ratio*upperBound.second.green()); |
|
187 | int green = (int)((1-ratio)*lowerBound.second.green() + ratio*upperBound.second.green()); | |
170 | int blue = (int)((1-ratio)*lowerBound.second.blue() + ratio*upperBound.second.blue()); |
|
188 | int blue = (int)((1-ratio)*lowerBound.second.blue() + ratio*upperBound.second.blue()); | |
171 | m_colorTable->append(qRgb(red, green, blue)); |
|
189 | m_colorTable->append(qRgb(red, green, blue)); | |
172 | break; |
|
190 | break; | |
173 | } |
|
191 | } | |
174 | else |
|
192 | else | |
175 | { |
|
193 | { | |
176 | if(k==colorStops.size()-2) |
|
194 | if(k==colorStops.size()-2) | |
177 | { |
|
195 | { | |
178 | m_colorTable->append(qRgb(colorStops.at(colorStops.size()-1).second.red(), colorStops.at(colorStops.size()-1).second.green(), colorStops.at(colorStops.size()-1).second.blue())); |
|
196 | m_colorTable->append(qRgb(colorStops.at(colorStops.size()-1).second.red(), colorStops.at(colorStops.size()-1).second.green(), colorStops.at(colorStops.size()-1).second.blue())); | |
179 | } |
|
197 | } | |
180 | } |
|
198 | } | |
181 | } |
|
199 | } | |
182 | } |
|
200 | } | |
183 | } |
|
201 | } | |
184 |
|
202 | |||
185 |
|
203 | |||
186 | //handlers |
|
204 | //handlers | |
187 |
|
205 | |||
188 | void ColorMapChart::handlePointAdded(int index) |
|
206 | void ColorMapChart::handlePointAdded(int index) | |
189 | { |
|
207 | { | |
190 |
|
208 | |||
191 | } |
|
209 | } | |
192 |
|
210 | |||
193 | void ColorMapChart::handlePointRemoved(int index) |
|
211 | void ColorMapChart::handlePointRemoved(int index) | |
194 | { |
|
212 | { | |
195 |
|
213 | |||
196 | } |
|
214 | } | |
197 |
|
215 | |||
198 | void ColorMapChart::handlePointsRemoved(int index, int count) |
|
216 | void ColorMapChart::handlePointsRemoved(int index, int count) | |
199 | { |
|
217 | { | |
200 |
|
218 | |||
201 | } |
|
219 | } | |
202 |
|
220 | |||
203 | void ColorMapChart::handlePointReplaced(int index) |
|
221 | void ColorMapChart::handlePointReplaced(int index) | |
204 | { |
|
222 | { | |
205 |
|
223 | |||
206 | } |
|
224 | } | |
207 |
|
225 | |||
208 | void ColorMapChart::handlePointsReplaced() |
|
226 | void ColorMapChart::handlePointsReplaced() | |
209 | { |
|
227 | { | |
210 |
|
228 | |||
211 | } |
|
229 | } | |
212 |
|
230 | |||
213 | void ColorMapChart::handleDomainUpdated() |
|
231 | void ColorMapChart::handleDomainUpdated() | |
214 | { |
|
232 | { | |
215 |
|
233 | |||
216 | } |
|
234 | } | |
217 |
|
235 | |||
218 | bool ColorMapChart::isEmpty() |
|
236 | bool ColorMapChart::isEmpty() | |
219 | { |
|
237 | { | |
220 |
|
238 | |||
221 | } |
|
239 | } | |
222 |
|
240 | |||
223 |
|
241 | |||
224 | #include "moc_colormapchart_p.cpp" |
|
242 | #include "moc_colormapchart_p.cpp" | |
225 |
|
243 | |||
226 | QT_CHARTS_END_NAMESPACE |
|
244 | QT_CHARTS_END_NAMESPACE |
@@ -1,123 +1,127 | |||||
1 | #ifndef COLORMAPCHART_H |
|
1 | #ifndef COLORMAPCHART_H | |
2 | #define COLORMAPCHART_H |
|
2 | #define COLORMAPCHART_H | |
3 |
|
3 | |||
4 | #include "point3d.h" |
|
4 | #include "point3d.h" | |
5 | #include <QtCharts/QChartGlobal> |
|
5 | #include <QtCharts/QChartGlobal> | |
6 | #include <private/chartitem_p.h> |
|
6 | #include <private/chartitem_p.h> | |
7 | #include <QtCharts/QValueAxis> |
|
7 | #include <QtCharts/QValueAxis> | |
8 | #include <QtGui/QPen> |
|
8 | #include <QtGui/QPen> | |
9 |
|
9 | |||
|
10 | //#include <QtCharts/QColorBarAxis> TODO : fix this | |||
|
11 | #include "qcolorbaraxis.h" | |||
|
12 | ||||
10 | QT_CHARTS_BEGIN_NAMESPACE |
|
13 | QT_CHARTS_BEGIN_NAMESPACE | |
11 |
|
14 | |||
12 | class ChartPresenter; |
|
15 | class ChartPresenter; | |
13 | class QColorMapSeries; |
|
16 | class QColorMapSeries; | |
14 |
|
17 | |||
15 | class ColorMapChart : public ChartItem |
|
18 | class ColorMapChart : public ChartItem | |
16 | { |
|
19 | { | |
17 | Q_OBJECT |
|
20 | Q_OBJECT | |
18 | public: |
|
21 | public: | |
19 |
|
22 | |||
20 | enum GradientType |
|
23 | enum GradientType | |
21 | { |
|
24 | { | |
22 | Rainbow, |
|
25 | Rainbow, | |
23 | CyclingRainbow, |
|
26 | CyclingRainbow, | |
24 | BlackAndWhite, |
|
27 | BlackAndWhite, | |
25 | ReverseBlackAndWhite |
|
28 | ReverseBlackAndWhite | |
26 | }; |
|
29 | }; | |
27 |
|
30 | |||
28 | explicit ColorMapChart(QColorMapSeries *series,QGraphicsItem *item = 0); |
|
31 | explicit ColorMapChart(QColorMapSeries *series,QGraphicsItem *item = 0); | |
29 | ~ColorMapChart() {} |
|
32 | ~ColorMapChart() {} | |
30 |
|
33 | |||
31 | bool isDirty() const { return m_dirty; } |
|
34 | bool isDirty() const { return m_dirty; } | |
32 | void setDirty(bool dirty); |
|
35 | void setDirty(bool dirty); | |
33 |
|
36 | |||
34 | // from QGraphicsItem |
|
37 | // from QGraphicsItem | |
35 | QRectF boundingRect() const; |
|
38 | QRectF boundingRect() const; | |
36 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); |
|
39 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); | |
37 |
|
40 | |||
38 | public Q_SLOTS: |
|
41 | public Q_SLOTS: | |
39 | void handlePointAdded(int index); |
|
42 | void handlePointAdded(int index); | |
40 | void handlePointRemoved(int index); |
|
43 | void handlePointRemoved(int index); | |
41 | void handlePointsRemoved(int index, int count); |
|
44 | void handlePointsRemoved(int index, int count); | |
42 | void handlePointReplaced(int index); |
|
45 | void handlePointReplaced(int index); | |
43 | void handlePointsReplaced(); |
|
46 | void handlePointsReplaced(); | |
44 | void handleDomainUpdated(); |
|
47 | void handleDomainUpdated(); | |
45 |
|
48 | |||
46 | private slots : |
|
49 | private slots : | |
47 | void populateColorTable(); |
|
50 | void populateColorTable(); | |
48 |
|
51 | |||
49 | Q_SIGNALS: |
|
52 | Q_SIGNALS: | |
50 | void clicked(const Point3D &point); |
|
53 | void clicked(const Point3D &point); | |
51 | void hovered(const Point3D &point, bool state); |
|
54 | void hovered(const Point3D &point, bool state); | |
52 | void pressed(const Point3D &point); |
|
55 | void pressed(const Point3D &point); | |
53 | void released(const Point3D &point); |
|
56 | void released(const Point3D &point); | |
54 | void doubleClicked(const Point3D &point); |
|
57 | void doubleClicked(const Point3D &point); | |
55 | void gradientTypeChanged(); |
|
58 | void gradientTypeChanged(); | |
56 |
|
59 | |||
57 | private: |
|
60 | private: | |
58 | inline bool isEmpty(); |
|
61 | inline bool isEmpty(); | |
59 | void addColorBar(); |
|
62 | void addColorBar(QRectF plotAreaRect); | |
60 | QLinearGradient createColorMapGradient(GradientType gradientType); |
|
63 | QLinearGradient createColorMapGradient(GradientType gradientType); | |
61 | void changeGradient(GradientType gradientType); |
|
64 | void changeGradient(GradientType gradientType); | |
62 |
|
65 | |||
63 | protected: |
|
66 | protected: | |
64 | QColorMapSeries *m_series; |
|
67 | QColorMapSeries *m_series; | |
65 | QVector<Point3D> m_points; |
|
68 | QVector<Point3D> m_points; | |
66 | QRectF m_rect; |
|
69 | QRectF m_rect; | |
67 | bool m_dirty; |
|
70 | bool m_dirty; | |
68 | QVector<QRgb> *m_colorTable; |
|
71 | QVector<QRgb> *m_colorTable; | |
69 | GradientType m_gradientType; |
|
72 | GradientType m_gradientType; | |
70 |
bool m_ |
|
73 | bool m_isColorBarDrawn; | |
|
74 | QColorBarAxis *m_colorbar; | |||
71 | }; |
|
75 | }; | |
72 |
|
76 | |||
73 | //class PixmapMarker: public QGraphicsRectItem |
|
77 | //class PixmapMarker: public QGraphicsRectItem | |
74 | //{ |
|
78 | //{ | |
75 |
|
79 | |||
76 | //public: |
|
80 | //public: | |
77 | // PixmapMarker(qreal x, qreal y, qreal w, qreal h, ColorMapChart *parent) |
|
81 | // PixmapMarker(qreal x, qreal y, qreal w, qreal h, ColorMapChart *parent) | |
78 | // : QGraphicsRectItem(x, y, w, h, parent), |
|
82 | // : QGraphicsRectItem(x, y, w, h, parent), | |
79 | // m_parent(parent) |
|
83 | // m_parent(parent) | |
80 | // { |
|
84 | // { | |
81 | // setAcceptHoverEvents(true); |
|
85 | // setAcceptHoverEvents(true); | |
82 | // setFlag(QGraphicsItem::ItemIsSelectable); |
|
86 | // setFlag(QGraphicsItem::ItemIsSelectable); | |
83 | // } |
|
87 | // } | |
84 |
|
88 | |||
85 | //protected: |
|
89 | //protected: | |
86 | // void mousePressEvent(QGraphicsSceneMouseEvent *event) |
|
90 | // void mousePressEvent(QGraphicsSceneMouseEvent *event) | |
87 | // { |
|
91 | // { | |
88 | // QGraphicsRectItem::mousePressEvent(event); |
|
92 | // QGraphicsRectItem::mousePressEvent(event); | |
89 | // m_parent->markerPressed(this); |
|
93 | // m_parent->markerPressed(this); | |
90 | // m_parent->setMousePressed(); |
|
94 | // m_parent->setMousePressed(); | |
91 | // } |
|
95 | // } | |
92 | // void hoverEnterEvent(QGraphicsSceneHoverEvent *event) |
|
96 | // void hoverEnterEvent(QGraphicsSceneHoverEvent *event) | |
93 | // { |
|
97 | // { | |
94 | // QGraphicsRectItem::hoverEnterEvent(event); |
|
98 | // QGraphicsRectItem::hoverEnterEvent(event); | |
95 | // m_parent->markerHovered(this, true); |
|
99 | // m_parent->markerHovered(this, true); | |
96 | // } |
|
100 | // } | |
97 | // void hoverLeaveEvent(QGraphicsSceneHoverEvent *event) |
|
101 | // void hoverLeaveEvent(QGraphicsSceneHoverEvent *event) | |
98 | // { |
|
102 | // { | |
99 | // QGraphicsRectItem::hoverLeaveEvent(event); |
|
103 | // QGraphicsRectItem::hoverLeaveEvent(event); | |
100 | // m_parent->markerHovered(this, false); |
|
104 | // m_parent->markerHovered(this, false); | |
101 | // } |
|
105 | // } | |
102 | // void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) |
|
106 | // void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) | |
103 | // { |
|
107 | // { | |
104 | // QGraphicsRectItem::mouseReleaseEvent(event); |
|
108 | // QGraphicsRectItem::mouseReleaseEvent(event); | |
105 | // m_parent->markerReleased(this); |
|
109 | // m_parent->markerReleased(this); | |
106 | // if (m_parent->mousePressed()) |
|
110 | // if (m_parent->mousePressed()) | |
107 | // m_parent->markerSelected(this); |
|
111 | // m_parent->markerSelected(this); | |
108 | // m_parent->setMousePressed(false); |
|
112 | // m_parent->setMousePressed(false); | |
109 | // } |
|
113 | // } | |
110 | // void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) |
|
114 | // void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) | |
111 | // { |
|
115 | // { | |
112 | // QGraphicsRectItem::mouseDoubleClickEvent(event); |
|
116 | // QGraphicsRectItem::mouseDoubleClickEvent(event); | |
113 | // m_parent->markerDoubleClicked(this); |
|
117 | // m_parent->markerDoubleClicked(this); | |
114 | // } |
|
118 | // } | |
115 |
|
119 | |||
116 | //private: |
|
120 | //private: | |
117 | // ColorMapChart *m_parent; |
|
121 | // ColorMapChart *m_parent; | |
118 | //}; |
|
122 | //}; | |
119 |
|
123 | |||
120 |
|
124 | |||
121 | QT_CHARTS_END_NAMESPACE |
|
125 | QT_CHARTS_END_NAMESPACE | |
122 |
|
126 | |||
123 | #endif // COLORMAPCHART_H |
|
127 | #endif // COLORMAPCHART_H |
@@ -1,638 +1,631 | |||||
1 | #include "qcolormapseries.h" |
|
1 | #include "qcolormapseries.h" | |
2 | #include <private/qcolormapseries_p.h> |
|
2 | #include <private/qcolormapseries_p.h> | |
3 | #include <private/abstractdomain_p.h> |
|
3 | #include <private/abstractdomain_p.h> | |
4 | #include <QtCharts/QValueAxis> |
|
4 | #include <QtCharts/QValueAxis> | |
5 | #include <private/colormapchart_p.h> |
|
5 | #include <private/colormapchart_p.h> | |
6 | #include <QtCharts/QColorMapLegendMarker> |
|
6 | #include <QtCharts/QColorMapLegendMarker> | |
7 | #include <private/charthelpers_p.h> |
|
7 | #include <private/charthelpers_p.h> | |
8 | #include <private/qchart_p.h> |
|
8 | #include <private/qchart_p.h> | |
9 | #include <QtGui/QPainter> |
|
9 | #include <QtGui/QPainter> | |
10 |
|
10 | |||
11 | //#include <algorithm> |
|
11 | //#include <algorithm> | |
12 | #include <cmath> |
|
12 | #include <cmath> | |
13 |
|
13 | |||
14 | #include "qcolorbaraxis.h" |
|
14 | #include "qcolorbaraxis.h" | |
15 |
|
15 | |||
16 | QT_CHARTS_BEGIN_NAMESPACE |
|
16 | QT_CHARTS_BEGIN_NAMESPACE | |
17 |
|
17 | |||
18 | /*! |
|
18 | /*! | |
19 | \internal |
|
19 | \internal | |
20 |
|
20 | |||
21 | Constructs empty series object which is a child of \a parent. |
|
21 | Constructs empty series object which is a child of \a parent. | |
22 | When series object is added to QChart instance ownerships is transferred. |
|
22 | When series object is added to QChart instance ownerships is transferred. | |
23 | */ |
|
23 | */ | |
24 | QColorMapSeries::QColorMapSeries(QObject *parent) |
|
24 | QColorMapSeries::QColorMapSeries(QObject *parent) | |
25 | : QAbstractSeries(*new QColorMapSeriesPrivate(this), parent) |
|
25 | : QAbstractSeries(*new QColorMapSeriesPrivate(this), parent) | |
26 | { |
|
26 | { | |
27 | } |
|
27 | } | |
28 |
|
28 | |||
29 | /*! |
|
29 | /*! | |
30 | \internal |
|
30 | \internal | |
31 |
|
31 | |||
32 | Constructs empty series object which is a child of \a parent. |
|
32 | Constructs empty series object which is a child of \a parent. | |
33 | When series object is added to QChart instance ownerships is transferred. |
|
33 | When series object is added to QChart instance ownerships is transferred. | |
34 | */ |
|
34 | */ | |
35 | QColorMapSeries::QColorMapSeries(QColorMapSeriesPrivate &d, QObject *parent) |
|
35 | QColorMapSeries::QColorMapSeries(QColorMapSeriesPrivate &d, QObject *parent) | |
36 | : QAbstractSeries(d, parent) |
|
36 | : QAbstractSeries(d, parent) | |
37 | { |
|
37 | { | |
38 | } |
|
38 | } | |
39 |
|
39 | |||
40 |
|
40 | |||
41 | /*! |
|
41 | /*! | |
42 | Destroys the object. Series added to QChart instances are owned by those, |
|
42 | Destroys the object. Series added to QChart instances are owned by those, | |
43 | and are destroyed when QChart instances are destroyed. |
|
43 | and are destroyed when QChart instances are destroyed. | |
44 | */ |
|
44 | */ | |
45 | QColorMapSeries::~QColorMapSeries() |
|
45 | QColorMapSeries::~QColorMapSeries() | |
46 | { |
|
46 | { | |
47 | } |
|
47 | } | |
48 |
|
48 | |||
49 | /*! |
|
49 | /*! | |
50 | \fn virtual SeriesType QBoxPlotSeries::type() const |
|
50 | \fn virtual SeriesType QBoxPlotSeries::type() const | |
51 | \brief Returns type of series. |
|
51 | \brief Returns type of series. | |
52 | \sa QAbstractSeries, SeriesType |
|
52 | \sa QAbstractSeries, SeriesType | |
53 | */ |
|
53 | */ | |
54 | QAbstractSeries::SeriesType QColorMapSeries::type() const |
|
54 | QAbstractSeries::SeriesType QColorMapSeries::type() const | |
55 | { |
|
55 | { | |
56 | return QAbstractSeries::SeriesTypeColorMap; |
|
56 | return QAbstractSeries::SeriesTypeColorMap; | |
57 | } |
|
57 | } | |
58 |
|
58 | |||
59 |
|
59 | |||
60 | /*! |
|
60 | /*! | |
61 | Adds data part \a dataPart to the series.\n |
|
61 | Adds data part \a dataPart to the series.\n | |
62 | If \a copy is true, adds a copy of the data part instead. |
|
62 | If \a copy is true, adds a copy of the data part instead. | |
63 | */ |
|
63 | */ | |
64 | void QColorMapSeries::append(ColorMapDataPart* dataPart, bool copy) |
|
64 | void QColorMapSeries::append(ColorMapDataPart* dataPart, bool copy) | |
65 | { |
|
65 | { | |
66 | Q_D(QColorMapSeries); |
|
66 | Q_D(QColorMapSeries); | |
67 | if(copy) |
|
67 | if(copy) | |
68 | d->m_dataParts << new ColorMapDataPart(dataPart); |
|
68 | d->m_dataParts << new ColorMapDataPart(dataPart); | |
69 | else |
|
69 | else | |
70 | d->m_dataParts << dataPart; |
|
70 | d->m_dataParts << dataPart; | |
71 | d->recomputeDataRange(); |
|
71 | d->recomputeDataRange(); | |
72 | emit dataPartAdded(d->m_dataParts.count() - 1); |
|
72 | emit dataPartAdded(d->m_dataParts.count() - 1); | |
73 | } |
|
73 | } | |
74 |
|
74 | |||
75 | /*! |
|
75 | /*! | |
76 | This is an overloaded function.\n |
|
76 | This is an overloaded function.\n | |
77 | Adds data parts \a dataParts to the series.\n |
|
77 | Adds data parts \a dataParts to the series.\n | |
78 | If \a copy is true, adds a copy of the data part instead. |
|
78 | If \a copy is true, adds a copy of the data part instead. | |
79 | */ |
|
79 | */ | |
80 | void QColorMapSeries::append(const QList<ColorMapDataPart*> &dataParts, bool copy) |
|
80 | void QColorMapSeries::append(const QList<ColorMapDataPart*> &dataParts, bool copy) | |
81 | { |
|
81 | { | |
82 | foreach (ColorMapDataPart* dataPart , dataParts) |
|
82 | foreach (ColorMapDataPart* dataPart , dataParts) | |
83 | append(dataPart,copy); |
|
83 | append(dataPart,copy); | |
84 | } |
|
84 | } | |
85 |
|
85 | |||
86 |
|
86 | |||
87 | /*! |
|
87 | /*! | |
88 | Returns number of data parts within series. |
|
88 | Returns number of data parts within series. | |
89 | */ |
|
89 | */ | |
90 | int QColorMapSeries::count() const |
|
90 | int QColorMapSeries::count() const | |
91 | { |
|
91 | { | |
92 | Q_D(const QColorMapSeries); |
|
92 | Q_D(const QColorMapSeries); | |
93 | return d->m_dataParts.count(); |
|
93 | return d->m_dataParts.count(); | |
94 | } |
|
94 | } | |
95 |
|
95 | |||
96 |
|
96 | |||
97 | /*! |
|
97 | /*! | |
98 | Stream operator for adding a data part \a point to the series. |
|
98 | Stream operator for adding a data part \a point to the series. | |
99 | \sa append() |
|
99 | \sa append() | |
100 | */ |
|
100 | */ | |
101 | QColorMapSeries &QColorMapSeries::operator <<(const ColorMapDataPart &dataPart) |
|
101 | QColorMapSeries &QColorMapSeries::operator <<(const ColorMapDataPart &dataPart) | |
102 | { |
|
102 | { | |
103 | append(new ColorMapDataPart(dataPart)); |
|
103 | append(new ColorMapDataPart(dataPart)); | |
104 | return *this; |
|
104 | return *this; | |
105 | } |
|
105 | } | |
106 |
|
106 | |||
107 | /*! |
|
107 | /*! | |
108 | Stream operator for adding a vector of data parts \a dataParts to the series. |
|
108 | Stream operator for adding a vector of data parts \a dataParts to the series. | |
109 | \sa append() |
|
109 | \sa append() | |
110 | */ |
|
110 | */ | |
111 | QColorMapSeries &QColorMapSeries::operator <<(const QList<ColorMapDataPart*> &dataParts) |
|
111 | QColorMapSeries &QColorMapSeries::operator <<(const QList<ColorMapDataPart*> &dataParts) | |
112 | { |
|
112 | { | |
113 | append(dataParts); |
|
113 | append(dataParts); | |
114 | return *this; |
|
114 | return *this; | |
115 | } |
|
115 | } | |
116 |
|
116 | |||
117 | /*! |
|
117 | /*! | |
118 | Returns a ColorMapData part containing a uniform grid of data points to be mapped in a ColorMapChart.\n |
|
118 | Returns a ColorMapData part containing a uniform grid of data points to be mapped in a ColorMapChart.\n | |
119 | The rectangle of data returned is determined by \a width and \height,\n |
|
119 | The rectangle of data returned is determined by \a width and \height,\n | |
120 | from the position \a xpos , \a ypos (starting at the top left corner of the plot area).\n |
|
120 | from the position \a xpos , \a ypos (starting at the top left corner of the plot area).\n | |
121 | When there are more points than pixels, \a strategy is applied to determine which to choose. |
|
121 | When there are more points than pixels, \a strategy is applied to determine which to choose. | |
122 | */ |
|
122 | */ | |
123 |
|
|
123 | QVector<double> *QColorMapSeries::getUniformGrid(int xpos, int ypos,int width, int height, QColorMapSeries::Strategy strategy) | |
124 | { |
|
124 | { | |
125 | Q_D(QColorMapSeries); |
|
125 | Q_D(QColorMapSeries); | |
126 | return d->getUniformGrid(xpos, ypos,width,height, strategy); |
|
126 | return d->getUniformGrid(xpos, ypos,width,height, strategy); | |
127 | } |
|
127 | } | |
128 |
|
128 | |||
129 | //void QColorMapSeries::attachAxis(QAbstractAxis *axis) |
|
129 | //void QColorMapSeries::attachAxis(QAbstractAxis *axis) | |
130 | //{ |
|
130 | //{ | |
131 | // axis = static_cast<QColorBarAxis*>(); |
|
131 | // axis = static_cast<QColorBarAxis*>(); | |
132 | // if(axis) |
|
132 | // if(axis) | |
133 | // { |
|
133 | // { | |
134 |
|
134 | |||
135 | // } |
|
135 | // } | |
136 | // else |
|
136 | // else | |
137 | // { |
|
137 | // { | |
138 | // QAbstractSeries::attachAxis(axis); |
|
138 | // QAbstractSeries::attachAxis(axis); | |
139 | // } |
|
139 | // } | |
140 | //} |
|
140 | //} | |
141 |
|
141 | |||
142 | /*! |
|
142 | /*! | |
143 | Sets \a pen used for drawing points on the chart. If the pen is not defined, the |
|
143 | Sets \a pen used for drawing points on the chart. If the pen is not defined, the | |
144 | pen from chart theme is used. |
|
144 | pen from chart theme is used. | |
145 | \sa QChart::setTheme() |
|
145 | \sa QChart::setTheme() | |
146 | */ |
|
146 | */ | |
147 | void QColorMapSeries::setPen(const QPen &pen) |
|
147 | void QColorMapSeries::setPen(const QPen &pen) | |
148 | { |
|
148 | { | |
149 | Q_D(QColorMapSeries); |
|
149 | Q_D(QColorMapSeries); | |
150 | if (d->m_pen != pen) |
|
150 | if (d->m_pen != pen) | |
151 | { |
|
151 | { | |
152 | //bool emitColorChanged = d->m_pen.color() != pen.color(); |
|
152 | //bool emitColorChanged = d->m_pen.color() != pen.color(); | |
153 | d->m_pen = pen; |
|
153 | d->m_pen = pen; | |
154 | emit d->updated(); |
|
154 | emit d->updated(); | |
155 | // if (emitColorChanged) |
|
155 | // if (emitColorChanged) | |
156 | // emit colorChanged(pen.color()); |
|
156 | // emit colorChanged(pen.color()); | |
157 | emit penChanged(pen); |
|
157 | emit penChanged(pen); | |
158 | } |
|
158 | } | |
159 | } |
|
159 | } | |
160 |
|
160 | |||
161 | QPen QColorMapSeries::pen() const |
|
161 | QPen QColorMapSeries::pen() const | |
162 | { |
|
162 | { | |
163 | Q_D(const QColorMapSeries); |
|
163 | Q_D(const QColorMapSeries); | |
164 | if (d->m_pen == QChartPrivate::defaultPen()) |
|
164 | if (d->m_pen == QChartPrivate::defaultPen()) | |
165 | return QPen(); |
|
165 | return QPen(); | |
166 | else |
|
166 | else | |
167 | return d->m_pen; |
|
167 | return d->m_pen; | |
168 | } |
|
168 | } | |
169 |
|
169 | |||
170 | /*! |
|
170 | /*! | |
171 | Sets \a brush used for drawing points on the chart. If the brush is not defined, brush |
|
171 | Sets \a brush used for drawing points on the chart. If the brush is not defined, brush | |
172 | from chart theme setting is used. |
|
172 | from chart theme setting is used. | |
173 | \sa QChart::setTheme() |
|
173 | \sa QChart::setTheme() | |
174 | */ |
|
174 | */ | |
175 | void QColorMapSeries::setBrush(const QBrush &brush) |
|
175 | void QColorMapSeries::setBrush(const QBrush &brush) | |
176 | { |
|
176 | { | |
177 | Q_D(QColorMapSeries); |
|
177 | Q_D(QColorMapSeries); | |
178 | if (d->m_brush != brush) |
|
178 | if (d->m_brush != brush) | |
179 | { |
|
179 | { | |
180 | d->m_brush = brush; |
|
180 | d->m_brush = brush; | |
181 | emit d->updated(); |
|
181 | emit d->updated(); | |
182 | } |
|
182 | } | |
183 | } |
|
183 | } | |
184 |
|
184 | |||
185 | QBrush QColorMapSeries::brush() const |
|
185 | QBrush QColorMapSeries::brush() const | |
186 | { |
|
186 | { | |
187 | Q_D(const QColorMapSeries); |
|
187 | Q_D(const QColorMapSeries); | |
188 | if (d->m_brush == QChartPrivate::defaultBrush()) |
|
188 | if (d->m_brush == QChartPrivate::defaultBrush()) | |
189 | return QBrush(); |
|
189 | return QBrush(); | |
190 | else |
|
190 | else | |
191 | return d->m_brush; |
|
191 | return d->m_brush; | |
192 | } |
|
192 | } | |
193 |
|
193 | |||
194 | //void QColorMapSeries::setColor(const QColor &color) |
|
194 | //void QColorMapSeries::setColor(const QColor &color) | |
195 | //{ |
|
195 | //{ | |
196 | // QPen p = pen(); |
|
196 | // QPen p = pen(); | |
197 | // if (p.color() != color) |
|
197 | // if (p.color() != color) | |
198 | // { |
|
198 | // { | |
199 | // p.setColor(color); |
|
199 | // p.setColor(color); | |
200 | // setPen(p); |
|
200 | // setPen(p); | |
201 | // } |
|
201 | // } | |
202 | //} |
|
202 | //} | |
203 |
|
203 | |||
204 | //QColor QColorMapSeries::color() const |
|
204 | //QColor QColorMapSeries::color() const | |
205 | //{ |
|
205 | //{ | |
206 | // return pen().color(); |
|
206 | // return pen().color(); | |
207 | //} |
|
207 | //} | |
208 |
|
208 | |||
209 | //void QColorMapSeries::setPointsVisible(bool visible) |
|
209 | //void QColorMapSeries::setPointsVisible(bool visible) | |
210 | //{ |
|
210 | //{ | |
211 | // Q_D(QColorMapSeries); |
|
211 | // Q_D(QColorMapSeries); | |
212 | // if (d->m_pointsVisible != visible) |
|
212 | // if (d->m_pointsVisible != visible) | |
213 | // { |
|
213 | // { | |
214 | // d->m_pointsVisible = visible; |
|
214 | // d->m_pointsVisible = visible; | |
215 | // emit d->updated(); |
|
215 | // emit d->updated(); | |
216 | // } |
|
216 | // } | |
217 | //} |
|
217 | //} | |
218 |
|
218 | |||
219 | //bool QColorMapSeries::pointsVisible() const |
|
219 | //bool QColorMapSeries::pointsVisible() const | |
220 | //{ |
|
220 | //{ | |
221 | // Q_D(const QColorMapSeries); |
|
221 | // Q_D(const QColorMapSeries); | |
222 | // return d->m_pointsVisible; |
|
222 | // return d->m_pointsVisible; | |
223 | //} |
|
223 | //} | |
224 |
|
224 | |||
225 | //void QColorMapSeries::setPointLabelsFormat(const QString &format) |
|
225 | //void QColorMapSeries::setPointLabelsFormat(const QString &format) | |
226 | //{ |
|
226 | //{ | |
227 | // Q_D(QColorMapSeries); |
|
227 | // Q_D(QColorMapSeries); | |
228 | // if (d->m_pointLabelsFormat != format) |
|
228 | // if (d->m_pointLabelsFormat != format) | |
229 | // { |
|
229 | // { | |
230 | // d->m_pointLabelsFormat = format; |
|
230 | // d->m_pointLabelsFormat = format; | |
231 | // emit pointLabelsFormatChanged(format); |
|
231 | // emit pointLabelsFormatChanged(format); | |
232 | // } |
|
232 | // } | |
233 | //} |
|
233 | //} | |
234 |
|
234 | |||
235 | //QString QColorMapSeries::pointLabelsFormat() const |
|
235 | //QString QColorMapSeries::pointLabelsFormat() const | |
236 | //{ |
|
236 | //{ | |
237 | // Q_D(const QColorMapSeries); |
|
237 | // Q_D(const QColorMapSeries); | |
238 | // return d->m_pointLabelsFormat; |
|
238 | // return d->m_pointLabelsFormat; | |
239 | //} |
|
239 | //} | |
240 |
|
240 | |||
241 | //void QColorMapSeries::setPointLabelsVisible(bool visible) |
|
241 | //void QColorMapSeries::setPointLabelsVisible(bool visible) | |
242 | //{ |
|
242 | //{ | |
243 | // Q_D(QColorMapSeries); |
|
243 | // Q_D(QColorMapSeries); | |
244 | // if (d->m_pointLabelsVisible != visible) |
|
244 | // if (d->m_pointLabelsVisible != visible) | |
245 | // { |
|
245 | // { | |
246 | // d->m_pointLabelsVisible = visible; |
|
246 | // d->m_pointLabelsVisible = visible; | |
247 | // emit pointLabelsVisibilityChanged(visible); |
|
247 | // emit pointLabelsVisibilityChanged(visible); | |
248 | // } |
|
248 | // } | |
249 | //} |
|
249 | //} | |
250 |
|
250 | |||
251 | //bool QColorMapSeries::pointLabelsVisible() const |
|
251 | //bool QColorMapSeries::pointLabelsVisible() const | |
252 | //{ |
|
252 | //{ | |
253 | // Q_D(const QColorMapSeries); |
|
253 | // Q_D(const QColorMapSeries); | |
254 | // return d->m_pointLabelsVisible; |
|
254 | // return d->m_pointLabelsVisible; | |
255 | //} |
|
255 | //} | |
256 |
|
256 | |||
257 | //void QColorMapSeries::setPointLabelsFont(const QFont &font) |
|
257 | //void QColorMapSeries::setPointLabelsFont(const QFont &font) | |
258 | //{ |
|
258 | //{ | |
259 | // Q_D(QColorMapSeries); |
|
259 | // Q_D(QColorMapSeries); | |
260 | // if (d->m_pointLabelsFont != font) { |
|
260 | // if (d->m_pointLabelsFont != font) { | |
261 | // d->m_pointLabelsFont = font; |
|
261 | // d->m_pointLabelsFont = font; | |
262 | // emit pointLabelsFontChanged(font); |
|
262 | // emit pointLabelsFontChanged(font); | |
263 | // } |
|
263 | // } | |
264 | //} |
|
264 | //} | |
265 |
|
265 | |||
266 | //QFont QColorMapSeries::pointLabelsFont() const |
|
266 | //QFont QColorMapSeries::pointLabelsFont() const | |
267 | //{ |
|
267 | //{ | |
268 | // Q_D(const QColorMapSeries); |
|
268 | // Q_D(const QColorMapSeries); | |
269 | // return d->m_pointLabelsFont; |
|
269 | // return d->m_pointLabelsFont; | |
270 | //} |
|
270 | //} | |
271 |
|
271 | |||
272 | //void QColorMapSeries::setPointLabelsColor(const QColor &color) |
|
272 | //void QColorMapSeries::setPointLabelsColor(const QColor &color) | |
273 | //{ |
|
273 | //{ | |
274 | // Q_D(QColorMapSeries); |
|
274 | // Q_D(QColorMapSeries); | |
275 | // if (d->m_pointLabelsColor != color) { |
|
275 | // if (d->m_pointLabelsColor != color) { | |
276 | // d->m_pointLabelsColor = color; |
|
276 | // d->m_pointLabelsColor = color; | |
277 | // emit pointLabelsColorChanged(color); |
|
277 | // emit pointLabelsColorChanged(color); | |
278 | // } |
|
278 | // } | |
279 | //} |
|
279 | //} | |
280 |
|
280 | |||
281 | //QColor QColorMapSeries::pointLabelsColor() const |
|
281 | //QColor QColorMapSeries::pointLabelsColor() const | |
282 | //{ |
|
282 | //{ | |
283 | // Q_D(const QColorMapSeries); |
|
283 | // Q_D(const QColorMapSeries); | |
284 | // if (d->m_pointLabelsColor == QChartPrivate::defaultPen().color()) |
|
284 | // if (d->m_pointLabelsColor == QChartPrivate::defaultPen().color()) | |
285 | // return QPen().color(); |
|
285 | // return QPen().color(); | |
286 | // else |
|
286 | // else | |
287 | // return d->m_pointLabelsColor; |
|
287 | // return d->m_pointLabelsColor; | |
288 | //} |
|
288 | //} | |
289 |
|
289 | |||
290 | //void QColorMapSeries::setPointLabelsClipping(bool enabled) |
|
290 | //void QColorMapSeries::setPointLabelsClipping(bool enabled) | |
291 | //{ |
|
291 | //{ | |
292 | // Q_D(QColorMapSeries); |
|
292 | // Q_D(QColorMapSeries); | |
293 | // if (d->m_pointLabelsClipping != enabled) { |
|
293 | // if (d->m_pointLabelsClipping != enabled) { | |
294 | // d->m_pointLabelsClipping = enabled; |
|
294 | // d->m_pointLabelsClipping = enabled; | |
295 | // emit pointLabelsClippingChanged(enabled); |
|
295 | // emit pointLabelsClippingChanged(enabled); | |
296 | // } |
|
296 | // } | |
297 | //} |
|
297 | //} | |
298 |
|
298 | |||
299 | //bool QColorMapSeries::pointLabelsClipping() const |
|
299 | //bool QColorMapSeries::pointLabelsClipping() const | |
300 | //{ |
|
300 | //{ | |
301 | // Q_D(const QColorMapSeries); |
|
301 | // Q_D(const QColorMapSeries); | |
302 | // return d->m_pointLabelsClipping; |
|
302 | // return d->m_pointLabelsClipping; | |
303 | //} |
|
303 | //} | |
304 | /*! |
|
304 | /*! | |
305 | Returns the minimum value of the series on the X axis. |
|
305 | Returns the minimum value of the series on the X axis. | |
306 | */ |
|
306 | */ | |
307 | double QColorMapSeries::minX() |
|
307 | double QColorMapSeries::minX() | |
308 | { |
|
308 | { | |
309 | Q_D(QColorMapSeries); |
|
309 | Q_D(QColorMapSeries); | |
310 | return d->m_minX; |
|
310 | return d->m_minX; | |
311 | } |
|
311 | } | |
312 |
|
312 | |||
313 | /*! |
|
313 | /*! | |
314 | Returns the minimum value of the series on the Y axis. |
|
314 | Returns the minimum value of the series on the Y axis. | |
315 | */ |
|
315 | */ | |
316 | double QColorMapSeries::minY() |
|
316 | double QColorMapSeries::minY() | |
317 | { |
|
317 | { | |
318 | Q_D(QColorMapSeries); |
|
318 | Q_D(QColorMapSeries); | |
319 | return d->m_minY; |
|
319 | return d->m_minY; | |
320 | } |
|
320 | } | |
321 |
|
321 | |||
322 | /*! |
|
322 | /*! | |
323 | Returns the minimum value of the series on the Z axis. |
|
323 | Returns the minimum value of the series on the Z axis. | |
324 | */ |
|
324 | */ | |
325 | double QColorMapSeries::minZ() |
|
325 | double QColorMapSeries::minZ() | |
326 | { |
|
326 | { | |
327 | Q_D(QColorMapSeries); |
|
327 | Q_D(QColorMapSeries); | |
328 | return d->m_minZ; |
|
328 | return d->m_minZ; | |
329 | } |
|
329 | } | |
330 |
|
330 | |||
331 | /*! |
|
331 | /*! | |
332 | Returns the maximum value of the series on the X axis. |
|
332 | Returns the maximum value of the series on the X axis. | |
333 | */ |
|
333 | */ | |
334 | double QColorMapSeries::maxX() |
|
334 | double QColorMapSeries::maxX() | |
335 | { |
|
335 | { | |
336 | Q_D(QColorMapSeries); |
|
336 | Q_D(QColorMapSeries); | |
337 | return d->m_maxX; |
|
337 | return d->m_maxX; | |
338 | } |
|
338 | } | |
339 |
|
339 | |||
340 | /*! |
|
340 | /*! | |
341 | Returns the maximum value of the series on the Y axis. |
|
341 | Returns the maximum value of the series on the Y axis. | |
342 | */ |
|
342 | */ | |
343 | double QColorMapSeries::maxY() |
|
343 | double QColorMapSeries::maxY() | |
344 | { |
|
344 | { | |
345 | Q_D(QColorMapSeries); |
|
345 | Q_D(QColorMapSeries); | |
346 | return d->m_maxY; |
|
346 | return d->m_maxY; | |
347 | } |
|
347 | } | |
348 |
|
348 | |||
349 | /*! |
|
349 | /*! | |
350 | Returns the maximum value of the series on the Z axis. |
|
350 | Returns the maximum value of the series on the Z axis. | |
351 | */ |
|
351 | */ | |
352 | double QColorMapSeries::maxZ() |
|
352 | double QColorMapSeries::maxZ() | |
353 | { |
|
353 | { | |
354 | Q_D(QColorMapSeries); |
|
354 | Q_D(QColorMapSeries); | |
355 | return d->m_maxZ; |
|
355 | return d->m_maxZ; | |
356 | } |
|
356 | } | |
357 |
|
357 | |||
358 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
358 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
359 |
|
359 | |||
360 | QColorMapSeriesPrivate::QColorMapSeriesPrivate(QColorMapSeries *q) |
|
360 | QColorMapSeriesPrivate::QColorMapSeriesPrivate(QColorMapSeries *q) | |
361 | : QAbstractSeriesPrivate(q), |
|
361 | : QAbstractSeriesPrivate(q), | |
362 | m_pen(QChartPrivate::defaultPen()), |
|
362 | m_pen(QChartPrivate::defaultPen()), | |
363 | m_brush(QChartPrivate::defaultBrush()), |
|
363 | m_brush(QChartPrivate::defaultBrush()), | |
364 | m_pointsVisible(false), |
|
364 | m_pointsVisible(false), | |
365 | m_pointLabelsFormat(QLatin1String("@xPoint, @yPoint")), //TODO : change |
|
365 | m_pointLabelsFormat(QLatin1String("@xPoint, @yPoint")), //TODO : change | |
366 | m_pointLabelsVisible(false), |
|
366 | m_pointLabelsVisible(false), | |
367 | m_pointLabelsFont(QChartPrivate::defaultFont()), |
|
367 | m_pointLabelsFont(QChartPrivate::defaultFont()), | |
368 | m_pointLabelsColor(QChartPrivate::defaultPen().color()), |
|
368 | m_pointLabelsColor(QChartPrivate::defaultPen().color()), | |
369 | m_pointLabelsClipping(true) |
|
369 | m_pointLabelsClipping(true) | |
370 | { |
|
370 | { | |
371 | } |
|
371 | } | |
372 |
|
372 | |||
373 | void QColorMapSeriesPrivate::initializeGraphics(QGraphicsItem* parent) |
|
373 | void QColorMapSeriesPrivate::initializeGraphics(QGraphicsItem* parent) | |
374 | { |
|
374 | { | |
375 | Q_Q(QColorMapSeries); |
|
375 | Q_Q(QColorMapSeries); | |
376 | ColorMapChart *colormap = new ColorMapChart(q,parent); |
|
376 | ColorMapChart *colormap = new ColorMapChart(q,parent); | |
377 | m_item.reset(colormap); |
|
377 | m_item.reset(colormap); | |
378 | QAbstractSeriesPrivate::initializeGraphics(parent); |
|
378 | QAbstractSeriesPrivate::initializeGraphics(parent); | |
379 | } |
|
379 | } | |
380 |
|
380 | |||
381 | void QColorMapSeriesPrivate::initializeDomain() |
|
381 | void QColorMapSeriesPrivate::initializeDomain() | |
382 | { |
|
382 | { | |
383 | domain()->setRange(m_minX, m_maxX, m_minY, m_maxY); |
|
383 | domain()->setRange(m_minX, m_maxX, m_minY, m_maxY); | |
384 | } |
|
384 | } | |
385 |
|
385 | |||
386 | void QColorMapSeriesPrivate::initializeTheme(int index, ChartTheme* theme, bool forced) |
|
386 | void QColorMapSeriesPrivate::initializeTheme(int index, ChartTheme* theme, bool forced) | |
387 | { |
|
387 | { | |
388 | // Q_Q(QColorMapSeries); |
|
388 | // Q_Q(QColorMapSeries); | |
389 |
|
389 | |||
390 | // const QList<QGradient> gradients = theme->seriesGradients(); |
|
390 | // const QList<QGradient> gradients = theme->seriesGradients(); | |
391 | // const QList<QColor> colors = theme->seriesColors(); |
|
391 | // const QList<QColor> colors = theme->seriesColors(); | |
392 |
|
392 | |||
393 | // if (forced || QChartPrivate::defaultPen() == m_pen) { |
|
393 | // if (forced || QChartPrivate::defaultPen() == m_pen) { | |
394 | // QPen pen; |
|
394 | // QPen pen; | |
395 | // pen.setColor(ChartThemeManager::colorAt(gradients.at(index % gradients.size()), 0.0)); |
|
395 | // pen.setColor(ChartThemeManager::colorAt(gradients.at(index % gradients.size()), 0.0)); | |
396 | // pen.setWidthF(2); |
|
396 | // pen.setWidthF(2); | |
397 | // q->setPen(pen); |
|
397 | // q->setPen(pen); | |
398 | // } |
|
398 | // } | |
399 |
|
399 | |||
400 | // if (forced || QChartPrivate::defaultBrush() == m_brush) { |
|
400 | // if (forced || QChartPrivate::defaultBrush() == m_brush) { | |
401 | // QBrush brush(colors.at(index % colors.size())); |
|
401 | // QBrush brush(colors.at(index % colors.size())); | |
402 | // q->setBrush(brush); |
|
402 | // q->setBrush(brush); | |
403 | // } |
|
403 | // } | |
404 |
|
404 | |||
405 | // if (forced || QChartPrivate::defaultPen().color() == m_pointLabelsColor) { |
|
405 | // if (forced || QChartPrivate::defaultPen().color() == m_pointLabelsColor) { | |
406 | // QColor color = theme->labelBrush().color(); |
|
406 | // QColor color = theme->labelBrush().color(); | |
407 | // q->setPointLabelsColor(color); |
|
407 | // q->setPointLabelsColor(color); | |
408 | // } |
|
408 | // } | |
409 | } |
|
409 | } | |
410 |
|
410 | |||
411 | QList<QLegendMarker*> QColorMapSeriesPrivate::createLegendMarkers(QLegend* legend) |
|
411 | QList<QLegendMarker*> QColorMapSeriesPrivate::createLegendMarkers(QLegend* legend) | |
412 | { |
|
412 | { | |
413 | Q_Q(QColorMapSeries); |
|
413 | Q_Q(QColorMapSeries); | |
414 | QList<QLegendMarker*> list; |
|
414 | QList<QLegendMarker*> list; | |
415 | return list << new QColorMapLegendMarker(q,legend); |
|
415 | return list << new QColorMapLegendMarker(q,legend); | |
416 | } |
|
416 | } | |
417 |
|
417 | |||
418 | void QColorMapSeriesPrivate::initializeAxes() |
|
418 | void QColorMapSeriesPrivate::initializeAxes() | |
419 | { |
|
419 | { | |
420 |
|
420 | |||
421 | } |
|
421 | } | |
422 |
|
422 | |||
423 | QAbstractAxis::AxisType QColorMapSeriesPrivate::defaultAxisType(Qt::Orientation orientation) const |
|
423 | QAbstractAxis::AxisType QColorMapSeriesPrivate::defaultAxisType(Qt::Orientation orientation) const | |
424 | { |
|
424 | { | |
425 | Q_UNUSED(orientation); |
|
425 | Q_UNUSED(orientation); | |
426 | return QAbstractAxis::AxisTypeValue; |
|
426 | return QAbstractAxis::AxisTypeValue; | |
427 | } |
|
427 | } | |
428 |
|
428 | |||
429 | QAbstractAxis* QColorMapSeriesPrivate::createDefaultAxis(Qt::Orientation orientation) const |
|
429 | QAbstractAxis* QColorMapSeriesPrivate::createDefaultAxis(Qt::Orientation orientation) const | |
430 | { |
|
430 | { | |
431 | Q_UNUSED(orientation); |
|
431 | Q_UNUSED(orientation); | |
432 | return new QValueAxis; |
|
432 | return new QValueAxis; | |
433 | } |
|
433 | } | |
434 |
|
434 | |||
435 |
|
435 | |||
436 |
|
|
436 | QVector<double> *QColorMapSeriesPrivate::getUniformGrid(int xpos, int ypos, int width, int height, QColorMapSeries::Strategy strategy) | |
437 | { |
|
437 | { | |
438 |
|
|
438 | QVector<double> *grid = new QVector<double>(width*height); | |
439 | // QVector<double> *ySeries = new QVector<double>(height); |
|
|||
440 | QVector<double> *dataSeries = new QVector<double>(width*height); |
|
|||
441 | QVector<double> *timeSeries = new QVector<double>(); |
|
|||
442 | QVector<double> *ySeries = new QVector<double>(); |
|
|||
443 | ColorMapDataPart* grid = new ColorMapDataPart(timeSeries,ySeries,dataSeries); |
|
|||
444 |
|
439 | |||
445 | double dx = (m_maxX - m_minX)/(double)width; |
|
440 | double dx = (m_maxX - m_minX)/(double)width; | |
446 | double dy = (m_maxY - m_minY)/(double)height; |
|
441 | double dy = (m_maxY - m_minY)/(double)height; | |
447 |
|
442 | |||
448 | int x=0; |
|
443 | int x=0; | |
449 | int y=0; |
|
444 | int y=0; | |
450 |
|
445 | |||
451 | for(int i=0;i<width;i++) //width-1? |
|
446 | QVector<Point3D> cluster; | |
452 | { |
|
447 | cluster.reserve(height*width/1000); | |
453 | timeSeries->append((double)i); |
|
|||
454 | } |
|
|||
455 |
|
448 | |||
456 |
|
449 | for (auto cell= grid->begin();cell<grid->end();++cell) | ||
457 | for (auto cell= dataSeries->begin();cell<dataSeries->end();++cell) |
|
|||
458 | { |
|
450 | { | |
459 | QVector<Point3D> cluster; |
|
451 | cluster.resize(0); | |
460 | this->buildCluster(x,y,dx,dy,cluster); |
|
452 | this->buildCluster(x,y,dx,dy,cluster); | |
461 | if(strategy == QColorMapSeries::LastPixel) |
|
453 | if(strategy == QColorMapSeries::LastPixel) | |
462 | *cell=this->clusterStrategyLast(cluster); |
|
454 | *cell=this->clusterStrategyLast(cluster); | |
463 | else if(strategy == QColorMapSeries::MeanPixel) |
|
455 | else if(strategy == QColorMapSeries::MeanPixel) | |
464 | *cell=this->clusterStrategyMean(cluster); |
|
456 | *cell=this->clusterStrategyMean(cluster); | |
465 | else if(strategy == QColorMapSeries::MedianPixel) |
|
457 | else if(strategy == QColorMapSeries::MedianPixel) | |
466 | *cell=this->clusterStrategyMedian(cluster); |
|
458 | *cell=this->clusterStrategyMedian(cluster); | |
467 | if(x<width-1) |
|
459 | if(x<width-1) | |
468 | { |
|
460 | { | |
469 | x++; |
|
461 | x++; | |
470 | } |
|
462 | } | |
471 | else |
|
463 | else | |
472 | { |
|
464 | { | |
473 | x=0; |
|
465 | x=0; | |
474 | ySeries->append((double)y); |
|
|||
475 | y++; |
|
466 | y++; | |
476 |
|
||||
477 | } |
|
467 | } | |
478 | } |
|
468 | } | |
|
469 | ||||
479 | return grid; |
|
470 | return grid; | |
480 | } |
|
471 | } | |
481 |
|
472 | |||
482 | /*! |
|
473 | /*! | |
483 | Recompute the data range on X, Y and Z axes each time a ColorMapDataPart is added to the series.\n |
|
474 | Recompute the data range on X, Y and Z axes each time a ColorMapDataPart is added to the series.\n | |
484 | The minimum distance between 2 adjacent values on X and Y axis is added to the maximum on X and Y respectively\n |
|
475 | The minimum distance between 2 adjacent values on X and Y axis is added to the maximum on X and Y respectively\n | |
485 | in order to take account of the width of the last element. |
|
476 | in order to take account of the width of the last element. | |
486 | */ |
|
477 | */ | |
487 | void QColorMapSeriesPrivate::recomputeDataRange() |
|
478 | void QColorMapSeriesPrivate::recomputeDataRange() | |
488 | { |
|
479 | { | |
489 | //TODO : if non empty |
|
480 | //TODO : if non empty | |
490 | m_minX = m_dataParts.first()->timesSeries().first(); |
|
481 | m_minX = m_dataParts.first()->timesSeries().first(); | |
491 | m_maxX = m_dataParts.last()->timesSeries().last(); |
|
482 | m_maxX = m_dataParts.last()->timesSeries().last(); | |
492 |
|
483 | |||
493 | m_minY = m_dataParts.last()->ySeries().last(); |
|
484 | m_minY = m_dataParts.last()->ySeries().last(); | |
494 | m_maxY = m_dataParts.last()->ySeries().first(); |
|
485 | m_maxY = m_dataParts.last()->ySeries().first(); | |
495 | m_minZ = m_dataParts.first()->dataSeries().first(); |
|
486 | m_minZ = m_dataParts.first()->dataSeries().first(); | |
496 | m_maxZ = m_dataParts.last()->dataSeries().last(); |
|
487 | m_maxZ = m_dataParts.last()->dataSeries().last(); | |
497 | double minDeltaX=m_maxX-m_minX; |
|
488 | double minDeltaX=m_maxX-m_minX; | |
498 | double minDeltaY=m_minY-m_maxY; |
|
489 | double minDeltaY=m_minY-m_maxY; | |
499 | foreach(ColorMapDataPart* datapart, m_dataParts) |
|
490 | foreach(ColorMapDataPart* datapart, m_dataParts) | |
500 | { |
|
491 | { | |
501 | m_minY = qMin(datapart->ySeries().first(),m_minY); |
|
492 | m_minY = qMin(datapart->ySeries().first(),m_minY); | |
502 | m_maxY = qMax(datapart->ySeries().last(),m_maxY); |
|
493 | m_maxY = qMax(datapart->ySeries().last(),m_maxY); | |
503 | for(int i=1;i<datapart->timesSeries().size();i++) |
|
494 | for(int i=1;i<datapart->timesSeries().size();i++) | |
504 | { |
|
495 | { | |
505 | double newDeltaX=datapart->timesSeries()[i]-datapart->timesSeries()[i-1]; |
|
496 | double newDeltaX=datapart->timesSeries()[i]-datapart->timesSeries()[i-1]; | |
506 | minDeltaX=qMin(minDeltaX,newDeltaX); |
|
497 | minDeltaX=qMin(minDeltaX,newDeltaX); | |
507 | } |
|
498 | } | |
508 | for(int i=1;i<datapart->ySeries().size();i++) |
|
499 | for(int i=1;i<datapart->ySeries().size();i++) | |
509 | { |
|
500 | { | |
510 | double newDeltaY=datapart->ySeries()[i]-datapart->ySeries()[i-1]; |
|
501 | double newDeltaY=datapart->ySeries()[i]-datapart->ySeries()[i-1]; | |
511 | minDeltaY=qMin(minDeltaY,newDeltaY); |
|
502 | minDeltaY=qMin(minDeltaY,newDeltaY); | |
512 | } |
|
503 | } | |
513 |
|
504 | |||
514 | for (int i = 0; i < datapart->dataSeries().count(); i++) |
|
505 | for (int i = 0; i < datapart->dataSeries().count(); i++) | |
515 | { |
|
506 | { | |
516 | double z = datapart->dataSeries().at(i); |
|
507 | double z = datapart->dataSeries().at(i); | |
517 | m_minZ = qMin(m_minZ, z); |
|
508 | m_minZ = qMin(m_minZ, z); | |
518 | m_maxZ = qMax(m_maxZ, z); |
|
509 | m_maxZ = qMax(m_maxZ, z); | |
519 | } |
|
510 | } | |
520 | } |
|
511 | } | |
521 | m_maxX+=minDeltaX; |
|
512 | m_maxX+=minDeltaX; | |
522 | m_maxY+=minDeltaY; |
|
513 | m_maxY+=minDeltaY; | |
523 | } |
|
514 | } | |
524 |
|
515 | |||
525 | /*! |
|
516 | /*! | |
526 | Returns the last value (bottom right Z value) of a \a cluster of points passed as argument. |
|
517 | Returns the last value (bottom right Z value) of a \a cluster of points passed as argument. | |
527 | */ |
|
518 | */ | |
528 | double QColorMapSeriesPrivate::clusterStrategyLast(QVector<Point3D>& cluster) |
|
519 | double QColorMapSeriesPrivate::clusterStrategyLast(QVector<Point3D>& cluster) | |
529 | { |
|
520 | { | |
530 | if(!cluster.isEmpty()) |
|
521 | if(!cluster.isEmpty()) | |
531 | return cluster.last().value(); |
|
522 | return cluster.last().value(); | |
532 | return 0; |
|
523 | return 0; | |
533 | } |
|
524 | } | |
534 |
|
525 | |||
535 | /*! |
|
526 | /*! | |
536 | Returns the mean value (mean Z value) of a \a cluster of points passed as argument. |
|
527 | Returns the mean value (mean Z value) of a \a cluster of points passed as argument. | |
537 | */ |
|
528 | */ | |
538 | double QColorMapSeriesPrivate::clusterStrategyMean(QVector<Point3D>& cluster) |
|
529 | double QColorMapSeriesPrivate::clusterStrategyMean(QVector<Point3D>& cluster) | |
539 | { |
|
530 | { | |
540 | if(!cluster.isEmpty()) |
|
531 | if(!cluster.isEmpty()) | |
541 | { |
|
532 | { | |
542 | double sum=0; |
|
533 | double sum=0; | |
543 | int count =0; |
|
534 | int count =0; | |
544 | for(int i =0;i<cluster.size();i++) |
|
535 | for(int i =0;i<cluster.size();i++) | |
545 | { |
|
536 | { | |
546 | if(!isnan(Point3D(cluster.at(i)).value())) |
|
537 | if(!isnan(Point3D(cluster.at(i)).value())) | |
547 | { |
|
538 | { | |
548 | sum+= Point3D(cluster.at(i)).value(); |
|
539 | sum+= Point3D(cluster.at(i)).value(); | |
549 | count++; |
|
540 | count++; | |
550 | } |
|
541 | } | |
551 | } |
|
542 | } | |
552 | return (sum/count); |
|
543 | return (sum/count); | |
553 | } |
|
544 | } | |
554 | return 0; |
|
545 | return 0; | |
555 | } |
|
546 | } | |
556 |
|
547 | |||
557 | /*! |
|
548 | /*! | |
558 | Returns the median value (median Z value) of a \a cluster of points passed as argument. |
|
549 | Returns the median value (median Z value) of a \a cluster of points passed as argument. | |
559 | */ |
|
550 | */ | |
560 | double QColorMapSeriesPrivate::clusterStrategyMedian(QVector<Point3D>& cluster) |
|
551 | double QColorMapSeriesPrivate::clusterStrategyMedian(QVector<Point3D>& cluster) | |
561 | { |
|
552 | { | |
562 | if(!cluster.isEmpty()) |
|
553 | if(!cluster.isEmpty()) | |
563 | { |
|
554 | { | |
564 | QVector<double> *copy = new QVector<double>(); |
|
555 | QVector<double> *copy = new QVector<double>(); | |
565 |
|
556 | |||
566 | for(int i =0;i<cluster.size();i++) |
|
557 | for(int i =0;i<cluster.size();i++) | |
567 | { |
|
558 | { | |
568 | if(!isnan(Point3D(cluster.at(i)).value())) |
|
559 | if(!isnan(Point3D(cluster.at(i)).value())) | |
569 | copy->append(Point3D(cluster.at(i)).value()); |
|
560 | copy->append(Point3D(cluster.at(i)).value()); | |
570 | } |
|
561 | } | |
571 |
|
562 | |||
572 | if(!copy->isEmpty()) |
|
563 | if(!copy->isEmpty()) | |
573 | { |
|
564 | { | |
574 | std::sort(copy->begin(), copy->end()); |
|
565 | std::sort(copy->begin(), copy->end()); | |
575 |
|
566 | |||
576 | if(copy->count() & 1) // odd |
|
567 | if(copy->count() & 1) // odd | |
577 | { |
|
568 | { | |
578 | int middle = (copy->count()+1)/2; |
|
569 | int middle = (copy->count()+1)/2; | |
579 | return copy->at(middle-1); |
|
570 | return copy->at(middle-1); | |
580 | } |
|
571 | } | |
581 | else //even |
|
572 | else //even | |
582 | { |
|
573 | { | |
583 | int middle = copy->count()/2; |
|
574 | int middle = copy->count()/2; | |
584 | return (copy->at(middle-1)+copy->at(middle))/2; |
|
575 | return (copy->at(middle-1)+copy->at(middle))/2; | |
585 | } |
|
576 | } | |
586 | } |
|
577 | } | |
587 | } |
|
578 | } | |
588 | return 0; |
|
579 | return 0; | |
589 | } |
|
580 | } | |
590 |
|
581 | |||
591 | /*! |
|
582 | /*! | |
592 | Computes which data points correspond to the given position and returns the in a \a cluster. |
|
583 | Computes which data points correspond to the given position and returns the in a \a cluster. | |
593 | */ |
|
584 | */ | |
594 | void QColorMapSeriesPrivate::buildCluster(int xpos, int ypos, double dx, double dy, QVector<Point3D>& cluster) |
|
585 | void QColorMapSeriesPrivate::buildCluster(int xpos, int ypos, double dx, double dy, QVector<Point3D>& cluster) | |
595 | { |
|
586 | { | |
596 | foreach(ColorMapDataPart *dataPart, m_dataParts) |
|
587 | foreach(ColorMapDataPart *dataPart, m_dataParts) | |
597 | { |
|
588 | { | |
598 | QPair<int,int> xRange = dataPart->getRange(dataPart->timesSeries(),m_minX+xpos*dx,m_minX+(xpos+1)*dx); |
|
589 | QPair<int,int> xRange = dataPart->getRange(dataPart->timesSeries(),m_minX+xpos*dx,m_minX+(xpos+1)*dx); | |
599 | QPair<int,int> yRange = dataPart->getRange(dataPart->ySeries(),m_maxY-(ypos+1)*dy,m_maxY-ypos*dy); |
|
590 | QPair<int,int> yRange = dataPart->getRange(dataPart->ySeries(),m_maxY-(ypos+1)*dy,m_maxY-ypos*dy); | |
600 |
|
591 | |||
|
592 | int timeSeriesSize = dataPart->timesSeries().size(); | |||
|
593 | ||||
601 | if(xRange.first != xRange.second && yRange.first != yRange.second) |
|
594 | if(xRange.first != xRange.second && yRange.first != yRange.second) | |
602 | { |
|
595 | { | |
603 | for(int i =xRange.first+1;i<xRange.second;i++) |
|
596 | for(int i =xRange.first+1;i<xRange.second;i++) | |
604 | { |
|
597 | { | |
605 | qreal xval=dataPart->timesSeries()[i]; |
|
598 | qreal xval=dataPart->timesSeries()[i]; | |
606 | for(int j=yRange.first+1;j<yRange.second;j++) |
|
599 | for(int j=yRange.first+1;j<yRange.second;j++) | |
607 | { |
|
600 | { | |
608 | qreal yval=dataPart->ySeries()[j]; |
|
601 | qreal yval=dataPart->ySeries()[j]; | |
609 |
qreal val=dataPart->dataSeries()[ i + ( |
|
602 | qreal val=dataPart->dataSeries()[ i + (timeSeriesSize * j)]; | |
610 | cluster.append(Point3D(xval,yval,val)); |
|
603 | cluster.append(Point3D(xval,yval,val)); | |
611 | } |
|
604 | } | |
612 | } |
|
605 | } | |
613 | } |
|
606 | } | |
614 | } |
|
607 | } | |
615 | } |
|
608 | } | |
616 |
|
609 | |||
617 |
|
610 | |||
618 | void QColorMapSeriesPrivate::initializeAnimations(QtCharts::QChart::AnimationOptions options, |
|
611 | void QColorMapSeriesPrivate::initializeAnimations(QtCharts::QChart::AnimationOptions options, | |
619 | int duration, QEasingCurve &curve) |
|
612 | int duration, QEasingCurve &curve) | |
620 | { |
|
613 | { | |
621 | // ColorMapChart *item = static_cast<ColorMapChart *>(m_item.data()); |
|
614 | // ColorMapChart *item = static_cast<ColorMapChart *>(m_item.data()); | |
622 | // Q_ASSERT(item); |
|
615 | // Q_ASSERT(item); | |
623 | // if (item->animation()) |
|
616 | // if (item->animation()) | |
624 | // item->animation()->stopAndDestroyLater(); |
|
617 | // item->animation()->stopAndDestroyLater(); | |
625 |
|
618 | |||
626 | // if (options.testFlag(QChart::SeriesAnimations)) |
|
619 | // if (options.testFlag(QChart::SeriesAnimations)) | |
627 | // item->setAnimation(new XYAnimation(item, duration, curve)); |
|
620 | // item->setAnimation(new XYAnimation(item, duration, curve)); | |
628 | // else |
|
621 | // else | |
629 | // item->setAnimation(0); |
|
622 | // item->setAnimation(0); | |
630 | QAbstractSeriesPrivate::initializeAnimations(options, duration, curve); |
|
623 | QAbstractSeriesPrivate::initializeAnimations(options, duration, curve); | |
631 | } |
|
624 | } | |
632 |
|
625 | |||
633 |
|
626 | |||
634 |
|
627 | |||
635 | #include "moc_qcolormapseries.cpp" |
|
628 | #include "moc_qcolormapseries.cpp" | |
636 | #include "moc_qcolormapseries_p.cpp" |
|
629 | #include "moc_qcolormapseries_p.cpp" | |
637 |
|
630 | |||
638 | QT_CHARTS_END_NAMESPACE |
|
631 | QT_CHARTS_END_NAMESPACE |
@@ -1,122 +1,122 | |||||
1 | #ifndef QCOLORMAPSERIES_H |
|
1 | #ifndef QCOLORMAPSERIES_H | |
2 | #define QCOLORMAPSERIES_H |
|
2 | #define QCOLORMAPSERIES_H | |
3 |
|
3 | |||
4 | #include <QtCharts/QChartGlobal> |
|
4 | #include <QtCharts/QChartGlobal> | |
5 | #include <QtCharts/QAbstractSeries> |
|
5 | #include <QtCharts/QAbstractSeries> | |
6 | #include <QtGui/QPen> |
|
6 | #include <QtGui/QPen> | |
7 | #include <QtGui/QBrush> |
|
7 | #include <QtGui/QBrush> | |
8 | #include "colormapdatapart.h" |
|
8 | #include "colormapdatapart.h" | |
9 |
|
9 | |||
10 | QT_CHARTS_BEGIN_NAMESPACE |
|
10 | QT_CHARTS_BEGIN_NAMESPACE | |
11 | class QColorMapSeriesPrivate; |
|
11 | class QColorMapSeriesPrivate; | |
12 |
|
12 | |||
13 |
|
13 | |||
14 | class QT_CHARTS_EXPORT QColorMapSeries : public QAbstractSeries |
|
14 | class QT_CHARTS_EXPORT QColorMapSeries : public QAbstractSeries | |
15 | { |
|
15 | { | |
16 | Q_OBJECT |
|
16 | Q_OBJECT | |
17 | // Q_PROPERTY(bool pointsVisible READ pointsVisible WRITE setPointsVisible) |
|
17 | // Q_PROPERTY(bool pointsVisible READ pointsVisible WRITE setPointsVisible) | |
18 | // Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged) |
|
18 | // Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged) | |
19 | // Q_PROPERTY(QString pointLabelsFormat READ pointLabelsFormat WRITE setPointLabelsFormat NOTIFY pointLabelsFormatChanged) |
|
19 | // Q_PROPERTY(QString pointLabelsFormat READ pointLabelsFormat WRITE setPointLabelsFormat NOTIFY pointLabelsFormatChanged) | |
20 | // Q_PROPERTY(bool pointLabelsVisible READ pointLabelsVisible WRITE setPointLabelsVisible NOTIFY pointLabelsVisibilityChanged) |
|
20 | // Q_PROPERTY(bool pointLabelsVisible READ pointLabelsVisible WRITE setPointLabelsVisible NOTIFY pointLabelsVisibilityChanged) | |
21 | // Q_PROPERTY(QFont pointLabelsFont READ pointLabelsFont WRITE setPointLabelsFont NOTIFY pointLabelsFontChanged) |
|
21 | // Q_PROPERTY(QFont pointLabelsFont READ pointLabelsFont WRITE setPointLabelsFont NOTIFY pointLabelsFontChanged) | |
22 | // Q_PROPERTY(QColor pointLabelsColor READ pointLabelsColor WRITE setPointLabelsColor NOTIFY pointLabelsColorChanged) |
|
22 | // Q_PROPERTY(QColor pointLabelsColor READ pointLabelsColor WRITE setPointLabelsColor NOTIFY pointLabelsColorChanged) | |
23 | // Q_PROPERTY(bool pointLabelsClipping READ pointLabelsClipping WRITE setPointLabelsClipping NOTIFY pointLabelsClippingChanged) |
|
23 | // Q_PROPERTY(bool pointLabelsClipping READ pointLabelsClipping WRITE setPointLabelsClipping NOTIFY pointLabelsClippingChanged) | |
24 |
|
24 | |||
25 | protected: |
|
25 | protected: | |
26 | explicit QColorMapSeries(QColorMapSeriesPrivate &d, QObject *parent =0); |
|
26 | explicit QColorMapSeries(QColorMapSeriesPrivate &d, QObject *parent =0); | |
27 |
|
27 | |||
28 |
|
28 | |||
29 | public : |
|
29 | public : | |
30 |
|
30 | |||
31 | enum Strategy |
|
31 | enum Strategy | |
32 | { |
|
32 | { | |
33 | LastPixel, |
|
33 | LastPixel, | |
34 | MeanPixel, |
|
34 | MeanPixel, | |
35 | MedianPixel |
|
35 | MedianPixel | |
36 | }; |
|
36 | }; | |
37 |
|
37 | |||
38 |
|
38 | |||
39 | explicit QColorMapSeries(QObject *parent =0); |
|
39 | explicit QColorMapSeries(QObject *parent =0); | |
40 | ~QColorMapSeries(); |
|
40 | ~QColorMapSeries(); | |
41 | QAbstractSeries::SeriesType type() const; |
|
41 | QAbstractSeries::SeriesType type() const; | |
42 | void append(ColorMapDataPart* dataPart, bool copy=true); |
|
42 | void append(ColorMapDataPart* dataPart, bool copy=true); | |
43 | void append(const QList<ColorMapDataPart *> &dataParts, bool copy=true); |
|
43 | void append(const QList<ColorMapDataPart *> &dataParts, bool copy=true); | |
44 |
|
44 | |||
45 | int count() const; |
|
45 | int count() const; | |
46 | QVector<ColorMapDataPart*> dataParts() const; |
|
46 | QVector<ColorMapDataPart*> dataParts() const; | |
47 |
|
47 | |||
48 | QColorMapSeries &operator << (const ColorMapDataPart &dataPart); |
|
48 | QColorMapSeries &operator << (const ColorMapDataPart &dataPart); | |
49 | QColorMapSeries &operator << (const QList<ColorMapDataPart *> &dataParts); |
|
49 | QColorMapSeries &operator << (const QList<ColorMapDataPart *> &dataParts); | |
50 |
|
50 | |||
51 |
|
|
51 | QVector<double> *getUniformGrid(int xpos, int ypos,int width, int height, Strategy strategy); | |
52 | //double getUniformGrid(int width, int height, Strategy lambda); |
|
52 | // QVector<double> *getUniformGrid(int width, int height, Strategy lambda); | |
53 |
|
53 | |||
54 | // virtual void attachAxis(QAbstractAxis *axis); |
|
54 | // virtual void attachAxis(QAbstractAxis *axis); | |
55 |
|
55 | |||
56 | virtual void setPen(const QPen &pen); |
|
56 | virtual void setPen(const QPen &pen); | |
57 | QPen pen() const; |
|
57 | QPen pen() const; | |
58 |
|
58 | |||
59 | virtual void setBrush(const QBrush &brush); |
|
59 | virtual void setBrush(const QBrush &brush); | |
60 | QBrush brush() const; |
|
60 | QBrush brush() const; | |
61 |
|
61 | |||
62 | // virtual void setColor(const QColor &color); |
|
62 | // virtual void setColor(const QColor &color); | |
63 | // QColor color() const; |
|
63 | // QColor color() const; | |
64 |
|
64 | |||
65 | // void setPointsVisible(bool visible = true); |
|
65 | // void setPointsVisible(bool visible = true); | |
66 | // bool pointsVisible() const; |
|
66 | // bool pointsVisible() const; | |
67 |
|
67 | |||
68 | // void setPointLabelsFormat(const QString &format); |
|
68 | // void setPointLabelsFormat(const QString &format); | |
69 | // QString pointLabelsFormat() const; |
|
69 | // QString pointLabelsFormat() const; | |
70 |
|
70 | |||
71 | // void setPointLabelsVisible(bool visible = true); |
|
71 | // void setPointLabelsVisible(bool visible = true); | |
72 | // bool pointLabelsVisible() const; |
|
72 | // bool pointLabelsVisible() const; | |
73 |
|
73 | |||
74 | // void setPointLabelsFont(const QFont &font); |
|
74 | // void setPointLabelsFont(const QFont &font); | |
75 | // QFont pointLabelsFont() const; |
|
75 | // QFont pointLabelsFont() const; | |
76 |
|
76 | |||
77 | // void setPointLabelsColor(const QColor &color); |
|
77 | // void setPointLabelsColor(const QColor &color); | |
78 | // QColor pointLabelsColor() const; |
|
78 | // QColor pointLabelsColor() const; | |
79 |
|
79 | |||
80 | // void setPointLabelsClipping(bool enabled = true); |
|
80 | // void setPointLabelsClipping(bool enabled = true); | |
81 | // bool pointLabelsClipping() const; |
|
81 | // bool pointLabelsClipping() const; | |
82 |
|
82 | |||
83 | double minX(); |
|
83 | double minX(); | |
84 | double minY(); |
|
84 | double minY(); | |
85 | double minZ(); |
|
85 | double minZ(); | |
86 | double maxX(); |
|
86 | double maxX(); | |
87 | double maxY(); |
|
87 | double maxY(); | |
88 | double maxZ(); |
|
88 | double maxZ(); | |
89 |
|
89 | |||
90 |
|
90 | |||
91 |
|
91 | |||
92 | Q_SIGNALS: |
|
92 | Q_SIGNALS: | |
93 | // void clicked(const Point3D &point); |
|
93 | // void clicked(const Point3D &point); | |
94 | // void hovered(const Point3D &point, bool state); |
|
94 | // void hovered(const Point3D &point, bool state); | |
95 | // void pressed(const Point3D &point); |
|
95 | // void pressed(const Point3D &point); | |
96 | // void released(const Point3D &point); |
|
96 | // void released(const Point3D &point); | |
97 | // void doubleClicked(const Point3D &point); |
|
97 | // void doubleClicked(const Point3D &point); | |
98 | // void pointReplaced(int index); |
|
98 | // void pointReplaced(int index); | |
99 | // void pointRemoved(int index); |
|
99 | // void pointRemoved(int index); | |
100 | void dataPartAdded(int index); |
|
100 | void dataPartAdded(int index); | |
101 | // void colorChanged(QColor color); |
|
101 | // void colorChanged(QColor color); | |
102 | // void pointsReplaced(); |
|
102 | // void pointsReplaced(); | |
103 | // void pointLabelsFormatChanged(const QString &format); |
|
103 | // void pointLabelsFormatChanged(const QString &format); | |
104 | // void pointLabelsVisibilityChanged(bool visible); |
|
104 | // void pointLabelsVisibilityChanged(bool visible); | |
105 | // void pointLabelsFontChanged(const QFont &font); |
|
105 | // void pointLabelsFontChanged(const QFont &font); | |
106 | // void pointLabelsColorChanged(const QColor &color); |
|
106 | // void pointLabelsColorChanged(const QColor &color); | |
107 | // void pointLabelsClippingChanged(bool clipping); |
|
107 | // void pointLabelsClippingChanged(bool clipping); | |
108 | // void pointsRemoved(int index, int count); |
|
108 | // void pointsRemoved(int index, int count); | |
109 | void penChanged(const QPen &pen); |
|
109 | void penChanged(const QPen &pen); | |
110 |
|
110 | |||
111 | private: |
|
111 | private: | |
112 | Q_DECLARE_PRIVATE(QColorMapSeries) |
|
112 | Q_DECLARE_PRIVATE(QColorMapSeries) | |
113 | Q_DISABLE_COPY(QColorMapSeries) |
|
113 | Q_DISABLE_COPY(QColorMapSeries) | |
114 | friend class ColorMapLegendMarker; |
|
114 | friend class ColorMapLegendMarker; | |
115 | friend class ColorMapChart; |
|
115 | friend class ColorMapChart; | |
116 | friend class QColorMapLegendMarkerPrivate; |
|
116 | friend class QColorMapLegendMarkerPrivate; | |
117 |
|
117 | |||
118 | }; |
|
118 | }; | |
119 |
|
119 | |||
120 | QT_CHARTS_END_NAMESPACE |
|
120 | QT_CHARTS_END_NAMESPACE | |
121 |
|
121 | |||
122 | #endif // QCOLORMAPSERIES_H |
|
122 | #endif // QCOLORMAPSERIES_H |
@@ -1,70 +1,68 | |||||
1 | #ifndef QCOLORMAPSERIES_P_H |
|
1 | #ifndef QCOLORMAPSERIES_P_H | |
2 | #define QCOLORMAPSERIES_P_H |
|
2 | #define QCOLORMAPSERIES_P_H | |
3 |
|
3 | |||
4 | #include <private/qabstractseries_p.h> |
|
4 | #include <private/qabstractseries_p.h> | |
5 | #include "colormapdatapart.h" |
|
5 | #include "colormapdatapart.h" | |
6 | #include <point3d.h> |
|
6 | #include <point3d.h> | |
7 |
|
7 | |||
8 | QT_CHARTS_BEGIN_NAMESPACE |
|
8 | QT_CHARTS_BEGIN_NAMESPACE | |
9 |
|
9 | |||
10 | #include "qcolormapseries.h" |
|
10 | #include "qcolormapseries.h" | |
11 |
|
11 | |||
12 | class QAbstractAxis; |
|
12 | class QAbstractAxis; | |
13 |
|
13 | |||
14 | class QColorMapSeriesPrivate : public QAbstractSeriesPrivate |
|
14 | class QColorMapSeriesPrivate : public QAbstractSeriesPrivate | |
15 | { |
|
15 | { | |
16 | Q_OBJECT |
|
16 | Q_OBJECT | |
17 |
|
17 | |||
18 | public : |
|
18 | public : | |
19 |
|
19 | |||
20 | QColorMapSeriesPrivate(QColorMapSeries *q); |
|
20 | QColorMapSeriesPrivate(QColorMapSeries *q); | |
21 |
|
21 | |||
22 | void initializeDomain(); |
|
22 | void initializeDomain(); | |
23 | void initializeAxes(); |
|
23 | void initializeAxes(); | |
24 | void initializeGraphics(QGraphicsItem* parent); |
|
24 | void initializeGraphics(QGraphicsItem* parent); | |
25 | void initializeTheme(int index, ChartTheme* theme, bool forced = false); |
|
25 | void initializeTheme(int index, ChartTheme* theme, bool forced = false); | |
26 | void initializeAnimations(QChart::AnimationOptions options, int duration, |
|
26 | void initializeAnimations(QChart::AnimationOptions options, int duration, | |
27 | QEasingCurve &curve); |
|
27 | QEasingCurve &curve); | |
28 |
|
28 | |||
29 | QList<QLegendMarker *> createLegendMarkers(QLegend *legend); |
|
29 | QList<QLegendMarker *> createLegendMarkers(QLegend *legend); | |
30 |
|
30 | |||
31 | QAbstractAxis::AxisType defaultAxisType(Qt::Orientation orientation) const; |
|
31 | QAbstractAxis::AxisType defaultAxisType(Qt::Orientation orientation) const; | |
32 | QAbstractAxis* createDefaultAxis(Qt::Orientation) const; |
|
32 | QAbstractAxis* createDefaultAxis(Qt::Orientation) const; | |
33 |
|
33 | |||
34 |
|
|
34 | QVector<double> *getUniformGrid(int xpos, int ypos,int width, int height, QColorMapSeries::Strategy strategy); | |
35 |
|
35 | |||
36 | Q_SIGNALS: |
|
36 | Q_SIGNALS: | |
37 | void updated(); |
|
37 | void updated(); | |
38 |
|
38 | |||
39 | protected: |
|
39 | protected: | |
40 | QList<ColorMapDataPart*> m_dataParts; |
|
40 | QList<ColorMapDataPart*> m_dataParts; | |
41 | QPen m_pen; |
|
41 | QPen m_pen; | |
42 | QBrush m_brush; |
|
42 | QBrush m_brush; | |
43 | bool m_pointsVisible; |
|
43 | bool m_pointsVisible; | |
44 | QString m_pointLabelsFormat; |
|
44 | QString m_pointLabelsFormat; | |
45 | bool m_pointLabelsVisible; |
|
45 | bool m_pointLabelsVisible; | |
46 | QFont m_pointLabelsFont; |
|
46 | QFont m_pointLabelsFont; | |
47 | QColor m_pointLabelsColor; |
|
47 | QColor m_pointLabelsColor; | |
48 | bool m_pointLabelsClipping; |
|
48 | bool m_pointLabelsClipping; | |
49 |
|
49 | |||
50 | private: |
|
50 | private: | |
51 | double m_minX; |
|
51 | double m_minX; | |
52 | double m_maxX; |
|
52 | double m_maxX; | |
53 | double m_minY; |
|
53 | double m_minY; | |
54 | double m_maxY; |
|
54 | double m_maxY; | |
55 | double m_minZ; |
|
55 | double m_minZ; | |
56 | double m_maxZ; |
|
56 | double m_maxZ; | |
57 | void recomputeDataRange(); |
|
57 | void recomputeDataRange(); | |
58 | QPair<int,int> getLastX(double start, double end); |
|
|||
59 | int getLastY(int x,double start, double end); |
|
|||
60 | double clusterStrategyLast(QVector<Point3D>& cluster); |
|
58 | double clusterStrategyLast(QVector<Point3D>& cluster); | |
61 | double clusterStrategyMean(QVector<Point3D> &cluster); |
|
59 | double clusterStrategyMean(QVector<Point3D> &cluster); | |
62 | double clusterStrategyMedian(QVector<Point3D>& cluster); |
|
60 | double clusterStrategyMedian(QVector<Point3D>& cluster); | |
63 | void buildCluster(int xpos,int ypos, double dx,double dy,QVector<Point3D>& cluster); |
|
61 | void buildCluster(int xpos,int ypos, double dx,double dy,QVector<Point3D>& cluster); | |
64 | Q_DECLARE_PUBLIC(QColorMapSeries) |
|
62 | Q_DECLARE_PUBLIC(QColorMapSeries) | |
65 | }; |
|
63 | }; | |
66 |
|
64 | |||
67 | QT_CHARTS_END_NAMESPACE |
|
65 | QT_CHARTS_END_NAMESPACE | |
68 |
|
66 | |||
69 |
|
67 | |||
70 | #endif // QCOLORMAPSERIES_P_H |
|
68 | #endif // QCOLORMAPSERIES_P_H |
General Comments 0
You need to be logged in to leave comments.
Login now