@@ -1,243 +1,244 | |||
|
1 | 1 | #include <QDebug> |
|
2 | 2 | #include "qbarchartseries.h" |
|
3 | 3 | #include "qbarcategory.h" |
|
4 | 4 | #include "qbarset.h" |
|
5 | 5 | #include "barchartmodel_p.h" |
|
6 | 6 | |
|
7 | 7 | |
|
8 | 8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
9 | 9 | |
|
10 | 10 | /*! |
|
11 | 11 | \class QBarChartSeries |
|
12 | 12 | \brief part of QtCommercial chart API. |
|
13 | 13 | |
|
14 | 14 | QBarChartSeries represents a series of data shown as bars. One QBarChartSeries can contain multible |
|
15 | 15 | QBarSet data sets. QBarChartSeries groups the data from sets to categories, which are defined |
|
16 | 16 | by QBarCategory class. |
|
17 | 17 | |
|
18 | 18 | \mainclass |
|
19 | 19 | |
|
20 | 20 | Example on how to add sets to bar chart: |
|
21 | 21 | \snippet ../example/barchart/main.cpp 2 |
|
22 | 22 | |
|
23 | 23 | |
|
24 | 24 | Example on how to enable tooltip and floating values: |
|
25 | 25 | \snippet ../example/barchart/main.cpp 3 |
|
26 | 26 | |
|
27 | 27 | \sa QBarCategory, QBarSet, QStackedBarChartSeries, QPercentBarChartSeries |
|
28 | 28 | */ |
|
29 | 29 | |
|
30 | 30 | /*! |
|
31 | 31 | \fn virtual QChartSeriesType QBarChartSeries::type() const |
|
32 | 32 | \brief Returns type of series. |
|
33 | 33 | \sa QChartSeries, QChartSeriesType |
|
34 | 34 | */ |
|
35 | 35 | /*! |
|
36 | 36 | \fn void QBarChartSeries::changed(int index) |
|
37 | 37 | \brief \internal \a index |
|
38 | 38 | */ |
|
39 | 39 | /*! |
|
40 | 40 | \fn void QBarChartSeries::floatingValuesEnabled(bool enabled) |
|
41 | 41 | \brief \internal \a enabled |
|
42 | 42 | */ |
|
43 | 43 | /*! |
|
44 | 44 | \fn void QBarChartSeries::toolTipEnabled(bool enabled) |
|
45 | 45 | \brief \internal \a enabled |
|
46 | 46 | */ |
|
47 | 47 | /*! |
|
48 | 48 | \fn void QBarChartSeries::separatorsEnabled(bool enabled) |
|
49 | 49 | \brief \internal \a enabled |
|
50 | 50 | */ |
|
51 | 51 | /*! |
|
52 | 52 | \fn void QBarChartSeries::showToolTip(QPoint pos, QString tip) |
|
53 | 53 | \brief \internal \a pos \a tip |
|
54 | 54 | */ |
|
55 | 55 | |
|
56 | 56 | /*! |
|
57 | 57 | Constructs empty QBarChartSeries. Parameter \a category defines the categories for chart. |
|
58 | Takes ownership of \a category. | |
|
58 | 59 | QBarChartSeries is QObject which is a child of a \a parent. |
|
59 | 60 | */ |
|
60 | 61 | QBarChartSeries::QBarChartSeries(QBarCategory *category, QObject *parent) |
|
61 | 62 | : QChartSeries(parent) |
|
62 | 63 | ,mModel(new BarChartModel(category, this)) |
|
63 | 64 | { |
|
64 | 65 | } |
|
65 | 66 | |
|
66 | 67 | /*! |
|
67 | 68 | Adds a set of bars to series. Takes ownership of \a set |
|
68 | 69 | */ |
|
69 | 70 | void QBarChartSeries::addBarSet(QBarSet *set) |
|
70 | 71 | { |
|
71 | 72 | mModel->addBarSet(set); |
|
72 | 73 | } |
|
73 | 74 | |
|
74 | 75 | /*! |
|
75 | 76 | Removes a set of bars from series. Releases ownership of \a set. Doesnt delete \a set. |
|
76 | 77 | */ |
|
77 | 78 | void QBarChartSeries::removeBarSet(QBarSet *set) |
|
78 | 79 | { |
|
79 | 80 | mModel->removeBarSet(set); |
|
80 | 81 | } |
|
81 | 82 | |
|
82 | 83 | /*! |
|
83 | 84 | Returns number of sets in series. |
|
84 | 85 | */ |
|
85 | 86 | int QBarChartSeries::countSets() |
|
86 | 87 | { |
|
87 | 88 | return mModel->countSets(); |
|
88 | 89 | } |
|
89 | 90 | |
|
90 | 91 | /*! |
|
92 | Returns number of categories in series | |
|
93 | */ | |
|
94 | int QBarChartSeries::countCategories() | |
|
95 | { | |
|
96 | return mModel->countCategories(); | |
|
97 | } | |
|
98 | ||
|
99 | /*! | |
|
91 | 100 | Simple iterator for set. Returns pointer to next set in series. |
|
92 | 101 | Returns first set, if parameter \a getFirst is true. |
|
93 | 102 | If series is empty, returns 0. |
|
94 | 103 | Returns 0 after last set. |
|
95 | 104 | */ |
|
96 | 105 | QBarSet* QBarChartSeries::nextSet(bool getFirst) |
|
97 | 106 | { |
|
98 | 107 | return mModel->nextSet(getFirst); |
|
99 | 108 | } |
|
100 | 109 | |
|
101 | 110 | /*! |
|
102 | 111 | Returns set indexed by \a index. Doesn't check for index bounds. |
|
103 | 112 | Assumes that \a index is between 0 and number of sets. Use countSets() to get valid index bound. |
|
104 | 113 | \sa countSets() |
|
105 | 114 | */ |
|
106 | 115 | QBarSet* QBarChartSeries::setAt(int index) |
|
107 | 116 | { |
|
108 | 117 | return mModel->setAt(index); |
|
109 | 118 | } |
|
110 | 119 | |
|
111 | 120 | /*! |
|
112 | 121 | Returns legend of series. Legend is a list of set names in series. |
|
113 | 122 | */ |
|
114 | 123 | QList<QString> QBarChartSeries::legend() |
|
115 | 124 | { |
|
116 | 125 | return mModel->legend(); |
|
117 | 126 | } |
|
118 | 127 | |
|
119 | 128 | /*! |
|
120 | 129 | \internal \a category |
|
121 | 130 | */ |
|
122 | 131 | QString QBarChartSeries::label(int category) |
|
123 | 132 | { |
|
124 | 133 | return mModel->label(category); |
|
125 | 134 | } |
|
126 | 135 | |
|
127 | 136 | /*! |
|
128 | 137 | Enables or disables floating values depending on parameter \a enabled. |
|
129 | 138 | Floating values are bar values, that are displayed on top of each bar. |
|
130 | 139 | Calling without parameter \a enabled, enables the floating values |
|
131 | 140 | */ |
|
132 | 141 | void QBarChartSeries::enableFloatingValues(bool enabled) |
|
133 | 142 | { |
|
134 | 143 | if (enabled) { |
|
135 | 144 | for (int i=0; i<mModel->countSets(); i++) { |
|
136 | 145 | QBarSet *set = mModel->setAt(i); |
|
137 | 146 | connect(set,SIGNAL(clicked()),set,SIGNAL(toggleFloatingValues())); |
|
138 | 147 | } |
|
139 | 148 | } else { |
|
140 | 149 | for (int i=0; i<mModel->countSets(); i++) { |
|
141 | 150 | QBarSet *set = mModel->setAt(i); |
|
142 | 151 | disconnect(set,SIGNAL(clicked()),set,SIGNAL(toggleFloatingValues())); |
|
143 | 152 | } |
|
144 | 153 | } |
|
145 | 154 | } |
|
146 | 155 | |
|
147 | 156 | /*! |
|
148 | 157 | Enables or disables tooltip depending on parameter \a enabled. |
|
149 | 158 | Tooltip shows the name of set, when mouse is hovering on top of bar. |
|
150 | 159 | Calling without parameter \a enabled, enables the tooltip |
|
151 | 160 | */ |
|
152 | 161 | void QBarChartSeries::enableToolTip(bool enabled) |
|
153 | 162 | { |
|
154 | 163 | if (enabled) { |
|
155 | 164 | for (int i=0; i<mModel->countSets(); i++) { |
|
156 | 165 | QBarSet *set = mModel->setAt(i); |
|
157 | 166 | connect(set,SIGNAL(showToolTip(QPoint,QString)),this,SIGNAL(showToolTip(QPoint,QString))); |
|
158 | 167 | } |
|
159 | 168 | } else { |
|
160 | 169 | for (int i=0; i<mModel->countSets(); i++) { |
|
161 | 170 | QBarSet *set = mModel->setAt(i); |
|
162 | 171 | disconnect(set,SIGNAL(showToolTip(QPoint,QString)),this,SIGNAL(showToolTip(QPoint,QString))); |
|
163 | 172 | } |
|
164 | 173 | } |
|
165 | 174 | } |
|
166 | 175 | |
|
167 | 176 | /*! |
|
168 | 177 | Enables or disables separators depending on parameter \a enabled. |
|
169 | 178 | Separators are visual elements that are drawn between categories. |
|
170 | 179 | Calling without parameter \a enabled, enables the separators |
|
171 | 180 | */ |
|
172 | 181 | void QBarChartSeries::enableSeparators(bool enabled) |
|
173 | 182 | { |
|
174 | 183 | emit separatorsEnabled(enabled); |
|
175 | 184 | } |
|
176 | 185 | |
|
177 | 186 | /*! |
|
178 | 187 | \internal |
|
179 | 188 | */ |
|
180 | int QBarChartSeries::countCategories() | |
|
181 | { | |
|
182 | return mModel->countCategories(); | |
|
183 | } | |
|
184 | ||
|
185 | /*! | |
|
186 | \internal | |
|
187 | */ | |
|
188 | 189 | qreal QBarChartSeries::min() |
|
189 | 190 | { |
|
190 | 191 | return mModel->min(); |
|
191 | 192 | } |
|
192 | 193 | |
|
193 | 194 | /*! |
|
194 | 195 | \internal |
|
195 | 196 | */ |
|
196 | 197 | qreal QBarChartSeries::max() |
|
197 | 198 | { |
|
198 | 199 | return mModel->max(); |
|
199 | 200 | } |
|
200 | 201 | |
|
201 | 202 | /*! |
|
202 | 203 | \internal \a set \a category |
|
203 | 204 | */ |
|
204 | 205 | qreal QBarChartSeries::valueAt(int set, int category) |
|
205 | 206 | { |
|
206 | 207 | return mModel->valueAt(set,category); |
|
207 | 208 | } |
|
208 | 209 | |
|
209 | 210 | /*! |
|
210 | 211 | \internal \a set \a category |
|
211 | 212 | */ |
|
212 | 213 | qreal QBarChartSeries::percentageAt(int set, int category) |
|
213 | 214 | { |
|
214 | 215 | return mModel->percentageAt(set,category); |
|
215 | 216 | } |
|
216 | 217 | |
|
217 | 218 | /*! |
|
218 | 219 | \internal \a category |
|
219 | 220 | */ |
|
220 | 221 | qreal QBarChartSeries::categorySum(int category) |
|
221 | 222 | { |
|
222 | 223 | return mModel->categorySum(category); |
|
223 | 224 | } |
|
224 | 225 | |
|
225 | 226 | /*! |
|
226 | 227 | \internal |
|
227 | 228 | */ |
|
228 | 229 | qreal QBarChartSeries::maxCategorySum() |
|
229 | 230 | { |
|
230 | 231 | return mModel->maxCategorySum(); |
|
231 | 232 | } |
|
232 | 233 | |
|
233 | 234 | /*! |
|
234 | 235 | \internal |
|
235 | 236 | */ |
|
236 | 237 | BarChartModel& QBarChartSeries::model() |
|
237 | 238 | { |
|
238 | 239 | return *mModel; |
|
239 | 240 | } |
|
240 | 241 | |
|
241 | 242 | #include "moc_qbarchartseries.cpp" |
|
242 | 243 | |
|
243 | 244 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,66 +1,66 | |||
|
1 | 1 | #ifndef BARCHARTSERIES_H |
|
2 | 2 | #define BARCHARTSERIES_H |
|
3 | 3 | |
|
4 | 4 | #include "qchartseries.h" |
|
5 | 5 | |
|
6 | 6 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
7 | 7 | |
|
8 | 8 | class QBarCategory; |
|
9 | 9 | class QBarSet; |
|
10 | 10 | class BarChartModel; |
|
11 | 11 | |
|
12 | 12 | // Container for series |
|
13 | 13 | class QTCOMMERCIALCHART_EXPORT QBarChartSeries : public QChartSeries |
|
14 | 14 | { |
|
15 | 15 | Q_OBJECT |
|
16 | 16 | public: |
|
17 | 17 | QBarChartSeries(QBarCategory *category, QObject* parent=0); |
|
18 | 18 | |
|
19 | 19 | virtual QChartSeriesType type() const { return QChartSeries::SeriesTypeBar; } |
|
20 | 20 | |
|
21 | 21 | void addBarSet(QBarSet *set); // Takes ownership of set |
|
22 | 22 | void removeBarSet(QBarSet *set); // Releases ownership, doesn't delete set |
|
23 | 23 | int countSets(); |
|
24 | int countCategories(); | |
|
24 | 25 | QBarSet* nextSet(bool getFirst=false); // Returns first set, if called with true |
|
25 | 26 | QBarSet *setAt(int index); |
|
26 | 27 | |
|
27 | 28 | QList<QString> legend(); // Returns legend of series (ie. names of all sets in series) |
|
28 | 29 | |
|
29 | 30 | public: |
|
30 | 31 | // TODO: Functions below this are not part of api and will be moved |
|
31 | 32 | // to private implementation, when we start using it |
|
32 | 33 | // TODO: TO PIMPL ---> |
|
33 | 34 | QString label(int category); |
|
34 | int countCategories(); | |
|
35 | 35 | qreal min(); |
|
36 | 36 | qreal max(); |
|
37 | 37 | qreal valueAt(int set, int category); |
|
38 | 38 | qreal percentageAt(int set, int category); |
|
39 | 39 | qreal categorySum(int category); |
|
40 | 40 | qreal maxCategorySum(); |
|
41 | 41 | BarChartModel& model(); |
|
42 | 42 | // <--- TO PIMPL |
|
43 | 43 | |
|
44 | 44 | signals: |
|
45 | 45 | void changed(int index); |
|
46 | 46 | |
|
47 | 47 | // TODO: internal signals, these to private implementation. |
|
48 | 48 | // TODO: TO PIMPL ---> |
|
49 | 49 | void floatingValuesEnabled(bool enabled); |
|
50 | 50 | void toolTipEnabled(bool enabled); |
|
51 | 51 | void separatorsEnabled(bool enabled); |
|
52 | 52 | void showToolTip(QPoint pos, QString tip); |
|
53 | 53 | // <--- TO PIMPL |
|
54 | 54 | |
|
55 | 55 | public Q_SLOTS: |
|
56 | 56 | void enableFloatingValues(bool enabled=true); // enables floating values on top of bars |
|
57 | 57 | void enableToolTip(bool enabled=true); // enables tooltips |
|
58 | 58 | void enableSeparators(bool enabled=true); // enables separators between categories |
|
59 | 59 | |
|
60 | 60 | protected: |
|
61 | 61 | BarChartModel* mModel; |
|
62 | 62 | }; |
|
63 | 63 | |
|
64 | 64 | QTCOMMERCIALCHART_END_NAMESPACE |
|
65 | 65 | |
|
66 | 66 | #endif // BARCHARTSERIES_H |
General Comments 0
You need to be logged in to leave comments.
Login now