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