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