##// END OF EJS Templates
added QXYLegendMarker
sauimone -
r2175:ff7965e6f308
parent child
Show More
@@ -0,0 +1,91
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
14 **
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
18 **
19 ****************************************************************************/
20
21 #include "qxylegendmarker.h"
22 #include "qxylegendmarker_p.h"
23 #include "qxyseries_p.h"
24 #include <QXYSeries>
25 #include <QDebug>
26
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28
29 QXYLegendMarker::QXYLegendMarker(QXYSeries* series, QLegend *legend, QObject *parent) :
30 QLegendMarker(*new QXYLegendMarkerPrivate(this,series,legend), parent)
31 {
32 }
33
34 QXYLegendMarker::~QXYLegendMarker()
35 {
36 // qDebug() << "deleting xy marker" << this;
37 }
38
39 /*!
40 \internal
41 */
42 QXYLegendMarker::QXYLegendMarker(QXYLegendMarkerPrivate &d, QObject *parent) :
43 QLegendMarker(d, parent)
44 {
45 }
46
47 QXYSeries* QXYLegendMarker::series()
48 {
49 Q_D(QXYLegendMarker);
50 return d->m_series;
51 }
52
53 QXYSeries* QXYLegendMarker::peerObject()
54 {
55 Q_D(QXYLegendMarker);
56 return d->m_series;
57 }
58
59 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
60
61 QXYLegendMarkerPrivate::QXYLegendMarkerPrivate(QXYLegendMarker *q, QXYSeries *series, QLegend *legend) :
62 QLegendMarkerPrivate(q,legend),
63 m_series(series)
64 {
65 QObject::connect(m_series, SIGNAL(nameChanged()), this, SLOT(updated()));
66 QObject::connect(m_series->d_func(), SIGNAL(updated()), this, SLOT(updated()));
67 updated();
68 }
69
70 QXYLegendMarkerPrivate::~QXYLegendMarkerPrivate()
71 {
72 QObject::disconnect(m_series->d_func(), SIGNAL(updated()), this, SLOT(updated()));
73 QObject::disconnect(m_series, SIGNAL(nameChanged()), this, SLOT(updated()));
74 }
75
76 void QXYLegendMarkerPrivate::updated()
77 {
78 m_item->setLabel(m_series->name());
79
80 if (m_series->type()== QAbstractSeries::SeriesTypeScatter) {
81 m_item->setBrush(m_series->brush());
82 } else {
83 m_item->setBrush(QBrush(m_series->pen().color()));
84 }
85 }
86
87 #include "moc_qxylegendmarker.cpp"
88 #include "moc_qxylegendmarker_p.cpp"
89
90 QTCOMMERCIALCHART_END_NAMESPACE
91
@@ -0,0 +1,57
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
14 **
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
18 **
19 ****************************************************************************/
20
21 #ifndef QXYLEGENDMARKER_H
22 #define QXYLEGENDMARKER_H
23
24 #include <QChartGlobal>
25 #include <QLegendMarker>
26 #include <QXYSeries>
27
28 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29
30 class QXYLegendMarkerPrivate;
31
32 class QTCOMMERCIALCHART_EXPORT QXYLegendMarker : public QLegendMarker
33 {
34 Q_OBJECT
35 public:
36 explicit QXYLegendMarker(QXYSeries* series, QLegend *legend, QObject *parent = 0);
37 virtual ~QXYLegendMarker();
38
39 virtual QXYSeries* series();
40 virtual QXYSeries* peerObject(); // TODO: rename to slice and remove these virtuals from base class?
41
42 protected:
43 QXYLegendMarker(QXYLegendMarkerPrivate &d, QObject *parent = 0);
44
45 //Q_SIGNALS:
46
47 //public Q_SLOTS:
48
49 private:
50 Q_DECLARE_PRIVATE(QXYLegendMarker)
51 Q_DISABLE_COPY(QXYLegendMarker)
52
53 };
54
55 QTCOMMERCIALCHART_END_NAMESPACE
56
57 #endif // QXYLEGENDMARKER_H
@@ -0,0 +1,65
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
14 **
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
18 **
19 ****************************************************************************/
20
21 // W A R N I N G
22 // -------------
23 //
24 // This file is not part of the QtCommercial Chart API. It exists purely as an
25 // implementation detail. This header file may change from version to
26 // version without notice, or even be removed.
27 //
28 // We mean it.
29
30 #ifndef QXYLEGENDMARKER_P_H
31 #define QXYLEGENDMARKER_P_H
32
33 #include "qchartglobal.h"
34 #include "qlegendmarker_p.h"
35 #include "legendmarkeritem_p.h"
36 #include <QXYSeries>
37
38 #include <QDebug>
39
40 QTCOMMERCIALCHART_BEGIN_NAMESPACE
41
42 class QXYLegendMarker;
43
44 class QXYLegendMarkerPrivate : public QLegendMarkerPrivate
45 {
46 Q_OBJECT
47 public:
48 explicit QXYLegendMarkerPrivate(QXYLegendMarker *q, QXYSeries *series, QLegend *legend);
49 virtual ~QXYLegendMarkerPrivate();
50
51 public Q_SLOTS:
52 virtual void updated();
53
54 private:
55 QXYLegendMarker *q_ptr;
56
57 QXYSeries* m_series;
58
59 friend class QLegendPrivate; // TODO: Is this needed?
60 Q_DECLARE_PUBLIC(QXYLegendMarker)
61 };
62
63 QTCOMMERCIALCHART_END_NAMESPACE
64
65 #endif // QXYLEGENDMARKER_P_H
@@ -1,28 +1,31
1 INCLUDEPATH += $$PWD
1 INCLUDEPATH += $$PWD
2 DEPENDPATH += $$PWD
2 DEPENDPATH += $$PWD
3
3
4 SOURCES += \
4 SOURCES += \
5 $$PWD/qlegend.cpp \
5 $$PWD/qlegend.cpp \
6 $$PWD/legendmarker.cpp \
6 $$PWD/legendmarker.cpp \
7 $$PWD/legendlayout.cpp \
7 $$PWD/legendlayout.cpp \
8 $$PWD/qlegendmarker.cpp \
8 $$PWD/qlegendmarker.cpp \
9 $$PWD/qpielegendmarker.cpp \
9 $$PWD/qpielegendmarker.cpp \
10 $$PWD/legendmarkeritem.cpp \
10 $$PWD/legendmarkeritem.cpp \
11 $$PWD/qbarlegendmarker.cpp
11 $$PWD/qbarlegendmarker.cpp \
12 $$PWD/qxylegendmarker.cpp
12
13
13 PRIVATE_HEADERS += \
14 PRIVATE_HEADERS += \
14 $$PWD/legendmarker_p.h \
15 $$PWD/legendmarker_p.h \
15 $$PWD/legendscroller_p.h \
16 $$PWD/legendscroller_p.h \
16 $$PWD/qlegend_p.h \
17 $$PWD/qlegend_p.h \
17 $$PWD/legendlayout_p.h \
18 $$PWD/legendlayout_p.h \
18 $$PWD/qlegendmarker_p.h \
19 $$PWD/qlegendmarker_p.h \
19 $$PWD/legendmarkeritem_p.h \
20 $$PWD/legendmarkeritem_p.h \
20 $$PWD/qpielegendmarker_p.h \
21 $$PWD/qpielegendmarker_p.h \
21 $$PWD/qbarlegendmarker_p.h
22 $$PWD/qbarlegendmarker_p.h \
23 $$PWD/qxylegendmarker_p.h
22
24
23
25
24 PUBLIC_HEADERS += \
26 PUBLIC_HEADERS += \
25 $$PWD/qlegend.h \
27 $$PWD/qlegend.h \
26 $$PWD/qlegendmarker.h \
28 $$PWD/qlegendmarker.h \
27 $$PWD/qpielegendmarker.h \
29 $$PWD/qpielegendmarker.h \
28 $$PWD/qbarlegendmarker.h
30 $$PWD/qbarlegendmarker.h \
31 $$PWD/qxylegendmarker.h
@@ -1,481 +1,480
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "qxyseries.h"
21 #include "qxyseries.h"
22 #include "qxyseries_p.h"
22 #include "qxyseries_p.h"
23 #include "domain_p.h"
23 #include "domain_p.h"
24 #include "legendmarker_p.h"
24 #include "legendmarker_p.h"
25 #include "qvalueaxis.h"
25 #include "qvalueaxis.h"
26
26
27 #include "qxylegendmarker.h"
28
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28
30
29 /*!
31 /*!
30 \class QXYSeries
32 \class QXYSeries
31 \brief The QXYSeries class is a base class for line, spline and scatter series.
33 \brief The QXYSeries class is a base class for line, spline and scatter series.
32 */
34 */
33 /*!
35 /*!
34 \qmlclass XYSeries
36 \qmlclass XYSeries
35 \inherits AbstractSeries
37 \inherits AbstractSeries
36 The XYSeries class is a base class for line, spline and scatter series.
38 The XYSeries class is a base class for line, spline and scatter series.
37
39
38 The class cannot be instantiated directly.
40 The class cannot be instantiated directly.
39 */
41 */
40
42
41 /*!
43 /*!
42 \property QXYSeries::pointsVisible
44 \property QXYSeries::pointsVisible
43 Controls if the data points are visible and should be drawn.
45 Controls if the data points are visible and should be drawn.
44 */
46 */
45 /*!
47 /*!
46 \qmlproperty bool XYSeries::pointsVisible
48 \qmlproperty bool XYSeries::pointsVisible
47 Controls if the data points are visible and should be drawn.
49 Controls if the data points are visible and should be drawn.
48 */
50 */
49
51
50 /*!
52 /*!
51 \fn QPen QXYSeries::pen() const
53 \fn QPen QXYSeries::pen() const
52 \brief Returns pen used to draw points for series.
54 \brief Returns pen used to draw points for series.
53 \sa setPen()
55 \sa setPen()
54 */
56 */
55
57
56 /*!
58 /*!
57 \fn QBrush QXYSeries::brush() const
59 \fn QBrush QXYSeries::brush() const
58 \brief Returns brush used to draw points for series.
60 \brief Returns brush used to draw points for series.
59 \sa setBrush()
61 \sa setBrush()
60 */
62 */
61
63
62 /*!
64 /*!
63 \property QXYSeries::color
65 \property QXYSeries::color
64 The color of the series. This is line (pen) color in case of QLineSeries or QSplineSeries and
66 The color of the series. This is line (pen) color in case of QLineSeries or QSplineSeries and
65 fill (brush) color in case of QScatterSeries or QAreaSeries.
67 fill (brush) color in case of QScatterSeries or QAreaSeries.
66 \sa QXYSeries::pen(), QXYSeries::brush()
68 \sa QXYSeries::pen(), QXYSeries::brush()
67 */
69 */
68 /*!
70 /*!
69 \qmlproperty color XYSeries::color
71 \qmlproperty color XYSeries::color
70 The color of the series. This is line (pen) color in case of LineSeries or SplineSeries and
72 The color of the series. This is line (pen) color in case of LineSeries or SplineSeries and
71 fill (brush) color in case of ScatterSeries or AreaSeries.
73 fill (brush) color in case of ScatterSeries or AreaSeries.
72 */
74 */
73
75
74 /*!
76 /*!
75 \fn void QXYSeries::clicked(const QPointF& point)
77 \fn void QXYSeries::clicked(const QPointF& point)
76 \brief Signal is emitted when user clicks the \a point on chart.
78 \brief Signal is emitted when user clicks the \a point on chart.
77 */
79 */
78 /*!
80 /*!
79 \qmlsignal XYSeries::onClicked(QPointF point)
81 \qmlsignal XYSeries::onClicked(QPointF point)
80 Signal is emitted when user clicks the \a point on chart. For example:
82 Signal is emitted when user clicks the \a point on chart. For example:
81 \code
83 \code
82 LineSeries {
84 LineSeries {
83 XYPoint { x: 0; y: 0 }
85 XYPoint { x: 0; y: 0 }
84 XYPoint { x: 1.1; y: 2.1 }
86 XYPoint { x: 1.1; y: 2.1 }
85 onClicked: console.log("onClicked: " + point.x + ", " + point.y);
87 onClicked: console.log("onClicked: " + point.x + ", " + point.y);
86 }
88 }
87 \endcode
89 \endcode
88 */
90 */
89
91
90 /*!
92 /*!
91 \fn void QXYSeries::pointReplaced(int index)
93 \fn void QXYSeries::pointReplaced(int index)
92 Signal is emitted when a point has been replaced at \a index.
94 Signal is emitted when a point has been replaced at \a index.
93 \sa replace()
95 \sa replace()
94 */
96 */
95 /*!
97 /*!
96 \qmlsignal XYSeries::onPointReplaced(int index)
98 \qmlsignal XYSeries::onPointReplaced(int index)
97 Signal is emitted when a point has been replaced at \a index.
99 Signal is emitted when a point has been replaced at \a index.
98 */
100 */
99
101
100 /*!
102 /*!
101 \fn void QXYSeries::pointsReplaced()
103 \fn void QXYSeries::pointsReplaced()
102 Signal is emitted when all points have been replaced with another points.
104 Signal is emitted when all points have been replaced with another points.
103 \sa replace()
105 \sa replace()
104 */
106 */
105 /*!
107 /*!
106 \qmlsignal XYSeries::onPointsReplaced()
108 \qmlsignal XYSeries::onPointsReplaced()
107 */
109 */
108
110
109 /*!
111 /*!
110 \fn void QXYSeries::pointAdded(int index)
112 \fn void QXYSeries::pointAdded(int index)
111 Signal is emitted when a point has been added at \a index.
113 Signal is emitted when a point has been added at \a index.
112 \sa append(), insert()
114 \sa append(), insert()
113 */
115 */
114 /*!
116 /*!
115 \qmlsignal XYSeries::onPointAdded(int index)
117 \qmlsignal XYSeries::onPointAdded(int index)
116 Signal is emitted when a point has been added at \a index.
118 Signal is emitted when a point has been added at \a index.
117 */
119 */
118
120
119 /*!
121 /*!
120 \fn void QXYSeries::pointRemoved(int index)
122 \fn void QXYSeries::pointRemoved(int index)
121 Signal is emitted when a point has been removed from \a index.
123 Signal is emitted when a point has been removed from \a index.
122 \sa remove()
124 \sa remove()
123 */
125 */
124 /*!
126 /*!
125 \qmlsignal XYSeries::onPointRemoved(int index)
127 \qmlsignal XYSeries::onPointRemoved(int index)
126 Signal is emitted when a point has been removed from \a index.
128 Signal is emitted when a point has been removed from \a index.
127 */
129 */
128
130
129 /*!
131 /*!
130 \fn void QXYSeries::colorChanged(QColor color)
132 \fn void QXYSeries::colorChanged(QColor color)
131 \brief Signal is emitted when the line (pen) color has changed to \a color.
133 \brief Signal is emitted when the line (pen) color has changed to \a color.
132 */
134 */
133 /*!
135 /*!
134 \qmlsignal XYSeries::onColorChanged(color color)
136 \qmlsignal XYSeries::onColorChanged(color color)
135 Signal is emitted when the line (pen) color has changed to \a color.
137 Signal is emitted when the line (pen) color has changed to \a color.
136 */
138 */
137
139
138 /*!
140 /*!
139 \fn void QXYSeriesPrivate::updated()
141 \fn void QXYSeriesPrivate::updated()
140 \brief \internal
142 \brief \internal
141 */
143 */
142
144
143 /*!
145 /*!
144 \qmlmethod XYSeries::append(real x, real y)
146 \qmlmethod XYSeries::append(real x, real y)
145 Append point (\a x, \a y) to the series
147 Append point (\a x, \a y) to the series
146 */
148 */
147
149
148 /*!
150 /*!
149 \qmlmethod XYSeries::replace(real oldX, real oldY, real newX, real newY)
151 \qmlmethod XYSeries::replace(real oldX, real oldY, real newX, real newY)
150 Replaces point (\a oldX, \a oldY) with point (\a newX, \a newY). Does nothing, if point (oldX, oldY) does not
152 Replaces point (\a oldX, \a oldY) with point (\a newX, \a newY). Does nothing, if point (oldX, oldY) does not
151 exist.
153 exist.
152 */
154 */
153
155
154 /*!
156 /*!
155 \qmlmethod XYSeries::remove(real x, real y)
157 \qmlmethod XYSeries::remove(real x, real y)
156 Removes point (\a x, \a y) from the series. Does nothing, if point (x, y) does not exist.
158 Removes point (\a x, \a y) from the series. Does nothing, if point (x, y) does not exist.
157 */
159 */
158
160
159 /*!
161 /*!
160 \qmlmethod XYSeries::insert(int index, real x, real y)
162 \qmlmethod XYSeries::insert(int index, real x, real y)
161 Inserts point (\a x, \a y) to the \a index. If index is 0 or smaller than 0 the point is prepended to the list of
163 Inserts point (\a x, \a y) to the \a index. If index is 0 or smaller than 0 the point is prepended to the list of
162 points. If index is the same as or bigger than count, the point is appended to the list of points.
164 points. If index is the same as or bigger than count, the point is appended to the list of points.
163 */
165 */
164
166
165 /*!
167 /*!
166 \qmlmethod QPointF XYSeries::at(int index)
168 \qmlmethod QPointF XYSeries::at(int index)
167 Returns point at \a index. Returns (0, 0) if the index is not valid.
169 Returns point at \a index. Returns (0, 0) if the index is not valid.
168 */
170 */
169
171
170 /*!
172 /*!
171 \internal
173 \internal
172
174
173 Constructs empty series object which is a child of \a parent.
175 Constructs empty series object which is a child of \a parent.
174 When series object is added to QChartView or QChart instance ownerships is transferred.
176 When series object is added to QChartView or QChart instance ownerships is transferred.
175 */
177 */
176 QXYSeries::QXYSeries(QXYSeriesPrivate &d, QObject *parent)
178 QXYSeries::QXYSeries(QXYSeriesPrivate &d, QObject *parent)
177 : QAbstractSeries(d, parent)
179 : QAbstractSeries(d, parent)
178 {
180 {
179 }
181 }
180
182
181 /*!
183 /*!
182 Destroys the object. Series added to QChartView or QChart instances are owned by those,
184 Destroys the object. Series added to QChartView or QChart instances are owned by those,
183 and are deleted when mentioned object are destroyed.
185 and are deleted when mentioned object are destroyed.
184 */
186 */
185 QXYSeries::~QXYSeries()
187 QXYSeries::~QXYSeries()
186 {
188 {
187 }
189 }
188
190
189 /*!
191 /*!
190 Adds data point \a x \a y to the series. Points are connected with lines on the chart.
192 Adds data point \a x \a y to the series. Points are connected with lines on the chart.
191 */
193 */
192 void QXYSeries::append(qreal x, qreal y)
194 void QXYSeries::append(qreal x, qreal y)
193 {
195 {
194 append(QPointF(x, y));
196 append(QPointF(x, y));
195 }
197 }
196
198
197 /*!
199 /*!
198 This is an overloaded function.
200 This is an overloaded function.
199 Adds data \a point to the series. Points are connected with lines on the chart.
201 Adds data \a point to the series. Points are connected with lines on the chart.
200 */
202 */
201 void QXYSeries::append(const QPointF &point)
203 void QXYSeries::append(const QPointF &point)
202 {
204 {
203 Q_D(QXYSeries);
205 Q_D(QXYSeries);
204 d->m_points << point;
206 d->m_points << point;
205 emit pointAdded(d->m_points.count() - 1);
207 emit pointAdded(d->m_points.count() - 1);
206 }
208 }
207
209
208 /*!
210 /*!
209 This is an overloaded function.
211 This is an overloaded function.
210 Adds list of data \a points to the series. Points are connected with lines on the chart.
212 Adds list of data \a points to the series. Points are connected with lines on the chart.
211 */
213 */
212 void QXYSeries::append(const QList<QPointF> &points)
214 void QXYSeries::append(const QList<QPointF> &points)
213 {
215 {
214 foreach (const QPointF &point , points)
216 foreach (const QPointF &point , points)
215 append(point);
217 append(point);
216 }
218 }
217
219
218 /*!
220 /*!
219 Replaces data point \a oldX \a oldY with data point \a newX \a newY.
221 Replaces data point \a oldX \a oldY with data point \a newX \a newY.
220 \sa QXYSeries::pointReplaced()
222 \sa QXYSeries::pointReplaced()
221 */
223 */
222 void QXYSeries::replace(qreal oldX, qreal oldY, qreal newX, qreal newY)
224 void QXYSeries::replace(qreal oldX, qreal oldY, qreal newX, qreal newY)
223 {
225 {
224 replace(QPointF(oldX, oldY), QPointF(newX, newY));
226 replace(QPointF(oldX, oldY), QPointF(newX, newY));
225 }
227 }
226
228
227 /*!
229 /*!
228 Replaces \a oldPoint with \a newPoint.
230 Replaces \a oldPoint with \a newPoint.
229 \sa QXYSeries::pointReplaced()
231 \sa QXYSeries::pointReplaced()
230 */
232 */
231 void QXYSeries::replace(const QPointF &oldPoint, const QPointF &newPoint)
233 void QXYSeries::replace(const QPointF &oldPoint, const QPointF &newPoint)
232 {
234 {
233 Q_D(QXYSeries);
235 Q_D(QXYSeries);
234 int index = d->m_points.indexOf(oldPoint);
236 int index = d->m_points.indexOf(oldPoint);
235 if (index == -1)
237 if (index == -1)
236 return;
238 return;
237 d->m_points[index] = newPoint;
239 d->m_points[index] = newPoint;
238 emit pointReplaced(index);
240 emit pointReplaced(index);
239 }
241 }
240
242
241 /*!
243 /*!
242 Replaces the current points with \a points. This is faster than replacing data points one by one,
244 Replaces the current points with \a points. This is faster than replacing data points one by one,
243 or first clearing all data, and then appending the new data. Emits QXYSeries::pointsReplaced()
245 or first clearing all data, and then appending the new data. Emits QXYSeries::pointsReplaced()
244 when the points have been replaced.
246 when the points have been replaced.
245 \sa QXYSeries::pointsReplaced()
247 \sa QXYSeries::pointsReplaced()
246 */
248 */
247 void QXYSeries::replace(QList<QPointF> points)
249 void QXYSeries::replace(QList<QPointF> points)
248 {
250 {
249 Q_D(QXYSeries);
251 Q_D(QXYSeries);
250 d->m_points = points.toVector();
252 d->m_points = points.toVector();
251 emit pointsReplaced();
253 emit pointsReplaced();
252 }
254 }
253
255
254 /*!
256 /*!
255 Removes current \a x and \a y value.
257 Removes current \a x and \a y value.
256 */
258 */
257 void QXYSeries::remove(qreal x, qreal y)
259 void QXYSeries::remove(qreal x, qreal y)
258 {
260 {
259 remove(QPointF(x, y));
261 remove(QPointF(x, y));
260 }
262 }
261
263
262 /*!
264 /*!
263 Removes current \a point x value.
265 Removes current \a point x value.
264
266
265 Note: point y value is ignored.
267 Note: point y value is ignored.
266 */
268 */
267 void QXYSeries::remove(const QPointF &point)
269 void QXYSeries::remove(const QPointF &point)
268 {
270 {
269 Q_D(QXYSeries);
271 Q_D(QXYSeries);
270 int index = d->m_points.indexOf(point);
272 int index = d->m_points.indexOf(point);
271 if (index == -1)
273 if (index == -1)
272 return;
274 return;
273 d->m_points.remove(index);
275 d->m_points.remove(index);
274 emit pointRemoved(index);
276 emit pointRemoved(index);
275 }
277 }
276
278
277 /*!
279 /*!
278 Inserts a \a point in the series at \a index position.
280 Inserts a \a point in the series at \a index position.
279 */
281 */
280 void QXYSeries::insert(int index, const QPointF &point)
282 void QXYSeries::insert(int index, const QPointF &point)
281 {
283 {
282 Q_D(QXYSeries);
284 Q_D(QXYSeries);
283 d->m_points.insert(index, point);
285 d->m_points.insert(index, point);
284 emit pointAdded(index);
286 emit pointAdded(index);
285 }
287 }
286
288
287 /*!
289 /*!
288 Removes all points from the series.
290 Removes all points from the series.
289 */
291 */
290 void QXYSeries::clear()
292 void QXYSeries::clear()
291 {
293 {
292 Q_D(QXYSeries);
294 Q_D(QXYSeries);
293 for (int i = d->m_points.size() - 1; i >= 0; i--)
295 for (int i = d->m_points.size() - 1; i >= 0; i--)
294 remove(d->m_points.at(i));
296 remove(d->m_points.at(i));
295 }
297 }
296
298
297 /*!
299 /*!
298 Returns list of points in the series.
300 Returns list of points in the series.
299 */
301 */
300 QList<QPointF> QXYSeries::points() const
302 QList<QPointF> QXYSeries::points() const
301 {
303 {
302 Q_D(const QXYSeries);
304 Q_D(const QXYSeries);
303 return d->m_points.toList();
305 return d->m_points.toList();
304 }
306 }
305
307
306 /*!
308 /*!
307 Returns number of data points within series.
309 Returns number of data points within series.
308 */
310 */
309 int QXYSeries::count() const
311 int QXYSeries::count() const
310 {
312 {
311 Q_D(const QXYSeries);
313 Q_D(const QXYSeries);
312 return d->m_points.count();
314 return d->m_points.count();
313 }
315 }
314
316
315
317
316 /*!
318 /*!
317 Sets \a pen used for drawing points on the chart. If the pen is not defined, the
319 Sets \a pen used for drawing points on the chart. If the pen is not defined, the
318 pen from chart theme is used.
320 pen from chart theme is used.
319 \sa QChart::setTheme()
321 \sa QChart::setTheme()
320 */
322 */
321 void QXYSeries::setPen(const QPen &pen)
323 void QXYSeries::setPen(const QPen &pen)
322 {
324 {
323 Q_D(QXYSeries);
325 Q_D(QXYSeries);
324 if (d->m_pen != pen) {
326 if (d->m_pen != pen) {
325 bool emitColorChanged = d->m_pen.color() != pen.color();
327 bool emitColorChanged = d->m_pen.color() != pen.color();
326 d->m_pen = pen;
328 d->m_pen = pen;
327 emit d->updated();
329 emit d->updated();
328 if (emitColorChanged)
330 if (emitColorChanged)
329 emit colorChanged(pen.color());
331 emit colorChanged(pen.color());
330 }
332 }
331 }
333 }
332
334
333 QPen QXYSeries::pen() const
335 QPen QXYSeries::pen() const
334 {
336 {
335 Q_D(const QXYSeries);
337 Q_D(const QXYSeries);
336 return d->m_pen;
338 return d->m_pen;
337 }
339 }
338
340
339 /*!
341 /*!
340 Sets \a brush used for drawing points on the chart. If the brush is not defined, brush
342 Sets \a brush used for drawing points on the chart. If the brush is not defined, brush
341 from chart theme setting is used.
343 from chart theme setting is used.
342 \sa QChart::setTheme()
344 \sa QChart::setTheme()
343 */
345 */
344 void QXYSeries::setBrush(const QBrush &brush)
346 void QXYSeries::setBrush(const QBrush &brush)
345 {
347 {
346 Q_D(QXYSeries);
348 Q_D(QXYSeries);
347 if (d->m_brush != brush) {
349 if (d->m_brush != brush) {
348 d->m_brush = brush;
350 d->m_brush = brush;
349 emit d->updated();
351 emit d->updated();
350 }
352 }
351 }
353 }
352
354
353 QBrush QXYSeries::brush() const
355 QBrush QXYSeries::brush() const
354 {
356 {
355 Q_D(const QXYSeries);
357 Q_D(const QXYSeries);
356 return d->m_brush;
358 return d->m_brush;
357 }
359 }
358
360
359 void QXYSeries::setColor(const QColor &color)
361 void QXYSeries::setColor(const QColor &color)
360 {
362 {
361 QPen p = pen();
363 QPen p = pen();
362 if (p.color() != color) {
364 if (p.color() != color) {
363 p.setColor(color);
365 p.setColor(color);
364 setPen(p);
366 setPen(p);
365 }
367 }
366 }
368 }
367
369
368 QColor QXYSeries::color() const
370 QColor QXYSeries::color() const
369 {
371 {
370 return pen().color();
372 return pen().color();
371 }
373 }
372
374
373 void QXYSeries::setPointsVisible(bool visible)
375 void QXYSeries::setPointsVisible(bool visible)
374 {
376 {
375 Q_D(QXYSeries);
377 Q_D(QXYSeries);
376 if (d->m_pointsVisible != visible) {
378 if (d->m_pointsVisible != visible) {
377 d->m_pointsVisible = visible;
379 d->m_pointsVisible = visible;
378 emit d->updated();
380 emit d->updated();
379 }
381 }
380 }
382 }
381
383
382 bool QXYSeries::pointsVisible() const
384 bool QXYSeries::pointsVisible() const
383 {
385 {
384 Q_D(const QXYSeries);
386 Q_D(const QXYSeries);
385 return d->m_pointsVisible;
387 return d->m_pointsVisible;
386 }
388 }
387
389
388
390
389 /*!
391 /*!
390 Stream operator for adding a data \a point to the series.
392 Stream operator for adding a data \a point to the series.
391 \sa append()
393 \sa append()
392 */
394 */
393 QXYSeries &QXYSeries::operator<< (const QPointF &point)
395 QXYSeries &QXYSeries::operator<< (const QPointF &point)
394 {
396 {
395 append(point);
397 append(point);
396 return *this;
398 return *this;
397 }
399 }
398
400
399
401
400 /*!
402 /*!
401 Stream operator for adding a list of \a points to the series.
403 Stream operator for adding a list of \a points to the series.
402 \sa append()
404 \sa append()
403 */
405 */
404
406
405 QXYSeries &QXYSeries::operator<< (const QList<QPointF>& points)
407 QXYSeries &QXYSeries::operator<< (const QList<QPointF>& points)
406 {
408 {
407 append(points);
409 append(points);
408 return *this;
410 return *this;
409 }
411 }
410
412
411 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
413 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
412
414
413
415
414 QXYSeriesPrivate::QXYSeriesPrivate(QXYSeries *q)
416 QXYSeriesPrivate::QXYSeriesPrivate(QXYSeries *q)
415 : QAbstractSeriesPrivate(q),
417 : QAbstractSeriesPrivate(q),
416 m_pointsVisible(false)
418 m_pointsVisible(false)
417 {
419 {
418 }
420 }
419
421
420 void QXYSeriesPrivate::scaleDomain(Domain &domain)
422 void QXYSeriesPrivate::scaleDomain(Domain &domain)
421 {
423 {
422 qreal minX(0);
424 qreal minX(0);
423 qreal minY(0);
425 qreal minY(0);
424 qreal maxX(1);
426 qreal maxX(1);
425 qreal maxY(1);
427 qreal maxY(1);
426
428
427 Q_Q(QXYSeries);
429 Q_Q(QXYSeries);
428
430
429 const QList<QPointF>& points = q->points();
431 const QList<QPointF>& points = q->points();
430
432
431 if (!points.isEmpty()) {
433 if (!points.isEmpty()) {
432 minX = points[0].x();
434 minX = points[0].x();
433 minY = points[0].y();
435 minY = points[0].y();
434 maxX = minX;
436 maxX = minX;
435 maxY = minY;
437 maxY = minY;
436
438
437 for (int i = 0; i < points.count(); i++) {
439 for (int i = 0; i < points.count(); i++) {
438 qreal x = points[i].x();
440 qreal x = points[i].x();
439 qreal y = points[i].y();
441 qreal y = points[i].y();
440 minX = qMin(minX, x);
442 minX = qMin(minX, x);
441 minY = qMin(minY, y);
443 minY = qMin(minY, y);
442 maxX = qMax(maxX, x);
444 maxX = qMax(maxX, x);
443 maxY = qMax(maxY, y);
445 maxY = qMax(maxY, y);
444 }
446 }
445 }
447 }
446
448
447 domain.setRange(minX, maxX, minY, maxY);
449 domain.setRange(minX, maxX, minY, maxY);
448 }
450 }
449
451
450 QList<LegendMarker *> QXYSeriesPrivate::createLegendMarker(QLegend *legend)
452 QList<LegendMarker *> QXYSeriesPrivate::createLegendMarker(QLegend *legend)
451 {
453 {
452 Q_Q(QXYSeries);
454 Q_Q(QXYSeries);
453 QList<LegendMarker *> list;
455 QList<LegendMarker *> list;
454 return list << new XYLegendMarker(q, legend);
456 return list << new XYLegendMarker(q, legend);
455 }
457 }
456
458
457 QList<QLegendMarker*> QXYSeriesPrivate::createLegendMarkers(QLegend* legend)
459 QList<QLegendMarker*> QXYSeriesPrivate::createLegendMarkers(QLegend* legend)
458 {
460 {
459 Q_UNUSED(legend);
461 Q_Q(QXYSeries);
460 // Q_Q(QXYSeries);
461 QList<QLegendMarker*> list;
462 QList<QLegendMarker*> list;
462 // TODO:
463 return list << new QXYLegendMarker(q,legend);
463 // return list << new QXYLegendMarker(q,legend);
464 return list;
465 }
464 }
466
465
467 void QXYSeriesPrivate::initializeAxis(QAbstractAxis *axis)
466 void QXYSeriesPrivate::initializeAxis(QAbstractAxis *axis)
468 {
467 {
469 Q_UNUSED(axis);
468 Q_UNUSED(axis);
470 }
469 }
471
470
472 QAbstractAxis::AxisType QXYSeriesPrivate::defaultAxisType(Qt::Orientation orientation) const
471 QAbstractAxis::AxisType QXYSeriesPrivate::defaultAxisType(Qt::Orientation orientation) const
473 {
472 {
474 Q_UNUSED(orientation);
473 Q_UNUSED(orientation);
475 return QAbstractAxis::AxisTypeValue;
474 return QAbstractAxis::AxisTypeValue;
476 }
475 }
477
476
478 #include "moc_qxyseries.cpp"
477 #include "moc_qxyseries.cpp"
479 #include "moc_qxyseries_p.cpp"
478 #include "moc_qxyseries_p.cpp"
480
479
481 QTCOMMERCIALCHART_END_NAMESPACE
480 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,94 +1,95
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #ifndef QXYSERIES_H
21 #ifndef QXYSERIES_H
22 #define QXYSERIES_H
22 #define QXYSERIES_H
23
23
24 #include <qchartglobal.h>
24 #include <qchartglobal.h>
25 #include <qabstractseries.h>
25 #include <qabstractseries.h>
26 #include <QPen>
26 #include <QPen>
27 #include <QBrush>
27 #include <QBrush>
28
28
29 class QModelIndex;
29 class QModelIndex;
30
30
31 QTCOMMERCIALCHART_BEGIN_NAMESPACE
31 QTCOMMERCIALCHART_BEGIN_NAMESPACE
32
32
33 class QXYSeriesPrivate;
33 class QXYSeriesPrivate;
34 class QXYModelMapper;
34 class QXYModelMapper;
35
35
36 class QTCOMMERCIALCHART_EXPORT QXYSeries : public QAbstractSeries
36 class QTCOMMERCIALCHART_EXPORT QXYSeries : public QAbstractSeries
37 {
37 {
38 Q_OBJECT
38 Q_OBJECT
39 Q_PROPERTY(bool pointsVisible READ pointsVisible WRITE setPointsVisible)
39 Q_PROPERTY(bool pointsVisible READ pointsVisible WRITE setPointsVisible)
40 Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged)
40 Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged)
41
41
42 protected:
42 protected:
43 explicit QXYSeries(QXYSeriesPrivate &d, QObject *parent = 0);
43 explicit QXYSeries(QXYSeriesPrivate &d, QObject *parent = 0);
44
44
45 public:
45 public:
46 ~QXYSeries();
46 ~QXYSeries();
47 void append(qreal x, qreal y);
47 void append(qreal x, qreal y);
48 void append(const QPointF &point);
48 void append(const QPointF &point);
49 void append(const QList<QPointF> &points);
49 void append(const QList<QPointF> &points);
50 void replace(qreal oldX, qreal oldY, qreal newX, qreal newY);
50 void replace(qreal oldX, qreal oldY, qreal newX, qreal newY);
51 void replace(const QPointF &oldPoint, const QPointF &newPoint);
51 void replace(const QPointF &oldPoint, const QPointF &newPoint);
52 void remove(qreal x, qreal y);
52 void remove(qreal x, qreal y);
53 void remove(const QPointF &point);
53 void remove(const QPointF &point);
54 void insert(int index, const QPointF &point);
54 void insert(int index, const QPointF &point);
55 void clear();
55 void clear();
56
56
57 int count() const;
57 int count() const;
58 QList<QPointF> points() const;
58 QList<QPointF> points() const;
59
59
60 QXYSeries &operator << (const QPointF &point);
60 QXYSeries &operator << (const QPointF &point);
61 QXYSeries &operator << (const QList<QPointF> &points);
61 QXYSeries &operator << (const QList<QPointF> &points);
62
62
63 virtual void setPen(const QPen &pen);
63 virtual void setPen(const QPen &pen);
64 QPen pen() const;
64 QPen pen() const;
65
65
66 virtual void setBrush(const QBrush &brush);
66 virtual void setBrush(const QBrush &brush);
67 QBrush brush() const;
67 QBrush brush() const;
68
68
69 virtual void setColor(const QColor &color);
69 virtual void setColor(const QColor &color);
70 virtual QColor color() const;
70 virtual QColor color() const;
71
71
72 void setPointsVisible(bool visible = true);
72 void setPointsVisible(bool visible = true);
73 bool pointsVisible() const;
73 bool pointsVisible() const;
74
74
75 void replace(QList<QPointF> points);
75 void replace(QList<QPointF> points);
76
76
77 Q_SIGNALS:
77 Q_SIGNALS:
78 void clicked(const QPointF &point);
78 void clicked(const QPointF &point);
79 void pointReplaced(int index);
79 void pointReplaced(int index);
80 void pointRemoved(int index);
80 void pointRemoved(int index);
81 void pointAdded(int index);
81 void pointAdded(int index);
82 void colorChanged(QColor color);
82 void colorChanged(QColor color);
83 void pointsReplaced();
83 void pointsReplaced();
84
84
85 private:
85 private:
86 Q_DECLARE_PRIVATE(QXYSeries)
86 Q_DECLARE_PRIVATE(QXYSeries)
87 Q_DISABLE_COPY(QXYSeries)
87 Q_DISABLE_COPY(QXYSeries)
88 friend class QXYLegendMarkerPrivate;
88 friend class XYLegendMarker;
89 friend class XYLegendMarker;
89 friend class XYChart;
90 friend class XYChart;
90 };
91 };
91
92
92 QTCOMMERCIALCHART_END_NAMESPACE
93 QTCOMMERCIALCHART_END_NAMESPACE
93
94
94 #endif // QXYSERIES_H
95 #endif // QXYSERIES_H
General Comments 0
You need to be logged in to leave comments. Login now