##// END OF EJS Templates
Added size customization to QScatterSeries
Tero Ahola -
r397:e3d058df67ba
parent child
Show More
1 NO CONTENT: new file 100644, binary diff hidden
NO CONTENT: new file 100644, binary diff hidden
1 NO CONTENT: modified file, binary diff hidden
NO CONTENT: modified file, binary diff hidden
@@ -13,40 +13,32 int main(int argc, char *argv[])
13 //! [1]
13 //! [1]
14 // Create chart view
14 // Create chart view
15 QChartView *chartView = new QChartView();
15 QChartView *chartView = new QChartView();
16 chartView->setChartTheme(QChart::ChartThemeIcy);
16 chartView->setRenderHint(QPainter::Antialiasing);
17 // Add scatter series with simple test data
17 chartView->setChartTheme(QChart::ChartThemeScientific);
18 // Add scatter series with linear test data with random "noise"
18 QScatterSeries *scatter = new QScatterSeries();
19 QScatterSeries *scatter = new QScatterSeries();
19 *scatter << QPointF(0.5, 5.0) << QPointF(1.0, 4.5) << QPointF(1.0, 5.5) << QPointF(1.5, 5.0);
20 for (qreal i(0.0); i < 20; i += 0.25) {
21 qreal x = i + (qreal)(rand() % 100) / 100.0;
22 qreal y = i + (qreal)(rand() % 100) / 100.0;
23 (*scatter) << QPointF(x, y);
24 }
20 // Chart takes ownership
25 // Chart takes ownership
21 chartView->addSeries(scatter);
26 chartView->addSeries(scatter);
22 //! [1]
27 //! [1]
23 // scatter->replace(0, QPointF(0.75, 5.0));
24
28
25 // And more
29 // And more
26 //! [3]
30 //! [2]
27 *scatter << QPointF(2.0, 5.5) << QPointF(2.2, 5.4);
31 //*scatter << QPointF(2.0, 5.5) << QPointF(2.2, 5.4);
28 //! [3]
32 //! [2]
29
33
30 // Add another scatter series (re-use the previous pointer because the code used as snippets
34 //! [3]
31 // in the docs)
35 QBrush brush(QColor(255, 0, 0, 80), Qt::SolidPattern);
32 // - more data with random component
33 scatter = new QScatterSeries();
34 for (qreal i(0.0); i < 20; i += 0.15) {
35 (*scatter) << QPointF(i + (qreal)(rand() % 100) / 100.0,
36 i + (qreal)(rand() % 100) / 100.0);
37 }
38 //! [4]
39 QBrush brush(QColor(255, 0, 0, 100), Qt::SolidPattern);
40 scatter->setBrush(brush);
36 scatter->setBrush(brush);
41 //! [4]
37 QPen pen(QColor(0, 255, 0, 60), 3);
42 //! [5]
43 QPen pen(QColor(0, 255, 0, 80), 3);
44 scatter->setPen(pen);
38 scatter->setPen(pen);
45 //! [5]
46 //! [6]
47 scatter->setShape(QScatterSeries::MarkerShapeRectangle);
39 scatter->setShape(QScatterSeries::MarkerShapeRectangle);
48 //! [6]
40 scatter->setSize(15.0);
49 chartView->addSeries(scatter);
41 //! [3]
50
42
51 // Use the chart widget as the central widget
43 // Use the chart widget as the central widget
52 QMainWindow w;
44 QMainWindow w;
@@ -14,6 +14,15
14 The example code would result the following:
14 The example code would result the following:
15
15
16 \image scatter_example1.jpg
16 \image scatter_example1.jpg
17
18 To customize the graphical representation of the series, you can modify pen, brush, shape and
19 size of the marker items. For example:
20
21 \snippet ../example/scatter/main.cpp 3
22
23 Would present your scatter markers as big rectangles with opaque, uglyish green outlines and
24 opaque red filling instead of the beatiful markers defined by the chart's theme:
25 \image scatter_example_custom.jpg
17 */
26 */
18
27
19 /*!
28 /*!
@@ -22,7 +31,6
22 This enum describes the shape used when rendering marker items.
31 This enum describes the shape used when rendering marker items.
23
32
24 \value MarkerShapeDefault
33 \value MarkerShapeDefault
25 \value MarkerShapePoint
26 \value MarkerShapeX
34 \value MarkerShapeX
27 \value MarkerShapeRectangle
35 \value MarkerShapeRectangle
28 \value MarkerShapeTiltedRectangle
36 \value MarkerShapeTiltedRectangle
@@ -53,7 +61,8 QScatterSeriesPrivate::QScatterSeriesPrivate() :
53 m_data(QList<QPointF>()),
61 m_data(QList<QPointF>()),
54 m_markerPen(QPen(QColor::Invalid)),
62 m_markerPen(QPen(QColor::Invalid)),
55 m_markerBrush(QBrush(QColor::Invalid)),
63 m_markerBrush(QBrush(QColor::Invalid)),
56 m_markerShape(QScatterSeries::MarkerShapeDefault)
64 m_markerShape(QScatterSeries::MarkerShapeDefault),
65 m_markerSize(9.0)
57 {
66 {
58 }
67 }
59
68
@@ -106,7 +115,7 void QScatterSeries::add(QList<QPointF> points)
106 \sa add()
115 \sa add()
107
116
108 For example:
117 For example:
109 \snippet ../example/scatter/main.cpp 3
118 \snippet ../example/scatter/main.cpp 2
110 */
119 */
111 QScatterSeries& QScatterSeries::operator << (const QPointF &value)
120 QScatterSeries& QScatterSeries::operator << (const QPointF &value)
112 {
121 {
@@ -214,13 +223,6 int QScatterSeries::closestPoint(QPointF coordinate)
214 Overrides the default pen used for drawing a marker item with a user defined \a pen. The
223 Overrides the default pen used for drawing a marker item with a user defined \a pen. The
215 default pen is defined by chart theme setting.
224 default pen is defined by chart theme setting.
216
225
217 For example:
218 \snippet ../example/scatter/main.cpp 5
219
220 Would present your scatter markers with an opaque, uglyish green outlines instead of the
221 beatiful markers defined by the chart's theme:
222 \image scatter_example_pen.jpg
223
224 \sa setBrush()
226 \sa setBrush()
225 \sa QChart::setChartTheme()
227 \sa QChart::setChartTheme()
226 */
228 */
@@ -241,12 +243,6 QPen QScatterSeries::pen()
241 Overrides the default brush of the marker items with a user defined \a brush. The default brush
243 Overrides the default brush of the marker items with a user defined \a brush. The default brush
242 is defined by chart theme setting.
244 is defined by chart theme setting.
243
245
244 For example:
245 \snippet ../example/scatter/main.cpp 4
246
247 Would fill your scatter markers with an opaque red color:
248 \image scatter_example_brush.jpg
249
250 \sa setPen()
246 \sa setPen()
251 \sa QChart::setChartTheme()
247 \sa QChart::setChartTheme()
252 */
248 */
@@ -266,12 +262,6 QBrush QScatterSeries::brush()
266 /*!
262 /*!
267 Overrides the default shape of the marker items with a user defined \a shape. The default shape
263 Overrides the default shape of the marker items with a user defined \a shape. The default shape
268 is defined by chart theme setting.
264 is defined by chart theme setting.
269
270 For example:
271 \snippet ../example/scatter/main.cpp 6
272
273 Would make your scatter marker items rectangle:
274 \image scatter_example_shape.jpg
275 */
265 */
276 void QScatterSeries::setShape(MarkerShape shape)
266 void QScatterSeries::setShape(MarkerShape shape)
277 {
267 {
@@ -286,6 +276,23 QScatterSeries::MarkerShape QScatterSeries::shape()
286 return (QScatterSeries::MarkerShape) d->m_markerShape;
276 return (QScatterSeries::MarkerShape) d->m_markerShape;
287 }
277 }
288
278
279 /*!
280 Returns the size of the marker items.
281 */
282 qreal QScatterSeries::size()
283 {
284 return d->m_markerSize;
285 }
286
287 /*!
288 Set the \a size of the marker items. The default size is 9.0.
289 */
290 void QScatterSeries::setSize(qreal size)
291 {
292 d->m_markerSize = size;
293 emit changed();
294 }
295
289 #include "moc_qscatterseries.cpp"
296 #include "moc_qscatterseries.cpp"
290
297
291 QTCOMMERCIALCHART_END_NAMESPACE
298 QTCOMMERCIALCHART_END_NAMESPACE
@@ -17,7 +17,6 public:
17 // TODO: to be defined by the graphics design
17 // TODO: to be defined by the graphics design
18 // TODO: marker shapes: "x", star, rectangle, tilted rect, triangle, circle, dot
18 // TODO: marker shapes: "x", star, rectangle, tilted rect, triangle, circle, dot
19 MarkerShapeDefault = 0,
19 MarkerShapeDefault = 0,
20 MarkerShapePoint,
21 MarkerShapeX,
20 MarkerShapeX,
22 MarkerShapeRectangle,
21 MarkerShapeRectangle,
23 MarkerShapeTiltedRectangle,
22 MarkerShapeTiltedRectangle,
@@ -53,7 +52,8 public:
53 void setBrush(QBrush brush);
52 void setBrush(QBrush brush);
54 MarkerShape shape();
53 MarkerShape shape();
55 void setShape(MarkerShape shape);
54 void setShape(MarkerShape shape);
56 // TODO: marker size?
55 qreal size();
56 void setSize(qreal size);
57
57
58 Q_SIGNALS:
58 Q_SIGNALS:
59 void clicked(QPointF coordinate);
59 void clicked(QPointF coordinate);
@@ -113,7 +113,7 void ScatterPresenter::changeGeometry()
113 int shape = m_series->shape();
113 int shape = m_series->shape();
114 m_path = QPainterPath();
114 m_path = QPainterPath();
115 m_path.setFillRule(Qt::WindingFill);
115 m_path.setFillRule(Qt::WindingFill);
116 const qreal size(9); // TODO: user defined size?
116 const qreal size = m_series->size();
117
117
118 foreach (QPointF point, m_series->data()) {
118 foreach (QPointF point, m_series->data()) {
119 // Convert relative coordinates to absolute pixel coordinates that can be used for drawing
119 // Convert relative coordinates to absolute pixel coordinates that can be used for drawing
@@ -127,9 +127,6 void ScatterPresenter::changeGeometry()
127 case QScatterSeries::MarkerShapeCircle:
127 case QScatterSeries::MarkerShapeCircle:
128 m_path.addEllipse(x, y, size, size);
128 m_path.addEllipse(x, y, size, size);
129 break;
129 break;
130 case QScatterSeries::MarkerShapePoint:
131 m_path.addEllipse(x, y, 2, 2);
132 break;
133 case QScatterSeries::MarkerShapeRectangle:
130 case QScatterSeries::MarkerShapeRectangle:
134 m_path.addRect(x, y, size, size);
131 m_path.addRect(x, y, size, size);
135 break;
132 break;
@@ -20,6 +20,7 public:
20 QPen m_markerPen;
20 QPen m_markerPen;
21 QBrush m_markerBrush;
21 QBrush m_markerBrush;
22 int m_markerShape;
22 int m_markerShape;
23 qreal m_markerSize;
23 };
24 };
24
25
25 QTCOMMERCIALCHART_END_NAMESPACE
26 QTCOMMERCIALCHART_END_NAMESPACE
1 NO CONTENT: file was removed, binary diff hidden
NO CONTENT: file was removed, binary diff hidden
1 NO CONTENT: file was removed, binary diff hidden
NO CONTENT: file was removed, binary diff hidden
1 NO CONTENT: file was removed, binary diff hidden
NO CONTENT: file was removed, binary diff hidden
General Comments 0
You need to be logged in to leave comments. Login now