|
1 | NO CONTENT: new file 100644, binary diff hidden |
|
1 | NO CONTENT: modified file, binary diff hidden |
@@ -13,40 +13,32 int main(int argc, char *argv[]) | |||
|
13 | 13 | //! [1] |
|
14 | 14 | // Create chart view |
|
15 | 15 | QChartView *chartView = new QChartView(); |
|
16 | chartView->setChartTheme(QChart::ChartThemeIcy); | |
|
17 | // Add scatter series with simple test data | |
|
16 | chartView->setRenderHint(QPainter::Antialiasing); | |
|
17 | chartView->setChartTheme(QChart::ChartThemeScientific); | |
|
18 | // Add scatter series with linear test data with random "noise" | |
|
18 | 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 | 25 | // Chart takes ownership |
|
21 | 26 | chartView->addSeries(scatter); |
|
22 | 27 | //! [1] |
|
23 | // scatter->replace(0, QPointF(0.75, 5.0)); | |
|
24 | 28 | |
|
25 | 29 | // And more |
|
26 |
//! [ |
|
|
27 | *scatter << QPointF(2.0, 5.5) << QPointF(2.2, 5.4); | |
|
28 |
//! [ |
|
|
30 | //! [2] | |
|
31 | //*scatter << QPointF(2.0, 5.5) << QPointF(2.2, 5.4); | |
|
32 | //! [2] | |
|
29 | 33 | |
|
30 | // Add another scatter series (re-use the previous pointer because the code used as snippets | |
|
31 | // in the docs) | |
|
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); | |
|
34 | //! [3] | |
|
35 | QBrush brush(QColor(255, 0, 0, 80), Qt::SolidPattern); | |
|
40 | 36 | scatter->setBrush(brush); |
|
41 | //! [4] | |
|
42 | //! [5] | |
|
43 | QPen pen(QColor(0, 255, 0, 80), 3); | |
|
37 | QPen pen(QColor(0, 255, 0, 60), 3); | |
|
44 | 38 | scatter->setPen(pen); |
|
45 | //! [5] | |
|
46 | //! [6] | |
|
47 | 39 | scatter->setShape(QScatterSeries::MarkerShapeRectangle); |
|
48 | //! [6] | |
|
49 | chartView->addSeries(scatter); | |
|
40 | scatter->setSize(15.0); | |
|
41 | //! [3] | |
|
50 | 42 | |
|
51 | 43 | // Use the chart widget as the central widget |
|
52 | 44 | QMainWindow w; |
@@ -14,6 +14,15 | |||
|
14 | 14 | The example code would result the following: |
|
15 | 15 | |
|
16 | 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 | 31 | This enum describes the shape used when rendering marker items. |
|
23 | 32 | |
|
24 | 33 | \value MarkerShapeDefault |
|
25 | \value MarkerShapePoint | |
|
26 | 34 | \value MarkerShapeX |
|
27 | 35 | \value MarkerShapeRectangle |
|
28 | 36 | \value MarkerShapeTiltedRectangle |
@@ -53,7 +61,8 QScatterSeriesPrivate::QScatterSeriesPrivate() : | |||
|
53 | 61 | m_data(QList<QPointF>()), |
|
54 | 62 | m_markerPen(QPen(QColor::Invalid)), |
|
55 | 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 | 115 | \sa add() |
|
107 | 116 | |
|
108 | 117 | For example: |
|
109 |
\snippet ../example/scatter/main.cpp |
|
|
118 | \snippet ../example/scatter/main.cpp 2 | |
|
110 | 119 | */ |
|
111 | 120 | QScatterSeries& QScatterSeries::operator << (const QPointF &value) |
|
112 | 121 | { |
@@ -214,13 +223,6 int QScatterSeries::closestPoint(QPointF coordinate) | |||
|
214 | 223 | Overrides the default pen used for drawing a marker item with a user defined \a pen. The |
|
215 | 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 | 226 | \sa setBrush() |
|
225 | 227 | \sa QChart::setChartTheme() |
|
226 | 228 | */ |
@@ -241,12 +243,6 QPen QScatterSeries::pen() | |||
|
241 | 243 | Overrides the default brush of the marker items with a user defined \a brush. The default brush |
|
242 | 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 | 246 | \sa setPen() |
|
251 | 247 | \sa QChart::setChartTheme() |
|
252 | 248 | */ |
@@ -266,12 +262,6 QBrush QScatterSeries::brush() | |||
|
266 | 262 | /*! |
|
267 | 263 | Overrides the default shape of the marker items with a user defined \a shape. The default shape |
|
268 | 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 | 266 | void QScatterSeries::setShape(MarkerShape shape) |
|
277 | 267 | { |
@@ -286,6 +276,23 QScatterSeries::MarkerShape QScatterSeries::shape() | |||
|
286 | 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 | 296 | #include "moc_qscatterseries.cpp" |
|
290 | 297 | |
|
291 | 298 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -17,7 +17,6 public: | |||
|
17 | 17 | // TODO: to be defined by the graphics design |
|
18 | 18 | // TODO: marker shapes: "x", star, rectangle, tilted rect, triangle, circle, dot |
|
19 | 19 | MarkerShapeDefault = 0, |
|
20 | MarkerShapePoint, | |
|
21 | 20 | MarkerShapeX, |
|
22 | 21 | MarkerShapeRectangle, |
|
23 | 22 | MarkerShapeTiltedRectangle, |
@@ -53,7 +52,8 public: | |||
|
53 | 52 | void setBrush(QBrush brush); |
|
54 | 53 | MarkerShape shape(); |
|
55 | 54 | void setShape(MarkerShape shape); |
|
56 | // TODO: marker size? | |
|
55 | qreal size(); | |
|
56 | void setSize(qreal size); | |
|
57 | 57 | |
|
58 | 58 | Q_SIGNALS: |
|
59 | 59 | void clicked(QPointF coordinate); |
@@ -113,7 +113,7 void ScatterPresenter::changeGeometry() | |||
|
113 | 113 | int shape = m_series->shape(); |
|
114 | 114 | m_path = QPainterPath(); |
|
115 | 115 | m_path.setFillRule(Qt::WindingFill); |
|
116 |
const qreal size( |
|
|
116 | const qreal size = m_series->size(); | |
|
117 | 117 | |
|
118 | 118 | foreach (QPointF point, m_series->data()) { |
|
119 | 119 | // Convert relative coordinates to absolute pixel coordinates that can be used for drawing |
@@ -127,9 +127,6 void ScatterPresenter::changeGeometry() | |||
|
127 | 127 | case QScatterSeries::MarkerShapeCircle: |
|
128 | 128 | m_path.addEllipse(x, y, size, size); |
|
129 | 129 | break; |
|
130 | case QScatterSeries::MarkerShapePoint: | |
|
131 | m_path.addEllipse(x, y, 2, 2); | |
|
132 | break; | |
|
133 | 130 | case QScatterSeries::MarkerShapeRectangle: |
|
134 | 131 | m_path.addRect(x, y, size, size); |
|
135 | 132 | break; |
@@ -20,6 +20,7 public: | |||
|
20 | 20 | QPen m_markerPen; |
|
21 | 21 | QBrush m_markerBrush; |
|
22 | 22 | int m_markerShape; |
|
23 | qreal m_markerSize; | |
|
23 | 24 | }; |
|
24 | 25 | |
|
25 | 26 | QTCOMMERCIALCHART_END_NAMESPACE |
|
1 | NO CONTENT: file was removed, binary diff hidden |
|
1 | NO CONTENT: file was removed, binary diff hidden |
|
1 | NO CONTENT: file was removed, binary diff hidden |
General Comments 0
You need to be logged in to leave comments.
Login now