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