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