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