@@ -0,0 +1,61 | |||
|
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 QAREASERIES_P_H_ | |
|
31 | #define QAREASERIES_P_H_ | |
|
32 | ||
|
33 | #include "qseries_p.h" | |
|
34 | ||
|
35 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
|
36 | ||
|
37 | class QAreaSeries; | |
|
38 | ||
|
39 | class QAreaSeriesPrivate: public QSeriesPrivate | |
|
40 | { | |
|
41 | Q_OBJECT | |
|
42 | ||
|
43 | public: | |
|
44 | QAreaSeriesPrivate(QLineSeries *upperSeries, QLineSeries *lowerSeries,QAreaSeries* q); | |
|
45 | ||
|
46 | Q_SIGNALS: | |
|
47 | void updated(); | |
|
48 | ||
|
49 | public: | |
|
50 | QBrush m_brush; | |
|
51 | QPen m_pen; | |
|
52 | QLineSeries* m_upperSeries; | |
|
53 | QLineSeries* m_lowerSeries; | |
|
54 | bool m_pointsVisible; | |
|
55 | ||
|
56 | friend class QAreaSeries; | |
|
57 | }; | |
|
58 | ||
|
59 | QTCOMMERCIALCHART_END_NAMESPACE | |
|
60 | ||
|
61 | #endif |
@@ -0,0 +1,46 | |||
|
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 QLINESERIES_P_H_ | |
|
31 | #define QLINESERIES_P_H_ | |
|
32 | ||
|
33 | #include "qxyseries_p.h" | |
|
34 | ||
|
35 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
|
36 | ||
|
37 | ||
|
38 | struct QLineSeriesPrivate: public QXYSeriesPrivate | |
|
39 | { | |
|
40 | QLineSeriesPrivate(QLineSeries* q); | |
|
41 | ||
|
42 | }; | |
|
43 | ||
|
44 | QTCOMMERCIALCHART_END_NAMESPACE | |
|
45 | ||
|
46 | #endif |
@@ -0,0 +1,50 | |||
|
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 QSERIES_P_H_ | |
|
31 | #define QSERIES_P_H_ | |
|
32 | ||
|
33 | #include "qseries.h" | |
|
34 | ||
|
35 | class QAbstractItemModel; | |
|
36 | ||
|
37 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
|
38 | ||
|
39 | struct QSeriesPrivate : public QObject | |
|
40 | { | |
|
41 | QSeriesPrivate(QSeries *q); | |
|
42 | virtual ~QSeriesPrivate(); | |
|
43 | QSeries *q_ptr; | |
|
44 | QAbstractItemModel* m_model; | |
|
45 | QString m_name; | |
|
46 | }; | |
|
47 | ||
|
48 | QTCOMMERCIALCHART_END_NAMESPACE | |
|
49 | ||
|
50 | #endif |
@@ -0,0 +1,48 | |||
|
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 QSCATTERSERIES_P_H_ | |
|
31 | #define QSCATTERSERIES_P_H_ | |
|
32 | ||
|
33 | #include "qxyseries_p.h" | |
|
34 | ||
|
35 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
|
36 | ||
|
37 | struct QScatterSeriesPrivate: public QXYSeriesPrivate | |
|
38 | { | |
|
39 | QScatterSeriesPrivate(QScatterSeries* q); | |
|
40 | ||
|
41 | QScatterSeries::MarkerShape m_shape; | |
|
42 | qreal m_size; | |
|
43 | ||
|
44 | }; | |
|
45 | ||
|
46 | QTCOMMERCIALCHART_END_NAMESPACE | |
|
47 | ||
|
48 | #endif |
@@ -0,0 +1,56 | |||
|
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 QSPLINESERIES_P_H_ | |
|
31 | #define QSPLINESERIES_P_H_ | |
|
32 | ||
|
33 | #include "qlineseries_p.h" | |
|
34 | ||
|
35 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
|
36 | ||
|
37 | ||
|
38 | class QSplineSeriesPrivate: public QLineSeriesPrivate | |
|
39 | { | |
|
40 | Q_OBJECT | |
|
41 | public: | |
|
42 | QSplineSeriesPrivate(QSplineSeries* q); | |
|
43 | void calculateControlPoints(); | |
|
44 | QList<qreal> getFirstControlPoints(QList<qreal> rhs); | |
|
45 | ||
|
46 | public Q_SLOTS: | |
|
47 | void updateControlPoints(); | |
|
48 | public: | |
|
49 | QList<QPointF> m_controlPoints; | |
|
50 | private: | |
|
51 | Q_DECLARE_PUBLIC(QSplineSeries) | |
|
52 | }; | |
|
53 | ||
|
54 | QTCOMMERCIALCHART_END_NAMESPACE | |
|
55 | ||
|
56 | #endif |
@@ -0,0 +1,73 | |||
|
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 QXYSERIES_P_H_ | |
|
31 | #define QXYSERIES_P_H_ | |
|
32 | ||
|
33 | #include "qseries_p.h" | |
|
34 | ||
|
35 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
|
36 | ||
|
37 | class QXYSeries; | |
|
38 | ||
|
39 | class QXYSeriesPrivate: public QSeriesPrivate | |
|
40 | { | |
|
41 | Q_OBJECT | |
|
42 | ||
|
43 | public: | |
|
44 | QXYSeriesPrivate(QXYSeries* q); | |
|
45 | ||
|
46 | Q_SIGNALS: | |
|
47 | void updated(); | |
|
48 | void pointReplaced(int index); | |
|
49 | void pointRemoved(int index); | |
|
50 | void pointAdded(int index); | |
|
51 | public: | |
|
52 | QVector<qreal> m_x; | |
|
53 | QVector<qreal> m_y; | |
|
54 | ||
|
55 | QPen m_pen; | |
|
56 | QBrush m_brush; | |
|
57 | ||
|
58 | int m_mapX; | |
|
59 | int m_mapY; | |
|
60 | int m_mapFirst; | |
|
61 | int m_mapCount; | |
|
62 | bool m_mapLimited; | |
|
63 | Qt::Orientation m_mapOrientation; | |
|
64 | int tempItemsRemoved; | |
|
65 | bool m_pointsVisible; | |
|
66 | ||
|
67 | friend class QScatterSeries; | |
|
68 | friend class QXYSeries; | |
|
69 | }; | |
|
70 | ||
|
71 | QTCOMMERCIALCHART_END_NAMESPACE | |
|
72 | ||
|
73 | #endif |
@@ -2,13 +2,12 INCLUDEPATH += $$PWD | |||
|
2 | 2 | DEPENDPATH += $$PWD |
|
3 | 3 | |
|
4 | 4 | SOURCES += \ |
|
5 | #$$PWD/areachartanimationitem.cpp \ | |
|
6 | 5 | $$PWD/areachartitem.cpp \ |
|
7 | 6 | $$PWD/qareaseries.cpp |
|
8 | 7 | |
|
9 | 8 | PRIVATE_HEADERS += \ |
|
10 | 9 | $$PWD/areachartitem_p.h \ |
|
11 |
|
|
|
10 | $$PWD/qareaseries_p.h | |
|
12 | 11 | |
|
13 | 12 | PUBLIC_HEADERS += \ |
|
14 | 13 | $$PWD/qareaseries.h No newline at end of file |
@@ -20,6 +20,7 | |||
|
20 | 20 | |
|
21 | 21 | #include "areachartitem_p.h" |
|
22 | 22 | #include "qareaseries.h" |
|
23 | #include "qareaseries_p.h" | |
|
23 | 24 | #include "qlineseries.h" |
|
24 | 25 | #include "chartpresenter_p.h" |
|
25 | 26 | #include <QPainter> |
@@ -42,7 +43,7 AreaChartItem::AreaChartItem(QAreaSeries *areaSeries, ChartPresenter *presenter) | |||
|
42 | 43 | if (m_series->lowerSeries()) |
|
43 | 44 | m_lower = new AreaBoundItem(this,m_series->lowerSeries()); |
|
44 | 45 | |
|
45 |
connect( |
|
|
46 | connect(m_series->d_func(),SIGNAL(updated()),this,SLOT(handleUpdated())); | |
|
46 | 47 | connect(this,SIGNAL(clicked(const QPointF&)),areaSeries,SIGNAL(clicked(const QPointF&))); |
|
47 | 48 | |
|
48 | 49 | handleUpdated(); |
@@ -19,6 +19,7 | |||
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #include "qareaseries.h" |
|
22 | #include "qareaseries_p.h" | |
|
22 | 23 | #include "qlineseries.h" |
|
23 | 24 | |
|
24 | 25 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
@@ -99,10 +100,7 QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||
|
99 | 100 | When series object is added to QChartView or QChart instance ownerships is transfered. |
|
100 | 101 | */ |
|
101 | 102 | QAreaSeries::QAreaSeries(QLineSeries *upperSeries, QLineSeries *lowerSeries) |
|
102 | : QSeries(upperSeries), | |
|
103 | m_upperSeries(upperSeries), | |
|
104 | m_lowerSeries(lowerSeries), | |
|
105 | m_pointsVisible(false) | |
|
103 | : QSeries(*new QAreaSeriesPrivate(upperSeries,lowerSeries,this),upperSeries) | |
|
106 | 104 | { |
|
107 | 105 | } |
|
108 | 106 | |
@@ -114,38 +112,100 QAreaSeries::~QAreaSeries() | |||
|
114 | 112 | { |
|
115 | 113 | } |
|
116 | 114 | |
|
115 | ||
|
116 | QSeries::QSeriesType QAreaSeries::type() const | |
|
117 | { | |
|
118 | return QSeries::SeriesTypeArea; | |
|
119 | } | |
|
120 | ||
|
121 | QLineSeries* QAreaSeries::upperSeries() const | |
|
122 | { | |
|
123 | Q_D(const QAreaSeries); | |
|
124 | return d->m_upperSeries; | |
|
125 | } | |
|
126 | ||
|
127 | QLineSeries* QAreaSeries::lowerSeries() const | |
|
128 | { | |
|
129 | Q_D(const QAreaSeries); | |
|
130 | return d->m_lowerSeries; | |
|
131 | } | |
|
132 | ||
|
117 | 133 | /*! |
|
118 | 134 | Sets \a pen used for drawing area outline. |
|
119 | 135 | */ |
|
120 | 136 | void QAreaSeries::setPen(const QPen &pen) |
|
121 | 137 | { |
|
122 | if (m_pen != pen) { | |
|
123 |
|
|
|
124 | emit updated(); | |
|
138 | Q_D(QAreaSeries); | |
|
139 | if (d->m_pen != pen) { | |
|
140 | d->m_pen = pen; | |
|
141 | emit d->updated(); | |
|
125 | 142 | } |
|
126 | 143 | } |
|
127 | 144 | |
|
145 | QPen QAreaSeries::pen() const | |
|
146 | { | |
|
147 | Q_D(const QAreaSeries); | |
|
148 | return d->m_pen; | |
|
149 | } | |
|
150 | ||
|
128 | 151 | /*! |
|
129 | 152 | Sets \a brush used for filling the area. |
|
130 | 153 | */ |
|
131 | 154 | void QAreaSeries::setBrush(const QBrush &brush) |
|
132 | 155 | { |
|
133 | if (m_brush != brush) { | |
|
134 |
|
|
|
135 | emit updated(); | |
|
156 | Q_D(QAreaSeries); | |
|
157 | if (d->m_brush != brush) { | |
|
158 | d->m_brush = brush; | |
|
159 | emit d->updated(); | |
|
136 | 160 | } |
|
137 | 161 | } |
|
162 | ||
|
163 | QBrush QAreaSeries::brush() const | |
|
164 | { | |
|
165 | Q_D(const QAreaSeries); | |
|
166 | return d->m_brush; | |
|
167 | } | |
|
138 | 168 | /*! |
|
139 | 169 | Sets if data points are \a visible and should be drawn on line. |
|
140 | 170 | */ |
|
141 | 171 | void QAreaSeries::setPointsVisible(bool visible) |
|
142 | 172 | { |
|
143 | if (m_pointsVisible != visible) { | |
|
144 |
|
|
|
145 | emit updated(); | |
|
173 | Q_D(QAreaSeries); | |
|
174 | if (d->m_pointsVisible != visible) { | |
|
175 | d->m_pointsVisible = visible; | |
|
176 | emit d->updated(); | |
|
146 | 177 | } |
|
147 | 178 | } |
|
148 | 179 | |
|
180 | bool QAreaSeries::pointsVisible() const | |
|
181 | { | |
|
182 | Q_D(const QAreaSeries); | |
|
183 | return d->m_pointsVisible; | |
|
184 | } | |
|
185 | ||
|
186 | bool QAreaSeries::setModel(QAbstractItemModel* model) | |
|
187 | { | |
|
188 | Q_UNUSED(model); | |
|
189 | qWarning()<<"Not implemented"; | |
|
190 | return false; | |
|
191 | } | |
|
192 | ||
|
193 | QAbstractItemModel* QAreaSeries::model() const | |
|
194 | { | |
|
195 | return 0; | |
|
196 | } | |
|
197 | ||
|
198 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
|
199 | ||
|
200 | QAreaSeriesPrivate::QAreaSeriesPrivate(QLineSeries *upperSeries, QLineSeries *lowerSeries,QAreaSeries* q):QSeriesPrivate(q), | |
|
201 | m_upperSeries(upperSeries), | |
|
202 | m_lowerSeries(lowerSeries), | |
|
203 | m_pointsVisible(false) | |
|
204 | { | |
|
205 | ||
|
206 | }; | |
|
207 | ||
|
149 | 208 | #include "moc_qareaseries.cpp" |
|
209 | #include "moc_qareaseries_p.cpp" | |
|
150 | 210 | |
|
151 | 211 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -28,6 +28,7 | |||
|
28 | 28 | |
|
29 | 29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
30 | 30 | class QLineSeries; |
|
31 | class QAreaSeriesPrivate; | |
|
31 | 32 | |
|
32 | 33 | class QTCOMMERCIALCHART_EXPORT QAreaSeries : public QSeries |
|
33 | 34 | { |
@@ -36,32 +37,33 public: | |||
|
36 | 37 | QAreaSeries(QLineSeries *upperSeries, QLineSeries *lowerSeries = 0); |
|
37 | 38 | virtual ~QAreaSeries(); |
|
38 | 39 | |
|
39 | public: // from QChartSeries | |
|
40 | virtual QSeriesType type() const { return QSeries::SeriesTypeArea; } | |
|
40 | public: | |
|
41 | QSeries::QSeriesType type() const; | |
|
41 | 42 | |
|
42 |
QLineSeries* upperSeries() const |
|
|
43 |
QLineSeries* lowerSeries() const |
|
|
43 | QLineSeries* upperSeries() const; | |
|
44 | QLineSeries* lowerSeries() const; | |
|
44 | 45 | |
|
45 | 46 | void setPen(const QPen &pen); |
|
46 |
QPen pen() const |
|
|
47 | QPen pen() const; | |
|
47 | 48 | |
|
48 | 49 | void setBrush(const QBrush &brush); |
|
49 |
QBrush brush() const |
|
|
50 | QBrush brush() const; | |
|
50 | 51 | |
|
51 | 52 | void setPointsVisible(bool visible); |
|
52 |
bool pointsVisible() const |
|
|
53 | bool pointsVisible() const; | |
|
54 | ||
|
55 | bool setModel(QAbstractItemModel* model); | |
|
56 | QAbstractItemModel* model() const; | |
|
53 | 57 | |
|
54 | 58 | Q_SIGNALS: |
|
55 | void updated(); | |
|
56 | 59 | void clicked(const QPointF &point); |
|
57 | 60 | void selected(); |
|
58 | 61 | |
|
59 | 62 | private: |
|
60 | QBrush m_brush; | |
|
61 | QPen m_pen; | |
|
62 | QLineSeries* m_upperSeries; | |
|
63 | QLineSeries* m_lowerSeries; | |
|
64 | bool m_pointsVisible; | |
|
63 | Q_DECLARE_PRIVATE(QAreaSeries); | |
|
64 | Q_DISABLE_COPY(QAreaSeries); | |
|
65 | friend class AreaLegendMarker; | |
|
66 | friend class AreaChartItem; | |
|
65 | 67 | }; |
|
66 | 68 | |
|
67 | 69 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -20,8 +20,8 PRIVATE_HEADERS += \ | |||
|
20 | 20 | $$PWD/percentbarchartitem_p.h \ |
|
21 | 21 | $$PWD/stackedbarchartitem_p.h \ |
|
22 | 22 | $$PWD/barlabel_p.h \ |
|
23 |
$$PWD/qbarset |
|
|
24 |
$$PWD/qbarseries |
|
|
23 | $$PWD/qbarset_p.h \ | |
|
24 | $$PWD/qbarseries_p.h | |
|
25 | 25 | |
|
26 | 26 | PUBLIC_HEADERS += \ |
|
27 | 27 | $$PWD/qbarseries.h \ |
This diff has been collapsed as it changes many lines, (641 lines changed) Show them Hide them | |||
@@ -18,324 +18,17 | |||
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | #include <QDebug> | |
|
22 | 21 | #include "qbarseries.h" |
|
22 | #include "qbarseries_p.h" | |
|
23 | 23 | #include "qbarset.h" |
|
24 | #include "qbarset_p.h" | |
|
24 | 25 | #include "barchartmodel_p.h" |
|
25 | #include "qbarseriesprivate_p.h" | |
|
26 | #include "qbarsetprivate_p.h" | |
|
26 | ||
|
27 | 27 | #include <QAbstractItemModel> |
|
28 | 28 | #include <QModelIndex> |
|
29 | 29 | |
|
30 | 30 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
31 | 31 | |
|
32 | QBarSeriesPrivate::QBarSeriesPrivate(QBarCategories categories, QBarSeries *parent) : QObject(parent), | |
|
33 | q_ptr(parent), | |
|
34 | m_internalModel(new BarChartModel(categories,this)) | |
|
35 | { | |
|
36 | m_model = 0; | |
|
37 | m_mapCategories = -1; | |
|
38 | m_mapBarBottom = -1; | |
|
39 | m_mapBarTop = -1; | |
|
40 | m_mapFirst = 0; | |
|
41 | m_mapCount = 0; | |
|
42 | m_mapOrientation = Qt::Vertical; | |
|
43 | } | |
|
44 | ||
|
45 | void QBarSeriesPrivate::appendBarSet(QBarSet *set) | |
|
46 | { | |
|
47 | m_internalModel->appendBarSet(set); | |
|
48 | // connect(set, SIGNAL(clicked(QString,Qt::MouseButtons)), this, SLOT(barsetClicked(QString,Qt::MouseButtons))); | |
|
49 | // connect(set, SIGNAL(valueChanged()), this, SLOT(barsetChanged())); | |
|
50 | emit restructuredBars(); | |
|
51 | } | |
|
52 | ||
|
53 | void QBarSeriesPrivate::removeBarSet(QBarSet *set) | |
|
54 | { | |
|
55 | // disconnect(set, SIGNAL(clicked(QString,Qt::MouseButtons)), this, SLOT(barsetClicked(QString,Qt::MouseButtons))); | |
|
56 | m_internalModel->removeBarSet(set); | |
|
57 | emit restructuredBars(); | |
|
58 | } | |
|
59 | void QBarSeriesPrivate::appendBarSets(QList<QBarSet* > sets) | |
|
60 | { | |
|
61 | foreach (QBarSet* barset, sets) { | |
|
62 | m_internalModel->appendBarSet(barset); | |
|
63 | connect(barset, SIGNAL(clicked(QString,Qt::MouseButtons)), this, SLOT(barsetClicked(QString,Qt::MouseButtons))); | |
|
64 | connect(barset, SIGNAL(valueChanged()), this, SLOT(barsetChanged())); | |
|
65 | } | |
|
66 | emit restructuredBars(); | |
|
67 | } | |
|
68 | ||
|
69 | void QBarSeriesPrivate::removeBarSets(QList<QBarSet* > sets) | |
|
70 | { | |
|
71 | foreach (QBarSet* barset, sets) { | |
|
72 | disconnect(barset, SIGNAL(clicked(QString,Qt::MouseButtons)), this, SLOT(barsetClicked(QString,Qt::MouseButtons))); | |
|
73 | m_internalModel->removeBarSet(barset); | |
|
74 | } | |
|
75 | emit restructuredBars(); | |
|
76 | } | |
|
77 | ||
|
78 | void QBarSeriesPrivate::insertBarSet(int i, QBarSet *set) | |
|
79 | { | |
|
80 | m_internalModel->insertBarSet(i, set); | |
|
81 | // emit barsetChanged(); | |
|
82 | } | |
|
83 | ||
|
84 | void QBarSeriesPrivate::insertCategory(int i, QString category) | |
|
85 | { | |
|
86 | m_internalModel->insertCategory(i, category); | |
|
87 | } | |
|
88 | ||
|
89 | void QBarSeriesPrivate::removeCategory(int i) | |
|
90 | { | |
|
91 | m_internalModel->removeCategory(i); | |
|
92 | } | |
|
93 | ||
|
94 | int QBarSeriesPrivate::barsetCount() const | |
|
95 | { | |
|
96 | // if(m_model) | |
|
97 | // return m_mapBarTop - m_mapBarBottom; | |
|
98 | // else | |
|
99 | return m_internalModel->barsetCount(); | |
|
100 | } | |
|
101 | ||
|
102 | int QBarSeriesPrivate::categoryCount() const | |
|
103 | { | |
|
104 | return m_internalModel->categoryCount(); | |
|
105 | } | |
|
106 | ||
|
107 | QList<QBarSet*> QBarSeriesPrivate::barSets() const | |
|
108 | { | |
|
109 | return m_internalModel->barSets(); | |
|
110 | } | |
|
111 | ||
|
112 | QBarSet* QBarSeriesPrivate::barsetAt(int index) | |
|
113 | { | |
|
114 | return m_internalModel->barsetAt(index); | |
|
115 | } | |
|
116 | ||
|
117 | QString QBarSeriesPrivate::categoryName(int category) | |
|
118 | { | |
|
119 | return m_internalModel->categoryName(category); | |
|
120 | } | |
|
121 | ||
|
122 | void QBarSeriesPrivate::setToolTipEnabled(bool enabled) | |
|
123 | { | |
|
124 | // TODO: what if we add sets after call to this function? Those sets won't have tooltip enabled. | |
|
125 | if (enabled) { | |
|
126 | for (int i=0; i<m_internalModel->barsetCount(); i++) { | |
|
127 | QBarSet *set = m_internalModel->barsetAt(i); | |
|
128 | connect(set, SIGNAL(showToolTip(QPoint,QString)), this, SIGNAL(showToolTip(QPoint,QString))); | |
|
129 | } | |
|
130 | } else { | |
|
131 | for (int i=0; i<m_internalModel->barsetCount(); i++) { | |
|
132 | QBarSet *set = m_internalModel->barsetAt(i); | |
|
133 | disconnect(set, SIGNAL(showToolTip(QPoint,QString)), this, SIGNAL(showToolTip(QPoint,QString))); | |
|
134 | } | |
|
135 | } | |
|
136 | } | |
|
137 | ||
|
138 | void QBarSeriesPrivate::barsetClicked(QString category, Qt::MouseButtons button) | |
|
139 | { | |
|
140 | emit clicked(qobject_cast<QBarSet*>(sender()), category, button); | |
|
141 | } | |
|
142 | ||
|
143 | qreal QBarSeriesPrivate::min() | |
|
144 | { | |
|
145 | return m_internalModel->min(); | |
|
146 | } | |
|
147 | ||
|
148 | qreal QBarSeriesPrivate::max() | |
|
149 | { | |
|
150 | return m_internalModel->max(); | |
|
151 | } | |
|
152 | ||
|
153 | qreal QBarSeriesPrivate::valueAt(int set, int category) | |
|
154 | { | |
|
155 | return m_internalModel->valueAt(set, category); | |
|
156 | } | |
|
157 | ||
|
158 | qreal QBarSeriesPrivate::percentageAt(int set, int category) | |
|
159 | { | |
|
160 | return m_internalModel->percentageAt(set, category); | |
|
161 | } | |
|
162 | ||
|
163 | qreal QBarSeriesPrivate::categorySum(int category) | |
|
164 | { | |
|
165 | return m_internalModel->categorySum(category); | |
|
166 | } | |
|
167 | ||
|
168 | qreal QBarSeriesPrivate::absoluteCategorySum(int category) | |
|
169 | { | |
|
170 | return m_internalModel->absoluteCategorySum(category); | |
|
171 | } | |
|
172 | ||
|
173 | qreal QBarSeriesPrivate::maxCategorySum() | |
|
174 | { | |
|
175 | return m_internalModel->maxCategorySum(); | |
|
176 | } | |
|
177 | ||
|
178 | BarChartModel& QBarSeriesPrivate::modelInternal() | |
|
179 | { | |
|
180 | return *m_internalModel; | |
|
181 | } | |
|
182 | ||
|
183 | bool QBarSeriesPrivate::setModel(QAbstractItemModel *model) | |
|
184 | { | |
|
185 | // disconnect signals from old model | |
|
186 | if(m_model) | |
|
187 | { | |
|
188 | disconnect(m_model, 0, this, 0); | |
|
189 | m_mapCategories = -1; | |
|
190 | m_mapBarBottom = -1; | |
|
191 | m_mapBarTop = -1; | |
|
192 | m_mapFirst = 0; | |
|
193 | m_mapCount = 0; | |
|
194 | m_mapOrientation = Qt::Vertical; | |
|
195 | } | |
|
196 | ||
|
197 | // set new model | |
|
198 | if(model) | |
|
199 | { | |
|
200 | m_model = model; | |
|
201 | return true; | |
|
202 | } | |
|
203 | else | |
|
204 | { | |
|
205 | m_model = 0; | |
|
206 | return false; | |
|
207 | } | |
|
208 | } | |
|
209 | ||
|
210 | void QBarSeriesPrivate::setModelMapping(int categories, int bottomBoundry, int topBoundry, Qt::Orientation orientation) | |
|
211 | { | |
|
212 | if (!m_model) | |
|
213 | return; | |
|
214 | ||
|
215 | m_mapCategories = categories; | |
|
216 | m_mapBarBottom = bottomBoundry; | |
|
217 | m_mapBarTop = topBoundry; | |
|
218 | // m_mapFirst = 1; | |
|
219 | m_mapOrientation = orientation; | |
|
220 | ||
|
221 | // connect the signals | |
|
222 | if (m_mapOrientation == Qt::Vertical) { | |
|
223 | m_mapCount = m_model->rowCount() - m_mapFirst; | |
|
224 | connect(m_model,SIGNAL(dataChanged(QModelIndex,QModelIndex)), | |
|
225 | this, SLOT(modelUpdated(QModelIndex, QModelIndex))); | |
|
226 | connect(m_model,SIGNAL(rowsInserted(QModelIndex, int, int)), | |
|
227 | this, SLOT(modelDataAdded(QModelIndex,int,int))); | |
|
228 | connect(m_model, SIGNAL(rowsRemoved(QModelIndex, int, int)), | |
|
229 | this, SLOT(modelDataRemoved(QModelIndex,int,int))); | |
|
230 | } else { | |
|
231 | m_mapCount = m_model->columnCount() - m_mapFirst; | |
|
232 | connect(m_model,SIGNAL(dataChanged(QModelIndex,QModelIndex)), | |
|
233 | this, SLOT(modelUpdated(QModelIndex, QModelIndex))); | |
|
234 | connect(m_model,SIGNAL(columnsInserted(QModelIndex, int, int)), | |
|
235 | this, SLOT(modelDataAdded(QModelIndex,int,int))); | |
|
236 | connect(m_model, SIGNAL(columnsRemoved(QModelIndex, int, int)), | |
|
237 | this, SLOT(modelDataRemoved(QModelIndex,int,int))); | |
|
238 | } | |
|
239 | ||
|
240 | // create the initial bars | |
|
241 | delete m_internalModel; | |
|
242 | if (m_mapOrientation == Qt::Vertical) { | |
|
243 | QStringList categories; | |
|
244 | for (int k = m_mapFirst; k < m_mapFirst + m_mapCount; k++) | |
|
245 | categories << m_model->data(m_model->index(k, m_mapCategories), Qt::DisplayRole).toString(); | |
|
246 | m_internalModel = new BarChartModel(categories, this); | |
|
247 | ||
|
248 | for (int i = m_mapBarBottom; i <= m_mapBarTop; i++) { | |
|
249 | QBarSet* barSet = new QBarSet(QString("Column: %1").arg(i + 1)); | |
|
250 | for(int m = m_mapFirst; m < m_mapFirst + m_mapCount; m++) | |
|
251 | *barSet << m_model->data(m_model->index(m, i), Qt::DisplayRole).toDouble(); | |
|
252 | appendBarSet(barSet); | |
|
253 | } | |
|
254 | } else { | |
|
255 | QStringList categories; | |
|
256 | for (int k = m_mapFirst; k < m_mapFirst + m_mapCount; k++) | |
|
257 | categories << m_model->data(m_model->index(m_mapCategories, k), Qt::DisplayRole).toString(); | |
|
258 | m_internalModel = new BarChartModel(categories, this); | |
|
259 | ||
|
260 | for (int i = m_mapBarBottom; i <= m_mapBarTop; i++) { | |
|
261 | QBarSet* barSet = new QBarSet(QString("Row: %1").arg(i + 1)); | |
|
262 | for(int m = m_mapFirst; m < m_mapFirst + m_mapCount; m++) | |
|
263 | *barSet << m_model->data(m_model->index(i, m), Qt::DisplayRole).toDouble(); | |
|
264 | appendBarSet(barSet); | |
|
265 | } | |
|
266 | } | |
|
267 | } | |
|
268 | ||
|
269 | void QBarSeriesPrivate::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight) | |
|
270 | { | |
|
271 | Q_UNUSED(bottomRight) | |
|
272 | ||
|
273 | if (m_mapOrientation == Qt::Vertical) | |
|
274 | { | |
|
275 | // model update is relevant to BarSeries if the change was made to the part of the model that was mapped to BarSeries | |
|
276 | if (topLeft.column() >= m_mapBarBottom && topLeft.column() <= m_mapBarTop && topLeft.row() >= m_mapFirst && topLeft.row() < m_mapFirst + m_mapCount) | |
|
277 | barsetAt(topLeft.column() - m_mapBarBottom)->setValue(topLeft.row() - m_mapFirst, m_model->data(topLeft, Qt::DisplayRole).toDouble()); | |
|
278 | } | |
|
279 | else | |
|
280 | { | |
|
281 | // model update is relevant to BarSeries if the change was made to the part of the model that was mapped to BarSeries | |
|
282 | if (topLeft.row() >= m_mapBarBottom && topLeft.row() <= m_mapBarTop && topLeft.column() >= m_mapFirst && topLeft.column() < m_mapFirst + m_mapCount) | |
|
283 | barsetAt(topLeft.row() - m_mapBarBottom)->setValue(topLeft.column() - m_mapFirst, m_model->data(topLeft, Qt::DisplayRole).toDouble()); | |
|
284 | } | |
|
285 | } | |
|
286 | ||
|
287 | void QBarSeriesPrivate::modelDataAdded(QModelIndex /*parent*/, int start, int /*end*/) | |
|
288 | { | |
|
289 | if (m_mapOrientation == Qt::Vertical) { | |
|
290 | insertCategory(start - m_mapFirst, QString("Row: %1").arg(start + 1)); | |
|
291 | for (int i = 0; i <= m_mapBarTop - m_mapBarBottom; i++) { | |
|
292 | barsetAt(i)->insertValue(start - m_mapFirst, m_model->data(m_model->index(start, i), Qt::DisplayRole).toDouble()); | |
|
293 | } | |
|
294 | } else { | |
|
295 | insertCategory(start - m_mapFirst, QString("Column: %1").arg(start + 1)); | |
|
296 | for (int i = 0; i <= m_mapBarTop - m_mapBarBottom; i++) { | |
|
297 | barsetAt(i)->insertValue(start - m_mapFirst, m_model->data(m_model->index(i, start), Qt::DisplayRole).toDouble()); | |
|
298 | } | |
|
299 | } | |
|
300 | emit restructuredBars(); | |
|
301 | } | |
|
302 | ||
|
303 | void QBarSeriesPrivate::modelDataRemoved(QModelIndex parent, int start, int end) | |
|
304 | { | |
|
305 | Q_UNUSED(parent) | |
|
306 | Q_UNUSED(end) | |
|
307 | ||
|
308 | removeCategory(start - m_mapFirst); | |
|
309 | for (int i = 0; i <= m_mapBarTop - m_mapBarBottom; i++) | |
|
310 | { | |
|
311 | barsetAt(i)->removeValue(start - m_mapFirst); | |
|
312 | } | |
|
313 | emit restructuredBars(); | |
|
314 | } | |
|
315 | ||
|
316 | void QBarSeriesPrivate::barsetChanged() | |
|
317 | { | |
|
318 | emit updatedBars(); | |
|
319 | } | |
|
320 | ||
|
321 | QBarCategories QBarSeriesPrivate::categories() const | |
|
322 | { | |
|
323 | QBarCategories categories; | |
|
324 | int count = m_internalModel->categoryCount(); | |
|
325 | for (int i=1; i <= count; i++) { | |
|
326 | categories.insert(i, m_internalModel->categoryName(i - 1)); | |
|
327 | } | |
|
328 | return categories; | |
|
329 | } | |
|
330 | ||
|
331 | void QBarSeriesPrivate::setLabelsVisible(bool visible) | |
|
332 | { | |
|
333 | foreach (QBarSet* s, barSets()) { | |
|
334 | s->setLabelsVisible(visible); | |
|
335 | } | |
|
336 | } | |
|
337 | ||
|
338 | ||
|
339 | 32 | /*! |
|
340 | 33 | \class QBarSeries |
|
341 | 34 | \brief part of QtCommercial chart API. |
@@ -364,17 +57,15 void QBarSeriesPrivate::setLabelsVisible(bool visible) | |||
|
364 | 57 | Constructs empty QBarSeries. Parameter \a categories defines the categories for chart. |
|
365 | 58 | QBarSeries is QObject which is a child of a \a parent. |
|
366 | 59 | */ |
|
367 | QBarSeries::QBarSeries(QBarCategories categories, QObject *parent) : QSeries(parent), | |
|
368 | d_ptr(new QBarSeriesPrivate(categories, this)) | |
|
369 | // m_internalModel(new BarChartModel(categories, this)) | |
|
60 | ||
|
61 | QBarSeries::QBarSeries(QBarCategories categories, QObject *parent) : QSeries(*new QBarSeriesPrivate(categories, this),parent) | |
|
62 | { | |
|
63 | ||
|
64 | } | |
|
65 | ||
|
66 | QSeries::QSeriesType QBarSeries::type() const | |
|
370 | 67 | { |
|
371 | // m_model = 0; | |
|
372 | // m_mapCategories = -1; | |
|
373 | // m_mapBarBottom = -1; | |
|
374 | // m_mapBarTop = -1; | |
|
375 | // m_mapFirst = 0; | |
|
376 | // m_mapCount = 0; | |
|
377 | // m_mapOrientation = Qt::Vertical; | |
|
68 | return QSeries::SeriesTypeBar; | |
|
378 | 69 | } |
|
379 | 70 | |
|
380 | 71 | /*! |
@@ -385,15 +76,10 QBarSeries::QBarSeries(QBarCategories categories, QObject *parent) : QSeries(par | |||
|
385 | 76 | void QBarSeries::appendBarSet(QBarSet *set) |
|
386 | 77 | { |
|
387 | 78 | Q_D(QBarSeries); |
|
388 | connect(&QBarSetPrivate::pimpl(set), SIGNAL(clicked(QString,Qt::MouseButtons)), d_ptr, SLOT(barsetClicked(QString,Qt::MouseButtons))); | |
|
389 | connect(&QBarSetPrivate::pimpl(set), SIGNAL(valueChanged()), d_ptr, SLOT(barsetChanged())); | |
|
390 | d->appendBarSet(set); | |
|
391 | /* | |
|
392 | m_internalModel->appendBarSet(set); | |
|
393 | connect(set, SIGNAL(clicked(QString,Qt::MouseButtons)), this, SLOT(barsetClicked(QString,Qt::MouseButtons))); | |
|
394 | connect(set, SIGNAL(valueChanged()), this, SLOT(barsetChanged())); | |
|
395 | emit restructuredBars(); | |
|
396 | */ | |
|
79 | d->m_internalModel->appendBarSet(set); | |
|
80 | QObject::connect(set->d_ptr.data(), SIGNAL(clicked(QString,Qt::MouseButtons)), d, SLOT(barsetClicked(QString,Qt::MouseButtons))); | |
|
81 | QObject::connect(set->d_ptr.data(), SIGNAL(valueChanged()), d, SLOT(barsetChanged())); | |
|
82 | emit d->restructuredBars(); | |
|
397 | 83 | } |
|
398 | 84 | |
|
399 | 85 | /*! |
@@ -404,13 +90,9 void QBarSeries::appendBarSet(QBarSet *set) | |||
|
404 | 90 | void QBarSeries::removeBarSet(QBarSet *set) |
|
405 | 91 | { |
|
406 | 92 | Q_D(QBarSeries); |
|
407 |
disconnect( |
|
|
408 | d->removeBarSet(set); | |
|
409 | /* | |
|
410 | disconnect(set, SIGNAL(clicked(QString,Qt::MouseButtons)), this, SLOT(barsetClicked(QString,Qt::MouseButtons))); | |
|
411 | m_internalModel->removeBarSet(set); | |
|
412 | emit restructuredBars(); | |
|
413 | */ | |
|
93 | QObject::disconnect(set->d_ptr.data(), SIGNAL(clicked(QString,Qt::MouseButtons)), d, SLOT(barsetClicked(QString,Qt::MouseButtons))); | |
|
94 | d->m_internalModel->removeBarSet(set); | |
|
95 | emit d->restructuredBars(); | |
|
414 | 96 | } |
|
415 | 97 | |
|
416 | 98 | /*! |
@@ -421,15 +103,13 void QBarSeries::removeBarSet(QBarSet *set) | |||
|
421 | 103 | void QBarSeries::appendBarSets(QList<QBarSet* > sets) |
|
422 | 104 | { |
|
423 | 105 | Q_D(QBarSeries); |
|
424 | d->appendBarSets(sets); | |
|
425 | /* | |
|
426 | 106 | foreach (QBarSet* barset, sets) { |
|
427 | m_internalModel->appendBarSet(barset); | |
|
428 | connect(barset, SIGNAL(clicked(QString,Qt::MouseButtons)), this, SLOT(barsetClicked(QString,Qt::MouseButtons))); | |
|
429 | connect(barset, SIGNAL(valueChanged()), this, SLOT(barsetChanged())); | |
|
107 | d->m_internalModel->appendBarSet(barset); | |
|
108 | QObject::connect(barset, SIGNAL(clicked(QString,Qt::MouseButtons)), this, SLOT(barsetClicked(QString,Qt::MouseButtons))); | |
|
109 | QObject::connect(barset, SIGNAL(valueChanged()), this, SLOT(barsetChanged())); | |
|
430 | 110 | } |
|
431 | emit restructuredBars(); | |
|
432 | */ | |
|
111 | emit d->restructuredBars(); | |
|
112 | ||
|
433 | 113 | } |
|
434 | 114 | |
|
435 | 115 | /*! |
@@ -440,14 +120,12 void QBarSeries::appendBarSets(QList<QBarSet* > sets) | |||
|
440 | 120 | void QBarSeries::removeBarSets(QList<QBarSet* > sets) |
|
441 | 121 | { |
|
442 | 122 | Q_D(QBarSeries); |
|
443 | d->removeBarSets(sets); | |
|
444 | /* | |
|
123 | ||
|
445 | 124 | foreach (QBarSet* barset, sets) { |
|
446 | disconnect(barset, SIGNAL(clicked(QString,Qt::MouseButtons)), this, SLOT(barsetClicked(QString,Qt::MouseButtons))); | |
|
447 | m_internalModel->removeBarSet(barset); | |
|
125 | QObject::disconnect(barset, SIGNAL(clicked(QString,Qt::MouseButtons)), this, SLOT(barsetClicked(QString,Qt::MouseButtons))); | |
|
126 | d->m_internalModel->removeBarSet(barset); | |
|
448 | 127 | } |
|
449 | emit restructuredBars(); | |
|
450 | */ | |
|
128 | emit d->restructuredBars(); | |
|
451 | 129 | } |
|
452 | 130 | |
|
453 | 131 | /*! |
@@ -457,11 +135,8 void QBarSeries::removeBarSets(QList<QBarSet* > sets) | |||
|
457 | 135 | void QBarSeries::insertBarSet(int i, QBarSet *set) |
|
458 | 136 | { |
|
459 | 137 | Q_D(QBarSeries); |
|
460 | d->insertBarSet(i,set); | |
|
461 | /* | |
|
462 | m_internalModel->insertBarSet(i, set); | |
|
463 | // emit barsetChanged(); | |
|
464 | */ | |
|
138 | d->m_internalModel->insertBarSet(i, set); | |
|
139 | emit d->barsetChanged(); | |
|
465 | 140 | } |
|
466 | 141 | |
|
467 | 142 | /*! |
@@ -472,8 +147,7 void QBarSeries::insertBarSet(int i, QBarSet *set) | |||
|
472 | 147 | void QBarSeries::insertCategory(int i, QString category) |
|
473 | 148 | { |
|
474 | 149 | Q_D(QBarSeries); |
|
475 | d->insertCategory(i,category); | |
|
476 | //m_internalModel->insertCategory(i, category); | |
|
150 | d->m_internalModel->insertCategory(i, category); | |
|
477 | 151 | } |
|
478 | 152 | |
|
479 | 153 | /*! |
@@ -483,8 +157,7 void QBarSeries::insertCategory(int i, QString category) | |||
|
483 | 157 | void QBarSeries::removeCategory(int i) |
|
484 | 158 | { |
|
485 | 159 | Q_D(QBarSeries); |
|
486 | d->removeCategory(i); | |
|
487 | //m_internalModel->removeCategory(i); | |
|
160 | d->m_internalModel->removeCategory(i); | |
|
488 | 161 | } |
|
489 | 162 | |
|
490 | 163 | /*! |
@@ -493,13 +166,13 void QBarSeries::removeCategory(int i) | |||
|
493 | 166 | int QBarSeries::barsetCount() const |
|
494 | 167 | { |
|
495 | 168 | Q_D(const QBarSeries); |
|
496 | return d->barsetCount(); | |
|
497 | 169 | /* |
|
498 | 170 | // if(m_model) |
|
499 | 171 | // return m_mapBarTop - m_mapBarBottom; |
|
500 | 172 | // else |
|
501 | return m_internalModel->barsetCount(); | |
|
173 | ||
|
502 | 174 | */ |
|
175 | return d->m_internalModel->barsetCount(); | |
|
503 | 176 | } |
|
504 | 177 | |
|
505 | 178 | /*! |
@@ -508,8 +181,7 int QBarSeries::barsetCount() const | |||
|
508 | 181 | int QBarSeries::categoryCount() const |
|
509 | 182 | { |
|
510 | 183 | Q_D(const QBarSeries); |
|
511 | return d->categoryCount(); | |
|
512 | // return m_internalModel->categoryCount(); | |
|
184 | return d->m_internalModel->categoryCount(); | |
|
513 | 185 | } |
|
514 | 186 | |
|
515 | 187 | /*! |
@@ -518,8 +190,7 int QBarSeries::categoryCount() const | |||
|
518 | 190 | QList<QBarSet*> QBarSeries::barSets() const |
|
519 | 191 | { |
|
520 | 192 | Q_D(const QBarSeries); |
|
521 | return d->barSets(); | |
|
522 | // return m_internalModel->barSets(); | |
|
193 | return d->m_internalModel->barSets(); | |
|
523 | 194 | } |
|
524 | 195 | |
|
525 | 196 | /*! |
@@ -842,15 +513,14 void QBarSeries::barsetChanged() | |||
|
842 | 513 | QBarCategories QBarSeries::categories() const |
|
843 | 514 | { |
|
844 | 515 | Q_D(const QBarSeries); |
|
845 | return d->categories(); | |
|
846 | /* | |
|
516 | ||
|
847 | 517 | QBarCategories categories; |
|
848 | int count = m_internalModel->categoryCount(); | |
|
518 | int count = d->m_internalModel->categoryCount(); | |
|
849 | 519 | for (int i=1; i <= count; i++) { |
|
850 | categories.insert(i, m_internalModel->categoryName(i - 1)); | |
|
520 | categories.insert(i, d->m_internalModel->categoryName(i - 1)); | |
|
851 | 521 | } |
|
852 | 522 | return categories; |
|
853 | */ | |
|
523 | ||
|
854 | 524 | } |
|
855 | 525 | |
|
856 | 526 | /*! |
@@ -858,17 +528,240 QBarCategories QBarSeries::categories() const | |||
|
858 | 528 | */ |
|
859 | 529 | void QBarSeries::setLabelsVisible(bool visible) |
|
860 | 530 | { |
|
861 | Q_D(QBarSeries); | |
|
862 | d->setLabelsVisible(visible); | |
|
863 | /* | |
|
864 | 531 | foreach (QBarSet* s, barSets()) { |
|
865 | 532 | s->setLabelsVisible(visible); |
|
866 | 533 | } |
|
867 | */ | |
|
868 | 534 | } |
|
869 | 535 | |
|
536 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
|
537 | ||
|
538 | QBarSeriesPrivate::QBarSeriesPrivate(QBarCategories categories, QBarSeries *q) : QSeriesPrivate(q), | |
|
539 | m_internalModel(new BarChartModel(categories,this)), | |
|
540 | m_model(0), | |
|
541 | m_mapCategories(-1), | |
|
542 | m_mapBarBottom(-1), | |
|
543 | m_mapBarTop(-1), | |
|
544 | m_mapFirst(0), | |
|
545 | m_mapCount(0), | |
|
546 | m_mapOrientation(Qt::Vertical) | |
|
547 | { | |
|
548 | } | |
|
549 | ||
|
550 | QBarSet* QBarSeriesPrivate::barsetAt(int index) | |
|
551 | { | |
|
552 | return m_internalModel->barsetAt(index); | |
|
553 | } | |
|
554 | ||
|
555 | QString QBarSeriesPrivate::categoryName(int category) | |
|
556 | { | |
|
557 | return m_internalModel->categoryName(category); | |
|
558 | } | |
|
559 | ||
|
560 | void QBarSeriesPrivate::setToolTipEnabled(bool enabled) | |
|
561 | { | |
|
562 | // TODO: what if we add sets after call to this function? Those sets won't have tooltip enabled. | |
|
563 | if (enabled) { | |
|
564 | for (int i=0; i<m_internalModel->barsetCount(); i++) { | |
|
565 | QBarSet *set = m_internalModel->barsetAt(i); | |
|
566 | connect(set, SIGNAL(showToolTip(QPoint,QString)), this, SIGNAL(showToolTip(QPoint,QString))); | |
|
567 | } | |
|
568 | } else { | |
|
569 | for (int i=0; i<m_internalModel->barsetCount(); i++) { | |
|
570 | QBarSet *set = m_internalModel->barsetAt(i); | |
|
571 | disconnect(set, SIGNAL(showToolTip(QPoint,QString)), this, SIGNAL(showToolTip(QPoint,QString))); | |
|
572 | } | |
|
573 | } | |
|
574 | } | |
|
575 | ||
|
576 | void QBarSeriesPrivate::barsetClicked(QString category, Qt::MouseButtons button) | |
|
577 | { | |
|
578 | emit clicked(qobject_cast<QBarSet*>(sender()), category, button); | |
|
579 | } | |
|
580 | ||
|
581 | qreal QBarSeriesPrivate::min() | |
|
582 | { | |
|
583 | return m_internalModel->min(); | |
|
584 | } | |
|
585 | ||
|
586 | qreal QBarSeriesPrivate::max() | |
|
587 | { | |
|
588 | return m_internalModel->max(); | |
|
589 | } | |
|
590 | ||
|
591 | qreal QBarSeriesPrivate::valueAt(int set, int category) | |
|
592 | { | |
|
593 | return m_internalModel->valueAt(set, category); | |
|
594 | } | |
|
595 | ||
|
596 | qreal QBarSeriesPrivate::percentageAt(int set, int category) | |
|
597 | { | |
|
598 | return m_internalModel->percentageAt(set, category); | |
|
599 | } | |
|
600 | ||
|
601 | qreal QBarSeriesPrivate::categorySum(int category) | |
|
602 | { | |
|
603 | return m_internalModel->categorySum(category); | |
|
604 | } | |
|
605 | ||
|
606 | qreal QBarSeriesPrivate::absoluteCategorySum(int category) | |
|
607 | { | |
|
608 | return m_internalModel->absoluteCategorySum(category); | |
|
609 | } | |
|
610 | ||
|
611 | qreal QBarSeriesPrivate::maxCategorySum() | |
|
612 | { | |
|
613 | return m_internalModel->maxCategorySum(); | |
|
614 | } | |
|
615 | ||
|
616 | BarChartModel& QBarSeriesPrivate::modelInternal() | |
|
617 | { | |
|
618 | return *m_internalModel; | |
|
619 | } | |
|
620 | ||
|
621 | bool QBarSeriesPrivate::setModel(QAbstractItemModel *model) | |
|
622 | { | |
|
623 | // disconnect signals from old model | |
|
624 | if(m_model) | |
|
625 | { | |
|
626 | disconnect(m_model, 0, this, 0); | |
|
627 | m_mapCategories = -1; | |
|
628 | m_mapBarBottom = -1; | |
|
629 | m_mapBarTop = -1; | |
|
630 | m_mapFirst = 0; | |
|
631 | m_mapCount = 0; | |
|
632 | m_mapOrientation = Qt::Vertical; | |
|
633 | } | |
|
634 | ||
|
635 | // set new model | |
|
636 | if(model) | |
|
637 | { | |
|
638 | m_model = model; | |
|
639 | return true; | |
|
640 | } | |
|
641 | else | |
|
642 | { | |
|
643 | m_model = 0; | |
|
644 | return false; | |
|
645 | } | |
|
646 | } | |
|
647 | ||
|
648 | void QBarSeriesPrivate::setModelMapping(int categories, int bottomBoundry, int topBoundry, Qt::Orientation orientation) | |
|
649 | { | |
|
650 | Q_Q(QBarSeries); | |
|
651 | ||
|
652 | if (!m_model) | |
|
653 | return; | |
|
654 | ||
|
655 | m_mapCategories = categories; | |
|
656 | m_mapBarBottom = bottomBoundry; | |
|
657 | m_mapBarTop = topBoundry; | |
|
658 | // m_mapFirst = 1; | |
|
659 | m_mapOrientation = orientation; | |
|
660 | ||
|
661 | // connect the signals | |
|
662 | if (m_mapOrientation == Qt::Vertical) { | |
|
663 | m_mapCount = m_model->rowCount() - m_mapFirst; | |
|
664 | connect(m_model,SIGNAL(dataChanged(QModelIndex,QModelIndex)), | |
|
665 | this, SLOT(modelUpdated(QModelIndex, QModelIndex))); | |
|
666 | connect(m_model,SIGNAL(rowsInserted(QModelIndex, int, int)), | |
|
667 | this, SLOT(modelDataAdded(QModelIndex,int,int))); | |
|
668 | connect(m_model, SIGNAL(rowsRemoved(QModelIndex, int, int)), | |
|
669 | this, SLOT(modelDataRemoved(QModelIndex,int,int))); | |
|
670 | } else { | |
|
671 | m_mapCount = m_model->columnCount() - m_mapFirst; | |
|
672 | connect(m_model,SIGNAL(dataChanged(QModelIndex,QModelIndex)), | |
|
673 | this, SLOT(modelUpdated(QModelIndex, QModelIndex))); | |
|
674 | connect(m_model,SIGNAL(columnsInserted(QModelIndex, int, int)), | |
|
675 | this, SLOT(modelDataAdded(QModelIndex,int,int))); | |
|
676 | connect(m_model, SIGNAL(columnsRemoved(QModelIndex, int, int)), | |
|
677 | this, SLOT(modelDataRemoved(QModelIndex,int,int))); | |
|
678 | } | |
|
679 | ||
|
680 | // create the initial bars | |
|
681 | delete m_internalModel; | |
|
682 | if (m_mapOrientation == Qt::Vertical) { | |
|
683 | QStringList categories; | |
|
684 | for (int k = m_mapFirst; k < m_mapFirst + m_mapCount; k++) | |
|
685 | categories << m_model->data(m_model->index(k, m_mapCategories), Qt::DisplayRole).toString(); | |
|
686 | m_internalModel = new BarChartModel(categories, this); | |
|
687 | ||
|
688 | for (int i = m_mapBarBottom; i <= m_mapBarTop; i++) { | |
|
689 | QBarSet* barSet = new QBarSet(QString("Column: %1").arg(i + 1)); | |
|
690 | for(int m = m_mapFirst; m < m_mapFirst + m_mapCount; m++) | |
|
691 | *barSet << m_model->data(m_model->index(m, i), Qt::DisplayRole).toDouble(); | |
|
692 | q->appendBarSet(barSet); | |
|
693 | } | |
|
694 | } else { | |
|
695 | QStringList categories; | |
|
696 | for (int k = m_mapFirst; k < m_mapFirst + m_mapCount; k++) | |
|
697 | categories << m_model->data(m_model->index(m_mapCategories, k), Qt::DisplayRole).toString(); | |
|
698 | m_internalModel = new BarChartModel(categories, this); | |
|
699 | ||
|
700 | for (int i = m_mapBarBottom; i <= m_mapBarTop; i++) { | |
|
701 | QBarSet* barSet = new QBarSet(QString("Row: %1").arg(i + 1)); | |
|
702 | for(int m = m_mapFirst; m < m_mapFirst + m_mapCount; m++) | |
|
703 | *barSet << m_model->data(m_model->index(i, m), Qt::DisplayRole).toDouble(); | |
|
704 | q->appendBarSet(barSet); | |
|
705 | } | |
|
706 | } | |
|
707 | } | |
|
708 | ||
|
709 | void QBarSeriesPrivate::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight) | |
|
710 | { | |
|
711 | Q_UNUSED(bottomRight) | |
|
712 | ||
|
713 | if (m_mapOrientation == Qt::Vertical) | |
|
714 | { | |
|
715 | // model update is relevant to BarSeries if the change was made to the part of the model that was mapped to BarSeries | |
|
716 | if (topLeft.column() >= m_mapBarBottom && topLeft.column() <= m_mapBarTop && topLeft.row() >= m_mapFirst && topLeft.row() < m_mapFirst + m_mapCount) | |
|
717 | barsetAt(topLeft.column() - m_mapBarBottom)->setValue(topLeft.row() - m_mapFirst, m_model->data(topLeft, Qt::DisplayRole).toDouble()); | |
|
718 | } | |
|
719 | else | |
|
720 | { | |
|
721 | // model update is relevant to BarSeries if the change was made to the part of the model that was mapped to BarSeries | |
|
722 | if (topLeft.row() >= m_mapBarBottom && topLeft.row() <= m_mapBarTop && topLeft.column() >= m_mapFirst && topLeft.column() < m_mapFirst + m_mapCount) | |
|
723 | barsetAt(topLeft.row() - m_mapBarBottom)->setValue(topLeft.column() - m_mapFirst, m_model->data(topLeft, Qt::DisplayRole).toDouble()); | |
|
724 | } | |
|
725 | } | |
|
726 | ||
|
727 | void QBarSeriesPrivate::modelDataAdded(QModelIndex /*parent*/, int start, int /*end*/) | |
|
728 | { | |
|
729 | Q_Q(QBarSeries); | |
|
730 | ||
|
731 | if (m_mapOrientation == Qt::Vertical) { | |
|
732 | q->insertCategory(start - m_mapFirst, QString("Row: %1").arg(start + 1)); | |
|
733 | for (int i = 0; i <= m_mapBarTop - m_mapBarBottom; i++) { | |
|
734 | barsetAt(i)->insertValue(start - m_mapFirst, m_model->data(m_model->index(start, i), Qt::DisplayRole).toDouble()); | |
|
735 | } | |
|
736 | } else { | |
|
737 | q->insertCategory(start - m_mapFirst, QString("Column: %1").arg(start + 1)); | |
|
738 | for (int i = 0; i <= m_mapBarTop - m_mapBarBottom; i++) { | |
|
739 | barsetAt(i)->insertValue(start - m_mapFirst, m_model->data(m_model->index(i, start), Qt::DisplayRole).toDouble()); | |
|
740 | } | |
|
741 | } | |
|
742 | emit restructuredBars(); | |
|
743 | } | |
|
744 | ||
|
745 | void QBarSeriesPrivate::modelDataRemoved(QModelIndex parent, int start, int end) | |
|
746 | { | |
|
747 | Q_Q(QBarSeries); | |
|
748 | Q_UNUSED(parent) | |
|
749 | Q_UNUSED(end) | |
|
750 | ||
|
751 | q->removeCategory(start - m_mapFirst); | |
|
752 | for (int i = 0; i <= m_mapBarTop - m_mapBarBottom; i++) | |
|
753 | { | |
|
754 | barsetAt(i)->removeValue(start - m_mapFirst); | |
|
755 | } | |
|
756 | emit restructuredBars(); | |
|
757 | } | |
|
758 | ||
|
759 | void QBarSeriesPrivate::barsetChanged() | |
|
760 | { | |
|
761 | emit updatedBars(); | |
|
762 | } | |
|
870 | 763 | |
|
871 | 764 | #include "moc_qbarseries.cpp" |
|
872 |
#include "moc_qbarseries |
|
|
765 | #include "moc_qbarseries_p.cpp" | |
|
873 | 766 | |
|
874 | 767 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -42,7 +42,7 class QTCOMMERCIALCHART_EXPORT QBarSeries : public QSeries | |||
|
42 | 42 | public: |
|
43 | 43 | QBarSeries(QStringList categories, QObject *parent = 0); |
|
44 | 44 | |
|
45 | virtual QSeriesType type() const { return QSeries::SeriesTypeBar; } | |
|
45 | QSeries::QSeriesType type() const; | |
|
46 | 46 | |
|
47 | 47 | void appendBarSet(QBarSet *set); // Takes ownership of set |
|
48 | 48 | void removeBarSet(QBarSet *set); // Releases ownership, doesn't delete set |
@@ -104,7 +104,6 private Q_SLOTS: | |||
|
104 | 104 | void barsetChanged(); |
|
105 | 105 | |
|
106 | 106 | protected: |
|
107 | QBarSeriesPrivate * const d_ptr; | |
|
108 | 107 | Q_DECLARE_PRIVATE(QBarSeries) |
|
109 | 108 | Q_DISABLE_COPY(QBarSeries) |
|
110 | 109 |
@@ -1,7 +1,8 | |||
|
1 |
#ifndef QBARSERIES |
|
|
2 |
#define QBARSERIES |
|
|
1 | #ifndef QBARSERIES_P_H | |
|
2 | #define QBARSERIES_P_H | |
|
3 | 3 | |
|
4 | 4 | #include "qbarseries.h" |
|
5 | #include "qseries_p.h" | |
|
5 | 6 | #include <QStringList> |
|
6 | 7 | #include <QSeries> |
|
7 | 8 | |
@@ -9,36 +10,12 class QModelIndex; | |||
|
9 | 10 | |
|
10 | 11 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
11 | 12 | |
|
12 | typedef QStringList QBarCategories; | |
|
13 | ||
|
14 | class QBarSeries; | |
|
15 | class QBarSet; | |
|
16 | class BarChartModel; | |
|
17 | class BarCategory; | |
|
18 | ||
|
19 | 13 | // Container for series |
|
20 |
class QBarSeriesPrivate : public Q |
|
|
14 | class QBarSeriesPrivate : public QSeriesPrivate | |
|
21 | 15 | { |
|
22 | 16 | Q_OBJECT |
|
23 | Q_DECLARE_PUBLIC(QBarSeries) | |
|
24 | 17 | public: |
|
25 |
QBarSeriesPrivate(Q |
|
|
26 | ||
|
27 | virtual QSeries::QSeriesType type() const { return QSeries::SeriesTypeBar; } | |
|
28 | ||
|
29 | void appendBarSet(QBarSet *set); // Takes ownership of set | |
|
30 | void removeBarSet(QBarSet *set); // Releases ownership, doesn't delete set | |
|
31 | void appendBarSets(QList<QBarSet* > sets); | |
|
32 | void removeBarSets(QList<QBarSet* > sets); | |
|
33 | void insertBarSet(int i, QBarSet *set); | |
|
34 | void insertCategory(int i, QString category); | |
|
35 | void removeCategory(int i); | |
|
36 | int barsetCount() const; | |
|
37 | int categoryCount() const; | |
|
38 | QList<QBarSet*> barSets() const; | |
|
39 | QBarCategories categories() const; | |
|
40 | ||
|
41 | void setLabelsVisible(bool visible = true); | |
|
18 | QBarSeriesPrivate(QBarCategories categories, QBarSeries *parent); | |
|
42 | 19 | |
|
43 | 20 | bool setModel(QAbstractItemModel *model); |
|
44 | 21 | void setModelMapping(int categories, int bottomBoundry, int topBoundry, Qt::Orientation orientation = Qt::Vertical); |
@@ -54,12 +31,6 public: | |||
|
54 | 31 | qreal maxCategorySum(); |
|
55 | 32 | BarChartModel& modelInternal(); |
|
56 | 33 | |
|
57 | static QBarSeriesPrivate &data(QBarSeries *barseries) | |
|
58 | { | |
|
59 | Q_ASSERT(barseries); | |
|
60 | return *barseries->d_ptr; | |
|
61 | } | |
|
62 | ||
|
63 | 34 | Q_SIGNALS: |
|
64 | 35 | void clicked(QBarSet *barset, QString category, Qt::MouseButtons button); // Up to user of api, what to do with these signals |
|
65 | 36 | void selected(); |
@@ -79,8 +50,6 private Q_SLOTS: | |||
|
79 | 50 | void barsetChanged(); |
|
80 | 51 | |
|
81 | 52 | protected: |
|
82 | QBarSeries * const q_ptr; | |
|
83 | ||
|
84 | 53 | BarChartModel *m_internalModel; // TODO: this may change... current "2 models" situation doesn't look good. |
|
85 | 54 | QAbstractItemModel* m_model; |
|
86 | 55 | int m_mapCategories; |
@@ -89,6 +58,8 protected: | |||
|
89 | 58 | int m_mapFirst; |
|
90 | 59 | int m_mapCount; |
|
91 | 60 | Qt::Orientation m_mapOrientation; |
|
61 | private: | |
|
62 | Q_DECLARE_PUBLIC(QBarSeries) | |
|
92 | 63 | }; |
|
93 | 64 | |
|
94 | 65 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -19,157 +19,11 | |||
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #include "qbarset.h" |
|
22 |
#include "qbarset |
|
|
23 | //#include <QDebug> | |
|
22 | #include "qbarset_p.h" | |
|
24 | 23 | #include <QToolTip> |
|
25 | 24 | |
|
26 | 25 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
27 | 26 | |
|
28 | ||
|
29 | QBarSetPrivate::QBarSetPrivate(QString name, QBarSet *parent) : QObject(parent), | |
|
30 | q_ptr(parent), | |
|
31 | m_name(name), | |
|
32 | m_labelsVisible(false) | |
|
33 | { | |
|
34 | ||
|
35 | } | |
|
36 | ||
|
37 | QBarSetPrivate::~QBarSetPrivate() | |
|
38 | { | |
|
39 | ||
|
40 | } | |
|
41 | ||
|
42 | void QBarSetPrivate::setName(QString name) | |
|
43 | { | |
|
44 | m_name = name; | |
|
45 | } | |
|
46 | ||
|
47 | QString QBarSetPrivate::name() const | |
|
48 | { | |
|
49 | return m_name; | |
|
50 | } | |
|
51 | ||
|
52 | QBarSetPrivate& QBarSetPrivate::operator << (const qreal &value) | |
|
53 | { | |
|
54 | m_values.append(value); | |
|
55 | emit structureChanged(); | |
|
56 | return *this; | |
|
57 | } | |
|
58 | ||
|
59 | void QBarSetPrivate::insertValue(int i, qreal value) | |
|
60 | { | |
|
61 | m_values.insert(i, value); | |
|
62 | } | |
|
63 | ||
|
64 | void QBarSetPrivate::removeValue(int i) | |
|
65 | { | |
|
66 | m_values.removeAt(i); | |
|
67 | } | |
|
68 | ||
|
69 | int QBarSetPrivate::count() const | |
|
70 | { | |
|
71 | return m_values.count(); | |
|
72 | } | |
|
73 | ||
|
74 | qreal QBarSetPrivate::valueAt(int index) const | |
|
75 | { | |
|
76 | return m_values.at(index); | |
|
77 | } | |
|
78 | ||
|
79 | void QBarSetPrivate::setValue(int index, qreal value) | |
|
80 | { | |
|
81 | m_values.replace(index,value); | |
|
82 | emit valueChanged(); | |
|
83 | } | |
|
84 | ||
|
85 | qreal QBarSetPrivate::sum() const | |
|
86 | { | |
|
87 | qreal sum(0); | |
|
88 | for (int i=0; i < m_values.count(); i++) { | |
|
89 | sum += m_values.at(i); | |
|
90 | } | |
|
91 | return sum; | |
|
92 | } | |
|
93 | ||
|
94 | void QBarSetPrivate::setPen(const QPen &pen) | |
|
95 | { | |
|
96 | m_pen = pen; | |
|
97 | emit valueChanged(); | |
|
98 | } | |
|
99 | ||
|
100 | QPen QBarSetPrivate::pen() const | |
|
101 | { | |
|
102 | return m_pen; | |
|
103 | } | |
|
104 | ||
|
105 | void QBarSetPrivate::setBrush(const QBrush &brush) | |
|
106 | { | |
|
107 | m_brush = brush; | |
|
108 | emit valueChanged(); | |
|
109 | } | |
|
110 | ||
|
111 | QBrush QBarSetPrivate::brush() const | |
|
112 | { | |
|
113 | return m_brush; | |
|
114 | } | |
|
115 | ||
|
116 | void QBarSetPrivate::setLabelPen(const QPen &pen) | |
|
117 | { | |
|
118 | m_labelPen = pen; | |
|
119 | emit valueChanged(); | |
|
120 | } | |
|
121 | ||
|
122 | QPen QBarSetPrivate::labelPen() const | |
|
123 | { | |
|
124 | return m_labelPen; | |
|
125 | } | |
|
126 | ||
|
127 | void QBarSetPrivate::setLabelBrush(const QBrush &brush) | |
|
128 | { | |
|
129 | m_labelBrush = brush; | |
|
130 | emit valueChanged(); | |
|
131 | } | |
|
132 | ||
|
133 | QBrush QBarSetPrivate::labelBrush() const | |
|
134 | { | |
|
135 | return m_labelBrush; | |
|
136 | } | |
|
137 | ||
|
138 | void QBarSetPrivate::setLabelFont(const QFont &font) | |
|
139 | { | |
|
140 | m_labelFont = font; | |
|
141 | emit valueChanged(); | |
|
142 | } | |
|
143 | ||
|
144 | QFont QBarSetPrivate::labelFont() const | |
|
145 | { | |
|
146 | return m_labelFont; | |
|
147 | } | |
|
148 | ||
|
149 | void QBarSetPrivate::setLabelsVisible(bool visible) | |
|
150 | { | |
|
151 | m_labelsVisible = visible; | |
|
152 | emit labelsVisibleChanged(visible); | |
|
153 | } | |
|
154 | ||
|
155 | bool QBarSetPrivate::labelsVisible() const | |
|
156 | { | |
|
157 | return m_labelsVisible; | |
|
158 | } | |
|
159 | ||
|
160 | void QBarSetPrivate::barHoverEnterEvent(QPoint pos) | |
|
161 | { | |
|
162 | emit showToolTip(pos, m_name); | |
|
163 | emit hoverEnter(pos); | |
|
164 | } | |
|
165 | ||
|
166 | void QBarSetPrivate::barHoverLeaveEvent() | |
|
167 | { | |
|
168 | // Emit signal to user of charts | |
|
169 | emit hoverLeave(); | |
|
170 | } | |
|
171 | ||
|
172 | ||
|
173 | 27 | /*! |
|
174 | 28 | \class QBarSet |
|
175 | 29 | \brief part of QtCommercial chart API. |
@@ -223,8 +77,7 QBarSet::QBarSet(QString name, QObject *parent) | |||
|
223 | 77 | */ |
|
224 | 78 | void QBarSet::setName(QString name) |
|
225 | 79 | { |
|
226 | Q_D(QBarSet); | |
|
227 | d->setName(name); | |
|
80 | d_ptr->m_name = name; | |
|
228 | 81 | } |
|
229 | 82 | |
|
230 | 83 | /*! |
@@ -232,8 +85,7 void QBarSet::setName(QString name) | |||
|
232 | 85 | */ |
|
233 | 86 | QString QBarSet::name() const |
|
234 | 87 | { |
|
235 | Q_D(const QBarSet); | |
|
236 | return d->name(); | |
|
88 | return d_ptr->m_name; | |
|
237 | 89 | } |
|
238 | 90 | |
|
239 | 91 | /*! |
@@ -241,13 +93,9 QString QBarSet::name() const | |||
|
241 | 93 | */ |
|
242 | 94 | QBarSet& QBarSet::operator << (const qreal &value) |
|
243 | 95 | { |
|
244 | Q_D(QBarSet); | |
|
245 | d->operator <<(value); | |
|
96 | d_ptr->m_values.append(value); | |
|
97 | emit d_ptr->structureChanged(); | |
|
246 | 98 | return *this; |
|
247 | ||
|
248 | // m_values.append(value); | |
|
249 | // emit structureChanged(); | |
|
250 | // return *this; | |
|
251 | 99 | } |
|
252 | 100 | |
|
253 | 101 | /*! |
@@ -257,9 +105,7 QBarSet& QBarSet::operator << (const qreal &value) | |||
|
257 | 105 | */ |
|
258 | 106 | void QBarSet::insertValue(int i, qreal value) |
|
259 | 107 | { |
|
260 | Q_D(QBarSet); | |
|
261 | d->insertValue(i,value); | |
|
262 | // m_values.insert(i, value); | |
|
108 | d_ptr->m_values.insert(i, value); | |
|
263 | 109 | } |
|
264 | 110 | |
|
265 | 111 | /*! |
@@ -268,9 +114,7 void QBarSet::insertValue(int i, qreal value) | |||
|
268 | 114 | */ |
|
269 | 115 | void QBarSet::removeValue(int i) |
|
270 | 116 | { |
|
271 | Q_D(QBarSet); | |
|
272 | d->removeValue(i); | |
|
273 | // m_values.removeAt(i); | |
|
117 | d_ptr->m_values.removeAt(i); | |
|
274 | 118 | } |
|
275 | 119 | |
|
276 | 120 | /*! |
@@ -278,9 +122,7 void QBarSet::removeValue(int i) | |||
|
278 | 122 | */ |
|
279 | 123 | int QBarSet::count() const |
|
280 | 124 | { |
|
281 | Q_D(const QBarSet); | |
|
282 | return d->count(); | |
|
283 | // return m_values.count(); | |
|
125 | return d_ptr->m_values.count(); | |
|
284 | 126 | } |
|
285 | 127 | |
|
286 | 128 | /*! |
@@ -288,9 +130,7 int QBarSet::count() const | |||
|
288 | 130 | */ |
|
289 | 131 | qreal QBarSet::valueAt(int index) const |
|
290 | 132 | { |
|
291 | Q_D(const QBarSet); | |
|
292 | return d->valueAt(index); | |
|
293 | // return m_values.at(index); | |
|
133 | return d_ptr->m_values.at(index); | |
|
294 | 134 | } |
|
295 | 135 | |
|
296 | 136 | /*! |
@@ -298,10 +138,8 qreal QBarSet::valueAt(int index) const | |||
|
298 | 138 | */ |
|
299 | 139 | void QBarSet::setValue(int index, qreal value) |
|
300 | 140 | { |
|
301 | Q_D(QBarSet); | |
|
302 | d->setValue(index,value); | |
|
303 | // m_values.replace(index,value); | |
|
304 | // emit valueChanged(); | |
|
141 | d_ptr->m_values.replace(index,value); | |
|
142 | emit d_ptr->valueChanged(); | |
|
305 | 143 | } |
|
306 | 144 | |
|
307 | 145 | /*! |
@@ -309,15 +147,11 void QBarSet::setValue(int index, qreal value) | |||
|
309 | 147 | */ |
|
310 | 148 | qreal QBarSet::sum() const |
|
311 | 149 | { |
|
312 | Q_D(const QBarSet); | |
|
313 | return d->sum(); | |
|
314 | /* | |
|
315 | 150 | qreal total(0); |
|
316 | for (int i=0; i < m_values.count(); i++) { | |
|
317 | total += m_values.at(i); | |
|
151 | for (int i=0; i < d_ptr->m_values.count(); i++) { | |
|
152 | total += d_ptr->m_values.at(i); | |
|
318 | 153 | } |
|
319 | 154 | return total; |
|
320 | */ | |
|
321 | 155 | } |
|
322 | 156 | |
|
323 | 157 | /*! |
@@ -325,10 +159,10 qreal QBarSet::sum() const | |||
|
325 | 159 | */ |
|
326 | 160 | void QBarSet::setPen(const QPen &pen) |
|
327 | 161 | { |
|
328 | Q_D(QBarSet); | |
|
329 | d->setPen(pen); | |
|
330 | // m_pen = pen; | |
|
331 | // emit valueChanged(); | |
|
162 | if(d_ptr->m_pen!=pen){ | |
|
163 | d_ptr->m_pen = pen; | |
|
164 | emit d_ptr->valueChanged(); | |
|
165 | } | |
|
332 | 166 | } |
|
333 | 167 | |
|
334 | 168 | /*! |
@@ -336,9 +170,7 void QBarSet::setPen(const QPen &pen) | |||
|
336 | 170 | */ |
|
337 | 171 | QPen QBarSet::pen() const |
|
338 | 172 | { |
|
339 | Q_D(const QBarSet); | |
|
340 | return d->pen(); | |
|
341 | // return m_pen; | |
|
173 | return d_ptr->m_pen; | |
|
342 | 174 | } |
|
343 | 175 | |
|
344 | 176 | /*! |
@@ -346,10 +178,10 QPen QBarSet::pen() const | |||
|
346 | 178 | */ |
|
347 | 179 | void QBarSet::setBrush(const QBrush &brush) |
|
348 | 180 | { |
|
349 | Q_D(QBarSet); | |
|
350 | d->setBrush(brush); | |
|
351 | // m_brush = brush; | |
|
352 | // emit valueChanged(); | |
|
181 | if(d_ptr->m_brush!=brush){ | |
|
182 | d_ptr->m_brush = brush; | |
|
183 | emit d_ptr->valueChanged(); | |
|
184 | } | |
|
353 | 185 | } |
|
354 | 186 | |
|
355 | 187 | /*! |
@@ -357,9 +189,7 void QBarSet::setBrush(const QBrush &brush) | |||
|
357 | 189 | */ |
|
358 | 190 | QBrush QBarSet::brush() const |
|
359 | 191 | { |
|
360 | Q_D(const QBarSet); | |
|
361 | return d->brush(); | |
|
362 | // return m_brush; | |
|
192 | return d_ptr->m_brush; | |
|
363 | 193 | } |
|
364 | 194 | |
|
365 | 195 | /*! |
@@ -367,10 +197,10 QBrush QBarSet::brush() const | |||
|
367 | 197 | */ |
|
368 | 198 | void QBarSet::setLabelPen(const QPen &pen) |
|
369 | 199 | { |
|
370 | Q_D(QBarSet); | |
|
371 |
d-> |
|
|
372 | // m_labelPen = pen; | |
|
373 | // emit valueChanged(); | |
|
200 | if(d_ptr->m_labelPen!=pen){ | |
|
201 | d_ptr->m_labelPen = pen; | |
|
202 | emit d_ptr->valueChanged(); | |
|
203 | } | |
|
374 | 204 | } |
|
375 | 205 | |
|
376 | 206 | /*! |
@@ -378,9 +208,7 void QBarSet::setLabelPen(const QPen &pen) | |||
|
378 | 208 | */ |
|
379 | 209 | QPen QBarSet::labelPen() const |
|
380 | 210 | { |
|
381 | Q_D(const QBarSet); | |
|
382 | return d->labelPen(); | |
|
383 | // return m_labelPen; | |
|
211 | return d_ptr->m_labelPen; | |
|
384 | 212 | } |
|
385 | 213 | |
|
386 | 214 | /*! |
@@ -388,10 +216,10 QPen QBarSet::labelPen() const | |||
|
388 | 216 | */ |
|
389 | 217 | void QBarSet::setLabelBrush(const QBrush &brush) |
|
390 | 218 | { |
|
391 | Q_D(QBarSet); | |
|
392 |
d-> |
|
|
393 | // m_labelBrush = brush; | |
|
394 | // emit valueChanged(); | |
|
219 | if(d_ptr->m_labelBrush!=brush){ | |
|
220 | d_ptr->m_labelBrush = brush; | |
|
221 | emit d_ptr->valueChanged(); | |
|
222 | } | |
|
395 | 223 | } |
|
396 | 224 | |
|
397 | 225 | /*! |
@@ -399,9 +227,7 void QBarSet::setLabelBrush(const QBrush &brush) | |||
|
399 | 227 | */ |
|
400 | 228 | QBrush QBarSet::labelBrush() const |
|
401 | 229 | { |
|
402 | Q_D(const QBarSet); | |
|
403 | return d->labelBrush(); | |
|
404 | // return m_labelBrush; | |
|
230 | return d_ptr->m_labelBrush; | |
|
405 | 231 | } |
|
406 | 232 | |
|
407 | 233 | /*! |
@@ -409,10 +235,11 QBrush QBarSet::labelBrush() const | |||
|
409 | 235 | */ |
|
410 | 236 | void QBarSet::setLabelFont(const QFont &font) |
|
411 | 237 | { |
|
412 | Q_D(QBarSet); | |
|
413 |
d-> |
|
|
414 | // m_labelFont = font; | |
|
415 | // emit valueChanged(); | |
|
238 | if(d_ptr->m_labelFont!=font) { | |
|
239 | d_ptr->m_labelFont = font; | |
|
240 | emit d_ptr->valueChanged(); | |
|
241 | } | |
|
242 | ||
|
416 | 243 | } |
|
417 | 244 | |
|
418 | 245 | /*! |
@@ -420,9 +247,7 void QBarSet::setLabelFont(const QFont &font) | |||
|
420 | 247 | */ |
|
421 | 248 | QFont QBarSet::labelFont() const |
|
422 | 249 | { |
|
423 | Q_D(const QBarSet); | |
|
424 | return d->labelFont(); | |
|
425 | // return m_labelFont; | |
|
250 | return d_ptr->m_labelFont; | |
|
426 | 251 | } |
|
427 | 252 | |
|
428 | 253 | /*! |
@@ -431,10 +256,10 QFont QBarSet::labelFont() const | |||
|
431 | 256 | |
|
432 | 257 | void QBarSet::setLabelsVisible(bool visible) |
|
433 | 258 | { |
|
434 | Q_D(QBarSet); | |
|
435 |
d-> |
|
|
436 |
|
|
|
437 | // emit labelsVisibleChanged(visible); | |
|
259 | if(d_ptr->m_labelsVisible!=visible) { | |
|
260 | d_ptr->m_labelsVisible = visible; | |
|
261 | emit d_ptr->labelsVisibleChanged(visible); | |
|
262 | } | |
|
438 | 263 | } |
|
439 | 264 | |
|
440 | 265 | /*! |
@@ -442,9 +267,7 void QBarSet::setLabelsVisible(bool visible) | |||
|
442 | 267 | */ |
|
443 | 268 | bool QBarSet::labelsVisible() const |
|
444 | 269 | { |
|
445 | Q_D(const QBarSet); | |
|
446 | return d->labelsVisible(); | |
|
447 | // return m_labelsVisible; | |
|
270 | return d_ptr->m_labelsVisible; | |
|
448 | 271 | } |
|
449 | 272 | |
|
450 | 273 | /* |
@@ -461,7 +284,38 void QBarSet::barHoverLeaveEvent() | |||
|
461 | 284 | emit hoverLeave(); |
|
462 | 285 | } |
|
463 | 286 | */ |
|
287 | ||
|
288 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
|
289 | ||
|
290 | QBarSetPrivate::QBarSetPrivate(QString name, QBarSet *parent) : QObject(parent), | |
|
291 | q_ptr(parent), | |
|
292 | m_name(name), | |
|
293 | m_labelsVisible(false) | |
|
294 | { | |
|
295 | ||
|
296 | } | |
|
297 | ||
|
298 | QBarSetPrivate::~QBarSetPrivate() | |
|
299 | { | |
|
300 | ||
|
301 | } | |
|
302 | ||
|
303 | ||
|
304 | //TODO: fixme , refactor it and get rid of it | |
|
305 | void QBarSetPrivate::barHoverEnterEvent(QPoint pos) | |
|
306 | { | |
|
307 | emit showToolTip(pos, m_name); | |
|
308 | emit hoverEnter(pos); | |
|
309 | } | |
|
310 | ||
|
311 | //TODO: fixme , refactor it and get rid of it | |
|
312 | void QBarSetPrivate::barHoverLeaveEvent() | |
|
313 | { | |
|
314 | // Emit signal to user of charts | |
|
315 | emit hoverLeave(); | |
|
316 | } | |
|
317 | ||
|
464 | 318 | #include "moc_qbarset.cpp" |
|
465 |
#include "moc_qbarset |
|
|
319 | #include "moc_qbarset_p.cpp" | |
|
466 | 320 | |
|
467 | 321 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -32,6 +32,7 class QBarSetPrivate; | |||
|
32 | 32 | class QTCOMMERCIALCHART_EXPORT QBarSet : public QObject |
|
33 | 33 | { |
|
34 | 34 | Q_OBJECT |
|
35 | ||
|
35 | 36 | public: |
|
36 | 37 | QBarSet(QString name, QObject *parent = 0); |
|
37 | 38 | |
@@ -66,37 +67,11 public: | |||
|
66 | 67 | Q_SIGNALS: |
|
67 | 68 | void clicked(QString category, Qt::MouseButtons button); // Clicked and hover signals exposed to user |
|
68 | 69 | |
|
69 | // TODO: TO PIMPL ---> | |
|
70 | // void structureChanged(); | |
|
71 | // void valueChanged(); | |
|
72 | // void hoverEnter(QPoint pos); | |
|
73 | // void hoverLeave(); | |
|
74 | // void showToolTip(QPoint pos, QString tip); // Private signal | |
|
75 | // void labelsVisibleChanged(bool visible); | |
|
76 | // <--- TO PIMPL | |
|
77 | ||
|
78 | public Q_SLOTS: | |
|
79 | // These are for internal communication | |
|
80 | // TODO: TO PIMPL ---> | |
|
81 | // void barHoverEnterEvent(QPoint pos); | |
|
82 | // void barHoverLeaveEvent(); | |
|
83 | // <--- TO PIMPL | |
|
84 | ||
|
85 | 70 | private: |
|
86 |
QBarSetPrivate |
|
|
87 | Q_DECLARE_PRIVATE(QBarSet) | |
|
71 | QScopedPointer<QBarSetPrivate> d_ptr; | |
|
88 | 72 | Q_DISABLE_COPY(QBarSet) |
|
89 | /* | |
|
90 | QString m_name; | |
|
91 | QList<qreal> m_values; // TODO: replace with map (category, value) | |
|
92 | QMap<QString, qreal> m_mappedValues; | |
|
93 | QPen m_pen; | |
|
94 | QBrush m_brush; | |
|
95 | QPen m_labelPen; | |
|
96 | QBrush m_labelBrush; | |
|
97 | QFont m_labelFont; | |
|
98 | bool m_labelsVisible; | |
|
99 | */ | |
|
73 | friend class QBarSeries; | |
|
74 | ||
|
100 | 75 | }; |
|
101 | 76 | |
|
102 | 77 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,5 +1,5 | |||
|
1 |
#ifndef QBARSET |
|
|
2 |
#define QBARSET |
|
|
1 | #ifndef QBARSET_P_H | |
|
2 | #define QBARSET_P_H | |
|
3 | 3 | |
|
4 | 4 | #include "qbarset.h" |
|
5 | 5 | |
@@ -8,46 +8,11 QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||
|
8 | 8 | class QBarSetPrivate : public QObject |
|
9 | 9 | { |
|
10 | 10 | Q_OBJECT |
|
11 | Q_DECLARE_PUBLIC(QBarSet) | |
|
12 | 11 | |
|
13 | 12 | public: |
|
14 | 13 | QBarSetPrivate(QString name, QBarSet *parent); |
|
15 | 14 | ~QBarSetPrivate(); |
|
16 | 15 | |
|
17 | void setName(QString name); | |
|
18 | QString name() const; | |
|
19 | QBarSetPrivate& operator << (const qreal &value); // appends new value to set | |
|
20 | void insertValue(int i, qreal value); | |
|
21 | void removeValue(int i); | |
|
22 | int count() const; | |
|
23 | qreal valueAt(int index) const; | |
|
24 | void setValue(int index, qreal value); | |
|
25 | qreal sum() const; | |
|
26 | ||
|
27 | void setPen(const QPen &pen); | |
|
28 | QPen pen() const; | |
|
29 | ||
|
30 | void setBrush(const QBrush &brush); | |
|
31 | QBrush brush() const; | |
|
32 | ||
|
33 | void setLabelPen(const QPen &pen); | |
|
34 | QPen labelPen() const; | |
|
35 | ||
|
36 | void setLabelBrush(const QBrush &brush); | |
|
37 | QBrush labelBrush() const; | |
|
38 | ||
|
39 | void setLabelFont(const QFont &font); | |
|
40 | QFont labelFont() const; | |
|
41 | ||
|
42 | void setLabelsVisible(bool visible = true); | |
|
43 | bool labelsVisible() const; | |
|
44 | ||
|
45 | static QBarSetPrivate &pimpl(QBarSet *barset) | |
|
46 | { | |
|
47 | Q_ASSERT(barset); | |
|
48 | return *barset->d_ptr; | |
|
49 | } | |
|
50 | ||
|
51 | 16 | Q_SIGNALS: |
|
52 | 17 | void clicked(QString category, Qt::MouseButtons button); |
|
53 | 18 | void structureChanged(); |
@@ -63,7 +28,6 public Q_SLOTS: | |||
|
63 | 28 | |
|
64 | 29 | public: |
|
65 | 30 | QBarSet * const q_ptr; |
|
66 | ||
|
67 | 31 | QString m_name; |
|
68 | 32 | QList<qreal> m_values; // TODO: replace with map (category, value) |
|
69 | 33 | QMap<QString, qreal> m_mappedValues; |
@@ -73,6 +37,8 public: | |||
|
73 | 37 | QBrush m_labelBrush; |
|
74 | 38 | QFont m_labelFont; |
|
75 | 39 | bool m_labelsVisible; |
|
40 | ||
|
41 | friend class QBarSet; | |
|
76 | 42 | }; |
|
77 | 43 | |
|
78 | 44 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -50,6 +50,11 QPercentBarSeries::QPercentBarSeries(QStringList categories, QObject *parent) | |||
|
50 | 50 | { |
|
51 | 51 | } |
|
52 | 52 | |
|
53 | QSeries::QSeriesType QPercentBarSeries::type() const | |
|
54 | { | |
|
55 | return QSeries::SeriesTypePercentBar; | |
|
56 | } | |
|
57 | ||
|
53 | 58 | #include "moc_qpercentbarseries.cpp" |
|
54 | 59 | |
|
55 | 60 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -31,7 +31,7 class QTCOMMERCIALCHART_EXPORT QPercentBarSeries : public QBarSeries | |||
|
31 | 31 | Q_OBJECT |
|
32 | 32 | public: |
|
33 | 33 | QPercentBarSeries(QStringList categories, QObject *parent = 0); |
|
34 | virtual QSeriesType type() const { return QSeries::SeriesTypePercentBar; } | |
|
34 | QSeries::QSeriesType type() const; | |
|
35 | 35 | }; |
|
36 | 36 | |
|
37 | 37 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -50,6 +50,11 QStackedBarSeries::QStackedBarSeries(QStringList categories, QObject *parent) | |||
|
50 | 50 | { |
|
51 | 51 | } |
|
52 | 52 | |
|
53 | QSeries::QSeriesType QStackedBarSeries::type() const | |
|
54 | { | |
|
55 | return QSeries::SeriesTypeStackedBar; | |
|
56 | } | |
|
57 | ||
|
53 | 58 | #include "moc_qstackedbarseries.cpp" |
|
54 | 59 | |
|
55 | 60 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -31,7 +31,7 class QTCOMMERCIALCHART_EXPORT QStackedBarSeries : public QBarSeries | |||
|
31 | 31 | Q_OBJECT |
|
32 | 32 | public: |
|
33 | 33 | QStackedBarSeries(QStringList categories, QObject *parent = 0); |
|
34 | virtual QSeriesType type() const { return QSeries::SeriesTypeStackedBar; } | |
|
34 | QSeries::QSeriesType type() const; | |
|
35 | 35 | }; |
|
36 | 36 | |
|
37 | 37 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -19,13 +19,15 | |||
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #include "legendmarker_p.h" |
|
22 | #include "qxyseries.h" | |
|
23 | #include "qxyseries_p.h" | |
|
22 | 24 | #include "qlegend.h" |
|
23 | 25 | #include "qbarseries.h" |
|
24 | 26 | #include "qpieseries.h" |
|
25 |
#include |
|
|
26 |
#include |
|
|
27 |
#include |
|
|
28 |
#include |
|
|
27 | #include "qpieslice.h" | |
|
28 | #include "qbarset.h" | |
|
29 | #include "qareaseries.h" | |
|
30 | #include "qareaseries_p.h" | |
|
29 | 31 | #include <QPainter> |
|
30 | 32 | #include <QGraphicsSceneEvent> |
|
31 | 33 | #include <QGraphicsSimpleTextItem> |
@@ -120,7 +122,7 AreaLegendMarker::AreaLegendMarker(QAreaSeries *series,QLegend *legend) : Legend | |||
|
120 | 122 | m_series(series) |
|
121 | 123 | { |
|
122 | 124 | QObject::connect(this, SIGNAL(selected()), series, SIGNAL(selected())); |
|
123 | QObject::connect(series,SIGNAL(updated()), this, SLOT(updated())); | |
|
125 | QObject::connect(series->d_func(),SIGNAL(updated()), this, SLOT(updated())); | |
|
124 | 126 | updated(); |
|
125 | 127 | } |
|
126 | 128 | |
@@ -169,7 +171,7 XYLegendMarker::XYLegendMarker(QXYSeries *series, QLegend *legend) : LegendMarke | |||
|
169 | 171 | m_series(series) |
|
170 | 172 | { |
|
171 | 173 | QObject::connect(this, SIGNAL(selected()), series, SIGNAL(selected())); |
|
172 | QObject::connect(series,SIGNAL(updated()), this, SLOT(updated())); | |
|
174 | QObject::connect(series->d_func(),SIGNAL(updated()), this, SLOT(updated())); | |
|
173 | 175 | updated(); |
|
174 | 176 | } |
|
175 | 177 |
@@ -6,7 +6,8 SOURCES += \ | |||
|
6 | 6 | $$PWD/qlineseries.cpp |
|
7 | 7 | |
|
8 | 8 | PRIVATE_HEADERS += \ |
|
9 | $$PWD/linechartitem_p.h | |
|
9 | $$PWD/linechartitem_p.h \ | |
|
10 | $$PWD/qlineseries_p.h | |
|
10 | 11 | |
|
11 | 12 | PUBLIC_HEADERS += \ |
|
12 | 13 | $$PWD/qlineseries.h No newline at end of file |
@@ -20,6 +20,7 | |||
|
20 | 20 | |
|
21 | 21 | #include "linechartitem_p.h" |
|
22 | 22 | #include "qlineseries.h" |
|
23 | #include "qlineseries_p.h" | |
|
23 | 24 | #include "chartpresenter_p.h" |
|
24 | 25 | #include <QPainter> |
|
25 | 26 | |
@@ -33,7 +34,7 m_series(series), | |||
|
33 | 34 | m_pointsVisible(false) |
|
34 | 35 | { |
|
35 | 36 | setZValue(ChartPresenter::LineChartZValue); |
|
36 | QObject::connect(series,SIGNAL(updated()),this,SLOT(handleUpdated())); | |
|
37 | QObject::connect(series->d_func(),SIGNAL(updated()),this,SLOT(handleUpdated())); | |
|
37 | 38 | handleUpdated(); |
|
38 | 39 | } |
|
39 | 40 |
@@ -19,6 +19,7 | |||
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #include "qlineseries.h" |
|
22 | #include "qlineseries_p.h" | |
|
22 | 23 | |
|
23 | 24 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
24 | 25 | |
@@ -59,8 +60,12 QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||
|
59 | 60 | Constructs empty series object which is a child of \a parent. |
|
60 | 61 | When series object is added to QChartView or QChart instance ownerships is transfered. |
|
61 | 62 | */ |
|
62 |
QLineSeries::QLineSeries(QObject *parent) : QXYSeries(parent) |
|
|
63 | m_pointsVisible(false) | |
|
63 | QLineSeries::QLineSeries(QObject *parent) : QXYSeries(*new QLineSeriesPrivate(this),parent) | |
|
64 | { | |
|
65 | ||
|
66 | } | |
|
67 | ||
|
68 | QLineSeries::QLineSeries(QLineSeriesPrivate &d,QObject *parent) : QXYSeries (d,parent) | |
|
64 | 69 | { |
|
65 | 70 | |
|
66 | 71 | } |
@@ -72,28 +77,28 QLineSeries::~QLineSeries() | |||
|
72 | 77 | { |
|
73 | 78 | } |
|
74 | 79 | |
|
75 | /*! | |
|
76 | Sets if data points are \a visible and should be drawn on line. | |
|
77 | */ | |
|
78 | void QLineSeries::setPointsVisible(bool visible) | |
|
80 | QSeries::QSeriesType QLineSeries::type() const | |
|
79 | 81 | { |
|
80 | if (m_pointsVisible != visible){ | |
|
81 | m_pointsVisible = visible; | |
|
82 | emit QXYSeries::updated(); | |
|
82 | return QSeries::SeriesTypeLine; | |
|
83 | 83 | } |
|
84 | } | |
|
85 | ||
|
86 | 84 | |
|
85 | /* | |
|
87 | 86 | QDebug operator<< (QDebug debug, const QLineSeries series) |
|
88 | 87 |
|
|
89 | Q_ASSERT(series.m_x.size() == series.m_y.size()); | |
|
90 | ||
|
91 | int size = series.m_x.size(); | |
|
92 | ||
|
88 | Q_ASSERT(series.d_func()->m_x.size() == series.d_func()->m_y.size()); | |
|
89 | int size = series.d_func()->m_x.size(); | |
|
93 | 90 | for (int i=0; i<size; i++) { |
|
94 | debug.nospace() << "(" << series.m_x.at(i) << ','<< series.m_y.at(i) << ") "; | |
|
91 | debug.nospace() << "(" << series.d_func()->m_x.at(i) << ','<< series.d_func()->m_y.at(i) << ") "; | |
|
95 | 92 | } |
|
96 | 93 | return debug.space(); |
|
97 | 94 |
|
|
95 | */ | |
|
96 | ||
|
97 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
|
98 | ||
|
99 | QLineSeriesPrivate::QLineSeriesPrivate(QLineSeries* q):QXYSeriesPrivate(q) | |
|
100 | { | |
|
101 | ||
|
102 | }; | |
|
98 | 103 | |
|
99 | 104 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -27,20 +27,23 | |||
|
27 | 27 | |
|
28 | 28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
29 | 29 | |
|
30 | class QLineSeriesPrivate; | |
|
31 | ||
|
30 | 32 | class QTCOMMERCIALCHART_EXPORT QLineSeries : public QXYSeries |
|
31 | 33 | { |
|
32 | 34 | public: |
|
33 | QLineSeries(QObject *parent=0); | |
|
34 |
|
|
|
35 | explicit QLineSeries(QObject *parent=0); | |
|
36 | ~QLineSeries(); | |
|
37 | ||
|
38 | QSeries::QSeriesType type() const; | |
|
35 | 39 | |
|
36 | void setPointsVisible(bool visible); | |
|
37 | bool pointsVisible() const {return m_pointsVisible;} | |
|
40 | protected: | |
|
41 | QLineSeries(QLineSeriesPrivate &d,QObject *parent = 0); | |
|
38 | 42 | |
|
39 | public: // from QChartSeries | |
|
40 | virtual QSeriesType type() const {return QSeries::SeriesTypeLine;} | |
|
41 | friend QDebug operator<< (QDebug d, const QLineSeries series); | |
|
42 | 43 | private: |
|
43 | bool m_pointsVisible; | |
|
44 | Q_DECLARE_PRIVATE(QLineSeries); | |
|
45 | Q_DISABLE_COPY(QLineSeries); | |
|
46 | friend class LineChartItem; | |
|
44 | 47 | |
|
45 | 48 | }; |
|
46 | 49 |
@@ -11,7 +11,7 PRIVATE_HEADERS += \ | |||
|
11 | 11 | $$PWD/pieslicedata_p.h \ |
|
12 | 12 | $$PWD/piechartitem_p.h \ |
|
13 | 13 | $$PWD/piesliceitem_p.h \ |
|
14 |
$$PWD/qpieseries |
|
|
14 | $$PWD/qpieseries_p.h | |
|
15 | 15 | |
|
16 | 16 | PUBLIC_HEADERS += \ |
|
17 | 17 | $$PWD/qpieseries.h \ |
@@ -19,7 +19,7 | |||
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #include "qpieseries.h" |
|
22 |
#include "qpieseries |
|
|
22 | #include "qpieseries_p.h" | |
|
23 | 23 | #include "qpieslice.h" |
|
24 | 24 | #include "pieslicedata_p.h" |
|
25 | 25 | #include <QAbstractItemModel> |
@@ -27,191 +27,6 | |||
|
27 | 27 | |
|
28 | 28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
29 | 29 | |
|
30 | QPieSeriesPrivate::QPieSeriesPrivate(QPieSeries *parent) | |
|
31 | :QObject(parent), | |
|
32 | q_ptr(parent), | |
|
33 | m_pieRelativeHorPos(0.5), | |
|
34 | m_pieRelativeVerPos(0.5), | |
|
35 | m_pieRelativeSize(0.7), | |
|
36 | m_pieStartAngle(0), | |
|
37 | m_pieEndAngle(360), | |
|
38 | m_total(0), | |
|
39 | m_mapValues(0), | |
|
40 | m_mapLabels(0), | |
|
41 | m_mapOrientation(Qt::Horizontal) | |
|
42 | { | |
|
43 | ||
|
44 | } | |
|
45 | ||
|
46 | QPieSeriesPrivate::~QPieSeriesPrivate() | |
|
47 | { | |
|
48 | ||
|
49 | } | |
|
50 | ||
|
51 | void QPieSeriesPrivate::updateDerivativeData() | |
|
52 | { | |
|
53 | m_total = 0; | |
|
54 | ||
|
55 | // nothing to do? | |
|
56 | if (m_slices.count() == 0) | |
|
57 | return; | |
|
58 | ||
|
59 | // calculate total | |
|
60 | foreach (QPieSlice* s, m_slices) | |
|
61 | m_total += s->value(); | |
|
62 | ||
|
63 | // nothing to show.. | |
|
64 | if (qFuzzyIsNull(m_total)) | |
|
65 | return; | |
|
66 | ||
|
67 | // update slice attributes | |
|
68 | qreal sliceAngle = m_pieStartAngle; | |
|
69 | qreal pieSpan = m_pieEndAngle - m_pieStartAngle; | |
|
70 | QVector<QPieSlice*> changed; | |
|
71 | foreach (QPieSlice* s, m_slices) { | |
|
72 | ||
|
73 | PieSliceData data = PieSliceData::data(s); | |
|
74 | data.m_percentage = s->value() / m_total; | |
|
75 | data.m_angleSpan = pieSpan * data.m_percentage; | |
|
76 | data.m_startAngle = sliceAngle; | |
|
77 | sliceAngle += data.m_angleSpan; | |
|
78 | ||
|
79 | if (PieSliceData::data(s) != data) { | |
|
80 | PieSliceData::data(s) = data; | |
|
81 | changed << s; | |
|
82 | } | |
|
83 | } | |
|
84 | ||
|
85 | // emit signals | |
|
86 | foreach (QPieSlice* s, changed) | |
|
87 | PieSliceData::data(s).emitChangedSignal(s); | |
|
88 | } | |
|
89 | ||
|
90 | void QPieSeriesPrivate::sliceChanged() | |
|
91 | { | |
|
92 | Q_ASSERT(m_slices.contains(qobject_cast<QPieSlice *>(sender()))); | |
|
93 | updateDerivativeData(); | |
|
94 | } | |
|
95 | ||
|
96 | void QPieSeriesPrivate::sliceClicked(Qt::MouseButtons buttons) | |
|
97 | { | |
|
98 | QPieSlice* slice = qobject_cast<QPieSlice *>(sender()); | |
|
99 | Q_ASSERT(m_slices.contains(slice)); | |
|
100 | Q_Q(QPieSeries); | |
|
101 | emit q->clicked(slice, buttons); | |
|
102 | } | |
|
103 | ||
|
104 | void QPieSeriesPrivate::sliceHoverEnter() | |
|
105 | { | |
|
106 | QPieSlice* slice = qobject_cast<QPieSlice *>(sender()); | |
|
107 | Q_ASSERT(m_slices.contains(slice)); | |
|
108 | Q_Q(QPieSeries); | |
|
109 | emit q->hoverEnter(slice); | |
|
110 | } | |
|
111 | ||
|
112 | void QPieSeriesPrivate::sliceHoverLeave() | |
|
113 | { | |
|
114 | QPieSlice* slice = qobject_cast<QPieSlice *>(sender()); | |
|
115 | Q_ASSERT(m_slices.contains(slice)); | |
|
116 | Q_Q(QPieSeries); | |
|
117 | emit q->hoverLeave(slice); | |
|
118 | } | |
|
119 | ||
|
120 | void QPieSeriesPrivate::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight) | |
|
121 | { | |
|
122 | Q_UNUSED(bottomRight) | |
|
123 | Q_Q(QPieSeries); | |
|
124 | ||
|
125 | if (m_mapOrientation == Qt::Vertical) | |
|
126 | { | |
|
127 | if (topLeft.column() == m_mapValues) | |
|
128 | if (m_mapValues == m_mapLabels) | |
|
129 | { | |
|
130 | m_slices.at(topLeft.row())->setValue(q->m_model->data(topLeft, Qt::DisplayRole).toDouble()); | |
|
131 | m_slices.at(topLeft.row())->setLabel(q->m_model->data(topLeft, Qt::DisplayRole).toString()); | |
|
132 | } | |
|
133 | else | |
|
134 | { | |
|
135 | m_slices.at(topLeft.row())->setValue(q->m_model->data(topLeft, Qt::DisplayRole).toDouble()); | |
|
136 | } | |
|
137 | else if (topLeft.column() == m_mapLabels) | |
|
138 | m_slices.at(topLeft.row())->setLabel(q->m_model->data(topLeft, Qt::DisplayRole).toString()); | |
|
139 | } | |
|
140 | else | |
|
141 | { | |
|
142 | if (topLeft.row() == m_mapValues) | |
|
143 | if (m_mapValues == m_mapLabels) | |
|
144 | { | |
|
145 | m_slices.at(topLeft.column())->setValue(q->m_model->data(topLeft, Qt::DisplayRole).toDouble()); | |
|
146 | m_slices.at(topLeft.column())->setLabel(q->m_model->data(topLeft, Qt::DisplayRole).toString()); | |
|
147 | } | |
|
148 | else | |
|
149 | { | |
|
150 | m_slices.at(topLeft.column())->setValue(q->m_model->data(topLeft, Qt::DisplayRole).toDouble()); | |
|
151 | } | |
|
152 | else if (topLeft.row() == m_mapLabels) | |
|
153 | m_slices.at(topLeft.column())->setLabel(q->m_model->data(topLeft, Qt::DisplayRole).toString()); | |
|
154 | } | |
|
155 | } | |
|
156 | ||
|
157 | void QPieSeriesPrivate::modelDataAdded(QModelIndex parent, int start, int end) | |
|
158 | { | |
|
159 | Q_UNUSED(parent) | |
|
160 | Q_UNUSED(end) | |
|
161 | Q_Q(QPieSeries); | |
|
162 | ||
|
163 | QPieSlice* newSlice = new QPieSlice; | |
|
164 | newSlice->setLabelVisible(true); | |
|
165 | if (m_mapOrientation == Qt::Vertical) | |
|
166 | { | |
|
167 | newSlice->setValue(q->m_model->data(q->m_model->index(start, m_mapValues), Qt::DisplayRole).toDouble()); | |
|
168 | newSlice->setLabel(q->m_model->data(q->m_model->index(start, m_mapLabels), Qt::DisplayRole).toString()); | |
|
169 | } | |
|
170 | else | |
|
171 | { | |
|
172 | newSlice->setValue(q->m_model->data(q->m_model->index(m_mapValues, start), Qt::DisplayRole).toDouble()); | |
|
173 | newSlice->setLabel(q->m_model->data(q->m_model->index(m_mapLabels, start), Qt::DisplayRole).toString()); | |
|
174 | } | |
|
175 | ||
|
176 | q->insert(start, newSlice); | |
|
177 | } | |
|
178 | ||
|
179 | void QPieSeriesPrivate::modelDataRemoved(QModelIndex parent, int start, int end) | |
|
180 | { | |
|
181 | Q_UNUSED(parent) | |
|
182 | Q_UNUSED(end) | |
|
183 | Q_Q(QPieSeries); | |
|
184 | q->remove(m_slices.at(start)); | |
|
185 | } | |
|
186 | ||
|
187 | bool QPieSeriesPrivate::setRealValue(qreal &value, qreal newValue, qreal max, qreal min) | |
|
188 | { | |
|
189 | // Remove rounding errors | |
|
190 | qreal roundedValue = newValue; | |
|
191 | if (qFuzzyIsNull(min) && qFuzzyIsNull(newValue)) | |
|
192 | roundedValue = 0.0; | |
|
193 | else if (qFuzzyCompare(newValue, max)) | |
|
194 | roundedValue = max; | |
|
195 | else if (qFuzzyCompare(newValue, min)) | |
|
196 | roundedValue = min; | |
|
197 | ||
|
198 | // Check if the position is valid after removing the rounding errors | |
|
199 | if (roundedValue < min || roundedValue > max) { | |
|
200 | qWarning("QPieSeries: Illegal value"); | |
|
201 | return false; | |
|
202 | } | |
|
203 | ||
|
204 | if (!qFuzzyIsNull(value - roundedValue)) { | |
|
205 | value = roundedValue; | |
|
206 | return true; | |
|
207 | } | |
|
208 | ||
|
209 | // The change was so small it is considered a rounding error | |
|
210 | return false; | |
|
211 | } | |
|
212 | ||
|
213 | ||
|
214 | ||
|
215 | 30 | /*! |
|
216 | 31 | \class QPieSeries |
|
217 | 32 | \brief Pie series API for QtCommercial Charts |
@@ -289,8 +104,7 bool QPieSeriesPrivate::setRealValue(qreal &value, qreal newValue, qreal max, qr | |||
|
289 | 104 | Constructs a series object which is a child of \a parent. |
|
290 | 105 | */ |
|
291 | 106 | QPieSeries::QPieSeries(QObject *parent) : |
|
292 | QSeries(parent), | |
|
293 | d_ptr(new QPieSeriesPrivate(this)) | |
|
107 | QSeries(*new QPieSeriesPrivate(this),parent) | |
|
294 | 108 | { |
|
295 | 109 | |
|
296 | 110 | } |
@@ -636,9 +450,9 bool QPieSeries::setModel(QAbstractItemModel* model) | |||
|
636 | 450 | { |
|
637 | 451 | Q_D(QPieSeries); |
|
638 | 452 | // disconnect signals from old model |
|
639 | if(m_model) | |
|
453 | if(d->m_model) | |
|
640 | 454 | { |
|
641 | disconnect(m_model, 0, this, 0); | |
|
455 | disconnect(d->m_model, 0, this, 0); | |
|
642 | 456 | d->m_mapValues = -1; |
|
643 | 457 | d->m_mapLabels = -1; |
|
644 | 458 | d->m_mapOrientation = Qt::Vertical; |
@@ -647,12 +461,12 bool QPieSeries::setModel(QAbstractItemModel* model) | |||
|
647 | 461 | // set new model |
|
648 | 462 | if(model) |
|
649 | 463 | { |
|
650 | m_model = model; | |
|
464 | d->m_model = model; | |
|
651 | 465 | return true; |
|
652 | 466 | } |
|
653 | 467 | else |
|
654 | 468 | { |
|
655 | m_model = 0; | |
|
469 | d->m_model = 0; | |
|
656 | 470 | return false; |
|
657 | 471 | } |
|
658 | 472 | } |
@@ -668,7 +482,7 void QPieSeries::setModelMapping(int modelValuesLine, int modelLabelsLine, Qt::O | |||
|
668 | 482 | { |
|
669 | 483 | Q_D(QPieSeries); |
|
670 | 484 | |
|
671 | if (m_model == 0) | |
|
485 | if (d->m_model == 0) | |
|
672 | 486 | return; |
|
673 | 487 | |
|
674 | 488 | d->m_mapValues = modelValuesLine; |
@@ -677,26 +491,211 void QPieSeries::setModelMapping(int modelValuesLine, int modelLabelsLine, Qt::O | |||
|
677 | 491 | |
|
678 | 492 | // connect the signals |
|
679 | 493 | if (d->m_mapOrientation == Qt::Vertical) { |
|
680 | connect(m_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), d, SLOT(modelUpdated(QModelIndex, QModelIndex))); | |
|
681 | connect(m_model, SIGNAL(rowsInserted(QModelIndex, int, int)), d, SLOT(modelDataAdded(QModelIndex,int,int))); | |
|
682 | connect(m_model, SIGNAL(rowsRemoved(QModelIndex, int, int)), d, SLOT(modelDataRemoved(QModelIndex,int,int))); | |
|
494 | connect(d->m_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), d, SLOT(modelUpdated(QModelIndex, QModelIndex))); | |
|
495 | connect(d->m_model, SIGNAL(rowsInserted(QModelIndex, int, int)), d, SLOT(modelDataAdded(QModelIndex,int,int))); | |
|
496 | connect(d->m_model, SIGNAL(rowsRemoved(QModelIndex, int, int)), d, SLOT(modelDataRemoved(QModelIndex,int,int))); | |
|
683 | 497 | } else { |
|
684 | connect(m_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), d, SLOT(modelUpdated(QModelIndex, QModelIndex))); | |
|
685 | connect(m_model, SIGNAL(columnsInserted(QModelIndex, int, int)), d, SLOT(modelDataAdded(QModelIndex,int,int))); | |
|
686 | connect(m_model, SIGNAL(columnsRemoved(QModelIndex, int, int)), d, SLOT(modelDataRemoved(QModelIndex,int,int))); | |
|
498 | connect(d->m_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), d, SLOT(modelUpdated(QModelIndex, QModelIndex))); | |
|
499 | connect(d->m_model, SIGNAL(columnsInserted(QModelIndex, int, int)), d, SLOT(modelDataAdded(QModelIndex,int,int))); | |
|
500 | connect(d->m_model, SIGNAL(columnsRemoved(QModelIndex, int, int)), d, SLOT(modelDataRemoved(QModelIndex,int,int))); | |
|
687 | 501 | } |
|
688 | 502 | |
|
689 | 503 | // create the initial slices set |
|
690 | 504 | if (d->m_mapOrientation == Qt::Vertical) { |
|
691 | for (int i = 0; i < m_model->rowCount(); i++) | |
|
692 | append(m_model->data(m_model->index(i, d->m_mapValues), Qt::DisplayRole).toDouble(), m_model->data(m_model->index(i, d->m_mapLabels), Qt::DisplayRole).toString()); | |
|
505 | for (int i = 0; i < d->m_model->rowCount(); i++) | |
|
506 | append(d->m_model->data(d->m_model->index(i, d->m_mapValues), Qt::DisplayRole).toDouble(), d->m_model->data(d->m_model->index(i, d->m_mapLabels), Qt::DisplayRole).toString()); | |
|
693 | 507 | } else { |
|
694 | for (int i = 0; i < m_model->columnCount(); i++) | |
|
695 | append(m_model->data(m_model->index(d->m_mapValues, i), Qt::DisplayRole).toDouble(), m_model->data(m_model->index(d->m_mapLabels, i), Qt::DisplayRole).toString()); | |
|
508 | for (int i = 0; i < d->m_model->columnCount(); i++) | |
|
509 | append(d->m_model->data(d->m_model->index(d->m_mapValues, i), Qt::DisplayRole).toDouble(), d->m_model->data(d->m_model->index(d->m_mapLabels, i), Qt::DisplayRole).toString()); | |
|
696 | 510 | } |
|
697 | 511 | } |
|
698 | 512 | |
|
513 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
|
514 | ||
|
515 | ||
|
516 | QPieSeriesPrivate::QPieSeriesPrivate(QPieSeries *parent) | |
|
517 | :QSeriesPrivate(parent), | |
|
518 | m_pieRelativeHorPos(0.5), | |
|
519 | m_pieRelativeVerPos(0.5), | |
|
520 | m_pieRelativeSize(0.7), | |
|
521 | m_pieStartAngle(0), | |
|
522 | m_pieEndAngle(360), | |
|
523 | m_total(0), | |
|
524 | m_mapValues(0), | |
|
525 | m_mapLabels(0), | |
|
526 | m_mapOrientation(Qt::Horizontal) | |
|
527 | { | |
|
528 | ||
|
529 | } | |
|
530 | ||
|
531 | QPieSeriesPrivate::~QPieSeriesPrivate() | |
|
532 | { | |
|
533 | ||
|
534 | } | |
|
535 | ||
|
536 | void QPieSeriesPrivate::updateDerivativeData() | |
|
537 | { | |
|
538 | m_total = 0; | |
|
539 | ||
|
540 | // nothing to do? | |
|
541 | if (m_slices.count() == 0) | |
|
542 | return; | |
|
543 | ||
|
544 | // calculate total | |
|
545 | foreach (QPieSlice* s, m_slices) | |
|
546 | m_total += s->value(); | |
|
547 | ||
|
548 | // nothing to show.. | |
|
549 | if (qFuzzyIsNull(m_total)) | |
|
550 | return; | |
|
551 | ||
|
552 | // update slice attributes | |
|
553 | qreal sliceAngle = m_pieStartAngle; | |
|
554 | qreal pieSpan = m_pieEndAngle - m_pieStartAngle; | |
|
555 | QVector<QPieSlice*> changed; | |
|
556 | foreach (QPieSlice* s, m_slices) { | |
|
557 | ||
|
558 | PieSliceData data = PieSliceData::data(s); | |
|
559 | data.m_percentage = s->value() / m_total; | |
|
560 | data.m_angleSpan = pieSpan * data.m_percentage; | |
|
561 | data.m_startAngle = sliceAngle; | |
|
562 | sliceAngle += data.m_angleSpan; | |
|
563 | ||
|
564 | if (PieSliceData::data(s) != data) { | |
|
565 | PieSliceData::data(s) = data; | |
|
566 | changed << s; | |
|
567 | } | |
|
568 | } | |
|
569 | ||
|
570 | // emit signals | |
|
571 | foreach (QPieSlice* s, changed) | |
|
572 | PieSliceData::data(s).emitChangedSignal(s); | |
|
573 | } | |
|
574 | ||
|
575 | void QPieSeriesPrivate::sliceChanged() | |
|
576 | { | |
|
577 | Q_ASSERT(m_slices.contains(qobject_cast<QPieSlice *>(sender()))); | |
|
578 | updateDerivativeData(); | |
|
579 | } | |
|
580 | ||
|
581 | void QPieSeriesPrivate::sliceClicked(Qt::MouseButtons buttons) | |
|
582 | { | |
|
583 | QPieSlice* slice = qobject_cast<QPieSlice *>(sender()); | |
|
584 | Q_ASSERT(m_slices.contains(slice)); | |
|
585 | Q_Q(QPieSeries); | |
|
586 | emit q->clicked(slice, buttons); | |
|
587 | } | |
|
588 | ||
|
589 | void QPieSeriesPrivate::sliceHoverEnter() | |
|
590 | { | |
|
591 | QPieSlice* slice = qobject_cast<QPieSlice *>(sender()); | |
|
592 | Q_ASSERT(m_slices.contains(slice)); | |
|
593 | Q_Q(QPieSeries); | |
|
594 | emit q->hoverEnter(slice); | |
|
595 | } | |
|
596 | ||
|
597 | void QPieSeriesPrivate::sliceHoverLeave() | |
|
598 | { | |
|
599 | QPieSlice* slice = qobject_cast<QPieSlice *>(sender()); | |
|
600 | Q_ASSERT(m_slices.contains(slice)); | |
|
601 | Q_Q(QPieSeries); | |
|
602 | emit q->hoverLeave(slice); | |
|
603 | } | |
|
604 | ||
|
605 | void QPieSeriesPrivate::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight) | |
|
606 | { | |
|
607 | Q_UNUSED(bottomRight) | |
|
608 | ||
|
609 | if (m_mapOrientation == Qt::Vertical) | |
|
610 | { | |
|
611 | if (topLeft.column() == m_mapValues) | |
|
612 | if (m_mapValues == m_mapLabels) | |
|
613 | { | |
|
614 | m_slices.at(topLeft.row())->setValue(m_model->data(topLeft, Qt::DisplayRole).toDouble()); | |
|
615 | m_slices.at(topLeft.row())->setLabel(m_model->data(topLeft, Qt::DisplayRole).toString()); | |
|
616 | } | |
|
617 | else | |
|
618 | { | |
|
619 | m_slices.at(topLeft.row())->setValue(m_model->data(topLeft, Qt::DisplayRole).toDouble()); | |
|
620 | } | |
|
621 | else if (topLeft.column() == m_mapLabels) | |
|
622 | m_slices.at(topLeft.row())->setLabel(m_model->data(topLeft, Qt::DisplayRole).toString()); | |
|
623 | } | |
|
624 | else | |
|
625 | { | |
|
626 | if (topLeft.row() == m_mapValues) | |
|
627 | if (m_mapValues == m_mapLabels) | |
|
628 | { | |
|
629 | m_slices.at(topLeft.column())->setValue(m_model->data(topLeft, Qt::DisplayRole).toDouble()); | |
|
630 | m_slices.at(topLeft.column())->setLabel(m_model->data(topLeft, Qt::DisplayRole).toString()); | |
|
631 | } | |
|
632 | else | |
|
633 | { | |
|
634 | m_slices.at(topLeft.column())->setValue(m_model->data(topLeft, Qt::DisplayRole).toDouble()); | |
|
635 | } | |
|
636 | else if (topLeft.row() == m_mapLabels) | |
|
637 | m_slices.at(topLeft.column())->setLabel(m_model->data(topLeft, Qt::DisplayRole).toString()); | |
|
638 | } | |
|
639 | } | |
|
640 | ||
|
641 | void QPieSeriesPrivate::modelDataAdded(QModelIndex parent, int start, int end) | |
|
642 | { | |
|
643 | Q_UNUSED(parent) | |
|
644 | Q_UNUSED(end) | |
|
645 | Q_Q(QPieSeries); | |
|
646 | ||
|
647 | QPieSlice* newSlice = new QPieSlice; | |
|
648 | newSlice->setLabelVisible(true); | |
|
649 | if (m_mapOrientation == Qt::Vertical) | |
|
650 | { | |
|
651 | newSlice->setValue(m_model->data(m_model->index(start, m_mapValues), Qt::DisplayRole).toDouble()); | |
|
652 | newSlice->setLabel(m_model->data(m_model->index(start, m_mapLabels), Qt::DisplayRole).toString()); | |
|
653 | } | |
|
654 | else | |
|
655 | { | |
|
656 | newSlice->setValue(m_model->data(m_model->index(m_mapValues, start), Qt::DisplayRole).toDouble()); | |
|
657 | newSlice->setLabel(m_model->data(m_model->index(m_mapLabels, start), Qt::DisplayRole).toString()); | |
|
658 | } | |
|
659 | ||
|
660 | q->insert(start, newSlice); | |
|
661 | } | |
|
662 | ||
|
663 | void QPieSeriesPrivate::modelDataRemoved(QModelIndex parent, int start, int end) | |
|
664 | { | |
|
665 | Q_UNUSED(parent) | |
|
666 | Q_UNUSED(end) | |
|
667 | Q_Q(QPieSeries); | |
|
668 | q->remove(m_slices.at(start)); | |
|
669 | } | |
|
670 | ||
|
671 | bool QPieSeriesPrivate::setRealValue(qreal &value, qreal newValue, qreal max, qreal min) | |
|
672 | { | |
|
673 | // Remove rounding errors | |
|
674 | qreal roundedValue = newValue; | |
|
675 | if (qFuzzyIsNull(min) && qFuzzyIsNull(newValue)) | |
|
676 | roundedValue = 0.0; | |
|
677 | else if (qFuzzyCompare(newValue, max)) | |
|
678 | roundedValue = max; | |
|
679 | else if (qFuzzyCompare(newValue, min)) | |
|
680 | roundedValue = min; | |
|
681 | ||
|
682 | // Check if the position is valid after removing the rounding errors | |
|
683 | if (roundedValue < min || roundedValue > max) { | |
|
684 | qWarning("QPieSeries: Illegal value"); | |
|
685 | return false; | |
|
686 | } | |
|
687 | ||
|
688 | if (!qFuzzyIsNull(value - roundedValue)) { | |
|
689 | value = roundedValue; | |
|
690 | return true; | |
|
691 | } | |
|
692 | ||
|
693 | // The change was so small it is considered a rounding error | |
|
694 | return false; | |
|
695 | } | |
|
696 | ||
|
697 | ||
|
699 | 698 | #include "moc_qpieseries.cpp" |
|
700 |
#include "moc_qpieseries |
|
|
699 | #include "moc_qpieseries_p.cpp" | |
|
701 | 700 | |
|
702 | 701 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -92,7 +92,6 Q_SIGNALS: | |||
|
92 | 92 | void pieSizeChanged(); |
|
93 | 93 | |
|
94 | 94 | private: |
|
95 | QPieSeriesPrivate * const d_ptr; | |
|
96 | 95 | Q_DECLARE_PRIVATE(QPieSeries) |
|
97 | 96 | Q_DISABLE_COPY(QPieSeries) |
|
98 | 97 | }; |
@@ -18,19 +18,19 | |||
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 |
#ifndef QPIESERIES |
|
|
22 |
#define QPIESERIES |
|
|
21 | #ifndef QPIESERIES_P_H | |
|
22 | #define QPIESERIES_P_H | |
|
23 | 23 | |
|
24 | 24 | #include "qpieseries.h" |
|
25 | #include "qseries_p.h" | |
|
25 | 26 | |
|
26 | 27 | class QModelIndex; |
|
27 | 28 | |
|
28 | 29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
29 | 30 | |
|
30 |
class QPieSeriesPrivate : public Q |
|
|
31 | class QPieSeriesPrivate : public QSeriesPrivate | |
|
31 | 32 | { |
|
32 | 33 | Q_OBJECT |
|
33 | Q_DECLARE_PUBLIC(QPieSeries) | |
|
34 | 34 | |
|
35 | 35 | public: |
|
36 | 36 | QPieSeriesPrivate(QPieSeries *parent); |
@@ -49,8 +49,6 public Q_SLOTS: | |||
|
49 | 49 | bool setRealValue(qreal &value, qreal newValue, qreal max, qreal min = 0.0); |
|
50 | 50 | |
|
51 | 51 | public: |
|
52 | QPieSeries * const q_ptr; | |
|
53 | ||
|
54 | 52 | QList<QPieSlice*> m_slices; |
|
55 | 53 | qreal m_pieRelativeHorPos; |
|
56 | 54 | qreal m_pieRelativeVerPos; |
@@ -63,8 +61,10 public: | |||
|
63 | 61 | int m_mapValues; |
|
64 | 62 | int m_mapLabels; |
|
65 | 63 | Qt::Orientation m_mapOrientation; |
|
64 | private: | |
|
65 | Q_DECLARE_PUBLIC(QPieSeries) | |
|
66 | 66 | }; |
|
67 | 67 | |
|
68 | 68 | QTCOMMERCIALCHART_END_NAMESPACE |
|
69 | 69 | |
|
70 |
#endif // QPIESERIES |
|
|
70 | #endif // QPIESERIES_P_H |
@@ -19,6 +19,9 | |||
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #include "qseries.h" |
|
22 | #include "qseries_p.h" | |
|
23 | ||
|
24 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
|
22 | 25 | |
|
23 | 26 | /*! |
|
24 | 27 | \class QSeries |
@@ -93,5 +96,55 | |||
|
93 | 96 | \sa setName() |
|
94 | 97 | */ |
|
95 | 98 | |
|
96 | QTCOMMERCIALCHART_USE_NAMESPACE | |
|
99 | QSeries::QSeries(QObject *parent) : QObject(parent), | |
|
100 | d_ptr(new QSeriesPrivate(this)) | |
|
101 | { | |
|
102 | ||
|
103 | } | |
|
104 | ||
|
105 | QSeries::QSeries(QSeriesPrivate &d,QObject *parent) : QObject(parent), | |
|
106 | d_ptr(&d) | |
|
107 | { | |
|
108 | ||
|
109 | } | |
|
110 | ||
|
111 | QSeries::~QSeries() | |
|
112 | { | |
|
113 | ||
|
114 | } | |
|
115 | ||
|
116 | QAbstractItemModel* QSeries::model() const | |
|
117 | { | |
|
118 | return d_ptr->m_model; | |
|
119 | } | |
|
120 | ||
|
121 | void QSeries::setName(const QString& name) | |
|
122 | { | |
|
123 | d_ptr->m_name = name; | |
|
124 | } | |
|
125 | ||
|
126 | QString QSeries::name() const | |
|
127 | { | |
|
128 | return d_ptr->m_name; | |
|
129 | } | |
|
130 | ||
|
131 | /////////////////////////////////////////////////////////////////////////////////////////////////// | |
|
132 | ||
|
133 | QSeriesPrivate::QSeriesPrivate(QSeries* q): q_ptr(q),m_model(0) | |
|
134 | { | |
|
135 | ||
|
136 | } | |
|
137 | ||
|
138 | QSeriesPrivate::~QSeriesPrivate() | |
|
139 | { | |
|
140 | ||
|
141 | } | |
|
142 | ||
|
143 | ||
|
144 | ||
|
145 | ||
|
97 | 146 | #include "moc_qseries.cpp" |
|
147 | ||
|
148 | QTCOMMERCIALCHART_END_NAMESPACE | |
|
149 | ||
|
150 |
@@ -29,10 +29,13 class QAbstractItemModel; | |||
|
29 | 29 | |
|
30 | 30 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
31 | 31 | |
|
32 | class QSeriesPrivate; | |
|
33 | ||
|
32 | 34 | class QTCOMMERCIALCHART_EXPORT QSeries : public QObject |
|
33 | 35 | { |
|
34 | 36 | Q_OBJECT |
|
35 | 37 | Q_PROPERTY(QString name READ name WRITE setName) |
|
38 | Q_ENUMS(QSeriesType) | |
|
36 | 39 | |
|
37 | 40 | public: |
|
38 | 41 | enum QSeriesType { |
@@ -47,23 +50,20 public: | |||
|
47 | 50 | }; |
|
48 | 51 | |
|
49 | 52 | protected: |
|
50 |
QSeries(QObject *parent = 0) |
|
|
53 | QSeries(QObject *parent = 0); | |
|
54 | QSeries(QSeriesPrivate &d,QObject *parent = 0); | |
|
51 | 55 | |
|
52 | 56 | public: |
|
53 |
|
|
|
57 | ~QSeries(); | |
|
54 | 58 | virtual QSeriesType type() const = 0; |
|
55 | 59 | // TODO |
|
56 |
virtual bool setModel(QAbstractItemModel* |
|
|
57 |
QAbstractItemModel* model() const |
|
|
58 | ||
|
59 | void setName(QString name) { m_name = name; } | |
|
60 | QString name() const { return m_name; } | |
|
60 | virtual bool setModel(QAbstractItemModel* model) = 0; | |
|
61 | QAbstractItemModel* model() const; | |
|
62 | void setName(const QString& name); | |
|
63 | QString name() const; | |
|
61 | 64 | |
|
62 | 65 | protected: |
|
63 | QAbstractItemModel* m_model; | |
|
64 | ||
|
65 | private: | |
|
66 | QString m_name; | |
|
66 | QScopedPointer<QSeriesPrivate> d_ptr; | |
|
67 | 67 | }; |
|
68 | 68 | |
|
69 | 69 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -19,7 +19,7 | |||
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #include "qscatterseries.h" |
|
22 |
#include "q |
|
|
22 | #include "qscatterseries_p.h" | |
|
23 | 23 | |
|
24 | 24 | /*! |
|
25 | 25 | \class QScatterSeries |
@@ -62,10 +62,7 QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||
|
62 | 62 | /*! |
|
63 | 63 | Constructs a series object which is a child of \a parent. |
|
64 | 64 | */ |
|
65 | QScatterSeries::QScatterSeries(QObject *parent) : | |
|
66 | QXYSeries(parent), | |
|
67 | m_shape(QScatterSeries::MarkerShapeCircle), | |
|
68 | m_size(15.0) | |
|
65 | QScatterSeries::QScatterSeries(QObject *parent) : QXYSeries(*new QScatterSeriesPrivate(this),parent) | |
|
69 | 66 | { |
|
70 | 67 | } |
|
71 | 68 | |
@@ -76,12 +73,18 QScatterSeries::~QScatterSeries() | |||
|
76 | 73 | { |
|
77 | 74 | } |
|
78 | 75 | |
|
76 | QSeries::QSeriesType QScatterSeries::type() const | |
|
77 | { | |
|
78 | return QSeries::SeriesTypeScatter; | |
|
79 | } | |
|
80 | ||
|
79 | 81 | /*! |
|
80 | 82 | Returns the shape used for drawing markers. |
|
81 | 83 | */ |
|
82 | 84 | QScatterSeries::MarkerShape QScatterSeries::shape() const |
|
83 | 85 | { |
|
84 | return m_shape; | |
|
86 | Q_D(const QScatterSeries); | |
|
87 | return d->m_shape; | |
|
85 | 88 | } |
|
86 | 89 | |
|
87 | 90 | /*! |
@@ -90,9 +93,10 QScatterSeries::MarkerShape QScatterSeries::shape() const | |||
|
90 | 93 | */ |
|
91 | 94 | void QScatterSeries::setShape(MarkerShape shape) |
|
92 | 95 | { |
|
93 | if (m_shape != shape) { | |
|
94 |
|
|
|
95 | emit QXYSeries::updated(); | |
|
96 | Q_D(QScatterSeries); | |
|
97 | if (d->m_shape != shape) { | |
|
98 | d->m_shape = shape; | |
|
99 | emit d->updated(); | |
|
96 | 100 | } |
|
97 | 101 | } |
|
98 | 102 | |
@@ -101,7 +105,8 void QScatterSeries::setShape(MarkerShape shape) | |||
|
101 | 105 | */ |
|
102 | 106 | qreal QScatterSeries::size() const |
|
103 | 107 | { |
|
104 | return m_size; | |
|
108 | Q_D(const QScatterSeries); | |
|
109 | return d->m_size; | |
|
105 | 110 | } |
|
106 | 111 | |
|
107 | 112 | /*! |
@@ -109,10 +114,22 qreal QScatterSeries::size() const | |||
|
109 | 114 | */ |
|
110 | 115 | void QScatterSeries::setSize(qreal size) |
|
111 | 116 | { |
|
112 | if (!qFuzzyIsNull(m_size - size)) { | |
|
113 | m_size = size; | |
|
114 | emit updated(); | |
|
117 | Q_D(QScatterSeries); | |
|
118 | ||
|
119 | if (!qFuzzyIsNull(d->m_size - size)) { | |
|
120 | d->m_size = size; | |
|
121 | emit d->updated(); | |
|
115 | 122 | } |
|
116 | 123 | } |
|
117 | 124 | |
|
125 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
|
126 | ||
|
127 | QScatterSeriesPrivate::QScatterSeriesPrivate(QScatterSeries* q):QXYSeriesPrivate(q), | |
|
128 | m_shape(QScatterSeries::MarkerShapeCircle), | |
|
129 | m_size(15.0) | |
|
130 | { | |
|
131 | ||
|
132 | }; | |
|
133 | ||
|
134 | ||
|
118 | 135 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -25,6 +25,7 | |||
|
25 | 25 | #include <qxyseries.h> |
|
26 | 26 | |
|
27 | 27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
28 | ||
|
28 | 29 | class QScatterSeriesPrivate; |
|
29 | 30 | |
|
30 | 31 | class QTCOMMERCIALCHART_EXPORT QScatterSeries : public QXYSeries |
@@ -37,21 +38,21 public: | |||
|
37 | 38 | }; |
|
38 | 39 | |
|
39 | 40 | public: |
|
40 | QScatterSeries(QObject *parent = 0); | |
|
41 | explicit QScatterSeries(QObject *parent = 0); | |
|
41 | 42 | ~QScatterSeries(); |
|
42 | 43 | |
|
43 | public: // from QChartSeries | |
|
44 | QSeriesType type() const { return QSeries::SeriesTypeScatter; } | |
|
44 | QSeries::QSeriesType type() const; | |
|
45 | 45 | |
|
46 | public: | |
|
47 | 46 | MarkerShape shape() const; |
|
48 | 47 | void setShape(MarkerShape shape); |
|
49 | 48 | qreal size() const; |
|
50 | 49 | void setSize(qreal size); |
|
51 | 50 | |
|
52 | 51 | private: |
|
53 | MarkerShape m_shape; | |
|
54 | qreal m_size; | |
|
52 | Q_DECLARE_PRIVATE(QScatterSeries); | |
|
53 | Q_DISABLE_COPY(QScatterSeries); | |
|
54 | friend class ScatterChartItem; | |
|
55 | ||
|
55 | 56 | }; |
|
56 | 57 | |
|
57 | 58 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -6,7 +6,8 SOURCES += \ | |||
|
6 | 6 | $$PWD/scatterchartitem.cpp |
|
7 | 7 | |
|
8 | 8 | PRIVATE_HEADERS += \ |
|
9 | $$PWD/scatterchartitem_p.h | |
|
9 | $$PWD/scatterchartitem_p.h \ | |
|
10 | $$PWD/qscatterseries_p.h | |
|
10 | 11 | |
|
11 | 12 | PUBLIC_HEADERS += \ |
|
12 | 13 | $$PWD/qscatterseries.h |
@@ -20,6 +20,7 | |||
|
20 | 20 | |
|
21 | 21 | #include "scatterchartitem_p.h" |
|
22 | 22 | #include "qscatterseries.h" |
|
23 | #include "qscatterseries_p.h" | |
|
23 | 24 | #include "chartpresenter_p.h" |
|
24 | 25 | #include <QPainter> |
|
25 | 26 | #include <QGraphicsScene> |
@@ -34,7 +35,7 ScatterChartItem::ScatterChartItem(QScatterSeries *series, ChartPresenter *prese | |||
|
34 | 35 | m_size(15) |
|
35 | 36 | |
|
36 | 37 | { |
|
37 | QObject::connect(m_series,SIGNAL(updated()), this, SLOT(handleUpdated())); | |
|
38 | QObject::connect(m_series->d_func(),SIGNAL(updated()), this, SLOT(handleUpdated())); | |
|
38 | 39 | |
|
39 | 40 | setZValue(ChartPresenter::ScatterSeriesZValue); |
|
40 | 41 | setFlags(QGraphicsItem::ItemClipsChildrenToShape); |
@@ -19,6 +19,7 | |||
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #include "qsplineseries.h" |
|
22 | #include "qsplineseries_p.h" | |
|
22 | 23 | |
|
23 | 24 | /*! |
|
24 | 25 | \class QSplineSeries |
@@ -46,32 +47,57 QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||
|
46 | 47 | */ |
|
47 | 48 | |
|
48 | 49 | QSplineSeries::QSplineSeries(QObject *parent) : |
|
49 | QLineSeries(parent) | |
|
50 | QLineSeries(*new QSplineSeriesPrivate(this),parent) | |
|
50 | 51 | { |
|
51 | connect(this,SIGNAL(pointAdded(int)), this, SLOT(updateControlPoints())); | |
|
52 | connect(this,SIGNAL(pointRemoved(int)), this, SLOT(updateControlPoints())); | |
|
53 | connect(this,SIGNAL(pointReplaced(int)), this, SLOT(updateControlPoints())); | |
|
54 | 52 | } |
|
55 | 53 | |
|
54 | QSeries::QSeriesType QSplineSeries::type() const | |
|
55 | { | |
|
56 | return QSeries::SeriesTypeSpline; | |
|
57 | } | |
|
58 | ||
|
59 | QPointF QSplineSeries::controlPoint(int index) const | |
|
60 | { | |
|
61 | Q_D(const QSplineSeries); | |
|
62 | return d->m_controlPoints[index]; | |
|
63 | } | |
|
64 | ||
|
65 | void QSplineSeries::setModelMappingRange(int first, int count) | |
|
66 | { | |
|
67 | Q_D(QSplineSeries); | |
|
68 | QLineSeries::setModelMappingRange(first, count); | |
|
69 | d->calculateControlPoints(); | |
|
70 | } | |
|
71 | ||
|
72 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
|
73 | ||
|
74 | QSplineSeriesPrivate::QSplineSeriesPrivate(QSplineSeries* q):QLineSeriesPrivate(q) | |
|
75 | { | |
|
76 | QObject::connect(this,SIGNAL(pointAdded(int)), this, SLOT(updateControlPoints())); | |
|
77 | QObject::connect(this,SIGNAL(pointRemoved(int)), this, SLOT(updateControlPoints())); | |
|
78 | QObject::connect(this,SIGNAL(pointReplaced(int)), this, SLOT(updateControlPoints())); | |
|
79 | }; | |
|
80 | ||
|
56 | 81 | /*! |
|
57 | 82 | \internal |
|
58 | 83 | Calculates control points which are needed by QPainterPath.cubicTo function to draw the cubic Bezier cureve between two points. |
|
59 | 84 | */ |
|
60 | void QSplineSeries::calculateControlPoints() | |
|
85 | void QSplineSeriesPrivate::calculateControlPoints() | |
|
61 | 86 | { |
|
62 | 87 | |
|
88 | Q_Q(QSplineSeries); | |
|
63 | 89 | // Based on http://www.codeproject.com/Articles/31859/Draw-a-Smooth-Curve-through-a-Set-of-2D-Points-wit |
|
64 | 90 | // CPOL License |
|
65 | 91 | |
|
66 | int n = count() - 1; | |
|
92 | int n = q->count() - 1; | |
|
67 | 93 | if (n == 1) |
|
68 | 94 | { // Special case: Bezier curve should be a straight line. |
|
69 | 95 | // firstControlPoints = new Point[1]; |
|
70 | 96 | // 3P1 = 2P0 + P3 |
|
71 | m_controlPoints.append(QPointF((2 * x(0) + x(1)) / 3, (2 * y(0) + y(1)) / 3)); | |
|
97 | m_controlPoints.append(QPointF((2 * q->x(0) + q->x(1)) / 3, (2 * q->y(0) + q->y(1)) / 3)); | |
|
72 | 98 | |
|
73 | 99 | // P2 = 2P1 P0 |
|
74 | m_controlPoints.append(QPointF(2 * m_controlPoints[0].x() - x(0), 2 * m_controlPoints[0].y() - y(0))); | |
|
100 | m_controlPoints.append(QPointF(2 * m_controlPoints[0].x() - q->x(0), 2 * m_controlPoints[0].y() - q->y(0))); | |
|
75 | 101 | return; |
|
76 | 102 | } |
|
77 | 103 | |
@@ -89,22 +115,22 void QSplineSeries::calculateControlPoints() | |||
|
89 | 115 | // | 0 0 0 0 0 0 0 0 ... 0 2 7 | | P1_n | | 8 * P(n-1) + Pn | |
|
90 | 116 | // |
|
91 | 117 | QList<qreal> rhs; |
|
92 | rhs.append(x(0) + 2 * x(1)); | |
|
118 | rhs.append(q->x(0) + 2 * q->x(1)); | |
|
93 | 119 | |
|
94 | 120 | // Set right hand side X values |
|
95 | 121 | for (int i = 1; i < n - 1; ++i) |
|
96 | rhs.append(4 * x(i) + 2 * x(i + 1)); | |
|
122 | rhs.append(4 * q->x(i) + 2 * q->x(i + 1)); | |
|
97 | 123 | |
|
98 | rhs.append((8 * x(n - 1) + x(n)) / 2.0); | |
|
124 | rhs.append((8 * q->x(n - 1) + q->x(n)) / 2.0); | |
|
99 | 125 | // Get first control points X-values |
|
100 | 126 | QList<qreal> xControl = getFirstControlPoints(rhs); |
|
101 | rhs[0] = y(0) + 2 * y(1); | |
|
127 | rhs[0] = q->y(0) + 2 * q->y(1); | |
|
102 | 128 | |
|
103 | 129 | // Set right hand side Y values |
|
104 | 130 | for (int i = 1; i < n - 1; ++i) |
|
105 | rhs[i] = 4 * y(i) + 2 * y(i + 1); | |
|
131 | rhs[i] = 4 * q->y(i) + 2 * q->y(i + 1); | |
|
106 | 132 | |
|
107 | rhs[n - 1] = (8 * y(n - 1) + y(n)) / 2.0; | |
|
133 | rhs[n - 1] = (8 * q->y(n - 1) + q->y(n)) / 2.0; | |
|
108 | 134 | // Get first control points Y-values |
|
109 | 135 | QList<qreal> yControl = getFirstControlPoints(rhs); |
|
110 | 136 | |
@@ -114,16 +140,16 void QSplineSeries::calculateControlPoints() | |||
|
114 | 140 | m_controlPoints.append(QPointF(xControl[i], yControl[i])); |
|
115 | 141 | // Second control point |
|
116 | 142 | if (i < n - 1) |
|
117 | m_controlPoints.append(QPointF(2 * x(i + 1) - xControl[i + 1], 2 * y(i + 1) - yControl[i + 1])); | |
|
143 | m_controlPoints.append(QPointF(2 * q->x(i + 1) - xControl[i + 1], 2 * q->y(i + 1) - yControl[i + 1])); | |
|
118 | 144 | else |
|
119 | m_controlPoints.append(QPointF((x(n) + xControl[n - 1]) / 2, (y(n) + yControl[n - 1]) / 2)); | |
|
145 | m_controlPoints.append(QPointF((q->x(n) + xControl[n - 1]) / 2, (q->y(n) + yControl[n - 1]) / 2)); | |
|
120 | 146 | } |
|
121 | 147 | } |
|
122 | 148 | |
|
123 | 149 | /*! |
|
124 | 150 | \internal |
|
125 | 151 | */ |
|
126 | QList<qreal> QSplineSeries::getFirstControlPoints(QList<qreal> rhs) | |
|
152 | QList<qreal> QSplineSeriesPrivate::getFirstControlPoints(QList<qreal> rhs) | |
|
127 | 153 | { |
|
128 | 154 | QList<qreal> x; // Solution vector. |
|
129 | 155 | QList<qreal> tmp; // Temp workspace. |
@@ -147,9 +173,10 QList<qreal> QSplineSeries::getFirstControlPoints(QList<qreal> rhs) | |||
|
147 | 173 | \internal |
|
148 | 174 | Updates the control points, besed on currently avaiable knots. |
|
149 | 175 | */ |
|
150 | void QSplineSeries::updateControlPoints() | |
|
176 | void QSplineSeriesPrivate::updateControlPoints() | |
|
151 | 177 | { |
|
152 | if (count() > 1) { | |
|
178 | Q_Q(QSplineSeries); | |
|
179 | if (q->count() > 1) { | |
|
153 | 180 | m_controlPoints.clear(); |
|
154 | 181 | calculateControlPoints(); |
|
155 | 182 | } |
@@ -187,12 +214,8 void QSplineSeries::updateControlPoints() | |||
|
187 | 214 | then all the items following \a first item in a model are used. |
|
188 | 215 | \sa setModel(), setModelMapping() |
|
189 | 216 | */ |
|
190 | void QSplineSeries::setModelMappingRange(int first, int count) | |
|
191 | { | |
|
192 | QLineSeries::setModelMappingRange(first, count); | |
|
193 | calculateControlPoints(); | |
|
194 | } | |
|
195 | 217 | |
|
196 | 218 | #include "moc_qsplineseries.cpp" |
|
219 | #include "moc_qsplineseries_p.cpp" | |
|
197 | 220 | |
|
198 | 221 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -29,30 +29,23 | |||
|
29 | 29 | |
|
30 | 30 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
31 | 31 | |
|
32 | class QSplineSeriesPrivate; | |
|
33 | ||
|
32 | 34 | class QTCOMMERCIALCHART_EXPORT QSplineSeries : public QLineSeries |
|
33 | 35 | { |
|
34 | 36 | Q_OBJECT |
|
35 | 37 | public: |
|
36 | 38 | |
|
37 | 39 | QSplineSeries(QObject *parent = 0); |
|
38 | QSeriesType type() const {return QSeries::SeriesTypeSpline;} | |
|
39 | ||
|
40 | QPointF controlPoint(int index) const {return m_controlPoints[index];} | |
|
41 | // bool setModel(QAbstractItemModel *model); | |
|
40 | QSeries::QSeriesType type() const; | |
|
42 | 41 | |
|
43 | // void setModelMapping(int modelX, int modelY, Qt::Orientation orientation = Qt::Vertical); | |
|
42 | QPointF controlPoint(int index) const; | |
|
44 | 43 | void setModelMappingRange(int first, int count); |
|
45 | 44 | |
|
46 | 45 | private: |
|
47 | void calculateControlPoints(); | |
|
48 | QList<qreal> getFirstControlPoints(QList<qreal> rhs); | |
|
49 | ||
|
50 | private Q_SLOTS: | |
|
51 | void updateControlPoints(); | |
|
52 | ||
|
53 | private: | |
|
54 | QList<QPointF> m_controlPoints; | |
|
55 | ||
|
46 | Q_DECLARE_PRIVATE(QSplineSeries); | |
|
47 | Q_DISABLE_COPY(QSplineSeries); | |
|
48 | friend class SplineChartItem; | |
|
56 | 49 | }; |
|
57 | 50 | |
|
58 | 51 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -6,7 +6,8 SOURCES += \ | |||
|
6 | 6 | $$PWD/splinechartitem.cpp |
|
7 | 7 | |
|
8 | 8 | PRIVATE_HEADERS += \ |
|
9 | $$PWD/splinechartitem_p.h | |
|
9 | $$PWD/splinechartitem_p.h \ | |
|
10 | $$PWD/qsplineseries_p.h | |
|
10 | 11 | |
|
11 | 12 | PUBLIC_HEADERS += \ |
|
12 | 13 | $$PWD/qsplineseries.h |
@@ -19,6 +19,7 | |||
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #include "splinechartitem_p.h" |
|
22 | #include "qsplineseries_p.h" | |
|
22 | 23 | #include "chartpresenter_p.h" |
|
23 | 24 | #include "chartanimator_p.h" |
|
24 | 25 | #include <QPainter> |
@@ -31,7 +32,7 SplineChartItem::SplineChartItem(QSplineSeries *series, ChartPresenter *presente | |||
|
31 | 32 | m_pointsVisible(false) |
|
32 | 33 | { |
|
33 | 34 | setZValue(ChartPresenter::LineChartZValue); |
|
34 | QObject::connect(series,SIGNAL(updated()),this,SLOT(handleUpdated())); | |
|
35 | QObject::connect(m_series->d_func(),SIGNAL(updated()),this,SLOT(handleUpdated())); | |
|
35 | 36 | handleUpdated(); |
|
36 | 37 | } |
|
37 | 38 |
@@ -32,7 +32,8 PRIVATE_HEADERS += \ | |||
|
32 | 32 | $$PWD/chartconfig_p.h \ |
|
33 | 33 | $$PWD/qchart_p.h \ |
|
34 | 34 | $$PWD/qchartview_p.h \ |
|
35 | $$PWD/scroller_p.h | |
|
35 | $$PWD/scroller_p.h \ | |
|
36 | $$PWD/qseries_p.h | |
|
36 | 37 | PUBLIC_HEADERS += \ |
|
37 | 38 | $$PWD/qchart.h \ |
|
38 | 39 | $$PWD/qchartglobal.h \ |
@@ -19,6 +19,7 | |||
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #include "qxyseries.h" |
|
22 | #include "qxyseries_p.h" | |
|
22 | 23 | #include <QAbstractItemModel> |
|
23 | 24 | |
|
24 | 25 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
@@ -82,15 +83,14 QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||
|
82 | 83 | Constructs empty series object which is a child of \a parent. |
|
83 | 84 | When series object is added to QChartView or QChart instance ownerships is transfered. |
|
84 | 85 | */ |
|
85 | QXYSeries::QXYSeries(QObject *parent):QSeries(parent) | |
|
86 | QXYSeries::QXYSeries(QObject *parent):QSeries(*new QXYSeriesPrivate(this),parent) | |
|
86 | 87 | { |
|
87 | m_mapX = -1; | |
|
88 | m_mapY = -1; | |
|
89 | m_mapFirst = 0; | |
|
90 | m_mapCount = 0; | |
|
91 | m_mapLimited = false; | |
|
92 | m_mapOrientation = Qt::Vertical; | |
|
93 | // m_mapYOrientation = Qt::Vertical; | |
|
88 | ||
|
89 | } | |
|
90 | ||
|
91 | QXYSeries::QXYSeries(QXYSeriesPrivate &d,QObject *parent):QSeries(d,parent) | |
|
92 | { | |
|
93 | ||
|
94 | 94 | } |
|
95 | 95 | /*! |
|
96 | 96 | Destroys the object. Series added to QChartView or QChart instances are owned by those, |
@@ -105,10 +105,11 QXYSeries::~QXYSeries() | |||
|
105 | 105 | */ |
|
106 | 106 | void QXYSeries::append(qreal x,qreal y) |
|
107 | 107 | { |
|
108 | Q_ASSERT(m_x.size() == m_y.size()); | |
|
109 | m_x<<x; | |
|
110 |
|
|
|
111 | emit pointAdded(m_x.size()-1); | |
|
108 | Q_D(QXYSeries); | |
|
109 | Q_ASSERT(d->m_x.size() == d->m_y.size()); | |
|
110 | d->m_x<<x; | |
|
111 | d->m_y<<y; | |
|
112 | emit d->pointAdded(d->m_x.size()-1); | |
|
112 | 113 | } |
|
113 | 114 | |
|
114 | 115 | /*! |
@@ -136,10 +137,11 void QXYSeries::append(const QList<QPointF> points) | |||
|
136 | 137 | */ |
|
137 | 138 | void QXYSeries::replace(qreal x,qreal y) |
|
138 | 139 | { |
|
139 | int index = m_x.indexOf(x); | |
|
140 | m_x[index] = x; | |
|
141 |
|
|
|
142 | emit pointReplaced(index); | |
|
140 | Q_D(QXYSeries); | |
|
141 | int index = d->m_x.indexOf(x); | |
|
142 | d->m_x[index] = x; | |
|
143 | d->m_y[index] = y; | |
|
144 | emit d->pointReplaced(index); | |
|
143 | 145 | } |
|
144 | 146 | |
|
145 | 147 | /*! |
@@ -156,14 +158,15 void QXYSeries::replace(const QPointF &point) | |||
|
156 | 158 | */ |
|
157 | 159 | void QXYSeries::remove(qreal x) |
|
158 | 160 | { |
|
159 | int index = m_x.indexOf(x); | |
|
161 | Q_D(QXYSeries); | |
|
162 | int index = d->m_x.indexOf(x); | |
|
160 | 163 | |
|
161 | 164 | if (index == -1) return; |
|
162 | 165 | |
|
163 | m_x.remove(index); | |
|
164 | m_y.remove(index); | |
|
166 | d->m_x.remove(index); | |
|
167 | d->m_y.remove(index); | |
|
165 | 168 | |
|
166 | emit pointRemoved(index); | |
|
169 | emit d->pointRemoved(index); | |
|
167 | 170 | } |
|
168 | 171 | |
|
169 | 172 | /*! |
@@ -171,16 +174,17 void QXYSeries::remove(qreal x) | |||
|
171 | 174 | */ |
|
172 | 175 | void QXYSeries::remove(qreal x,qreal y) |
|
173 | 176 | { |
|
177 | Q_D(QXYSeries); | |
|
174 | 178 | int index =-1; |
|
175 | 179 | do { |
|
176 | index = m_x.indexOf(x,index+1); | |
|
177 | } while (index !=-1 && m_y.at(index)!=y); | |
|
180 | index = d->m_x.indexOf(x,index+1); | |
|
181 | } while (index !=-1 && d->m_y.at(index)!=y); | |
|
178 | 182 | |
|
179 | 183 | if (index==-1) return; |
|
180 | 184 | |
|
181 | m_x.remove(index); | |
|
182 | m_y.remove(index); | |
|
183 | emit pointRemoved(index); | |
|
185 | d->m_x.remove(index); | |
|
186 | d->m_y.remove(index); | |
|
187 | emit d->pointRemoved(index); | |
|
184 | 188 | } |
|
185 | 189 | |
|
186 | 190 | /*! |
@@ -196,8 +200,9 void QXYSeries::remove(const QPointF &point) | |||
|
196 | 200 | */ |
|
197 | 201 | void QXYSeries::removeAll() |
|
198 | 202 | { |
|
199 | m_x.clear(); | |
|
200 |
|
|
|
203 | Q_D(QXYSeries); | |
|
204 | d->m_x.clear(); | |
|
205 | d->m_y.clear(); | |
|
201 | 206 | } |
|
202 | 207 | |
|
203 | 208 | /*! |
@@ -205,16 +210,17 void QXYSeries::removeAll() | |||
|
205 | 210 | */ |
|
206 | 211 | qreal QXYSeries::x(int pos) const |
|
207 | 212 | { |
|
208 | if (m_model) { | |
|
209 | if (m_mapOrientation == Qt::Vertical) | |
|
213 | Q_D(const QXYSeries); | |
|
214 | if (d->m_model) { | |
|
215 | if (d->m_mapOrientation == Qt::Vertical) | |
|
210 | 216 | // consecutive data is read from model's column |
|
211 | return m_model->data(m_model->index(pos + m_mapFirst, m_mapX), Qt::DisplayRole).toDouble(); | |
|
217 | return d->m_model->data(d->m_model->index(pos + d->m_mapFirst, d->m_mapX), Qt::DisplayRole).toDouble(); | |
|
212 | 218 | else |
|
213 | 219 | // consecutive data is read from model's row |
|
214 | return m_model->data(m_model->index(m_mapX, pos + m_mapFirst), Qt::DisplayRole).toDouble(); | |
|
220 | return d->m_model->data(d->m_model->index(d->m_mapX, pos + d->m_mapFirst), Qt::DisplayRole).toDouble(); | |
|
215 | 221 | } else { |
|
216 | 222 | // model is not specified, return the data from series' internal data store |
|
217 | return m_x.at(pos); | |
|
223 | return d->m_x.at(pos); | |
|
218 | 224 | } |
|
219 | 225 | } |
|
220 | 226 | |
@@ -223,16 +229,17 qreal QXYSeries::x(int pos) const | |||
|
223 | 229 | */ |
|
224 | 230 | qreal QXYSeries::y(int pos) const |
|
225 | 231 | { |
|
226 | if (m_model) { | |
|
227 | if (m_mapOrientation == Qt::Vertical) | |
|
232 | Q_D(const QXYSeries); | |
|
233 | if (d->m_model) { | |
|
234 | if (d->m_mapOrientation == Qt::Vertical) | |
|
228 | 235 | // consecutive data is read from model's column |
|
229 | return m_model->data(m_model->index(pos + m_mapFirst, m_mapY), Qt::DisplayRole).toDouble(); | |
|
236 | return d->m_model->data(d->m_model->index(pos + d->m_mapFirst, d->m_mapY), Qt::DisplayRole).toDouble(); | |
|
230 | 237 | else |
|
231 | 238 | // consecutive data is read from model's row |
|
232 | return m_model->data(m_model->index(m_mapY, pos + m_mapFirst), Qt::DisplayRole).toDouble(); | |
|
239 | return d->m_model->data(d->m_model->index(d->m_mapY, pos + d->m_mapFirst), Qt::DisplayRole).toDouble(); | |
|
233 | 240 | } else { |
|
234 | 241 | // model is not specified, return the data from series' internal data store |
|
235 | return m_y.at(pos); | |
|
242 | return d->m_y.at(pos); | |
|
236 | 243 | } |
|
237 | 244 | } |
|
238 | 245 | |
@@ -241,28 +248,30 qreal QXYSeries::y(int pos) const | |||
|
241 | 248 | */ |
|
242 | 249 | int QXYSeries::count() const |
|
243 | 250 | { |
|
244 | Q_ASSERT(m_x.size() == m_y.size()); | |
|
251 | Q_D(const QXYSeries); | |
|
252 | ||
|
253 | Q_ASSERT(d->m_x.size() == d->m_y.size()); | |
|
245 | 254 | |
|
246 | if (m_model) { | |
|
247 | if (m_mapOrientation == Qt::Vertical) { | |
|
255 | if (d->m_model) { | |
|
256 | if (d->m_mapOrientation == Qt::Vertical) { | |
|
248 | 257 | // data is in a column. Return the number of mapped items if the model's column have enough items |
|
249 | 258 | // or the number of items that can be mapped |
|
250 | if (m_mapLimited) | |
|
251 | return qMin(m_mapCount, qMax(m_model->rowCount() - m_mapFirst, 0)); | |
|
259 | if (d->m_mapLimited) | |
|
260 | return qMin(d->m_mapCount, qMax(d->m_model->rowCount() - d->m_mapFirst, 0)); | |
|
252 | 261 | else |
|
253 | return qMax(m_model->rowCount() - m_mapFirst, 0); | |
|
262 | return qMax(d->m_model->rowCount() - d->m_mapFirst, 0); | |
|
254 | 263 | } else { |
|
255 | 264 | // data is in a row. Return the number of mapped items if the model's row have enough items |
|
256 | 265 | // or the number of items that can be mapped |
|
257 | if (m_mapLimited) | |
|
258 | return qMin(m_mapCount, qMax(m_model->columnCount() - m_mapFirst, 0)); | |
|
266 | if (d->m_mapLimited) | |
|
267 | return qMin(d->m_mapCount, qMax(d->m_model->columnCount() - d->m_mapFirst, 0)); | |
|
259 | 268 | else |
|
260 | return qMax(m_model->columnCount() - m_mapFirst, 0); | |
|
269 | return qMax(d->m_model->columnCount() - d->m_mapFirst, 0); | |
|
261 | 270 | } |
|
262 | 271 | } |
|
263 | 272 | |
|
264 | 273 | // model is not specified, return the number of points in the series internal data store |
|
265 | return m_x.size(); | |
|
274 | return d->m_x.size(); | |
|
266 | 275 | } |
|
267 | 276 | |
|
268 | 277 | /*! |
@@ -270,9 +279,10 int QXYSeries::count() const | |||
|
270 | 279 | */ |
|
271 | 280 | QList<QPointF> QXYSeries::data() |
|
272 | 281 | { |
|
282 | Q_D(QXYSeries); | |
|
273 | 283 | QList<QPointF> data; |
|
274 | for (int i(0); i < m_x.count() && i < m_y.count(); i++) | |
|
275 | data.append(QPointF(m_x.at(i), m_y.at(i))); | |
|
284 | for (int i(0); i < d->m_x.count() && i < d->m_y.count(); i++) | |
|
285 | data.append(QPointF(d->m_x.at(i), d->m_y.at(i))); | |
|
276 | 286 | return data; |
|
277 | 287 | } |
|
278 | 288 | |
@@ -284,12 +294,19 QList<QPointF> QXYSeries::data() | |||
|
284 | 294 | */ |
|
285 | 295 | void QXYSeries::setPen(const QPen &pen) |
|
286 | 296 | { |
|
287 | if (pen != m_pen) { | |
|
288 |
|
|
|
289 | emit updated(); | |
|
297 | Q_D(QXYSeries); | |
|
298 | if (d->m_pen!=pen) { | |
|
299 | d->m_pen = pen; | |
|
300 | emit d->updated(); | |
|
290 | 301 | } |
|
291 | 302 | } |
|
292 | 303 | |
|
304 | QPen QXYSeries::pen() const | |
|
305 | { | |
|
306 | Q_D(const QXYSeries); | |
|
307 | return d->m_pen; | |
|
308 | } | |
|
309 | ||
|
293 | 310 | /*! |
|
294 | 311 | Sets \a brush used for drawing points on the chart. If the brush is not defined, brush |
|
295 | 312 | from chart theme setting is used. |
@@ -297,12 +314,39 void QXYSeries::setPen(const QPen &pen) | |||
|
297 | 314 | */ |
|
298 | 315 | void QXYSeries::setBrush(const QBrush &brush) |
|
299 | 316 | { |
|
300 | if (brush != m_brush) { | |
|
301 |
|
|
|
302 | emit updated(); | |
|
317 | Q_D(QXYSeries); | |
|
318 | if (d->m_brush!=brush) { | |
|
319 | d->m_brush = brush; | |
|
320 | emit d->updated(); | |
|
303 | 321 | } |
|
304 | 322 | } |
|
305 | 323 | |
|
324 | QBrush QXYSeries::brush() const | |
|
325 | { | |
|
326 | Q_D(const QXYSeries); | |
|
327 | return d->m_brush; | |
|
328 | } | |
|
329 | ||
|
330 | ||
|
331 | /*! | |
|
332 | Sets if data points are \a visible and should be drawn on line. | |
|
333 | */ | |
|
334 | void QXYSeries::setPointsVisible(bool visible) | |
|
335 | { | |
|
336 | Q_D(QXYSeries); | |
|
337 | if (d->m_pointsVisible != visible){ | |
|
338 | d->m_pointsVisible = visible; | |
|
339 | emit d->updated(); | |
|
340 | } | |
|
341 | } | |
|
342 | ||
|
343 | ||
|
344 | bool QXYSeries::pointsVisible() const | |
|
345 | { | |
|
346 | Q_D(const QXYSeries); | |
|
347 | return d->m_pointsVisible; | |
|
348 | } | |
|
349 | ||
|
306 | 350 | |
|
307 | 351 | /*! |
|
308 | 352 | Stream operator for adding a data \a point to the series. |
@@ -332,13 +376,13 QXYSeries& QXYSeries::operator<< (const QList<QPointF> points) | |||
|
332 | 376 | void QXYSeries::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight) |
|
333 | 377 | { |
|
334 | 378 | Q_UNUSED(bottomRight) |
|
335 | ||
|
336 | if (m_mapOrientation == Qt::Vertical) { | |
|
337 | if (topLeft.row() >= m_mapFirst && (!m_mapLimited || topLeft.row() < m_mapFirst + m_mapCount)) | |
|
338 | emit pointReplaced(topLeft.row() - m_mapFirst); | |
|
379 | Q_D(QXYSeries); | |
|
380 | if (d->m_mapOrientation == Qt::Vertical) { | |
|
381 | if (topLeft.row() >= d->m_mapFirst && (!d->m_mapLimited || topLeft.row() < d->m_mapFirst + d->m_mapCount)) | |
|
382 | emit d->pointReplaced(topLeft.row() - d->m_mapFirst); | |
|
339 | 383 | } else { |
|
340 | if (topLeft.column() >= m_mapFirst && (!m_mapLimited || topLeft.column() < m_mapFirst + m_mapCount)) | |
|
341 | emit pointReplaced(topLeft.column() - m_mapFirst); | |
|
384 | if (topLeft.column() >= d->m_mapFirst && (!d->m_mapLimited || topLeft.column() < d->m_mapFirst + d->m_mapCount)) | |
|
385 | emit d->pointReplaced(topLeft.column() - d->m_mapFirst); | |
|
342 | 386 | } |
|
343 | 387 | } |
|
344 | 388 | |
@@ -349,9 +393,9 void QXYSeries::modelDataAboutToBeAdded(QModelIndex parent, int start, int end) | |||
|
349 | 393 | { |
|
350 | 394 | Q_UNUSED(parent) |
|
351 | 395 | // Q_UNUSED(end) |
|
352 | ||
|
353 | if (m_mapLimited) { | |
|
354 | if (start >= m_mapFirst + m_mapCount) { | |
|
396 | Q_D(QXYSeries); | |
|
397 | if (d->m_mapLimited) { | |
|
398 | if (start >= d->m_mapFirst + d->m_mapCount) { | |
|
355 | 399 | // the added data is below mapped area |
|
356 | 400 | // therefore it has no relevance |
|
357 | 401 | return; |
@@ -362,10 +406,10 void QXYSeries::modelDataAboutToBeAdded(QModelIndex parent, int start, int end) | |||
|
362 | 406 | // if the number of items currently is equal the m_mapCount then some needs to be removed from xychartitem |
|
363 | 407 | // internal storage before new ones can be added |
|
364 | 408 | |
|
365 | int itemsToRemove = qMin(count() - qMax(start - m_mapFirst, 0), end - start + 1); | |
|
366 | if (m_mapCount == count()) { | |
|
409 | int itemsToRemove = qMin(count() - qMax(start - d->m_mapFirst, 0), end - start + 1); | |
|
410 | if (d->m_mapCount == count()) { | |
|
367 | 411 | for (int i = 0; i < itemsToRemove; i++) |
|
368 | emit pointRemoved(qMin(end, count()) - i); | |
|
412 | emit d->pointRemoved(qMin(end, count()) - i); | |
|
369 | 413 | } |
|
370 | 414 | } |
|
371 | 415 | } else { |
@@ -382,9 +426,9 void QXYSeries::modelDataAdded(QModelIndex parent, int start, int end) | |||
|
382 | 426 | { |
|
383 | 427 | Q_UNUSED(parent) |
|
384 | 428 | // Q_UNUSED(end) |
|
385 | ||
|
386 | if (m_mapLimited) { | |
|
387 | if (start >= m_mapFirst + m_mapCount) { | |
|
429 | Q_D(QXYSeries); | |
|
430 | if (d->m_mapLimited) { | |
|
431 | if (start >= d->m_mapFirst + d->m_mapCount) { | |
|
388 | 432 | // the added data is below mapped area |
|
389 | 433 | // therefore it has no relevance |
|
390 | 434 | return; |
@@ -392,16 +436,16 void QXYSeries::modelDataAdded(QModelIndex parent, int start, int end) | |||
|
392 | 436 | // the added data is in the mapped area or before it |
|
393 | 437 | // update needed |
|
394 | 438 | if (count() > 0) { |
|
395 | int toBeAdded = qMin(m_mapCount - (start - m_mapFirst), end - start + 1); | |
|
439 | int toBeAdded = qMin(d->m_mapCount - (start - d->m_mapFirst), end - start + 1); | |
|
396 | 440 | for (int i = 0; i < toBeAdded; i++) |
|
397 | if (start + i >= m_mapFirst) | |
|
398 | emit pointAdded(start + i); | |
|
441 | if (start + i >= d->m_mapFirst) | |
|
442 | emit d->pointAdded(start + i); | |
|
399 | 443 | } |
|
400 | 444 | } |
|
401 | 445 | } else { |
|
402 | 446 | // map is not limited (it included all the items starting from m_mapFirst till the end of model) |
|
403 | 447 | for (int i = 0; i < end - start + 1; i++) |
|
404 | emit pointAdded(start + i); | |
|
448 | emit d->pointAdded(start + i); | |
|
405 | 449 | } |
|
406 | 450 | } |
|
407 | 451 | |
@@ -412,9 +456,9 void QXYSeries::modelDataAboutToBeRemoved(QModelIndex parent, int start, int end | |||
|
412 | 456 | { |
|
413 | 457 | Q_UNUSED(parent) |
|
414 | 458 | // Q_UNUSED(end) |
|
415 | ||
|
416 | if (m_mapLimited) { | |
|
417 | if (start >= m_mapFirst + m_mapCount) { | |
|
459 | Q_D(QXYSeries); | |
|
460 | if (d->m_mapLimited) { | |
|
461 | if (start >= d->m_mapFirst + d->m_mapCount) { | |
|
418 | 462 | // the removed data is below mapped area |
|
419 | 463 | // therefore it has no relevance |
|
420 | 464 | return; |
@@ -426,14 +470,14 void QXYSeries::modelDataAboutToBeRemoved(QModelIndex parent, int start, int end | |||
|
426 | 470 | // the number equals the number of items that are removed and that lay before |
|
427 | 471 | // or in the mapped area. Items that lay beyond the map do not count |
|
428 | 472 | // the max is the current number of items in storage (count()) |
|
429 | int itemsToRemove = qMin(count(), qMin(end, m_mapFirst + m_mapCount - 1) - start + 1); | |
|
473 | int itemsToRemove = qMin(count(), qMin(end, d->m_mapFirst + d->m_mapCount - 1) - start + 1); | |
|
430 | 474 | for (int i = 0; i < itemsToRemove; i++) |
|
431 | emit pointRemoved(start); | |
|
475 | emit d->pointRemoved(start); | |
|
432 | 476 | } |
|
433 | 477 | } else { |
|
434 | 478 | // map is not limited (it included all the items starting from m_mapFirst till the end of model) |
|
435 | 479 | for (int i = 0; i < end - start + 1; i++) |
|
436 | emit pointRemoved(start); | |
|
480 | emit d->pointRemoved(start); | |
|
437 | 481 | } |
|
438 | 482 | } |
|
439 | 483 | |
@@ -442,14 +486,15 void QXYSeries::modelDataAboutToBeRemoved(QModelIndex parent, int start, int end | |||
|
442 | 486 | */ |
|
443 | 487 | void QXYSeries::modelDataRemoved(QModelIndex parent, int start, int end) |
|
444 | 488 | { |
|
489 | ||
|
445 | 490 | Q_UNUSED(parent) |
|
446 | 491 | Q_UNUSED(end) |
|
447 | ||
|
492 | Q_D(QXYSeries); | |
|
448 | 493 | // how many items there were before data was removed |
|
449 | 494 | // int oldCount = count() - 1; |
|
450 | 495 | |
|
451 | if (m_mapLimited) { | |
|
452 | if (start >= m_mapFirst + m_mapCount) { | |
|
496 | if (d->m_mapLimited) { | |
|
497 | if (start >= d->m_mapFirst + d->m_mapCount) { | |
|
453 | 498 | // the removed data is below mapped area |
|
454 | 499 | // therefore it has no relevance |
|
455 | 500 | return; |
@@ -457,18 +502,18 void QXYSeries::modelDataRemoved(QModelIndex parent, int start, int end) | |||
|
457 | 502 | // if the current items count in the whole model is bigger than the index of the last item |
|
458 | 503 | // that was removed than it means there are some extra items available |
|
459 | 504 | |
|
460 | int removedItemsCount = qMin(count(), qMin(end, m_mapFirst + m_mapCount - 1) - start + 1); | |
|
505 | int removedItemsCount = qMin(count(), qMin(end, d->m_mapFirst + d->m_mapCount - 1) - start + 1); | |
|
461 | 506 | int extraItemsAvailable = 0; |
|
462 | if (m_mapOrientation == Qt::Vertical) { | |
|
463 | extraItemsAvailable = qMax(m_model->rowCount() + (end - start + 1) - qMax(end + 1, m_mapFirst + m_mapCount), 0); | |
|
507 | if (d->m_mapOrientation == Qt::Vertical) { | |
|
508 | extraItemsAvailable = qMax(d->m_model->rowCount() + (end - start + 1) - qMax(end + 1, d->m_mapFirst + d->m_mapCount), 0); | |
|
464 | 509 | } else { |
|
465 | extraItemsAvailable = qMax(m_model->columnCount() + (end - start + 1) - qMax(end + 1, m_mapFirst + m_mapCount), 0); | |
|
510 | extraItemsAvailable = qMax(d->m_model->columnCount() + (end - start + 1) - qMax(end + 1, d->m_mapFirst + d->m_mapCount), 0); | |
|
466 | 511 | } |
|
467 | 512 | |
|
468 | 513 | // if there are excess items available (below the mapped area) use them to repopulate mapped area |
|
469 | 514 | int toBeAdded = qMin(extraItemsAvailable, removedItemsCount); |
|
470 | 515 | for (int k = 0; k < toBeAdded; k++) |
|
471 | emit pointAdded(m_mapFirst + m_mapCount - removedItemsCount + k); | |
|
516 | emit d->pointAdded(d->m_mapFirst + d->m_mapCount - removedItemsCount + k); | |
|
472 | 517 | } |
|
473 | 518 | } else { |
|
474 | 519 | // data was removed from XYSeries interal storage. Nothing more to do |
@@ -480,25 +525,26 void QXYSeries::modelDataRemoved(QModelIndex parent, int start, int end) | |||
|
480 | 525 | Sets the \a model to be used as a data source |
|
481 | 526 | \sa setModelMapping(), setModelMappingRange() |
|
482 | 527 | */ |
|
483 |
bool QXYSeries::setModel(QAbstractItemModel *model) |
|
|
484 | ||
|
528 | bool QXYSeries::setModel(QAbstractItemModel *model) | |
|
529 | { | |
|
530 | Q_D(QXYSeries); | |
|
485 | 531 | // disconnect signals from old model |
|
486 | if (m_model) { | |
|
487 | disconnect(m_model, 0, this, 0); | |
|
488 | m_mapX = -1; | |
|
489 | m_mapY = -1; | |
|
490 | m_mapFirst = 0; | |
|
491 | m_mapCount = 0; | |
|
492 | m_mapLimited = false; | |
|
493 | m_mapOrientation = Qt::Vertical; | |
|
532 | if (d->m_model) { | |
|
533 | QObject::disconnect(d->m_model, 0, this, 0); | |
|
534 | d->m_mapX = -1; | |
|
535 | d->m_mapY = -1; | |
|
536 | d->m_mapFirst = 0; | |
|
537 | d->m_mapCount = 0; | |
|
538 | d->m_mapLimited = false; | |
|
539 | d->m_mapOrientation = Qt::Vertical; | |
|
494 | 540 | } |
|
495 | 541 | |
|
496 | 542 | // set new model |
|
497 | 543 | if (model) { |
|
498 | m_model = model; | |
|
544 | d->m_model = model; | |
|
499 | 545 | return true; |
|
500 | 546 | } else { |
|
501 | m_model = 0; | |
|
547 | d->m_model = 0; | |
|
502 | 548 | return false; |
|
503 | 549 | } |
|
504 | 550 | } |
@@ -512,24 +558,25 bool QXYSeries::setModel(QAbstractItemModel *model) { | |||
|
512 | 558 | */ |
|
513 | 559 | void QXYSeries::setModelMapping(int modelX, int modelY, Qt::Orientation orientation) |
|
514 | 560 | { |
|
515 | if (m_model == 0) | |
|
561 | Q_D(QXYSeries); | |
|
562 | if (d->m_model == 0) | |
|
516 | 563 | return; |
|
517 | m_mapX = modelX; | |
|
518 | m_mapY = modelY; | |
|
519 | m_mapFirst = 0; | |
|
520 | m_mapOrientation = orientation; | |
|
521 | if (m_mapOrientation == Qt::Vertical) { | |
|
522 | connect(m_model,SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(modelUpdated(QModelIndex, QModelIndex))); | |
|
523 | connect(m_model,SIGNAL(rowsAboutToBeInserted(QModelIndex, int, int)), this, SLOT(modelDataAboutToBeAdded(QModelIndex,int,int))); | |
|
524 | connect(m_model,SIGNAL(rowsInserted(QModelIndex, int, int)), this, SLOT(modelDataAdded(QModelIndex,int,int))); | |
|
525 | connect(m_model, SIGNAL(rowsAboutToBeRemoved(QModelIndex, int, int)), this, SLOT(modelDataAboutToBeRemoved(QModelIndex,int,int))); | |
|
526 | connect(m_model, SIGNAL(rowsRemoved(QModelIndex, int, int)), this, SLOT(modelDataRemoved(QModelIndex,int,int))); | |
|
564 | d->m_mapX = modelX; | |
|
565 | d->m_mapY = modelY; | |
|
566 | d->m_mapFirst = 0; | |
|
567 | d->m_mapOrientation = orientation; | |
|
568 | if (d->m_mapOrientation == Qt::Vertical) { | |
|
569 | connect(d->m_model,SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(modelUpdated(QModelIndex, QModelIndex))); | |
|
570 | connect(d->m_model,SIGNAL(rowsAboutToBeInserted(QModelIndex, int, int)), this, SLOT(modelDataAboutToBeAdded(QModelIndex,int,int))); | |
|
571 | connect(d->m_model,SIGNAL(rowsInserted(QModelIndex, int, int)), this, SLOT(modelDataAdded(QModelIndex,int,int))); | |
|
572 | connect(d->m_model, SIGNAL(rowsAboutToBeRemoved(QModelIndex, int, int)), this, SLOT(modelDataAboutToBeRemoved(QModelIndex,int,int))); | |
|
573 | connect(d->m_model, SIGNAL(rowsRemoved(QModelIndex, int, int)), this, SLOT(modelDataRemoved(QModelIndex,int,int))); | |
|
527 | 574 | } else { |
|
528 | connect(m_model,SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(modelUpdated(QModelIndex, QModelIndex))); | |
|
529 | connect(m_model,SIGNAL(columnsAboutToBeInserted(QModelIndex, int, int)), this, SLOT(modelDataAboutToBeAdded(QModelIndex,int,int))); | |
|
530 | connect(m_model,SIGNAL(columnsInserted(QModelIndex, int, int)), this, SLOT(modelDataAdded(QModelIndex,int,int))); | |
|
531 | connect(m_model, SIGNAL(columnsAboutToBeRemoved(QModelIndex, int, int)), this, SLOT(modelDataAboutToBeRemoved(QModelIndex,int,int))); | |
|
532 | connect(m_model, SIGNAL(columnsRemoved(QModelIndex, int, int)), this, SLOT(modelDataRemoved(QModelIndex,int,int))); | |
|
575 | connect(d->m_model,SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(modelUpdated(QModelIndex, QModelIndex))); | |
|
576 | connect(d->m_model,SIGNAL(columnsAboutToBeInserted(QModelIndex, int, int)), this, SLOT(modelDataAboutToBeAdded(QModelIndex,int,int))); | |
|
577 | connect(d->m_model,SIGNAL(columnsInserted(QModelIndex, int, int)), this, SLOT(modelDataAdded(QModelIndex,int,int))); | |
|
578 | connect(d->m_model, SIGNAL(columnsAboutToBeRemoved(QModelIndex, int, int)), this, SLOT(modelDataAboutToBeRemoved(QModelIndex,int,int))); | |
|
579 | connect(d->m_model, SIGNAL(columnsRemoved(QModelIndex, int, int)), this, SLOT(modelDataRemoved(QModelIndex,int,int))); | |
|
533 | 580 | } |
|
534 | 581 | } |
|
535 | 582 | |
@@ -543,15 +590,43 void QXYSeries::setModelMapping(int modelX, int modelY, Qt::Orientation orientat | |||
|
543 | 590 | */ |
|
544 | 591 | void QXYSeries::setModelMappingRange(int first, int count) |
|
545 | 592 | { |
|
546 | m_mapFirst = first; | |
|
593 | Q_D(QXYSeries); | |
|
594 | d->m_mapFirst = first; | |
|
547 | 595 | if (count == 0) { |
|
548 | m_mapLimited = false; | |
|
596 | d->m_mapLimited = false; | |
|
549 | 597 | } else { |
|
550 | m_mapCount = count; | |
|
551 | m_mapLimited = true; | |
|
598 | d->m_mapCount = count; | |
|
599 | d->m_mapLimited = true; | |
|
600 | } | |
|
552 | 601 | } |
|
602 | ||
|
603 | int QXYSeries::mapFirst() const | |
|
604 | { | |
|
605 | Q_D(const QXYSeries); | |
|
606 | return d->m_mapFirst; | |
|
607 | } | |
|
608 | ||
|
609 | int QXYSeries::mapCount() const | |
|
610 | { | |
|
611 | Q_D(const QXYSeries); | |
|
612 | return d->m_mapCount; | |
|
613 | } | |
|
614 | ||
|
615 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
|
616 | ||
|
617 | QXYSeriesPrivate::QXYSeriesPrivate(QXYSeries *q): QSeriesPrivate(q), | |
|
618 | m_mapX(-1), | |
|
619 | m_mapY(-1), | |
|
620 | m_mapFirst(0), | |
|
621 | m_mapCount(0), | |
|
622 | m_mapLimited(false), | |
|
623 | m_mapOrientation( Qt::Vertical), | |
|
624 | m_pointsVisible(false) | |
|
625 | { | |
|
626 | ||
|
553 | 627 | } |
|
554 | 628 | |
|
555 | 629 | #include "moc_qxyseries.cpp" |
|
630 | #include "moc_qxyseries_p.cpp" | |
|
556 | 631 | |
|
557 | 632 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -30,12 +30,15 class QModelIndex; | |||
|
30 | 30 | |
|
31 | 31 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
32 | 32 | |
|
33 | class QXYSeriesPrivate; | |
|
34 | ||
|
33 | 35 | class QTCOMMERCIALCHART_EXPORT QXYSeries : public QSeries |
|
34 | 36 | { |
|
35 | 37 | Q_OBJECT |
|
36 | 38 | protected: |
|
37 | QXYSeries(QObject *parent = 0); | |
|
38 | virtual ~QXYSeries(); | |
|
39 | explicit QXYSeries(QObject *parent = 0); | |
|
40 | explicit QXYSeries(QXYSeriesPrivate &d,QObject *parent = 0); | |
|
41 | ~QXYSeries(); | |
|
39 | 42 | |
|
40 | 43 | public: |
|
41 | 44 | void append(qreal x, qreal y); |
@@ -57,16 +60,20 public: | |||
|
57 | 60 | QXYSeries& operator << (const QList<QPointF> points); |
|
58 | 61 | |
|
59 | 62 | void setPen(const QPen &pen); |
|
60 |
QPen pen() const |
|
|
63 | QPen pen() const; | |
|
64 | ||
|
61 | 65 | void setBrush(const QBrush &brush); |
|
62 |
QBrush brush() const |
|
|
66 | QBrush brush() const; | |
|
67 | ||
|
68 | void setPointsVisible(bool visible); | |
|
69 | bool pointsVisible() const; | |
|
63 | 70 | |
|
64 | 71 | bool setModel(QAbstractItemModel *model); |
|
65 | 72 | |
|
66 | 73 | virtual void setModelMapping(int modelX, int modelY, Qt::Orientation orientation = Qt::Vertical); |
|
67 | 74 | virtual void setModelMappingRange(int first, int count = 0); |
|
68 |
int mapFirst() const |
|
|
69 |
int mapCount() const |
|
|
75 | int mapFirst() const; | |
|
76 | int mapCount() const; | |
|
70 | 77 | |
|
71 | 78 | private Q_SLOTS: |
|
72 | 79 | void modelUpdated(QModelIndex topLeft, QModelIndex bottomRight); |
@@ -78,25 +85,12 private Q_SLOTS: | |||
|
78 | 85 | Q_SIGNALS: |
|
79 | 86 | void clicked(const QPointF &point); |
|
80 | 87 | void selected(); |
|
81 | void updated(); | |
|
82 | void pointReplaced(int index); | |
|
83 | void pointRemoved(int index); | |
|
84 | void pointAdded(int index); | |
|
85 | 88 | |
|
86 | protected: | |
|
87 | QVector<qreal> m_x; | |
|
88 | QVector<qreal> m_y; | |
|
89 | ||
|
90 | QPen m_pen; | |
|
91 | QBrush m_brush; | |
|
92 | ||
|
93 | int m_mapX; | |
|
94 | int m_mapY; | |
|
95 | int m_mapFirst; | |
|
96 | int m_mapCount; | |
|
97 | bool m_mapLimited; | |
|
98 | Qt::Orientation m_mapOrientation; | |
|
99 | int tempItemsRemoved; | |
|
89 | private: | |
|
90 | Q_DECLARE_PRIVATE(QXYSeries); | |
|
91 | Q_DISABLE_COPY(QXYSeries); | |
|
92 | friend class XYLegendMarker; | |
|
93 | friend class XYChartItem; | |
|
100 | 94 | }; |
|
101 | 95 | |
|
102 | 96 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -6,7 +6,8 SOURCES += \ | |||
|
6 | 6 | $$PWD/qxyseries.cpp |
|
7 | 7 | |
|
8 | 8 | PRIVATE_HEADERS += \ |
|
9 | $$PWD/xychartitem_p.h | |
|
9 | $$PWD/xychartitem_p.h \ | |
|
10 | $$PWD/qxyseries_p.h | |
|
10 | 11 | |
|
11 | 12 | |
|
12 | 13 | PUBLIC_HEADERS += \ |
@@ -20,6 +20,7 | |||
|
20 | 20 | |
|
21 | 21 | #include "xychartitem_p.h" |
|
22 | 22 | #include "qxyseries.h" |
|
23 | #include "qxyseries_p.h" | |
|
23 | 24 | #include "chartpresenter_p.h" |
|
24 | 25 | #include "chartanimator_p.h" |
|
25 | 26 | #include <QPainter> |
@@ -37,9 +38,9 XYChartItem::XYChartItem(QXYSeries *series, ChartPresenter *presenter):ChartItem | |||
|
37 | 38 | m_maxY(0), |
|
38 | 39 | m_series(series) |
|
39 | 40 | { |
|
40 | connect(series,SIGNAL(pointReplaced(int)),this,SLOT(handlePointReplaced(int))); | |
|
41 | connect(series,SIGNAL(pointAdded(int)),this,SLOT(handlePointAdded(int))); | |
|
42 | connect(series,SIGNAL(pointRemoved(int)),this,SLOT(handlePointRemoved(int))); | |
|
41 | connect(series->d_func(),SIGNAL(pointReplaced(int)),this,SLOT(handlePointReplaced(int))); | |
|
42 | connect(series->d_func(),SIGNAL(pointAdded(int)),this,SLOT(handlePointAdded(int))); | |
|
43 | connect(series->d_func(),SIGNAL(pointRemoved(int)),this,SLOT(handlePointRemoved(int))); | |
|
43 | 44 | connect(this,SIGNAL(clicked(const QPointF&)),series,SIGNAL(clicked(const QPointF&))); |
|
44 | 45 | } |
|
45 | 46 |
General Comments 0
You need to be logged in to leave comments.
Login now