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