@@ -10,10 +10,10 int main(int argc, char *argv[]) | |||||
10 | { |
|
10 | { | |
11 | QApplication a(argc, argv); |
|
11 | QApplication a(argc, argv); | |
12 |
|
12 | |||
13 | // Create chart widget |
|
13 | //! [1] | |
|
14 | // Create chart view | |||
14 | QChartView *chartView = new QChartView(); |
|
15 | QChartView *chartView = new QChartView(); | |
15 |
|
16 | |||
16 | //! [1] |
|
|||
17 | // Add scatter series with simple test data |
|
17 | // Add scatter series with simple test data | |
18 | QScatterSeries *scatter = new QScatterSeries(); |
|
18 | QScatterSeries *scatter = new QScatterSeries(); | |
19 | *scatter << QPointF(0.5, 5.0) |
|
19 | *scatter << QPointF(0.5, 5.0) | |
@@ -21,25 +21,40 int main(int argc, char *argv[]) | |||||
21 | << QPointF(1.0, 5.5) |
|
21 | << QPointF(1.0, 5.5) | |
22 | << QPointF(1.5, 5.0) |
|
22 | << QPointF(1.5, 5.0) | |
23 | << QPointF(2.0, 4.5) |
|
23 | << QPointF(2.0, 4.5) | |
24 | << QPointF(2.0, 5.5) |
|
|||
25 | << QPointF(2.5, 5.0); |
|
24 | << QPointF(2.5, 5.0); | |
26 | // Chart takes ownership |
|
25 | // Chart takes ownership | |
27 | chartView->addSeries(scatter); |
|
26 | chartView->addSeries(scatter); | |
28 | //! [1] |
|
27 | //! [1] | |
29 |
|
28 | |||
30 | // Add another scatter series |
|
29 | // Add some more data | |
|
30 | //! [2] | |||
|
31 | scatter->addData(QPointF(2.0, 5.5)); | |||
|
32 | //! [2] | |||
|
33 | ||||
|
34 | // And more | |||
|
35 | //! [3] | |||
|
36 | *scatter << QPointF(2.0, 5.5); | |||
|
37 | //! [3] | |||
|
38 | ||||
|
39 | // Add another scatter series (re-use the previous pointer) | |||
31 | // - more data with random component |
|
40 | // - more data with random component | |
32 |
|
|
41 | scatter = new QScatterSeries(); | |
33 | for (qreal i(0.0); i < 20; i += 0.15) { |
|
42 | for (qreal i(0.0); i < 20; i += 0.15) { | |
34 |
(*scatter |
|
43 | (*scatter) << QPointF(i + (qreal)(rand() % 100) / 100.0, | |
35 | i + (qreal)(rand() % 100) / 100.0); |
|
44 | i + (qreal)(rand() % 100) / 100.0); | |
36 | } |
|
45 | } | |
|
46 | //! [4] | |||
37 | QBrush brush(QColor(255, 0, 0, 100), Qt::SolidPattern); |
|
47 | QBrush brush(QColor(255, 0, 0, 100), Qt::SolidPattern); | |
38 |
scatter |
|
48 | scatter->setMarkerBrush(brush); | |
|
49 | //! [4] | |||
|
50 | //! [5] | |||
39 | QPen pen(QColor(0, 255, 0, 80), 3); |
|
51 | QPen pen(QColor(0, 255, 0, 80), 3); | |
40 |
scatter |
|
52 | scatter->setMarkerPen(pen); | |
41 | scatter2->setMarkerShape(QScatterSeries::MarkerShapeRectangle); |
|
53 | //! [5] | |
42 | chartView->addSeries(scatter2); |
|
54 | //! [6] | |
|
55 | scatter->setMarkerShape(QScatterSeries::MarkerShapeRectangle); | |||
|
56 | //! [6] | |||
|
57 | chartView->addSeries(scatter); | |||
43 |
|
58 | |||
44 | // Use the chart widget as the central widget |
|
59 | // Use the chart widget as the central widget | |
45 | QMainWindow w; |
|
60 | QMainWindow w; |
@@ -2,18 +2,19 | |||||
2 | #include "scatterseries_p.h" |
|
2 | #include "scatterseries_p.h" | |
3 | #include "qchart.h" |
|
3 | #include "qchart.h" | |
4 |
|
4 | |||
5 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
5 | /*! | |
|
6 | \class QScatterSeries | |||
|
7 | \brief QtCommercial Chart series API for showing scatter series. | |||
6 |
|
|
8 | ||
7 | QScatterSeriesPrivate::QScatterSeriesPrivate() : |
|
9 | \mainclass | |
8 | m_data(QList<QPointF>()), |
|
10 | ||
9 | m_markerPen(QPen()), |
|
11 | Example on how to create a chart with scatter series: | |
10 | m_markerBrush(QBrush()), |
|
12 | \snippet ../example/scatter/main.cpp 1 | |
11 | m_markerShape(QScatterSeries::MarkerShapeDefault) |
|
13 | ||
12 | { |
|
14 | The example code would result the following: | |
13 | // Initialize pen color to invalid to use a theme color by default |
|
15 | ||
14 | m_markerPen.setColor(QColor::Invalid); |
|
16 | \image scatter_example1.jpg | |
15 | m_markerBrush.setColor(QColor::Invalid); |
|
17 | */ | |
16 | } |
|
|||
17 |
|
18 | |||
18 | /*! |
|
19 | /*! | |
19 | \enum QScatterSeries::MarkerShape |
|
20 | \enum QScatterSeries::MarkerShape | |
@@ -30,32 +31,44 QScatterSeriesPrivate::QScatterSeriesPrivate() : | |||||
30 | */ |
|
31 | */ | |
31 |
|
32 | |||
32 | /*! |
|
33 | /*! | |
33 | \class QScatterSeries |
|
34 | \fn QChartSeriesType QScatterSeries::type() const | |
34 | \brief QtCommercial Chart series API for showing scatter series. |
|
35 | \brief Returns QChartSeries::SeriesTypeScatter. | |
|
36 | */ | |||
35 |
|
37 | |||
36 | \snippet ../../example/scatter/main.cpp 1 |
|
38 | /*! | |
37 | Example on how to create a chart with scatter series: |
|
39 | \fn void QScatterSeries::clicked() | |
38 | \code |
|
40 | \brief TODO | |
39 | #include <qchartglobal.h> |
|
41 | */ | |
40 | #include <qchartview.h> |
|
|||
41 | #include <qscatterseries.h> |
|
|||
42 | ... |
|
|||
43 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
|||
44 |
|
||||
45 | // Create chart widget |
|
|||
46 | QChartView *chartView = new QChartView(); |
|
|||
47 | QScatterSeries *scatter = new QScatterSeries(); |
|
|||
48 | *scatter << QPointF(0.5, 5.0) << QPointF(1.0, 4.5) << QPointF(1.0, 5.5) << QPointF(1.5, 5.0); |
|
|||
49 | chartView->addSeries(scatter); |
|
|||
50 | // Then add the QChartView into a layout... |
|
|||
51 | \endcode |
|
|||
52 |
|
42 | |||
53 | The example code would result the following: |
|
43 | /*! | |
|
44 | \fn void QScatterSeries::hoverEnter() | |||
|
45 | \brief TODO | |||
|
46 | */ | |||
54 |
|
47 | |||
55 | \image scatter_example1.jpg |
|
48 | /*! | |
|
49 | \fn void QScatterSeries::hoverLeave() | |||
|
50 | \brief TODO | |||
56 | */ |
|
51 | */ | |
57 |
|
52 | |||
58 | /*! |
|
53 | /*! | |
|
54 | \fn void QScatterSeries::changed() | |||
|
55 | \brief TODO | |||
|
56 | */ | |||
|
57 | ||||
|
58 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||
|
59 | ||||
|
60 | QScatterSeriesPrivate::QScatterSeriesPrivate() : | |||
|
61 | m_data(QList<QPointF>()), | |||
|
62 | m_markerPen(QPen()), | |||
|
63 | m_markerBrush(QBrush()), | |||
|
64 | m_markerShape(QScatterSeries::MarkerShapeDefault) | |||
|
65 | { | |||
|
66 | // Initialize pen color to invalid to use a theme color by default | |||
|
67 | m_markerPen.setColor(QColor::Invalid); | |||
|
68 | m_markerBrush.setColor(QColor::Invalid); | |||
|
69 | } | |||
|
70 | ||||
|
71 | /*! | |||
59 | Constructs a series object which is a child of \a parent. |
|
72 | Constructs a series object which is a child of \a parent. | |
60 | */ |
|
73 | */ | |
61 | QScatterSeries::QScatterSeries(QObject *parent) : |
|
74 | QScatterSeries::QScatterSeries(QObject *parent) : | |
@@ -73,11 +86,9 QScatterSeries::~QScatterSeries() | |||||
73 | } |
|
86 | } | |
74 |
|
87 | |||
75 | /*! |
|
88 | /*! | |
76 | Add single data point to the series. |
|
89 | Add single data point with \a value to the series. | |
77 | For example: |
|
90 | For example: | |
78 | \code |
|
91 | \snippet ../example/scatter/main.cpp 2 | |
79 | mySeries.addData(QPointF(0.5, 5.0)); |
|
|||
80 | \endcode |
|
|||
81 | */ |
|
92 | */ | |
82 | void QScatterSeries::addData(QPointF value) |
|
93 | void QScatterSeries::addData(QPointF value) | |
83 | { |
|
94 | { | |
@@ -86,15 +97,20 void QScatterSeries::addData(QPointF value) | |||||
86 | } |
|
97 | } | |
87 |
|
98 | |||
88 | /*! |
|
99 | /*! | |
89 |
|
|
100 | Add list of \a points to the series. | |
90 | \sa addData(), QScatterSeries::addData(QPointF value) |
|
101 | */ | |
|
102 | void QScatterSeries::addData(QList<QPointF> points) | |||
|
103 | { | |||
|
104 | d->m_data.append(data); | |||
|
105 | emit changed(); | |||
|
106 | } | |||
91 |
|
107 | |||
92 | For example: |
|
108 | /*! | |
93 | \code |
|
109 | Stream operator for adding a data point with \a value to the series. | |
94 | mySeries << QPointF(0.5, 5.0) |
|
110 | \sa addData() | |
95 | << QPointF(1.0, 4.5); |
|
|||
96 | \endcode |
|
|||
97 |
|
111 | |||
|
112 | For example: | |||
|
113 | \snippet ../example/scatter/main.cpp 3 | |||
98 | */ |
|
114 | */ | |
99 | QScatterSeries& QScatterSeries::operator << (const QPointF &value) |
|
115 | QScatterSeries& QScatterSeries::operator << (const QPointF &value) | |
100 | { |
|
116 | { | |
@@ -104,9 +120,20 QScatterSeries& QScatterSeries::operator << (const QPointF &value) | |||||
104 | } |
|
120 | } | |
105 |
|
121 | |||
106 | /*! |
|
122 | /*! | |
107 | Replaces the data of the series with the given list of data points. |
|
123 | Stream operator for adding a list of points to the series. | |
|
124 | \sa addData() | |||
|
125 | */ | |||
|
126 | QScatterSeries& QScatterSeries::operator << (QList<QPointF> value) | |||
|
127 | { | |||
|
128 | d->m_data.append(value); | |||
|
129 | emit changed(); | |||
|
130 | return *this; | |||
|
131 | } | |||
|
132 | ||||
|
133 | /*! | |||
|
134 | Replaces the data of the series with the given list of data \a points. | |||
108 | */ |
|
135 | */ | |
109 |
void QScatterSeries::setData(QList<QPointF> |
|
136 | void QScatterSeries::setData(QList<QPointF> points) | |
110 | { |
|
137 | { | |
111 | d->m_data = data; |
|
138 | d->m_data = data; | |
112 | emit changed(); |
|
139 | emit changed(); | |
@@ -121,20 +148,18 QList<QPointF> QScatterSeries::data() | |||||
121 | } |
|
148 | } | |
122 |
|
149 | |||
123 | /*! |
|
150 | /*! | |
124 |
Overrides the default pen used for drawing a marker item with a user defined pen. The |
|
151 | Overrides the default pen used for drawing a marker item with a user defined \a pen. The | |
125 | pen is defined by chart theme setting. |
|
152 | default pen is defined by chart theme setting. | |
126 |
|
153 | |||
127 | For example: |
|
154 | For example: | |
128 | \code |
|
155 | \snippet ../example/scatter/main.cpp 5 | |
129 | QPen pen(QColor(0, 255, 0, 80), 3); |
|
|||
130 | myScatter->setMarkerPen(pen); |
|
|||
131 | \endcode |
|
|||
132 |
|
156 | |||
133 |
Would present your scatter markers with an opaque, uglyish green outlines |
|
157 | Would present your scatter markers with an opaque, uglyish green outlines instead of the | |
|
158 | beatiful markers defined by the chart's theme: | |||
134 | \image scatter_example_pen.jpg |
|
159 | \image scatter_example_pen.jpg | |
135 |
|
160 | |||
136 | \sa setMarkerBrush() |
|
161 | \sa setMarkerBrush() | |
137 | \sa QChart::setTheme() |
|
162 | \sa QChart::setChartTheme() | |
138 | */ |
|
163 | */ | |
139 | void QScatterSeries::setMarkerPen(QPen pen) |
|
164 | void QScatterSeries::setMarkerPen(QPen pen) | |
140 | { |
|
165 | { | |
@@ -150,20 +175,17 QPen QScatterSeries::markerPen() | |||||
150 | } |
|
175 | } | |
151 |
|
176 | |||
152 | /*! |
|
177 | /*! | |
153 | Overrides the default brush of the marker items with a user defined brush. The default |
|
178 | Overrides the default brush of the marker items with a user defined \a brush. The default brush | |
154 |
|
|
179 | is defined by chart theme setting. | |
155 |
|
180 | |||
156 | For example: |
|
181 | For example: | |
157 | \code |
|
182 | \snippet ../example/scatter/main.cpp 4 | |
158 | QBrush brush(QColor(255, 0, 0, 100), Qt::SolidPattern); |
|
|||
159 | myRandomScatter->setMarkerBrush(brush); |
|
|||
160 | \endcode |
|
|||
161 |
|
183 | |||
162 | Would fill your scatter markers with an opaque red color: |
|
184 | Would fill your scatter markers with an opaque red color: | |
163 | \image scatter_example_brush.jpg |
|
185 | \image scatter_example_brush.jpg | |
164 |
|
186 | |||
165 | \sa setMarkerPen() |
|
187 | \sa setMarkerPen() | |
166 | \sa QChart::setTheme() |
|
188 | \sa QChart::setChartTheme() | |
167 | */ |
|
189 | */ | |
168 | void QScatterSeries::setMarkerBrush(QBrush brush) |
|
190 | void QScatterSeries::setMarkerBrush(QBrush brush) | |
169 | { |
|
191 | { | |
@@ -179,13 +201,11 QBrush QScatterSeries::markerBrush() | |||||
179 | } |
|
201 | } | |
180 |
|
202 | |||
181 | /*! |
|
203 | /*! | |
182 | Overrides the default shape of the marker items with a user defined shape. The default |
|
204 | Overrides the default shape of the marker items with a user defined \a shape. The default shape | |
183 |
|
|
205 | is defined by chart theme setting. | |
184 |
|
206 | |||
185 | For example: |
|
207 | For example: | |
186 | \code |
|
208 | \snippet ../example/scatter/main.cpp 6 | |
187 | myScatter->setMarkerShape(QScatterSeries::MarkerShapeRectangle); |
|
|||
188 | \endcode |
|
|||
189 |
|
209 | |||
190 | Would make your scatter marker items rectangle: |
|
210 | Would make your scatter marker items rectangle: | |
191 | \image scatter_example_shape.jpg |
|
211 | \image scatter_example_shape.jpg |
@@ -33,28 +33,33 public: // from QChartSeries | |||||
33 | QChartSeriesType type() const { return QChartSeries::SeriesTypeScatter; } |
|
33 | QChartSeriesType type() const { return QChartSeries::SeriesTypeScatter; } | |
34 |
|
34 | |||
35 | public: |
|
35 | public: | |
36 | // TODO: the name of the function? addPoint? addData? addValue? |
|
|||
37 | void addData(QPointF value); |
|
36 | void addData(QPointF value); | |
|
37 | void addData(QList<QPointF> points); | |||
|
38 | void setData(QList<QPointF> points); | |||
38 | QScatterSeries& operator << (const QPointF &value); |
|
39 | QScatterSeries& operator << (const QPointF &value); | |
39 | void setData(QList<QPointF> data); |
|
40 | QScatterSeries& operator << (QList<QPointF> points); | |
40 | QList<QPointF> data(); |
|
41 | QList<QPointF> data(); | |
41 | //TODO: insertData? |
|
42 | //TODO: insertData? | |
42 |
|
43 | |||
43 | void setMarkerPen(QPen pen); |
|
|||
44 | QPen markerPen(); |
|
44 | QPen markerPen(); | |
45 | void setMarkerBrush(QBrush brush); |
|
|||
46 | QBrush markerBrush(); |
|
45 | QBrush markerBrush(); | |
47 | void setMarkerShape(MarkerShape shape); |
|
|||
48 | MarkerShape markerShape(); |
|
46 | MarkerShape markerShape(); | |
49 | // TODO: marker size? |
|
47 | // TODO: marker size? | |
50 |
|
48 | |||
|
49 | public Q_SLOTS: | |||
|
50 | void setMarkerPen(QPen pen); | |||
|
51 | void setMarkerBrush(QBrush brush); | |||
|
52 | void setMarkerShape(MarkerShape shape); | |||
|
53 | ||||
51 | Q_SIGNALS: |
|
54 | Q_SIGNALS: | |
52 | // TODO: move to PIMPL for simplicity or does the user ever need these signals? |
|
55 | void clicked(/* TODO: parameters? */); | |
|
56 | void hoverEnter(/* TODO: parameters? */); | |||
|
57 | void hoverLeave(/* TODO: parameters? */); | |||
|
58 | // TODO: move to PIMPL for simplicity or does the user ever need changed signals? | |||
53 | // TODO: more finegrained signaling for performance reasons |
|
59 | // TODO: more finegrained signaling for performance reasons | |
54 | // (check QPieSeries implementation with change sets) |
|
60 | // (check QPieSeries implementation with change sets) | |
55 | void changed(); |
|
61 | void changed(); | |
56 |
|
62 | |||
57 | //public Q_SLOTS: |
|
|||
58 | private: |
|
63 | private: | |
59 | Q_DECLARE_PRIVATE(QScatterSeries) |
|
64 | Q_DECLARE_PRIVATE(QScatterSeries) | |
60 | Q_DISABLE_COPY(QScatterSeries) |
|
65 | Q_DISABLE_COPY(QScatterSeries) |
@@ -134,6 +134,11 void ScatterPresenter::paint(QPainter *painter, const QStyleOptionGraphicsItem * | |||||
134 | painter->restore(); |
|
134 | painter->restore(); | |
135 | } |
|
135 | } | |
136 |
|
136 | |||
|
137 | void ScatterPresenter::mousePressEvent(QGraphicsSceneMouseEvent *event) | |||
|
138 | { | |||
|
139 | qDebug() << "ScatterPresenter::mousePressEvent" << event; | |||
|
140 | } | |||
|
141 | ||||
137 | void ScatterPresenter::changeGeometry() |
|
142 | void ScatterPresenter::changeGeometry() | |
138 | { |
|
143 | { | |
139 | if (m_boundingRect.isValid()) { |
|
144 | if (m_boundingRect.isValid()) { |
@@ -23,6 +23,7 public: | |||||
23 | public: // from ChartItem |
|
23 | public: // from ChartItem | |
24 | QRectF boundingRect() const { return m_boundingRect; } |
|
24 | QRectF boundingRect() const { return m_boundingRect; } | |
25 | void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *); |
|
25 | void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *); | |
|
26 | void mousePressEvent (QGraphicsSceneMouseEvent * event); | |||
26 |
|
27 | |||
27 | signals: |
|
28 | signals: | |
28 |
|
29 |
General Comments 0
You need to be logged in to leave comments.
Login now