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