@@ -1,25 +1,25 | |||||
1 | #ifndef CHARTVIEW_H_ |
|
1 | #ifndef CHARTVIEW_H_ | |
2 | #define CHARTVIEW_H_ |
|
2 | #define CHARTVIEW_H_ | |
3 |
|
3 | |||
4 | #include <qchartview.h> |
|
4 | #include <qchartview.h> | |
5 | #include <QTimer> |
|
5 | #include <QTimer> | |
6 |
|
6 | |||
7 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
7 | QTCOMMERCIALCHART_USE_NAMESPACE | |
8 |
|
8 | |||
9 | class ChartView: public QChartView |
|
9 | class ChartView: public QChartView | |
10 | { |
|
10 | { | |
11 | Q_OBJECT |
|
11 | Q_OBJECT | |
12 | public: |
|
12 | public: | |
13 | ChartView(QWidget* parent=0); |
|
13 | ChartView(QWidget* parent=0); | |
14 | virtual ~ChartView(); |
|
14 | virtual ~ChartView(); | |
15 |
|
15 | |||
16 | public slots: |
|
16 | public slots: | |
17 | void handleTimeout(); |
|
17 | void handleTimeout(); | |
18 |
|
18 | |||
19 | private: |
|
19 | private: | |
20 | QTimer m_timer; |
|
20 | QTimer m_timer; | |
21 |
QList<Q |
|
21 | QList<QSeries*> m_series; | |
22 | int m_index; |
|
22 | int m_index; | |
23 | }; |
|
23 | }; | |
24 |
|
24 | |||
25 | #endif /* CHARTVIEW_H_ */ |
|
25 | #endif /* CHARTVIEW_H_ */ |
@@ -1,232 +1,232 | |||||
1 | #include <QDebug> |
|
1 | #include <QDebug> | |
2 | #include "qbarseries.h" |
|
2 | #include "qbarseries.h" | |
3 | #include "qbarcategory.h" |
|
3 | #include "qbarcategory.h" | |
4 | #include "qbarset.h" |
|
4 | #include "qbarset.h" | |
5 | #include "barchartmodel_p.h" |
|
5 | #include "barchartmodel_p.h" | |
6 |
|
6 | |||
7 |
|
7 | |||
8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
9 |
|
9 | |||
10 | /*! |
|
10 | /*! | |
11 | \class QBarSeries |
|
11 | \class QBarSeries | |
12 | \brief part of QtCommercial chart API. |
|
12 | \brief part of QtCommercial chart API. | |
13 |
|
13 | |||
14 | QBarSeries represents a series of data shown as bars. One QBarSeries can contain multible |
|
14 | QBarSeries represents a series of data shown as bars. One QBarSeries can contain multible | |
15 | QBarSet data sets. QBarSeries groups the data from sets to categories, which are defined |
|
15 | QBarSet data sets. QBarSeries groups the data from sets to categories, which are defined | |
16 | by QBarCategory class. |
|
16 | by QBarCategory class. | |
17 |
|
17 | |||
18 | \mainclass |
|
18 | \mainclass | |
19 |
|
19 | |||
20 | \sa QBarCategory, QBarSet, QStackedBarSeries, QPercentBarSeries |
|
20 | \sa QBarCategory, QBarSet, QStackedBarSeries, QPercentBarSeries | |
21 | */ |
|
21 | */ | |
22 |
|
22 | |||
23 | /*! |
|
23 | /*! | |
24 |
\fn virtual Q |
|
24 | \fn virtual QSeriesType QBarSeries::type() const | |
25 | \brief Returns type of series. |
|
25 | \brief Returns type of series. | |
26 |
\sa Q |
|
26 | \sa QSeries, QSeriesType | |
27 | */ |
|
27 | */ | |
28 | /*! |
|
28 | /*! | |
29 | \fn void QBarSeries::changed(int index) |
|
29 | \fn void QBarSeries::changed(int index) | |
30 | \brief \internal \a index |
|
30 | \brief \internal \a index | |
31 | */ |
|
31 | */ | |
32 | /*! |
|
32 | /*! | |
33 | \fn void QBarSeries::floatingValuesEnabled(bool enabled) |
|
33 | \fn void QBarSeries::floatingValuesEnabled(bool enabled) | |
34 | \brief \internal \a enabled |
|
34 | \brief \internal \a enabled | |
35 | */ |
|
35 | */ | |
36 | /*! |
|
36 | /*! | |
37 | \fn void QBarSeries::toolTipEnabled(bool enabled) |
|
37 | \fn void QBarSeries::toolTipEnabled(bool enabled) | |
38 | \brief \internal \a enabled |
|
38 | \brief \internal \a enabled | |
39 | */ |
|
39 | */ | |
40 | /*! |
|
40 | /*! | |
41 | \fn void QBarSeries::separatorsEnabled(bool enabled) |
|
41 | \fn void QBarSeries::separatorsEnabled(bool enabled) | |
42 | \brief \internal \a enabled |
|
42 | \brief \internal \a enabled | |
43 | */ |
|
43 | */ | |
44 | /*! |
|
44 | /*! | |
45 | \fn void QBarSeries::showToolTip(QPoint pos, QString tip) |
|
45 | \fn void QBarSeries::showToolTip(QPoint pos, QString tip) | |
46 | \brief \internal \a pos \a tip |
|
46 | \brief \internal \a pos \a tip | |
47 | */ |
|
47 | */ | |
48 |
|
48 | |||
49 | /*! |
|
49 | /*! | |
50 | Constructs empty QBarSeries. Parameter \a category defines the categories for chart. |
|
50 | Constructs empty QBarSeries. Parameter \a category defines the categories for chart. | |
51 | Takes ownership of \a category. |
|
51 | Takes ownership of \a category. | |
52 | QBarSeries is QObject which is a child of a \a parent. |
|
52 | QBarSeries is QObject which is a child of a \a parent. | |
53 | */ |
|
53 | */ | |
54 | QBarSeries::QBarSeries(QBarCategory *category, QObject *parent) |
|
54 | QBarSeries::QBarSeries(QBarCategory *category, QObject *parent) | |
55 |
: Q |
|
55 | : QSeries(parent) | |
56 | ,mModel(new BarChartModel(category, this)) |
|
56 | ,mModel(new BarChartModel(category, this)) | |
57 | { |
|
57 | { | |
58 | } |
|
58 | } | |
59 |
|
59 | |||
60 | /*! |
|
60 | /*! | |
61 | Adds a set of bars to series. Takes ownership of \a set |
|
61 | Adds a set of bars to series. Takes ownership of \a set | |
62 | */ |
|
62 | */ | |
63 | void QBarSeries::addBarSet(QBarSet *set) |
|
63 | void QBarSeries::addBarSet(QBarSet *set) | |
64 | { |
|
64 | { | |
65 | mModel->addBarSet(set); |
|
65 | mModel->addBarSet(set); | |
66 | } |
|
66 | } | |
67 |
|
67 | |||
68 | /*! |
|
68 | /*! | |
69 | Removes a set of bars from series. Releases ownership of \a set. Doesnt delete \a set. |
|
69 | Removes a set of bars from series. Releases ownership of \a set. Doesnt delete \a set. | |
70 | */ |
|
70 | */ | |
71 | void QBarSeries::removeBarSet(QBarSet *set) |
|
71 | void QBarSeries::removeBarSet(QBarSet *set) | |
72 | { |
|
72 | { | |
73 | mModel->removeBarSet(set); |
|
73 | mModel->removeBarSet(set); | |
74 | } |
|
74 | } | |
75 |
|
75 | |||
76 | /*! |
|
76 | /*! | |
77 | Returns number of sets in series. |
|
77 | Returns number of sets in series. | |
78 | */ |
|
78 | */ | |
79 | int QBarSeries::countSets() |
|
79 | int QBarSeries::countSets() | |
80 | { |
|
80 | { | |
81 | return mModel->countSets(); |
|
81 | return mModel->countSets(); | |
82 | } |
|
82 | } | |
83 |
|
83 | |||
84 | /*! |
|
84 | /*! | |
85 | Returns number of categories in series |
|
85 | Returns number of categories in series | |
86 | */ |
|
86 | */ | |
87 | int QBarSeries::countCategories() |
|
87 | int QBarSeries::countCategories() | |
88 | { |
|
88 | { | |
89 | return mModel->countCategories(); |
|
89 | return mModel->countCategories(); | |
90 | } |
|
90 | } | |
91 |
|
91 | |||
92 | /*! |
|
92 | /*! | |
93 | Returns a list of sets in series. Keeps ownership of sets. |
|
93 | Returns a list of sets in series. Keeps ownership of sets. | |
94 | */ |
|
94 | */ | |
95 | QList<QBarSet*> QBarSeries::barSets() |
|
95 | QList<QBarSet*> QBarSeries::barSets() | |
96 | { |
|
96 | { | |
97 | return mModel->barSets(); |
|
97 | return mModel->barSets(); | |
98 | } |
|
98 | } | |
99 |
|
99 | |||
100 | /*! |
|
100 | /*! | |
101 | \internal \a index |
|
101 | \internal \a index | |
102 | */ |
|
102 | */ | |
103 | QBarSet* QBarSeries::barsetAt(int index) |
|
103 | QBarSet* QBarSeries::barsetAt(int index) | |
104 | { |
|
104 | { | |
105 | return mModel->setAt(index); |
|
105 | return mModel->setAt(index); | |
106 | } |
|
106 | } | |
107 |
|
107 | |||
108 | /*! |
|
108 | /*! | |
109 | Returns legend of series. Legend is a list of set names in series. |
|
109 | Returns legend of series. Legend is a list of set names in series. | |
110 | */ |
|
110 | */ | |
111 | QList<QString> QBarSeries::legend() |
|
111 | QList<QString> QBarSeries::legend() | |
112 | { |
|
112 | { | |
113 | return mModel->legend(); |
|
113 | return mModel->legend(); | |
114 | } |
|
114 | } | |
115 |
|
115 | |||
116 | /*! |
|
116 | /*! | |
117 | \internal \a category |
|
117 | \internal \a category | |
118 | */ |
|
118 | */ | |
119 | QString QBarSeries::label(int category) |
|
119 | QString QBarSeries::label(int category) | |
120 | { |
|
120 | { | |
121 | return mModel->label(category); |
|
121 | return mModel->label(category); | |
122 | } |
|
122 | } | |
123 |
|
123 | |||
124 | /*! |
|
124 | /*! | |
125 | Enables or disables floating values depending on parameter \a enabled. |
|
125 | Enables or disables floating values depending on parameter \a enabled. | |
126 | Floating values are bar values, that are displayed on top of each bar. |
|
126 | Floating values are bar values, that are displayed on top of each bar. | |
127 | Calling without parameter \a enabled, enables the floating values |
|
127 | Calling without parameter \a enabled, enables the floating values | |
128 | */ |
|
128 | */ | |
129 | void QBarSeries::setFloatingValuesEnabled(bool enabled) |
|
129 | void QBarSeries::setFloatingValuesEnabled(bool enabled) | |
130 | { |
|
130 | { | |
131 | if (enabled) { |
|
131 | if (enabled) { | |
132 | for (int i=0; i<mModel->countSets(); i++) { |
|
132 | for (int i=0; i<mModel->countSets(); i++) { | |
133 | QBarSet *set = mModel->setAt(i); |
|
133 | QBarSet *set = mModel->setAt(i); | |
134 | connect(set,SIGNAL(clicked()),set,SIGNAL(toggleFloatingValues())); |
|
134 | connect(set,SIGNAL(clicked()),set,SIGNAL(toggleFloatingValues())); | |
135 | } |
|
135 | } | |
136 | } else { |
|
136 | } else { | |
137 | for (int i=0; i<mModel->countSets(); i++) { |
|
137 | for (int i=0; i<mModel->countSets(); i++) { | |
138 | QBarSet *set = mModel->setAt(i); |
|
138 | QBarSet *set = mModel->setAt(i); | |
139 | disconnect(set,SIGNAL(clicked()),set,SIGNAL(toggleFloatingValues())); |
|
139 | disconnect(set,SIGNAL(clicked()),set,SIGNAL(toggleFloatingValues())); | |
140 | } |
|
140 | } | |
141 | } |
|
141 | } | |
142 | } |
|
142 | } | |
143 |
|
143 | |||
144 | /*! |
|
144 | /*! | |
145 | Enables or disables tooltip depending on parameter \a enabled. |
|
145 | Enables or disables tooltip depending on parameter \a enabled. | |
146 | Tooltip shows the name of set, when mouse is hovering on top of bar. |
|
146 | Tooltip shows the name of set, when mouse is hovering on top of bar. | |
147 | Calling without parameter \a enabled, enables the tooltip |
|
147 | Calling without parameter \a enabled, enables the tooltip | |
148 | */ |
|
148 | */ | |
149 | void QBarSeries::setToolTipEnabled(bool enabled) |
|
149 | void QBarSeries::setToolTipEnabled(bool enabled) | |
150 | { |
|
150 | { | |
151 | if (enabled) { |
|
151 | if (enabled) { | |
152 | for (int i=0; i<mModel->countSets(); i++) { |
|
152 | for (int i=0; i<mModel->countSets(); i++) { | |
153 | QBarSet *set = mModel->setAt(i); |
|
153 | QBarSet *set = mModel->setAt(i); | |
154 | connect(set,SIGNAL(showToolTip(QPoint,QString)),this,SIGNAL(showToolTip(QPoint,QString))); |
|
154 | connect(set,SIGNAL(showToolTip(QPoint,QString)),this,SIGNAL(showToolTip(QPoint,QString))); | |
155 | } |
|
155 | } | |
156 | } else { |
|
156 | } else { | |
157 | for (int i=0; i<mModel->countSets(); i++) { |
|
157 | for (int i=0; i<mModel->countSets(); i++) { | |
158 | QBarSet *set = mModel->setAt(i); |
|
158 | QBarSet *set = mModel->setAt(i); | |
159 | disconnect(set,SIGNAL(showToolTip(QPoint,QString)),this,SIGNAL(showToolTip(QPoint,QString))); |
|
159 | disconnect(set,SIGNAL(showToolTip(QPoint,QString)),this,SIGNAL(showToolTip(QPoint,QString))); | |
160 | } |
|
160 | } | |
161 | } |
|
161 | } | |
162 | } |
|
162 | } | |
163 |
|
163 | |||
164 | /*! |
|
164 | /*! | |
165 | Enables or disables separators depending on parameter \a enabled. |
|
165 | Enables or disables separators depending on parameter \a enabled. | |
166 | Separators are visual elements that are drawn between categories. |
|
166 | Separators are visual elements that are drawn between categories. | |
167 | Calling without parameter \a enabled, enables the separators |
|
167 | Calling without parameter \a enabled, enables the separators | |
168 | */ |
|
168 | */ | |
169 | void QBarSeries::setSeparatorsEnabled(bool enabled) |
|
169 | void QBarSeries::setSeparatorsEnabled(bool enabled) | |
170 | { |
|
170 | { | |
171 | emit separatorsEnabled(enabled); |
|
171 | emit separatorsEnabled(enabled); | |
172 | } |
|
172 | } | |
173 |
|
173 | |||
174 | /*! |
|
174 | /*! | |
175 | \internal |
|
175 | \internal | |
176 | */ |
|
176 | */ | |
177 | qreal QBarSeries::min() |
|
177 | qreal QBarSeries::min() | |
178 | { |
|
178 | { | |
179 | return mModel->min(); |
|
179 | return mModel->min(); | |
180 | } |
|
180 | } | |
181 |
|
181 | |||
182 | /*! |
|
182 | /*! | |
183 | \internal |
|
183 | \internal | |
184 | */ |
|
184 | */ | |
185 | qreal QBarSeries::max() |
|
185 | qreal QBarSeries::max() | |
186 | { |
|
186 | { | |
187 | return mModel->max(); |
|
187 | return mModel->max(); | |
188 | } |
|
188 | } | |
189 |
|
189 | |||
190 | /*! |
|
190 | /*! | |
191 | \internal \a set \a category |
|
191 | \internal \a set \a category | |
192 | */ |
|
192 | */ | |
193 | qreal QBarSeries::valueAt(int set, int category) |
|
193 | qreal QBarSeries::valueAt(int set, int category) | |
194 | { |
|
194 | { | |
195 | return mModel->valueAt(set,category); |
|
195 | return mModel->valueAt(set,category); | |
196 | } |
|
196 | } | |
197 |
|
197 | |||
198 | /*! |
|
198 | /*! | |
199 | \internal \a set \a category |
|
199 | \internal \a set \a category | |
200 | */ |
|
200 | */ | |
201 | qreal QBarSeries::percentageAt(int set, int category) |
|
201 | qreal QBarSeries::percentageAt(int set, int category) | |
202 | { |
|
202 | { | |
203 | return mModel->percentageAt(set,category); |
|
203 | return mModel->percentageAt(set,category); | |
204 | } |
|
204 | } | |
205 |
|
205 | |||
206 | /*! |
|
206 | /*! | |
207 | \internal \a category |
|
207 | \internal \a category | |
208 | */ |
|
208 | */ | |
209 | qreal QBarSeries::categorySum(int category) |
|
209 | qreal QBarSeries::categorySum(int category) | |
210 | { |
|
210 | { | |
211 | return mModel->categorySum(category); |
|
211 | return mModel->categorySum(category); | |
212 | } |
|
212 | } | |
213 |
|
213 | |||
214 | /*! |
|
214 | /*! | |
215 | \internal |
|
215 | \internal | |
216 | */ |
|
216 | */ | |
217 | qreal QBarSeries::maxCategorySum() |
|
217 | qreal QBarSeries::maxCategorySum() | |
218 | { |
|
218 | { | |
219 | return mModel->maxCategorySum(); |
|
219 | return mModel->maxCategorySum(); | |
220 | } |
|
220 | } | |
221 |
|
221 | |||
222 | /*! |
|
222 | /*! | |
223 | \internal |
|
223 | \internal | |
224 | */ |
|
224 | */ | |
225 | BarChartModel& QBarSeries::model() |
|
225 | BarChartModel& QBarSeries::model() | |
226 | { |
|
226 | { | |
227 | return *mModel; |
|
227 | return *mModel; | |
228 | } |
|
228 | } | |
229 |
|
229 | |||
230 | #include "moc_qbarseries.cpp" |
|
230 | #include "moc_qbarseries.cpp" | |
231 |
|
231 | |||
232 | QTCOMMERCIALCHART_END_NAMESPACE |
|
232 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,66 +1,66 | |||||
1 | #ifndef BARSERIES_H |
|
1 | #ifndef BARSERIES_H | |
2 | #define BARSERIES_H |
|
2 | #define BARSERIES_H | |
3 |
|
3 | |||
4 |
#include "q |
|
4 | #include "qseries.h" | |
5 |
|
5 | |||
6 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
6 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
7 |
|
7 | |||
8 | class QBarCategory; |
|
8 | class QBarCategory; | |
9 | class QBarSet; |
|
9 | class QBarSet; | |
10 | class BarChartModel; |
|
10 | class BarChartModel; | |
11 |
|
11 | |||
12 | // Container for series |
|
12 | // Container for series | |
13 |
class QTCOMMERCIALCHART_EXPORT QBarSeries : public Q |
|
13 | class QTCOMMERCIALCHART_EXPORT QBarSeries : public QSeries | |
14 | { |
|
14 | { | |
15 | Q_OBJECT |
|
15 | Q_OBJECT | |
16 | public: |
|
16 | public: | |
17 | QBarSeries(QBarCategory *category, QObject* parent=0); |
|
17 | QBarSeries(QBarCategory *category, QObject* parent=0); | |
18 |
|
18 | |||
19 |
virtual Q |
|
19 | virtual QSeriesType type() const { return QSeries::SeriesTypeBar; } | |
20 |
|
20 | |||
21 | void addBarSet(QBarSet *set); // Takes ownership of set |
|
21 | void addBarSet(QBarSet *set); // Takes ownership of set | |
22 | void removeBarSet(QBarSet *set); // Releases ownership, doesn't delete set |
|
22 | void removeBarSet(QBarSet *set); // Releases ownership, doesn't delete set | |
23 | int countSets(); |
|
23 | int countSets(); | |
24 | int countCategories(); |
|
24 | int countCategories(); | |
25 | QList<QBarSet*> barSets(); |
|
25 | QList<QBarSet*> barSets(); | |
26 |
|
26 | |||
27 | QList<QString> legend(); // Returns legend of series (ie. names of all sets in series) |
|
27 | QList<QString> legend(); // Returns legend of series (ie. names of all sets in series) | |
28 |
|
28 | |||
29 | public: |
|
29 | public: | |
30 | // TODO: Functions below this are not part of api and will be moved |
|
30 | // TODO: Functions below this are not part of api and will be moved | |
31 | // to private implementation, when we start using it |
|
31 | // to private implementation, when we start using it | |
32 | // TODO: TO PIMPL ---> |
|
32 | // TODO: TO PIMPL ---> | |
33 | QBarSet *barsetAt(int index); |
|
33 | QBarSet *barsetAt(int index); | |
34 | QString label(int category); |
|
34 | QString label(int category); | |
35 | qreal min(); |
|
35 | qreal min(); | |
36 | qreal max(); |
|
36 | qreal max(); | |
37 | qreal valueAt(int set, int category); |
|
37 | qreal valueAt(int set, int category); | |
38 | qreal percentageAt(int set, int category); |
|
38 | qreal percentageAt(int set, int category); | |
39 | qreal categorySum(int category); |
|
39 | qreal categorySum(int category); | |
40 | qreal maxCategorySum(); |
|
40 | qreal maxCategorySum(); | |
41 | BarChartModel& model(); |
|
41 | BarChartModel& model(); | |
42 | // <--- TO PIMPL |
|
42 | // <--- TO PIMPL | |
43 |
|
43 | |||
44 | signals: |
|
44 | signals: | |
45 | void changed(int index); |
|
45 | void changed(int index); | |
46 |
|
46 | |||
47 | // TODO: internal signals, these to private implementation. |
|
47 | // TODO: internal signals, these to private implementation. | |
48 | // TODO: TO PIMPL ---> |
|
48 | // TODO: TO PIMPL ---> | |
49 | void floatingValuesEnabled(bool enabled); |
|
49 | void floatingValuesEnabled(bool enabled); | |
50 | void toolTipEnabled(bool enabled); |
|
50 | void toolTipEnabled(bool enabled); | |
51 | void separatorsEnabled(bool enabled); |
|
51 | void separatorsEnabled(bool enabled); | |
52 | void showToolTip(QPoint pos, QString tip); |
|
52 | void showToolTip(QPoint pos, QString tip); | |
53 | // <--- TO PIMPL |
|
53 | // <--- TO PIMPL | |
54 |
|
54 | |||
55 | public Q_SLOTS: |
|
55 | public Q_SLOTS: | |
56 | void setFloatingValuesEnabled(bool enabled=true); // enables floating values on top of bars |
|
56 | void setFloatingValuesEnabled(bool enabled=true); // enables floating values on top of bars | |
57 | void setToolTipEnabled(bool enabled=true); // enables tooltips |
|
57 | void setToolTipEnabled(bool enabled=true); // enables tooltips | |
58 | void setSeparatorsEnabled(bool enabled=true); // enables separators between categories |
|
58 | void setSeparatorsEnabled(bool enabled=true); // enables separators between categories | |
59 |
|
59 | |||
60 | protected: |
|
60 | protected: | |
61 | BarChartModel* mModel; |
|
61 | BarChartModel* mModel; | |
62 | }; |
|
62 | }; | |
63 |
|
63 | |||
64 | QTCOMMERCIALCHART_END_NAMESPACE |
|
64 | QTCOMMERCIALCHART_END_NAMESPACE | |
65 |
|
65 | |||
66 | #endif // BARSERIES_H |
|
66 | #endif // BARSERIES_H |
@@ -1,36 +1,36 | |||||
1 | #include "qpercentbarseries.h" |
|
1 | #include "qpercentbarseries.h" | |
2 |
|
2 | |||
3 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
3 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
4 |
|
4 | |||
5 | /*! |
|
5 | /*! | |
6 | \class QPercentBarSeries |
|
6 | \class QPercentBarSeries | |
7 | \brief part of QtCommercial chart API. |
|
7 | \brief part of QtCommercial chart API. | |
8 |
|
8 | |||
9 | QPercentBarSeries represents a series of data shown as bars. Each bar of QBarSet is shown as percentage |
|
9 | QPercentBarSeries represents a series of data shown as bars. Each bar of QBarSet is shown as percentage | |
10 | of all bars in category. One QPercentBarSeries can contain multible QBarSet data sets. |
|
10 | of all bars in category. One QPercentBarSeries can contain multible QBarSet data sets. | |
11 | QBarSeries groups the data from sets to categories, which are defined by QBarCategory class. |
|
11 | QBarSeries groups the data from sets to categories, which are defined by QBarCategory class. | |
12 |
|
12 | |||
13 | \mainclass |
|
13 | \mainclass | |
14 |
|
14 | |||
15 | \sa QBarCategory, QBarSet, QStackedBarSeries, QBarSeries |
|
15 | \sa QBarCategory, QBarSet, QStackedBarSeries, QBarSeries | |
16 | */ |
|
16 | */ | |
17 |
|
17 | |||
18 | /*! |
|
18 | /*! | |
19 |
\fn virtual Q |
|
19 | \fn virtual QSeriesType QPercentBarSeries::type() const | |
20 | \brief Returns type of series. |
|
20 | \brief Returns type of series. | |
21 |
\sa Q |
|
21 | \sa QSeries, QSeriesType | |
22 | */ |
|
22 | */ | |
23 |
|
23 | |||
24 | /*! |
|
24 | /*! | |
25 | Constructs empty QPercentBarSeries. Parameter \a category defines the categories for chart. |
|
25 | Constructs empty QPercentBarSeries. Parameter \a category defines the categories for chart. | |
26 | QPercentBarSeries is QObject which is a child of a \a parent. |
|
26 | QPercentBarSeries is QObject which is a child of a \a parent. | |
27 | */ |
|
27 | */ | |
28 | QPercentBarSeries::QPercentBarSeries(QBarCategory *category, QObject *parent) |
|
28 | QPercentBarSeries::QPercentBarSeries(QBarCategory *category, QObject *parent) | |
29 | : QBarSeries(category, parent) |
|
29 | : QBarSeries(category, parent) | |
30 | { |
|
30 | { | |
31 | } |
|
31 | } | |
32 |
|
32 | |||
33 | #include "moc_qpercentbarseries.cpp" |
|
33 | #include "moc_qpercentbarseries.cpp" | |
34 |
|
34 | |||
35 | QTCOMMERCIALCHART_END_NAMESPACE |
|
35 | QTCOMMERCIALCHART_END_NAMESPACE | |
36 |
|
36 |
@@ -1,20 +1,20 | |||||
1 | #ifndef PERCENTBARSERIES_H |
|
1 | #ifndef PERCENTBARSERIES_H | |
2 | #define PERCENTBARSERIES_H |
|
2 | #define PERCENTBARSERIES_H | |
3 |
|
3 | |||
4 | #include "qbarseries.h" |
|
4 | #include "qbarseries.h" | |
5 |
|
5 | |||
6 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
6 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
7 |
|
7 | |||
8 | class QTCOMMERCIALCHART_EXPORT QPercentBarSeries : public QBarSeries |
|
8 | class QTCOMMERCIALCHART_EXPORT QPercentBarSeries : public QBarSeries | |
9 | { |
|
9 | { | |
10 | Q_OBJECT |
|
10 | Q_OBJECT | |
11 | public: |
|
11 | public: | |
12 | QPercentBarSeries(QBarCategory *category, QObject* parent=0); |
|
12 | QPercentBarSeries(QBarCategory *category, QObject* parent=0); | |
13 |
|
13 | |||
14 |
virtual Q |
|
14 | virtual QSeriesType type() const { return QSeries::SeriesTypePercentBar; } | |
15 | }; |
|
15 | }; | |
16 |
|
16 | |||
17 | QTCOMMERCIALCHART_END_NAMESPACE |
|
17 | QTCOMMERCIALCHART_END_NAMESPACE | |
18 |
|
18 | |||
19 |
|
19 | |||
20 | #endif // PERCENTBARSERIES_H |
|
20 | #endif // PERCENTBARSERIES_H |
@@ -1,36 +1,36 | |||||
1 | #include "qstackedbarseries.h" |
|
1 | #include "qstackedbarseries.h" | |
2 |
|
2 | |||
3 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
3 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
4 |
|
4 | |||
5 | /*! |
|
5 | /*! | |
6 | \class QStackedBarSeries |
|
6 | \class QStackedBarSeries | |
7 | \brief part of QtCommercial chart API. |
|
7 | \brief part of QtCommercial chart API. | |
8 |
|
8 | |||
9 | QStackedBarSeries represents a series of data shown as bars. All bars in same category are |
|
9 | QStackedBarSeries represents a series of data shown as bars. All bars in same category are | |
10 | stacked on top of each other. One QStackedBarSeries can contain multible QBarSet data sets. |
|
10 | stacked on top of each other. One QStackedBarSeries can contain multible QBarSet data sets. | |
11 | QStackedBarSeries groups the data from sets to categories, which are defined by QBarCategory class. |
|
11 | QStackedBarSeries groups the data from sets to categories, which are defined by QBarCategory class. | |
12 |
|
12 | |||
13 | \mainclass |
|
13 | \mainclass | |
14 |
|
14 | |||
15 | \sa QBarCategory, QBarSet, QPercentBarSeries, QBarSeries |
|
15 | \sa QBarCategory, QBarSet, QPercentBarSeries, QBarSeries | |
16 | */ |
|
16 | */ | |
17 |
|
17 | |||
18 | /*! |
|
18 | /*! | |
19 |
\fn virtual Q |
|
19 | \fn virtual QSeriesType QStackedBarSeries::type() const | |
20 | \brief Returns type of series. |
|
20 | \brief Returns type of series. | |
21 |
\sa Q |
|
21 | \sa QSeries, QSeriesType | |
22 | */ |
|
22 | */ | |
23 |
|
23 | |||
24 | /*! |
|
24 | /*! | |
25 | Constructs empty QStackedBarSeries. Parameter \a category defines the categories for chart. |
|
25 | Constructs empty QStackedBarSeries. Parameter \a category defines the categories for chart. | |
26 | QStackedBarSeries is QObject which is a child of a \a parent. |
|
26 | QStackedBarSeries is QObject which is a child of a \a parent. | |
27 | */ |
|
27 | */ | |
28 | QStackedBarSeries::QStackedBarSeries(QBarCategory *category, QObject *parent) |
|
28 | QStackedBarSeries::QStackedBarSeries(QBarCategory *category, QObject *parent) | |
29 | : QBarSeries(category, parent) |
|
29 | : QBarSeries(category, parent) | |
30 | { |
|
30 | { | |
31 | } |
|
31 | } | |
32 |
|
32 | |||
33 | #include "moc_qstackedbarseries.cpp" |
|
33 | #include "moc_qstackedbarseries.cpp" | |
34 |
|
34 | |||
35 | QTCOMMERCIALCHART_END_NAMESPACE |
|
35 | QTCOMMERCIALCHART_END_NAMESPACE | |
36 |
|
36 |
@@ -1,21 +1,21 | |||||
1 | #ifndef STACKEDBARSERIES_H |
|
1 | #ifndef STACKEDBARSERIES_H | |
2 | #define STACKEDBARSERIES_H |
|
2 | #define STACKEDBARSERIES_H | |
3 |
|
3 | |||
4 | #include "qbarseries.h" |
|
4 | #include "qbarseries.h" | |
5 |
|
5 | |||
6 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
6 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
7 |
|
7 | |||
8 | class QBarCategory; |
|
8 | class QBarCategory; | |
9 |
|
9 | |||
10 | class QTCOMMERCIALCHART_EXPORT QStackedBarSeries : public QBarSeries |
|
10 | class QTCOMMERCIALCHART_EXPORT QStackedBarSeries : public QBarSeries | |
11 | { |
|
11 | { | |
12 | Q_OBJECT |
|
12 | Q_OBJECT | |
13 | public: |
|
13 | public: | |
14 | QStackedBarSeries(QBarCategory *category, QObject* parent=0); |
|
14 | QStackedBarSeries(QBarCategory *category, QObject* parent=0); | |
15 |
|
15 | |||
16 |
virtual Q |
|
16 | virtual QSeriesType type() const { return QSeries::SeriesTypeStackedBar; } | |
17 | }; |
|
17 | }; | |
18 |
|
18 | |||
19 | QTCOMMERCIALCHART_END_NAMESPACE |
|
19 | QTCOMMERCIALCHART_END_NAMESPACE | |
20 |
|
20 | |||
21 | #endif // STACKEDBARSERIES_H |
|
21 | #endif // STACKEDBARSERIES_H |
@@ -1,357 +1,357 | |||||
1 | #include "chartdataset_p.h" |
|
1 | #include "chartdataset_p.h" | |
2 | #include "qchartaxis.h" |
|
2 | #include "qchartaxis.h" | |
3 | //series |
|
3 | //series | |
4 | #include "qlineseries.h" |
|
4 | #include "qlineseries.h" | |
5 | #include "qbarseries.h" |
|
5 | #include "qbarseries.h" | |
6 | #include "qstackedbarseries.h" |
|
6 | #include "qstackedbarseries.h" | |
7 | #include "qpercentbarseries.h" |
|
7 | #include "qpercentbarseries.h" | |
8 | #include "qpieseries.h" |
|
8 | #include "qpieseries.h" | |
9 | #include "qscatterseries.h" |
|
9 | #include "qscatterseries.h" | |
10 |
|
10 | |||
11 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
11 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
12 |
|
12 | |||
13 | ChartDataSet::ChartDataSet(QObject *parent):QObject(parent), |
|
13 | ChartDataSet::ChartDataSet(QObject *parent):QObject(parent), | |
14 | m_axisX(new QChartAxis(this)), |
|
14 | m_axisX(new QChartAxis(this)), | |
15 | m_axisY(new QChartAxis(this)), |
|
15 | m_axisY(new QChartAxis(this)), | |
16 | m_domainIndex(0), |
|
16 | m_domainIndex(0), | |
17 | m_axisXInitialized(false) |
|
17 | m_axisXInitialized(false) | |
18 | { |
|
18 | { | |
19 | } |
|
19 | } | |
20 |
|
20 | |||
21 | ChartDataSet::~ChartDataSet() |
|
21 | ChartDataSet::~ChartDataSet() | |
22 | { |
|
22 | { | |
23 | // TODO Auto-generated destructor stub |
|
23 | // TODO Auto-generated destructor stub | |
24 | } |
|
24 | } | |
25 |
|
25 | |||
26 | const Domain ChartDataSet::domain(QChartAxis *axisY) const |
|
26 | const Domain ChartDataSet::domain(QChartAxis *axisY) const | |
27 | { |
|
27 | { | |
28 | int i = m_domainMap.count(axisY); |
|
28 | int i = m_domainMap.count(axisY); | |
29 | if(i == 0){ |
|
29 | if(i == 0){ | |
30 | return Domain(); |
|
30 | return Domain(); | |
31 | } |
|
31 | } | |
32 | i = i - m_domainIndex -1; |
|
32 | i = i - m_domainIndex -1; | |
33 | return m_domainMap.values(axisY).at(i); |
|
33 | return m_domainMap.values(axisY).at(i); | |
34 | } |
|
34 | } | |
35 |
|
35 | |||
36 |
void ChartDataSet::addSeries(Q |
|
36 | void ChartDataSet::addSeries(QSeries* series, QChartAxis *axisY) | |
37 | { |
|
37 | { | |
38 | // TODO: we should check the series not already added |
|
38 | // TODO: we should check the series not already added | |
39 |
|
39 | |||
40 | series->setParent(this); // take ownership |
|
40 | series->setParent(this); // take ownership | |
41 | clearDomains(); |
|
41 | clearDomains(); | |
42 |
|
42 | |||
43 | if(axisY==0) axisY = m_axisY; |
|
43 | if(axisY==0) axisY = m_axisY; | |
44 | axisY->setParent(this); // take ownership |
|
44 | axisY->setParent(this); // take ownership | |
45 |
|
45 | |||
46 |
QList<Q |
|
46 | QList<QSeries*> seriesList = m_seriesMap.values(axisY); | |
47 |
|
47 | |||
48 | QList<Domain> domainList = m_domainMap.values(axisY); |
|
48 | QList<Domain> domainList = m_domainMap.values(axisY); | |
49 |
|
49 | |||
50 | Q_ASSERT(domainList.size()<=1); |
|
50 | Q_ASSERT(domainList.size()<=1); | |
51 |
|
51 | |||
52 | Domain domain; |
|
52 | Domain domain; | |
53 |
|
53 | |||
54 | if(domainList.size()>0) domain = domainList.at(0); |
|
54 | if(domainList.size()>0) domain = domainList.at(0); | |
55 |
|
55 | |||
56 | switch(series->type()) |
|
56 | switch(series->type()) | |
57 | { |
|
57 | { | |
58 |
case Q |
|
58 | case QSeries::SeriesTypeLine: { | |
59 |
|
59 | |||
60 | QLineSeries* xyseries = static_cast<QLineSeries*>(series); |
|
60 | QLineSeries* xyseries = static_cast<QLineSeries*>(series); | |
61 |
|
61 | |||
62 | for (int i = 0; i < xyseries->count(); i++) |
|
62 | for (int i = 0; i < xyseries->count(); i++) | |
63 | { |
|
63 | { | |
64 | qreal x = xyseries->x(i); |
|
64 | qreal x = xyseries->x(i); | |
65 | qreal y = xyseries->y(i); |
|
65 | qreal y = xyseries->y(i); | |
66 | domain.m_minX = qMin(domain.m_minX,x); |
|
66 | domain.m_minX = qMin(domain.m_minX,x); | |
67 | domain.m_minY = qMin(domain.m_minY,y); |
|
67 | domain.m_minY = qMin(domain.m_minY,y); | |
68 | domain.m_maxX = qMax(domain.m_maxX,x); |
|
68 | domain.m_maxX = qMax(domain.m_maxX,x); | |
69 | domain.m_maxY = qMax(domain.m_maxY,y); |
|
69 | domain.m_maxY = qMax(domain.m_maxY,y); | |
70 | } |
|
70 | } | |
71 | break; |
|
71 | break; | |
72 | } |
|
72 | } | |
73 |
case Q |
|
73 | case QSeries::SeriesTypeBar: { | |
74 | qDebug() << "QChartSeries::SeriesTypeBar"; |
|
74 | qDebug() << "QChartSeries::SeriesTypeBar"; | |
75 | QBarSeries* barSeries = static_cast<QBarSeries*>(series); |
|
75 | QBarSeries* barSeries = static_cast<QBarSeries*>(series); | |
76 | qreal x = barSeries->countCategories(); |
|
76 | qreal x = barSeries->countCategories(); | |
77 | qreal y = barSeries->max(); |
|
77 | qreal y = barSeries->max(); | |
78 | domain.m_minX = qMin(domain.m_minX,x); |
|
78 | domain.m_minX = qMin(domain.m_minX,x); | |
79 | domain.m_minY = qMin(domain.m_minY,y); |
|
79 | domain.m_minY = qMin(domain.m_minY,y); | |
80 | domain.m_maxX = qMax(domain.m_maxX,x); |
|
80 | domain.m_maxX = qMax(domain.m_maxX,x); | |
81 | domain.m_maxY = qMax(domain.m_maxY,y); |
|
81 | domain.m_maxY = qMax(domain.m_maxY,y); | |
82 | break; |
|
82 | break; | |
83 | } |
|
83 | } | |
84 |
case Q |
|
84 | case QSeries::SeriesTypeStackedBar: { | |
85 | qDebug() << "QChartSeries::SeriesTypeStackedBar"; |
|
85 | qDebug() << "QChartSeries::SeriesTypeStackedBar"; | |
86 |
|
86 | |||
87 | QStackedBarSeries* stackedBarSeries = static_cast<QStackedBarSeries*>(series); |
|
87 | QStackedBarSeries* stackedBarSeries = static_cast<QStackedBarSeries*>(series); | |
88 | qreal x = stackedBarSeries->countCategories(); |
|
88 | qreal x = stackedBarSeries->countCategories(); | |
89 | qreal y = stackedBarSeries->maxCategorySum(); |
|
89 | qreal y = stackedBarSeries->maxCategorySum(); | |
90 | domain.m_minX = qMin(domain.m_minX,x); |
|
90 | domain.m_minX = qMin(domain.m_minX,x); | |
91 | domain.m_minY = qMin(domain.m_minY,y); |
|
91 | domain.m_minY = qMin(domain.m_minY,y); | |
92 | domain.m_maxX = qMax(domain.m_maxX,x); |
|
92 | domain.m_maxX = qMax(domain.m_maxX,x); | |
93 | domain.m_maxY = qMax(domain.m_maxY,y); |
|
93 | domain.m_maxY = qMax(domain.m_maxY,y); | |
94 | break; |
|
94 | break; | |
95 | } |
|
95 | } | |
96 |
case Q |
|
96 | case QSeries::SeriesTypePercentBar: { | |
97 | qDebug() << "QChartSeries::SeriesTypePercentBar"; |
|
97 | qDebug() << "QChartSeries::SeriesTypePercentBar"; | |
98 |
|
98 | |||
99 | QPercentBarSeries* percentBarSeries = static_cast<QPercentBarSeries*>(series); |
|
99 | QPercentBarSeries* percentBarSeries = static_cast<QPercentBarSeries*>(series); | |
100 | qreal x = percentBarSeries->countCategories(); |
|
100 | qreal x = percentBarSeries->countCategories(); | |
101 | domain.m_minX = qMin(domain.m_minX,x); |
|
101 | domain.m_minX = qMin(domain.m_minX,x); | |
102 | domain.m_minY = 0; |
|
102 | domain.m_minY = 0; | |
103 | domain.m_maxX = qMax(domain.m_maxX,x); |
|
103 | domain.m_maxX = qMax(domain.m_maxX,x); | |
104 | domain.m_maxY = 100; |
|
104 | domain.m_maxY = 100; | |
105 | break; |
|
105 | break; | |
106 | } |
|
106 | } | |
107 |
|
107 | |||
108 |
case Q |
|
108 | case QSeries::SeriesTypePie: { | |
109 | QPieSeries *pieSeries = static_cast<QPieSeries *>(series); |
|
109 | QPieSeries *pieSeries = static_cast<QPieSeries *>(series); | |
110 | // TODO: domain stuff |
|
110 | // TODO: domain stuff | |
111 | break; |
|
111 | break; | |
112 | } |
|
112 | } | |
113 |
|
113 | |||
114 |
case Q |
|
114 | case QSeries::SeriesTypeScatter: { | |
115 | QScatterSeries *scatterSeries = qobject_cast<QScatterSeries *>(series); |
|
115 | QScatterSeries *scatterSeries = qobject_cast<QScatterSeries *>(series); | |
116 | Q_ASSERT(scatterSeries); |
|
116 | Q_ASSERT(scatterSeries); | |
117 | foreach (QPointF point, scatterSeries->data()) { |
|
117 | foreach (QPointF point, scatterSeries->data()) { | |
118 | domain.m_minX = qMin(domain.m_minX, point.x()); |
|
118 | domain.m_minX = qMin(domain.m_minX, point.x()); | |
119 | domain.m_maxX = qMax(domain.m_maxX, point.x()); |
|
119 | domain.m_maxX = qMax(domain.m_maxX, point.x()); | |
120 | domain.m_minY = qMin(domain.m_minY, point.y()); |
|
120 | domain.m_minY = qMin(domain.m_minY, point.y()); | |
121 | domain.m_maxY = qMax(domain.m_maxY, point.y()); |
|
121 | domain.m_maxY = qMax(domain.m_maxY, point.y()); | |
122 | } |
|
122 | } | |
123 | break; |
|
123 | break; | |
124 | } |
|
124 | } | |
125 |
|
125 | |||
126 | default: { |
|
126 | default: { | |
127 | qDebug()<<__FUNCTION__<<"type" << series->type()<<"not supported"; |
|
127 | qDebug()<<__FUNCTION__<<"type" << series->type()<<"not supported"; | |
128 | return; |
|
128 | return; | |
129 | break; |
|
129 | break; | |
130 | } |
|
130 | } | |
131 |
|
131 | |||
132 | } |
|
132 | } | |
133 |
|
133 | |||
134 | if(!m_domainMap.contains(axisY)) |
|
134 | if(!m_domainMap.contains(axisY)) | |
135 | { |
|
135 | { | |
136 | emit axisAdded(axisY); |
|
136 | emit axisAdded(axisY); | |
137 | QObject::connect(axisY,SIGNAL(minChanged(qreal)),this,SLOT(handleMinChanged(qreal))); |
|
137 | QObject::connect(axisY,SIGNAL(minChanged(qreal)),this,SLOT(handleMinChanged(qreal))); | |
138 | QObject::connect(axisY,SIGNAL(maxChanged(qreal)),this,SLOT(handleMaxChanged(qreal))); |
|
138 | QObject::connect(axisY,SIGNAL(maxChanged(qreal)),this,SLOT(handleMaxChanged(qreal))); | |
139 | QObject::connect(axisY,SIGNAL(ticksChanged(QChartAxis*)),this,SLOT(handleTickChanged(QChartAxis*))); |
|
139 | QObject::connect(axisY,SIGNAL(ticksChanged(QChartAxis*)),this,SLOT(handleTickChanged(QChartAxis*))); | |
140 | } |
|
140 | } | |
141 | m_domainMap.replace(axisY,domain); |
|
141 | m_domainMap.replace(axisY,domain); | |
142 | m_seriesMap.insert(axisY,series); |
|
142 | m_seriesMap.insert(axisY,series); | |
143 |
|
143 | |||
144 | if(!m_axisXInitialized) |
|
144 | if(!m_axisXInitialized) | |
145 | { |
|
145 | { | |
146 | emit axisAdded(axisX()); |
|
146 | emit axisAdded(axisX()); | |
147 | QObject::connect(axisX(),SIGNAL(minChanged(qreal)),this,SLOT(handleMinChanged(qreal))); |
|
147 | QObject::connect(axisX(),SIGNAL(minChanged(qreal)),this,SLOT(handleMinChanged(qreal))); | |
148 | QObject::connect(axisX(),SIGNAL(maxChanged(qreal)),this,SLOT(handleMaxChanged(qreal))); |
|
148 | QObject::connect(axisX(),SIGNAL(maxChanged(qreal)),this,SLOT(handleMaxChanged(qreal))); | |
149 | QObject::connect(axisX(),SIGNAL(ticksChanged(QChartAxis*)),this,SLOT(handleTickChanged(QChartAxis*))); |
|
149 | QObject::connect(axisX(),SIGNAL(ticksChanged(QChartAxis*)),this,SLOT(handleTickChanged(QChartAxis*))); | |
150 | m_axisXInitialized=true; |
|
150 | m_axisXInitialized=true; | |
151 | } |
|
151 | } | |
152 |
|
152 | |||
153 |
|
153 | |||
154 | emit seriesAdded(series); |
|
154 | emit seriesAdded(series); | |
155 | QStringList ylabels = createLabels(axisY,domain.m_minY,domain.m_maxY); |
|
155 | QStringList ylabels = createLabels(axisY,domain.m_minY,domain.m_maxY); | |
156 | QStringList xlabels = createLabels(axisX(),domain.m_minX,domain.m_maxX); |
|
156 | QStringList xlabels = createLabels(axisX(),domain.m_minX,domain.m_maxX); | |
157 | emit axisLabelsChanged(axisY,ylabels); |
|
157 | emit axisLabelsChanged(axisY,ylabels); | |
158 | emit axisLabelsChanged(axisX(),xlabels); |
|
158 | emit axisLabelsChanged(axisX(),xlabels); | |
159 | emit seriesDomainChanged(series,domain); |
|
159 | emit seriesDomainChanged(series,domain); | |
160 |
|
160 | |||
161 | } |
|
161 | } | |
162 |
|
162 | |||
163 |
void ChartDataSet::removeSeries(Q |
|
163 | void ChartDataSet::removeSeries(QSeries* series) | |
164 | { |
|
164 | { | |
165 | QList<QChartAxis*> keys = m_seriesMap.uniqueKeys(); |
|
165 | QList<QChartAxis*> keys = m_seriesMap.uniqueKeys(); | |
166 | foreach(QChartAxis* axis , keys) { |
|
166 | foreach(QChartAxis* axis , keys) { | |
167 | if(m_seriesMap.contains(axis,series)){ |
|
167 | if(m_seriesMap.contains(axis,series)){ | |
168 | emit seriesRemoved(series); |
|
168 | emit seriesRemoved(series); | |
169 | m_seriesMap.remove(axis,series); |
|
169 | m_seriesMap.remove(axis,series); | |
170 | //remove axis if no longer there |
|
170 | //remove axis if no longer there | |
171 | if(!m_seriesMap.contains(axis)){ |
|
171 | if(!m_seriesMap.contains(axis)){ | |
172 | emit axisRemoved(axis); |
|
172 | emit axisRemoved(axis); | |
173 | m_domainMap.remove(axis); |
|
173 | m_domainMap.remove(axis); | |
174 | if(axis != m_axisY) |
|
174 | if(axis != m_axisY) | |
175 | delete axis; |
|
175 | delete axis; | |
176 | } |
|
176 | } | |
177 | series->setParent(0); |
|
177 | series->setParent(0); | |
178 | break; |
|
178 | break; | |
179 | } |
|
179 | } | |
180 | } |
|
180 | } | |
181 | } |
|
181 | } | |
182 |
|
182 | |||
183 | void ChartDataSet::removeAllSeries() |
|
183 | void ChartDataSet::removeAllSeries() | |
184 | { |
|
184 | { | |
185 | QList<QChartAxis*> keys = m_seriesMap.uniqueKeys(); |
|
185 | QList<QChartAxis*> keys = m_seriesMap.uniqueKeys(); | |
186 | foreach(QChartAxis* axis , keys) { |
|
186 | foreach(QChartAxis* axis , keys) { | |
187 |
QList<Q |
|
187 | QList<QSeries*> seriesList = m_seriesMap.values(axis); | |
188 | for(int i =0 ; i < seriesList.size();i++ ) |
|
188 | for(int i =0 ; i < seriesList.size();i++ ) | |
189 | { |
|
189 | { | |
190 | emit seriesRemoved(seriesList.at(i)); |
|
190 | emit seriesRemoved(seriesList.at(i)); | |
191 | delete(seriesList.at(i)); |
|
191 | delete(seriesList.at(i)); | |
192 | } |
|
192 | } | |
193 | m_seriesMap.remove(axis); |
|
193 | m_seriesMap.remove(axis); | |
194 | m_domainMap.remove(axis); |
|
194 | m_domainMap.remove(axis); | |
195 | emit axisRemoved(axis); |
|
195 | emit axisRemoved(axis); | |
196 | if(axis != m_axisY) delete axis; |
|
196 | if(axis != m_axisY) delete axis; | |
197 | } |
|
197 | } | |
198 | m_domainIndex=0; |
|
198 | m_domainIndex=0; | |
199 | } |
|
199 | } | |
200 |
|
200 | |||
201 | bool ChartDataSet::nextDomain() |
|
201 | bool ChartDataSet::nextDomain() | |
202 | { |
|
202 | { | |
203 | int limit = (m_domainMap.values().size()/m_domainMap.uniqueKeys().size())-1; |
|
203 | int limit = (m_domainMap.values().size()/m_domainMap.uniqueKeys().size())-1; | |
204 |
|
204 | |||
205 | if (m_domainIndex < limit) { |
|
205 | if (m_domainIndex < limit) { | |
206 | m_domainIndex++; |
|
206 | m_domainIndex++; | |
207 | setDomain(m_domainIndex); |
|
207 | setDomain(m_domainIndex); | |
208 | return true; |
|
208 | return true; | |
209 | } |
|
209 | } | |
210 | else { |
|
210 | else { | |
211 | return false; |
|
211 | return false; | |
212 | } |
|
212 | } | |
213 | } |
|
213 | } | |
214 |
|
214 | |||
215 | bool ChartDataSet::previousDomain() |
|
215 | bool ChartDataSet::previousDomain() | |
216 | { |
|
216 | { | |
217 | if (m_domainIndex > 0) { |
|
217 | if (m_domainIndex > 0) { | |
218 | m_domainIndex--; |
|
218 | m_domainIndex--; | |
219 | setDomain(m_domainIndex); |
|
219 | setDomain(m_domainIndex); | |
220 | return true; |
|
220 | return true; | |
221 | } |
|
221 | } | |
222 | else { |
|
222 | else { | |
223 | return false; |
|
223 | return false; | |
224 | } |
|
224 | } | |
225 | } |
|
225 | } | |
226 |
|
226 | |||
227 | void ChartDataSet::setDomain(int index) |
|
227 | void ChartDataSet::setDomain(int index) | |
228 | { |
|
228 | { | |
229 | QList<QChartAxis*> domainList = m_domainMap.uniqueKeys(); |
|
229 | QList<QChartAxis*> domainList = m_domainMap.uniqueKeys(); | |
230 |
|
230 | |||
231 | Domain domain; |
|
231 | Domain domain; | |
232 |
|
232 | |||
233 | foreach (QChartAxis* axis , domainList) { |
|
233 | foreach (QChartAxis* axis , domainList) { | |
234 | int i = m_domainMap.count(axis) - index -1; |
|
234 | int i = m_domainMap.count(axis) - index -1; | |
235 | Q_ASSERT(i>=0); |
|
235 | Q_ASSERT(i>=0); | |
236 | domain = m_domainMap.values(axis).at(i); |
|
236 | domain = m_domainMap.values(axis).at(i); | |
237 | QStringList labels = createLabels(axis,domain.m_minY,domain.m_maxY); |
|
237 | QStringList labels = createLabels(axis,domain.m_minY,domain.m_maxY); | |
238 |
QList<Q |
|
238 | QList<QSeries*> seriesList = m_seriesMap.values(axis); | |
239 |
foreach(Q |
|
239 | foreach(QSeries* series, seriesList) { | |
240 | emit seriesDomainChanged(series,domain); |
|
240 | emit seriesDomainChanged(series,domain); | |
241 | } |
|
241 | } | |
242 | emit axisLabelsChanged(axis,labels); |
|
242 | emit axisLabelsChanged(axis,labels); | |
243 | } |
|
243 | } | |
244 |
|
244 | |||
245 | QStringList labels = createLabels(axisX(),domain.m_minX,domain.m_maxX); |
|
245 | QStringList labels = createLabels(axisX(),domain.m_minX,domain.m_maxX); | |
246 | emit axisLabelsChanged(axisX(),labels); |
|
246 | emit axisLabelsChanged(axisX(),labels); | |
247 | } |
|
247 | } | |
248 |
|
248 | |||
249 | void ChartDataSet::clearDomains(int toIndex) |
|
249 | void ChartDataSet::clearDomains(int toIndex) | |
250 | { |
|
250 | { | |
251 | Q_ASSERT(toIndex>=0); |
|
251 | Q_ASSERT(toIndex>=0); | |
252 |
|
252 | |||
253 | m_domainIndex = toIndex; |
|
253 | m_domainIndex = toIndex; | |
254 |
|
254 | |||
255 | QList<QChartAxis*> keys = m_domainMap.uniqueKeys(); |
|
255 | QList<QChartAxis*> keys = m_domainMap.uniqueKeys(); | |
256 |
|
256 | |||
257 | foreach (QChartAxis* key , keys) |
|
257 | foreach (QChartAxis* key , keys) | |
258 | { |
|
258 | { | |
259 | QList<Domain> domains = m_domainMap.values(key); |
|
259 | QList<Domain> domains = m_domainMap.values(key); | |
260 | m_domainMap.remove(key); |
|
260 | m_domainMap.remove(key); | |
261 | int i = domains.size() - toIndex - 1; |
|
261 | int i = domains.size() - toIndex - 1; | |
262 | while(i--){ |
|
262 | while(i--){ | |
263 | domains.removeFirst(); |
|
263 | domains.removeFirst(); | |
264 | } |
|
264 | } | |
265 | for(int j=domains.size()-1; j>=0 ;j--) |
|
265 | for(int j=domains.size()-1; j>=0 ;j--) | |
266 | m_domainMap.insert(key,domains.at(j)); |
|
266 | m_domainMap.insert(key,domains.at(j)); | |
267 | } |
|
267 | } | |
268 | } |
|
268 | } | |
269 |
|
269 | |||
270 | void ChartDataSet::addDomain(const QRectF& rect, const QRectF& viewport) |
|
270 | void ChartDataSet::addDomain(const QRectF& rect, const QRectF& viewport) | |
271 | { |
|
271 | { | |
272 | Q_ASSERT(rect.isValid()); |
|
272 | Q_ASSERT(rect.isValid()); | |
273 | Q_ASSERT(viewport.isValid()); |
|
273 | Q_ASSERT(viewport.isValid()); | |
274 |
|
274 | |||
275 | clearDomains(m_domainIndex); |
|
275 | clearDomains(m_domainIndex); | |
276 |
|
276 | |||
277 | QList<QChartAxis*> domainList = m_domainMap.uniqueKeys(); |
|
277 | QList<QChartAxis*> domainList = m_domainMap.uniqueKeys(); | |
278 |
|
278 | |||
279 | Domain domain; |
|
279 | Domain domain; | |
280 |
|
280 | |||
281 | foreach (QChartAxis* axis , domainList){ |
|
281 | foreach (QChartAxis* axis , domainList){ | |
282 | domain = m_domainMap.value(axis).subDomain(rect,viewport.width(),viewport.height()); |
|
282 | domain = m_domainMap.value(axis).subDomain(rect,viewport.width(),viewport.height()); | |
283 | QStringList labels = createLabels(axis,domain.m_minY,domain.m_maxY); |
|
283 | QStringList labels = createLabels(axis,domain.m_minY,domain.m_maxY); | |
284 |
QList<Q |
|
284 | QList<QSeries*> seriesList = m_seriesMap.values(axis); | |
285 |
foreach(Q |
|
285 | foreach(QSeries* series, seriesList){ | |
286 | emit seriesDomainChanged(series,domain); |
|
286 | emit seriesDomainChanged(series,domain); | |
287 | } |
|
287 | } | |
288 | emit axisLabelsChanged(axis,labels); |
|
288 | emit axisLabelsChanged(axis,labels); | |
289 | m_domainMap.insert(axis,domain); |
|
289 | m_domainMap.insert(axis,domain); | |
290 | } |
|
290 | } | |
291 |
|
291 | |||
292 | QStringList labels = createLabels(axisX(),domain.m_minX,domain.m_maxX); |
|
292 | QStringList labels = createLabels(axisX(),domain.m_minX,domain.m_maxX); | |
293 | emit axisLabelsChanged(axisX(),labels); |
|
293 | emit axisLabelsChanged(axisX(),labels); | |
294 |
|
294 | |||
295 | m_domainIndex++; |
|
295 | m_domainIndex++; | |
296 | } |
|
296 | } | |
297 |
|
297 | |||
298 |
QChartAxis* ChartDataSet::axisY(Q |
|
298 | QChartAxis* ChartDataSet::axisY(QSeries* series) const | |
299 | { |
|
299 | { | |
300 | if(series == 0) return m_axisY; |
|
300 | if(series == 0) return m_axisY; | |
301 |
|
301 | |||
302 | QList<QChartAxis*> keys = m_seriesMap.uniqueKeys(); |
|
302 | QList<QChartAxis*> keys = m_seriesMap.uniqueKeys(); | |
303 |
|
303 | |||
304 | foreach(QChartAxis* axis , keys) { |
|
304 | foreach(QChartAxis* axis , keys) { | |
305 | if(m_seriesMap.contains(axis,series)){ |
|
305 | if(m_seriesMap.contains(axis,series)){ | |
306 | return axis; |
|
306 | return axis; | |
307 | } |
|
307 | } | |
308 | } |
|
308 | } | |
309 | return 0; |
|
309 | return 0; | |
310 | } |
|
310 | } | |
311 |
|
311 | |||
312 | QStringList ChartDataSet::createLabels(QChartAxis* axis,qreal min, qreal max) |
|
312 | QStringList ChartDataSet::createLabels(QChartAxis* axis,qreal min, qreal max) | |
313 | { |
|
313 | { | |
314 | Q_ASSERT(max>=min); |
|
314 | Q_ASSERT(max>=min); | |
315 |
|
315 | |||
316 | QStringList labels; |
|
316 | QStringList labels; | |
317 |
|
317 | |||
318 | int ticks = axis->ticksCount()-1; |
|
318 | int ticks = axis->ticksCount()-1; | |
319 |
|
319 | |||
320 | for(int i=0; i<= ticks; i++){ |
|
320 | for(int i=0; i<= ticks; i++){ | |
321 | qreal value = min + (i * (max - min)/ ticks); |
|
321 | qreal value = min + (i * (max - min)/ ticks); | |
322 | QString label = axis->axisTickLabel(value); |
|
322 | QString label = axis->axisTickLabel(value); | |
323 | if(label.isEmpty()){ |
|
323 | if(label.isEmpty()){ | |
324 | labels << QString::number(value); |
|
324 | labels << QString::number(value); | |
325 | }else{ |
|
325 | }else{ | |
326 | labels << label; |
|
326 | labels << label; | |
327 | } |
|
327 | } | |
328 | } |
|
328 | } | |
329 | return labels; |
|
329 | return labels; | |
330 | } |
|
330 | } | |
331 |
|
331 | |||
332 |
|
332 | |||
333 | void ChartDataSet::handleMinChanged(qreal min) |
|
333 | void ChartDataSet::handleMinChanged(qreal min) | |
334 | { |
|
334 | { | |
335 |
|
335 | |||
336 | } |
|
336 | } | |
337 |
|
337 | |||
338 | void ChartDataSet::handleMaxChanged(qreal max) |
|
338 | void ChartDataSet::handleMaxChanged(qreal max) | |
339 | { |
|
339 | { | |
340 |
|
340 | |||
341 | } |
|
341 | } | |
342 |
|
342 | |||
343 | void ChartDataSet::handleTickChanged(QChartAxis* axis) |
|
343 | void ChartDataSet::handleTickChanged(QChartAxis* axis) | |
344 | { |
|
344 | { | |
345 | Domain domain = m_domainMap.value(axisY()); |
|
345 | Domain domain = m_domainMap.value(axisY()); | |
346 | if(axis==axisX()){ |
|
346 | if(axis==axisX()){ | |
347 | QStringList labels = createLabels(axis,domain.m_minX,domain.m_maxX); |
|
347 | QStringList labels = createLabels(axis,domain.m_minX,domain.m_maxX); | |
348 | emit axisLabelsChanged(axis,labels); |
|
348 | emit axisLabelsChanged(axis,labels); | |
349 | }else{ |
|
349 | }else{ | |
350 | QStringList labels = createLabels(axis,domain.m_minY,domain.m_maxY); |
|
350 | QStringList labels = createLabels(axis,domain.m_minY,domain.m_maxY); | |
351 | emit axisLabelsChanged(axis,labels); |
|
351 | emit axisLabelsChanged(axis,labels); | |
352 | } |
|
352 | } | |
353 | } |
|
353 | } | |
354 |
|
354 | |||
355 | #include "moc_chartdataset_p.cpp" |
|
355 | #include "moc_chartdataset_p.cpp" | |
356 |
|
356 | |||
357 | QTCOMMERCIALCHART_END_NAMESPACE |
|
357 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,60 +1,60 | |||||
1 | #ifndef CHARTDATASET_P_H_ |
|
1 | #ifndef CHARTDATASET_P_H_ | |
2 | #define CHARTDATASET_P_H_ |
|
2 | #define CHARTDATASET_P_H_ | |
3 |
|
3 | |||
4 |
#include "q |
|
4 | #include "qseries.h" | |
5 | #include "domain_p.h" |
|
5 | #include "domain_p.h" | |
6 | #include <QVector> |
|
6 | #include <QVector> | |
7 |
|
7 | |||
8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
9 |
|
9 | |||
10 | class QChartAxis; |
|
10 | class QChartAxis; | |
11 |
|
11 | |||
12 | class ChartDataSet : public QObject |
|
12 | class ChartDataSet : public QObject | |
13 | { |
|
13 | { | |
14 | Q_OBJECT |
|
14 | Q_OBJECT | |
15 | public: |
|
15 | public: | |
16 | ChartDataSet(QObject* parent=0); |
|
16 | ChartDataSet(QObject* parent=0); | |
17 | virtual ~ChartDataSet(); |
|
17 | virtual ~ChartDataSet(); | |
18 |
|
18 | |||
19 |
void addSeries(Q |
|
19 | void addSeries(QSeries* series,QChartAxis *axisY = 0); | |
20 |
void removeSeries(Q |
|
20 | void removeSeries(QSeries* series); | |
21 | void removeAllSeries(); |
|
21 | void removeAllSeries(); | |
22 | void addDomain(const QRectF& rect, const QRectF& viewport); |
|
22 | void addDomain(const QRectF& rect, const QRectF& viewport); | |
23 | bool nextDomain(); |
|
23 | bool nextDomain(); | |
24 | bool previousDomain(); |
|
24 | bool previousDomain(); | |
25 | void clearDomains(int toIndex =0); |
|
25 | void clearDomains(int toIndex =0); | |
26 | const Domain domain(QChartAxis *axisY) const; |
|
26 | const Domain domain(QChartAxis *axisY) const; | |
27 | int domainIndex() const {return m_domainIndex;} |
|
27 | int domainIndex() const {return m_domainIndex;} | |
28 | void setDomain(int index); |
|
28 | void setDomain(int index); | |
29 |
|
29 | |||
30 | QChartAxis* axisX() const { return m_axisX;}; |
|
30 | QChartAxis* axisX() const { return m_axisX;}; | |
31 |
QChartAxis* axisY(Q |
|
31 | QChartAxis* axisY(QSeries* series = 0) const; | |
32 |
|
32 | |||
33 | signals: |
|
33 | signals: | |
34 |
void seriesAdded(Q |
|
34 | void seriesAdded(QSeries* series); | |
35 |
void seriesRemoved(Q |
|
35 | void seriesRemoved(QSeries* series); | |
36 | void axisAdded(QChartAxis* axis); |
|
36 | void axisAdded(QChartAxis* axis); | |
37 | void axisRemoved(QChartAxis* axis); |
|
37 | void axisRemoved(QChartAxis* axis); | |
38 | void axisLabelsChanged(QChartAxis* axis, const QStringList& labels); |
|
38 | void axisLabelsChanged(QChartAxis* axis, const QStringList& labels); | |
39 |
void seriesDomainChanged(Q |
|
39 | void seriesDomainChanged(QSeries* series,const Domain& domain); | |
40 |
|
40 | |||
41 | private slots: |
|
41 | private slots: | |
42 | void handleMinChanged(qreal min); |
|
42 | void handleMinChanged(qreal min); | |
43 | void handleMaxChanged(qreal max); |
|
43 | void handleMaxChanged(qreal max); | |
44 | void handleTickChanged(QChartAxis*); |
|
44 | void handleTickChanged(QChartAxis*); | |
45 |
|
45 | |||
46 | private: |
|
46 | private: | |
47 | QStringList createLabels(QChartAxis* axis,qreal min, qreal max); |
|
47 | QStringList createLabels(QChartAxis* axis,qreal min, qreal max); | |
48 |
|
48 | |||
49 | private: |
|
49 | private: | |
50 | QMultiMap<QChartAxis*, Domain> m_domainMap; |
|
50 | QMultiMap<QChartAxis*, Domain> m_domainMap; | |
51 |
QMultiMap<QChartAxis*, Q |
|
51 | QMultiMap<QChartAxis*, QSeries*> m_seriesMap; | |
52 | QChartAxis* m_axisX; |
|
52 | QChartAxis* m_axisX; | |
53 | QChartAxis* m_axisY; |
|
53 | QChartAxis* m_axisY; | |
54 | int m_domainIndex; |
|
54 | int m_domainIndex; | |
55 | bool m_axisXInitialized; |
|
55 | bool m_axisXInitialized; | |
56 | }; |
|
56 | }; | |
57 |
|
57 | |||
58 | QTCOMMERCIALCHART_END_NAMESPACE |
|
58 | QTCOMMERCIALCHART_END_NAMESPACE | |
59 |
|
59 | |||
60 | #endif /* CHARTENGINE_P_H_ */ |
|
60 | #endif /* CHARTENGINE_P_H_ */ |
@@ -1,283 +1,283 | |||||
1 | #include "qchart.h" |
|
1 | #include "qchart.h" | |
2 | #include "qchartaxis.h" |
|
2 | #include "qchartaxis.h" | |
3 | #include "chartpresenter_p.h" |
|
3 | #include "chartpresenter_p.h" | |
4 | #include "chartdataset_p.h" |
|
4 | #include "chartdataset_p.h" | |
5 | #include "charttheme_p.h" |
|
5 | #include "charttheme_p.h" | |
6 | //series |
|
6 | //series | |
7 | #include "qbarseries.h" |
|
7 | #include "qbarseries.h" | |
8 | #include "qstackedbarseries.h" |
|
8 | #include "qstackedbarseries.h" | |
9 | #include "qpercentbarseries.h" |
|
9 | #include "qpercentbarseries.h" | |
10 | #include "qlineseries.h" |
|
10 | #include "qlineseries.h" | |
11 | #include "qpieseries.h" |
|
11 | #include "qpieseries.h" | |
12 | #include "qscatterseries.h" |
|
12 | #include "qscatterseries.h" | |
13 | //items |
|
13 | //items | |
14 | #include "axisitem_p.h" |
|
14 | #include "axisitem_p.h" | |
15 | #include "axisanimationitem_p.h" |
|
15 | #include "axisanimationitem_p.h" | |
16 | #include "barpresenter.h" |
|
16 | #include "barpresenter.h" | |
17 | #include "stackedbarpresenter.h" |
|
17 | #include "stackedbarpresenter.h" | |
18 | #include "linechartitem_p.h" |
|
18 | #include "linechartitem_p.h" | |
19 | #include "percentbarpresenter.h" |
|
19 | #include "percentbarpresenter.h" | |
20 | #include "linechartanimationitem_p.h" |
|
20 | #include "linechartanimationitem_p.h" | |
21 | #include "piepresenter_p.h" |
|
21 | #include "piepresenter_p.h" | |
22 | #include "scatterpresenter_p.h" |
|
22 | #include "scatterpresenter_p.h" | |
23 |
|
23 | |||
24 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
24 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
25 |
|
25 | |||
26 | ChartPresenter::ChartPresenter(QChart* chart,ChartDataSet* dataset):QObject(chart), |
|
26 | ChartPresenter::ChartPresenter(QChart* chart,ChartDataSet* dataset):QObject(chart), | |
27 | m_chart(chart), |
|
27 | m_chart(chart), | |
28 | m_dataset(dataset), |
|
28 | m_dataset(dataset), | |
29 | m_chartTheme(0), |
|
29 | m_chartTheme(0), | |
30 | m_marginSize(0), |
|
30 | m_marginSize(0), | |
31 | m_rect(QRectF(QPoint(0,0),m_chart->size())), |
|
31 | m_rect(QRectF(QPoint(0,0),m_chart->size())), | |
32 | m_options(0) |
|
32 | m_options(0) | |
33 | { |
|
33 | { | |
34 | createConnections(); |
|
34 | createConnections(); | |
35 | setChartTheme(QChart::ChartThemeDefault); |
|
35 | setChartTheme(QChart::ChartThemeDefault); | |
36 |
|
36 | |||
37 | } |
|
37 | } | |
38 |
|
38 | |||
39 | ChartPresenter::~ChartPresenter() |
|
39 | ChartPresenter::~ChartPresenter() | |
40 | { |
|
40 | { | |
41 | } |
|
41 | } | |
42 |
|
42 | |||
43 | void ChartPresenter::createConnections() |
|
43 | void ChartPresenter::createConnections() | |
44 | { |
|
44 | { | |
45 | QObject::connect(m_chart,SIGNAL(geometryChanged()),this,SLOT(handleGeometryChanged())); |
|
45 | QObject::connect(m_chart,SIGNAL(geometryChanged()),this,SLOT(handleGeometryChanged())); | |
46 |
QObject::connect(m_dataset,SIGNAL(seriesAdded(Q |
|
46 | QObject::connect(m_dataset,SIGNAL(seriesAdded(QSeries*)),this,SLOT(handleSeriesAdded(QSeries*))); | |
47 |
QObject::connect(m_dataset,SIGNAL(seriesRemoved(Q |
|
47 | QObject::connect(m_dataset,SIGNAL(seriesRemoved(QSeries*)),this,SLOT(handleSeriesRemoved(QSeries*))); | |
48 | QObject::connect(m_dataset,SIGNAL(axisAdded(QChartAxis*)),this,SLOT(handleAxisAdded(QChartAxis*))); |
|
48 | QObject::connect(m_dataset,SIGNAL(axisAdded(QChartAxis*)),this,SLOT(handleAxisAdded(QChartAxis*))); | |
49 | QObject::connect(m_dataset,SIGNAL(axisRemoved(QChartAxis*)),this,SLOT(handleAxisRemoved(QChartAxis*))); |
|
49 | QObject::connect(m_dataset,SIGNAL(axisRemoved(QChartAxis*)),this,SLOT(handleAxisRemoved(QChartAxis*))); | |
50 |
QObject::connect(m_dataset,SIGNAL(seriesDomainChanged(Q |
|
50 | QObject::connect(m_dataset,SIGNAL(seriesDomainChanged(QSeries*,const Domain&)),this,SLOT(handleSeriesDomainChanged(QSeries*,const Domain&))); | |
51 | QObject::connect(m_dataset,SIGNAL(axisLabelsChanged(QChartAxis*,const QStringList&)),this,SLOT(handleAxisLabelsChanged(QChartAxis*,const QStringList&))); |
|
51 | QObject::connect(m_dataset,SIGNAL(axisLabelsChanged(QChartAxis*,const QStringList&)),this,SLOT(handleAxisLabelsChanged(QChartAxis*,const QStringList&))); | |
52 | } |
|
52 | } | |
53 |
|
53 | |||
54 |
|
54 | |||
55 | QRectF ChartPresenter::geometry() const |
|
55 | QRectF ChartPresenter::geometry() const | |
56 | { |
|
56 | { | |
57 | return m_rect; |
|
57 | return m_rect; | |
58 | } |
|
58 | } | |
59 |
|
59 | |||
60 | void ChartPresenter::handleGeometryChanged() |
|
60 | void ChartPresenter::handleGeometryChanged() | |
61 | { |
|
61 | { | |
62 | m_rect = QRectF(QPoint(0,0),m_chart->size()); |
|
62 | m_rect = QRectF(QPoint(0,0),m_chart->size()); | |
63 | m_rect.adjust(m_marginSize,m_marginSize, -m_marginSize, -m_marginSize); |
|
63 | m_rect.adjust(m_marginSize,m_marginSize, -m_marginSize, -m_marginSize); | |
64 | Q_ASSERT(m_rect.isValid()); |
|
64 | Q_ASSERT(m_rect.isValid()); | |
65 | emit geometryChanged(m_rect); |
|
65 | emit geometryChanged(m_rect); | |
66 | } |
|
66 | } | |
67 |
|
67 | |||
68 | int ChartPresenter::margin() const |
|
68 | int ChartPresenter::margin() const | |
69 | { |
|
69 | { | |
70 | return m_marginSize; |
|
70 | return m_marginSize; | |
71 | } |
|
71 | } | |
72 |
|
72 | |||
73 | void ChartPresenter::setMargin(int margin) |
|
73 | void ChartPresenter::setMargin(int margin) | |
74 | { |
|
74 | { | |
75 | m_marginSize = margin; |
|
75 | m_marginSize = margin; | |
76 | } |
|
76 | } | |
77 |
|
77 | |||
78 | void ChartPresenter::handleAxisAdded(QChartAxis* axis) |
|
78 | void ChartPresenter::handleAxisAdded(QChartAxis* axis) | |
79 | { |
|
79 | { | |
80 |
|
80 | |||
81 | AxisItem* item ; |
|
81 | AxisItem* item ; | |
82 |
|
82 | |||
83 | if(!m_options.testFlag(QChart::GridAxisAnimations)) |
|
83 | if(!m_options.testFlag(QChart::GridAxisAnimations)) | |
84 | { |
|
84 | { | |
85 | item = new AxisItem(axis==m_dataset->axisX()?AxisItem::X_AXIS : AxisItem::Y_AXIS,m_chart); |
|
85 | item = new AxisItem(axis==m_dataset->axisX()?AxisItem::X_AXIS : AxisItem::Y_AXIS,m_chart); | |
86 | }else{ |
|
86 | }else{ | |
87 | item = new AxisAnimationItem(axis==m_dataset->axisX()?AxisItem::X_AXIS : AxisItem::Y_AXIS,m_chart); |
|
87 | item = new AxisAnimationItem(axis==m_dataset->axisX()?AxisItem::X_AXIS : AxisItem::Y_AXIS,m_chart); | |
88 | } |
|
88 | } | |
89 |
|
89 | |||
90 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); |
|
90 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); | |
91 | QObject::connect(axis,SIGNAL(update(QChartAxis*)),item,SLOT(handleAxisUpdate(QChartAxis*))); |
|
91 | QObject::connect(axis,SIGNAL(update(QChartAxis*)),item,SLOT(handleAxisUpdate(QChartAxis*))); | |
92 |
|
92 | |||
93 | item->handleAxisUpdate(axis); |
|
93 | item->handleAxisUpdate(axis); | |
94 | item->handleGeometryChanged(m_rect); |
|
94 | item->handleGeometryChanged(m_rect); | |
95 | m_chartTheme->decorate(axis,item); |
|
95 | m_chartTheme->decorate(axis,item); | |
96 | m_axisItems.insert(axis,item); |
|
96 | m_axisItems.insert(axis,item); | |
97 | } |
|
97 | } | |
98 |
|
98 | |||
99 | void ChartPresenter::handleAxisRemoved(QChartAxis* axis) |
|
99 | void ChartPresenter::handleAxisRemoved(QChartAxis* axis) | |
100 | { |
|
100 | { | |
101 | AxisItem* item = m_axisItems.take(axis); |
|
101 | AxisItem* item = m_axisItems.take(axis); | |
102 | Q_ASSERT(item); |
|
102 | Q_ASSERT(item); | |
103 | delete item; |
|
103 | delete item; | |
104 | } |
|
104 | } | |
105 |
|
105 | |||
106 |
|
106 | |||
107 |
void ChartPresenter::handleSeriesAdded(Q |
|
107 | void ChartPresenter::handleSeriesAdded(QSeries* series) | |
108 | { |
|
108 | { | |
109 | switch(series->type()) |
|
109 | switch(series->type()) | |
110 | { |
|
110 | { | |
111 |
case Q |
|
111 | case QSeries::SeriesTypeLine: { | |
112 | QLineSeries* lineSeries = static_cast<QLineSeries*>(series); |
|
112 | QLineSeries* lineSeries = static_cast<QLineSeries*>(series); | |
113 | LineChartItem* item; |
|
113 | LineChartItem* item; | |
114 | if(m_options.testFlag(QChart::SeriesAnimations)){ |
|
114 | if(m_options.testFlag(QChart::SeriesAnimations)){ | |
115 | item = new LineChartAnimationItem(this,lineSeries,m_chart); |
|
115 | item = new LineChartAnimationItem(this,lineSeries,m_chart); | |
116 | }else{ |
|
116 | }else{ | |
117 | item = new LineChartItem(this,lineSeries,m_chart); |
|
117 | item = new LineChartItem(this,lineSeries,m_chart); | |
118 | } |
|
118 | } | |
119 | m_chartTheme->decorate(item,lineSeries,m_chartItems.count()); |
|
119 | m_chartTheme->decorate(item,lineSeries,m_chartItems.count()); | |
120 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); |
|
120 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); | |
121 | QObject::connect(lineSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int))); |
|
121 | QObject::connect(lineSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int))); | |
122 | m_chartItems.insert(series,item); |
|
122 | m_chartItems.insert(series,item); | |
123 | break; |
|
123 | break; | |
124 | } |
|
124 | } | |
125 |
|
125 | |||
126 |
case Q |
|
126 | case QSeries::SeriesTypeBar: { | |
127 | QBarSeries* barSeries = static_cast<QBarSeries*>(series); |
|
127 | QBarSeries* barSeries = static_cast<QBarSeries*>(series); | |
128 | BarPresenter* item = new BarPresenter(barSeries,m_chart); |
|
128 | BarPresenter* item = new BarPresenter(barSeries,m_chart); | |
129 | m_chartTheme->decorate(item,barSeries,m_chartItems.count()); |
|
129 | m_chartTheme->decorate(item,barSeries,m_chartItems.count()); | |
130 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); |
|
130 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); | |
131 | QObject::connect(barSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int))); |
|
131 | QObject::connect(barSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int))); | |
132 | m_chartItems.insert(series,item); |
|
132 | m_chartItems.insert(series,item); | |
133 | // m_axisXItem->setVisible(false); |
|
133 | // m_axisXItem->setVisible(false); | |
134 | break; |
|
134 | break; | |
135 | } |
|
135 | } | |
136 |
|
136 | |||
137 |
case Q |
|
137 | case QSeries::SeriesTypeStackedBar: { | |
138 |
|
138 | |||
139 | QStackedBarSeries* stackedBarSeries = static_cast<QStackedBarSeries*>(series); |
|
139 | QStackedBarSeries* stackedBarSeries = static_cast<QStackedBarSeries*>(series); | |
140 | StackedBarPresenter* item = new StackedBarPresenter(stackedBarSeries,m_chart); |
|
140 | StackedBarPresenter* item = new StackedBarPresenter(stackedBarSeries,m_chart); | |
141 | m_chartTheme->decorate(item,stackedBarSeries,m_chartItems.count()); |
|
141 | m_chartTheme->decorate(item,stackedBarSeries,m_chartItems.count()); | |
142 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); |
|
142 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); | |
143 | QObject::connect(stackedBarSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int))); |
|
143 | QObject::connect(stackedBarSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int))); | |
144 | m_chartItems.insert(series,item); |
|
144 | m_chartItems.insert(series,item); | |
145 | break; |
|
145 | break; | |
146 | } |
|
146 | } | |
147 |
|
147 | |||
148 |
case Q |
|
148 | case QSeries::SeriesTypePercentBar: { | |
149 |
|
149 | |||
150 | QPercentBarSeries* percentBarSeries = static_cast<QPercentBarSeries*>(series); |
|
150 | QPercentBarSeries* percentBarSeries = static_cast<QPercentBarSeries*>(series); | |
151 | PercentBarPresenter* item = new PercentBarPresenter(percentBarSeries,m_chart); |
|
151 | PercentBarPresenter* item = new PercentBarPresenter(percentBarSeries,m_chart); | |
152 | m_chartTheme->decorate(item,percentBarSeries ,m_chartItems.count()); |
|
152 | m_chartTheme->decorate(item,percentBarSeries ,m_chartItems.count()); | |
153 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); |
|
153 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); | |
154 | QObject::connect(percentBarSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int))); |
|
154 | QObject::connect(percentBarSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int))); | |
155 | m_chartItems.insert(series,item); |
|
155 | m_chartItems.insert(series,item); | |
156 | break; |
|
156 | break; | |
157 | } |
|
157 | } | |
158 |
case Q |
|
158 | case QSeries::SeriesTypeScatter: { | |
159 | QScatterSeries *scatterSeries = qobject_cast<QScatterSeries *>(series); |
|
159 | QScatterSeries *scatterSeries = qobject_cast<QScatterSeries *>(series); | |
160 | ScatterPresenter *scatterPresenter = new ScatterPresenter(scatterSeries, m_chart); |
|
160 | ScatterPresenter *scatterPresenter = new ScatterPresenter(scatterSeries, m_chart); | |
161 | QObject::connect(scatterPresenter, SIGNAL(clicked()), scatterSeries, SIGNAL(clicked())); |
|
161 | QObject::connect(scatterPresenter, SIGNAL(clicked()), scatterSeries, SIGNAL(clicked())); | |
162 | QObject::connect(this, SIGNAL(geometryChanged(const QRectF&)), |
|
162 | QObject::connect(this, SIGNAL(geometryChanged(const QRectF&)), | |
163 | scatterPresenter, SLOT(handleGeometryChanged(const QRectF&))); |
|
163 | scatterPresenter, SLOT(handleGeometryChanged(const QRectF&))); | |
164 | m_chartTheme->decorate(scatterPresenter, scatterSeries, m_chartItems.count()); |
|
164 | m_chartTheme->decorate(scatterPresenter, scatterSeries, m_chartItems.count()); | |
165 | m_chartItems.insert(scatterSeries, scatterPresenter); |
|
165 | m_chartItems.insert(scatterSeries, scatterPresenter); | |
166 | break; |
|
166 | break; | |
167 | } |
|
167 | } | |
168 |
case Q |
|
168 | case QSeries::SeriesTypePie: { | |
169 | QPieSeries *s = qobject_cast<QPieSeries *>(series); |
|
169 | QPieSeries *s = qobject_cast<QPieSeries *>(series); | |
170 | PiePresenter* pie = new PiePresenter(m_chart, s); |
|
170 | PiePresenter* pie = new PiePresenter(m_chart, s); | |
171 | m_chartTheme->decorate(pie, s, m_chartItems.count()); |
|
171 | m_chartTheme->decorate(pie, s, m_chartItems.count()); | |
172 | QObject::connect(this, SIGNAL(geometryChanged(const QRectF&)), pie, SLOT(handleGeometryChanged(const QRectF&))); |
|
172 | QObject::connect(this, SIGNAL(geometryChanged(const QRectF&)), pie, SLOT(handleGeometryChanged(const QRectF&))); | |
173 |
|
173 | |||
174 | // Hide all from background when there is only piechart |
|
174 | // Hide all from background when there is only piechart | |
175 | // TODO: refactor this ugly code... should be one setting for this |
|
175 | // TODO: refactor this ugly code... should be one setting for this | |
176 | if (m_chartItems.count() == 0) { |
|
176 | if (m_chartItems.count() == 0) { | |
177 | m_chart->axisX()->setAxisVisible(false); |
|
177 | m_chart->axisX()->setAxisVisible(false); | |
178 | m_chart->axisY()->setAxisVisible(false); |
|
178 | m_chart->axisY()->setAxisVisible(false); | |
179 | m_chart->axisX()->setGridVisible(false); |
|
179 | m_chart->axisX()->setGridVisible(false); | |
180 | m_chart->axisY()->setGridVisible(false); |
|
180 | m_chart->axisY()->setGridVisible(false); | |
181 | m_chart->axisX()->setLabelsVisible(false); |
|
181 | m_chart->axisX()->setLabelsVisible(false); | |
182 | m_chart->axisY()->setLabelsVisible(false); |
|
182 | m_chart->axisY()->setLabelsVisible(false); | |
183 | m_chart->axisX()->setShadesVisible(false); |
|
183 | m_chart->axisX()->setShadesVisible(false); | |
184 | m_chart->axisY()->setShadesVisible(false); |
|
184 | m_chart->axisY()->setShadesVisible(false); | |
185 | m_chart->setChartBackgroundBrush(Qt::transparent); |
|
185 | m_chart->setChartBackgroundBrush(Qt::transparent); | |
186 | } |
|
186 | } | |
187 |
|
187 | |||
188 | m_chartItems.insert(series, pie); |
|
188 | m_chartItems.insert(series, pie); | |
189 | break; |
|
189 | break; | |
190 | } |
|
190 | } | |
191 | default: { |
|
191 | default: { | |
192 | qDebug()<< "Series type" << series->type() << "not implemented."; |
|
192 | qDebug()<< "Series type" << series->type() << "not implemented."; | |
193 | break; |
|
193 | break; | |
194 | } |
|
194 | } | |
195 | } |
|
195 | } | |
196 |
|
196 | |||
197 | if(m_rect.isValid()) emit geometryChanged(m_rect); |
|
197 | if(m_rect.isValid()) emit geometryChanged(m_rect); | |
198 | } |
|
198 | } | |
199 |
|
199 | |||
200 |
void ChartPresenter::handleSeriesRemoved(Q |
|
200 | void ChartPresenter::handleSeriesRemoved(QSeries* series) | |
201 | { |
|
201 | { | |
202 | ChartItem* item = m_chartItems.take(series); |
|
202 | ChartItem* item = m_chartItems.take(series); | |
203 | delete item; |
|
203 | delete item; | |
204 | } |
|
204 | } | |
205 |
|
205 | |||
206 |
void ChartPresenter::handleSeriesChanged(Q |
|
206 | void ChartPresenter::handleSeriesChanged(QSeries* series) | |
207 | { |
|
207 | { | |
208 | //TODO: |
|
208 | //TODO: | |
209 | } |
|
209 | } | |
210 |
|
210 | |||
211 |
void ChartPresenter::handleSeriesDomainChanged(Q |
|
211 | void ChartPresenter::handleSeriesDomainChanged(QSeries* series, const Domain& domain) | |
212 | { |
|
212 | { | |
213 | m_chartItems.value(series)->handleDomainChanged(domain); |
|
213 | m_chartItems.value(series)->handleDomainChanged(domain); | |
214 | } |
|
214 | } | |
215 |
|
215 | |||
216 | void ChartPresenter::handleAxisLabelsChanged(QChartAxis* axis,const QStringList& labels) |
|
216 | void ChartPresenter::handleAxisLabelsChanged(QChartAxis* axis,const QStringList& labels) | |
217 | { |
|
217 | { | |
218 | m_axisItems.value(axis)->handleLabelsChanged(axis,labels); |
|
218 | m_axisItems.value(axis)->handleLabelsChanged(axis,labels); | |
219 | } |
|
219 | } | |
220 |
|
220 | |||
221 | void ChartPresenter::setChartTheme(QChart::ChartTheme theme) |
|
221 | void ChartPresenter::setChartTheme(QChart::ChartTheme theme) | |
222 | { |
|
222 | { | |
223 | delete m_chartTheme; |
|
223 | delete m_chartTheme; | |
224 |
|
224 | |||
225 | m_chartTheme = ChartTheme::createTheme(theme); |
|
225 | m_chartTheme = ChartTheme::createTheme(theme); | |
226 |
|
226 | |||
227 | m_chartTheme->decorate(m_chart); |
|
227 | m_chartTheme->decorate(m_chart); | |
228 |
QMapIterator<Q |
|
228 | QMapIterator<QSeries*,ChartItem*> i(m_chartItems); | |
229 |
|
229 | |||
230 | int index=0; |
|
230 | int index=0; | |
231 | while (i.hasNext()) { |
|
231 | while (i.hasNext()) { | |
232 | i.next(); |
|
232 | i.next(); | |
233 | m_chartTheme->decorate(i.value(),i.key(),index); |
|
233 | m_chartTheme->decorate(i.value(),i.key(),index); | |
234 | index++; |
|
234 | index++; | |
235 | } |
|
235 | } | |
236 |
|
236 | |||
237 | QMapIterator<QChartAxis*,AxisItem*> j(m_axisItems); |
|
237 | QMapIterator<QChartAxis*,AxisItem*> j(m_axisItems); | |
238 | while (j.hasNext()) { |
|
238 | while (j.hasNext()) { | |
239 | j.next(); |
|
239 | j.next(); | |
240 | m_chartTheme->decorate(j.key(),j.value()); |
|
240 | m_chartTheme->decorate(j.key(),j.value()); | |
241 | } |
|
241 | } | |
242 | } |
|
242 | } | |
243 |
|
243 | |||
244 | QChart::ChartTheme ChartPresenter::chartTheme() |
|
244 | QChart::ChartTheme ChartPresenter::chartTheme() | |
245 | { |
|
245 | { | |
246 | return m_chartTheme->id(); |
|
246 | return m_chartTheme->id(); | |
247 | } |
|
247 | } | |
248 |
|
248 | |||
249 | void ChartPresenter::setAnimationOptions(QChart::AnimationOptions options) |
|
249 | void ChartPresenter::setAnimationOptions(QChart::AnimationOptions options) | |
250 | { |
|
250 | { | |
251 | if(m_options!=options) { |
|
251 | if(m_options!=options) { | |
252 |
|
252 | |||
253 | m_options=options; |
|
253 | m_options=options; | |
254 |
|
254 | |||
255 | //recreate elements |
|
255 | //recreate elements | |
256 |
|
256 | |||
257 | QList<QChartAxis*> axisList = m_axisItems.uniqueKeys(); |
|
257 | QList<QChartAxis*> axisList = m_axisItems.uniqueKeys(); | |
258 |
QList<Q |
|
258 | QList<QSeries*> seriesList = m_chartItems.uniqueKeys(); | |
259 |
|
259 | |||
260 | foreach(QChartAxis* axis, axisList) { |
|
260 | foreach(QChartAxis* axis, axisList) { | |
261 | handleAxisRemoved(axis); |
|
261 | handleAxisRemoved(axis); | |
262 | handleAxisAdded(axis); |
|
262 | handleAxisAdded(axis); | |
263 | } |
|
263 | } | |
264 |
foreach(Q |
|
264 | foreach(QSeries* series, seriesList) { | |
265 | handleSeriesRemoved(series); |
|
265 | handleSeriesRemoved(series); | |
266 | handleSeriesAdded(series); |
|
266 | handleSeriesAdded(series); | |
267 | } |
|
267 | } | |
268 |
|
268 | |||
269 | //now reintialize view data |
|
269 | //now reintialize view data | |
270 | //TODO: make it more nice |
|
270 | //TODO: make it more nice | |
271 | m_dataset->setDomain(m_dataset->domainIndex()); |
|
271 | m_dataset->setDomain(m_dataset->domainIndex()); | |
272 | } |
|
272 | } | |
273 | } |
|
273 | } | |
274 |
|
274 | |||
275 | QChart::AnimationOptions ChartPresenter::animationOptions() const |
|
275 | QChart::AnimationOptions ChartPresenter::animationOptions() const | |
276 | { |
|
276 | { | |
277 | return m_options; |
|
277 | return m_options; | |
278 | } |
|
278 | } | |
279 |
|
279 | |||
280 |
|
280 | |||
281 | #include "moc_chartpresenter_p.cpp" |
|
281 | #include "moc_chartpresenter_p.cpp" | |
282 |
|
282 | |||
283 | QTCOMMERCIALCHART_END_NAMESPACE |
|
283 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,67 +1,67 | |||||
1 | #ifndef CHARTPRESENTER_H_ |
|
1 | #ifndef CHARTPRESENTER_H_ | |
2 | #define CHARTPRESENTER_H_ |
|
2 | #define CHARTPRESENTER_H_ | |
3 |
|
3 | |||
4 | #include "qchartglobal.h" |
|
4 | #include "qchartglobal.h" | |
5 | #include "qchart.h" //becouse of QChart::ChartThemeId //TODO |
|
5 | #include "qchart.h" //becouse of QChart::ChartThemeId //TODO | |
6 | #include "qchartaxis.h" |
|
6 | #include "qchartaxis.h" | |
7 | #include <QRectF> |
|
7 | #include <QRectF> | |
8 |
|
8 | |||
9 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
9 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
10 |
|
10 | |||
11 | class ChartItem; |
|
11 | class ChartItem; | |
12 |
class Q |
|
12 | class QSeries; | |
13 | class ChartDataSet; |
|
13 | class ChartDataSet; | |
14 | //class QChart; |
|
14 | //class QChart; | |
15 | class Domain; |
|
15 | class Domain; | |
16 | class AxisItem; |
|
16 | class AxisItem; | |
17 | class ChartTheme; |
|
17 | class ChartTheme; | |
18 |
|
18 | |||
19 | class ChartPresenter: public QObject |
|
19 | class ChartPresenter: public QObject | |
20 | { |
|
20 | { | |
21 | Q_OBJECT |
|
21 | Q_OBJECT | |
22 | public: |
|
22 | public: | |
23 | enum ZValues { BackgroundZValue = -1 , ShadesZValue, GridZValue, AxisZValue , LineChartZValue }; |
|
23 | enum ZValues { BackgroundZValue = -1 , ShadesZValue, GridZValue, AxisZValue , LineChartZValue }; | |
24 |
|
24 | |||
25 | ChartPresenter(QChart* chart,ChartDataSet *dataset); |
|
25 | ChartPresenter(QChart* chart,ChartDataSet *dataset); | |
26 | virtual ~ChartPresenter(); |
|
26 | virtual ~ChartPresenter(); | |
27 |
|
27 | |||
28 | void setMargin(int margin); |
|
28 | void setMargin(int margin); | |
29 | int margin() const; |
|
29 | int margin() const; | |
30 |
|
30 | |||
31 | QRectF geometry() const; |
|
31 | QRectF geometry() const; | |
32 |
|
32 | |||
33 | void setChartTheme(QChart::ChartTheme theme); |
|
33 | void setChartTheme(QChart::ChartTheme theme); | |
34 | QChart::ChartTheme chartTheme(); |
|
34 | QChart::ChartTheme chartTheme(); | |
35 |
|
35 | |||
36 | void setAnimationOptions(QChart::AnimationOptions options); |
|
36 | void setAnimationOptions(QChart::AnimationOptions options); | |
37 | QChart::AnimationOptions animationOptions() const; |
|
37 | QChart::AnimationOptions animationOptions() const; | |
38 |
|
38 | |||
39 | private: |
|
39 | private: | |
40 | void createConnections(); |
|
40 | void createConnections(); | |
41 |
|
41 | |||
42 | public slots: |
|
42 | public slots: | |
43 |
void handleSeriesAdded(Q |
|
43 | void handleSeriesAdded(QSeries* series); | |
44 |
void handleSeriesRemoved(Q |
|
44 | void handleSeriesRemoved(QSeries* series); | |
45 | void handleAxisAdded(QChartAxis* axis); |
|
45 | void handleAxisAdded(QChartAxis* axis); | |
46 | void handleAxisRemoved(QChartAxis* axis); |
|
46 | void handleAxisRemoved(QChartAxis* axis); | |
47 |
void handleSeriesDomainChanged(Q |
|
47 | void handleSeriesDomainChanged(QSeries* series, const Domain& domain); | |
48 | void handleAxisLabelsChanged(QChartAxis* axis, const QStringList& labels); |
|
48 | void handleAxisLabelsChanged(QChartAxis* axis, const QStringList& labels); | |
49 |
void handleSeriesChanged(Q |
|
49 | void handleSeriesChanged(QSeries* series); | |
50 | void handleGeometryChanged(); |
|
50 | void handleGeometryChanged(); | |
51 | signals: |
|
51 | signals: | |
52 | void geometryChanged(const QRectF& rect); |
|
52 | void geometryChanged(const QRectF& rect); | |
53 | private: |
|
53 | private: | |
54 |
QMap<Q |
|
54 | QMap<QSeries*,ChartItem*> m_chartItems; | |
55 | QMap<QChartAxis*,AxisItem*> m_axisItems; |
|
55 | QMap<QChartAxis*,AxisItem*> m_axisItems; | |
56 | QChart* m_chart; |
|
56 | QChart* m_chart; | |
57 | ChartDataSet* m_dataset; |
|
57 | ChartDataSet* m_dataset; | |
58 | ChartTheme *m_chartTheme; |
|
58 | ChartTheme *m_chartTheme; | |
59 | int m_marginSize; |
|
59 | int m_marginSize; | |
60 | QRectF m_rect; |
|
60 | QRectF m_rect; | |
61 | QChart::AnimationOptions m_options; |
|
61 | QChart::AnimationOptions m_options; | |
62 |
|
62 | |||
63 | }; |
|
63 | }; | |
64 |
|
64 | |||
65 | QTCOMMERCIALCHART_END_NAMESPACE |
|
65 | QTCOMMERCIALCHART_END_NAMESPACE | |
66 |
|
66 | |||
67 | #endif /* CHARTPRESENTER_H_ */ |
|
67 | #endif /* CHARTPRESENTER_H_ */ |
@@ -1,270 +1,270 | |||||
1 | #include "charttheme_p.h" |
|
1 | #include "charttheme_p.h" | |
2 | #include "qchart.h" |
|
2 | #include "qchart.h" | |
3 | #include "qchartaxis.h" |
|
3 | #include "qchartaxis.h" | |
4 | #include <QTime> |
|
4 | #include <QTime> | |
5 |
|
5 | |||
6 | //series |
|
6 | //series | |
7 | #include "qbarset.h" |
|
7 | #include "qbarset.h" | |
8 | #include "qbarseries.h" |
|
8 | #include "qbarseries.h" | |
9 | #include "qstackedbarseries.h" |
|
9 | #include "qstackedbarseries.h" | |
10 | #include "qpercentbarseries.h" |
|
10 | #include "qpercentbarseries.h" | |
11 | #include "qlineseries.h" |
|
11 | #include "qlineseries.h" | |
12 | #include "qscatterseries.h" |
|
12 | #include "qscatterseries.h" | |
13 | #include "qpieseries.h" |
|
13 | #include "qpieseries.h" | |
14 | #include "qpieslice.h" |
|
14 | #include "qpieslice.h" | |
15 |
|
15 | |||
16 | //items |
|
16 | //items | |
17 | #include "axisitem_p.h" |
|
17 | #include "axisitem_p.h" | |
18 | #include "barpresenter.h" |
|
18 | #include "barpresenter.h" | |
19 | #include "stackedbarpresenter.h" |
|
19 | #include "stackedbarpresenter.h" | |
20 | #include "linechartitem_p.h" |
|
20 | #include "linechartitem_p.h" | |
21 | #include "percentbarpresenter.h" |
|
21 | #include "percentbarpresenter.h" | |
22 | #include "scatterpresenter_p.h" |
|
22 | #include "scatterpresenter_p.h" | |
23 | #include "piepresenter_p.h" |
|
23 | #include "piepresenter_p.h" | |
24 |
|
24 | |||
25 | //themes |
|
25 | //themes | |
26 | #include "chartthemevanilla_p.h" |
|
26 | #include "chartthemevanilla_p.h" | |
27 | #include "chartthemeicy_p.h" |
|
27 | #include "chartthemeicy_p.h" | |
28 | #include "chartthemegrayscale_p.h" |
|
28 | #include "chartthemegrayscale_p.h" | |
29 | #include "chartthemescientific_p.h" |
|
29 | #include "chartthemescientific_p.h" | |
30 |
|
30 | |||
31 |
|
31 | |||
32 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
32 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
33 |
|
33 | |||
34 | /* TODO |
|
34 | /* TODO | |
35 | case QChart::ChartThemeUnnamed1: |
|
35 | case QChart::ChartThemeUnnamed1: | |
36 | m_seriesThemes.append(SeriesTheme(QColor(QRgb(0xff3fa9f5)), 2)); |
|
36 | m_seriesThemes.append(SeriesTheme(QColor(QRgb(0xff3fa9f5)), 2)); | |
37 | m_seriesThemes.append(SeriesTheme(QColor(QRgb(0xff7AC943)), 2)); |
|
37 | m_seriesThemes.append(SeriesTheme(QColor(QRgb(0xff7AC943)), 2)); | |
38 | m_seriesThemes.append(SeriesTheme(QColor(QRgb(0xffFF931E)), 2)); |
|
38 | m_seriesThemes.append(SeriesTheme(QColor(QRgb(0xffFF931E)), 2)); | |
39 | m_seriesThemes.append(SeriesTheme(QColor(QRgb(0xffFF1D25)), 2)); |
|
39 | m_seriesThemes.append(SeriesTheme(QColor(QRgb(0xffFF1D25)), 2)); | |
40 | m_seriesThemes.append(SeriesTheme(QColor(QRgb(0xffFF7BAC)), 2)); |
|
40 | m_seriesThemes.append(SeriesTheme(QColor(QRgb(0xffFF7BAC)), 2)); | |
41 |
|
41 | |||
42 | m_gradientStartColor = QColor(QRgb(0xfff3dc9e)); |
|
42 | m_gradientStartColor = QColor(QRgb(0xfff3dc9e)); | |
43 | m_gradientEndColor = QColor(QRgb(0xffafafaf)); |
|
43 | m_gradientEndColor = QColor(QRgb(0xffafafaf)); | |
44 | */ |
|
44 | */ | |
45 |
|
45 | |||
46 | ChartTheme::ChartTheme(QChart::ChartTheme id) |
|
46 | ChartTheme::ChartTheme(QChart::ChartTheme id) | |
47 | { |
|
47 | { | |
48 | m_id = id; |
|
48 | m_id = id; | |
49 | m_seriesColor.append(QRgb(0xff000000)); |
|
49 | m_seriesColor.append(QRgb(0xff000000)); | |
50 | m_seriesColor.append(QRgb(0xff707070)); |
|
50 | m_seriesColor.append(QRgb(0xff707070)); | |
51 | m_gradientStartColor = QColor(QRgb(0xffffffff)); |
|
51 | m_gradientStartColor = QColor(QRgb(0xffffffff)); | |
52 | m_gradientEndColor = QColor(QRgb(0xffafafaf)); |
|
52 | m_gradientEndColor = QColor(QRgb(0xffafafaf)); | |
53 |
|
53 | |||
54 | qsrand(QTime(0,0,0).secsTo(QTime::currentTime())); |
|
54 | qsrand(QTime(0,0,0).secsTo(QTime::currentTime())); | |
55 | } |
|
55 | } | |
56 |
|
56 | |||
57 |
|
57 | |||
58 | ChartTheme* ChartTheme::createTheme(QChart::ChartTheme theme) |
|
58 | ChartTheme* ChartTheme::createTheme(QChart::ChartTheme theme) | |
59 | { |
|
59 | { | |
60 | switch(theme) { |
|
60 | switch(theme) { | |
61 | case QChart::ChartThemeDefault: |
|
61 | case QChart::ChartThemeDefault: | |
62 | return new ChartThemeIcy(); |
|
62 | return new ChartThemeIcy(); | |
63 | case QChart::ChartThemeVanilla: |
|
63 | case QChart::ChartThemeVanilla: | |
64 | return new ChartThemeVanilla(); |
|
64 | return new ChartThemeVanilla(); | |
65 | case QChart::ChartThemeIcy: |
|
65 | case QChart::ChartThemeIcy: | |
66 | return new ChartThemeIcy(); |
|
66 | return new ChartThemeIcy(); | |
67 | case QChart::ChartThemeGrayscale: |
|
67 | case QChart::ChartThemeGrayscale: | |
68 | return new ChartThemeGrayscale(); |
|
68 | return new ChartThemeGrayscale(); | |
69 | case QChart::ChartThemeScientific: |
|
69 | case QChart::ChartThemeScientific: | |
70 | return new ChartThemeScientific(); |
|
70 | return new ChartThemeScientific(); | |
71 | } |
|
71 | } | |
72 | } |
|
72 | } | |
73 |
|
73 | |||
74 | void ChartTheme::decorate(QChart* chart) |
|
74 | void ChartTheme::decorate(QChart* chart) | |
75 | { |
|
75 | { | |
76 | QLinearGradient backgroundGradient; |
|
76 | QLinearGradient backgroundGradient; | |
77 | backgroundGradient.setColorAt(0.0, m_gradientStartColor); |
|
77 | backgroundGradient.setColorAt(0.0, m_gradientStartColor); | |
78 | backgroundGradient.setColorAt(1.0, m_gradientEndColor); |
|
78 | backgroundGradient.setColorAt(1.0, m_gradientEndColor); | |
79 | backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode); |
|
79 | backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode); | |
80 | chart->setChartBackgroundBrush(backgroundGradient); |
|
80 | chart->setChartBackgroundBrush(backgroundGradient); | |
81 | } |
|
81 | } | |
82 | //TODO helper to by removed later |
|
82 | //TODO helper to by removed later | |
83 |
void ChartTheme::decorate(ChartItem* item, Q |
|
83 | void ChartTheme::decorate(ChartItem* item, QSeries* series,int count) | |
84 | { |
|
84 | { | |
85 | switch(series->type()) |
|
85 | switch(series->type()) | |
86 | { |
|
86 | { | |
87 |
case Q |
|
87 | case QSeries::SeriesTypeLine: { | |
88 | QLineSeries* s = static_cast<QLineSeries*>(series); |
|
88 | QLineSeries* s = static_cast<QLineSeries*>(series); | |
89 | LineChartItem* i = static_cast<LineChartItem*>(item); |
|
89 | LineChartItem* i = static_cast<LineChartItem*>(item); | |
90 | decorate(i,s,count); |
|
90 | decorate(i,s,count); | |
91 | break; |
|
91 | break; | |
92 | } |
|
92 | } | |
93 |
case Q |
|
93 | case QSeries::SeriesTypeBar: { | |
94 | QBarSeries* b = static_cast<QBarSeries*>(series); |
|
94 | QBarSeries* b = static_cast<QBarSeries*>(series); | |
95 | BarPresenter* i = static_cast<BarPresenter*>(item); |
|
95 | BarPresenter* i = static_cast<BarPresenter*>(item); | |
96 | decorate(i,b,count); |
|
96 | decorate(i,b,count); | |
97 | break; |
|
97 | break; | |
98 | } |
|
98 | } | |
99 |
case Q |
|
99 | case QSeries::SeriesTypeStackedBar: { | |
100 | QStackedBarSeries* s = static_cast<QStackedBarSeries*>(series); |
|
100 | QStackedBarSeries* s = static_cast<QStackedBarSeries*>(series); | |
101 | StackedBarPresenter* i = static_cast<StackedBarPresenter*>(item); |
|
101 | StackedBarPresenter* i = static_cast<StackedBarPresenter*>(item); | |
102 | decorate(i,s,count); |
|
102 | decorate(i,s,count); | |
103 | break; |
|
103 | break; | |
104 | } |
|
104 | } | |
105 |
case Q |
|
105 | case QSeries::SeriesTypePercentBar: { | |
106 | QPercentBarSeries* s = static_cast<QPercentBarSeries*>(series); |
|
106 | QPercentBarSeries* s = static_cast<QPercentBarSeries*>(series); | |
107 | PercentBarPresenter* i = static_cast<PercentBarPresenter*>(item); |
|
107 | PercentBarPresenter* i = static_cast<PercentBarPresenter*>(item); | |
108 | decorate(i,s,count); |
|
108 | decorate(i,s,count); | |
109 | break; |
|
109 | break; | |
110 | } |
|
110 | } | |
111 |
case Q |
|
111 | case QSeries::SeriesTypeScatter: { | |
112 | QScatterSeries* s = qobject_cast<QScatterSeries*>(series); |
|
112 | QScatterSeries* s = qobject_cast<QScatterSeries*>(series); | |
113 | Q_ASSERT(s); |
|
113 | Q_ASSERT(s); | |
114 | ScatterPresenter* i = static_cast<ScatterPresenter*>(item); |
|
114 | ScatterPresenter* i = static_cast<ScatterPresenter*>(item); | |
115 | Q_ASSERT(i); |
|
115 | Q_ASSERT(i); | |
116 | decorate(i, s, count); |
|
116 | decorate(i, s, count); | |
117 | break; |
|
117 | break; | |
118 | } |
|
118 | } | |
119 |
case Q |
|
119 | case QSeries::SeriesTypePie: { | |
120 | QPieSeries* s = static_cast<QPieSeries*>(series); |
|
120 | QPieSeries* s = static_cast<QPieSeries*>(series); | |
121 | PiePresenter* i = static_cast<PiePresenter*>(item); |
|
121 | PiePresenter* i = static_cast<PiePresenter*>(item); | |
122 | decorate(i,s,count); |
|
122 | decorate(i,s,count); | |
123 | break; |
|
123 | break; | |
124 | } |
|
124 | } | |
125 | default: |
|
125 | default: | |
126 | qDebug()<<"Wrong item to be decorated by theme"; |
|
126 | qDebug()<<"Wrong item to be decorated by theme"; | |
127 | break; |
|
127 | break; | |
128 | } |
|
128 | } | |
129 |
|
129 | |||
130 | } |
|
130 | } | |
131 |
|
131 | |||
132 | void ChartTheme::decorate(LineChartItem* item, QLineSeries* series,int count) |
|
132 | void ChartTheme::decorate(LineChartItem* item, QLineSeries* series,int count) | |
133 | { |
|
133 | { | |
134 | QPen pen; |
|
134 | QPen pen; | |
135 | if(pen != series->pen()){ |
|
135 | if(pen != series->pen()){ | |
136 | item->setPen(series->pen()); |
|
136 | item->setPen(series->pen()); | |
137 | return; |
|
137 | return; | |
138 | } |
|
138 | } | |
139 | pen.setColor(m_seriesColor.at(count%m_seriesColor.size())); |
|
139 | pen.setColor(m_seriesColor.at(count%m_seriesColor.size())); | |
140 | pen.setWidthF(2); |
|
140 | pen.setWidthF(2); | |
141 | item->setPen(pen); |
|
141 | item->setPen(pen); | |
142 | } |
|
142 | } | |
143 |
|
143 | |||
144 | void ChartTheme::decorate(BarPresenter* item, QBarSeries* series,int count) |
|
144 | void ChartTheme::decorate(BarPresenter* item, QBarSeries* series,int count) | |
145 | { |
|
145 | { | |
146 | QList<QBarSet*> sets = series->barSets(); |
|
146 | QList<QBarSet*> sets = series->barSets(); | |
147 | for (int i=0; i<series->countSets(); i++) { |
|
147 | for (int i=0; i<series->countSets(); i++) { | |
148 | sets.at(i)->setBrush(QBrush(m_seriesColor.at(i%m_seriesColor.count()))); |
|
148 | sets.at(i)->setBrush(QBrush(m_seriesColor.at(i%m_seriesColor.count()))); | |
149 | } |
|
149 | } | |
150 | } |
|
150 | } | |
151 |
|
151 | |||
152 | void ChartTheme::decorate(StackedBarPresenter* item, QStackedBarSeries* series,int count) |
|
152 | void ChartTheme::decorate(StackedBarPresenter* item, QStackedBarSeries* series,int count) | |
153 | { |
|
153 | { | |
154 | QList<QBarSet*> sets = series->barSets(); |
|
154 | QList<QBarSet*> sets = series->barSets(); | |
155 | for (int i=0; i<series->countSets(); i++) { |
|
155 | for (int i=0; i<series->countSets(); i++) { | |
156 | sets.at(i)->setBrush(QBrush(m_seriesColor.at(i%m_seriesColor.count()))); |
|
156 | sets.at(i)->setBrush(QBrush(m_seriesColor.at(i%m_seriesColor.count()))); | |
157 | } |
|
157 | } | |
158 | } |
|
158 | } | |
159 |
|
159 | |||
160 | void ChartTheme::decorate(PercentBarPresenter* item, QPercentBarSeries* series,int count) |
|
160 | void ChartTheme::decorate(PercentBarPresenter* item, QPercentBarSeries* series,int count) | |
161 | { |
|
161 | { | |
162 | QList<QBarSet*> sets = series->barSets(); |
|
162 | QList<QBarSet*> sets = series->barSets(); | |
163 | for (int i=0; i<series->countSets(); i++) { |
|
163 | for (int i=0; i<series->countSets(); i++) { | |
164 | sets.at(i)->setBrush(QBrush(m_seriesColor.at(i%m_seriesColor.count()))); |
|
164 | sets.at(i)->setBrush(QBrush(m_seriesColor.at(i%m_seriesColor.count()))); | |
165 | } |
|
165 | } | |
166 | } |
|
166 | } | |
167 |
|
167 | |||
168 | void ChartTheme::decorate(ScatterPresenter* presenter, QScatterSeries* series, int count) |
|
168 | void ChartTheme::decorate(ScatterPresenter* presenter, QScatterSeries* series, int count) | |
169 | { |
|
169 | { | |
170 | Q_ASSERT(presenter); |
|
170 | Q_ASSERT(presenter); | |
171 | Q_ASSERT(series); |
|
171 | Q_ASSERT(series); | |
172 |
|
172 | |||
173 | QColor color = m_seriesColor.at(count % m_seriesColor.size()); |
|
173 | QColor color = m_seriesColor.at(count % m_seriesColor.size()); | |
174 | // TODO: define alpha in the theme? or in the series? |
|
174 | // TODO: define alpha in the theme? or in the series? | |
175 | //color.setAlpha(120); |
|
175 | //color.setAlpha(120); | |
176 |
|
176 | |||
177 | QBrush brush(color, Qt::SolidPattern); |
|
177 | QBrush brush(color, Qt::SolidPattern); | |
178 | presenter->m_markerBrush = brush; |
|
178 | presenter->m_markerBrush = brush; | |
179 |
|
179 | |||
180 | QPen pen(brush, 3); |
|
180 | QPen pen(brush, 3); | |
181 | pen.setColor(color); |
|
181 | pen.setColor(color); | |
182 | presenter->m_markerPen = pen; |
|
182 | presenter->m_markerPen = pen; | |
183 | } |
|
183 | } | |
184 |
|
184 | |||
185 | void ChartTheme::decorate(PiePresenter* item, QPieSeries* series, int /*count*/) |
|
185 | void ChartTheme::decorate(PiePresenter* item, QPieSeries* series, int /*count*/) | |
186 | { |
|
186 | { | |
187 | // create a list of slice colors based on current theme |
|
187 | // create a list of slice colors based on current theme | |
188 | int i = 0; |
|
188 | int i = 0; | |
189 | QList<QColor> colors; |
|
189 | QList<QColor> colors; | |
190 | while (colors.count() < series->count()) { |
|
190 | while (colors.count() < series->count()) { | |
191 |
|
191 | |||
192 | // get base color |
|
192 | // get base color | |
193 | QColor c = m_seriesColor[i++]; |
|
193 | QColor c = m_seriesColor[i++]; | |
194 | i = i % m_seriesColor.count(); |
|
194 | i = i % m_seriesColor.count(); | |
195 |
|
195 | |||
196 | // dont use black colors... looks bad |
|
196 | // dont use black colors... looks bad | |
197 | if (c == Qt::black) |
|
197 | if (c == Qt::black) | |
198 | continue; |
|
198 | continue; | |
199 |
|
199 | |||
200 | // by default use the "raw" theme color |
|
200 | // by default use the "raw" theme color | |
201 | if (!colors.contains(c)) { |
|
201 | if (!colors.contains(c)) { | |
202 | colors << c; |
|
202 | colors << c; | |
203 | continue; |
|
203 | continue; | |
204 | } |
|
204 | } | |
205 | // ...ok we need to generate something that looks like the same color |
|
205 | // ...ok we need to generate something that looks like the same color | |
206 | // but different lightness |
|
206 | // but different lightness | |
207 |
|
207 | |||
208 | int tryCount = 0; |
|
208 | int tryCount = 0; | |
209 | while (tryCount++ < 100) { |
|
209 | while (tryCount++ < 100) { | |
210 |
|
210 | |||
211 | // find maximum value we can raise the lightness |
|
211 | // find maximum value we can raise the lightness | |
212 | int lMax = 255; |
|
212 | int lMax = 255; | |
213 | if (lMax > 255 - c.red()) |
|
213 | if (lMax > 255 - c.red()) | |
214 | lMax = 255 - c.red(); |
|
214 | lMax = 255 - c.red(); | |
215 | if (lMax > 255 - c.green()) |
|
215 | if (lMax > 255 - c.green()) | |
216 | lMax = 255 - c.green(); |
|
216 | lMax = 255 - c.green(); | |
217 | if (lMax > 255 - c.blue()) |
|
217 | if (lMax > 255 - c.blue()) | |
218 | lMax = 255 - c.blue(); |
|
218 | lMax = 255 - c.blue(); | |
219 |
|
219 | |||
220 | // find maximum value we can make it darker |
|
220 | // find maximum value we can make it darker | |
221 | int dMax = 255; |
|
221 | int dMax = 255; | |
222 | if (dMax > c.red()) |
|
222 | if (dMax > c.red()) | |
223 | dMax = c.red(); |
|
223 | dMax = c.red(); | |
224 | if (dMax > c.green()) |
|
224 | if (dMax > c.green()) | |
225 | dMax = c.green(); |
|
225 | dMax = c.green(); | |
226 | if (dMax > c.blue()) |
|
226 | if (dMax > c.blue()) | |
227 | dMax = c.blue(); |
|
227 | dMax = c.blue(); | |
228 |
|
228 | |||
229 | int max = dMax + lMax; |
|
229 | int max = dMax + lMax; | |
230 | if (max == 0) { |
|
230 | if (max == 0) { | |
231 | // no room to make color lighter or darker... |
|
231 | // no room to make color lighter or darker... | |
232 | qDebug() << "cannot generate a color for pie!"; |
|
232 | qDebug() << "cannot generate a color for pie!"; | |
233 | break; |
|
233 | break; | |
234 | } |
|
234 | } | |
235 |
|
235 | |||
236 | // generate random color |
|
236 | // generate random color | |
237 | int r = c.red() - dMax; |
|
237 | int r = c.red() - dMax; | |
238 | int g = c.green() - dMax; |
|
238 | int g = c.green() - dMax; | |
239 | int b = c.blue() - dMax; |
|
239 | int b = c.blue() - dMax; | |
240 | int d = qrand() % max; |
|
240 | int d = qrand() % max; | |
241 | c.setRgb(r+d, g+d, b+d); |
|
241 | c.setRgb(r+d, g+d, b+d); | |
242 |
|
242 | |||
243 | // found a unique color? |
|
243 | // found a unique color? | |
244 | if (!colors.contains(c)) |
|
244 | if (!colors.contains(c)) | |
245 | break; |
|
245 | break; | |
246 | } |
|
246 | } | |
247 |
|
247 | |||
248 | qDebug() << "generated a color for pie" << c; |
|
248 | qDebug() << "generated a color for pie" << c; | |
249 | colors << c; |
|
249 | colors << c; | |
250 | } |
|
250 | } | |
251 |
|
251 | |||
252 | // finally update colors |
|
252 | // finally update colors | |
253 | foreach (QPieSlice* s, series->slices()) { |
|
253 | foreach (QPieSlice* s, series->slices()) { | |
254 | QColor c = colors.takeFirst(); |
|
254 | QColor c = colors.takeFirst(); | |
255 | s->setPen(c); |
|
255 | s->setPen(c); | |
256 | s->setBrush(c); |
|
256 | s->setBrush(c); | |
257 | } |
|
257 | } | |
258 | } |
|
258 | } | |
259 |
|
259 | |||
260 |
|
260 | |||
261 | void ChartTheme::decorate(QChartAxis* axis,AxisItem* item) |
|
261 | void ChartTheme::decorate(QChartAxis* axis,AxisItem* item) | |
262 | { |
|
262 | { | |
263 | //TODO: dummy defults for now |
|
263 | //TODO: dummy defults for now | |
264 | axis->setLabelsBrush(Qt::black); |
|
264 | axis->setLabelsBrush(Qt::black); | |
265 | axis->setLabelsPen(Qt::NoPen); |
|
265 | axis->setLabelsPen(Qt::NoPen); | |
266 | axis->setShadesPen(Qt::NoPen); |
|
266 | axis->setShadesPen(Qt::NoPen); | |
267 | axis->setShadesOpacity(0.5); |
|
267 | axis->setShadesOpacity(0.5); | |
268 | } |
|
268 | } | |
269 |
|
269 | |||
270 | QTCOMMERCIALCHART_END_NAMESPACE |
|
270 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,52 +1,52 | |||||
1 | #ifndef CHARTTHEME_H |
|
1 | #ifndef CHARTTHEME_H | |
2 | #define CHARTTHEME_H |
|
2 | #define CHARTTHEME_H | |
3 |
|
3 | |||
4 | #include "qchartglobal.h" |
|
4 | #include "qchartglobal.h" | |
5 | #include "qchart.h" |
|
5 | #include "qchart.h" | |
6 | #include <QColor> |
|
6 | #include <QColor> | |
7 |
|
7 | |||
8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
9 |
|
9 | |||
10 | class ChartItem; |
|
10 | class ChartItem; | |
11 |
class Q |
|
11 | class QSeries; | |
12 | class LineChartItem; |
|
12 | class LineChartItem; | |
13 | class QLineSeries; |
|
13 | class QLineSeries; | |
14 | class BarPresenter; |
|
14 | class BarPresenter; | |
15 | class QBarSeries; |
|
15 | class QBarSeries; | |
16 | class StackedBarPresenter; |
|
16 | class StackedBarPresenter; | |
17 | class QStackedBarSeries; |
|
17 | class QStackedBarSeries; | |
18 | class QPercentBarSeries; |
|
18 | class QPercentBarSeries; | |
19 | class PercentBarPresenter; |
|
19 | class PercentBarPresenter; | |
20 | class QScatterSeries; |
|
20 | class QScatterSeries; | |
21 | class ScatterPresenter; |
|
21 | class ScatterPresenter; | |
22 | class PiePresenter; |
|
22 | class PiePresenter; | |
23 | class QPieSeries; |
|
23 | class QPieSeries; | |
24 |
|
24 | |||
25 | class ChartTheme |
|
25 | class ChartTheme | |
26 | { |
|
26 | { | |
27 | protected: |
|
27 | protected: | |
28 | explicit ChartTheme(QChart::ChartTheme id = QChart::ChartThemeDefault); |
|
28 | explicit ChartTheme(QChart::ChartTheme id = QChart::ChartThemeDefault); | |
29 | public: |
|
29 | public: | |
30 | static ChartTheme* createTheme(QChart::ChartTheme theme); |
|
30 | static ChartTheme* createTheme(QChart::ChartTheme theme); | |
31 | QChart::ChartTheme id() const {return m_id;} |
|
31 | QChart::ChartTheme id() const {return m_id;} | |
32 | void decorate(QChart* chart); |
|
32 | void decorate(QChart* chart); | |
33 |
void decorate(ChartItem* item, Q |
|
33 | void decorate(ChartItem* item, QSeries* series,int count); | |
34 | void decorate(BarPresenter* item, QBarSeries* series,int count); |
|
34 | void decorate(BarPresenter* item, QBarSeries* series,int count); | |
35 | void decorate(StackedBarPresenter* item, QStackedBarSeries* series,int count); |
|
35 | void decorate(StackedBarPresenter* item, QStackedBarSeries* series,int count); | |
36 | void decorate(PercentBarPresenter* item, QPercentBarSeries* series,int count); |
|
36 | void decorate(PercentBarPresenter* item, QPercentBarSeries* series,int count); | |
37 | void decorate(LineChartItem* item, QLineSeries*, int count); |
|
37 | void decorate(LineChartItem* item, QLineSeries*, int count); | |
38 | void decorate(ScatterPresenter* presenter, QScatterSeries* series, int count); |
|
38 | void decorate(ScatterPresenter* presenter, QScatterSeries* series, int count); | |
39 | void decorate(PiePresenter* item, QPieSeries* series, int count); |
|
39 | void decorate(PiePresenter* item, QPieSeries* series, int count); | |
40 | void decorate(QChartAxis* axis,AxisItem* item); |
|
40 | void decorate(QChartAxis* axis,AxisItem* item); | |
41 |
|
41 | |||
42 | protected: |
|
42 | protected: | |
43 | QChart::ChartTheme m_id; |
|
43 | QChart::ChartTheme m_id; | |
44 | QColor m_gradientStartColor; |
|
44 | QColor m_gradientStartColor; | |
45 | QColor m_gradientEndColor; |
|
45 | QColor m_gradientEndColor; | |
46 | QList<QColor> m_seriesColor; |
|
46 | QList<QColor> m_seriesColor; | |
47 |
|
47 | |||
48 | }; |
|
48 | }; | |
49 |
|
49 | |||
50 | QTCOMMERCIALCHART_END_NAMESPACE |
|
50 | QTCOMMERCIALCHART_END_NAMESPACE | |
51 |
|
51 | |||
52 | #endif // CHARTTHEME_H |
|
52 | #endif // CHARTTHEME_H |
@@ -1,195 +1,195 | |||||
1 | #include "qlineseries.h" |
|
1 | #include "qlineseries.h" | |
2 |
|
2 | |||
3 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
3 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
4 |
|
4 | |||
5 | /*! |
|
5 | /*! | |
6 | \class QLineSeries |
|
6 | \class QLineSeries | |
7 | \brief The QLineSeries class is used for making line charts. |
|
7 | \brief The QLineSeries class is used for making line charts. | |
8 |
|
8 | |||
9 | \mainclass |
|
9 | \mainclass | |
10 |
|
10 | |||
11 | A line chart is used to show information as a series of data points |
|
11 | A line chart is used to show information as a series of data points | |
12 | connected by straight lines. |
|
12 | connected by straight lines. | |
13 |
|
13 | |||
14 | \image linechart.png |
|
14 | \image linechart.png | |
15 |
|
15 | |||
16 | To create line charts, users need to first QLineSeries object. |
|
16 | To create line charts, users need to first QLineSeries object. | |
17 |
|
17 | |||
18 | \snippet ../example/linechart/main.cpp 1 |
|
18 | \snippet ../example/linechart/main.cpp 1 | |
19 |
|
19 | |||
20 | Populate with the data |
|
20 | Populate with the data | |
21 |
|
21 | |||
22 | \snippet ../example/linechart/main.cpp 2 |
|
22 | \snippet ../example/linechart/main.cpp 2 | |
23 |
|
23 | |||
24 | Add created series objects to QChartView or QChart instance. |
|
24 | Add created series objects to QChartView or QChart instance. | |
25 |
|
25 | |||
26 | \snippet ../example/linechart/main.cpp 3 |
|
26 | \snippet ../example/linechart/main.cpp 3 | |
27 |
|
27 | |||
28 | */ |
|
28 | */ | |
29 |
|
29 | |||
30 | /*! |
|
30 | /*! | |
31 |
\fn virtual Q |
|
31 | \fn virtual QSeriesType QLineSeries::type() const | |
32 | \brief Returns type of series. |
|
32 | \brief Returns type of series. | |
33 |
\sa Q |
|
33 | \sa QSeries, QSeriesType | |
34 | */ |
|
34 | */ | |
35 |
|
35 | |||
36 | /*! |
|
36 | /*! | |
37 | \fn QPen QLineSeries::pen() const |
|
37 | \fn QPen QLineSeries::pen() const | |
38 | \brief Returns the pen used to draw line for this series. |
|
38 | \brief Returns the pen used to draw line for this series. | |
39 | \sa setPen() |
|
39 | \sa setPen() | |
40 | */ |
|
40 | */ | |
41 |
|
41 | |||
42 | /*! |
|
42 | /*! | |
43 | \fn bool QLineSeries::isPointsVisible() const |
|
43 | \fn bool QLineSeries::isPointsVisible() const | |
44 | \brief Returns if the points are drawn for this series. |
|
44 | \brief Returns if the points are drawn for this series. | |
45 | \sa setPointsVisible() |
|
45 | \sa setPointsVisible() | |
46 | */ |
|
46 | */ | |
47 |
|
47 | |||
48 |
|
48 | |||
49 | /*! |
|
49 | /*! | |
50 | \fn void QLineSeries::changed(int index) |
|
50 | \fn void QLineSeries::changed(int index) | |
51 | \brief \internal \a index |
|
51 | \brief \internal \a index | |
52 | */ |
|
52 | */ | |
53 |
|
53 | |||
54 | /*! |
|
54 | /*! | |
55 | Constructs empty series object which is a child of \a parent. |
|
55 | Constructs empty series object which is a child of \a parent. | |
56 | When series object is added to QChartView or QChart instance ownerships is transfered. |
|
56 | When series object is added to QChartView or QChart instance ownerships is transfered. | |
57 | */ |
|
57 | */ | |
58 |
QLineSeries::QLineSeries(QObject* parent):Q |
|
58 | QLineSeries::QLineSeries(QObject* parent):QSeries(parent), | |
59 | m_pointsVisible(false) |
|
59 | m_pointsVisible(false) | |
60 | { |
|
60 | { | |
61 | } |
|
61 | } | |
62 | /*! |
|
62 | /*! | |
63 | Destroys the object. Series added to QChartView or QChart instances are owned by those, |
|
63 | Destroys the object. Series added to QChartView or QChart instances are owned by those, | |
64 | and are deleted when mentioned object are destroyed. |
|
64 | and are deleted when mentioned object are destroyed. | |
65 | */ |
|
65 | */ | |
66 | QLineSeries::~QLineSeries() |
|
66 | QLineSeries::~QLineSeries() | |
67 | { |
|
67 | { | |
68 | } |
|
68 | } | |
69 |
|
69 | |||
70 | /*! |
|
70 | /*! | |
71 | Adds data point \a x \a y to the series. Points are connected with lines on the chart. |
|
71 | Adds data point \a x \a y to the series. Points are connected with lines on the chart. | |
72 | */ |
|
72 | */ | |
73 | void QLineSeries::add(qreal x,qreal y) |
|
73 | void QLineSeries::add(qreal x,qreal y) | |
74 | { |
|
74 | { | |
75 | m_x<<x; |
|
75 | m_x<<x; | |
76 | m_y<<y; |
|
76 | m_y<<y; | |
77 | } |
|
77 | } | |
78 |
|
78 | |||
79 | /*! |
|
79 | /*! | |
80 | This is an overloaded function. |
|
80 | This is an overloaded function. | |
81 | Adds data \a point to the series. Points are connected with lines on the chart. |
|
81 | Adds data \a point to the series. Points are connected with lines on the chart. | |
82 | */ |
|
82 | */ | |
83 | void QLineSeries::add(const QPointF& point) |
|
83 | void QLineSeries::add(const QPointF& point) | |
84 | { |
|
84 | { | |
85 | m_x<<point.x(); |
|
85 | m_x<<point.x(); | |
86 | m_y<<point.y(); |
|
86 | m_y<<point.y(); | |
87 | } |
|
87 | } | |
88 |
|
88 | |||
89 | /*! |
|
89 | /*! | |
90 | Modifies \a y value for given \a x a value. |
|
90 | Modifies \a y value for given \a x a value. | |
91 | */ |
|
91 | */ | |
92 | void QLineSeries::replace(qreal x,qreal y) |
|
92 | void QLineSeries::replace(qreal x,qreal y) | |
93 | { |
|
93 | { | |
94 | int index = m_x.indexOf(x); |
|
94 | int index = m_x.indexOf(x); | |
95 | m_x[index]=x; |
|
95 | m_x[index]=x; | |
96 | m_y[index]=y; |
|
96 | m_y[index]=y; | |
97 | emit changed(index); |
|
97 | emit changed(index); | |
98 | } |
|
98 | } | |
99 |
|
99 | |||
100 | /*! |
|
100 | /*! | |
101 | This is an overloaded function. |
|
101 | This is an overloaded function. | |
102 | Replaces current y value of for given \a point x value with \a point y value. |
|
102 | Replaces current y value of for given \a point x value with \a point y value. | |
103 | */ |
|
103 | */ | |
104 | void QLineSeries::replace(const QPointF& point) |
|
104 | void QLineSeries::replace(const QPointF& point) | |
105 | { |
|
105 | { | |
106 | int index = m_x.indexOf(point.x()); |
|
106 | int index = m_x.indexOf(point.x()); | |
107 | m_x[index]=point.x(); |
|
107 | m_x[index]=point.x(); | |
108 | m_y[index]=point.y(); |
|
108 | m_y[index]=point.y(); | |
109 | emit changed(index); |
|
109 | emit changed(index); | |
110 | } |
|
110 | } | |
111 |
|
111 | |||
112 | /*! |
|
112 | /*! | |
113 | Removes current \a x and y value. |
|
113 | Removes current \a x and y value. | |
114 | */ |
|
114 | */ | |
115 | void QLineSeries::remove(qreal x) |
|
115 | void QLineSeries::remove(qreal x) | |
116 | { |
|
116 | { | |
117 |
|
117 | |||
118 | } |
|
118 | } | |
119 |
|
119 | |||
120 | /*! |
|
120 | /*! | |
121 | Removes current \a point x value. Note \a point y value is ignored. |
|
121 | Removes current \a point x value. Note \a point y value is ignored. | |
122 | */ |
|
122 | */ | |
123 | void QLineSeries::remove(const QPointF& point) |
|
123 | void QLineSeries::remove(const QPointF& point) | |
124 | { |
|
124 | { | |
125 |
|
125 | |||
126 | } |
|
126 | } | |
127 |
|
127 | |||
128 | /*! |
|
128 | /*! | |
129 | Clears all the data. |
|
129 | Clears all the data. | |
130 | */ |
|
130 | */ | |
131 | void QLineSeries::clear() |
|
131 | void QLineSeries::clear() | |
132 | { |
|
132 | { | |
133 | m_x.clear(); |
|
133 | m_x.clear(); | |
134 | m_y.clear(); |
|
134 | m_y.clear(); | |
135 | } |
|
135 | } | |
136 |
|
136 | |||
137 | /*! |
|
137 | /*! | |
138 | \internal \a pos |
|
138 | \internal \a pos | |
139 | */ |
|
139 | */ | |
140 | qreal QLineSeries::x(int pos) const |
|
140 | qreal QLineSeries::x(int pos) const | |
141 | { |
|
141 | { | |
142 | return m_x.at(pos); |
|
142 | return m_x.at(pos); | |
143 | } |
|
143 | } | |
144 |
|
144 | |||
145 | /*! |
|
145 | /*! | |
146 | \internal \a pos |
|
146 | \internal \a pos | |
147 | */ |
|
147 | */ | |
148 | qreal QLineSeries::y(int pos) const |
|
148 | qreal QLineSeries::y(int pos) const | |
149 | { |
|
149 | { | |
150 | return m_y.at(pos); |
|
150 | return m_y.at(pos); | |
151 | } |
|
151 | } | |
152 |
|
152 | |||
153 | /*! |
|
153 | /*! | |
154 | Returns number of data points within series. |
|
154 | Returns number of data points within series. | |
155 | */ |
|
155 | */ | |
156 | int QLineSeries::count() const |
|
156 | int QLineSeries::count() const | |
157 | { |
|
157 | { | |
158 | Q_ASSERT(m_x.size() == m_y.size()); |
|
158 | Q_ASSERT(m_x.size() == m_y.size()); | |
159 |
|
159 | |||
160 | return m_x.size(); |
|
160 | return m_x.size(); | |
161 |
|
161 | |||
162 | } |
|
162 | } | |
163 |
|
163 | |||
164 | /*! |
|
164 | /*! | |
165 | Sets \a pen used for drawing given series.. |
|
165 | Sets \a pen used for drawing given series.. | |
166 | */ |
|
166 | */ | |
167 | void QLineSeries::setPen(const QPen& pen) |
|
167 | void QLineSeries::setPen(const QPen& pen) | |
168 | { |
|
168 | { | |
169 | m_pen=pen; |
|
169 | m_pen=pen; | |
170 | } |
|
170 | } | |
171 |
|
171 | |||
172 | /*! |
|
172 | /*! | |
173 | Sets if data points are \a visible and should be drawn on line. |
|
173 | Sets if data points are \a visible and should be drawn on line. | |
174 | */ |
|
174 | */ | |
175 | void QLineSeries::setPointsVisible(bool visible) |
|
175 | void QLineSeries::setPointsVisible(bool visible) | |
176 | { |
|
176 | { | |
177 | m_pointsVisible=visible; |
|
177 | m_pointsVisible=visible; | |
178 | } |
|
178 | } | |
179 |
|
179 | |||
180 | QDebug operator<< (QDebug debug, const QLineSeries series) |
|
180 | QDebug operator<< (QDebug debug, const QLineSeries series) | |
181 | { |
|
181 | { | |
182 | Q_ASSERT(series.m_x.size() == series.m_y.size()); |
|
182 | Q_ASSERT(series.m_x.size() == series.m_y.size()); | |
183 |
|
183 | |||
184 | int size = series.m_x.size(); |
|
184 | int size = series.m_x.size(); | |
185 |
|
185 | |||
186 | for (int i=0;i<size;i++) { |
|
186 | for (int i=0;i<size;i++) { | |
187 | debug.nospace() << "(" << series.m_x.at(i) << ','<< series.m_y.at(i) << ") "; |
|
187 | debug.nospace() << "(" << series.m_x.at(i) << ','<< series.m_y.at(i) << ") "; | |
188 | } |
|
188 | } | |
189 | return debug.space(); |
|
189 | return debug.space(); | |
190 | } |
|
190 | } | |
191 |
|
191 | |||
192 |
|
192 | |||
193 | #include "moc_qlineseries.cpp" |
|
193 | #include "moc_qlineseries.cpp" | |
194 |
|
194 | |||
195 | QTCOMMERCIALCHART_END_NAMESPACE |
|
195 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,52 +1,52 | |||||
1 |
#ifndef QLINE |
|
1 | #ifndef QLINESERIES_H_ | |
2 |
#define QLINE |
|
2 | #define QLINESERIES_H_ | |
3 |
|
3 | |||
4 | #include "qchartglobal.h" |
|
4 | #include "qchartglobal.h" | |
5 |
#include "q |
|
5 | #include "qseries.h" | |
6 | #include <QDebug> |
|
6 | #include <QDebug> | |
7 | #include <QPen> |
|
7 | #include <QPen> | |
8 | #include <QBrush> |
|
8 | #include <QBrush> | |
9 |
|
9 | |||
10 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
10 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
11 |
|
11 | |||
12 |
class QTCOMMERCIALCHART_EXPORT QLineSeries : public Q |
|
12 | class QTCOMMERCIALCHART_EXPORT QLineSeries : public QSeries | |
13 | { |
|
13 | { | |
14 | Q_OBJECT |
|
14 | Q_OBJECT | |
15 | public: |
|
15 | public: | |
16 | QLineSeries(QObject* parent=0); |
|
16 | QLineSeries(QObject* parent=0); | |
17 | virtual ~QLineSeries(); |
|
17 | virtual ~QLineSeries(); | |
18 |
|
18 | |||
19 | public: // from QChartSeries |
|
19 | public: // from QChartSeries | |
20 |
virtual Q |
|
20 | virtual QSeriesType type() const { return QSeries::SeriesTypeLine;} | |
21 | void add(qreal x, qreal y); |
|
21 | void add(qreal x, qreal y); | |
22 | void add(const QPointF& point); |
|
22 | void add(const QPointF& point); | |
23 | void replace(qreal x,qreal y); |
|
23 | void replace(qreal x,qreal y); | |
24 | void replace(const QPointF& point); |
|
24 | void replace(const QPointF& point); | |
25 | void remove(qreal x); |
|
25 | void remove(qreal x); | |
26 | void remove(const QPointF& point); |
|
26 | void remove(const QPointF& point); | |
27 | void clear(); |
|
27 | void clear(); | |
28 |
|
28 | |||
29 | void setPen(const QPen& pen); |
|
29 | void setPen(const QPen& pen); | |
30 | QPen pen() const { return m_pen;} |
|
30 | QPen pen() const { return m_pen;} | |
31 |
|
31 | |||
32 | void setPointsVisible(bool visible); |
|
32 | void setPointsVisible(bool visible); | |
33 | bool isPointsVisible() const {return m_pointsVisible;} |
|
33 | bool isPointsVisible() const {return m_pointsVisible;} | |
34 |
|
34 | |||
35 | int count() const; |
|
35 | int count() const; | |
36 | qreal x(int pos) const; |
|
36 | qreal x(int pos) const; | |
37 | qreal y(int pos) const; |
|
37 | qreal y(int pos) const; | |
38 | friend QDebug operator<< (QDebug d, const QLineSeries series); |
|
38 | friend QDebug operator<< (QDebug d, const QLineSeries series); | |
39 |
|
39 | |||
40 | signals: |
|
40 | signals: | |
41 | void changed(int index); |
|
41 | void changed(int index); | |
42 |
|
42 | |||
43 | private: |
|
43 | private: | |
44 | QVector<qreal> m_x; |
|
44 | QVector<qreal> m_x; | |
45 | QVector<qreal> m_y; |
|
45 | QVector<qreal> m_y; | |
46 | QPen m_pen; |
|
46 | QPen m_pen; | |
47 | bool m_pointsVisible; |
|
47 | bool m_pointsVisible; | |
48 | }; |
|
48 | }; | |
49 |
|
49 | |||
50 | QTCOMMERCIALCHART_END_NAMESPACE |
|
50 | QTCOMMERCIALCHART_END_NAMESPACE | |
51 |
|
51 | |||
52 | #endif |
|
52 | #endif |
@@ -1,534 +1,534 | |||||
1 | #include "qpieseries.h" |
|
1 | #include "qpieseries.h" | |
2 | #include "qpieslice.h" |
|
2 | #include "qpieslice.h" | |
3 | #include <QDebug> |
|
3 | #include <QDebug> | |
4 |
|
4 | |||
5 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
5 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
6 |
|
6 | |||
7 |
|
7 | |||
8 | /*! |
|
8 | /*! | |
9 | \class QPieSeries::ChangeSet |
|
9 | \class QPieSeries::ChangeSet | |
10 | \brief Defines the changes in the series. |
|
10 | \brief Defines the changes in the series. | |
11 |
|
11 | |||
12 | Contains the changes that have occurred in the series. Lists of added, changed and removed slices. |
|
12 | Contains the changes that have occurred in the series. Lists of added, changed and removed slices. | |
13 |
|
13 | |||
14 | \sa QPieSeries::changed() |
|
14 | \sa QPieSeries::changed() | |
15 | */ |
|
15 | */ | |
16 |
|
16 | |||
17 | /*! |
|
17 | /*! | |
18 | \internal |
|
18 | \internal | |
19 | */ |
|
19 | */ | |
20 | void QPieSeries::ChangeSet::appendAdded(QPieSlice* slice) |
|
20 | void QPieSeries::ChangeSet::appendAdded(QPieSlice* slice) | |
21 | { |
|
21 | { | |
22 | if (!m_added.contains(slice)) |
|
22 | if (!m_added.contains(slice)) | |
23 | m_added << slice; |
|
23 | m_added << slice; | |
24 | } |
|
24 | } | |
25 |
|
25 | |||
26 | /*! |
|
26 | /*! | |
27 | \internal |
|
27 | \internal | |
28 | */ |
|
28 | */ | |
29 | void QPieSeries::ChangeSet::appendAdded(QList<QPieSlice*> slices) |
|
29 | void QPieSeries::ChangeSet::appendAdded(QList<QPieSlice*> slices) | |
30 | { |
|
30 | { | |
31 | foreach (QPieSlice* s, slices) |
|
31 | foreach (QPieSlice* s, slices) | |
32 | appendAdded(s); |
|
32 | appendAdded(s); | |
33 | } |
|
33 | } | |
34 |
|
34 | |||
35 | /*! |
|
35 | /*! | |
36 | \internal |
|
36 | \internal | |
37 | */ |
|
37 | */ | |
38 | void QPieSeries::ChangeSet::appendChanged(QPieSlice* slice) |
|
38 | void QPieSeries::ChangeSet::appendChanged(QPieSlice* slice) | |
39 | { |
|
39 | { | |
40 | if (!m_changed.contains(slice)) |
|
40 | if (!m_changed.contains(slice)) | |
41 | m_changed << slice; |
|
41 | m_changed << slice; | |
42 | } |
|
42 | } | |
43 |
|
43 | |||
44 | /*! |
|
44 | /*! | |
45 | \internal |
|
45 | \internal | |
46 | */ |
|
46 | */ | |
47 | void QPieSeries::ChangeSet::appendRemoved(QPieSlice* slice) |
|
47 | void QPieSeries::ChangeSet::appendRemoved(QPieSlice* slice) | |
48 | { |
|
48 | { | |
49 | if (!m_removed.contains(slice)) |
|
49 | if (!m_removed.contains(slice)) | |
50 | m_removed << slice; |
|
50 | m_removed << slice; | |
51 | } |
|
51 | } | |
52 |
|
52 | |||
53 | /*! |
|
53 | /*! | |
54 | Returns a list of slices that have been added to the series. |
|
54 | Returns a list of slices that have been added to the series. | |
55 | \sa QPieSeries::changed() |
|
55 | \sa QPieSeries::changed() | |
56 | */ |
|
56 | */ | |
57 | QList<QPieSlice*> QPieSeries::ChangeSet::added() const |
|
57 | QList<QPieSlice*> QPieSeries::ChangeSet::added() const | |
58 | { |
|
58 | { | |
59 | return m_added; |
|
59 | return m_added; | |
60 | } |
|
60 | } | |
61 |
|
61 | |||
62 | /*! |
|
62 | /*! | |
63 | Returns a list of slices that have been changed in the series. |
|
63 | Returns a list of slices that have been changed in the series. | |
64 | \sa QPieSeries::changed() |
|
64 | \sa QPieSeries::changed() | |
65 | */ |
|
65 | */ | |
66 | QList<QPieSlice*> QPieSeries::ChangeSet::changed() const |
|
66 | QList<QPieSlice*> QPieSeries::ChangeSet::changed() const | |
67 | { |
|
67 | { | |
68 | return m_changed; |
|
68 | return m_changed; | |
69 | } |
|
69 | } | |
70 |
|
70 | |||
71 | /*! |
|
71 | /*! | |
72 | Returns a list of slices that have been removed from the series. |
|
72 | Returns a list of slices that have been removed from the series. | |
73 | \sa QPieSeries::changed() |
|
73 | \sa QPieSeries::changed() | |
74 | */ |
|
74 | */ | |
75 | QList<QPieSlice*> QPieSeries::ChangeSet::removed() const |
|
75 | QList<QPieSlice*> QPieSeries::ChangeSet::removed() const | |
76 | { |
|
76 | { | |
77 | return m_removed; |
|
77 | return m_removed; | |
78 | } |
|
78 | } | |
79 |
|
79 | |||
80 |
|
80 | |||
81 | /*! |
|
81 | /*! | |
82 | Returns true if there are no added/changed or removed slices in the change set. |
|
82 | Returns true if there are no added/changed or removed slices in the change set. | |
83 | */ |
|
83 | */ | |
84 | bool QPieSeries::ChangeSet::isEmpty() const |
|
84 | bool QPieSeries::ChangeSet::isEmpty() const | |
85 | { |
|
85 | { | |
86 | if (m_added.count() || m_changed.count() || m_removed.count()) |
|
86 | if (m_added.count() || m_changed.count() || m_removed.count()) | |
87 | return false; |
|
87 | return false; | |
88 | return true; |
|
88 | return true; | |
89 | } |
|
89 | } | |
90 |
|
90 | |||
91 | /*! |
|
91 | /*! | |
92 | \enum QPieSeries::PiePosition |
|
92 | \enum QPieSeries::PiePosition | |
93 |
|
93 | |||
94 | This enum describes pie position within its bounding rectangle |
|
94 | This enum describes pie position within its bounding rectangle | |
95 |
|
95 | |||
96 | \value PiePositionMaximized |
|
96 | \value PiePositionMaximized | |
97 | \value PiePositionTopLeft |
|
97 | \value PiePositionTopLeft | |
98 | \value PiePositionTopRight |
|
98 | \value PiePositionTopRight | |
99 | \value PiePositionBottomLeft |
|
99 | \value PiePositionBottomLeft | |
100 | \value PiePositionBottomRight |
|
100 | \value PiePositionBottomRight | |
101 | */ |
|
101 | */ | |
102 |
|
102 | |||
103 | /*! |
|
103 | /*! | |
104 | \class QPieSeries |
|
104 | \class QPieSeries | |
105 | \brief Pie series API for QtCommercial Charts |
|
105 | \brief Pie series API for QtCommercial Charts | |
106 |
|
106 | |||
107 | The pie series defines a pie chart which consists of pie slices which are QPieSlice objects. |
|
107 | The pie series defines a pie chart which consists of pie slices which are QPieSlice objects. | |
108 | The slices can have any values as the QPieSeries will calculate its relative value to the sum of all slices. |
|
108 | The slices can have any values as the QPieSeries will calculate its relative value to the sum of all slices. | |
109 | The actual slice size (span) is determined by that relative value. |
|
109 | The actual slice size (span) is determined by that relative value. | |
110 |
|
110 | |||
111 | By default the pie is defined as full but it can be a partial pie. |
|
111 | By default the pie is defined as full but it can be a partial pie. | |
112 | This can be done by setting a starting angle and angle span to the series. |
|
112 | This can be done by setting a starting angle and angle span to the series. | |
113 |
|
113 | |||
114 | Example on how to create a chart with pie series: |
|
114 | Example on how to create a chart with pie series: | |
115 | \snippet ../example/piechart/main.cpp 1 |
|
115 | \snippet ../example/piechart/main.cpp 1 | |
116 |
|
116 | |||
117 | To help with the most common user intercation scenarions there some convenience functions. Specifically |
|
117 | To help with the most common user intercation scenarions there some convenience functions. Specifically | |
118 | exploding and higlighting: |
|
118 | exploding and higlighting: | |
119 | \snippet ../example/piechart/main.cpp 2 |
|
119 | \snippet ../example/piechart/main.cpp 2 | |
120 |
|
120 | |||
121 | */ |
|
121 | */ | |
122 |
|
122 | |||
123 | /*! |
|
123 | /*! | |
124 | Constructs a series object which is a child of \a parent. |
|
124 | Constructs a series object which is a child of \a parent. | |
125 | */ |
|
125 | */ | |
126 | QPieSeries::QPieSeries(QObject *parent) : |
|
126 | QPieSeries::QPieSeries(QObject *parent) : | |
127 |
Q |
|
127 | QSeries(parent), | |
128 | m_sizeFactor(1.0), |
|
128 | m_sizeFactor(1.0), | |
129 | m_position(PiePositionMaximized), |
|
129 | m_position(PiePositionMaximized), | |
130 | m_pieStartAngle(0), |
|
130 | m_pieStartAngle(0), | |
131 | m_pieAngleSpan(360) |
|
131 | m_pieAngleSpan(360) | |
132 | { |
|
132 | { | |
133 |
|
133 | |||
134 | } |
|
134 | } | |
135 |
|
135 | |||
136 | /*! |
|
136 | /*! | |
137 | Destroys the object. Note that adding series to QChart transfers the ownership to the chart. |
|
137 | Destroys the object. Note that adding series to QChart transfers the ownership to the chart. | |
138 | */ |
|
138 | */ | |
139 | QPieSeries::~QPieSeries() |
|
139 | QPieSeries::~QPieSeries() | |
140 | { |
|
140 | { | |
141 |
|
141 | |||
142 | } |
|
142 | } | |
143 |
|
143 | |||
144 | /*! |
|
144 | /*! | |
145 | Returns QChartSeries::SeriesTypePie. |
|
145 | Returns QChartSeries::SeriesTypePie. | |
146 | */ |
|
146 | */ | |
147 |
Q |
|
147 | QSeries::QSeriesType QPieSeries::type() const | |
148 | { |
|
148 | { | |
149 |
return Q |
|
149 | return QSeries::SeriesTypePie; | |
150 | } |
|
150 | } | |
151 |
|
151 | |||
152 | /*! |
|
152 | /*! | |
153 | \internal \a data |
|
153 | \internal \a data | |
154 | */ |
|
154 | */ | |
155 | bool QPieSeries::setData(QList<qreal> data) |
|
155 | bool QPieSeries::setData(QList<qreal> data) | |
156 | { |
|
156 | { | |
157 | // TODO: remove this function |
|
157 | // TODO: remove this function | |
158 | QList<QPieSlice*> slices; |
|
158 | QList<QPieSlice*> slices; | |
159 | foreach (qreal value, data) |
|
159 | foreach (qreal value, data) | |
160 | slices << new QPieSlice(value, QString::number(value)); |
|
160 | slices << new QPieSlice(value, QString::number(value)); | |
161 | replace(slices); |
|
161 | replace(slices); | |
162 | return true; |
|
162 | return true; | |
163 | } |
|
163 | } | |
164 |
|
164 | |||
165 | /*! |
|
165 | /*! | |
166 | Sets an array of \a slices to the series replacing the existing slices. |
|
166 | Sets an array of \a slices to the series replacing the existing slices. | |
167 | Slice ownership is passed to the series. |
|
167 | Slice ownership is passed to the series. | |
168 | */ |
|
168 | */ | |
169 | void QPieSeries::replace(QList<QPieSlice*> slices) |
|
169 | void QPieSeries::replace(QList<QPieSlice*> slices) | |
170 | { |
|
170 | { | |
171 | clear(); |
|
171 | clear(); | |
172 | add(slices); |
|
172 | add(slices); | |
173 | } |
|
173 | } | |
174 |
|
174 | |||
175 | /*! |
|
175 | /*! | |
176 | Adds an array of \a slices to the series. |
|
176 | Adds an array of \a slices to the series. | |
177 | Slice ownership is passed to the series. |
|
177 | Slice ownership is passed to the series. | |
178 | */ |
|
178 | */ | |
179 | void QPieSeries::add(QList<QPieSlice*> slices) |
|
179 | void QPieSeries::add(QList<QPieSlice*> slices) | |
180 | { |
|
180 | { | |
181 | ChangeSet changeSet; |
|
181 | ChangeSet changeSet; | |
182 | foreach (QPieSlice* s, slices) { |
|
182 | foreach (QPieSlice* s, slices) { | |
183 | s->setParent(this); |
|
183 | s->setParent(this); | |
184 | m_slices << s; |
|
184 | m_slices << s; | |
185 | changeSet.appendAdded(s); |
|
185 | changeSet.appendAdded(s); | |
186 | } |
|
186 | } | |
187 |
|
187 | |||
188 | updateDerivativeData(); |
|
188 | updateDerivativeData(); | |
189 |
|
189 | |||
190 | foreach (QPieSlice* s, slices) { |
|
190 | foreach (QPieSlice* s, slices) { | |
191 | connect(s, SIGNAL(changed()), this, SLOT(sliceChanged())); |
|
191 | connect(s, SIGNAL(changed()), this, SLOT(sliceChanged())); | |
192 | connect(s, SIGNAL(clicked()), this, SLOT(sliceClicked())); |
|
192 | connect(s, SIGNAL(clicked()), this, SLOT(sliceClicked())); | |
193 | connect(s, SIGNAL(hoverEnter()), this, SLOT(sliceHoverEnter())); |
|
193 | connect(s, SIGNAL(hoverEnter()), this, SLOT(sliceHoverEnter())); | |
194 | connect(s, SIGNAL(hoverLeave()), this, SLOT(sliceHoverLeave())); |
|
194 | connect(s, SIGNAL(hoverLeave()), this, SLOT(sliceHoverLeave())); | |
195 | } |
|
195 | } | |
196 |
|
196 | |||
197 | emit changed(changeSet); |
|
197 | emit changed(changeSet); | |
198 | } |
|
198 | } | |
199 |
|
199 | |||
200 | /*! |
|
200 | /*! | |
201 | Adds a single \a slice to the series. |
|
201 | Adds a single \a slice to the series. | |
202 | Slice ownership is passed to the series. |
|
202 | Slice ownership is passed to the series. | |
203 | */ |
|
203 | */ | |
204 | void QPieSeries::add(QPieSlice* slice) |
|
204 | void QPieSeries::add(QPieSlice* slice) | |
205 | { |
|
205 | { | |
206 | add(QList<QPieSlice*>() << slice); |
|
206 | add(QList<QPieSlice*>() << slice); | |
207 | } |
|
207 | } | |
208 |
|
208 | |||
209 |
|
209 | |||
210 | /*! |
|
210 | /*! | |
211 | Adds a single slice to the series with give \a value and \a name. |
|
211 | Adds a single slice to the series with give \a value and \a name. | |
212 | Slice ownership is passed to the series. |
|
212 | Slice ownership is passed to the series. | |
213 | */ |
|
213 | */ | |
214 | QPieSlice* QPieSeries::add(qreal value, QString name) |
|
214 | QPieSlice* QPieSeries::add(qreal value, QString name) | |
215 | { |
|
215 | { | |
216 | QPieSlice* slice = new QPieSlice(value, name); |
|
216 | QPieSlice* slice = new QPieSlice(value, name); | |
217 | add(slice); |
|
217 | add(slice); | |
218 | return slice; |
|
218 | return slice; | |
219 | } |
|
219 | } | |
220 |
|
220 | |||
221 | /*! |
|
221 | /*! | |
222 | Removes a single \a slice from the series and deletes the slice. |
|
222 | Removes a single \a slice from the series and deletes the slice. | |
223 |
|
223 | |||
224 | Do not reference this pointer after this call. |
|
224 | Do not reference this pointer after this call. | |
225 | */ |
|
225 | */ | |
226 | void QPieSeries::remove(QPieSlice* slice) |
|
226 | void QPieSeries::remove(QPieSlice* slice) | |
227 | { |
|
227 | { | |
228 | if (!m_slices.removeOne(slice)) { |
|
228 | if (!m_slices.removeOne(slice)) { | |
229 | Q_ASSERT(0); // TODO: how should this be reported? |
|
229 | Q_ASSERT(0); // TODO: how should this be reported? | |
230 | return; |
|
230 | return; | |
231 | } |
|
231 | } | |
232 |
|
232 | |||
233 | ChangeSet changeSet; |
|
233 | ChangeSet changeSet; | |
234 | changeSet.appendRemoved(slice); |
|
234 | changeSet.appendRemoved(slice); | |
235 | emit changed(changeSet); |
|
235 | emit changed(changeSet); | |
236 |
|
236 | |||
237 | delete slice; |
|
237 | delete slice; | |
238 | slice = NULL; |
|
238 | slice = NULL; | |
239 |
|
239 | |||
240 | updateDerivativeData(); |
|
240 | updateDerivativeData(); | |
241 | } |
|
241 | } | |
242 |
|
242 | |||
243 | /*! |
|
243 | /*! | |
244 | Clears all slices from the series. |
|
244 | Clears all slices from the series. | |
245 | */ |
|
245 | */ | |
246 | void QPieSeries::clear() |
|
246 | void QPieSeries::clear() | |
247 | { |
|
247 | { | |
248 | if (m_slices.count() == 0) |
|
248 | if (m_slices.count() == 0) | |
249 | return; |
|
249 | return; | |
250 |
|
250 | |||
251 | ChangeSet changeSet; |
|
251 | ChangeSet changeSet; | |
252 | foreach (QPieSlice* s, m_slices) { |
|
252 | foreach (QPieSlice* s, m_slices) { | |
253 | changeSet.appendRemoved(s); |
|
253 | changeSet.appendRemoved(s); | |
254 | m_slices.removeOne(s); |
|
254 | m_slices.removeOne(s); | |
255 | delete s; |
|
255 | delete s; | |
256 | } |
|
256 | } | |
257 | emit changed(changeSet); |
|
257 | emit changed(changeSet); | |
258 | updateDerivativeData(); |
|
258 | updateDerivativeData(); | |
259 | } |
|
259 | } | |
260 |
|
260 | |||
261 | /*! |
|
261 | /*! | |
262 | Counts the number of the slices in this series. |
|
262 | Counts the number of the slices in this series. | |
263 | */ |
|
263 | */ | |
264 | int QPieSeries::count() const |
|
264 | int QPieSeries::count() const | |
265 | { |
|
265 | { | |
266 | return m_slices.count(); |
|
266 | return m_slices.count(); | |
267 | } |
|
267 | } | |
268 |
|
268 | |||
269 | /*! |
|
269 | /*! | |
270 | Returns a list of slices that belong to this series. |
|
270 | Returns a list of slices that belong to this series. | |
271 | */ |
|
271 | */ | |
272 | QList<QPieSlice*> QPieSeries::slices() const |
|
272 | QList<QPieSlice*> QPieSeries::slices() const | |
273 | { |
|
273 | { | |
274 | return m_slices; |
|
274 | return m_slices; | |
275 | } |
|
275 | } | |
276 |
|
276 | |||
277 | /*! |
|
277 | /*! | |
278 | Sets the size \a factor of the pie. 1.0 is the default value. |
|
278 | Sets the size \a factor of the pie. 1.0 is the default value. | |
279 | Note that the pie will not grow beyond its absolute maximum size. |
|
279 | Note that the pie will not grow beyond its absolute maximum size. | |
280 | In practice its use is to make the pie appear smaller. |
|
280 | In practice its use is to make the pie appear smaller. | |
281 | \sa sizeFactor() |
|
281 | \sa sizeFactor() | |
282 | */ |
|
282 | */ | |
283 | void QPieSeries::setSizeFactor(qreal factor) |
|
283 | void QPieSeries::setSizeFactor(qreal factor) | |
284 | { |
|
284 | { | |
285 | if (factor < 0.0) |
|
285 | if (factor < 0.0) | |
286 | return; |
|
286 | return; | |
287 |
|
287 | |||
288 | if (m_sizeFactor != factor) { |
|
288 | if (m_sizeFactor != factor) { | |
289 | m_sizeFactor = factor; |
|
289 | m_sizeFactor = factor; | |
290 | emit sizeFactorChanged(); |
|
290 | emit sizeFactorChanged(); | |
291 | } |
|
291 | } | |
292 | } |
|
292 | } | |
293 |
|
293 | |||
294 | /*! |
|
294 | /*! | |
295 | Gets the size factor of the pie. |
|
295 | Gets the size factor of the pie. | |
296 | \sa setSizeFactor() |
|
296 | \sa setSizeFactor() | |
297 | */ |
|
297 | */ | |
298 | qreal QPieSeries::sizeFactor() const |
|
298 | qreal QPieSeries::sizeFactor() const | |
299 | { |
|
299 | { | |
300 | return m_sizeFactor; |
|
300 | return m_sizeFactor; | |
301 | } |
|
301 | } | |
302 |
|
302 | |||
303 | /*! |
|
303 | /*! | |
304 | Sets the \a position of the pie within its bounding rectangle. |
|
304 | Sets the \a position of the pie within its bounding rectangle. | |
305 | \sa PiePosition, position() |
|
305 | \sa PiePosition, position() | |
306 | */ |
|
306 | */ | |
307 | void QPieSeries::setPosition(PiePosition position) |
|
307 | void QPieSeries::setPosition(PiePosition position) | |
308 | { |
|
308 | { | |
309 | if (m_position != position) { |
|
309 | if (m_position != position) { | |
310 | m_position = position; |
|
310 | m_position = position; | |
311 | emit positionChanged(); |
|
311 | emit positionChanged(); | |
312 | } |
|
312 | } | |
313 | } |
|
313 | } | |
314 |
|
314 | |||
315 | /*! |
|
315 | /*! | |
316 | Gets the position of the pie within its bounding rectangle. |
|
316 | Gets the position of the pie within its bounding rectangle. | |
317 | \sa PiePosition, setPosition() |
|
317 | \sa PiePosition, setPosition() | |
318 | */ |
|
318 | */ | |
319 | QPieSeries::PiePosition QPieSeries::position() const |
|
319 | QPieSeries::PiePosition QPieSeries::position() const | |
320 | { |
|
320 | { | |
321 | return m_position; |
|
321 | return m_position; | |
322 | } |
|
322 | } | |
323 |
|
323 | |||
324 |
|
324 | |||
325 | /*! |
|
325 | /*! | |
326 | Sets the \a startAngle and \a angleSpan of this series. |
|
326 | Sets the \a startAngle and \a angleSpan of this series. | |
327 |
|
327 | |||
328 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. |
|
328 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. | |
329 | */ |
|
329 | */ | |
330 | void QPieSeries::setSpan(qreal startAngle, qreal angleSpan) |
|
330 | void QPieSeries::setSpan(qreal startAngle, qreal angleSpan) | |
331 | { |
|
331 | { | |
332 | if (startAngle >= 0 && startAngle < 360 && |
|
332 | if (startAngle >= 0 && startAngle < 360 && | |
333 | angleSpan > 0 && angleSpan <= 360) { |
|
333 | angleSpan > 0 && angleSpan <= 360) { | |
334 | m_pieStartAngle = startAngle; |
|
334 | m_pieStartAngle = startAngle; | |
335 | m_pieAngleSpan = angleSpan; |
|
335 | m_pieAngleSpan = angleSpan; | |
336 | updateDerivativeData(); |
|
336 | updateDerivativeData(); | |
337 | } |
|
337 | } | |
338 | } |
|
338 | } | |
339 |
|
339 | |||
340 | /*! |
|
340 | /*! | |
341 | Sets the all the slice labels \a visible or invisible. |
|
341 | Sets the all the slice labels \a visible or invisible. | |
342 |
|
342 | |||
343 | \sa QPieSlice::isLabelVisible(), QPieSlice::setLabelVisible() |
|
343 | \sa QPieSlice::isLabelVisible(), QPieSlice::setLabelVisible() | |
344 | */ |
|
344 | */ | |
345 | void QPieSeries::setLabelsVisible(bool visible) |
|
345 | void QPieSeries::setLabelsVisible(bool visible) | |
346 | { |
|
346 | { | |
347 | foreach (QPieSlice* s, m_slices) |
|
347 | foreach (QPieSlice* s, m_slices) | |
348 | s->setLabelVisible(visible); |
|
348 | s->setLabelVisible(visible); | |
349 | } |
|
349 | } | |
350 |
|
350 | |||
351 | /*! |
|
351 | /*! | |
352 | Convenience method for exploding a slice when user clicks the pie. Set \a enable to true to |
|
352 | Convenience method for exploding a slice when user clicks the pie. Set \a enable to true to | |
353 | explode slices by clicking. |
|
353 | explode slices by clicking. | |
354 |
|
354 | |||
355 | \sa QPieSlice::isExploded(), QPieSlice::setExploded(), QPieSlice::setExplodeDistance() |
|
355 | \sa QPieSlice::isExploded(), QPieSlice::setExploded(), QPieSlice::setExplodeDistance() | |
356 | */ |
|
356 | */ | |
357 | void QPieSeries::enableClickExplodes(bool enable) |
|
357 | void QPieSeries::enableClickExplodes(bool enable) | |
358 | { |
|
358 | { | |
359 | if (enable) |
|
359 | if (enable) | |
360 | connect(this, SIGNAL(clicked(QPieSlice*)), this, SLOT(toggleExploded(QPieSlice*))); |
|
360 | connect(this, SIGNAL(clicked(QPieSlice*)), this, SLOT(toggleExploded(QPieSlice*))); | |
361 | else |
|
361 | else | |
362 | disconnect(this, SLOT(toggleExploded(QPieSlice*))); |
|
362 | disconnect(this, SLOT(toggleExploded(QPieSlice*))); | |
363 | } |
|
363 | } | |
364 |
|
364 | |||
365 | /*! |
|
365 | /*! | |
366 | Convenience method for highlighting a slice when user hovers over the slice. |
|
366 | Convenience method for highlighting a slice when user hovers over the slice. | |
367 | It changes the slice color to be lighter and shows the label of the slice. |
|
367 | It changes the slice color to be lighter and shows the label of the slice. | |
368 | Set \a enable to true to highlight a slice when user hovers on top of it. |
|
368 | Set \a enable to true to highlight a slice when user hovers on top of it. | |
369 |
|
369 | |||
370 | \sa QPieSlice::isExploded(), QPieSlice::setExploded() |
|
370 | \sa QPieSlice::isExploded(), QPieSlice::setExploded() | |
371 | */ |
|
371 | */ | |
372 |
|
372 | |||
373 | void QPieSeries::enableHoverHighlight(bool enable) |
|
373 | void QPieSeries::enableHoverHighlight(bool enable) | |
374 | { |
|
374 | { | |
375 | if (enable) { |
|
375 | if (enable) { | |
376 | connect(this, SIGNAL(hoverEnter(QPieSlice*)), this, SLOT(highlightOn(QPieSlice*))); |
|
376 | connect(this, SIGNAL(hoverEnter(QPieSlice*)), this, SLOT(highlightOn(QPieSlice*))); | |
377 | connect(this, SIGNAL(hoverLeave(QPieSlice*)), this, SLOT(highlightOff(QPieSlice*))); |
|
377 | connect(this, SIGNAL(hoverLeave(QPieSlice*)), this, SLOT(highlightOff(QPieSlice*))); | |
378 | } else { |
|
378 | } else { | |
379 | disconnect(this, SLOT(hoverEnter(QPieSlice*))); |
|
379 | disconnect(this, SLOT(hoverEnter(QPieSlice*))); | |
380 | disconnect(this, SLOT(hoverLeave(QPieSlice*))); |
|
380 | disconnect(this, SLOT(hoverLeave(QPieSlice*))); | |
381 | } |
|
381 | } | |
382 | } |
|
382 | } | |
383 |
|
383 | |||
384 | /*! |
|
384 | /*! | |
385 | \fn void QPieSeries::changed(const QPieSeries::ChangeSet& changeSet) |
|
385 | \fn void QPieSeries::changed(const QPieSeries::ChangeSet& changeSet) | |
386 |
|
386 | |||
387 | This signal emitted when something has changed in the series. |
|
387 | This signal emitted when something has changed in the series. | |
388 | The \a changeSet contains the details of which slices have been added, changed or removed. |
|
388 | The \a changeSet contains the details of which slices have been added, changed or removed. | |
389 |
|
389 | |||
390 | \sa QPieSeries::ChangeSet, QPieSlice::changed() |
|
390 | \sa QPieSeries::ChangeSet, QPieSlice::changed() | |
391 | */ |
|
391 | */ | |
392 |
|
392 | |||
393 | /*! |
|
393 | /*! | |
394 | \fn void QPieSeries::clicked(QPieSlice* slice) |
|
394 | \fn void QPieSeries::clicked(QPieSlice* slice) | |
395 |
|
395 | |||
396 | This signal is emitted when a \a slice has been clicked. |
|
396 | This signal is emitted when a \a slice has been clicked. | |
397 |
|
397 | |||
398 | \sa QPieSlice::clicked() |
|
398 | \sa QPieSlice::clicked() | |
399 | */ |
|
399 | */ | |
400 |
|
400 | |||
401 | /*! |
|
401 | /*! | |
402 | \fn void QPieSeries::hoverEnter(QPieSlice* slice) |
|
402 | \fn void QPieSeries::hoverEnter(QPieSlice* slice) | |
403 |
|
403 | |||
404 | This signal is emitted when user has hovered over a \a slice. |
|
404 | This signal is emitted when user has hovered over a \a slice. | |
405 |
|
405 | |||
406 | \sa QPieSlice::hoverEnter() |
|
406 | \sa QPieSlice::hoverEnter() | |
407 | */ |
|
407 | */ | |
408 |
|
408 | |||
409 | /*! |
|
409 | /*! | |
410 | \fn void QPieSeries::hoverLeave(QPieSlice* slice) |
|
410 | \fn void QPieSeries::hoverLeave(QPieSlice* slice) | |
411 |
|
411 | |||
412 | This signal is emitted when user has hovered away from a \a slice. |
|
412 | This signal is emitted when user has hovered away from a \a slice. | |
413 |
|
413 | |||
414 | \sa QPieSlice::hoverLeave() |
|
414 | \sa QPieSlice::hoverLeave() | |
415 | */ |
|
415 | */ | |
416 |
|
416 | |||
417 | /*! |
|
417 | /*! | |
418 | \fn void QPieSeries::sizeFactorChanged() |
|
418 | \fn void QPieSeries::sizeFactorChanged() | |
419 |
|
419 | |||
420 | This signal is emitted when size factor has been changed. |
|
420 | This signal is emitted when size factor has been changed. | |
421 |
|
421 | |||
422 | \sa sizeFactor(), setSizeFactor() |
|
422 | \sa sizeFactor(), setSizeFactor() | |
423 | */ |
|
423 | */ | |
424 |
|
424 | |||
425 | /*! |
|
425 | /*! | |
426 | \fn void QPieSeries::positionChanged() |
|
426 | \fn void QPieSeries::positionChanged() | |
427 |
|
427 | |||
428 | This signal is emitted when position of the pie has been changed. |
|
428 | This signal is emitted when position of the pie has been changed. | |
429 |
|
429 | |||
430 | \sa position(), setPosition() |
|
430 | \sa position(), setPosition() | |
431 | */ |
|
431 | */ | |
432 |
|
432 | |||
433 | void QPieSeries::sliceChanged() |
|
433 | void QPieSeries::sliceChanged() | |
434 | { |
|
434 | { | |
435 | QPieSlice* slice = qobject_cast<QPieSlice *>(sender()); |
|
435 | QPieSlice* slice = qobject_cast<QPieSlice *>(sender()); | |
436 | Q_ASSERT(m_slices.contains(slice)); |
|
436 | Q_ASSERT(m_slices.contains(slice)); | |
437 |
|
437 | |||
438 | ChangeSet changeSet; |
|
438 | ChangeSet changeSet; | |
439 | changeSet.appendChanged(slice); |
|
439 | changeSet.appendChanged(slice); | |
440 | emit changed(changeSet); |
|
440 | emit changed(changeSet); | |
441 |
|
441 | |||
442 | updateDerivativeData(); |
|
442 | updateDerivativeData(); | |
443 | } |
|
443 | } | |
444 |
|
444 | |||
445 | void QPieSeries::sliceClicked() |
|
445 | void QPieSeries::sliceClicked() | |
446 | { |
|
446 | { | |
447 | QPieSlice* slice = qobject_cast<QPieSlice *>(sender()); |
|
447 | QPieSlice* slice = qobject_cast<QPieSlice *>(sender()); | |
448 | Q_ASSERT(m_slices.contains(slice)); |
|
448 | Q_ASSERT(m_slices.contains(slice)); | |
449 | emit clicked(slice); |
|
449 | emit clicked(slice); | |
450 | } |
|
450 | } | |
451 |
|
451 | |||
452 | void QPieSeries::sliceHoverEnter() |
|
452 | void QPieSeries::sliceHoverEnter() | |
453 | { |
|
453 | { | |
454 | QPieSlice* slice = qobject_cast<QPieSlice *>(sender()); |
|
454 | QPieSlice* slice = qobject_cast<QPieSlice *>(sender()); | |
455 | Q_ASSERT(m_slices.contains(slice)); |
|
455 | Q_ASSERT(m_slices.contains(slice)); | |
456 | emit hoverEnter(slice); |
|
456 | emit hoverEnter(slice); | |
457 | } |
|
457 | } | |
458 |
|
458 | |||
459 | void QPieSeries::sliceHoverLeave() |
|
459 | void QPieSeries::sliceHoverLeave() | |
460 | { |
|
460 | { | |
461 | QPieSlice* slice = qobject_cast<QPieSlice *>(sender()); |
|
461 | QPieSlice* slice = qobject_cast<QPieSlice *>(sender()); | |
462 | Q_ASSERT(m_slices.contains(slice)); |
|
462 | Q_ASSERT(m_slices.contains(slice)); | |
463 | emit hoverLeave(slice); |
|
463 | emit hoverLeave(slice); | |
464 | } |
|
464 | } | |
465 |
|
465 | |||
466 | void QPieSeries::toggleExploded(QPieSlice* slice) |
|
466 | void QPieSeries::toggleExploded(QPieSlice* slice) | |
467 | { |
|
467 | { | |
468 | Q_ASSERT(slice); |
|
468 | Q_ASSERT(slice); | |
469 | slice->setExploded(!slice->isExploded()); |
|
469 | slice->setExploded(!slice->isExploded()); | |
470 | } |
|
470 | } | |
471 |
|
471 | |||
472 | void QPieSeries::highlightOn(QPieSlice* slice) |
|
472 | void QPieSeries::highlightOn(QPieSlice* slice) | |
473 | { |
|
473 | { | |
474 | Q_ASSERT(slice); |
|
474 | Q_ASSERT(slice); | |
475 | QColor c = slice->brush().color().lighter(); |
|
475 | QColor c = slice->brush().color().lighter(); | |
476 | slice->setBrush(c); |
|
476 | slice->setBrush(c); | |
477 | slice->setLabelVisible(true); |
|
477 | slice->setLabelVisible(true); | |
478 | } |
|
478 | } | |
479 |
|
479 | |||
480 | void QPieSeries::highlightOff(QPieSlice* slice) |
|
480 | void QPieSeries::highlightOff(QPieSlice* slice) | |
481 | { |
|
481 | { | |
482 | Q_ASSERT(slice); |
|
482 | Q_ASSERT(slice); | |
483 | QColor c = slice->brush().color().darker(150); |
|
483 | QColor c = slice->brush().color().darker(150); | |
484 | slice->setBrush(c); |
|
484 | slice->setBrush(c); | |
485 | slice->setLabelVisible(false); |
|
485 | slice->setLabelVisible(false); | |
486 | } |
|
486 | } | |
487 |
|
487 | |||
488 | void QPieSeries::updateDerivativeData() |
|
488 | void QPieSeries::updateDerivativeData() | |
489 | { |
|
489 | { | |
490 | m_total = 0; |
|
490 | m_total = 0; | |
491 |
|
491 | |||
492 | // nothing to do? |
|
492 | // nothing to do? | |
493 | if (m_slices.count() == 0) |
|
493 | if (m_slices.count() == 0) | |
494 | return; |
|
494 | return; | |
495 |
|
495 | |||
496 | // calculate total |
|
496 | // calculate total | |
497 | foreach (QPieSlice* s, m_slices) |
|
497 | foreach (QPieSlice* s, m_slices) | |
498 | m_total += s->value(); |
|
498 | m_total += s->value(); | |
499 |
|
499 | |||
500 | // we must have some values |
|
500 | // we must have some values | |
501 | Q_ASSERT(m_total > 0); // TODO: is this the correct way to handle this? |
|
501 | Q_ASSERT(m_total > 0); // TODO: is this the correct way to handle this? | |
502 |
|
502 | |||
503 | // update slice attributes |
|
503 | // update slice attributes | |
504 | qreal sliceAngle = m_pieStartAngle; |
|
504 | qreal sliceAngle = m_pieStartAngle; | |
505 | foreach (QPieSlice* s, m_slices) { |
|
505 | foreach (QPieSlice* s, m_slices) { | |
506 |
|
506 | |||
507 | bool changed = false; |
|
507 | bool changed = false; | |
508 |
|
508 | |||
509 | qreal percentage = s->value() / m_total; |
|
509 | qreal percentage = s->value() / m_total; | |
510 | if (s->m_percentage != percentage) { |
|
510 | if (s->m_percentage != percentage) { | |
511 | s->m_percentage = percentage; |
|
511 | s->m_percentage = percentage; | |
512 | changed = true; |
|
512 | changed = true; | |
513 | } |
|
513 | } | |
514 |
|
514 | |||
515 | qreal sliceSpan = m_pieAngleSpan * percentage; |
|
515 | qreal sliceSpan = m_pieAngleSpan * percentage; | |
516 | if (s->m_angleSpan != sliceSpan) { |
|
516 | if (s->m_angleSpan != sliceSpan) { | |
517 | s->m_angleSpan = sliceSpan; |
|
517 | s->m_angleSpan = sliceSpan; | |
518 | changed = true; |
|
518 | changed = true; | |
519 | } |
|
519 | } | |
520 |
|
520 | |||
521 | if (s->m_startAngle != sliceAngle) { |
|
521 | if (s->m_startAngle != sliceAngle) { | |
522 | s->m_startAngle = sliceAngle; |
|
522 | s->m_startAngle = sliceAngle; | |
523 | changed = true; |
|
523 | changed = true; | |
524 | } |
|
524 | } | |
525 | sliceAngle += sliceSpan; |
|
525 | sliceAngle += sliceSpan; | |
526 |
|
526 | |||
527 | if (changed) |
|
527 | if (changed) | |
528 | emit s->changed(); |
|
528 | emit s->changed(); | |
529 | } |
|
529 | } | |
530 | } |
|
530 | } | |
531 |
|
531 | |||
532 | #include "moc_qpieseries.cpp" |
|
532 | #include "moc_qpieseries.cpp" | |
533 |
|
533 | |||
534 | QTCOMMERCIALCHART_END_NAMESPACE |
|
534 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,133 +1,133 | |||||
1 | #ifndef PIESERIES_H |
|
1 | #ifndef PIESERIES_H | |
2 | #define PIESERIES_H |
|
2 | #define PIESERIES_H | |
3 |
|
3 | |||
4 |
#include "q |
|
4 | #include "qseries.h" | |
5 | #include <QObject> |
|
5 | #include <QObject> | |
6 | #include <QRectF> |
|
6 | #include <QRectF> | |
7 | #include <QColor> |
|
7 | #include <QColor> | |
8 | #include <QPen> |
|
8 | #include <QPen> | |
9 | #include <QBrush> |
|
9 | #include <QBrush> | |
10 | #include <QSignalMapper> |
|
10 | #include <QSignalMapper> | |
11 |
|
11 | |||
12 | class QGraphicsObject; |
|
12 | class QGraphicsObject; | |
13 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
13 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
14 | class PiePresenter; |
|
14 | class PiePresenter; | |
15 | class PieSlice; |
|
15 | class PieSlice; | |
16 | class QPieSlice; |
|
16 | class QPieSlice; | |
17 |
|
17 | |||
18 |
class QTCOMMERCIALCHART_EXPORT QPieSeries : public Q |
|
18 | class QTCOMMERCIALCHART_EXPORT QPieSeries : public QSeries | |
19 | { |
|
19 | { | |
20 | Q_OBJECT |
|
20 | Q_OBJECT | |
21 |
|
21 | |||
22 | public: |
|
22 | public: | |
23 | enum PiePosition { |
|
23 | enum PiePosition { | |
24 | PiePositionMaximized = 0, |
|
24 | PiePositionMaximized = 0, | |
25 | PiePositionTopLeft, |
|
25 | PiePositionTopLeft, | |
26 | PiePositionTopRight, |
|
26 | PiePositionTopRight, | |
27 | PiePositionBottomLeft, |
|
27 | PiePositionBottomLeft, | |
28 | PiePositionBottomRight |
|
28 | PiePositionBottomRight | |
29 | }; |
|
29 | }; | |
30 |
|
30 | |||
31 | class ChangeSet |
|
31 | class ChangeSet | |
32 | { |
|
32 | { | |
33 | public: |
|
33 | public: | |
34 |
|
34 | |||
35 | // TODO: these should not really be exposed to the public API |
|
35 | // TODO: these should not really be exposed to the public API | |
36 | void appendAdded(QPieSlice* slice); |
|
36 | void appendAdded(QPieSlice* slice); | |
37 | void appendAdded(QList<QPieSlice*> slices); |
|
37 | void appendAdded(QList<QPieSlice*> slices); | |
38 | void appendChanged(QPieSlice* slice); |
|
38 | void appendChanged(QPieSlice* slice); | |
39 | void appendRemoved(QPieSlice* slice); |
|
39 | void appendRemoved(QPieSlice* slice); | |
40 |
|
40 | |||
41 | QList<QPieSlice*> added() const; |
|
41 | QList<QPieSlice*> added() const; | |
42 | QList<QPieSlice*> changed() const; |
|
42 | QList<QPieSlice*> changed() const; | |
43 | QList<QPieSlice*> removed() const; |
|
43 | QList<QPieSlice*> removed() const; | |
44 |
|
44 | |||
45 | bool isEmpty() const; |
|
45 | bool isEmpty() const; | |
46 |
|
46 | |||
47 | private: |
|
47 | private: | |
48 | QList<QPieSlice*> m_added; |
|
48 | QList<QPieSlice*> m_added; | |
49 | QList<QPieSlice*> m_changed; |
|
49 | QList<QPieSlice*> m_changed; | |
50 | QList<QPieSlice*> m_removed; |
|
50 | QList<QPieSlice*> m_removed; | |
51 | }; |
|
51 | }; | |
52 |
|
52 | |||
53 | public: |
|
53 | public: | |
54 | QPieSeries(QObject *parent = 0); |
|
54 | QPieSeries(QObject *parent = 0); | |
55 | virtual ~QPieSeries(); |
|
55 | virtual ~QPieSeries(); | |
56 |
|
56 | |||
57 | public: // from QChartSeries |
|
57 | public: // from QChartSeries | |
58 |
Q |
|
58 | QSeriesType type() const; | |
59 | virtual bool setData(QList<qreal> data); // TODO: remove this |
|
59 | virtual bool setData(QList<qreal> data); // TODO: remove this | |
60 |
|
60 | |||
61 | public: |
|
61 | public: | |
62 | void replace(QList<QPieSlice*> slices); |
|
62 | void replace(QList<QPieSlice*> slices); | |
63 | void add(QList<QPieSlice*> slices); |
|
63 | void add(QList<QPieSlice*> slices); | |
64 | void add(QPieSlice* slice); |
|
64 | void add(QPieSlice* slice); | |
65 | QPieSlice* add(qreal value, QString name); |
|
65 | QPieSlice* add(qreal value, QString name); | |
66 | void remove(QPieSlice* slice); |
|
66 | void remove(QPieSlice* slice); | |
67 | void clear(); |
|
67 | void clear(); | |
68 |
|
68 | |||
69 | int count() const; |
|
69 | int count() const; | |
70 |
|
70 | |||
71 | QList<QPieSlice*> slices() const; |
|
71 | QList<QPieSlice*> slices() const; | |
72 |
|
72 | |||
73 | void setSizeFactor(qreal sizeFactor); |
|
73 | void setSizeFactor(qreal sizeFactor); | |
74 | qreal sizeFactor() const; |
|
74 | qreal sizeFactor() const; | |
75 |
|
75 | |||
76 | void setPosition(PiePosition position); |
|
76 | void setPosition(PiePosition position); | |
77 | PiePosition position() const; |
|
77 | PiePosition position() const; | |
78 |
|
78 | |||
79 | void setSpan(qreal startAngle, qreal angleSpan); |
|
79 | void setSpan(qreal startAngle, qreal angleSpan); | |
80 |
|
80 | |||
81 | void setLabelsVisible(bool visible); |
|
81 | void setLabelsVisible(bool visible); | |
82 | void enableClickExplodes(bool enable); |
|
82 | void enableClickExplodes(bool enable); | |
83 | void enableHoverHighlight(bool enable); |
|
83 | void enableHoverHighlight(bool enable); | |
84 |
|
84 | |||
85 | // TODO: find slices? |
|
85 | // TODO: find slices? | |
86 | // QList<QPieSlice*> findByValue(qreal value); |
|
86 | // QList<QPieSlice*> findByValue(qreal value); | |
87 | // ... |
|
87 | // ... | |
88 |
|
88 | |||
89 | // TODO: sorting slices? |
|
89 | // TODO: sorting slices? | |
90 | // void sort(QPieSeries::SortByValue|label|??) |
|
90 | // void sort(QPieSeries::SortByValue|label|??) | |
91 |
|
91 | |||
92 | // TODO: general graphics customization |
|
92 | // TODO: general graphics customization | |
93 | // setDrawStyle(2d|3d) |
|
93 | // setDrawStyle(2d|3d) | |
94 | // setDropShadows(bool) |
|
94 | // setDropShadows(bool) | |
95 |
|
95 | |||
96 | Q_SIGNALS: |
|
96 | Q_SIGNALS: | |
97 | void changed(const QPieSeries::ChangeSet& changeSet); |
|
97 | void changed(const QPieSeries::ChangeSet& changeSet); | |
98 | void clicked(QPieSlice* slice); |
|
98 | void clicked(QPieSlice* slice); | |
99 | void hoverEnter(QPieSlice* slice); |
|
99 | void hoverEnter(QPieSlice* slice); | |
100 | void hoverLeave(QPieSlice* slice); |
|
100 | void hoverLeave(QPieSlice* slice); | |
101 | void sizeFactorChanged(); |
|
101 | void sizeFactorChanged(); | |
102 | void positionChanged(); |
|
102 | void positionChanged(); | |
103 |
|
103 | |||
104 | private Q_SLOTS: // TODO: should be private and not visible in the interface at all |
|
104 | private Q_SLOTS: // TODO: should be private and not visible in the interface at all | |
105 | void sliceChanged(); |
|
105 | void sliceChanged(); | |
106 | void sliceClicked(); |
|
106 | void sliceClicked(); | |
107 | void sliceHoverEnter(); |
|
107 | void sliceHoverEnter(); | |
108 | void sliceHoverLeave(); |
|
108 | void sliceHoverLeave(); | |
109 | void toggleExploded(QPieSlice* slice); |
|
109 | void toggleExploded(QPieSlice* slice); | |
110 | void highlightOn(QPieSlice* slice); |
|
110 | void highlightOn(QPieSlice* slice); | |
111 | void highlightOff(QPieSlice* slice); |
|
111 | void highlightOff(QPieSlice* slice); | |
112 |
|
112 | |||
113 | private: |
|
113 | private: | |
114 | void updateDerivativeData(); |
|
114 | void updateDerivativeData(); | |
115 |
|
115 | |||
116 | private: |
|
116 | private: | |
117 | Q_DISABLE_COPY(QPieSeries) |
|
117 | Q_DISABLE_COPY(QPieSeries) | |
118 |
|
118 | |||
119 | // TODO: use PIML |
|
119 | // TODO: use PIML | |
120 | friend class PiePresenter; |
|
120 | friend class PiePresenter; | |
121 | friend class PieSlice; |
|
121 | friend class PieSlice; | |
122 |
|
122 | |||
123 | QList<QPieSlice*> m_slices; |
|
123 | QList<QPieSlice*> m_slices; | |
124 | qreal m_sizeFactor; |
|
124 | qreal m_sizeFactor; | |
125 | PiePosition m_position; |
|
125 | PiePosition m_position; | |
126 | qreal m_total; |
|
126 | qreal m_total; | |
127 | qreal m_pieStartAngle; |
|
127 | qreal m_pieStartAngle; | |
128 | qreal m_pieAngleSpan; |
|
128 | qreal m_pieAngleSpan; | |
129 | }; |
|
129 | }; | |
130 |
|
130 | |||
131 | QTCOMMERCIALCHART_END_NAMESPACE |
|
131 | QTCOMMERCIALCHART_END_NAMESPACE | |
132 |
|
132 | |||
133 | #endif // PIESERIES_H |
|
133 | #endif // PIESERIES_H |
@@ -1,285 +1,285 | |||||
1 | #include "qchart.h" |
|
1 | #include "qchart.h" | |
2 | #include "qchartaxis.h" |
|
2 | #include "qchartaxis.h" | |
3 | #include "chartpresenter_p.h" |
|
3 | #include "chartpresenter_p.h" | |
4 | #include "chartdataset_p.h" |
|
4 | #include "chartdataset_p.h" | |
5 | #include <QGraphicsScene> |
|
5 | #include <QGraphicsScene> | |
6 | #include <QGraphicsSceneResizeEvent> |
|
6 | #include <QGraphicsSceneResizeEvent> | |
7 | #include <QDebug> |
|
7 | #include <QDebug> | |
8 |
|
8 | |||
9 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
9 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
10 |
|
10 | |||
11 | /*! |
|
11 | /*! | |
12 | \enum QChart::ChartTheme |
|
12 | \enum QChart::ChartTheme | |
13 |
|
13 | |||
14 | This enum describes the theme used by the chart. |
|
14 | This enum describes the theme used by the chart. | |
15 |
|
15 | |||
16 | \value ChartThemeDefault |
|
16 | \value ChartThemeDefault | |
17 | \value ChartThemeVanilla |
|
17 | \value ChartThemeVanilla | |
18 | \value ChartThemeIcy |
|
18 | \value ChartThemeIcy | |
19 | \value ChartThemeGrayscale |
|
19 | \value ChartThemeGrayscale | |
20 | \value ChartThemeScientific |
|
20 | \value ChartThemeScientific | |
21 | */ |
|
21 | */ | |
22 |
|
22 | |||
23 | /*! |
|
23 | /*! | |
24 | \enum QChart::AnimationOption |
|
24 | \enum QChart::AnimationOption | |
25 |
|
25 | |||
26 | For enabling/disabling animations. Defaults to NoAnimation. |
|
26 | For enabling/disabling animations. Defaults to NoAnimation. | |
27 |
|
27 | |||
28 | \value NoAnimation |
|
28 | \value NoAnimation | |
29 | \value GridAxisAnimations |
|
29 | \value GridAxisAnimations | |
30 | \value SeriesAnimations |
|
30 | \value SeriesAnimations | |
31 | \value AllAnimations |
|
31 | \value AllAnimations | |
32 | */ |
|
32 | */ | |
33 |
|
33 | |||
34 | /*! |
|
34 | /*! | |
35 | \class QChart |
|
35 | \class QChart | |
36 | \brief QtCommercial chart API. |
|
36 | \brief QtCommercial chart API. | |
37 |
|
37 | |||
38 | QChart is a QGraphicsWidget that you can show in a QGraphicsScene. It manages the graphical |
|
38 | QChart is a QGraphicsWidget that you can show in a QGraphicsScene. It manages the graphical | |
39 | representation of different types of QChartSeries and other chart related objects like |
|
39 | representation of different types of QChartSeries and other chart related objects like | |
40 | QChartAxis and QChartLegend. If you simply want to show a chart in a layout, you can use the |
|
40 | QChartAxis and QChartLegend. If you simply want to show a chart in a layout, you can use the | |
41 | convenience class QChartView instead of QChart. |
|
41 | convenience class QChartView instead of QChart. | |
42 | \sa QChartView |
|
42 | \sa QChartView | |
43 | */ |
|
43 | */ | |
44 |
|
44 | |||
45 | /*! |
|
45 | /*! | |
46 | Constructs a chart object which is a child of a\a parent. Parameter \a wFlags is passed to the QGraphicsWidget constructor. |
|
46 | Constructs a chart object which is a child of a\a parent. Parameter \a wFlags is passed to the QGraphicsWidget constructor. | |
47 | */ |
|
47 | */ | |
48 | QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) : QGraphicsWidget(parent,wFlags), |
|
48 | QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) : QGraphicsWidget(parent,wFlags), | |
49 | m_backgroundItem(0), |
|
49 | m_backgroundItem(0), | |
50 | m_titleItem(0), |
|
50 | m_titleItem(0), | |
51 | m_dataset(new ChartDataSet(this)), |
|
51 | m_dataset(new ChartDataSet(this)), | |
52 | m_presenter(new ChartPresenter(this,m_dataset)) |
|
52 | m_presenter(new ChartPresenter(this,m_dataset)) | |
53 | { |
|
53 | { | |
54 | } |
|
54 | } | |
55 |
|
55 | |||
56 | /*! |
|
56 | /*! | |
57 | Destroys the object and it's children, like QChartSeries and QChartAxis object added to it. |
|
57 | Destroys the object and it's children, like QChartSeries and QChartAxis object added to it. | |
58 | */ |
|
58 | */ | |
59 | QChart::~QChart() |
|
59 | QChart::~QChart() | |
60 | { |
|
60 | { | |
61 | } |
|
61 | } | |
62 |
|
62 | |||
63 | /*! |
|
63 | /*! | |
64 | Adds the \a series and optional \a axisY onto the chart and takes the ownership of the objects. |
|
64 | Adds the \a series and optional \a axisY onto the chart and takes the ownership of the objects. | |
65 | If auto scaling is enabled, re-scales the axes the series is bound to (both the x axis and |
|
65 | If auto scaling is enabled, re-scales the axes the series is bound to (both the x axis and | |
66 | the y axis). |
|
66 | the y axis). | |
67 | */ |
|
67 | */ | |
68 |
void QChart::addSeries(Q |
|
68 | void QChart::addSeries(QSeries* series, QChartAxis* axisY) | |
69 | { |
|
69 | { | |
70 | m_dataset->addSeries(series, axisY); |
|
70 | m_dataset->addSeries(series, axisY); | |
71 | } |
|
71 | } | |
72 |
|
72 | |||
73 | /*! |
|
73 | /*! | |
74 | Removes the \a series specified in a perameter from the QChartView. |
|
74 | Removes the \a series specified in a perameter from the QChartView. | |
75 | It releses its ownership of the specified QChartSeries object. |
|
75 | It releses its ownership of the specified QChartSeries object. | |
76 | It does not delete the pointed QChartSeries data object |
|
76 | It does not delete the pointed QChartSeries data object | |
77 | \sa addSeries(), removeAllSeries() |
|
77 | \sa addSeries(), removeAllSeries() | |
78 | */ |
|
78 | */ | |
79 |
void QChart::removeSeries(Q |
|
79 | void QChart::removeSeries(QSeries* series) | |
80 | { |
|
80 | { | |
81 | m_dataset->removeSeries(series); |
|
81 | m_dataset->removeSeries(series); | |
82 | } |
|
82 | } | |
83 |
|
83 | |||
84 | /*! |
|
84 | /*! | |
85 | Removes all the QChartSeries that have been added to the QChartView |
|
85 | Removes all the QChartSeries that have been added to the QChartView | |
86 | It also deletes the pointed QChartSeries data objects |
|
86 | It also deletes the pointed QChartSeries data objects | |
87 | \sa addSeries(), removeSeries() |
|
87 | \sa addSeries(), removeSeries() | |
88 | */ |
|
88 | */ | |
89 | void QChart::removeAllSeries() |
|
89 | void QChart::removeAllSeries() | |
90 | { |
|
90 | { | |
91 | m_dataset->removeAllSeries(); |
|
91 | m_dataset->removeAllSeries(); | |
92 | } |
|
92 | } | |
93 |
|
93 | |||
94 | /*! |
|
94 | /*! | |
95 | Sets the \a brush that is used for painting the background of the chart area. |
|
95 | Sets the \a brush that is used for painting the background of the chart area. | |
96 | */ |
|
96 | */ | |
97 | void QChart::setChartBackgroundBrush(const QBrush& brush) |
|
97 | void QChart::setChartBackgroundBrush(const QBrush& brush) | |
98 | { |
|
98 | { | |
99 | createChartBackgroundItem(); |
|
99 | createChartBackgroundItem(); | |
100 | m_backgroundItem->setBrush(brush); |
|
100 | m_backgroundItem->setBrush(brush); | |
101 | m_backgroundItem->update(); |
|
101 | m_backgroundItem->update(); | |
102 | } |
|
102 | } | |
103 |
|
103 | |||
104 | /*! |
|
104 | /*! | |
105 | Sets the \a pen that is used for painting the background of the chart area. |
|
105 | Sets the \a pen that is used for painting the background of the chart area. | |
106 | */ |
|
106 | */ | |
107 | void QChart::setChartBackgroundPen(const QPen& pen) |
|
107 | void QChart::setChartBackgroundPen(const QPen& pen) | |
108 | { |
|
108 | { | |
109 | createChartBackgroundItem(); |
|
109 | createChartBackgroundItem(); | |
110 | m_backgroundItem->setPen(pen); |
|
110 | m_backgroundItem->setPen(pen); | |
111 | m_backgroundItem->update(); |
|
111 | m_backgroundItem->update(); | |
112 | } |
|
112 | } | |
113 |
|
113 | |||
114 | /*! |
|
114 | /*! | |
115 | Sets the chart \a title. The description text that is rendered above the chart. |
|
115 | Sets the chart \a title. The description text that is rendered above the chart. | |
116 | */ |
|
116 | */ | |
117 | void QChart::setChartTitle(const QString& title) |
|
117 | void QChart::setChartTitle(const QString& title) | |
118 | { |
|
118 | { | |
119 | createChartTitleItem(); |
|
119 | createChartTitleItem(); | |
120 | m_titleItem->setPlainText(title); |
|
120 | m_titleItem->setPlainText(title); | |
121 | } |
|
121 | } | |
122 |
|
122 | |||
123 | /*! |
|
123 | /*! | |
124 | Sets the \a font that is used for rendering the description text that is rendered above the chart. |
|
124 | Sets the \a font that is used for rendering the description text that is rendered above the chart. | |
125 | */ |
|
125 | */ | |
126 | void QChart::setChartTitleFont(const QFont& font) |
|
126 | void QChart::setChartTitleFont(const QFont& font) | |
127 | { |
|
127 | { | |
128 | createChartTitleItem(); |
|
128 | createChartTitleItem(); | |
129 | m_titleItem->setFont(font); |
|
129 | m_titleItem->setFont(font); | |
130 | } |
|
130 | } | |
131 |
|
131 | |||
132 | void QChart::createChartBackgroundItem() |
|
132 | void QChart::createChartBackgroundItem() | |
133 | { |
|
133 | { | |
134 | if(!m_backgroundItem) { |
|
134 | if(!m_backgroundItem) { | |
135 | m_backgroundItem = new QGraphicsRectItem(this); |
|
135 | m_backgroundItem = new QGraphicsRectItem(this); | |
136 | m_backgroundItem->setPen(Qt::NoPen); |
|
136 | m_backgroundItem->setPen(Qt::NoPen); | |
137 | m_backgroundItem->setZValue(ChartPresenter::BackgroundZValue); |
|
137 | m_backgroundItem->setZValue(ChartPresenter::BackgroundZValue); | |
138 | } |
|
138 | } | |
139 | } |
|
139 | } | |
140 |
|
140 | |||
141 | void QChart::createChartTitleItem() |
|
141 | void QChart::createChartTitleItem() | |
142 | { |
|
142 | { | |
143 | if(!m_titleItem) { |
|
143 | if(!m_titleItem) { | |
144 | m_titleItem = new QGraphicsTextItem(this); |
|
144 | m_titleItem = new QGraphicsTextItem(this); | |
145 | m_titleItem->setZValue(ChartPresenter::BackgroundZValue); |
|
145 | m_titleItem->setZValue(ChartPresenter::BackgroundZValue); | |
146 | } |
|
146 | } | |
147 | } |
|
147 | } | |
148 |
|
148 | |||
149 | /*! |
|
149 | /*! | |
150 | Returns the chart margin, which is the distance between the widget edge and the part of the chart where the actual data can be displayed. |
|
150 | Returns the chart margin, which is the distance between the widget edge and the part of the chart where the actual data can be displayed. | |
151 | \sa setMargin() |
|
151 | \sa setMargin() | |
152 | */ |
|
152 | */ | |
153 | int QChart::margin() const |
|
153 | int QChart::margin() const | |
154 | { |
|
154 | { | |
155 | return m_presenter->margin(); |
|
155 | return m_presenter->margin(); | |
156 | } |
|
156 | } | |
157 |
|
157 | |||
158 | /*! |
|
158 | /*! | |
159 | Sets the chart \a margin, which is the distance between the widget edge and the part of the chart where the actual data can be displayed. |
|
159 | Sets the chart \a margin, which is the distance between the widget edge and the part of the chart where the actual data can be displayed. | |
160 | \sa margin() |
|
160 | \sa margin() | |
161 | */ |
|
161 | */ | |
162 | void QChart::setMargin(int margin) |
|
162 | void QChart::setMargin(int margin) | |
163 | { |
|
163 | { | |
164 | m_presenter->setMargin(margin); |
|
164 | m_presenter->setMargin(margin); | |
165 | } |
|
165 | } | |
166 |
|
166 | |||
167 | /*! |
|
167 | /*! | |
168 | Sets the \a theme used by the chart for rendering the graphical representation of the data |
|
168 | Sets the \a theme used by the chart for rendering the graphical representation of the data | |
169 | \sa ChartTheme, chartTheme() |
|
169 | \sa ChartTheme, chartTheme() | |
170 | */ |
|
170 | */ | |
171 | void QChart::setChartTheme(QChart::ChartTheme theme) |
|
171 | void QChart::setChartTheme(QChart::ChartTheme theme) | |
172 | { |
|
172 | { | |
173 | m_presenter->setChartTheme(theme); |
|
173 | m_presenter->setChartTheme(theme); | |
174 | } |
|
174 | } | |
175 |
|
175 | |||
176 | /*! |
|
176 | /*! | |
177 | Returns the theme enum used by the chart. |
|
177 | Returns the theme enum used by the chart. | |
178 | \sa ChartTheme, setChartTheme() |
|
178 | \sa ChartTheme, setChartTheme() | |
179 | */ |
|
179 | */ | |
180 | QChart::ChartTheme QChart::chartTheme() const |
|
180 | QChart::ChartTheme QChart::chartTheme() const | |
181 | { |
|
181 | { | |
182 | return m_presenter->chartTheme(); |
|
182 | return m_presenter->chartTheme(); | |
183 | } |
|
183 | } | |
184 |
|
184 | |||
185 | /*! |
|
185 | /*! | |
186 | Zooms in the view by a factor of 2 |
|
186 | Zooms in the view by a factor of 2 | |
187 | */ |
|
187 | */ | |
188 | void QChart::zoomIn() |
|
188 | void QChart::zoomIn() | |
189 | { |
|
189 | { | |
190 | if (!m_dataset->nextDomain()) { |
|
190 | if (!m_dataset->nextDomain()) { | |
191 | QRectF rect = m_presenter->geometry(); |
|
191 | QRectF rect = m_presenter->geometry(); | |
192 | rect.setWidth(rect.width()/2); |
|
192 | rect.setWidth(rect.width()/2); | |
193 | rect.setHeight(rect.height()/2); |
|
193 | rect.setHeight(rect.height()/2); | |
194 | rect.moveCenter(m_presenter->geometry().center()); |
|
194 | rect.moveCenter(m_presenter->geometry().center()); | |
195 | zoomIn(rect); |
|
195 | zoomIn(rect); | |
196 | } |
|
196 | } | |
197 | } |
|
197 | } | |
198 |
|
198 | |||
199 | /*! |
|
199 | /*! | |
200 | Zooms in the view to a maximum level at which \a rect is still fully visible. |
|
200 | Zooms in the view to a maximum level at which \a rect is still fully visible. | |
201 | */ |
|
201 | */ | |
202 | void QChart::zoomIn(const QRectF& rect) |
|
202 | void QChart::zoomIn(const QRectF& rect) | |
203 | { |
|
203 | { | |
204 | if(!rect.isValid()) return; |
|
204 | if(!rect.isValid()) return; | |
205 | QRectF r = rect.normalized(); |
|
205 | QRectF r = rect.normalized(); | |
206 | int margin = m_presenter->margin(); |
|
206 | int margin = m_presenter->margin(); | |
207 | r.translate(-margin, -margin); |
|
207 | r.translate(-margin, -margin); | |
208 | m_dataset->addDomain(r,m_presenter->geometry()); |
|
208 | m_dataset->addDomain(r,m_presenter->geometry()); | |
209 | } |
|
209 | } | |
210 |
|
210 | |||
211 | /*! |
|
211 | /*! | |
212 | Restores the view zoom level to the previous one. |
|
212 | Restores the view zoom level to the previous one. | |
213 | */ |
|
213 | */ | |
214 | void QChart::zoomOut() |
|
214 | void QChart::zoomOut() | |
215 | { |
|
215 | { | |
216 | m_dataset->previousDomain(); |
|
216 | m_dataset->previousDomain(); | |
217 | } |
|
217 | } | |
218 |
|
218 | |||
219 | /*! |
|
219 | /*! | |
220 | Resets to the default view. |
|
220 | Resets to the default view. | |
221 | */ |
|
221 | */ | |
222 | void QChart::zoomReset() |
|
222 | void QChart::zoomReset() | |
223 | { |
|
223 | { | |
224 | m_dataset->clearDomains(); |
|
224 | m_dataset->clearDomains(); | |
225 | } |
|
225 | } | |
226 |
|
226 | |||
227 | /*! |
|
227 | /*! | |
228 | Returns the pointer to the x axis object of the chart |
|
228 | Returns the pointer to the x axis object of the chart | |
229 | */ |
|
229 | */ | |
230 | QChartAxis* QChart::axisX() const |
|
230 | QChartAxis* QChart::axisX() const | |
231 | { |
|
231 | { | |
232 | return m_dataset->axisX(); |
|
232 | return m_dataset->axisX(); | |
233 | } |
|
233 | } | |
234 |
|
234 | |||
235 | /*! |
|
235 | /*! | |
236 | Returns the pointer to the y axis object of the chart |
|
236 | Returns the pointer to the y axis object of the chart | |
237 | */ |
|
237 | */ | |
238 | QChartAxis* QChart::axisY() const |
|
238 | QChartAxis* QChart::axisY() const | |
239 | { |
|
239 | { | |
240 | return m_dataset->axisY(); |
|
240 | return m_dataset->axisY(); | |
241 | } |
|
241 | } | |
242 |
|
242 | |||
243 | /*! |
|
243 | /*! | |
244 | Resizes and updates the chart area using the \a event data |
|
244 | Resizes and updates the chart area using the \a event data | |
245 | */ |
|
245 | */ | |
246 | void QChart::resizeEvent(QGraphicsSceneResizeEvent *event) |
|
246 | void QChart::resizeEvent(QGraphicsSceneResizeEvent *event) | |
247 | { |
|
247 | { | |
248 |
|
248 | |||
249 | m_rect = QRectF(QPoint(0,0),event->newSize()); |
|
249 | m_rect = QRectF(QPoint(0,0),event->newSize()); | |
250 | QRectF rect = m_rect.adjusted(margin(),margin(), -margin(), -margin()); |
|
250 | QRectF rect = m_rect.adjusted(margin(),margin(), -margin(), -margin()); | |
251 |
|
251 | |||
252 | // recalculate title position |
|
252 | // recalculate title position | |
253 | if (m_titleItem) { |
|
253 | if (m_titleItem) { | |
254 | QPointF center = m_rect.center() -m_titleItem->boundingRect().center(); |
|
254 | QPointF center = m_rect.center() -m_titleItem->boundingRect().center(); | |
255 | m_titleItem->setPos(center.x(),m_rect.top()/2 + margin()/2); |
|
255 | m_titleItem->setPos(center.x(),m_rect.top()/2 + margin()/2); | |
256 | } |
|
256 | } | |
257 |
|
257 | |||
258 | //recalculate background gradient |
|
258 | //recalculate background gradient | |
259 | if (m_backgroundItem) { |
|
259 | if (m_backgroundItem) { | |
260 | m_backgroundItem->setRect(rect); |
|
260 | m_backgroundItem->setRect(rect); | |
261 | } |
|
261 | } | |
262 |
|
262 | |||
263 | QGraphicsWidget::resizeEvent(event); |
|
263 | QGraphicsWidget::resizeEvent(event); | |
264 | update(); |
|
264 | update(); | |
265 | } |
|
265 | } | |
266 |
|
266 | |||
267 | /*! |
|
267 | /*! | |
268 | Sets animation \a options for the chart |
|
268 | Sets animation \a options for the chart | |
269 | */ |
|
269 | */ | |
270 | void QChart::setAnimationOptions(AnimationOptions options) |
|
270 | void QChart::setAnimationOptions(AnimationOptions options) | |
271 | { |
|
271 | { | |
272 | m_presenter->setAnimationOptions(options); |
|
272 | m_presenter->setAnimationOptions(options); | |
273 | } |
|
273 | } | |
274 |
|
274 | |||
275 | /*! |
|
275 | /*! | |
276 | Returns animation options for the chart |
|
276 | Returns animation options for the chart | |
277 | */ |
|
277 | */ | |
278 | QChart::AnimationOptions QChart::animationOptions() const |
|
278 | QChart::AnimationOptions QChart::animationOptions() const | |
279 | { |
|
279 | { | |
280 | return m_presenter->animationOptions(); |
|
280 | return m_presenter->animationOptions(); | |
281 | } |
|
281 | } | |
282 |
|
282 | |||
283 | #include "moc_qchart.cpp" |
|
283 | #include "moc_qchart.cpp" | |
284 |
|
284 | |||
285 | QTCOMMERCIALCHART_END_NAMESPACE |
|
285 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,95 +1,95 | |||||
1 | #ifndef QCHART_H |
|
1 | #ifndef QCHART_H | |
2 | #define QCHART_H |
|
2 | #define QCHART_H | |
3 |
|
3 | |||
4 | #include <qchartglobal.h> |
|
4 | #include <qchartglobal.h> | |
5 |
#include <q |
|
5 | #include <qseries.h> | |
6 | #include <QGraphicsWidget> |
|
6 | #include <QGraphicsWidget> | |
7 | #include <QLinearGradient> |
|
7 | #include <QLinearGradient> | |
8 | #include <QFont> |
|
8 | #include <QFont> | |
9 |
|
9 | |||
10 | class QGraphicsSceneResizeEvent; |
|
10 | class QGraphicsSceneResizeEvent; | |
11 |
|
11 | |||
12 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
12 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
13 |
|
13 | |||
14 | class AxisItem; |
|
14 | class AxisItem; | |
15 |
class Q |
|
15 | class QSeries; | |
16 | class PlotDomain; |
|
16 | class PlotDomain; | |
17 | class BarPresenter; |
|
17 | class BarPresenter; | |
18 | class QChartAxis; |
|
18 | class QChartAxis; | |
19 | class ChartTheme; |
|
19 | class ChartTheme; | |
20 | class ChartItem; |
|
20 | class ChartItem; | |
21 | class ChartDataSet; |
|
21 | class ChartDataSet; | |
22 | class ChartPresenter; |
|
22 | class ChartPresenter; | |
23 |
|
23 | |||
24 | class QTCOMMERCIALCHART_EXPORT QChart : public QGraphicsWidget |
|
24 | class QTCOMMERCIALCHART_EXPORT QChart : public QGraphicsWidget | |
25 | { |
|
25 | { | |
26 | Q_OBJECT |
|
26 | Q_OBJECT | |
27 | public: |
|
27 | public: | |
28 | enum ChartTheme { |
|
28 | enum ChartTheme { | |
29 | ChartThemeDefault, |
|
29 | ChartThemeDefault, | |
30 | ChartThemeVanilla, |
|
30 | ChartThemeVanilla, | |
31 | ChartThemeIcy, |
|
31 | ChartThemeIcy, | |
32 | ChartThemeGrayscale, |
|
32 | ChartThemeGrayscale, | |
33 | ChartThemeScientific |
|
33 | ChartThemeScientific | |
34 | //ChartThemeUnnamed1 |
|
34 | //ChartThemeUnnamed1 | |
35 | /*! The default theme follows the GUI style of the Operating System */ |
|
35 | /*! The default theme follows the GUI style of the Operating System */ | |
36 | }; |
|
36 | }; | |
37 |
|
37 | |||
38 | enum AnimationOption { |
|
38 | enum AnimationOption { | |
39 | NoAnimation = 0x0, |
|
39 | NoAnimation = 0x0, | |
40 | GridAxisAnimations = 0x1, |
|
40 | GridAxisAnimations = 0x1, | |
41 | SeriesAnimations =0x2, |
|
41 | SeriesAnimations =0x2, | |
42 | AllAnimations = 0x3 |
|
42 | AllAnimations = 0x3 | |
43 | }; |
|
43 | }; | |
44 | Q_DECLARE_FLAGS(AnimationOptions, AnimationOption) |
|
44 | Q_DECLARE_FLAGS(AnimationOptions, AnimationOption) | |
45 |
|
45 | |||
46 | public: |
|
46 | public: | |
47 | QChart(QGraphicsItem *parent = 0, Qt::WindowFlags wFlags = 0); |
|
47 | QChart(QGraphicsItem *parent = 0, Qt::WindowFlags wFlags = 0); | |
48 | ~QChart(); |
|
48 | ~QChart(); | |
49 |
|
49 | |||
50 |
void addSeries(Q |
|
50 | void addSeries(QSeries* series, QChartAxis* axisY = 0); | |
51 |
void removeSeries(Q |
|
51 | void removeSeries(QSeries* series); //returns ownership , deletes axis if no series attached | |
52 | void removeAllSeries(); // deletes series and axis |
|
52 | void removeAllSeries(); // deletes series and axis | |
53 |
|
53 | |||
54 | void setMargin(int margin); |
|
54 | void setMargin(int margin); | |
55 | int margin() const; |
|
55 | int margin() const; | |
56 | void setChartTheme(QChart::ChartTheme theme); |
|
56 | void setChartTheme(QChart::ChartTheme theme); | |
57 | QChart::ChartTheme chartTheme() const; |
|
57 | QChart::ChartTheme chartTheme() const; | |
58 |
|
58 | |||
59 | void setChartTitle(const QString& title); |
|
59 | void setChartTitle(const QString& title); | |
60 | void setChartTitleFont(const QFont& font); |
|
60 | void setChartTitleFont(const QFont& font); | |
61 | void setChartBackgroundBrush(const QBrush& brush); |
|
61 | void setChartBackgroundBrush(const QBrush& brush); | |
62 | void setChartBackgroundPen(const QPen& pen); |
|
62 | void setChartBackgroundPen(const QPen& pen); | |
63 |
|
63 | |||
64 | void setAnimationOptions(AnimationOptions options); |
|
64 | void setAnimationOptions(AnimationOptions options); | |
65 | AnimationOptions animationOptions() const; |
|
65 | AnimationOptions animationOptions() const; | |
66 |
|
66 | |||
67 | void zoomIn(); |
|
67 | void zoomIn(); | |
68 | void zoomIn(const QRectF& rect); |
|
68 | void zoomIn(const QRectF& rect); | |
69 | void zoomOut(); |
|
69 | void zoomOut(); | |
70 | void zoomReset(); |
|
70 | void zoomReset(); | |
71 |
|
71 | |||
72 | QChartAxis* axisX() const; |
|
72 | QChartAxis* axisX() const; | |
73 | QChartAxis* axisY() const; |
|
73 | QChartAxis* axisY() const; | |
74 |
|
74 | |||
75 | protected: |
|
75 | protected: | |
76 | void resizeEvent(QGraphicsSceneResizeEvent *event); |
|
76 | void resizeEvent(QGraphicsSceneResizeEvent *event); | |
77 |
|
77 | |||
78 | private: |
|
78 | private: | |
79 | inline void createChartBackgroundItem(); |
|
79 | inline void createChartBackgroundItem(); | |
80 | inline void createChartTitleItem(); |
|
80 | inline void createChartTitleItem(); | |
81 |
|
81 | |||
82 | private: |
|
82 | private: | |
83 | Q_DISABLE_COPY(QChart) |
|
83 | Q_DISABLE_COPY(QChart) | |
84 | QGraphicsRectItem* m_backgroundItem; |
|
84 | QGraphicsRectItem* m_backgroundItem; | |
85 | QGraphicsTextItem* m_titleItem; |
|
85 | QGraphicsTextItem* m_titleItem; | |
86 | QRectF m_rect; |
|
86 | QRectF m_rect; | |
87 | ChartDataSet *m_dataset; |
|
87 | ChartDataSet *m_dataset; | |
88 | ChartPresenter *m_presenter; |
|
88 | ChartPresenter *m_presenter; | |
89 | }; |
|
89 | }; | |
90 |
|
90 | |||
91 | QTCOMMERCIALCHART_END_NAMESPACE |
|
91 | QTCOMMERCIALCHART_END_NAMESPACE | |
92 |
|
92 | |||
93 | Q_DECLARE_OPERATORS_FOR_FLAGS(QTCOMMERCIALCHART_NAMESPACE::QChart::AnimationOptions) |
|
93 | Q_DECLARE_OPERATORS_FOR_FLAGS(QTCOMMERCIALCHART_NAMESPACE::QChart::AnimationOptions) | |
94 |
|
94 | |||
95 | #endif |
|
95 | #endif |
@@ -1,351 +1,351 | |||||
1 | #include "qchartview.h" |
|
1 | #include "qchartview.h" | |
2 | #include "qchart.h" |
|
2 | #include "qchart.h" | |
3 | #include "qchartaxis.h" |
|
3 | #include "qchartaxis.h" | |
4 | #include <QGraphicsView> |
|
4 | #include <QGraphicsView> | |
5 | #include <QGraphicsScene> |
|
5 | #include <QGraphicsScene> | |
6 | #include <QRubberBand> |
|
6 | #include <QRubberBand> | |
7 | #include <QResizeEvent> |
|
7 | #include <QResizeEvent> | |
8 | #include <QDebug> |
|
8 | #include <QDebug> | |
9 |
|
9 | |||
10 | /*! |
|
10 | /*! | |
11 | \enum QChartView::RubberBandPolicy |
|
11 | \enum QChartView::RubberBandPolicy | |
12 |
|
12 | |||
13 | This enum describes the different types of rubber bands that can be used for zoom rect selection |
|
13 | This enum describes the different types of rubber bands that can be used for zoom rect selection | |
14 |
|
14 | |||
15 | \value NoRubberBand |
|
15 | \value NoRubberBand | |
16 | \value VerticalRubberBand |
|
16 | \value VerticalRubberBand | |
17 | \value HorizonalRubberBand |
|
17 | \value HorizonalRubberBand | |
18 | \value RectangleRubberBand |
|
18 | \value RectangleRubberBand | |
19 | */ |
|
19 | */ | |
20 |
|
20 | |||
21 | /*! |
|
21 | /*! | |
22 | \class QChartView |
|
22 | \class QChartView | |
23 | \brief Standalone charting widget. |
|
23 | \brief Standalone charting widget. | |
24 |
|
24 | |||
25 | QChartView is a standalone widget that can display charts. It does not require separate |
|
25 | QChartView is a standalone widget that can display charts. It does not require separate | |
26 | QGraphicsScene to work. It manages the graphical representation of different types of |
|
26 | QGraphicsScene to work. It manages the graphical representation of different types of | |
27 | QChartSeries and other chart related objects like QChartAxis and QChartLegend. If you want to |
|
27 | QChartSeries and other chart related objects like QChartAxis and QChartLegend. If you want to | |
28 | display a chart in your existing QGraphicsScene, you can use the QChart class instead. |
|
28 | display a chart in your existing QGraphicsScene, you can use the QChart class instead. | |
29 |
|
29 | |||
30 | \sa QChart |
|
30 | \sa QChart | |
31 | */ |
|
31 | */ | |
32 |
|
32 | |||
33 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
33 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
34 |
|
34 | |||
35 | /*! |
|
35 | /*! | |
36 | Constructs a chartView object which is a child of a\a parent. |
|
36 | Constructs a chartView object which is a child of a\a parent. | |
37 | */ |
|
37 | */ | |
38 | QChartView::QChartView(QWidget *parent) : |
|
38 | QChartView::QChartView(QWidget *parent) : | |
39 | QGraphicsView(parent), |
|
39 | QGraphicsView(parent), | |
40 | m_scene(new QGraphicsScene(this)), |
|
40 | m_scene(new QGraphicsScene(this)), | |
41 | m_chart(new QChart()), |
|
41 | m_chart(new QChart()), | |
42 | m_rubberBand(0), |
|
42 | m_rubberBand(0), | |
43 | m_verticalRubberBand(false), |
|
43 | m_verticalRubberBand(false), | |
44 | m_horizonalRubberBand(false) |
|
44 | m_horizonalRubberBand(false) | |
45 | { |
|
45 | { | |
46 | setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); |
|
46 | setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); | |
47 | setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); |
|
47 | setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); | |
48 | setScene(m_scene); |
|
48 | setScene(m_scene); | |
49 | m_chart->setMargin(50); |
|
49 | m_chart->setMargin(50); | |
50 | m_scene->addItem(m_chart); |
|
50 | m_scene->addItem(m_chart); | |
51 | setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); |
|
51 | setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); | |
52 | } |
|
52 | } | |
53 |
|
53 | |||
54 |
|
54 | |||
55 | /*! |
|
55 | /*! | |
56 | Destroys the object and it's children, like QChartSeries and QChartAxis object added to it. |
|
56 | Destroys the object and it's children, like QChartSeries and QChartAxis object added to it. | |
57 | */ |
|
57 | */ | |
58 | QChartView::~QChartView() |
|
58 | QChartView::~QChartView() | |
59 | { |
|
59 | { | |
60 | } |
|
60 | } | |
61 |
|
61 | |||
62 | /*! |
|
62 | /*! | |
63 | Resizes and updates the chart area using the \a event data |
|
63 | Resizes and updates the chart area using the \a event data | |
64 | */ |
|
64 | */ | |
65 | void QChartView::resizeEvent(QResizeEvent *event) |
|
65 | void QChartView::resizeEvent(QResizeEvent *event) | |
66 | { |
|
66 | { | |
67 | m_scene->setSceneRect(0,0,size().width(),size().height()); |
|
67 | m_scene->setSceneRect(0,0,size().width(),size().height()); | |
68 | m_chart->resize(size()); |
|
68 | m_chart->resize(size()); | |
69 | QWidget::resizeEvent(event); |
|
69 | QWidget::resizeEvent(event); | |
70 | } |
|
70 | } | |
71 |
|
71 | |||
72 | /*! |
|
72 | /*! | |
73 | Adds the \a series and optional \a axisY onto the chart and takes the ownership of the objects. |
|
73 | Adds the \a series and optional \a axisY onto the chart and takes the ownership of the objects. | |
74 | If auto scaling is enabled, re-scales the axes the series is bound to (both the x axis and |
|
74 | If auto scaling is enabled, re-scales the axes the series is bound to (both the x axis and | |
75 | the y axis). |
|
75 | the y axis). | |
76 | \sa removeSeries(), removeAllSeries() |
|
76 | \sa removeSeries(), removeAllSeries() | |
77 | */ |
|
77 | */ | |
78 |
void QChartView::addSeries(Q |
|
78 | void QChartView::addSeries(QSeries* series,QChartAxis *axisY) | |
79 | { |
|
79 | { | |
80 | m_chart->addSeries(series,axisY); |
|
80 | m_chart->addSeries(series,axisY); | |
81 | } |
|
81 | } | |
82 |
|
82 | |||
83 | /*! |
|
83 | /*! | |
84 | Removes the \a series specified in a perameter from the QChartView. |
|
84 | Removes the \a series specified in a perameter from the QChartView. | |
85 | It releses its ownership of the specified QChartSeries object. |
|
85 | It releses its ownership of the specified QChartSeries object. | |
86 | It does not delete the pointed QChartSeries data object |
|
86 | It does not delete the pointed QChartSeries data object | |
87 | \sa addSeries(), removeAllSeries() |
|
87 | \sa addSeries(), removeAllSeries() | |
88 | */ |
|
88 | */ | |
89 |
void QChartView::removeSeries(Q |
|
89 | void QChartView::removeSeries(QSeries* series) | |
90 | { |
|
90 | { | |
91 | m_chart->removeSeries(series); |
|
91 | m_chart->removeSeries(series); | |
92 | } |
|
92 | } | |
93 |
|
93 | |||
94 | /*! |
|
94 | /*! | |
95 | Removes all the QChartSeries that have been added to the QChartView |
|
95 | Removes all the QChartSeries that have been added to the QChartView | |
96 | It also deletes the pointed QChartSeries data objects |
|
96 | It also deletes the pointed QChartSeries data objects | |
97 | \sa addSeries(), removeSeries() |
|
97 | \sa addSeries(), removeSeries() | |
98 | */ |
|
98 | */ | |
99 | void QChartView::removeAllSeries() |
|
99 | void QChartView::removeAllSeries() | |
100 | { |
|
100 | { | |
101 | m_chart->removeAllSeries(); |
|
101 | m_chart->removeAllSeries(); | |
102 | } |
|
102 | } | |
103 |
|
103 | |||
104 | /*! |
|
104 | /*! | |
105 | Zooms in the view by a factor of 2 |
|
105 | Zooms in the view by a factor of 2 | |
106 | */ |
|
106 | */ | |
107 | void QChartView::zoomIn() |
|
107 | void QChartView::zoomIn() | |
108 | { |
|
108 | { | |
109 | m_chart->zoomIn(); |
|
109 | m_chart->zoomIn(); | |
110 | } |
|
110 | } | |
111 |
|
111 | |||
112 | /*! |
|
112 | /*! | |
113 | Zooms in the view to a maximum level at which \a rect is still fully visible. |
|
113 | Zooms in the view to a maximum level at which \a rect is still fully visible. | |
114 | */ |
|
114 | */ | |
115 | void QChartView::zoomIn(const QRect& rect) |
|
115 | void QChartView::zoomIn(const QRect& rect) | |
116 | { |
|
116 | { | |
117 | m_chart->zoomIn(rect); |
|
117 | m_chart->zoomIn(rect); | |
118 | } |
|
118 | } | |
119 |
|
119 | |||
120 | /*! |
|
120 | /*! | |
121 | Restores the view zoom level to the previous one. |
|
121 | Restores the view zoom level to the previous one. | |
122 | */ |
|
122 | */ | |
123 | void QChartView::zoomOut() |
|
123 | void QChartView::zoomOut() | |
124 | { |
|
124 | { | |
125 | m_chart->zoomOut(); |
|
125 | m_chart->zoomOut(); | |
126 | } |
|
126 | } | |
127 |
|
127 | |||
128 | /*! |
|
128 | /*! | |
129 | Returns the chart margin, which is the distance between the widget edge and the part of the chart where the actual data can be displayed. |
|
129 | Returns the chart margin, which is the distance between the widget edge and the part of the chart where the actual data can be displayed. | |
130 | */ |
|
130 | */ | |
131 | int QChartView::margin() const |
|
131 | int QChartView::margin() const | |
132 | { |
|
132 | { | |
133 | return m_chart->margin(); |
|
133 | return m_chart->margin(); | |
134 | } |
|
134 | } | |
135 |
|
135 | |||
136 | /*! |
|
136 | /*! | |
137 | Sets the chart \a title. A description text that is rendered above the chart. |
|
137 | Sets the chart \a title. A description text that is rendered above the chart. | |
138 | */ |
|
138 | */ | |
139 | void QChartView::setChartTitle(const QString& title) |
|
139 | void QChartView::setChartTitle(const QString& title) | |
140 | { |
|
140 | { | |
141 | m_chart->setChartTitle(title); |
|
141 | m_chart->setChartTitle(title); | |
142 | } |
|
142 | } | |
143 |
|
143 | |||
144 | /*! |
|
144 | /*! | |
145 | Sets the \a font that is used for rendering the description text that is rendered above the chart. |
|
145 | Sets the \a font that is used for rendering the description text that is rendered above the chart. | |
146 | */ |
|
146 | */ | |
147 | void QChartView::setChartTitleFont(const QFont& font) |
|
147 | void QChartView::setChartTitleFont(const QFont& font) | |
148 | { |
|
148 | { | |
149 | m_chart->setChartTitleFont(font); |
|
149 | m_chart->setChartTitleFont(font); | |
150 | } |
|
150 | } | |
151 |
|
151 | |||
152 | /*! |
|
152 | /*! | |
153 | Sets the \a brush that is used for painting the background of the chart area of the QChartView widget. |
|
153 | Sets the \a brush that is used for painting the background of the chart area of the QChartView widget. | |
154 | */ |
|
154 | */ | |
155 | void QChartView::setChartBackgroundBrush(const QBrush& brush) |
|
155 | void QChartView::setChartBackgroundBrush(const QBrush& brush) | |
156 | { |
|
156 | { | |
157 | m_chart->setChartBackgroundBrush(brush); |
|
157 | m_chart->setChartBackgroundBrush(brush); | |
158 | } |
|
158 | } | |
159 |
|
159 | |||
160 | /*! |
|
160 | /*! | |
161 | Sets the \a pen that is used for painting the background of the chart area of the QChartView widget. |
|
161 | Sets the \a pen that is used for painting the background of the chart area of the QChartView widget. | |
162 | */ |
|
162 | */ | |
163 | void QChartView::setChartBackgroundPen(const QPen& pen) |
|
163 | void QChartView::setChartBackgroundPen(const QPen& pen) | |
164 | { |
|
164 | { | |
165 | m_chart->setChartBackgroundPen(pen); |
|
165 | m_chart->setChartBackgroundPen(pen); | |
166 | } |
|
166 | } | |
167 |
|
167 | |||
168 | /*! |
|
168 | /*! | |
169 | Sets the RubberBandPlicy to \a policy. Selected policy determines the way zooming is performed. |
|
169 | Sets the RubberBandPlicy to \a policy. Selected policy determines the way zooming is performed. | |
170 | */ |
|
170 | */ | |
171 | void QChartView::setRubberBandPolicy(const RubberBandPolicy policy) |
|
171 | void QChartView::setRubberBandPolicy(const RubberBandPolicy policy) | |
172 | { |
|
172 | { | |
173 | switch(policy) { |
|
173 | switch(policy) { | |
174 | case VerticalRubberBand: |
|
174 | case VerticalRubberBand: | |
175 | m_verticalRubberBand = true; |
|
175 | m_verticalRubberBand = true; | |
176 | m_horizonalRubberBand = false; |
|
176 | m_horizonalRubberBand = false; | |
177 | break; |
|
177 | break; | |
178 | case HorizonalRubberBand: |
|
178 | case HorizonalRubberBand: | |
179 | m_verticalRubberBand = false; |
|
179 | m_verticalRubberBand = false; | |
180 | m_horizonalRubberBand = true; |
|
180 | m_horizonalRubberBand = true; | |
181 | break; |
|
181 | break; | |
182 | case RectangleRubberBand: |
|
182 | case RectangleRubberBand: | |
183 | m_verticalRubberBand = true; |
|
183 | m_verticalRubberBand = true; | |
184 | m_horizonalRubberBand = true; |
|
184 | m_horizonalRubberBand = true; | |
185 | break; |
|
185 | break; | |
186 | case NoRubberBand: |
|
186 | case NoRubberBand: | |
187 | default: |
|
187 | default: | |
188 | delete m_rubberBand; |
|
188 | delete m_rubberBand; | |
189 | m_rubberBand=0; |
|
189 | m_rubberBand=0; | |
190 | m_horizonalRubberBand = false; |
|
190 | m_horizonalRubberBand = false; | |
191 | m_verticalRubberBand = false; |
|
191 | m_verticalRubberBand = false; | |
192 | return; |
|
192 | return; | |
193 | } |
|
193 | } | |
194 | if(!m_rubberBand) { |
|
194 | if(!m_rubberBand) { | |
195 | m_rubberBand = new QRubberBand(QRubberBand::Rectangle, this); |
|
195 | m_rubberBand = new QRubberBand(QRubberBand::Rectangle, this); | |
196 | m_rubberBand->setEnabled(true); |
|
196 | m_rubberBand->setEnabled(true); | |
197 | } |
|
197 | } | |
198 | } |
|
198 | } | |
199 |
|
199 | |||
200 | /*! |
|
200 | /*! | |
201 | Returns the RubberBandPolicy that is currently being used by the widget. |
|
201 | Returns the RubberBandPolicy that is currently being used by the widget. | |
202 | */ |
|
202 | */ | |
203 | QChartView::RubberBandPolicy QChartView::rubberBandPolicy() const |
|
203 | QChartView::RubberBandPolicy QChartView::rubberBandPolicy() const | |
204 | { |
|
204 | { | |
205 | if(m_horizonalRubberBand && m_verticalRubberBand) return RectangleRubberBand; |
|
205 | if(m_horizonalRubberBand && m_verticalRubberBand) return RectangleRubberBand; | |
206 | if(m_horizonalRubberBand) return HorizonalRubberBand; |
|
206 | if(m_horizonalRubberBand) return HorizonalRubberBand; | |
207 | if(m_verticalRubberBand) return VerticalRubberBand; |
|
207 | if(m_verticalRubberBand) return VerticalRubberBand; | |
208 | return NoRubberBand; |
|
208 | return NoRubberBand; | |
209 | } |
|
209 | } | |
210 |
|
210 | |||
211 | /*! |
|
211 | /*! | |
212 | If Left mouse button is pressed and the RubberBandPolicy is enabled the \a event is accepted and the rubber band is displayed on the screen allowing the user to select the zoom area. |
|
212 | If Left mouse button is pressed and the RubberBandPolicy is enabled the \a event is accepted and the rubber band is displayed on the screen allowing the user to select the zoom area. | |
213 | If different mouse button is pressed and/or the RubberBandPolicy is disabled then the \a event is passed to QGraphicsView::mousePressEvent() implementation is called. |
|
213 | If different mouse button is pressed and/or the RubberBandPolicy is disabled then the \a event is passed to QGraphicsView::mousePressEvent() implementation is called. | |
214 | */ |
|
214 | */ | |
215 | void QChartView::mousePressEvent(QMouseEvent *event) |
|
215 | void QChartView::mousePressEvent(QMouseEvent *event) | |
216 | { |
|
216 | { | |
217 | if(m_rubberBand && m_rubberBand->isEnabled() && event->button() == Qt::LeftButton) { |
|
217 | if(m_rubberBand && m_rubberBand->isEnabled() && event->button() == Qt::LeftButton) { | |
218 |
|
218 | |||
219 | int margin = m_chart->margin(); |
|
219 | int margin = m_chart->margin(); | |
220 | QRect rect(margin, margin, width() - 2 * margin, height() - 2 * margin); |
|
220 | QRect rect(margin, margin, width() - 2 * margin, height() - 2 * margin); | |
221 |
|
221 | |||
222 | if (rect.contains(event->pos())) { |
|
222 | if (rect.contains(event->pos())) { | |
223 | m_rubberBandOrigin = event->pos(); |
|
223 | m_rubberBandOrigin = event->pos(); | |
224 | m_rubberBand->setGeometry(QRect(m_rubberBandOrigin, QSize())); |
|
224 | m_rubberBand->setGeometry(QRect(m_rubberBandOrigin, QSize())); | |
225 | m_rubberBand->show(); |
|
225 | m_rubberBand->show(); | |
226 | event->accept(); |
|
226 | event->accept(); | |
227 | } |
|
227 | } | |
228 | } |
|
228 | } | |
229 | else { |
|
229 | else { | |
230 | QGraphicsView::mousePressEvent(event); |
|
230 | QGraphicsView::mousePressEvent(event); | |
231 | } |
|
231 | } | |
232 | } |
|
232 | } | |
233 |
|
233 | |||
234 | /*! |
|
234 | /*! | |
235 | If RubberBand rectange specification has been initiated in pressEvent then \a event data is used to update RubberBand geometry. |
|
235 | If RubberBand rectange specification has been initiated in pressEvent then \a event data is used to update RubberBand geometry. | |
236 | In other case the defualt QGraphicsView::mouseMoveEvent implementation is called. |
|
236 | In other case the defualt QGraphicsView::mouseMoveEvent implementation is called. | |
237 | */ |
|
237 | */ | |
238 | void QChartView::mouseMoveEvent(QMouseEvent *event) |
|
238 | void QChartView::mouseMoveEvent(QMouseEvent *event) | |
239 | { |
|
239 | { | |
240 | if(m_rubberBand && m_rubberBand->isVisible()) { |
|
240 | if(m_rubberBand && m_rubberBand->isVisible()) { | |
241 | int margin = m_chart->margin(); |
|
241 | int margin = m_chart->margin(); | |
242 | QRect rect(margin, margin, width() - 2 * margin, height() - 2 * margin); |
|
242 | QRect rect(margin, margin, width() - 2 * margin, height() - 2 * margin); | |
243 | int width = event->pos().x() - m_rubberBandOrigin.x(); |
|
243 | int width = event->pos().x() - m_rubberBandOrigin.x(); | |
244 | int height = event->pos().y() - m_rubberBandOrigin.y(); |
|
244 | int height = event->pos().y() - m_rubberBandOrigin.y(); | |
245 | if(!m_verticalRubberBand) { |
|
245 | if(!m_verticalRubberBand) { | |
246 | m_rubberBandOrigin.setY(rect.top()); |
|
246 | m_rubberBandOrigin.setY(rect.top()); | |
247 | height = rect.height(); |
|
247 | height = rect.height(); | |
248 | } |
|
248 | } | |
249 | if(!m_horizonalRubberBand) { |
|
249 | if(!m_horizonalRubberBand) { | |
250 | m_rubberBandOrigin.setX(rect.left()); |
|
250 | m_rubberBandOrigin.setX(rect.left()); | |
251 | width= rect.width(); |
|
251 | width= rect.width(); | |
252 | } |
|
252 | } | |
253 | m_rubberBand->setGeometry(QRect(m_rubberBandOrigin.x(),m_rubberBandOrigin.y(), width,height).normalized()); |
|
253 | m_rubberBand->setGeometry(QRect(m_rubberBandOrigin.x(),m_rubberBandOrigin.y(), width,height).normalized()); | |
254 | } |
|
254 | } | |
255 | else { |
|
255 | else { | |
256 | QGraphicsView::mouseMoveEvent(event); |
|
256 | QGraphicsView::mouseMoveEvent(event); | |
257 | } |
|
257 | } | |
258 | } |
|
258 | } | |
259 |
|
259 | |||
260 | /*! |
|
260 | /*! | |
261 | If left mouse button is release and RubberBand is enabled then \a event is accepted and the view is zoomed in to rect specified by RubberBand |
|
261 | If left mouse button is release and RubberBand is enabled then \a event is accepted and the view is zoomed in to rect specified by RubberBand | |
262 | If it is the right mouse button \a event then RubberBand is dissmissed and zoom is canceled. |
|
262 | If it is the right mouse button \a event then RubberBand is dissmissed and zoom is canceled. | |
263 | */ |
|
263 | */ | |
264 | void QChartView::mouseReleaseEvent(QMouseEvent *event) |
|
264 | void QChartView::mouseReleaseEvent(QMouseEvent *event) | |
265 | { |
|
265 | { | |
266 | if(m_rubberBand) { |
|
266 | if(m_rubberBand) { | |
267 | if (event->button() == Qt::LeftButton && m_rubberBand->isVisible()) { |
|
267 | if (event->button() == Qt::LeftButton && m_rubberBand->isVisible()) { | |
268 | m_rubberBand->hide(); |
|
268 | m_rubberBand->hide(); | |
269 | QRect rect = m_rubberBand->geometry(); |
|
269 | QRect rect = m_rubberBand->geometry(); | |
270 | m_chart->zoomIn(rect); |
|
270 | m_chart->zoomIn(rect); | |
271 | event->accept(); |
|
271 | event->accept(); | |
272 | } |
|
272 | } | |
273 |
|
273 | |||
274 | if(event->button()==Qt::RightButton) |
|
274 | if(event->button()==Qt::RightButton) | |
275 | m_chart->zoomReset(); |
|
275 | m_chart->zoomReset(); | |
276 | } |
|
276 | } | |
277 | else { |
|
277 | else { | |
278 | QGraphicsView::mouseReleaseEvent(event); |
|
278 | QGraphicsView::mouseReleaseEvent(event); | |
279 | } |
|
279 | } | |
280 | } |
|
280 | } | |
281 |
|
281 | |||
282 | /*! |
|
282 | /*! | |
283 | Pressing + and - keys performs zoomIn() and zoomOut() respectivly. |
|
283 | Pressing + and - keys performs zoomIn() and zoomOut() respectivly. | |
284 | In other \a event is passed to the QGraphicsView::keyPressEvent() implementation |
|
284 | In other \a event is passed to the QGraphicsView::keyPressEvent() implementation | |
285 | */ |
|
285 | */ | |
286 | void QChartView::keyPressEvent(QKeyEvent *event) |
|
286 | void QChartView::keyPressEvent(QKeyEvent *event) | |
287 | { |
|
287 | { | |
288 | switch (event->key()) { |
|
288 | switch (event->key()) { | |
289 | case Qt::Key_Plus: |
|
289 | case Qt::Key_Plus: | |
290 | zoomIn(); |
|
290 | zoomIn(); | |
291 | break; |
|
291 | break; | |
292 | case Qt::Key_Minus: |
|
292 | case Qt::Key_Minus: | |
293 | zoomOut(); |
|
293 | zoomOut(); | |
294 | break; |
|
294 | break; | |
295 | default: |
|
295 | default: | |
296 | QGraphicsView::keyPressEvent(event); |
|
296 | QGraphicsView::keyPressEvent(event); | |
297 | break; |
|
297 | break; | |
298 | } |
|
298 | } | |
299 | } |
|
299 | } | |
300 |
|
300 | |||
301 | /*! |
|
301 | /*! | |
302 | Sets the \a theme used by the chart for rendering the graphical representation of the data |
|
302 | Sets the \a theme used by the chart for rendering the graphical representation of the data | |
303 | \sa QChart::ChartTheme, chartTheme() |
|
303 | \sa QChart::ChartTheme, chartTheme() | |
304 | */ |
|
304 | */ | |
305 | void QChartView::setChartTheme(QChart::ChartTheme theme) |
|
305 | void QChartView::setChartTheme(QChart::ChartTheme theme) | |
306 | { |
|
306 | { | |
307 | m_chart->setChartTheme(theme); |
|
307 | m_chart->setChartTheme(theme); | |
308 | } |
|
308 | } | |
309 |
|
309 | |||
310 | /*! |
|
310 | /*! | |
311 | Returns the theme enum used by the chart. |
|
311 | Returns the theme enum used by the chart. | |
312 | \sa setChartTheme() |
|
312 | \sa setChartTheme() | |
313 | */ |
|
313 | */ | |
314 | QChart::ChartTheme QChartView::chartTheme() const |
|
314 | QChart::ChartTheme QChartView::chartTheme() const | |
315 | { |
|
315 | { | |
316 | return m_chart->chartTheme(); |
|
316 | return m_chart->chartTheme(); | |
317 | } |
|
317 | } | |
318 |
|
318 | |||
319 | /*! |
|
319 | /*! | |
320 | Returns the pointer to the x axis object of the chart |
|
320 | Returns the pointer to the x axis object of the chart | |
321 | */ |
|
321 | */ | |
322 | QChartAxis* QChartView::axisX() const |
|
322 | QChartAxis* QChartView::axisX() const | |
323 | { |
|
323 | { | |
324 | return m_chart->axisX(); |
|
324 | return m_chart->axisX(); | |
325 | } |
|
325 | } | |
326 |
|
326 | |||
327 | /*! |
|
327 | /*! | |
328 | Returns the pointer to the y axis object of the chart |
|
328 | Returns the pointer to the y axis object of the chart | |
329 | */ |
|
329 | */ | |
330 | QChartAxis* QChartView::axisY() const |
|
330 | QChartAxis* QChartView::axisY() const | |
331 | { |
|
331 | { | |
332 | return m_chart->axisY(); |
|
332 | return m_chart->axisY(); | |
333 | } |
|
333 | } | |
334 |
|
334 | |||
335 | /*! |
|
335 | /*! | |
336 | Sets animation \a options for the chart |
|
336 | Sets animation \a options for the chart | |
337 | */ |
|
337 | */ | |
338 | void QChartView::setAnimationOptions(QChart::AnimationOptions options) |
|
338 | void QChartView::setAnimationOptions(QChart::AnimationOptions options) | |
339 | { |
|
339 | { | |
340 | m_chart->setAnimationOptions(options); |
|
340 | m_chart->setAnimationOptions(options); | |
341 | } |
|
341 | } | |
342 |
|
342 | |||
343 | /*! |
|
343 | /*! | |
344 | Returns animation options for the chart |
|
344 | Returns animation options for the chart | |
345 | */ |
|
345 | */ | |
346 | QChart::AnimationOptions QChartView::animationOptions() const |
|
346 | QChart::AnimationOptions QChartView::animationOptions() const | |
347 | { |
|
347 | { | |
348 | return m_chart->animationOptions(); |
|
348 | return m_chart->animationOptions(); | |
349 | } |
|
349 | } | |
350 |
|
350 | |||
351 | QTCOMMERCIALCHART_END_NAMESPACE |
|
351 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,74 +1,74 | |||||
1 | #ifndef QCHARTWIDGET_H |
|
1 | #ifndef QCHARTWIDGET_H | |
2 | #define QCHARTWIDGET_H |
|
2 | #define QCHARTWIDGET_H | |
3 |
|
3 | |||
4 | #include "qchartglobal.h" |
|
4 | #include "qchartglobal.h" | |
5 |
#include "q |
|
5 | #include "qseries.h" | |
6 | #include "qchart.h" |
|
6 | #include "qchart.h" | |
7 | #include <QGraphicsView> |
|
7 | #include <QGraphicsView> | |
8 |
|
8 | |||
9 | class QGraphicsScene; |
|
9 | class QGraphicsScene; | |
10 | class QRubberBand; |
|
10 | class QRubberBand; | |
11 |
|
11 | |||
12 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
12 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
13 |
|
13 | |||
14 | class QChart; |
|
14 | class QChart; | |
15 |
|
15 | |||
16 | class QTCOMMERCIALCHART_EXPORT QChartView : public QGraphicsView |
|
16 | class QTCOMMERCIALCHART_EXPORT QChartView : public QGraphicsView | |
17 | { |
|
17 | { | |
18 | public: |
|
18 | public: | |
19 | enum RubberBandPolicy { NoRubberBand, VerticalRubberBand, HorizonalRubberBand, RectangleRubberBand }; |
|
19 | enum RubberBandPolicy { NoRubberBand, VerticalRubberBand, HorizonalRubberBand, RectangleRubberBand }; | |
20 |
|
20 | |||
21 | explicit QChartView(QWidget *parent = 0); |
|
21 | explicit QChartView(QWidget *parent = 0); | |
22 | ~QChartView(); |
|
22 | ~QChartView(); | |
23 |
|
23 | |||
24 | //implement from QWidget |
|
24 | //implement from QWidget | |
25 | void resizeEvent(QResizeEvent *event); |
|
25 | void resizeEvent(QResizeEvent *event); | |
26 |
|
26 | |||
27 |
void addSeries(Q |
|
27 | void addSeries(QSeries* series,QChartAxis* axisY=0);// takes series ownership , takes axis ownership | |
28 |
void removeSeries(Q |
|
28 | void removeSeries(QSeries* series); //returns ownership , deletes axis if no series attached | |
29 | void removeAllSeries(); // deletes series and axis |
|
29 | void removeAllSeries(); // deletes series and axis | |
30 | int margin() const; |
|
30 | int margin() const; | |
31 |
|
31 | |||
32 | void setChartTitle(const QString& title); |
|
32 | void setChartTitle(const QString& title); | |
33 | void setChartTitleFont(const QFont& font); |
|
33 | void setChartTitleFont(const QFont& font); | |
34 | void setChartBackgroundBrush(const QBrush& brush); |
|
34 | void setChartBackgroundBrush(const QBrush& brush); | |
35 | void setChartBackgroundPen(const QPen& pen); |
|
35 | void setChartBackgroundPen(const QPen& pen); | |
36 |
|
36 | |||
37 | void zoomIn(); |
|
37 | void zoomIn(); | |
38 | void zoomIn(const QRect& rect); |
|
38 | void zoomIn(const QRect& rect); | |
39 | void zoomOut(); |
|
39 | void zoomOut(); | |
40 |
|
40 | |||
41 | void setRubberBandPolicy(const RubberBandPolicy ); |
|
41 | void setRubberBandPolicy(const RubberBandPolicy ); | |
42 | RubberBandPolicy rubberBandPolicy() const; |
|
42 | RubberBandPolicy rubberBandPolicy() const; | |
43 |
|
43 | |||
44 | void setChartTheme(QChart::ChartTheme theme); |
|
44 | void setChartTheme(QChart::ChartTheme theme); | |
45 | QChart::ChartTheme chartTheme() const; |
|
45 | QChart::ChartTheme chartTheme() const; | |
46 |
|
46 | |||
47 | void setAnimationOptions(QChart::AnimationOptions options); |
|
47 | void setAnimationOptions(QChart::AnimationOptions options); | |
48 | QChart::AnimationOptions animationOptions() const; |
|
48 | QChart::AnimationOptions animationOptions() const; | |
49 |
|
49 | |||
50 | QChartAxis* axisX() const; |
|
50 | QChartAxis* axisX() const; | |
51 | QChartAxis* axisY() const; |
|
51 | QChartAxis* axisY() const; | |
52 |
|
52 | |||
53 | protected: |
|
53 | protected: | |
54 | void mousePressEvent(QMouseEvent *event); |
|
54 | void mousePressEvent(QMouseEvent *event); | |
55 | void mouseMoveEvent(QMouseEvent *event); |
|
55 | void mouseMoveEvent(QMouseEvent *event); | |
56 | void mouseReleaseEvent(QMouseEvent *event); |
|
56 | void mouseReleaseEvent(QMouseEvent *event); | |
57 | void keyPressEvent(QKeyEvent *event); |
|
57 | void keyPressEvent(QKeyEvent *event); | |
58 |
|
58 | |||
59 |
|
59 | |||
60 | private: |
|
60 | private: | |
61 | QGraphicsScene *m_scene; |
|
61 | QGraphicsScene *m_scene; | |
62 | QChart* m_chart; |
|
62 | QChart* m_chart; | |
63 | QPoint m_rubberBandOrigin; |
|
63 | QPoint m_rubberBandOrigin; | |
64 | QRubberBand* m_rubberBand; |
|
64 | QRubberBand* m_rubberBand; | |
65 | bool m_verticalRubberBand; |
|
65 | bool m_verticalRubberBand; | |
66 | bool m_horizonalRubberBand; |
|
66 | bool m_horizonalRubberBand; | |
67 | Q_DISABLE_COPY(QChartView) |
|
67 | Q_DISABLE_COPY(QChartView) | |
68 |
|
68 | |||
69 |
|
69 | |||
70 | }; |
|
70 | }; | |
71 |
|
71 | |||
72 | QTCOMMERCIALCHART_END_NAMESPACE |
|
72 | QTCOMMERCIALCHART_END_NAMESPACE | |
73 |
|
73 | |||
74 | #endif // QCHARTWIDGET_H |
|
74 | #endif // QCHARTWIDGET_H |
@@ -1,52 +1,52 | |||||
1 |
#include "q |
|
1 | #include "qseries.h" | |
2 |
|
2 | |||
3 | /*! |
|
3 | /*! | |
4 |
\class Q |
|
4 | \class QSeries | |
5 | \brief Base class for all QtCommercial Chart series. |
|
5 | \brief Base class for all QtCommercial Chart series. | |
6 | \mainclass |
|
6 | \mainclass | |
7 |
|
7 | |||
8 | Usually you use the series type specific inherited classes instead of the base class. |
|
8 | Usually you use the series type specific inherited classes instead of the base class. | |
9 | \sa QScatterSeries |
|
9 | \sa QScatterSeries | |
10 | */ |
|
10 | */ | |
11 |
|
11 | |||
12 | /*! |
|
12 | /*! | |
13 |
\enum Q |
|
13 | \enum QSeries::QSeriesType | |
14 |
|
14 | |||
15 | The type of the series object. |
|
15 | The type of the series object. | |
16 |
|
16 | |||
17 | \value SeriesTypeLine |
|
17 | \value SeriesTypeLine | |
18 | \value SeriesTypeArea |
|
18 | \value SeriesTypeArea | |
19 | \value SeriesTypeBar |
|
19 | \value SeriesTypeBar | |
20 | \value SeriesTypeStackedBar |
|
20 | \value SeriesTypeStackedBar | |
21 | \value SeriesTypePercentBar |
|
21 | \value SeriesTypePercentBar | |
22 | \value SeriesTypePie |
|
22 | \value SeriesTypePie | |
23 | \value SeriesTypeScatter |
|
23 | \value SeriesTypeScatter | |
24 | \value SeriesTypeSpline |
|
24 | \value SeriesTypeSpline | |
25 | */ |
|
25 | */ | |
26 |
|
26 | |||
27 | /*! |
|
27 | /*! | |
28 |
\fn Q |
|
28 | \fn QSeries::QSeries(QObject *parent) | |
29 | \brief Constructs ChartSeries object with \a parent. |
|
29 | \brief Constructs ChartSeries object with \a parent. | |
30 | */ |
|
30 | */ | |
31 |
|
31 | |||
32 | /*! |
|
32 | /*! | |
33 |
\fn Q |
|
33 | \fn QSeries::~QSeries() | |
34 | \brief Virtual destructor for the chart series. |
|
34 | \brief Virtual destructor for the chart series. | |
35 | */ |
|
35 | */ | |
36 |
|
36 | |||
37 | /*! |
|
37 | /*! | |
38 |
\fn Q |
|
38 | \fn QSeriesType QSeries::type() const | |
39 | \brief The type of the series. |
|
39 | \brief The type of the series. | |
40 | */ |
|
40 | */ | |
41 |
|
41 | |||
42 | /*! |
|
42 | /*! | |
43 |
\fn bool Q |
|
43 | \fn bool QSeries::setModel(QAbstractItemModel *model) | |
44 | \brief Use the \a model to provide data for the series. The model overrides possible user data |
|
44 | \brief Use the \a model to provide data for the series. The model overrides possible user data | |
45 | set with QChartSeries type specific data setters. For example if you call both |
|
45 | set with QChartSeries type specific data setters. For example if you call both | |
46 | QScatterSeries::addData() and QScatterSeries::setModel, only the data provided by the model is |
|
46 | QScatterSeries::addData() and QScatterSeries::setModel, only the data provided by the model is | |
47 | used by the series. Returns true if the model is valid for the series. |
|
47 | used by the series. Returns true if the model is valid for the series. | |
48 | */ |
|
48 | */ | |
49 |
|
49 | |||
50 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
50 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
51 |
#include "moc_q |
|
51 | #include "moc_qseries.cpp" | |
52 | QTCOMMERCIALCHART_END_NAMESPACE |
|
52 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,37 +1,37 | |||||
1 |
#ifndef Q |
|
1 | #ifndef QSERIES_H | |
2 |
#define Q |
|
2 | #define QSERIES_H | |
3 |
|
3 | |||
4 | #include "qchartglobal.h" |
|
4 | #include "qchartglobal.h" | |
5 | #include <QObject> |
|
5 | #include <QObject> | |
6 | #include <QAbstractItemModel> |
|
6 | #include <QAbstractItemModel> | |
7 |
|
7 | |||
8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
9 |
|
9 | |||
10 |
class QTCOMMERCIALCHART_EXPORT Q |
|
10 | class QTCOMMERCIALCHART_EXPORT QSeries : public QObject | |
11 | { |
|
11 | { | |
12 | Q_OBJECT |
|
12 | Q_OBJECT | |
13 | public: |
|
13 | public: | |
14 |
enum Q |
|
14 | enum QSeriesType { | |
15 | SeriesTypeLine, |
|
15 | SeriesTypeLine, | |
16 | SeriesTypeArea, |
|
16 | SeriesTypeArea, | |
17 | SeriesTypeBar, |
|
17 | SeriesTypeBar, | |
18 | SeriesTypeStackedBar, |
|
18 | SeriesTypeStackedBar, | |
19 | SeriesTypePercentBar, |
|
19 | SeriesTypePercentBar, | |
20 | SeriesTypePie, |
|
20 | SeriesTypePie, | |
21 | SeriesTypeScatter, |
|
21 | SeriesTypeScatter, | |
22 | SeriesTypeSpline |
|
22 | SeriesTypeSpline | |
23 | }; |
|
23 | }; | |
24 |
|
24 | |||
25 | protected: |
|
25 | protected: | |
26 |
Q |
|
26 | QSeries(QObject *parent = 0) : QObject(parent) {} | |
27 |
|
27 | |||
28 | public: |
|
28 | public: | |
29 |
virtual ~Q |
|
29 | virtual ~QSeries() {} | |
30 |
virtual Q |
|
30 | virtual QSeriesType type() const = 0; | |
31 | // TODO |
|
31 | // TODO | |
32 | virtual bool setModel(QAbstractItemModel* /*model*/) { return false; } |
|
32 | virtual bool setModel(QAbstractItemModel* /*model*/) { return false; } | |
33 | }; |
|
33 | }; | |
34 |
|
34 | |||
35 | QTCOMMERCIALCHART_END_NAMESPACE |
|
35 | QTCOMMERCIALCHART_END_NAMESPACE | |
36 |
|
36 | |||
37 | #endif |
|
37 | #endif |
@@ -1,225 +1,225 | |||||
1 | #include "qscatterseries.h" |
|
1 | #include "qscatterseries.h" | |
2 | #include "scatterseries_p.h" |
|
2 | #include "scatterseries_p.h" | |
3 | #include "qchart.h" |
|
3 | #include "qchart.h" | |
4 |
|
4 | |||
5 | /*! |
|
5 | /*! | |
6 | \class QScatterSeries |
|
6 | \class QScatterSeries | |
7 | \brief QtCommercial Chart series API for showing scatter series. |
|
7 | \brief QtCommercial Chart series API for showing scatter series. | |
8 |
|
8 | |||
9 | \mainclass |
|
9 | \mainclass | |
10 |
|
10 | |||
11 | Example on how to create a chart with scatter series: |
|
11 | Example on how to create a chart with scatter series: | |
12 | \snippet ../example/scatter/main.cpp 1 |
|
12 | \snippet ../example/scatter/main.cpp 1 | |
13 |
|
13 | |||
14 | The example code would result the following: |
|
14 | The example code would result the following: | |
15 |
|
15 | |||
16 | \image scatter_example1.jpg |
|
16 | \image scatter_example1.jpg | |
17 | */ |
|
17 | */ | |
18 |
|
18 | |||
19 | /*! |
|
19 | /*! | |
20 | \enum QScatterSeries::MarkerShape |
|
20 | \enum QScatterSeries::MarkerShape | |
21 |
|
21 | |||
22 | This enum describes the shape used when rendering marker items. |
|
22 | This enum describes the shape used when rendering marker items. | |
23 |
|
23 | |||
24 | \value MarkerShapeDefault |
|
24 | \value MarkerShapeDefault | |
25 | \value MarkerShapePoint |
|
25 | \value MarkerShapePoint | |
26 | \value MarkerShapeX |
|
26 | \value MarkerShapeX | |
27 | \value MarkerShapeRectangle |
|
27 | \value MarkerShapeRectangle | |
28 | \value MarkerShapeTiltedRectangle |
|
28 | \value MarkerShapeTiltedRectangle | |
29 | \value MarkerShapeTriangle |
|
29 | \value MarkerShapeTriangle | |
30 | \value MarkerShapeCircle |
|
30 | \value MarkerShapeCircle | |
31 | */ |
|
31 | */ | |
32 |
|
32 | |||
33 | /*! |
|
33 | /*! | |
34 | \fn QChartSeriesType QScatterSeries::type() const |
|
34 | \fn QChartSeriesType QScatterSeries::type() const | |
35 | \brief Returns QChartSeries::SeriesTypeScatter. |
|
35 | \brief Returns QChartSeries::SeriesTypeScatter. | |
36 | */ |
|
36 | */ | |
37 |
|
37 | |||
38 | /*! |
|
38 | /*! | |
39 | \fn void QScatterSeries::clicked() |
|
39 | \fn void QScatterSeries::clicked() | |
40 | \brief TODO |
|
40 | \brief TODO | |
41 | */ |
|
41 | */ | |
42 |
|
42 | |||
43 | /*! |
|
43 | /*! | |
44 | \fn void QScatterSeries::changed() |
|
44 | \fn void QScatterSeries::changed() | |
45 | \brief TODO |
|
45 | \brief TODO | |
46 | */ |
|
46 | */ | |
47 |
|
47 | |||
48 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
48 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
49 |
|
49 | |||
50 | QScatterSeriesPrivate::QScatterSeriesPrivate() : |
|
50 | QScatterSeriesPrivate::QScatterSeriesPrivate() : | |
51 | m_data(QList<QPointF>()), |
|
51 | m_data(QList<QPointF>()), | |
52 | m_markerPen(QPen()), |
|
52 | m_markerPen(QPen()), | |
53 | m_markerBrush(QBrush()), |
|
53 | m_markerBrush(QBrush()), | |
54 | m_markerShape(QScatterSeries::MarkerShapeDefault) |
|
54 | m_markerShape(QScatterSeries::MarkerShapeDefault) | |
55 | { |
|
55 | { | |
56 | // Initialize pen color to invalid to use a theme color by default |
|
56 | // Initialize pen color to invalid to use a theme color by default | |
57 | m_markerPen.setColor(QColor::Invalid); |
|
57 | m_markerPen.setColor(QColor::Invalid); | |
58 | m_markerBrush.setColor(QColor::Invalid); |
|
58 | m_markerBrush.setColor(QColor::Invalid); | |
59 | } |
|
59 | } | |
60 |
|
60 | |||
61 | /*! |
|
61 | /*! | |
62 | Constructs a series object which is a child of \a parent. |
|
62 | Constructs a series object which is a child of \a parent. | |
63 | */ |
|
63 | */ | |
64 | QScatterSeries::QScatterSeries(QObject *parent) : |
|
64 | QScatterSeries::QScatterSeries(QObject *parent) : | |
65 |
Q |
|
65 | QSeries(parent), | |
66 | d(new QScatterSeriesPrivate()) |
|
66 | d(new QScatterSeriesPrivate()) | |
67 | { |
|
67 | { | |
68 | } |
|
68 | } | |
69 |
|
69 | |||
70 | /*! |
|
70 | /*! | |
71 | Destroys the object. Note that adding series to QChart transfers the ownership to the chart. |
|
71 | Destroys the object. Note that adding series to QChart transfers the ownership to the chart. | |
72 | */ |
|
72 | */ | |
73 | QScatterSeries::~QScatterSeries() |
|
73 | QScatterSeries::~QScatterSeries() | |
74 | { |
|
74 | { | |
75 | delete d; |
|
75 | delete d; | |
76 | } |
|
76 | } | |
77 |
|
77 | |||
78 | /*! |
|
78 | /*! | |
79 | Add single data point with \a x and \a y coordinates to the series. |
|
79 | Add single data point with \a x and \a y coordinates to the series. | |
80 | */ |
|
80 | */ | |
81 | void QScatterSeries::add(qreal x, qreal y) |
|
81 | void QScatterSeries::add(qreal x, qreal y) | |
82 | { |
|
82 | { | |
83 | d->m_data.append(QPointF(x, y)); |
|
83 | d->m_data.append(QPointF(x, y)); | |
84 | emit changed(); |
|
84 | emit changed(); | |
85 | } |
|
85 | } | |
86 |
|
86 | |||
87 | /*! |
|
87 | /*! | |
88 | Add single data point with \a value to the series. |
|
88 | Add single data point with \a value to the series. | |
89 | */ |
|
89 | */ | |
90 | void QScatterSeries::add(QPointF value) |
|
90 | void QScatterSeries::add(QPointF value) | |
91 | { |
|
91 | { | |
92 | d->m_data.append(value); |
|
92 | d->m_data.append(value); | |
93 | emit changed(); |
|
93 | emit changed(); | |
94 | } |
|
94 | } | |
95 |
|
95 | |||
96 | /*! |
|
96 | /*! | |
97 | Add list of \a points to the series. |
|
97 | Add list of \a points to the series. | |
98 | */ |
|
98 | */ | |
99 | void QScatterSeries::add(QList<QPointF> points) |
|
99 | void QScatterSeries::add(QList<QPointF> points) | |
100 | { |
|
100 | { | |
101 | d->m_data.append(points); |
|
101 | d->m_data.append(points); | |
102 | emit changed(); |
|
102 | emit changed(); | |
103 | } |
|
103 | } | |
104 |
|
104 | |||
105 | /*! |
|
105 | /*! | |
106 | Stream operator for adding a data point with \a value to the series. |
|
106 | Stream operator for adding a data point with \a value to the series. | |
107 | \sa add() |
|
107 | \sa add() | |
108 |
|
108 | |||
109 | For example: |
|
109 | For example: | |
110 | \snippet ../example/scatter/main.cpp 3 |
|
110 | \snippet ../example/scatter/main.cpp 3 | |
111 | */ |
|
111 | */ | |
112 | QScatterSeries& QScatterSeries::operator << (const QPointF &value) |
|
112 | QScatterSeries& QScatterSeries::operator << (const QPointF &value) | |
113 | { |
|
113 | { | |
114 | d->m_data.append(value); |
|
114 | d->m_data.append(value); | |
115 | emit changed(); |
|
115 | emit changed(); | |
116 | return *this; |
|
116 | return *this; | |
117 | } |
|
117 | } | |
118 |
|
118 | |||
119 | /*! |
|
119 | /*! | |
120 | Stream operator for adding a list of points to the series. |
|
120 | Stream operator for adding a list of points to the series. | |
121 | \sa add() |
|
121 | \sa add() | |
122 | */ |
|
122 | */ | |
123 | QScatterSeries& QScatterSeries::operator << (QList<QPointF> value) |
|
123 | QScatterSeries& QScatterSeries::operator << (QList<QPointF> value) | |
124 | { |
|
124 | { | |
125 | d->m_data.append(value); |
|
125 | d->m_data.append(value); | |
126 | emit changed(); |
|
126 | emit changed(); | |
127 | return *this; |
|
127 | return *this; | |
128 | } |
|
128 | } | |
129 |
|
129 | |||
130 | /*! |
|
130 | /*! | |
131 | Replaces the data of the series with the given list of data \a points. |
|
131 | Replaces the data of the series with the given list of data \a points. | |
132 | */ |
|
132 | */ | |
133 | void QScatterSeries::setData(QList<QPointF> points) |
|
133 | void QScatterSeries::setData(QList<QPointF> points) | |
134 | { |
|
134 | { | |
135 | d->m_data = points; |
|
135 | d->m_data = points; | |
136 | emit changed(); |
|
136 | emit changed(); | |
137 | } |
|
137 | } | |
138 |
|
138 | |||
139 | /*! |
|
139 | /*! | |
140 | Returns the current list of data points of the series. |
|
140 | Returns the current list of data points of the series. | |
141 | */ |
|
141 | */ | |
142 | QList<QPointF> QScatterSeries::data() |
|
142 | QList<QPointF> QScatterSeries::data() | |
143 | { |
|
143 | { | |
144 | return d->m_data; |
|
144 | return d->m_data; | |
145 | } |
|
145 | } | |
146 |
|
146 | |||
147 | /*! |
|
147 | /*! | |
148 | Overrides the default pen used for drawing a marker item with a user defined \a pen. The |
|
148 | Overrides the default pen used for drawing a marker item with a user defined \a pen. The | |
149 | default pen is defined by chart theme setting. |
|
149 | default pen is defined by chart theme setting. | |
150 |
|
150 | |||
151 | For example: |
|
151 | For example: | |
152 | \snippet ../example/scatter/main.cpp 5 |
|
152 | \snippet ../example/scatter/main.cpp 5 | |
153 |
|
153 | |||
154 | Would present your scatter markers with an opaque, uglyish green outlines instead of the |
|
154 | Would present your scatter markers with an opaque, uglyish green outlines instead of the | |
155 | beatiful markers defined by the chart's theme: |
|
155 | beatiful markers defined by the chart's theme: | |
156 | \image scatter_example_pen.jpg |
|
156 | \image scatter_example_pen.jpg | |
157 |
|
157 | |||
158 | \sa setBrush() |
|
158 | \sa setBrush() | |
159 | \sa QChart::setChartTheme() |
|
159 | \sa QChart::setChartTheme() | |
160 | */ |
|
160 | */ | |
161 | void QScatterSeries::setPen(QPen pen) |
|
161 | void QScatterSeries::setPen(QPen pen) | |
162 | { |
|
162 | { | |
163 | d->m_markerPen = pen; |
|
163 | d->m_markerPen = pen; | |
164 | } |
|
164 | } | |
165 |
|
165 | |||
166 | /*! |
|
166 | /*! | |
167 | Returns the pen used for drawing markers. |
|
167 | Returns the pen used for drawing markers. | |
168 | */ |
|
168 | */ | |
169 | QPen QScatterSeries::pen() |
|
169 | QPen QScatterSeries::pen() | |
170 | { |
|
170 | { | |
171 | return d->m_markerPen; |
|
171 | return d->m_markerPen; | |
172 | } |
|
172 | } | |
173 |
|
173 | |||
174 | /*! |
|
174 | /*! | |
175 | Overrides the default brush of the marker items with a user defined \a brush. The default brush |
|
175 | Overrides the default brush of the marker items with a user defined \a brush. The default brush | |
176 | is defined by chart theme setting. |
|
176 | is defined by chart theme setting. | |
177 |
|
177 | |||
178 | For example: |
|
178 | For example: | |
179 | \snippet ../example/scatter/main.cpp 4 |
|
179 | \snippet ../example/scatter/main.cpp 4 | |
180 |
|
180 | |||
181 | Would fill your scatter markers with an opaque red color: |
|
181 | Would fill your scatter markers with an opaque red color: | |
182 | \image scatter_example_brush.jpg |
|
182 | \image scatter_example_brush.jpg | |
183 |
|
183 | |||
184 | \sa setPen() |
|
184 | \sa setPen() | |
185 | \sa QChart::setChartTheme() |
|
185 | \sa QChart::setChartTheme() | |
186 | */ |
|
186 | */ | |
187 | void QScatterSeries::setBrush(QBrush brush) |
|
187 | void QScatterSeries::setBrush(QBrush brush) | |
188 | { |
|
188 | { | |
189 | d->m_markerBrush = brush; |
|
189 | d->m_markerBrush = brush; | |
190 | } |
|
190 | } | |
191 |
|
191 | |||
192 | /*! |
|
192 | /*! | |
193 | Returns the brush used for drawing markers. |
|
193 | Returns the brush used for drawing markers. | |
194 | */ |
|
194 | */ | |
195 | QBrush QScatterSeries::brush() |
|
195 | QBrush QScatterSeries::brush() | |
196 | { |
|
196 | { | |
197 | return d->m_markerBrush; |
|
197 | return d->m_markerBrush; | |
198 | } |
|
198 | } | |
199 |
|
199 | |||
200 | /*! |
|
200 | /*! | |
201 | Overrides the default shape of the marker items with a user defined \a shape. The default shape |
|
201 | Overrides the default shape of the marker items with a user defined \a shape. The default shape | |
202 | is defined by chart theme setting. |
|
202 | is defined by chart theme setting. | |
203 |
|
203 | |||
204 | For example: |
|
204 | For example: | |
205 | \snippet ../example/scatter/main.cpp 6 |
|
205 | \snippet ../example/scatter/main.cpp 6 | |
206 |
|
206 | |||
207 | Would make your scatter marker items rectangle: |
|
207 | Would make your scatter marker items rectangle: | |
208 | \image scatter_example_shape.jpg |
|
208 | \image scatter_example_shape.jpg | |
209 | */ |
|
209 | */ | |
210 | void QScatterSeries::setShape(MarkerShape shape) |
|
210 | void QScatterSeries::setShape(MarkerShape shape) | |
211 | { |
|
211 | { | |
212 | d->m_markerShape = shape; |
|
212 | d->m_markerShape = shape; | |
213 | } |
|
213 | } | |
214 |
|
214 | |||
215 | /*! |
|
215 | /*! | |
216 | Returns the shape used for drawing markers. |
|
216 | Returns the shape used for drawing markers. | |
217 | */ |
|
217 | */ | |
218 | QScatterSeries::MarkerShape QScatterSeries::shape() |
|
218 | QScatterSeries::MarkerShape QScatterSeries::shape() | |
219 | { |
|
219 | { | |
220 | return (QScatterSeries::MarkerShape) d->m_markerShape; |
|
220 | return (QScatterSeries::MarkerShape) d->m_markerShape; | |
221 | } |
|
221 | } | |
222 |
|
222 | |||
223 | #include "moc_qscatterseries.cpp" |
|
223 | #include "moc_qscatterseries.cpp" | |
224 |
|
224 | |||
225 | QTCOMMERCIALCHART_END_NAMESPACE |
|
225 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,68 +1,68 | |||||
1 | #ifndef QSCATTERSERIES_H |
|
1 | #ifndef QSCATTERSERIES_H | |
2 | #define QSCATTERSERIES_H |
|
2 | #define QSCATTERSERIES_H | |
3 |
|
3 | |||
4 |
#include "q |
|
4 | #include "qseries.h" | |
5 | #include <QRectF> |
|
5 | #include <QRectF> | |
6 | #include <QColor> |
|
6 | #include <QColor> | |
7 |
|
7 | |||
8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
9 | class QScatterSeriesPrivate; |
|
9 | class QScatterSeriesPrivate; | |
10 |
|
10 | |||
11 |
class QTCOMMERCIALCHART_EXPORT QScatterSeries : public Q |
|
11 | class QTCOMMERCIALCHART_EXPORT QScatterSeries : public QSeries | |
12 | { |
|
12 | { | |
13 | Q_OBJECT |
|
13 | Q_OBJECT | |
14 |
|
14 | |||
15 | public: |
|
15 | public: | |
16 | enum MarkerShape { |
|
16 | enum MarkerShape { | |
17 | // TODO: to be defined by the graphics design |
|
17 | // TODO: to be defined by the graphics design | |
18 | // TODO: marker shapes: "x", star, rectangle, tilted rect, triangle, circle, dot |
|
18 | // TODO: marker shapes: "x", star, rectangle, tilted rect, triangle, circle, dot | |
19 | MarkerShapeDefault = 0, |
|
19 | MarkerShapeDefault = 0, | |
20 | MarkerShapePoint, |
|
20 | MarkerShapePoint, | |
21 | MarkerShapeX, |
|
21 | MarkerShapeX, | |
22 | MarkerShapeRectangle, |
|
22 | MarkerShapeRectangle, | |
23 | MarkerShapeTiltedRectangle, |
|
23 | MarkerShapeTiltedRectangle, | |
24 | MarkerShapeTriangle, |
|
24 | MarkerShapeTriangle, | |
25 | MarkerShapeCircle |
|
25 | MarkerShapeCircle | |
26 | }; |
|
26 | }; | |
27 |
|
27 | |||
28 | public: |
|
28 | public: | |
29 | QScatterSeries(QObject *parent = 0); |
|
29 | QScatterSeries(QObject *parent = 0); | |
30 | ~QScatterSeries(); |
|
30 | ~QScatterSeries(); | |
31 |
|
31 | |||
32 | public: // from QChartSeries |
|
32 | public: // from QChartSeries | |
33 |
Q |
|
33 | QSeriesType type() const { return QSeries::SeriesTypeScatter; } | |
34 |
|
34 | |||
35 | public: |
|
35 | public: | |
36 | void add(qreal x, qreal y); |
|
36 | void add(qreal x, qreal y); | |
37 | void add(QPointF value); |
|
37 | void add(QPointF value); | |
38 | void add(QList<QPointF> points); |
|
38 | void add(QList<QPointF> points); | |
39 | void setData(QList<QPointF> points); |
|
39 | void setData(QList<QPointF> points); | |
40 | QScatterSeries& operator << (const QPointF &value); |
|
40 | QScatterSeries& operator << (const QPointF &value); | |
41 | QScatterSeries& operator << (QList<QPointF> points); |
|
41 | QScatterSeries& operator << (QList<QPointF> points); | |
42 | QList<QPointF> data(); |
|
42 | QList<QPointF> data(); | |
43 | //TODO: insert, replace, remove, clear...? |
|
43 | //TODO: insert, replace, remove, clear...? | |
44 |
|
44 | |||
45 | QPen pen(); |
|
45 | QPen pen(); | |
46 | void setPen(QPen pen); |
|
46 | void setPen(QPen pen); | |
47 | QBrush brush(); |
|
47 | QBrush brush(); | |
48 | void setBrush(QBrush brush); |
|
48 | void setBrush(QBrush brush); | |
49 | MarkerShape shape(); |
|
49 | MarkerShape shape(); | |
50 | void setShape(MarkerShape shape); |
|
50 | void setShape(MarkerShape shape); | |
51 | // TODO: marker size? |
|
51 | // TODO: marker size? | |
52 |
|
52 | |||
53 | Q_SIGNALS: |
|
53 | Q_SIGNALS: | |
54 | void clicked(/* TODO: parameters? */); |
|
54 | void clicked(/* TODO: parameters? */); | |
55 | // TODO: move to PIMPL for simplicity or does the user ever need changed signals? |
|
55 | // TODO: move to PIMPL for simplicity or does the user ever need changed signals? | |
56 | // TODO: more finegrained signaling for performance reasons |
|
56 | // TODO: more finegrained signaling for performance reasons | |
57 | // (check QPieSeries implementation with change sets) |
|
57 | // (check QPieSeries implementation with change sets) | |
58 | void changed(); |
|
58 | void changed(); | |
59 |
|
59 | |||
60 | private: |
|
60 | private: | |
61 | Q_DECLARE_PRIVATE(QScatterSeries) |
|
61 | Q_DECLARE_PRIVATE(QScatterSeries) | |
62 | Q_DISABLE_COPY(QScatterSeries) |
|
62 | Q_DISABLE_COPY(QScatterSeries) | |
63 | QScatterSeriesPrivate *const d; |
|
63 | QScatterSeriesPrivate *const d; | |
64 | }; |
|
64 | }; | |
65 |
|
65 | |||
66 | QTCOMMERCIALCHART_END_NAMESPACE |
|
66 | QTCOMMERCIALCHART_END_NAMESPACE | |
67 |
|
67 | |||
68 | #endif // QSCATTERSERIES_H |
|
68 | #endif // QSCATTERSERIES_H |
@@ -1,27 +1,27 | |||||
1 | #ifndef QSCATTERSERIESPRIVATE_H |
|
1 | #ifndef QSCATTERSERIESPRIVATE_H | |
2 | #define QSCATTERSERIESPRIVATE_H |
|
2 | #define QSCATTERSERIESPRIVATE_H | |
3 |
|
3 | |||
4 | #include "qchartglobal.h" |
|
4 | #include "qchartglobal.h" | |
5 |
#include "q |
|
5 | #include "qseries.h" | |
6 | #include <QPen> |
|
6 | #include <QPen> | |
7 |
|
7 | |||
8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
9 |
|
9 | |||
10 | /*! |
|
10 | /*! | |
11 | * The PIMPL class of QScatterSeries. |
|
11 | * The PIMPL class of QScatterSeries. | |
12 | */ |
|
12 | */ | |
13 | class QScatterSeriesPrivate |
|
13 | class QScatterSeriesPrivate | |
14 | { |
|
14 | { | |
15 | public: |
|
15 | public: | |
16 | QScatterSeriesPrivate(); |
|
16 | QScatterSeriesPrivate(); | |
17 |
|
17 | |||
18 | public: |
|
18 | public: | |
19 | QList<QPointF> m_data; |
|
19 | QList<QPointF> m_data; | |
20 | QPen m_markerPen; |
|
20 | QPen m_markerPen; | |
21 | QBrush m_markerBrush; |
|
21 | QBrush m_markerBrush; | |
22 | int m_markerShape; |
|
22 | int m_markerShape; | |
23 | }; |
|
23 | }; | |
24 |
|
24 | |||
25 | QTCOMMERCIALCHART_END_NAMESPACE |
|
25 | QTCOMMERCIALCHART_END_NAMESPACE | |
26 |
|
26 | |||
27 | #endif // QSCATTERSERIESPRIVATE_H |
|
27 | #endif // QSCATTERSERIESPRIVATE_H |
@@ -1,94 +1,89 | |||||
1 | !include( ../common.pri ):error( Couldn't find the common.pri file! ) |
|
1 | !include( ../common.pri ):error( Couldn't find the common.pri file! ) | |
2 | TARGET = QtCommercialChart |
|
2 | TARGET = QtCommercialChart | |
3 | DESTDIR = $$CHART_BUILD_LIB_DIR |
|
3 | DESTDIR = $$CHART_BUILD_LIB_DIR | |
4 | TEMPLATE = lib |
|
4 | TEMPLATE = lib | |
5 | QT += core \ |
|
5 | QT += core \ | |
6 | gui |
|
6 | gui | |
7 | CONFIG += debug_and_release |
|
7 | CONFIG += debug_and_release | |
8 | CONFIG(debug, debug|release):TARGET = QtCommercialChartd |
|
8 | CONFIG(debug, debug|release):TARGET = QtCommercialChartd | |
9 | SOURCES += \ |
|
9 | SOURCES += axisitem.cpp \ | |
10 | axisitem.cpp \ |
|
|||
11 | axisanimationitem.cpp \ |
|
10 | axisanimationitem.cpp \ | |
12 | chartdataset.cpp \ |
|
11 | chartdataset.cpp \ | |
13 | chartpresenter.cpp \ |
|
12 | chartpresenter.cpp \ | |
14 | charttheme.cpp \ |
|
13 | charttheme.cpp \ | |
15 | domain.cpp \ |
|
14 | domain.cpp \ | |
16 | qchart.cpp \ |
|
15 | qchart.cpp \ | |
17 | qchartaxis.cpp \ |
|
16 | qchartaxis.cpp \ | |
18 |
qchart |
|
17 | qchartview.cpp \ | |
19 |
q |
|
18 | qseries.cpp | |
20 | PRIVATE_HEADERS += \ |
|
19 | PRIVATE_HEADERS += axisitem_p.h \ | |
21 | axisitem_p.h \ |
|
|||
22 | axisanimationitem_p.h \ |
|
20 | axisanimationitem_p.h \ | |
23 | chartdataset_p.h \ |
|
21 | chartdataset_p.h \ | |
24 | chartitem_p.h \ |
|
22 | chartitem_p.h \ | |
25 | chartpresenter_p.h \ |
|
23 | chartpresenter_p.h \ | |
26 | charttheme_p.h \ |
|
24 | charttheme_p.h \ | |
27 | domain_p.h |
|
25 | domain_p.h | |
28 | PUBLIC_HEADERS += \ |
|
26 | PUBLIC_HEADERS += qchart.h \ | |
29 | qchart.h \ |
|
|||
30 | qchartaxis.h \ |
|
27 | qchartaxis.h \ | |
31 | qchartglobal.h \ |
|
28 | qchartglobal.h \ | |
32 |
q |
|
29 | qseries.h \ | |
33 |
qchartview.h |
|
30 | qchartview.h | |
34 |
|
||||
35 |
include(linechart/linechart.pri) |
|
31 | include(linechart/linechart.pri) | |
36 |
include(barchart/barchart.pri) |
|
32 | include(barchart/barchart.pri) | |
37 | include(piechart/piechart.pri) |
|
33 | include(piechart/piechart.pri) | |
38 | include(scatterseries/scatter.pri) |
|
34 | include(scatterseries/scatter.pri) | |
39 |
|
||||
40 | THEMES += themes/chartthemeicy_p.h \ |
|
35 | THEMES += themes/chartthemeicy_p.h \ | |
41 | themes/chartthemegrayscale_p.h \ |
|
36 | themes/chartthemegrayscale_p.h \ | |
42 | themes/chartthemescientific_p.h \ |
|
37 | themes/chartthemescientific_p.h \ | |
43 | themes/chartthemevanilla_p.h |
|
38 | themes/chartthemevanilla_p.h | |
44 | HEADERS += $$PUBLIC_HEADERS |
|
39 | HEADERS += $$PUBLIC_HEADERS | |
45 | HEADERS += $$PRIVATE_HEADERS |
|
40 | HEADERS += $$PRIVATE_HEADERS | |
46 | HEADERS += $$THEMES |
|
41 | HEADERS += $$THEMES | |
47 | INCLUDEPATH += linechart \ |
|
42 | INCLUDEPATH += linechart \ | |
48 | barchart \ |
|
43 | barchart \ | |
49 | themes \ |
|
44 | themes \ | |
50 | . |
|
45 | . | |
51 | OBJECTS_DIR = $$CHART_BUILD_DIR/lib |
|
46 | OBJECTS_DIR = $$CHART_BUILD_DIR/lib | |
52 | MOC_DIR = $$CHART_BUILD_DIR/lib |
|
47 | MOC_DIR = $$CHART_BUILD_DIR/lib | |
53 | UI_DIR = $$CHART_BUILD_DIR/lib |
|
48 | UI_DIR = $$CHART_BUILD_DIR/lib | |
54 | RCC_DIR = $$CHART_BUILD_DIR/lib |
|
49 | RCC_DIR = $$CHART_BUILD_DIR/lib | |
55 | DEFINES += QTCOMMERCIALCHART_LIBRARY |
|
50 | DEFINES += QTCOMMERCIALCHART_LIBRARY | |
56 | public_headers.path = $$[QT_INSTALL_HEADERS]/QtCommercialChart |
|
51 | public_headers.path = $$[QT_INSTALL_HEADERS]/QtCommercialChart | |
57 | public_headers.files = $$PUBLIC_HEADERS |
|
52 | public_headers.files = $$PUBLIC_HEADERS | |
58 | target.path = $$[QT_INSTALL_LIBS] |
|
53 | target.path = $$[QT_INSTALL_LIBS] | |
59 | INSTALLS += target \ |
|
54 | INSTALLS += target \ | |
60 | public_headers |
|
55 | public_headers | |
61 | install_build_public_headers.name = bild_public_headers |
|
56 | install_build_public_headers.name = bild_public_headers | |
62 | install_build_public_headers.output = $$CHART_BUILD_PUBLIC_HEADER_DIR/${QMAKE_FILE_BASE}.h |
|
57 | install_build_public_headers.output = $$CHART_BUILD_PUBLIC_HEADER_DIR/${QMAKE_FILE_BASE}.h | |
63 | install_build_public_headers.input = PUBLIC_HEADERS |
|
58 | install_build_public_headers.input = PUBLIC_HEADERS | |
64 | install_build_public_headers.commands = $$QMAKE_COPY \ |
|
59 | install_build_public_headers.commands = $$QMAKE_COPY \ | |
65 | ${QMAKE_FILE_NAME} \ |
|
60 | ${QMAKE_FILE_NAME} \ | |
66 | $$CHART_BUILD_PUBLIC_HEADER_DIR |
|
61 | $$CHART_BUILD_PUBLIC_HEADER_DIR | |
67 | install_build_public_headers.CONFIG += target_predeps \ |
|
62 | install_build_public_headers.CONFIG += target_predeps \ | |
68 | no_link |
|
63 | no_link | |
69 | install_build_private_headers.name = bild_private_headers |
|
64 | install_build_private_headers.name = bild_private_headers | |
70 | install_build_private_headers.output = $$CHART_BUILD_PRIVATE_HEADER_DIR/${QMAKE_FILE_BASE}.h |
|
65 | install_build_private_headers.output = $$CHART_BUILD_PRIVATE_HEADER_DIR/${QMAKE_FILE_BASE}.h | |
71 | install_build_private_headers.input = PRIVATE_HEADERS |
|
66 | install_build_private_headers.input = PRIVATE_HEADERS | |
72 | install_build_private_headers.commands = $$QMAKE_COPY \ |
|
67 | install_build_private_headers.commands = $$QMAKE_COPY \ | |
73 | ${QMAKE_FILE_NAME} \ |
|
68 | ${QMAKE_FILE_NAME} \ | |
74 | $$CHART_BUILD_PRIVATE_HEADER_DIR |
|
69 | $$CHART_BUILD_PRIVATE_HEADER_DIR | |
75 | install_build_private_headers.CONFIG += target_predeps \ |
|
70 | install_build_private_headers.CONFIG += target_predeps \ | |
76 | no_link |
|
71 | no_link | |
77 |
QMAKE_EXTRA_COMPILERS += install_build_public_headers |
|
72 | QMAKE_EXTRA_COMPILERS += install_build_public_headers \ | |
|
73 | install_build_private_headers | |||
78 | chartversion.target = qchartversion_p.h |
|
74 | chartversion.target = qchartversion_p.h | |
79 | chartversion.commands = @echo \ |
|
75 | chartversion.commands = @echo \ | |
80 | "build_time" \ |
|
76 | "build_time" \ | |
81 | > \ |
|
77 | > \ | |
82 | $$chartversion.target; |
|
78 | $$chartversion.target; | |
83 | chartversion.depends = $$HEADERS \ |
|
79 | chartversion.depends = $$HEADERS \ | |
84 | $$SOURCES |
|
80 | $$SOURCES | |
85 | PRE_TARGETDEPS += qchartversion_p.h |
|
81 | PRE_TARGETDEPS += qchartversion_p.h | |
86 | QMAKE_CLEAN += qchartversion_p.h |
|
82 | QMAKE_CLEAN += qchartversion_p.h | |
87 | QMAKE_EXTRA_TARGETS += chartversion |
|
83 | QMAKE_EXTRA_TARGETS += chartversion | |
88 | unix:QMAKE_DISTCLEAN += -r \ |
|
84 | unix:QMAKE_DISTCLEAN += -r \ | |
89 | $$CHART_BUILD_HEADER_DIR \ |
|
85 | $$CHART_BUILD_HEADER_DIR \ | |
90 | $$CHART_BUILD_LIB_DIR |
|
86 | $$CHART_BUILD_LIB_DIR | |
91 | win32:QMAKE_DISTCLEAN += /Q \ |
|
87 | win32:QMAKE_DISTCLEAN += /Q \ | |
92 | $$CHART_BUILD_HEADER_DIR \ |
|
88 | $$CHART_BUILD_HEADER_DIR \ | |
93 | $$CHART_BUILD_LIB_DIR |
|
89 | $$CHART_BUILD_LIB_DIR | |
94 |
|
@@ -1,599 +1,598 | |||||
1 | #include <QtTest/QtTest> |
|
1 | #include <QtTest/QtTest> | |
2 | #include <qchartaxis.h> |
|
2 | #include <qchartaxis.h> | |
3 | #include <qchartseries.h> |
|
|||
4 | #include <qlineseries.h> |
|
3 | #include <qlineseries.h> | |
5 | #include <private/chartdataset_p.h> |
|
4 | #include <private/chartdataset_p.h> | |
6 | #include <private/domain_p.h> |
|
5 | #include <private/domain_p.h> | |
7 |
|
6 | |||
8 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
7 | QTCOMMERCIALCHART_USE_NAMESPACE | |
9 |
|
8 | |||
10 | Q_DECLARE_METATYPE(Domain) |
|
9 | Q_DECLARE_METATYPE(Domain) | |
11 | Q_DECLARE_METATYPE(QChartAxis*) |
|
10 | Q_DECLARE_METATYPE(QChartAxis*) | |
12 |
Q_DECLARE_METATYPE(Q |
|
11 | Q_DECLARE_METATYPE(QSeries*) | |
13 | Q_DECLARE_METATYPE(QLineSeries*) |
|
12 | Q_DECLARE_METATYPE(QLineSeries*) | |
14 |
|
13 | |||
15 | class tst_ChartDataSet: public QObject { |
|
14 | class tst_ChartDataSet: public QObject { | |
16 | Q_OBJECT |
|
15 | Q_OBJECT | |
17 |
|
16 | |||
18 | public slots: |
|
17 | public slots: | |
19 | void initTestCase(); |
|
18 | void initTestCase(); | |
20 | void cleanupTestCase(); |
|
19 | void cleanupTestCase(); | |
21 | void init(); |
|
20 | void init(); | |
22 | void cleanup(); |
|
21 | void cleanup(); | |
23 |
|
22 | |||
24 | private slots: |
|
23 | private slots: | |
25 | void chartdataset_data(); |
|
24 | void chartdataset_data(); | |
26 | void chartdataset(); |
|
25 | void chartdataset(); | |
27 |
|
26 | |||
28 | void addDomain_data(); |
|
27 | void addDomain_data(); | |
29 | void addDomain(); |
|
28 | void addDomain(); | |
30 | void addSeries_data(); |
|
29 | void addSeries_data(); | |
31 | void addSeries(); |
|
30 | void addSeries(); | |
32 | void axisY_data(); |
|
31 | void axisY_data(); | |
33 | void axisY(); |
|
32 | void axisY(); | |
34 | void clearDomains_data(); |
|
33 | void clearDomains_data(); | |
35 | void clearDomains(); |
|
34 | void clearDomains(); | |
36 | void domain_data(); |
|
35 | void domain_data(); | |
37 | void domain(); |
|
36 | void domain(); | |
38 | void nextpreviousDomain_data(); |
|
37 | void nextpreviousDomain_data(); | |
39 | void nextpreviousDomain(); |
|
38 | void nextpreviousDomain(); | |
40 | void removeSeries_data(); |
|
39 | void removeSeries_data(); | |
41 | void removeSeries(); |
|
40 | void removeSeries(); | |
42 | void removeAllSeries_data(); |
|
41 | void removeAllSeries_data(); | |
43 | void removeAllSeries(); |
|
42 | void removeAllSeries(); | |
44 | }; |
|
43 | }; | |
45 |
|
44 | |||
46 | void tst_ChartDataSet::initTestCase() |
|
45 | void tst_ChartDataSet::initTestCase() | |
47 | { |
|
46 | { | |
48 | qRegisterMetaType<Domain>("Domain"); |
|
47 | qRegisterMetaType<Domain>("Domain"); | |
49 | qRegisterMetaType<QChartAxis*>(); |
|
48 | qRegisterMetaType<QChartAxis*>(); | |
50 |
qRegisterMetaType<Q |
|
49 | qRegisterMetaType<QSeries*>(); | |
51 | } |
|
50 | } | |
52 |
|
51 | |||
53 | void tst_ChartDataSet::cleanupTestCase() |
|
52 | void tst_ChartDataSet::cleanupTestCase() | |
54 | { |
|
53 | { | |
55 | } |
|
54 | } | |
56 |
|
55 | |||
57 | void tst_ChartDataSet::init() |
|
56 | void tst_ChartDataSet::init() | |
58 | { |
|
57 | { | |
59 | } |
|
58 | } | |
60 |
|
59 | |||
61 | void tst_ChartDataSet::cleanup() |
|
60 | void tst_ChartDataSet::cleanup() | |
62 | { |
|
61 | { | |
63 | } |
|
62 | } | |
64 |
|
63 | |||
65 | void tst_ChartDataSet::chartdataset_data() |
|
64 | void tst_ChartDataSet::chartdataset_data() | |
66 | { |
|
65 | { | |
67 | } |
|
66 | } | |
68 |
|
67 | |||
69 | void tst_ChartDataSet::chartdataset() |
|
68 | void tst_ChartDataSet::chartdataset() | |
70 | { |
|
69 | { | |
71 | ChartDataSet dataSet; |
|
70 | ChartDataSet dataSet; | |
72 | QVERIFY2(dataSet.axisX(), "Missing axisX."); |
|
71 | QVERIFY2(dataSet.axisX(), "Missing axisX."); | |
73 | QVERIFY2(dataSet.axisY(), "Missing axisY."); |
|
72 | QVERIFY2(dataSet.axisY(), "Missing axisY."); | |
74 | //check if not dangling pointer |
|
73 | //check if not dangling pointer | |
75 | dataSet.axisX()->objectName(); |
|
74 | dataSet.axisX()->objectName(); | |
76 | dataSet.axisY()->objectName(); |
|
75 | dataSet.axisY()->objectName(); | |
77 | QVERIFY(dataSet.domain(dataSet.axisX())==Domain()); |
|
76 | QVERIFY(dataSet.domain(dataSet.axisX())==Domain()); | |
78 | QVERIFY(dataSet.domain(dataSet.axisY())==Domain()); |
|
77 | QVERIFY(dataSet.domain(dataSet.axisY())==Domain()); | |
79 | QCOMPARE(dataSet.domainIndex(), 0); |
|
78 | QCOMPARE(dataSet.domainIndex(), 0); | |
80 | } |
|
79 | } | |
81 |
|
80 | |||
82 | void tst_ChartDataSet::addDomain_data() |
|
81 | void tst_ChartDataSet::addDomain_data() | |
83 | { |
|
82 | { | |
84 | QTest::addColumn<QRectF>("rect"); |
|
83 | QTest::addColumn<QRectF>("rect"); | |
85 | QTest::addColumn<QRectF>("viewport"); |
|
84 | QTest::addColumn<QRectF>("viewport"); | |
86 | QTest::newRow("400x400,1000x1000") << QRectF(200, 200, 600, 600) |
|
85 | QTest::newRow("400x400,1000x1000") << QRectF(200, 200, 600, 600) | |
87 | << QRectF(0, 0, 1000, 1000); |
|
86 | << QRectF(0, 0, 1000, 1000); | |
88 | QTest::newRow("600x600,1000x1000") << QRectF(100, 100, 700, 700) |
|
87 | QTest::newRow("600x600,1000x1000") << QRectF(100, 100, 700, 700) | |
89 | << QRectF(0, 0, 1000, 1000); |
|
88 | << QRectF(0, 0, 1000, 1000); | |
90 | QTest::newRow("200x200,1000x1000") << QRectF(400, 400, 600, 600) |
|
89 | QTest::newRow("200x200,1000x1000") << QRectF(400, 400, 600, 600) | |
91 | << QRectF(0, 0, 1000, 1000); |
|
90 | << QRectF(0, 0, 1000, 1000); | |
92 | } |
|
91 | } | |
93 |
|
92 | |||
94 | void tst_ChartDataSet::addDomain() |
|
93 | void tst_ChartDataSet::addDomain() | |
95 | { |
|
94 | { | |
96 | QFETCH(QRectF, rect); |
|
95 | QFETCH(QRectF, rect); | |
97 | QFETCH(QRectF, viewport); |
|
96 | QFETCH(QRectF, viewport); | |
98 |
|
97 | |||
99 | ChartDataSet dataSet; |
|
98 | ChartDataSet dataSet; | |
100 |
|
99 | |||
101 | Domain domain1(0, 1000, 0, 1000); |
|
100 | Domain domain1(0, 1000, 0, 1000); | |
102 | QLineSeries series; |
|
101 | QLineSeries series; | |
103 | series.add(0, 0); |
|
102 | series.add(0, 0); | |
104 | series.add(1000, 1000); |
|
103 | series.add(1000, 1000); | |
105 |
|
104 | |||
106 | dataSet.addSeries(&series); |
|
105 | dataSet.addSeries(&series); | |
107 |
|
106 | |||
108 | QCOMPARE(dataSet.domainIndex(), 0); |
|
107 | QCOMPARE(dataSet.domainIndex(), 0); | |
109 |
|
108 | |||
110 | QSignalSpy spy0(&dataSet, SIGNAL(axisAdded(QChartAxis*))); |
|
109 | QSignalSpy spy0(&dataSet, SIGNAL(axisAdded(QChartAxis*))); | |
111 | QSignalSpy spy1(&dataSet, |
|
110 | QSignalSpy spy1(&dataSet, | |
112 | SIGNAL(axisLabelsChanged(QChartAxis*, QStringList const&))); |
|
111 | SIGNAL(axisLabelsChanged(QChartAxis*, QStringList const&))); | |
113 | QSignalSpy spy2(&dataSet, SIGNAL(axisRemoved(QChartAxis*))); |
|
112 | QSignalSpy spy2(&dataSet, SIGNAL(axisRemoved(QChartAxis*))); | |
114 |
QSignalSpy spy3(&dataSet, SIGNAL(seriesAdded(Q |
|
113 | QSignalSpy spy3(&dataSet, SIGNAL(seriesAdded(QSeries*))); | |
115 | QSignalSpy spy4(&dataSet, |
|
114 | QSignalSpy spy4(&dataSet, | |
116 |
SIGNAL(seriesDomainChanged(Q |
|
115 | SIGNAL(seriesDomainChanged(QSeries*, Domain const&))); | |
117 |
QSignalSpy spy5(&dataSet, SIGNAL(seriesRemoved(Q |
|
116 | QSignalSpy spy5(&dataSet, SIGNAL(seriesRemoved(QSeries*))); | |
118 |
|
117 | |||
119 | Domain domain2 = dataSet.domain(dataSet.axisY()); |
|
118 | Domain domain2 = dataSet.domain(dataSet.axisY()); | |
120 | QVERIFY(domain1 == domain2); |
|
119 | QVERIFY(domain1 == domain2); | |
121 |
|
120 | |||
122 | dataSet.addDomain(rect, viewport); |
|
121 | dataSet.addDomain(rect, viewport); | |
123 | QCOMPARE(dataSet.domainIndex(), 1); |
|
122 | QCOMPARE(dataSet.domainIndex(), 1); | |
124 | Domain domain3 = dataSet.domain(dataSet.axisY()); |
|
123 | Domain domain3 = dataSet.domain(dataSet.axisY()); | |
125 | Domain domain4 = domain1.subDomain(rect, viewport.width(), |
|
124 | Domain domain4 = domain1.subDomain(rect, viewport.width(), | |
126 | viewport.height()); |
|
125 | viewport.height()); | |
127 | QVERIFY(domain3 == domain4); |
|
126 | QVERIFY(domain3 == domain4); | |
128 |
|
127 | |||
129 | QCOMPARE(spy0.count(), 0); |
|
128 | QCOMPARE(spy0.count(), 0); | |
130 | QCOMPARE(spy1.count(), 2); |
|
129 | QCOMPARE(spy1.count(), 2); | |
131 | QCOMPARE(spy2.count(), 0); |
|
130 | QCOMPARE(spy2.count(), 0); | |
132 | QCOMPARE(spy3.count(), 0); |
|
131 | QCOMPARE(spy3.count(), 0); | |
133 | QCOMPARE(spy4.count(), 1); |
|
132 | QCOMPARE(spy4.count(), 1); | |
134 | QCOMPARE(spy5.count(), 0); |
|
133 | QCOMPARE(spy5.count(), 0); | |
135 | } |
|
134 | } | |
136 |
|
135 | |||
137 | void tst_ChartDataSet::addSeries_data() |
|
136 | void tst_ChartDataSet::addSeries_data() | |
138 | { |
|
137 | { | |
139 | QTest::addColumn<int>("seriesCount"); |
|
138 | QTest::addColumn<int>("seriesCount"); | |
140 | QTest::addColumn<int>("axisYCount"); |
|
139 | QTest::addColumn<int>("axisYCount"); | |
141 | QTest::newRow("2 series, default axis") << 2 << 0; |
|
140 | QTest::newRow("2 series, default axis") << 2 << 0; | |
142 | QTest::newRow("2 series, 2 new axis") << 2 << 2; |
|
141 | QTest::newRow("2 series, 2 new axis") << 2 << 2; | |
143 | QTest::newRow("2 series, 1 new axis") << 2 << 2; |
|
142 | QTest::newRow("2 series, 1 new axis") << 2 << 2; | |
144 | QTest::newRow("3 series, 3 new axis") << 3 << 3; |
|
143 | QTest::newRow("3 series, 3 new axis") << 3 << 3; | |
145 | QTest::newRow("3 series, 2 new axis") << 3 << 2; |
|
144 | QTest::newRow("3 series, 2 new axis") << 3 << 2; | |
146 | QTest::newRow("3 series, 1 new axis") << 3 << 1; |
|
145 | QTest::newRow("3 series, 1 new axis") << 3 << 1; | |
147 | } |
|
146 | } | |
148 |
|
147 | |||
149 | void tst_ChartDataSet::addSeries() |
|
148 | void tst_ChartDataSet::addSeries() | |
150 | { |
|
149 | { | |
151 | QFETCH(int, seriesCount); |
|
150 | QFETCH(int, seriesCount); | |
152 | QFETCH(int, axisYCount); |
|
151 | QFETCH(int, axisYCount); | |
153 |
|
152 | |||
154 | ChartDataSet dataSet; |
|
153 | ChartDataSet dataSet; | |
155 |
|
154 | |||
156 | QSignalSpy spy0(&dataSet, SIGNAL(axisAdded(QChartAxis*))); |
|
155 | QSignalSpy spy0(&dataSet, SIGNAL(axisAdded(QChartAxis*))); | |
157 | QSignalSpy spy1(&dataSet, |
|
156 | QSignalSpy spy1(&dataSet, | |
158 | SIGNAL(axisLabelsChanged(QChartAxis*, QStringList const&))); |
|
157 | SIGNAL(axisLabelsChanged(QChartAxis*, QStringList const&))); | |
159 | QSignalSpy spy2(&dataSet, SIGNAL(axisRemoved(QChartAxis*))); |
|
158 | QSignalSpy spy2(&dataSet, SIGNAL(axisRemoved(QChartAxis*))); | |
160 |
QSignalSpy spy3(&dataSet, SIGNAL(seriesAdded(Q |
|
159 | QSignalSpy spy3(&dataSet, SIGNAL(seriesAdded(QSeries*))); | |
161 | QSignalSpy spy4(&dataSet, |
|
160 | QSignalSpy spy4(&dataSet, | |
162 |
SIGNAL(seriesDomainChanged(Q |
|
161 | SIGNAL(seriesDomainChanged(QSeries*, Domain const&))); | |
163 |
QSignalSpy spy5(&dataSet, SIGNAL(seriesRemoved(Q |
|
162 | QSignalSpy spy5(&dataSet, SIGNAL(seriesRemoved(QSeries*))); | |
164 |
|
163 | |||
165 | QList<QChartAxis*> axisList; |
|
164 | QList<QChartAxis*> axisList; | |
166 |
|
165 | |||
167 | for (int i = 0; i < axisYCount; i++) { |
|
166 | for (int i = 0; i < axisYCount; i++) { | |
168 | QChartAxis* axis = new QChartAxis(); |
|
167 | QChartAxis* axis = new QChartAxis(); | |
169 | axisList << axis; |
|
168 | axisList << axis; | |
170 | } |
|
169 | } | |
171 |
|
170 | |||
172 | QList<QChartAxis*>::iterator iterator = axisList.begin(); |
|
171 | QList<QChartAxis*>::iterator iterator = axisList.begin(); | |
173 |
|
172 | |||
174 | for (int i = 0; i < seriesCount; i++) { |
|
173 | for (int i = 0; i < seriesCount; i++) { | |
175 | QChartAxis* axisY = 0; |
|
174 | QChartAxis* axisY = 0; | |
176 | QLineSeries* series = new QLineSeries(); |
|
175 | QLineSeries* series = new QLineSeries(); | |
177 | if (iterator != axisList.end()) { |
|
176 | if (iterator != axisList.end()) { | |
178 | axisY = *iterator; |
|
177 | axisY = *iterator; | |
179 | iterator++; |
|
178 | iterator++; | |
180 | } else if (axisList.count() > 0) { |
|
179 | } else if (axisList.count() > 0) { | |
181 | iterator--; |
|
180 | iterator--; | |
182 | axisY = *iterator; |
|
181 | axisY = *iterator; | |
183 | iterator++; |
|
182 | iterator++; | |
184 | } |
|
183 | } | |
185 | dataSet.addSeries(series, axisY); |
|
184 | dataSet.addSeries(series, axisY); | |
186 | } |
|
185 | } | |
187 |
|
186 | |||
188 | //default axis |
|
187 | //default axis | |
189 | if (axisYCount == 0) |
|
188 | if (axisYCount == 0) | |
190 | axisYCount+=2; |
|
189 | axisYCount+=2; | |
191 | else |
|
190 | else | |
192 | axisYCount++; |
|
191 | axisYCount++; | |
193 |
|
192 | |||
194 | QCOMPARE(spy0.count(), axisYCount); |
|
193 | QCOMPARE(spy0.count(), axisYCount); | |
195 | QCOMPARE(spy1.count(), seriesCount*2); |
|
194 | QCOMPARE(spy1.count(), seriesCount*2); | |
196 | QCOMPARE(spy2.count(), 0); |
|
195 | QCOMPARE(spy2.count(), 0); | |
197 | QCOMPARE(spy3.count(), seriesCount); |
|
196 | QCOMPARE(spy3.count(), seriesCount); | |
198 | QCOMPARE(spy4.count(), seriesCount); |
|
197 | QCOMPARE(spy4.count(), seriesCount); | |
199 | QCOMPARE(spy5.count(), 0); |
|
198 | QCOMPARE(spy5.count(), 0); | |
200 |
|
199 | |||
201 | QCOMPARE(dataSet.domainIndex(), 0); |
|
200 | QCOMPARE(dataSet.domainIndex(), 0); | |
202 | } |
|
201 | } | |
203 |
|
202 | |||
204 | void tst_ChartDataSet::axisY_data() |
|
203 | void tst_ChartDataSet::axisY_data() | |
205 | { |
|
204 | { | |
206 | QTest::addColumn<QChartAxis*>("axisY"); |
|
205 | QTest::addColumn<QChartAxis*>("axisY"); | |
207 | QTest::newRow("axisY1") << new QChartAxis(); |
|
206 | QTest::newRow("axisY1") << new QChartAxis(); | |
208 | QTest::newRow("axisY2") << new QChartAxis(); |
|
207 | QTest::newRow("axisY2") << new QChartAxis(); | |
209 | } |
|
208 | } | |
210 |
|
209 | |||
211 | void tst_ChartDataSet::axisY() |
|
210 | void tst_ChartDataSet::axisY() | |
212 | { |
|
211 | { | |
213 | QFETCH(QChartAxis*, axisY); |
|
212 | QFETCH(QChartAxis*, axisY); | |
214 |
|
213 | |||
215 | ChartDataSet dataSet; |
|
214 | ChartDataSet dataSet; | |
216 |
|
215 | |||
217 | QChartAxis* defaultAxisY = dataSet.axisY(); |
|
216 | QChartAxis* defaultAxisY = dataSet.axisY(); | |
218 |
|
217 | |||
219 | QVERIFY2(defaultAxisY, "Missing axisY."); |
|
218 | QVERIFY2(defaultAxisY, "Missing axisY."); | |
220 |
|
219 | |||
221 | QLineSeries* series1 = new QLineSeries(); |
|
220 | QLineSeries* series1 = new QLineSeries(); | |
222 | dataSet.addSeries(series1); |
|
221 | dataSet.addSeries(series1); | |
223 |
|
222 | |||
224 | QLineSeries* series2 = new QLineSeries(); |
|
223 | QLineSeries* series2 = new QLineSeries(); | |
225 | dataSet.addSeries(series2, axisY); |
|
224 | dataSet.addSeries(series2, axisY); | |
226 |
|
225 | |||
227 | QVERIFY(dataSet.axisY(series1) == defaultAxisY); |
|
226 | QVERIFY(dataSet.axisY(series1) == defaultAxisY); | |
228 | QVERIFY(dataSet.axisY(series2) == axisY); |
|
227 | QVERIFY(dataSet.axisY(series2) == axisY); | |
229 |
|
228 | |||
230 |
|
229 | |||
231 | } |
|
230 | } | |
232 |
|
231 | |||
233 | void tst_ChartDataSet::clearDomains_data() |
|
232 | void tst_ChartDataSet::clearDomains_data() | |
234 | { |
|
233 | { | |
235 | QTest::addColumn<int>("indexCount"); |
|
234 | QTest::addColumn<int>("indexCount"); | |
236 | QTest::newRow("0") << 0; |
|
235 | QTest::newRow("0") << 0; | |
237 | QTest::newRow("1") << 1; |
|
236 | QTest::newRow("1") << 1; | |
238 | QTest::newRow("5") << 2; |
|
237 | QTest::newRow("5") << 2; | |
239 | QTest::newRow("8") << 3; |
|
238 | QTest::newRow("8") << 3; | |
240 | } |
|
239 | } | |
241 |
|
240 | |||
242 | void tst_ChartDataSet::clearDomains() |
|
241 | void tst_ChartDataSet::clearDomains() | |
243 | { |
|
242 | { | |
244 | QFETCH(int, indexCount); |
|
243 | QFETCH(int, indexCount); | |
245 |
|
244 | |||
246 | Domain domain1(0, 100, 0, 100); |
|
245 | Domain domain1(0, 100, 0, 100); | |
247 | QLineSeries* series = new QLineSeries(); |
|
246 | QLineSeries* series = new QLineSeries(); | |
248 | series->add(0, 0); |
|
247 | series->add(0, 0); | |
249 | series->add(100, 100); |
|
248 | series->add(100, 100); | |
250 |
|
249 | |||
251 | ChartDataSet dataSet; |
|
250 | ChartDataSet dataSet; | |
252 |
|
251 | |||
253 | QCOMPARE(dataSet.domainIndex(), 0); |
|
252 | QCOMPARE(dataSet.domainIndex(), 0); | |
254 |
|
253 | |||
255 | dataSet.addSeries(series); |
|
254 | dataSet.addSeries(series); | |
256 |
|
255 | |||
257 | Domain domain2 = dataSet.domain(dataSet.axisY()); |
|
256 | Domain domain2 = dataSet.domain(dataSet.axisY()); | |
258 |
|
257 | |||
259 | QVERIFY(domain2 == domain1); |
|
258 | QVERIFY(domain2 == domain1); | |
260 |
|
259 | |||
261 | QList<Domain> domains; |
|
260 | QList<Domain> domains; | |
262 |
|
261 | |||
263 | domains << domain1; |
|
262 | domains << domain1; | |
264 |
|
263 | |||
265 | for (int i = 0; i < indexCount; i++) { |
|
264 | for (int i = 0; i < indexCount; i++) { | |
266 | dataSet.addDomain(QRect(0, 0, 10, 10), QRect(0, 0, 100, 100)); |
|
265 | dataSet.addDomain(QRect(0, 0, 10, 10), QRect(0, 0, 100, 100)); | |
267 | domains << dataSet.domain(dataSet.axisY()); |
|
266 | domains << dataSet.domain(dataSet.axisY()); | |
268 | } |
|
267 | } | |
269 |
|
268 | |||
270 | QSignalSpy spy0(&dataSet, SIGNAL(axisAdded(QChartAxis*))); |
|
269 | QSignalSpy spy0(&dataSet, SIGNAL(axisAdded(QChartAxis*))); | |
271 | QSignalSpy spy1(&dataSet, |
|
270 | QSignalSpy spy1(&dataSet, | |
272 | SIGNAL(axisLabelsChanged(QChartAxis*, QStringList const&))); |
|
271 | SIGNAL(axisLabelsChanged(QChartAxis*, QStringList const&))); | |
273 | QSignalSpy spy2(&dataSet, SIGNAL(axisRemoved(QChartAxis*))); |
|
272 | QSignalSpy spy2(&dataSet, SIGNAL(axisRemoved(QChartAxis*))); | |
274 |
QSignalSpy spy3(&dataSet, SIGNAL(seriesAdded(Q |
|
273 | QSignalSpy spy3(&dataSet, SIGNAL(seriesAdded(QSeries*))); | |
275 | QSignalSpy spy4(&dataSet, |
|
274 | QSignalSpy spy4(&dataSet, | |
276 |
SIGNAL(seriesDomainChanged(Q |
|
275 | SIGNAL(seriesDomainChanged(QSeries*, Domain const&))); | |
277 |
QSignalSpy spy5(&dataSet, SIGNAL(seriesRemoved(Q |
|
276 | QSignalSpy spy5(&dataSet, SIGNAL(seriesRemoved(QSeries*))); | |
278 |
|
277 | |||
279 | dataSet.clearDomains(indexCount); |
|
278 | dataSet.clearDomains(indexCount); | |
280 |
|
279 | |||
281 | QCOMPARE(dataSet.domainIndex(), indexCount); |
|
280 | QCOMPARE(dataSet.domainIndex(), indexCount); | |
282 |
|
281 | |||
283 | domain2 = dataSet.domain(dataSet.axisY()); |
|
282 | domain2 = dataSet.domain(dataSet.axisY()); | |
284 |
|
283 | |||
285 | QVERIFY(domain2 == domains.at(indexCount)); |
|
284 | QVERIFY(domain2 == domains.at(indexCount)); | |
286 |
|
285 | |||
287 | QCOMPARE(spy0.count(), 0); |
|
286 | QCOMPARE(spy0.count(), 0); | |
288 | QCOMPARE(spy1.count(), 0); |
|
287 | QCOMPARE(spy1.count(), 0); | |
289 | QCOMPARE(spy2.count(), 0); |
|
288 | QCOMPARE(spy2.count(), 0); | |
290 | QCOMPARE(spy3.count(), 0); |
|
289 | QCOMPARE(spy3.count(), 0); | |
291 | QCOMPARE(spy4.count(), 0); |
|
290 | QCOMPARE(spy4.count(), 0); | |
292 | QCOMPARE(spy5.count(), 0); |
|
291 | QCOMPARE(spy5.count(), 0); | |
293 | } |
|
292 | } | |
294 |
|
293 | |||
295 | void tst_ChartDataSet::domain_data() |
|
294 | void tst_ChartDataSet::domain_data() | |
296 | { |
|
295 | { | |
297 | QTest::addColumn<Domain>("domain1"); |
|
296 | QTest::addColumn<Domain>("domain1"); | |
298 | QTest::addColumn<Domain>("domain2"); |
|
297 | QTest::addColumn<Domain>("domain2"); | |
299 | QTest::addColumn<Domain>("domain3"); |
|
298 | QTest::addColumn<Domain>("domain3"); | |
300 | QTest::addColumn<Domain>("domain"); |
|
299 | QTest::addColumn<Domain>("domain"); | |
301 | QTest::newRow("Domain(0,10,0,10)") << Domain(0, 10, 0, 10) |
|
300 | QTest::newRow("Domain(0,10,0,10)") << Domain(0, 10, 0, 10) | |
302 | << Domain(0, 5, 0, 5) << Domain(0, 3, 0, 3) << Domain(0, 10, 0, 10); |
|
301 | << Domain(0, 5, 0, 5) << Domain(0, 3, 0, 3) << Domain(0, 10, 0, 10); | |
303 | QTest::newRow("Domain(-1,11,0,11)") << Domain(-1, 10, 0, 10) |
|
302 | QTest::newRow("Domain(-1,11,0,11)") << Domain(-1, 10, 0, 10) | |
304 | << Domain(0, 11, 0, 11) << Domain(0, 3, 0, 3) |
|
303 | << Domain(0, 11, 0, 11) << Domain(0, 3, 0, 3) | |
305 | << Domain(-1, 11, 0, 11); |
|
304 | << Domain(-1, 11, 0, 11); | |
306 | QTest::newRow("Domain(-5,5,1,8)") << Domain(-5, 0, 1, 1) |
|
305 | QTest::newRow("Domain(-5,5,1,8)") << Domain(-5, 0, 1, 1) | |
307 | << Domain(0, 5, 0, 8) << Domain(1, 2, 1, 2) << Domain(-5, 5, 0, 8); |
|
306 | << Domain(0, 5, 0, 8) << Domain(1, 2, 1, 2) << Domain(-5, 5, 0, 8); | |
308 | } |
|
307 | } | |
309 |
|
308 | |||
310 | void tst_ChartDataSet::domain() |
|
309 | void tst_ChartDataSet::domain() | |
311 | { |
|
310 | { | |
312 | QFETCH(Domain, domain1); |
|
311 | QFETCH(Domain, domain1); | |
313 | QFETCH(Domain, domain2); |
|
312 | QFETCH(Domain, domain2); | |
314 | QFETCH(Domain, domain3); |
|
313 | QFETCH(Domain, domain3); | |
315 | QFETCH(Domain, domain); |
|
314 | QFETCH(Domain, domain); | |
316 |
|
315 | |||
317 | ChartDataSet dataSet; |
|
316 | ChartDataSet dataSet; | |
318 | QLineSeries* series1 = new QLineSeries(); |
|
317 | QLineSeries* series1 = new QLineSeries(); | |
319 | series1->add(domain1.m_minX, domain1.m_minY); |
|
318 | series1->add(domain1.m_minX, domain1.m_minY); | |
320 | series1->add(domain1.m_maxX, domain1.m_maxY); |
|
319 | series1->add(domain1.m_maxX, domain1.m_maxY); | |
321 | QLineSeries* series2 = new QLineSeries(); |
|
320 | QLineSeries* series2 = new QLineSeries(); | |
322 | series2->add(domain2.m_minX, domain2.m_minY); |
|
321 | series2->add(domain2.m_minX, domain2.m_minY); | |
323 | series2->add(domain2.m_maxX, domain2.m_maxY); |
|
322 | series2->add(domain2.m_maxX, domain2.m_maxY); | |
324 | QLineSeries* series3 = new QLineSeries(); |
|
323 | QLineSeries* series3 = new QLineSeries(); | |
325 | series3->add(domain3.m_minX, domain3.m_minY); |
|
324 | series3->add(domain3.m_minX, domain3.m_minY); | |
326 | series3->add(domain3.m_maxX, domain3.m_maxY); |
|
325 | series3->add(domain3.m_maxX, domain3.m_maxY); | |
327 |
|
326 | |||
328 | QSignalSpy spy0(&dataSet, SIGNAL(axisAdded(QChartAxis*))); |
|
327 | QSignalSpy spy0(&dataSet, SIGNAL(axisAdded(QChartAxis*))); | |
329 | QSignalSpy spy1(&dataSet, |
|
328 | QSignalSpy spy1(&dataSet, | |
330 | SIGNAL(axisLabelsChanged(QChartAxis*, QStringList const&))); |
|
329 | SIGNAL(axisLabelsChanged(QChartAxis*, QStringList const&))); | |
331 | QSignalSpy spy2(&dataSet, SIGNAL(axisRemoved(QChartAxis*))); |
|
330 | QSignalSpy spy2(&dataSet, SIGNAL(axisRemoved(QChartAxis*))); | |
332 |
QSignalSpy spy3(&dataSet, SIGNAL(seriesAdded(Q |
|
331 | QSignalSpy spy3(&dataSet, SIGNAL(seriesAdded(QSeries*))); | |
333 | QSignalSpy spy4(&dataSet, |
|
332 | QSignalSpy spy4(&dataSet, | |
334 |
SIGNAL(seriesDomainChanged(Q |
|
333 | SIGNAL(seriesDomainChanged(QSeries*, Domain const&))); | |
335 |
QSignalSpy spy5(&dataSet, SIGNAL(seriesRemoved(Q |
|
334 | QSignalSpy spy5(&dataSet, SIGNAL(seriesRemoved(QSeries*))); | |
336 |
|
335 | |||
337 | dataSet.addSeries(series1); |
|
336 | dataSet.addSeries(series1); | |
338 | dataSet.addSeries(series2); |
|
337 | dataSet.addSeries(series2); | |
339 | dataSet.addSeries(series3); |
|
338 | dataSet.addSeries(series3); | |
340 |
|
339 | |||
341 | QCOMPARE(dataSet.domainIndex(), 0); |
|
340 | QCOMPARE(dataSet.domainIndex(), 0); | |
342 | QVERIFY2(dataSet.domain(dataSet.axisY()) == domain, "Domain not equal"); |
|
341 | QVERIFY2(dataSet.domain(dataSet.axisY()) == domain, "Domain not equal"); | |
343 |
|
342 | |||
344 | QCOMPARE(spy0.count(), 2); |
|
343 | QCOMPARE(spy0.count(), 2); | |
345 | QCOMPARE(spy1.count(), 6); |
|
344 | QCOMPARE(spy1.count(), 6); | |
346 | QCOMPARE(spy2.count(), 0); |
|
345 | QCOMPARE(spy2.count(), 0); | |
347 | QCOMPARE(spy3.count(), 3); |
|
346 | QCOMPARE(spy3.count(), 3); | |
348 | QCOMPARE(spy4.count(), 3); |
|
347 | QCOMPARE(spy4.count(), 3); | |
349 | QCOMPARE(spy5.count(), 0); |
|
348 | QCOMPARE(spy5.count(), 0); | |
350 | } |
|
349 | } | |
351 |
|
350 | |||
352 | void tst_ChartDataSet::nextpreviousDomain_data() |
|
351 | void tst_ChartDataSet::nextpreviousDomain_data() | |
353 | { |
|
352 | { | |
354 | QTest::addColumn<QRectF>("rect"); |
|
353 | QTest::addColumn<QRectF>("rect"); | |
355 | QTest::addColumn<QRectF>("viewport"); |
|
354 | QTest::addColumn<QRectF>("viewport"); | |
356 | QTest::newRow("400x400,1000x1000") << QRectF(200, 200, 600, 600) |
|
355 | QTest::newRow("400x400,1000x1000") << QRectF(200, 200, 600, 600) | |
357 | << QRectF(0, 0, 1000, 1000); |
|
356 | << QRectF(0, 0, 1000, 1000); | |
358 | QTest::newRow("600x600,1000x1000") << QRectF(100, 100, 700, 700) |
|
357 | QTest::newRow("600x600,1000x1000") << QRectF(100, 100, 700, 700) | |
359 | << QRectF(0, 0, 1000, 1000); |
|
358 | << QRectF(0, 0, 1000, 1000); | |
360 | QTest::newRow("200x200,1000x1000") << QRectF(400, 400, 600, 600) |
|
359 | QTest::newRow("200x200,1000x1000") << QRectF(400, 400, 600, 600) | |
361 | << QRectF(0, 0, 1000, 1000); |
|
360 | << QRectF(0, 0, 1000, 1000); | |
362 | } |
|
361 | } | |
363 |
|
362 | |||
364 | void tst_ChartDataSet::nextpreviousDomain() |
|
363 | void tst_ChartDataSet::nextpreviousDomain() | |
365 | { |
|
364 | { | |
366 |
|
365 | |||
367 | QFETCH(QRectF, rect); |
|
366 | QFETCH(QRectF, rect); | |
368 | QFETCH(QRectF, viewport); |
|
367 | QFETCH(QRectF, viewport); | |
369 |
|
368 | |||
370 | ChartDataSet dataSet; |
|
369 | ChartDataSet dataSet; | |
371 |
|
370 | |||
372 | Domain domain1(0, 1000, 0, 1000); |
|
371 | Domain domain1(0, 1000, 0, 1000); | |
373 | QLineSeries* series = new QLineSeries(); |
|
372 | QLineSeries* series = new QLineSeries(); | |
374 | series->add(0, 0); |
|
373 | series->add(0, 0); | |
375 | series->add(1000, 1000); |
|
374 | series->add(1000, 1000); | |
376 |
|
375 | |||
377 | dataSet.addSeries(series); |
|
376 | dataSet.addSeries(series); | |
378 |
|
377 | |||
379 | QCOMPARE(dataSet.domainIndex(), 0); |
|
378 | QCOMPARE(dataSet.domainIndex(), 0); | |
380 |
|
379 | |||
381 | Domain domain2 = dataSet.domain(dataSet.axisY()); |
|
380 | Domain domain2 = dataSet.domain(dataSet.axisY()); | |
382 | QVERIFY(domain1 == domain2); |
|
381 | QVERIFY(domain1 == domain2); | |
383 |
|
382 | |||
384 | dataSet.addDomain(rect, viewport); |
|
383 | dataSet.addDomain(rect, viewport); | |
385 | QCOMPARE(dataSet.domainIndex(), 1); |
|
384 | QCOMPARE(dataSet.domainIndex(), 1); | |
386 | Domain domain3 = dataSet.domain(dataSet.axisY()); |
|
385 | Domain domain3 = dataSet.domain(dataSet.axisY()); | |
387 | Domain domain4 = domain1.subDomain(rect, viewport.width(), |
|
386 | Domain domain4 = domain1.subDomain(rect, viewport.width(), | |
388 | viewport.height()); |
|
387 | viewport.height()); | |
389 | QVERIFY(domain3 == domain4); |
|
388 | QVERIFY(domain3 == domain4); | |
390 |
|
389 | |||
391 | dataSet.addDomain(rect, viewport); |
|
390 | dataSet.addDomain(rect, viewport); | |
392 | QCOMPARE(dataSet.domainIndex(), 2); |
|
391 | QCOMPARE(dataSet.domainIndex(), 2); | |
393 | Domain domain5 = dataSet.domain(dataSet.axisY()); |
|
392 | Domain domain5 = dataSet.domain(dataSet.axisY()); | |
394 | Domain domain6 = domain3.subDomain(rect, viewport.width(), |
|
393 | Domain domain6 = domain3.subDomain(rect, viewport.width(), | |
395 | viewport.height()); |
|
394 | viewport.height()); | |
396 | QVERIFY(domain5 == domain6); |
|
395 | QVERIFY(domain5 == domain6); | |
397 |
|
396 | |||
398 | dataSet.addDomain(rect, viewport); |
|
397 | dataSet.addDomain(rect, viewport); | |
399 | QCOMPARE(dataSet.domainIndex(), 3); |
|
398 | QCOMPARE(dataSet.domainIndex(), 3); | |
400 | Domain domain7 = dataSet.domain(dataSet.axisY()); |
|
399 | Domain domain7 = dataSet.domain(dataSet.axisY()); | |
401 | Domain domain8 = domain5.subDomain(rect, viewport.width(), |
|
400 | Domain domain8 = domain5.subDomain(rect, viewport.width(), | |
402 | viewport.height()); |
|
401 | viewport.height()); | |
403 | QVERIFY(domain7 == domain8); |
|
402 | QVERIFY(domain7 == domain8); | |
404 |
|
403 | |||
405 | QSignalSpy spy0(&dataSet, SIGNAL(axisAdded(QChartAxis*))); |
|
404 | QSignalSpy spy0(&dataSet, SIGNAL(axisAdded(QChartAxis*))); | |
406 | QSignalSpy spy1(&dataSet, |
|
405 | QSignalSpy spy1(&dataSet, | |
407 | SIGNAL(axisLabelsChanged(QChartAxis*, QStringList const&))); |
|
406 | SIGNAL(axisLabelsChanged(QChartAxis*, QStringList const&))); | |
408 | QSignalSpy spy2(&dataSet, SIGNAL(axisRemoved(QChartAxis*))); |
|
407 | QSignalSpy spy2(&dataSet, SIGNAL(axisRemoved(QChartAxis*))); | |
409 |
QSignalSpy spy3(&dataSet, SIGNAL(seriesAdded(Q |
|
408 | QSignalSpy spy3(&dataSet, SIGNAL(seriesAdded(QSeries*))); | |
410 | QSignalSpy spy4(&dataSet, |
|
409 | QSignalSpy spy4(&dataSet, | |
411 |
SIGNAL(seriesDomainChanged(Q |
|
410 | SIGNAL(seriesDomainChanged(QSeries*, Domain const&))); | |
412 |
QSignalSpy spy5(&dataSet, SIGNAL(seriesRemoved(Q |
|
411 | QSignalSpy spy5(&dataSet, SIGNAL(seriesRemoved(QSeries*))); | |
413 |
|
412 | |||
414 | Domain domain; |
|
413 | Domain domain; | |
415 |
|
414 | |||
416 | bool previous = dataSet.previousDomain(); |
|
415 | bool previous = dataSet.previousDomain(); | |
417 | QCOMPARE(previous, true); |
|
416 | QCOMPARE(previous, true); | |
418 | QCOMPARE(dataSet.domainIndex(), 2); |
|
417 | QCOMPARE(dataSet.domainIndex(), 2); | |
419 | domain = dataSet.domain(dataSet.axisY()); |
|
418 | domain = dataSet.domain(dataSet.axisY()); | |
420 | QVERIFY(domain == domain5); |
|
419 | QVERIFY(domain == domain5); | |
421 | previous = dataSet.previousDomain(); |
|
420 | previous = dataSet.previousDomain(); | |
422 | QCOMPARE(previous, true); |
|
421 | QCOMPARE(previous, true); | |
423 | QCOMPARE(dataSet.domainIndex(), 1); |
|
422 | QCOMPARE(dataSet.domainIndex(), 1); | |
424 | domain = dataSet.domain(dataSet.axisY()); |
|
423 | domain = dataSet.domain(dataSet.axisY()); | |
425 | QVERIFY(domain == domain3); |
|
424 | QVERIFY(domain == domain3); | |
426 | previous = dataSet.previousDomain(); |
|
425 | previous = dataSet.previousDomain(); | |
427 | QCOMPARE(previous, true); |
|
426 | QCOMPARE(previous, true); | |
428 | QCOMPARE(dataSet.domainIndex(), 0); |
|
427 | QCOMPARE(dataSet.domainIndex(), 0); | |
429 | domain = dataSet.domain(dataSet.axisY()); |
|
428 | domain = dataSet.domain(dataSet.axisY()); | |
430 | QVERIFY(domain == domain1); |
|
429 | QVERIFY(domain == domain1); | |
431 | previous = dataSet.previousDomain(); |
|
430 | previous = dataSet.previousDomain(); | |
432 | QCOMPARE(previous, false); |
|
431 | QCOMPARE(previous, false); | |
433 | QCOMPARE(dataSet.domainIndex(), 0); |
|
432 | QCOMPARE(dataSet.domainIndex(), 0); | |
434 | domain = dataSet.domain(dataSet.axisY()); |
|
433 | domain = dataSet.domain(dataSet.axisY()); | |
435 | QVERIFY(domain == domain1); |
|
434 | QVERIFY(domain == domain1); | |
436 |
|
435 | |||
437 | bool next = dataSet.nextDomain(); |
|
436 | bool next = dataSet.nextDomain(); | |
438 | QCOMPARE(next, true); |
|
437 | QCOMPARE(next, true); | |
439 | QCOMPARE(dataSet.domainIndex(),1); |
|
438 | QCOMPARE(dataSet.domainIndex(),1); | |
440 | next = dataSet.nextDomain(); |
|
439 | next = dataSet.nextDomain(); | |
441 | QCOMPARE(next, true); |
|
440 | QCOMPARE(next, true); | |
442 | QCOMPARE(dataSet.domainIndex(),2); |
|
441 | QCOMPARE(dataSet.domainIndex(),2); | |
443 | next = dataSet.nextDomain(); |
|
442 | next = dataSet.nextDomain(); | |
444 | QCOMPARE(next, true); |
|
443 | QCOMPARE(next, true); | |
445 | QCOMPARE(dataSet.domainIndex(),3); |
|
444 | QCOMPARE(dataSet.domainIndex(),3); | |
446 | next = dataSet.nextDomain(); |
|
445 | next = dataSet.nextDomain(); | |
447 | QCOMPARE(next, false); |
|
446 | QCOMPARE(next, false); | |
448 | QCOMPARE(dataSet.domainIndex(),3); |
|
447 | QCOMPARE(dataSet.domainIndex(),3); | |
449 |
|
448 | |||
450 |
|
449 | |||
451 | QCOMPARE(spy0.count(), 0); |
|
450 | QCOMPARE(spy0.count(), 0); | |
452 | QCOMPARE(spy1.count(), 12); |
|
451 | QCOMPARE(spy1.count(), 12); | |
453 | QCOMPARE(spy2.count(), 0); |
|
452 | QCOMPARE(spy2.count(), 0); | |
454 | QCOMPARE(spy3.count(), 0); |
|
453 | QCOMPARE(spy3.count(), 0); | |
455 | QCOMPARE(spy4.count(), 6); |
|
454 | QCOMPARE(spy4.count(), 6); | |
456 | QCOMPARE(spy5.count(), 0); |
|
455 | QCOMPARE(spy5.count(), 0); | |
457 | } |
|
456 | } | |
458 |
|
457 | |||
459 | void tst_ChartDataSet::removeSeries_data() |
|
458 | void tst_ChartDataSet::removeSeries_data() | |
460 | { |
|
459 | { | |
461 | QTest::addColumn<int>("seriesCount"); |
|
460 | QTest::addColumn<int>("seriesCount"); | |
462 | QTest::addColumn<int>("axisYCount"); |
|
461 | QTest::addColumn<int>("axisYCount"); | |
463 | QTest::newRow("2 series, default axis") << 2 << 0; |
|
462 | QTest::newRow("2 series, default axis") << 2 << 0; | |
464 | QTest::newRow("2 series, 2 new axis") << 2 << 2; |
|
463 | QTest::newRow("2 series, 2 new axis") << 2 << 2; | |
465 | QTest::newRow("2 series, 1 new axis") << 2 << 2; |
|
464 | QTest::newRow("2 series, 1 new axis") << 2 << 2; | |
466 | QTest::newRow("3 series, 3 new axis") << 3 << 3; |
|
465 | QTest::newRow("3 series, 3 new axis") << 3 << 3; | |
467 | QTest::newRow("3 series, 2 new axis") << 3 << 2; |
|
466 | QTest::newRow("3 series, 2 new axis") << 3 << 2; | |
468 | QTest::newRow("3 series, 1 new axis") << 3 << 1; |
|
467 | QTest::newRow("3 series, 1 new axis") << 3 << 1; | |
469 | } |
|
468 | } | |
470 |
|
469 | |||
471 | void tst_ChartDataSet::removeSeries() |
|
470 | void tst_ChartDataSet::removeSeries() | |
472 | { |
|
471 | { | |
473 | QFETCH(int, seriesCount); |
|
472 | QFETCH(int, seriesCount); | |
474 | QFETCH(int, axisYCount); |
|
473 | QFETCH(int, axisYCount); | |
475 |
|
474 | |||
476 | ChartDataSet dataSet; |
|
475 | ChartDataSet dataSet; | |
477 |
|
476 | |||
478 | QList<QChartAxis*> axisList; |
|
477 | QList<QChartAxis*> axisList; | |
479 |
QList<Q |
|
478 | QList<QSeries*> seriesList; | |
480 |
|
479 | |||
481 | for (int i = 0; i < axisYCount; i++) { |
|
480 | for (int i = 0; i < axisYCount; i++) { | |
482 | QChartAxis* axis = new QChartAxis(); |
|
481 | QChartAxis* axis = new QChartAxis(); | |
483 | axisList << axis; |
|
482 | axisList << axis; | |
484 | } |
|
483 | } | |
485 |
|
484 | |||
486 | QList<QChartAxis*>::iterator iterator = axisList.begin(); |
|
485 | QList<QChartAxis*>::iterator iterator = axisList.begin(); | |
487 |
|
486 | |||
488 | for (int i = 0; i < seriesCount; i++) { |
|
487 | for (int i = 0; i < seriesCount; i++) { | |
489 | QChartAxis* axisY = 0; |
|
488 | QChartAxis* axisY = 0; | |
490 | QLineSeries* series = new QLineSeries(); |
|
489 | QLineSeries* series = new QLineSeries(); | |
491 | if (iterator != axisList.end()) { |
|
490 | if (iterator != axisList.end()) { | |
492 | axisY = *iterator; |
|
491 | axisY = *iterator; | |
493 | iterator++; |
|
492 | iterator++; | |
494 | } else if (axisList.count() > 0) { |
|
493 | } else if (axisList.count() > 0) { | |
495 | iterator--; |
|
494 | iterator--; | |
496 | axisY = *iterator; |
|
495 | axisY = *iterator; | |
497 | iterator++; |
|
496 | iterator++; | |
498 | } |
|
497 | } | |
499 | dataSet.addSeries(series, axisY); |
|
498 | dataSet.addSeries(series, axisY); | |
500 | seriesList << series; |
|
499 | seriesList << series; | |
501 | } |
|
500 | } | |
502 |
|
501 | |||
503 | QSignalSpy spy0(&dataSet, SIGNAL(axisAdded(QChartAxis*))); |
|
502 | QSignalSpy spy0(&dataSet, SIGNAL(axisAdded(QChartAxis*))); | |
504 | QSignalSpy spy1(&dataSet, |
|
503 | QSignalSpy spy1(&dataSet, | |
505 | SIGNAL(axisLabelsChanged(QChartAxis*, QStringList const&))); |
|
504 | SIGNAL(axisLabelsChanged(QChartAxis*, QStringList const&))); | |
506 | QSignalSpy spy2(&dataSet, SIGNAL(axisRemoved(QChartAxis*))); |
|
505 | QSignalSpy spy2(&dataSet, SIGNAL(axisRemoved(QChartAxis*))); | |
507 |
QSignalSpy spy3(&dataSet, SIGNAL(seriesAdded(Q |
|
506 | QSignalSpy spy3(&dataSet, SIGNAL(seriesAdded(QSeries*))); | |
508 | QSignalSpy spy4(&dataSet, |
|
507 | QSignalSpy spy4(&dataSet, | |
509 |
SIGNAL(seriesDomainChanged(Q |
|
508 | SIGNAL(seriesDomainChanged(QSeries*, Domain const&))); | |
510 |
QSignalSpy spy5(&dataSet, SIGNAL(seriesRemoved(Q |
|
509 | QSignalSpy spy5(&dataSet, SIGNAL(seriesRemoved(QSeries*))); | |
511 |
|
510 | |||
512 | for (int i = 0; i < seriesCount; i++) { |
|
511 | for (int i = 0; i < seriesCount; i++) { | |
513 | dataSet.removeSeries(seriesList.at(i)); |
|
512 | dataSet.removeSeries(seriesList.at(i)); | |
514 | } |
|
513 | } | |
515 |
|
514 | |||
516 | //default axis |
|
515 | //default axis | |
517 | if (axisYCount == 0) |
|
516 | if (axisYCount == 0) | |
518 | axisYCount++; |
|
517 | axisYCount++; | |
519 |
|
518 | |||
520 | QCOMPARE(spy0.count(), 0); |
|
519 | QCOMPARE(spy0.count(), 0); | |
521 | QCOMPARE(spy1.count(), 0); |
|
520 | QCOMPARE(spy1.count(), 0); | |
522 | QCOMPARE(spy2.count(), axisYCount); |
|
521 | QCOMPARE(spy2.count(), axisYCount); | |
523 | QCOMPARE(spy3.count(), 0); |
|
522 | QCOMPARE(spy3.count(), 0); | |
524 | QCOMPARE(spy4.count(), 0); |
|
523 | QCOMPARE(spy4.count(), 0); | |
525 | QCOMPARE(spy5.count(), seriesCount); |
|
524 | QCOMPARE(spy5.count(), seriesCount); | |
526 |
|
525 | |||
527 | QCOMPARE(dataSet.domainIndex(), 0); |
|
526 | QCOMPARE(dataSet.domainIndex(), 0); | |
528 |
|
527 | |||
529 | qDeleteAll(seriesList); |
|
528 | qDeleteAll(seriesList); | |
530 | } |
|
529 | } | |
531 |
|
530 | |||
532 | void tst_ChartDataSet::removeAllSeries_data() |
|
531 | void tst_ChartDataSet::removeAllSeries_data() | |
533 | { |
|
532 | { | |
534 | QTest::addColumn<int>("seriesCount"); |
|
533 | QTest::addColumn<int>("seriesCount"); | |
535 | QTest::addColumn<int>("axisYCount"); |
|
534 | QTest::addColumn<int>("axisYCount"); | |
536 | QTest::newRow("2 series, default axis") << 2 << 0; |
|
535 | QTest::newRow("2 series, default axis") << 2 << 0; | |
537 | QTest::newRow("2 series, 2 new axis") << 2 << 2; |
|
536 | QTest::newRow("2 series, 2 new axis") << 2 << 2; | |
538 | QTest::newRow("2 series, 1 new axis") << 2 << 2; |
|
537 | QTest::newRow("2 series, 1 new axis") << 2 << 2; | |
539 | QTest::newRow("3 series, 3 new axis") << 3 << 3; |
|
538 | QTest::newRow("3 series, 3 new axis") << 3 << 3; | |
540 | QTest::newRow("3 series, 2 new axis") << 3 << 2; |
|
539 | QTest::newRow("3 series, 2 new axis") << 3 << 2; | |
541 | QTest::newRow("3 series, 1 new axis") << 3 << 1; |
|
540 | QTest::newRow("3 series, 1 new axis") << 3 << 1; | |
542 | } |
|
541 | } | |
543 |
|
542 | |||
544 | void tst_ChartDataSet::removeAllSeries() |
|
543 | void tst_ChartDataSet::removeAllSeries() | |
545 | { |
|
544 | { | |
546 | QFETCH(int, seriesCount); |
|
545 | QFETCH(int, seriesCount); | |
547 | QFETCH(int, axisYCount); |
|
546 | QFETCH(int, axisYCount); | |
548 |
|
547 | |||
549 | ChartDataSet dataSet; |
|
548 | ChartDataSet dataSet; | |
550 |
|
549 | |||
551 | QList<QChartAxis*> axisList; |
|
550 | QList<QChartAxis*> axisList; | |
552 |
|
551 | |||
553 | for (int i = 0; i < axisYCount; i++) { |
|
552 | for (int i = 0; i < axisYCount; i++) { | |
554 | QChartAxis* axis = new QChartAxis(); |
|
553 | QChartAxis* axis = new QChartAxis(); | |
555 | axisList << axis; |
|
554 | axisList << axis; | |
556 | } |
|
555 | } | |
557 |
|
556 | |||
558 | QList<QChartAxis*>::iterator iterator = axisList.begin(); |
|
557 | QList<QChartAxis*>::iterator iterator = axisList.begin(); | |
559 |
|
558 | |||
560 | for (int i = 0; i < seriesCount; i++) { |
|
559 | for (int i = 0; i < seriesCount; i++) { | |
561 | QChartAxis* axisY = 0; |
|
560 | QChartAxis* axisY = 0; | |
562 | QLineSeries* series = new QLineSeries(); |
|
561 | QLineSeries* series = new QLineSeries(); | |
563 | if (iterator != axisList.end()) { |
|
562 | if (iterator != axisList.end()) { | |
564 | axisY = *iterator; |
|
563 | axisY = *iterator; | |
565 | iterator++; |
|
564 | iterator++; | |
566 | } else if (axisList.count() > 0) { |
|
565 | } else if (axisList.count() > 0) { | |
567 | iterator--; |
|
566 | iterator--; | |
568 | axisY = *iterator; |
|
567 | axisY = *iterator; | |
569 | iterator++; |
|
568 | iterator++; | |
570 | } |
|
569 | } | |
571 | dataSet.addSeries(series, axisY); |
|
570 | dataSet.addSeries(series, axisY); | |
572 | } |
|
571 | } | |
573 |
|
572 | |||
574 | QSignalSpy spy0(&dataSet, SIGNAL(axisAdded(QChartAxis*))); |
|
573 | QSignalSpy spy0(&dataSet, SIGNAL(axisAdded(QChartAxis*))); | |
575 | QSignalSpy spy1(&dataSet, SIGNAL(axisLabelsChanged(QChartAxis*, QStringList const&))); |
|
574 | QSignalSpy spy1(&dataSet, SIGNAL(axisLabelsChanged(QChartAxis*, QStringList const&))); | |
576 | QSignalSpy spy2(&dataSet, SIGNAL(axisRemoved(QChartAxis*))); |
|
575 | QSignalSpy spy2(&dataSet, SIGNAL(axisRemoved(QChartAxis*))); | |
577 |
QSignalSpy spy3(&dataSet, SIGNAL(seriesAdded(Q |
|
576 | QSignalSpy spy3(&dataSet, SIGNAL(seriesAdded(QSeries*))); | |
578 |
QSignalSpy spy4(&dataSet, SIGNAL(seriesDomainChanged(Q |
|
577 | QSignalSpy spy4(&dataSet, SIGNAL(seriesDomainChanged(QSeries*, Domain const&))); | |
579 |
QSignalSpy spy5(&dataSet, SIGNAL(seriesRemoved(Q |
|
578 | QSignalSpy spy5(&dataSet, SIGNAL(seriesRemoved(QSeries*))); | |
580 |
|
579 | |||
581 | dataSet.removeAllSeries(); |
|
580 | dataSet.removeAllSeries(); | |
582 | //default axis |
|
581 | //default axis | |
583 | if (axisYCount == 0) |
|
582 | if (axisYCount == 0) | |
584 | axisYCount++; |
|
583 | axisYCount++; | |
585 |
|
584 | |||
586 | QCOMPARE(spy0.count(), 0); |
|
585 | QCOMPARE(spy0.count(), 0); | |
587 | QCOMPARE(spy1.count(), 0); |
|
586 | QCOMPARE(spy1.count(), 0); | |
588 | QCOMPARE(spy2.count(), axisYCount); |
|
587 | QCOMPARE(spy2.count(), axisYCount); | |
589 | QCOMPARE(spy3.count(), 0); |
|
588 | QCOMPARE(spy3.count(), 0); | |
590 | QCOMPARE(spy4.count(), 0); |
|
589 | QCOMPARE(spy4.count(), 0); | |
591 | QCOMPARE(spy5.count(), seriesCount); |
|
590 | QCOMPARE(spy5.count(), seriesCount); | |
592 |
|
591 | |||
593 | QCOMPARE(dataSet.domainIndex(), 0); |
|
592 | QCOMPARE(dataSet.domainIndex(), 0); | |
594 | } |
|
593 | } | |
595 |
|
594 | |||
596 |
|
595 | |||
597 | QTEST_MAIN(tst_ChartDataSet) |
|
596 | QTEST_MAIN(tst_ChartDataSet) | |
598 | #include "tst_chartdataset.moc" |
|
597 | #include "tst_chartdataset.moc" | |
599 |
|
598 |
@@ -1,372 +1,371 | |||||
1 | #include "mainwidget.h" |
|
1 | #include "mainwidget.h" | |
2 | #include "dataseriedialog.h" |
|
2 | #include "dataseriedialog.h" | |
3 | #include "qchartseries.h" |
|
|||
4 | #include "qpieseries.h" |
|
3 | #include "qpieseries.h" | |
5 | #include "qscatterseries.h" |
|
4 | #include "qscatterseries.h" | |
6 | #include <qlineseries.h> |
|
5 | #include <qlineseries.h> | |
7 | #include <qbarset.h> |
|
6 | #include <qbarset.h> | |
8 | #include <qbarcategory.h> |
|
7 | #include <qbarcategory.h> | |
9 | #include <qbarseries.h> |
|
8 | #include <qbarseries.h> | |
10 | #include <qstackedbarseries.h> |
|
9 | #include <qstackedbarseries.h> | |
11 | #include <qpercentbarseries.h> |
|
10 | #include <qpercentbarseries.h> | |
12 | #include <QPushButton> |
|
11 | #include <QPushButton> | |
13 | #include <QComboBox> |
|
12 | #include <QComboBox> | |
14 | #include <QSpinBox> |
|
13 | #include <QSpinBox> | |
15 | #include <QCheckBox> |
|
14 | #include <QCheckBox> | |
16 | #include <QGridLayout> |
|
15 | #include <QGridLayout> | |
17 | #include <QHBoxLayout> |
|
16 | #include <QHBoxLayout> | |
18 | #include <QLabel> |
|
17 | #include <QLabel> | |
19 | #include <QSpacerItem> |
|
18 | #include <QSpacerItem> | |
20 | #include <QMessageBox> |
|
19 | #include <QMessageBox> | |
21 | #include <cmath> |
|
20 | #include <cmath> | |
22 | #include <QDebug> |
|
21 | #include <QDebug> | |
23 | #include <QStandardItemModel> |
|
22 | #include <QStandardItemModel> | |
24 |
|
23 | |||
25 |
|
24 | |||
26 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
25 | QTCOMMERCIALCHART_USE_NAMESPACE | |
27 |
|
26 | |||
28 | MainWidget::MainWidget(QWidget *parent) : |
|
27 | MainWidget::MainWidget(QWidget *parent) : | |
29 | QWidget(parent) |
|
28 | QWidget(parent) | |
30 | { |
|
29 | { | |
31 | m_chartWidget = new QChartView(this); |
|
30 | m_chartWidget = new QChartView(this); | |
32 | m_chartWidget->setRubberBandPolicy(QChartView::HorizonalRubberBand); |
|
31 | m_chartWidget->setRubberBandPolicy(QChartView::HorizonalRubberBand); | |
33 |
|
32 | |||
34 | // Grid layout for the controls for configuring the chart widget |
|
33 | // Grid layout for the controls for configuring the chart widget | |
35 | QGridLayout *grid = new QGridLayout(); |
|
34 | QGridLayout *grid = new QGridLayout(); | |
36 | QPushButton *addSeriesButton = new QPushButton("Add series"); |
|
35 | QPushButton *addSeriesButton = new QPushButton("Add series"); | |
37 | connect(addSeriesButton, SIGNAL(clicked()), this, SLOT(addSeries())); |
|
36 | connect(addSeriesButton, SIGNAL(clicked()), this, SLOT(addSeries())); | |
38 | grid->addWidget(addSeriesButton, 0, 1); |
|
37 | grid->addWidget(addSeriesButton, 0, 1); | |
39 | initBackroundCombo(grid); |
|
38 | initBackroundCombo(grid); | |
40 | initScaleControls(grid); |
|
39 | initScaleControls(grid); | |
41 | initThemeCombo(grid); |
|
40 | initThemeCombo(grid); | |
42 | QCheckBox *zoomCheckBox = new QCheckBox("Drag'n drop Zoom"); |
|
41 | QCheckBox *zoomCheckBox = new QCheckBox("Drag'n drop Zoom"); | |
43 | connect(zoomCheckBox, SIGNAL(toggled(bool)), m_chartWidget, SLOT(setZoomEnabled(bool))); |
|
42 | connect(zoomCheckBox, SIGNAL(toggled(bool)), m_chartWidget, SLOT(setZoomEnabled(bool))); | |
44 | zoomCheckBox->setChecked(true); |
|
43 | zoomCheckBox->setChecked(true); | |
45 | grid->addWidget(zoomCheckBox, grid->rowCount(), 0); |
|
44 | grid->addWidget(zoomCheckBox, grid->rowCount(), 0); | |
46 | // add row with empty label to make all the other rows static |
|
45 | // add row with empty label to make all the other rows static | |
47 | grid->addWidget(new QLabel(""), grid->rowCount(), 0); |
|
46 | grid->addWidget(new QLabel(""), grid->rowCount(), 0); | |
48 | grid->setRowStretch(grid->rowCount() - 1, 1); |
|
47 | grid->setRowStretch(grid->rowCount() - 1, 1); | |
49 |
|
48 | |||
50 | // Another grid layout as a main layout |
|
49 | // Another grid layout as a main layout | |
51 | QGridLayout *mainLayout = new QGridLayout(); |
|
50 | QGridLayout *mainLayout = new QGridLayout(); | |
52 | mainLayout->addLayout(grid, 0, 0); |
|
51 | mainLayout->addLayout(grid, 0, 0); | |
53 |
|
52 | |||
54 | // Init series type specific controls |
|
53 | // Init series type specific controls | |
55 | initPieControls(); |
|
54 | initPieControls(); | |
56 | mainLayout->addLayout(m_pieLayout, 2, 0); |
|
55 | mainLayout->addLayout(m_pieLayout, 2, 0); | |
57 | // Scatter series specific settings |
|
56 | // Scatter series specific settings | |
58 | // m_scatterLayout = new QGridLayout(); |
|
57 | // m_scatterLayout = new QGridLayout(); | |
59 | // m_scatterLayout->addWidget(new QLabel("scatter"), 0, 0); |
|
58 | // m_scatterLayout->addWidget(new QLabel("scatter"), 0, 0); | |
60 | // m_scatterLayout->setEnabled(false); |
|
59 | // m_scatterLayout->setEnabled(false); | |
61 | // mainLayout->addLayout(m_scatterLayout, 1, 0); |
|
60 | // mainLayout->addLayout(m_scatterLayout, 1, 0); | |
62 |
|
61 | |||
63 | // Add layouts and the chart widget to the main layout |
|
62 | // Add layouts and the chart widget to the main layout | |
64 | mainLayout->addWidget(m_chartWidget, 0, 1, 3, 1); |
|
63 | mainLayout->addWidget(m_chartWidget, 0, 1, 3, 1); | |
65 | setLayout(mainLayout); |
|
64 | setLayout(mainLayout); | |
66 | } |
|
65 | } | |
67 |
|
66 | |||
68 | // Combo box for selecting the chart's background |
|
67 | // Combo box for selecting the chart's background | |
69 | void MainWidget::initBackroundCombo(QGridLayout *grid) |
|
68 | void MainWidget::initBackroundCombo(QGridLayout *grid) | |
70 | { |
|
69 | { | |
71 | QComboBox *backgroundCombo = new QComboBox(this); |
|
70 | QComboBox *backgroundCombo = new QComboBox(this); | |
72 | backgroundCombo->addItem("Color"); |
|
71 | backgroundCombo->addItem("Color"); | |
73 | backgroundCombo->addItem("Gradient"); |
|
72 | backgroundCombo->addItem("Gradient"); | |
74 | backgroundCombo->addItem("Image"); |
|
73 | backgroundCombo->addItem("Image"); | |
75 | connect(backgroundCombo, SIGNAL(currentIndexChanged(int)), |
|
74 | connect(backgroundCombo, SIGNAL(currentIndexChanged(int)), | |
76 | this, SLOT(backgroundChanged(int))); |
|
75 | this, SLOT(backgroundChanged(int))); | |
77 |
|
76 | |||
78 | grid->addWidget(new QLabel("Background:"), grid->rowCount(), 0); |
|
77 | grid->addWidget(new QLabel("Background:"), grid->rowCount(), 0); | |
79 | grid->addWidget(backgroundCombo, grid->rowCount() - 1, 1); |
|
78 | grid->addWidget(backgroundCombo, grid->rowCount() - 1, 1); | |
80 | } |
|
79 | } | |
81 |
|
80 | |||
82 | // Scale related controls (auto-scale vs. manual min-max values) |
|
81 | // Scale related controls (auto-scale vs. manual min-max values) | |
83 | void MainWidget::initScaleControls(QGridLayout *grid) |
|
82 | void MainWidget::initScaleControls(QGridLayout *grid) | |
84 | { |
|
83 | { | |
85 | m_autoScaleCheck = new QCheckBox("Automatic scaling"); |
|
84 | m_autoScaleCheck = new QCheckBox("Automatic scaling"); | |
86 | connect(m_autoScaleCheck, SIGNAL(stateChanged(int)), this, SLOT(autoScaleChanged(int))); |
|
85 | connect(m_autoScaleCheck, SIGNAL(stateChanged(int)), this, SLOT(autoScaleChanged(int))); | |
87 | // Allow setting also non-sense values (like -2147483648 and 2147483647) |
|
86 | // Allow setting also non-sense values (like -2147483648 and 2147483647) | |
88 | m_xMinSpin = new QSpinBox(); |
|
87 | m_xMinSpin = new QSpinBox(); | |
89 | m_xMinSpin->setMinimum(INT_MIN); |
|
88 | m_xMinSpin->setMinimum(INT_MIN); | |
90 | m_xMinSpin->setMaximum(INT_MAX); |
|
89 | m_xMinSpin->setMaximum(INT_MAX); | |
91 | m_xMinSpin->setValue(0); |
|
90 | m_xMinSpin->setValue(0); | |
92 | connect(m_xMinSpin, SIGNAL(valueChanged(int)), this, SLOT(xMinChanged(int))); |
|
91 | connect(m_xMinSpin, SIGNAL(valueChanged(int)), this, SLOT(xMinChanged(int))); | |
93 | m_xMaxSpin = new QSpinBox(); |
|
92 | m_xMaxSpin = new QSpinBox(); | |
94 | m_xMaxSpin->setMinimum(INT_MIN); |
|
93 | m_xMaxSpin->setMinimum(INT_MIN); | |
95 | m_xMaxSpin->setMaximum(INT_MAX); |
|
94 | m_xMaxSpin->setMaximum(INT_MAX); | |
96 | m_xMaxSpin->setValue(10); |
|
95 | m_xMaxSpin->setValue(10); | |
97 | connect(m_xMaxSpin, SIGNAL(valueChanged(int)), this, SLOT(xMaxChanged(int))); |
|
96 | connect(m_xMaxSpin, SIGNAL(valueChanged(int)), this, SLOT(xMaxChanged(int))); | |
98 | m_yMinSpin = new QSpinBox(); |
|
97 | m_yMinSpin = new QSpinBox(); | |
99 | m_yMinSpin->setMinimum(INT_MIN); |
|
98 | m_yMinSpin->setMinimum(INT_MIN); | |
100 | m_yMinSpin->setMaximum(INT_MAX); |
|
99 | m_yMinSpin->setMaximum(INT_MAX); | |
101 | m_yMinSpin->setValue(0); |
|
100 | m_yMinSpin->setValue(0); | |
102 | connect(m_yMinSpin, SIGNAL(valueChanged(int)), this, SLOT(yMinChanged(int))); |
|
101 | connect(m_yMinSpin, SIGNAL(valueChanged(int)), this, SLOT(yMinChanged(int))); | |
103 | m_yMaxSpin = new QSpinBox(); |
|
102 | m_yMaxSpin = new QSpinBox(); | |
104 | m_yMaxSpin->setMinimum(INT_MIN); |
|
103 | m_yMaxSpin->setMinimum(INT_MIN); | |
105 | m_yMaxSpin->setMaximum(INT_MAX); |
|
104 | m_yMaxSpin->setMaximum(INT_MAX); | |
106 | m_yMaxSpin->setValue(10); |
|
105 | m_yMaxSpin->setValue(10); | |
107 | connect(m_yMaxSpin, SIGNAL(valueChanged(int)), this, SLOT(yMaxChanged(int))); |
|
106 | connect(m_yMaxSpin, SIGNAL(valueChanged(int)), this, SLOT(yMaxChanged(int))); | |
108 |
|
107 | |||
109 | grid->addWidget(m_autoScaleCheck, grid->rowCount(), 0); |
|
108 | grid->addWidget(m_autoScaleCheck, grid->rowCount(), 0); | |
110 | grid->addWidget(new QLabel("x min:"), grid->rowCount(), 0); |
|
109 | grid->addWidget(new QLabel("x min:"), grid->rowCount(), 0); | |
111 | grid->addWidget(m_xMinSpin, grid->rowCount() - 1, 1); |
|
110 | grid->addWidget(m_xMinSpin, grid->rowCount() - 1, 1); | |
112 | grid->addWidget(new QLabel("x max:"), grid->rowCount(), 0); |
|
111 | grid->addWidget(new QLabel("x max:"), grid->rowCount(), 0); | |
113 | grid->addWidget(m_xMaxSpin, grid->rowCount() - 1, 1); |
|
112 | grid->addWidget(m_xMaxSpin, grid->rowCount() - 1, 1); | |
114 | grid->addWidget(new QLabel("y min:"), grid->rowCount(), 0); |
|
113 | grid->addWidget(new QLabel("y min:"), grid->rowCount(), 0); | |
115 | grid->addWidget(m_yMinSpin, grid->rowCount() - 1, 1); |
|
114 | grid->addWidget(m_yMinSpin, grid->rowCount() - 1, 1); | |
116 | grid->addWidget(new QLabel("y max:"), grid->rowCount(), 0); |
|
115 | grid->addWidget(new QLabel("y max:"), grid->rowCount(), 0); | |
117 | grid->addWidget(m_yMaxSpin, grid->rowCount() - 1, 1); |
|
116 | grid->addWidget(m_yMaxSpin, grid->rowCount() - 1, 1); | |
118 |
|
117 | |||
119 | m_autoScaleCheck->setChecked(true); |
|
118 | m_autoScaleCheck->setChecked(true); | |
120 | } |
|
119 | } | |
121 |
|
120 | |||
122 | // Combo box for selecting theme |
|
121 | // Combo box for selecting theme | |
123 | void MainWidget::initThemeCombo(QGridLayout *grid) |
|
122 | void MainWidget::initThemeCombo(QGridLayout *grid) | |
124 | { |
|
123 | { | |
125 | QComboBox *chartTheme = new QComboBox(); |
|
124 | QComboBox *chartTheme = new QComboBox(); | |
126 | chartTheme->addItem("Default"); |
|
125 | chartTheme->addItem("Default"); | |
127 | chartTheme->addItem("Vanilla"); |
|
126 | chartTheme->addItem("Vanilla"); | |
128 | chartTheme->addItem("Icy"); |
|
127 | chartTheme->addItem("Icy"); | |
129 | chartTheme->addItem("Grayscale"); |
|
128 | chartTheme->addItem("Grayscale"); | |
130 | chartTheme->addItem("Scientific"); |
|
129 | chartTheme->addItem("Scientific"); | |
131 | chartTheme->addItem("Unnamed1"); |
|
130 | chartTheme->addItem("Unnamed1"); | |
132 | connect(chartTheme, SIGNAL(currentIndexChanged(int)), |
|
131 | connect(chartTheme, SIGNAL(currentIndexChanged(int)), | |
133 | this, SLOT(changeChartTheme(int))); |
|
132 | this, SLOT(changeChartTheme(int))); | |
134 | grid->addWidget(new QLabel("Chart theme:"), 8, 0); |
|
133 | grid->addWidget(new QLabel("Chart theme:"), 8, 0); | |
135 | grid->addWidget(chartTheme, 8, 1); |
|
134 | grid->addWidget(chartTheme, 8, 1); | |
136 | } |
|
135 | } | |
137 |
|
136 | |||
138 | void MainWidget::initPieControls() |
|
137 | void MainWidget::initPieControls() | |
139 | { |
|
138 | { | |
140 | // Pie series specific settings |
|
139 | // Pie series specific settings | |
141 | // Pie size factory |
|
140 | // Pie size factory | |
142 | QDoubleSpinBox *pieSizeSpin = new QDoubleSpinBox(); |
|
141 | QDoubleSpinBox *pieSizeSpin = new QDoubleSpinBox(); | |
143 | pieSizeSpin->setMinimum(LONG_MIN); |
|
142 | pieSizeSpin->setMinimum(LONG_MIN); | |
144 | pieSizeSpin->setMaximum(LONG_MAX); |
|
143 | pieSizeSpin->setMaximum(LONG_MAX); | |
145 | pieSizeSpin->setValue(1.0); |
|
144 | pieSizeSpin->setValue(1.0); | |
146 | pieSizeSpin->setSingleStep(0.1); |
|
145 | pieSizeSpin->setSingleStep(0.1); | |
147 | connect(pieSizeSpin, SIGNAL(valueChanged(double)), this, SLOT(setPieSizeFactor(double))); |
|
146 | connect(pieSizeSpin, SIGNAL(valueChanged(double)), this, SLOT(setPieSizeFactor(double))); | |
148 | // Pie position |
|
147 | // Pie position | |
149 | QComboBox *piePosCombo = new QComboBox(this); |
|
148 | QComboBox *piePosCombo = new QComboBox(this); | |
150 | piePosCombo->addItem("Maximized"); |
|
149 | piePosCombo->addItem("Maximized"); | |
151 | piePosCombo->addItem("Top left"); |
|
150 | piePosCombo->addItem("Top left"); | |
152 | piePosCombo->addItem("Top right"); |
|
151 | piePosCombo->addItem("Top right"); | |
153 | piePosCombo->addItem("Bottom left"); |
|
152 | piePosCombo->addItem("Bottom left"); | |
154 | piePosCombo->addItem("Bottom right"); |
|
153 | piePosCombo->addItem("Bottom right"); | |
155 | connect(piePosCombo, SIGNAL(currentIndexChanged(int)), |
|
154 | connect(piePosCombo, SIGNAL(currentIndexChanged(int)), | |
156 | this, SLOT(setPiePosition(int))); |
|
155 | this, SLOT(setPiePosition(int))); | |
157 | m_pieLayout = new QGridLayout(); |
|
156 | m_pieLayout = new QGridLayout(); | |
158 | m_pieLayout->setEnabled(false); |
|
157 | m_pieLayout->setEnabled(false); | |
159 | m_pieLayout->addWidget(new QLabel("Pie size factor"), 0, 0); |
|
158 | m_pieLayout->addWidget(new QLabel("Pie size factor"), 0, 0); | |
160 | m_pieLayout->addWidget(pieSizeSpin, 0, 1); |
|
159 | m_pieLayout->addWidget(pieSizeSpin, 0, 1); | |
161 | m_pieLayout->addWidget(new QLabel("Pie position"), 1, 0); |
|
160 | m_pieLayout->addWidget(new QLabel("Pie position"), 1, 0); | |
162 | m_pieLayout->addWidget(piePosCombo, 1, 1); |
|
161 | m_pieLayout->addWidget(piePosCombo, 1, 1); | |
163 | } |
|
162 | } | |
164 |
|
163 | |||
165 | void MainWidget::addSeries() |
|
164 | void MainWidget::addSeries() | |
166 | { |
|
165 | { | |
167 | DataSerieDialog dialog(m_defaultSeriesName, this); |
|
166 | DataSerieDialog dialog(m_defaultSeriesName, this); | |
168 | connect(&dialog, SIGNAL(accepted(QString, int, int, QString, bool)), |
|
167 | connect(&dialog, SIGNAL(accepted(QString, int, int, QString, bool)), | |
169 | this, SLOT(addSeries(QString, int, int, QString, bool))); |
|
168 | this, SLOT(addSeries(QString, int, int, QString, bool))); | |
170 | dialog.exec(); |
|
169 | dialog.exec(); | |
171 | } |
|
170 | } | |
172 |
|
171 | |||
173 | QList<RealList> MainWidget::generateTestData(int columnCount, int rowCount, QString dataCharacteristics) |
|
172 | QList<RealList> MainWidget::generateTestData(int columnCount, int rowCount, QString dataCharacteristics) | |
174 | { |
|
173 | { | |
175 | // TODO: dataCharacteristics |
|
174 | // TODO: dataCharacteristics | |
176 | QList<RealList> testData; |
|
175 | QList<RealList> testData; | |
177 | for (int j(0); j < columnCount; j++) { |
|
176 | for (int j(0); j < columnCount; j++) { | |
178 | QList <qreal> newColumn; |
|
177 | QList <qreal> newColumn; | |
179 | for (int i(0); i < rowCount; i++) { |
|
178 | for (int i(0); i < rowCount; i++) { | |
180 | if (dataCharacteristics == "Sin") { |
|
179 | if (dataCharacteristics == "Sin") { | |
181 | newColumn.append(abs(sin(3.14159265358979 / 50 * i) * 100)); |
|
180 | newColumn.append(abs(sin(3.14159265358979 / 50 * i) * 100)); | |
182 | } else if (dataCharacteristics == "Sin + random") { |
|
181 | } else if (dataCharacteristics == "Sin + random") { | |
183 | newColumn.append(abs(sin(3.14159265358979 / 50 * i) * 100) + (rand() % 5)); |
|
182 | newColumn.append(abs(sin(3.14159265358979 / 50 * i) * 100) + (rand() % 5)); | |
184 | } else if (dataCharacteristics == "Random") { |
|
183 | } else if (dataCharacteristics == "Random") { | |
185 | newColumn.append(rand() % 5); |
|
184 | newColumn.append(rand() % 5); | |
186 | } else if (dataCharacteristics == "Linear") { |
|
185 | } else if (dataCharacteristics == "Linear") { | |
187 | //newColumn.append(i * (j + 1.0)); |
|
186 | //newColumn.append(i * (j + 1.0)); | |
188 | // TODO: temporary hack to make pie work; prevent zero values: |
|
187 | // TODO: temporary hack to make pie work; prevent zero values: | |
189 | newColumn.append(i * (j + 1.0) + 0.1); |
|
188 | newColumn.append(i * (j + 1.0) + 0.1); | |
190 | } else { // "constant" |
|
189 | } else { // "constant" | |
191 | newColumn.append((j + 1.0)); |
|
190 | newColumn.append((j + 1.0)); | |
192 | } |
|
191 | } | |
193 | } |
|
192 | } | |
194 | testData.append(newColumn); |
|
193 | testData.append(newColumn); | |
195 | } |
|
194 | } | |
196 | return testData; |
|
195 | return testData; | |
197 | } |
|
196 | } | |
198 |
|
197 | |||
199 | QStringList MainWidget::generateLabels(int count) |
|
198 | QStringList MainWidget::generateLabels(int count) | |
200 | { |
|
199 | { | |
201 | QStringList result; |
|
200 | QStringList result; | |
202 | for (int i(0); i < count; i++) |
|
201 | for (int i(0); i < count; i++) | |
203 | result.append("label" + QString::number(i)); |
|
202 | result.append("label" + QString::number(i)); | |
204 | return result; |
|
203 | return result; | |
205 | } |
|
204 | } | |
206 |
|
205 | |||
207 | void MainWidget::addSeries(QString seriesName, int columnCount, int rowCount, QString dataCharacteristics, bool labelsEnabled) |
|
206 | void MainWidget::addSeries(QString seriesName, int columnCount, int rowCount, QString dataCharacteristics, bool labelsEnabled) | |
208 | { |
|
207 | { | |
209 | qDebug() << "addSeries: " << seriesName |
|
208 | qDebug() << "addSeries: " << seriesName | |
210 | << " columnCount: " << columnCount |
|
209 | << " columnCount: " << columnCount | |
211 | << " rowCount: " << rowCount |
|
210 | << " rowCount: " << rowCount | |
212 | << " dataCharacteristics: " << dataCharacteristics |
|
211 | << " dataCharacteristics: " << dataCharacteristics | |
213 | << " labels enabled: " << labelsEnabled; |
|
212 | << " labels enabled: " << labelsEnabled; | |
214 | m_defaultSeriesName = seriesName; |
|
213 | m_defaultSeriesName = seriesName; | |
215 |
|
214 | |||
216 | QList<RealList> data = generateTestData(columnCount, rowCount, dataCharacteristics); |
|
215 | QList<RealList> data = generateTestData(columnCount, rowCount, dataCharacteristics); | |
217 |
|
216 | |||
218 | // Line series and scatter series use similar data |
|
217 | // Line series and scatter series use similar data | |
219 | if (seriesName.contains("line", Qt::CaseInsensitive)) { |
|
218 | if (seriesName.contains("line", Qt::CaseInsensitive)) { | |
220 | for (int j(0); j < data.count(); j ++) { |
|
219 | for (int j(0); j < data.count(); j ++) { | |
221 | QList<qreal> column = data.at(j); |
|
220 | QList<qreal> column = data.at(j); | |
222 | QLineSeries *series = new QLineSeries(); |
|
221 | QLineSeries *series = new QLineSeries(); | |
223 | for (int i(0); i < column.count(); i++) { |
|
222 | for (int i(0); i < column.count(); i++) { | |
224 | series->add(i, column.at(i)); |
|
223 | series->add(i, column.at(i)); | |
225 | } |
|
224 | } | |
226 | m_chartWidget->addSeries(series); |
|
225 | m_chartWidget->addSeries(series); | |
227 | setCurrentSeries(series); |
|
226 | setCurrentSeries(series); | |
228 | } |
|
227 | } | |
229 | } else if (seriesName.contains("scatter", Qt::CaseInsensitive)) { |
|
228 | } else if (seriesName.contains("scatter", Qt::CaseInsensitive)) { | |
230 | for (int j(0); j < data.count(); j++) { |
|
229 | for (int j(0); j < data.count(); j++) { | |
231 | QList<qreal> column = data.at(j); |
|
230 | QList<qreal> column = data.at(j); | |
232 | QScatterSeries *series = new QScatterSeries(); |
|
231 | QScatterSeries *series = new QScatterSeries(); | |
233 | for (int i(0); i < column.count(); i++) { |
|
232 | for (int i(0); i < column.count(); i++) { | |
234 | (*series) << QPointF(i, column.at(i)); |
|
233 | (*series) << QPointF(i, column.at(i)); | |
235 | } |
|
234 | } | |
236 | m_chartWidget->addSeries(series); |
|
235 | m_chartWidget->addSeries(series); | |
237 | setCurrentSeries(series); |
|
236 | setCurrentSeries(series); | |
238 | } |
|
237 | } | |
239 | } else if (seriesName.contains("pie", Qt::CaseInsensitive)) { |
|
238 | } else if (seriesName.contains("pie", Qt::CaseInsensitive)) { | |
240 | QStringList labels = generateLabels(rowCount); |
|
239 | QStringList labels = generateLabels(rowCount); | |
241 | for (int j(0); j < data.count(); j++) { |
|
240 | for (int j(0); j < data.count(); j++) { | |
242 | QPieSeries *series = new QPieSeries(); |
|
241 | QPieSeries *series = new QPieSeries(); | |
243 | QList<qreal> column = data.at(j); |
|
242 | QList<qreal> column = data.at(j); | |
244 | for (int i(0); i < column.count(); i++) { |
|
243 | for (int i(0); i < column.count(); i++) { | |
245 | series->add(column.at(i), labels.at(i)); |
|
244 | series->add(column.at(i), labels.at(i)); | |
246 | } |
|
245 | } | |
247 | m_chartWidget->addSeries(series); |
|
246 | m_chartWidget->addSeries(series); | |
248 | setCurrentSeries(series); |
|
247 | setCurrentSeries(series); | |
249 | } |
|
248 | } | |
250 | } else if (seriesName == "Bar" |
|
249 | } else if (seriesName == "Bar" | |
251 | || seriesName == "Stacked bar" |
|
250 | || seriesName == "Stacked bar" | |
252 | || seriesName == "Percent bar") { |
|
251 | || seriesName == "Percent bar") { | |
253 | // TODO: replace QBarCategory with QStringList? |
|
252 | // TODO: replace QBarCategory with QStringList? | |
254 | QBarCategory *category = new QBarCategory; |
|
253 | QBarCategory *category = new QBarCategory; | |
255 | QStringList labels = generateLabels(rowCount); |
|
254 | QStringList labels = generateLabels(rowCount); | |
256 | foreach(QString label, labels) |
|
255 | foreach(QString label, labels) | |
257 | *category << label; |
|
256 | *category << label; | |
258 | QBarSeries* series = 0; |
|
257 | QBarSeries* series = 0; | |
259 | if (seriesName == "Bar") |
|
258 | if (seriesName == "Bar") | |
260 | series = new QBarSeries(category, this); |
|
259 | series = new QBarSeries(category, this); | |
261 | else if (seriesName == "Stacked bar") |
|
260 | else if (seriesName == "Stacked bar") | |
262 | series = new QStackedBarSeries(category, this); |
|
261 | series = new QStackedBarSeries(category, this); | |
263 | else |
|
262 | else | |
264 | series = new QPercentBarSeries(category, this); |
|
263 | series = new QPercentBarSeries(category, this); | |
265 |
|
264 | |||
266 | for (int j(0); j < data.count(); j++) { |
|
265 | for (int j(0); j < data.count(); j++) { | |
267 | QList<qreal> column = data.at(j); |
|
266 | QList<qreal> column = data.at(j); | |
268 | QBarSet *set = new QBarSet("set" + QString::number(j)); |
|
267 | QBarSet *set = new QBarSet("set" + QString::number(j)); | |
269 | for (int i(0); i < column.count(); i++) { |
|
268 | for (int i(0); i < column.count(); i++) { | |
270 | *set << column.at(i); |
|
269 | *set << column.at(i); | |
271 | } |
|
270 | } | |
272 | series->addBarSet(set); |
|
271 | series->addBarSet(set); | |
273 | } |
|
272 | } | |
274 | series->enableFloatingValues(); |
|
273 | series->enableFloatingValues(); | |
275 | series->setToolTipEnabled(); |
|
274 | series->setToolTipEnabled(); | |
276 | series->enableSeparators(false); |
|
275 | series->enableSeparators(false); | |
277 | m_chartWidget->addSeries(series); |
|
276 | m_chartWidget->addSeries(series); | |
278 | setCurrentSeries(series); |
|
277 | setCurrentSeries(series); | |
279 | } |
|
278 | } | |
280 |
|
279 | |||
281 | // TODO: spline and area |
|
280 | // TODO: spline and area | |
282 | } |
|
281 | } | |
283 |
|
282 | |||
284 |
void MainWidget::setCurrentSeries(Q |
|
283 | void MainWidget::setCurrentSeries(QSeries *series) | |
285 | { |
|
284 | { | |
286 | if (series) { |
|
285 | if (series) { | |
287 | m_currentSeries = series; |
|
286 | m_currentSeries = series; | |
288 | switch (m_currentSeries->type()) { |
|
287 | switch (m_currentSeries->type()) { | |
289 |
case Q |
|
288 | case QSeries::SeriesTypeLine: | |
290 | break; |
|
289 | break; | |
291 |
case Q |
|
290 | case QSeries::SeriesTypeScatter: | |
292 | break; |
|
291 | break; | |
293 |
case Q |
|
292 | case QSeries::SeriesTypePie: | |
294 | break; |
|
293 | break; | |
295 |
case Q |
|
294 | case QSeries::SeriesTypeBar: | |
296 | qDebug() << "setCurrentSeries (bar)"; |
|
295 | qDebug() << "setCurrentSeries (bar)"; | |
297 | break; |
|
296 | break; | |
298 |
case Q |
|
297 | case QSeries::SeriesTypeStackedBar: | |
299 | qDebug() << "setCurrentSeries (Stackedbar)"; |
|
298 | qDebug() << "setCurrentSeries (Stackedbar)"; | |
300 | break; |
|
299 | break; | |
301 |
case Q |
|
300 | case QSeries::SeriesTypePercentBar: | |
302 | qDebug() << "setCurrentSeries (Percentbar)"; |
|
301 | qDebug() << "setCurrentSeries (Percentbar)"; | |
303 | break; |
|
302 | break; | |
304 | default: |
|
303 | default: | |
305 | Q_ASSERT(false); |
|
304 | Q_ASSERT(false); | |
306 | break; |
|
305 | break; | |
307 | } |
|
306 | } | |
308 | } |
|
307 | } | |
309 | } |
|
308 | } | |
310 |
|
309 | |||
311 | void MainWidget::backgroundChanged(int itemIndex) |
|
310 | void MainWidget::backgroundChanged(int itemIndex) | |
312 | { |
|
311 | { | |
313 | qDebug() << "backgroundChanged: " << itemIndex; |
|
312 | qDebug() << "backgroundChanged: " << itemIndex; | |
314 | } |
|
313 | } | |
315 |
|
314 | |||
316 | void MainWidget::autoScaleChanged(int value) |
|
315 | void MainWidget::autoScaleChanged(int value) | |
317 | { |
|
316 | { | |
318 | if (value) { |
|
317 | if (value) { | |
319 | // TODO: enable auto scaling |
|
318 | // TODO: enable auto scaling | |
320 | } else { |
|
319 | } else { | |
321 | // TODO: set scaling manually (and disable auto scaling) |
|
320 | // TODO: set scaling manually (and disable auto scaling) | |
322 | } |
|
321 | } | |
323 |
|
322 | |||
324 | m_xMinSpin->setEnabled(!value); |
|
323 | m_xMinSpin->setEnabled(!value); | |
325 | m_xMaxSpin->setEnabled(!value); |
|
324 | m_xMaxSpin->setEnabled(!value); | |
326 | m_yMinSpin->setEnabled(!value); |
|
325 | m_yMinSpin->setEnabled(!value); | |
327 | m_yMaxSpin->setEnabled(!value); |
|
326 | m_yMaxSpin->setEnabled(!value); | |
328 | } |
|
327 | } | |
329 |
|
328 | |||
330 | void MainWidget::xMinChanged(int value) |
|
329 | void MainWidget::xMinChanged(int value) | |
331 | { |
|
330 | { | |
332 | qDebug() << "xMinChanged: " << value; |
|
331 | qDebug() << "xMinChanged: " << value; | |
333 | } |
|
332 | } | |
334 |
|
333 | |||
335 | void MainWidget::xMaxChanged(int value) |
|
334 | void MainWidget::xMaxChanged(int value) | |
336 | { |
|
335 | { | |
337 | qDebug() << "xMaxChanged: " << value; |
|
336 | qDebug() << "xMaxChanged: " << value; | |
338 | } |
|
337 | } | |
339 |
|
338 | |||
340 | void MainWidget::yMinChanged(int value) |
|
339 | void MainWidget::yMinChanged(int value) | |
341 | { |
|
340 | { | |
342 | qDebug() << "yMinChanged: " << value; |
|
341 | qDebug() << "yMinChanged: " << value; | |
343 | } |
|
342 | } | |
344 |
|
343 | |||
345 | void MainWidget::yMaxChanged(int value) |
|
344 | void MainWidget::yMaxChanged(int value) | |
346 | { |
|
345 | { | |
347 | qDebug() << "yMaxChanged: " << value; |
|
346 | qDebug() << "yMaxChanged: " << value; | |
348 | } |
|
347 | } | |
349 |
|
348 | |||
350 | void MainWidget::changeChartTheme(int themeIndex) |
|
349 | void MainWidget::changeChartTheme(int themeIndex) | |
351 | { |
|
350 | { | |
352 | qDebug() << "changeChartTheme: " << themeIndex; |
|
351 | qDebug() << "changeChartTheme: " << themeIndex; | |
353 | m_chartWidget->setChartTheme((QChart::ChartTheme) themeIndex); |
|
352 | m_chartWidget->setChartTheme((QChart::ChartTheme) themeIndex); | |
354 | //TODO: remove this hack. This is just to make it so that theme change is seen immediately. |
|
353 | //TODO: remove this hack. This is just to make it so that theme change is seen immediately. | |
355 | QSize s = size(); |
|
354 | QSize s = size(); | |
356 | s.setWidth(s.width()+1); |
|
355 | s.setWidth(s.width()+1); | |
357 | resize(s); |
|
356 | resize(s); | |
358 | } |
|
357 | } | |
359 |
|
358 | |||
360 | void MainWidget::setPieSizeFactor(double size) |
|
359 | void MainWidget::setPieSizeFactor(double size) | |
361 | { |
|
360 | { | |
362 | QPieSeries *pie = qobject_cast<QPieSeries *>(m_currentSeries); |
|
361 | QPieSeries *pie = qobject_cast<QPieSeries *>(m_currentSeries); | |
363 | if (pie) |
|
362 | if (pie) | |
364 | pie->setSizeFactor(qreal(size)); |
|
363 | pie->setSizeFactor(qreal(size)); | |
365 | } |
|
364 | } | |
366 |
|
365 | |||
367 | void MainWidget::setPiePosition(int position) |
|
366 | void MainWidget::setPiePosition(int position) | |
368 | { |
|
367 | { | |
369 | QPieSeries *pie = qobject_cast<QPieSeries *>(m_currentSeries); |
|
368 | QPieSeries *pie = qobject_cast<QPieSeries *>(m_currentSeries); | |
370 | if (pie) |
|
369 | if (pie) | |
371 | pie->setPosition((QPieSeries::PiePosition) position); |
|
370 | pie->setPosition((QPieSeries::PiePosition) position); | |
372 | } |
|
371 | } |
@@ -1,59 +1,59 | |||||
1 | #ifndef MAINWIDGET_H |
|
1 | #ifndef MAINWIDGET_H | |
2 | #define MAINWIDGET_H |
|
2 | #define MAINWIDGET_H | |
3 |
|
3 | |||
4 | #include <qchartglobal.h> |
|
4 | #include <qchartglobal.h> | |
5 | #include <qchartview.h> |
|
5 | #include <qchartview.h> | |
6 | #include <QWidget> |
|
6 | #include <QWidget> | |
7 |
|
7 | |||
8 | class QSpinBox; |
|
8 | class QSpinBox; | |
9 | class QCheckBox; |
|
9 | class QCheckBox; | |
10 | class QGridLayout; |
|
10 | class QGridLayout; | |
11 |
|
11 | |||
12 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
12 | QTCOMMERCIALCHART_USE_NAMESPACE | |
13 |
|
13 | |||
14 | #define RealList QList<qreal> |
|
14 | #define RealList QList<qreal> | |
15 |
|
15 | |||
16 | class MainWidget : public QWidget |
|
16 | class MainWidget : public QWidget | |
17 | { |
|
17 | { | |
18 | Q_OBJECT |
|
18 | Q_OBJECT | |
19 | public: |
|
19 | public: | |
20 | explicit MainWidget(QWidget *parent = 0); |
|
20 | explicit MainWidget(QWidget *parent = 0); | |
21 |
|
21 | |||
22 | signals: |
|
22 | signals: | |
23 |
|
23 | |||
24 | private: |
|
24 | private: | |
25 | void initBackroundCombo(QGridLayout *grid); |
|
25 | void initBackroundCombo(QGridLayout *grid); | |
26 | void initScaleControls(QGridLayout *grid); |
|
26 | void initScaleControls(QGridLayout *grid); | |
27 | void initThemeCombo(QGridLayout *grid); |
|
27 | void initThemeCombo(QGridLayout *grid); | |
28 | void initPieControls(); |
|
28 | void initPieControls(); | |
29 |
|
29 | |||
30 | private slots: |
|
30 | private slots: | |
31 | void addSeries(); |
|
31 | void addSeries(); | |
32 | void addSeries(QString series, int columnCount, int rowCount, QString dataCharacteristics, bool labelsEnabled); |
|
32 | void addSeries(QString series, int columnCount, int rowCount, QString dataCharacteristics, bool labelsEnabled); | |
33 | void backgroundChanged(int itemIndex); |
|
33 | void backgroundChanged(int itemIndex); | |
34 | void autoScaleChanged(int value); |
|
34 | void autoScaleChanged(int value); | |
35 | void xMinChanged(int value); |
|
35 | void xMinChanged(int value); | |
36 | void xMaxChanged(int value); |
|
36 | void xMaxChanged(int value); | |
37 | void yMinChanged(int value); |
|
37 | void yMinChanged(int value); | |
38 | void yMaxChanged(int value); |
|
38 | void yMaxChanged(int value); | |
39 |
void setCurrentSeries(Q |
|
39 | void setCurrentSeries(QSeries *series); | |
40 | void changeChartTheme(int themeIndex); |
|
40 | void changeChartTheme(int themeIndex); | |
41 | void setPieSizeFactor(double margin); |
|
41 | void setPieSizeFactor(double margin); | |
42 | void setPiePosition(int position); |
|
42 | void setPiePosition(int position); | |
43 | QList<RealList> generateTestData(int columnCount, int rowCount, QString dataCharacteristics); |
|
43 | QList<RealList> generateTestData(int columnCount, int rowCount, QString dataCharacteristics); | |
44 | QStringList generateLabels(int count); |
|
44 | QStringList generateLabels(int count); | |
45 |
|
45 | |||
46 | private: |
|
46 | private: | |
47 | QChartView *m_chartWidget; |
|
47 | QChartView *m_chartWidget; | |
48 | QCheckBox *m_autoScaleCheck; |
|
48 | QCheckBox *m_autoScaleCheck; | |
49 | QSpinBox *m_xMinSpin; |
|
49 | QSpinBox *m_xMinSpin; | |
50 | QSpinBox *m_xMaxSpin; |
|
50 | QSpinBox *m_xMaxSpin; | |
51 | QSpinBox *m_yMinSpin; |
|
51 | QSpinBox *m_yMinSpin; | |
52 | QSpinBox *m_yMaxSpin; |
|
52 | QSpinBox *m_yMaxSpin; | |
53 | QString m_defaultSeriesName; |
|
53 | QString m_defaultSeriesName; | |
54 |
Q |
|
54 | QSeries *m_currentSeries; | |
55 | QGridLayout *m_scatterLayout; |
|
55 | QGridLayout *m_scatterLayout; | |
56 | QGridLayout *m_pieLayout; |
|
56 | QGridLayout *m_pieLayout; | |
57 | }; |
|
57 | }; | |
58 |
|
58 | |||
59 | #endif // MAINWIDGET_H |
|
59 | #endif // MAINWIDGET_H |
General Comments 0
You need to be logged in to leave comments.
Login now