##// END OF EJS Templates
Fixing review findings in QScatterSeries
Tero Ahola -
r358:543ce926fdb7
parent child
Show More
@@ -7,10 +7,13
7 <img src="images/qt_commercial_logo.png" alt="qtcommercial"/>
7 <img src="images/qt_commercial_logo.png" alt="qtcommercial"/>
8
8
9 <p>
9 <p>
10 QCharts is a part of Qt Commercial addons package. It provides a set of simple chart components which are available for Qt Commercial customers.
10 QCharts is a part of Qt Commercial addons package. It provides a set of easy to use chart
11 It uses Qt Graphics View Framework, therefore charts can be easily integrated 2D modern user interfaces. QCharts can be used as QWidgets, QGraphicsWidget or QML elements.
11 components which are available for Qt Commercial customers. It uses Qt Graphics View
12 Users can easily create impressive graphs by selecting one of the charts themes.
12 Framework, therefore charts can be easily integrated to modern 2D user interfaces. QCharts can
13 be used as QWidgets, QGraphicsWidget or QML elements. Users can easily create impressive
14 graphs by selecting one of the charts themes.
13 </p>
15 </p>
16
14 <table><tr>
17 <table><tr>
15 <td><img src="images/linechart.png" alt="linechart" /></td>
18 <td><img src="images/linechart.png" alt="linechart" /></td>
16 <td><img src="images/chartview_example_bar.jpg " alt="barchart" /></td>
19 <td><img src="images/chartview_example_bar.jpg " alt="barchart" /></td>
@@ -27,14 +27,9 int main(int argc, char *argv[])
27 chartView->addSeries(scatter);
27 chartView->addSeries(scatter);
28 //! [1]
28 //! [1]
29
29
30 // Add some more data
31 //! [2]
32 scatter->addData(QPointF(2.0, 5.5));
33 //! [2]
34
35 // And more
30 // And more
36 //! [3]
31 //! [3]
37 *scatter << QPointF(2.0, 5.5);
32 *scatter << QPointF(2.0, 5.5) << QPointF(2.2, 5.4);
38 //! [3]
33 //! [3]
39
34
40 // Add another scatter series (re-use the previous pointer)
35 // Add another scatter series (re-use the previous pointer)
@@ -46,14 +41,14 int main(int argc, char *argv[])
46 }
41 }
47 //! [4]
42 //! [4]
48 QBrush brush(QColor(255, 0, 0, 100), Qt::SolidPattern);
43 QBrush brush(QColor(255, 0, 0, 100), Qt::SolidPattern);
49 scatter->setMarkerBrush(brush);
44 scatter->setBrush(brush);
50 //! [4]
45 //! [4]
51 //! [5]
46 //! [5]
52 QPen pen(QColor(0, 255, 0, 80), 3);
47 QPen pen(QColor(0, 255, 0, 80), 3);
53 scatter->setMarkerPen(pen);
48 scatter->setPen(pen);
54 //! [5]
49 //! [5]
55 //! [6]
50 //! [6]
56 scatter->setMarkerShape(QScatterSeries::MarkerShapeRectangle);
51 scatter->setShape(QScatterSeries::MarkerShapeRectangle);
57 //! [6]
52 //! [6]
58 chartView->addSeries(scatter);
53 chartView->addSeries(scatter);
59
54
@@ -59,7 +59,7 void DeclarativeScatterSeries::appendData(QDeclarativeListProperty<ScatterElemen
59 if (series) {
59 if (series) {
60 series->m_data.append(element);
60 series->m_data.append(element);
61 if (series->m_series)
61 if (series->m_series)
62 series->m_series->addData(QPointF(element->x(), element->y()));
62 series->m_series->add(element->x(), element->y());
63 }
63 }
64 }
64 }
65
65
@@ -41,16 +41,6
41 */
41 */
42
42
43 /*!
43 /*!
44 \fn void QScatterSeries::hoverEnter()
45 \brief TODO
46 */
47
48 /*!
49 \fn void QScatterSeries::hoverLeave()
50 \brief TODO
51 */
52
53 /*!
54 \fn void QScatterSeries::changed()
44 \fn void QScatterSeries::changed()
55 \brief TODO
45 \brief TODO
56 */
46 */
@@ -86,11 +76,18 QScatterSeries::~QScatterSeries()
86 }
76 }
87
77
88 /*!
78 /*!
79 Add single data point with \a x and \a y coordinates to the series.
80 */
81 void QScatterSeries::add(qreal x, qreal y)
82 {
83 d->m_data.append(QPointF(x, y));
84 emit changed();
85 }
86
87 /*!
89 Add single data point with \a value to the series.
88 Add single data point with \a value to the series.
90 For example:
91 \snippet ../example/scatter/main.cpp 2
92 */
89 */
93 void QScatterSeries::addData(QPointF value)
90 void QScatterSeries::add(QPointF value)
94 {
91 {
95 d->m_data.append(value);
92 d->m_data.append(value);
96 emit changed();
93 emit changed();
@@ -99,7 +96,7 void QScatterSeries::addData(QPointF value)
99 /*!
96 /*!
100 Add list of \a points to the series.
97 Add list of \a points to the series.
101 */
98 */
102 void QScatterSeries::addData(QList<QPointF> points)
99 void QScatterSeries::add(QList<QPointF> points)
103 {
100 {
104 d->m_data.append(points);
101 d->m_data.append(points);
105 emit changed();
102 emit changed();
@@ -107,7 +104,7 void QScatterSeries::addData(QList<QPointF> points)
107
104
108 /*!
105 /*!
109 Stream operator for adding a data point with \a value to the series.
106 Stream operator for adding a data point with \a value to the series.
110 \sa addData()
107 \sa add()
111
108
112 For example:
109 For example:
113 \snippet ../example/scatter/main.cpp 3
110 \snippet ../example/scatter/main.cpp 3
@@ -121,7 +118,7 QScatterSeries& QScatterSeries::operator << (const QPointF &value)
121
118
122 /*!
119 /*!
123 Stream operator for adding a list of points to the series.
120 Stream operator for adding a list of points to the series.
124 \sa addData()
121 \sa add()
125 */
122 */
126 QScatterSeries& QScatterSeries::operator << (QList<QPointF> value)
123 QScatterSeries& QScatterSeries::operator << (QList<QPointF> value)
127 {
124 {
@@ -158,10 +155,10 QList<QPointF> QScatterSeries::data()
158 beatiful markers defined by the chart's theme:
155 beatiful markers defined by the chart's theme:
159 \image scatter_example_pen.jpg
156 \image scatter_example_pen.jpg
160
157
161 \sa setMarkerBrush()
158 \sa setBrush()
162 \sa QChart::setChartTheme()
159 \sa QChart::setChartTheme()
163 */
160 */
164 void QScatterSeries::setMarkerPen(QPen pen)
161 void QScatterSeries::setPen(QPen pen)
165 {
162 {
166 d->m_markerPen = pen;
163 d->m_markerPen = pen;
167 }
164 }
@@ -169,7 +166,7 void QScatterSeries::setMarkerPen(QPen pen)
169 /*!
166 /*!
170 Returns the pen used for drawing markers.
167 Returns the pen used for drawing markers.
171 */
168 */
172 QPen QScatterSeries::markerPen()
169 QPen QScatterSeries::pen()
173 {
170 {
174 return d->m_markerPen;
171 return d->m_markerPen;
175 }
172 }
@@ -184,10 +181,10 QPen QScatterSeries::markerPen()
184 Would fill your scatter markers with an opaque red color:
181 Would fill your scatter markers with an opaque red color:
185 \image scatter_example_brush.jpg
182 \image scatter_example_brush.jpg
186
183
187 \sa setMarkerPen()
184 \sa setPen()
188 \sa QChart::setChartTheme()
185 \sa QChart::setChartTheme()
189 */
186 */
190 void QScatterSeries::setMarkerBrush(QBrush brush)
187 void QScatterSeries::setBrush(QBrush brush)
191 {
188 {
192 d->m_markerBrush = brush;
189 d->m_markerBrush = brush;
193 }
190 }
@@ -195,7 +192,7 void QScatterSeries::setMarkerBrush(QBrush brush)
195 /*!
192 /*!
196 Returns the brush used for drawing markers.
193 Returns the brush used for drawing markers.
197 */
194 */
198 QBrush QScatterSeries::markerBrush()
195 QBrush QScatterSeries::brush()
199 {
196 {
200 return d->m_markerBrush;
197 return d->m_markerBrush;
201 }
198 }
@@ -210,7 +207,7 QBrush QScatterSeries::markerBrush()
210 Would make your scatter marker items rectangle:
207 Would make your scatter marker items rectangle:
211 \image scatter_example_shape.jpg
208 \image scatter_example_shape.jpg
212 */
209 */
213 void QScatterSeries::setMarkerShape(MarkerShape shape)
210 void QScatterSeries::setShape(MarkerShape shape)
214 {
211 {
215 d->m_markerShape = shape;
212 d->m_markerShape = shape;
216 }
213 }
@@ -218,7 +215,7 void QScatterSeries::setMarkerShape(MarkerShape shape)
218 /*!
215 /*!
219 Returns the shape used for drawing markers.
216 Returns the shape used for drawing markers.
220 */
217 */
221 QScatterSeries::MarkerShape QScatterSeries::markerShape()
218 QScatterSeries::MarkerShape QScatterSeries::shape()
222 {
219 {
223 return (QScatterSeries::MarkerShape) d->m_markerShape;
220 return (QScatterSeries::MarkerShape) d->m_markerShape;
224 }
221 }
@@ -33,28 +33,25 public: // from QChartSeries
33 QChartSeriesType type() const { return QChartSeries::SeriesTypeScatter; }
33 QChartSeriesType type() const { return QChartSeries::SeriesTypeScatter; }
34
34
35 public:
35 public:
36 void addData(QPointF value);
36 void add(qreal x, qreal y);
37 void addData(QList<QPointF> points);
37 void add(QPointF value);
38 void add(QList<QPointF> points);
38 void setData(QList<QPointF> points);
39 void setData(QList<QPointF> points);
39 QScatterSeries& operator << (const QPointF &value);
40 QScatterSeries& operator << (const QPointF &value);
40 QScatterSeries& operator << (QList<QPointF> points);
41 QScatterSeries& operator << (QList<QPointF> points);
41 QList<QPointF> data();
42 QList<QPointF> data();
42 //TODO: insertData?
43 //TODO: insert, replace, remove, clear...?
43
44
44 QPen markerPen();
45 QPen pen();
45 QBrush markerBrush();
46 void setPen(QPen pen);
46 MarkerShape markerShape();
47 QBrush brush();
48 void setBrush(QBrush brush);
49 MarkerShape shape();
50 void setShape(MarkerShape shape);
47 // TODO: marker size?
51 // TODO: marker size?
48
52
49 public Q_SLOTS:
50 void setMarkerPen(QPen pen);
51 void setMarkerBrush(QBrush brush);
52 void setMarkerShape(MarkerShape shape);
53
54 Q_SIGNALS:
53 Q_SIGNALS:
55 void clicked(/* TODO: parameters? */);
54 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?
55 // TODO: move to PIMPL for simplicity or does the user ever need changed signals?
59 // TODO: more finegrained signaling for performance reasons
56 // TODO: more finegrained signaling for performance reasons
60 // (check QPieSeries implementation with change sets)
57 // (check QPieSeries implementation with change sets)
@@ -25,6 +25,7 ScatterPresenter::ScatterPresenter(QScatterSeries *series, QGraphicsObject *pare
25
25
26 QGraphicsDropShadowEffect *dropShadow = new QGraphicsDropShadowEffect();
26 QGraphicsDropShadowEffect *dropShadow = new QGraphicsDropShadowEffect();
27 dropShadow->setOffset(2.0);
27 dropShadow->setOffset(2.0);
28 dropShadow->setBlurRadius(2.0);
28 setGraphicsEffect(dropShadow);
29 setGraphicsEffect(dropShadow);
29 }
30 }
30
31
@@ -54,10 +55,10 void ScatterPresenter::paint(QPainter *painter, const QStyleOptionGraphicsItem *
54 // Paint the shape
55 // Paint the shape
55 // The custom settings in series override those defined by the theme
56 // The custom settings in series override those defined by the theme
56 QPen pen = m_markerPen;
57 QPen pen = m_markerPen;
57 if (m_series->markerPen().color().isValid())
58 if (m_series->pen().color().isValid())
58 pen = m_series->markerPen();
59 pen = m_series->pen();
59 if (m_series->markerBrush().color().isValid())
60 if (m_series->brush().color().isValid())
60 painter->setBrush(m_series->markerBrush());
61 painter->setBrush(m_series->brush());
61 else
62 else
62 painter->setBrush(m_markerBrush);
63 painter->setBrush(m_markerBrush);
63 painter->setPen(pen);
64 painter->setPen(pen);
@@ -82,7 +83,7 void ScatterPresenter::changeGeometry()
82 qreal scalex = m_boundingRect.width() / m_visibleChartArea.spanX();
83 qreal scalex = m_boundingRect.width() / m_visibleChartArea.spanX();
83 qreal scaley = m_boundingRect.height() / m_visibleChartArea.spanY();
84 qreal scaley = m_boundingRect.height() / m_visibleChartArea.spanY();
84
85
85 int shape = m_series->markerShape();
86 int shape = m_series->shape();
86 m_path = QPainterPath();
87 m_path = QPainterPath();
87
88
88 foreach (QPointF point, m_series->data()) {
89 foreach (QPointF point, m_series->data()) {
@@ -104,14 +105,8 void ScatterPresenter::changeGeometry()
104 m_path.addRect(x, y, 9, 9);
105 m_path.addRect(x, y, 9, 9);
105 break;
106 break;
106 case QScatterSeries::MarkerShapeTiltedRectangle: {
107 case QScatterSeries::MarkerShapeTiltedRectangle: {
107 // TODO:
108 // TODO: tilt the rectangle
108 // static const QPointF points[4] = {
109 m_path.addRect(x, y, 9, 9);
109 // QPointF(-1.0 + x, 0.0 + y),
110 // QPointF(0.0 + x, 1.0 + y),
111 // QPointF(1.0 + x, 0.0 + y),
112 // QPointF(0.0 + x, -1.0 + y)
113 // };
114 //m_path.addPolygon(QPolygon(4, &points));
115 break;
110 break;
116 }
111 }
117 default:
112 default:
General Comments 0
You need to be logged in to leave comments. Login now