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