##// END OF EJS Templates
QBar series: Model related members initializations added to constructor
Marek Rosa -
r528:631ae1704892
parent child
Show More
@@ -1,245 +1,249
1 #include <QDebug>
1 #include <QDebug>
2 #include "qbarseries.h"
2 #include "qbarseries.h"
3 #include "qbarset.h"
3 #include "qbarset.h"
4 #include "barchartmodel_p.h"
4 #include "barchartmodel_p.h"
5
5
6 QTCOMMERCIALCHART_BEGIN_NAMESPACE
6 QTCOMMERCIALCHART_BEGIN_NAMESPACE
7
7
8 /*!
8 /*!
9 \class QBarSeries
9 \class QBarSeries
10 \brief part of QtCommercial chart API.
10 \brief part of QtCommercial chart API.
11
11
12 QBarSeries represents a series of data shown as bars. One QBarSeries can contain multible
12 QBarSeries represents a series of data shown as bars. One QBarSeries can contain multible
13 QBarSet data sets. QBarSeries groups the data from sets to categories, which are defined
13 QBarSet data sets. QBarSeries groups the data from sets to categories, which are defined
14 by QStringList.
14 by QStringList.
15
15
16 \mainclass
16 \mainclass
17
17
18 \sa QBarSet, QStackedBarSeries, QPercentBarSeries
18 \sa QBarSet, QStackedBarSeries, QPercentBarSeries
19 */
19 */
20
20
21 /*!
21 /*!
22 \fn virtual QSeriesType QBarSeries::type() const
22 \fn virtual QSeriesType QBarSeries::type() const
23 \brief Returns type of series.
23 \brief Returns type of series.
24 \sa QSeries, QSeriesType
24 \sa QSeries, QSeriesType
25 */
25 */
26
26
27 /*!
27 /*!
28 \fn void QBarSeries::showToolTip(QPoint pos, QString tip)
28 \fn void QBarSeries::showToolTip(QPoint pos, QString tip)
29 \brief \internal \a pos \a tip
29 \brief \internal \a pos \a tip
30 */
30 */
31
31
32 /*!
32 /*!
33 Constructs empty QBarSeries. Parameter \a categories defines the categories for chart.
33 Constructs empty QBarSeries. Parameter \a categories defines the categories for chart.
34 QBarSeries is QObject which is a child of a \a parent.
34 QBarSeries is QObject which is a child of a \a parent.
35 */
35 */
36 QBarSeries::QBarSeries(QStringList categories, QObject *parent)
36 QBarSeries::QBarSeries(QStringList categories, QObject *parent)
37 : QSeries(parent)
37 : QSeries(parent)
38 ,mModel(new BarChartModel(categories, this))
38 ,mModel(new BarChartModel(categories, this))
39 {
39 {
40 m_model = NULL;
41 m_mapCategories = -1;
42 m_mapBarBottom - 1;
43 m_mapBarTop - 1;
40 }
44 }
41
45
42 /*!
46 /*!
43 Adds a set of bars to series. Takes ownership of \a set.
47 Adds a set of bars to series. Takes ownership of \a set.
44 Connects the clicked(QString) and rightClicked(QString) signals
48 Connects the clicked(QString) and rightClicked(QString) signals
45 of \a set to this series
49 of \a set to this series
46 */
50 */
47 void QBarSeries::addBarSet(QBarSet *set)
51 void QBarSeries::addBarSet(QBarSet *set)
48 {
52 {
49 mModel->addBarSet(set);
53 mModel->addBarSet(set);
50 connect(set,SIGNAL(clicked(QString)),this,SLOT(barsetClicked(QString)));
54 connect(set,SIGNAL(clicked(QString)),this,SLOT(barsetClicked(QString)));
51 connect(set,SIGNAL(rightClicked(QString)),this,SLOT(barsetRightClicked(QString)));
55 connect(set,SIGNAL(rightClicked(QString)),this,SLOT(barsetRightClicked(QString)));
52 }
56 }
53
57
54 /*!
58 /*!
55 Removes a set of bars from series. Releases ownership of \a set. Doesnt delete \a set.
59 Removes a set of bars from series. Releases ownership of \a set. Doesnt delete \a set.
56 Disconnects the clicked(QString) and rightClicked(QString) signals
60 Disconnects the clicked(QString) and rightClicked(QString) signals
57 of \a set from this series
61 of \a set from this series
58 */
62 */
59 void QBarSeries::removeBarSet(QBarSet *set)
63 void QBarSeries::removeBarSet(QBarSet *set)
60 {
64 {
61 disconnect(set,SIGNAL(clicked(QString)),this,SLOT(barsetClicked(QString)));
65 disconnect(set,SIGNAL(clicked(QString)),this,SLOT(barsetClicked(QString)));
62 disconnect(set,SIGNAL(rightClicked(QString)),this,SLOT(barsetRightClicked(QString)));
66 disconnect(set,SIGNAL(rightClicked(QString)),this,SLOT(barsetRightClicked(QString)));
63 mModel->removeBarSet(set);
67 mModel->removeBarSet(set);
64 }
68 }
65
69
66 /*!
70 /*!
67 Returns number of sets in series.
71 Returns number of sets in series.
68 */
72 */
69 int QBarSeries::barsetCount()
73 int QBarSeries::barsetCount()
70 {
74 {
71 if(m_model)
75 if(m_model)
72 return m_mapBarTop - m_mapBarBottom;
76 return m_mapBarTop - m_mapBarBottom;
73 else
77 else
74 return mModel->barsetCount();
78 return mModel->barsetCount();
75 }
79 }
76
80
77 /*!
81 /*!
78 Returns number of categories in series
82 Returns number of categories in series
79 */
83 */
80 int QBarSeries::categoryCount()
84 int QBarSeries::categoryCount()
81 {
85 {
82 return mModel->categoryCount();
86 return mModel->categoryCount();
83 }
87 }
84
88
85 /*!
89 /*!
86 Returns a list of sets in series. Keeps ownership of sets.
90 Returns a list of sets in series. Keeps ownership of sets.
87 */
91 */
88 QList<QBarSet*> QBarSeries::barSets()
92 QList<QBarSet*> QBarSeries::barSets()
89 {
93 {
90 return mModel->barSets();
94 return mModel->barSets();
91 }
95 }
92
96
93 /*!
97 /*!
94 \internal \a index
98 \internal \a index
95 */
99 */
96 QBarSet* QBarSeries::barsetAt(int index)
100 QBarSet* QBarSeries::barsetAt(int index)
97 {
101 {
98 return mModel->setAt(index);
102 return mModel->setAt(index);
99 }
103 }
100
104
101 /*!
105 /*!
102 Returns legend of series.
106 Returns legend of series.
103 */
107 */
104 QList<QSeries::LegendEntry> QBarSeries::legendEntries()
108 QList<QSeries::LegendEntry> QBarSeries::legendEntries()
105 {
109 {
106 return mModel->legendEntries();
110 return mModel->legendEntries();
107 }
111 }
108
112
109 /*!
113 /*!
110 \internal \a category
114 \internal \a category
111 */
115 */
112 QString QBarSeries::categoryName(int category)
116 QString QBarSeries::categoryName(int category)
113 {
117 {
114 return mModel->categoryName(category);
118 return mModel->categoryName(category);
115 }
119 }
116
120
117 /*!
121 /*!
118 Enables or disables tooltip depending on parameter \a enabled.
122 Enables or disables tooltip depending on parameter \a enabled.
119 Tooltip shows the name of set, when mouse is hovering on top of bar.
123 Tooltip shows the name of set, when mouse is hovering on top of bar.
120 Calling without parameter \a enabled, enables the tooltip
124 Calling without parameter \a enabled, enables the tooltip
121 */
125 */
122 void QBarSeries::setToolTipEnabled(bool enabled)
126 void QBarSeries::setToolTipEnabled(bool enabled)
123 {
127 {
124 // TODO: what if we add sets after call to this function? Those sets won't have tooltip enabled.
128 // TODO: what if we add sets after call to this function? Those sets won't have tooltip enabled.
125 if (enabled) {
129 if (enabled) {
126 for (int i=0; i<mModel->barsetCount(); i++) {
130 for (int i=0; i<mModel->barsetCount(); i++) {
127 QBarSet *set = mModel->setAt(i);
131 QBarSet *set = mModel->setAt(i);
128 connect(set,SIGNAL(showToolTip(QPoint,QString)),this,SIGNAL(showToolTip(QPoint,QString)));
132 connect(set,SIGNAL(showToolTip(QPoint,QString)),this,SIGNAL(showToolTip(QPoint,QString)));
129 }
133 }
130 } else {
134 } else {
131 for (int i=0; i<mModel->barsetCount(); i++) {
135 for (int i=0; i<mModel->barsetCount(); i++) {
132 QBarSet *set = mModel->setAt(i);
136 QBarSet *set = mModel->setAt(i);
133 disconnect(set,SIGNAL(showToolTip(QPoint,QString)),this,SIGNAL(showToolTip(QPoint,QString)));
137 disconnect(set,SIGNAL(showToolTip(QPoint,QString)),this,SIGNAL(showToolTip(QPoint,QString)));
134 }
138 }
135 }
139 }
136 }
140 }
137
141
138 /*!
142 /*!
139 Enables or disables separators depending on parameter \a enabled.
143 Enables or disables separators depending on parameter \a enabled.
140 Separators are visual elements that are drawn between categories.
144 Separators are visual elements that are drawn between categories.
141 Calling without parameter \a enabled, enables the separators
145 Calling without parameter \a enabled, enables the separators
142 */
146 */
143 void QBarSeries::setSeparatorsVisible(bool visible)
147 void QBarSeries::setSeparatorsVisible(bool visible)
144 {
148 {
145 mSeparatorsVisible = visible;
149 mSeparatorsVisible = visible;
146 emit enableSeparators(visible);
150 emit enableSeparators(visible);
147 }
151 }
148
152
149
153
150 /*!
154 /*!
151 \internal \a category
155 \internal \a category
152 */
156 */
153 void QBarSeries::barsetClicked(QString category)
157 void QBarSeries::barsetClicked(QString category)
154 {
158 {
155 emit clicked(qobject_cast<QBarSet*>(sender()), category);
159 emit clicked(qobject_cast<QBarSet*>(sender()), category);
156 }
160 }
157
161
158 /*!
162 /*!
159 \internal \a category
163 \internal \a category
160 */
164 */
161 void QBarSeries::barsetRightClicked(QString category)
165 void QBarSeries::barsetRightClicked(QString category)
162 {
166 {
163 emit rightClicked(qobject_cast<QBarSet*>(sender()), category);
167 emit rightClicked(qobject_cast<QBarSet*>(sender()), category);
164 }
168 }
165
169
166
170
167 /*!
171 /*!
168 \internal
172 \internal
169 */
173 */
170 qreal QBarSeries::min()
174 qreal QBarSeries::min()
171 {
175 {
172 return mModel->min();
176 return mModel->min();
173 }
177 }
174
178
175 /*!
179 /*!
176 \internal
180 \internal
177 */
181 */
178 qreal QBarSeries::max()
182 qreal QBarSeries::max()
179 {
183 {
180 return mModel->max();
184 return mModel->max();
181 }
185 }
182
186
183 /*!
187 /*!
184 \internal \a set \a category
188 \internal \a set \a category
185 */
189 */
186 qreal QBarSeries::valueAt(int set, int category)
190 qreal QBarSeries::valueAt(int set, int category)
187 {
191 {
188 return mModel->valueAt(set,category);
192 return mModel->valueAt(set,category);
189 }
193 }
190
194
191 /*!
195 /*!
192 \internal \a set \a category
196 \internal \a set \a category
193 */
197 */
194 qreal QBarSeries::percentageAt(int set, int category)
198 qreal QBarSeries::percentageAt(int set, int category)
195 {
199 {
196 return mModel->percentageAt(set,category);
200 return mModel->percentageAt(set,category);
197 }
201 }
198
202
199 /*!
203 /*!
200 \internal \a category
204 \internal \a category
201 */
205 */
202 qreal QBarSeries::categorySum(int category)
206 qreal QBarSeries::categorySum(int category)
203 {
207 {
204 return mModel->categorySum(category);
208 return mModel->categorySum(category);
205 }
209 }
206
210
207 /*!
211 /*!
208 \internal
212 \internal
209 */
213 */
210 qreal QBarSeries::maxCategorySum()
214 qreal QBarSeries::maxCategorySum()
211 {
215 {
212 return mModel->maxCategorySum();
216 return mModel->maxCategorySum();
213 }
217 }
214
218
215 /*!
219 /*!
216 \internal
220 \internal
217 */
221 */
218 BarChartModel& QBarSeries::model()
222 BarChartModel& QBarSeries::model()
219 {
223 {
220 return *mModel;
224 return *mModel;
221 }
225 }
222
226
223 bool QBarSeries::separatorsVisible()
227 bool QBarSeries::separatorsVisible()
224 {
228 {
225 return mSeparatorsVisible;
229 return mSeparatorsVisible;
226 }
230 }
227
231
228 bool QBarSeries::setModel(QAbstractItemModel* model)
232 bool QBarSeries::setModel(QAbstractItemModel* model)
229 {
233 {
230 m_model = model;
234 m_model = model;
231 }
235 }
232
236
233 void QBarSeries::setModelMappingCategories(int modelColumn)
237 void QBarSeries::setModelMappingCategories(int modelColumn)
234 {
238 {
235 //
239 //
236 }
240 }
237
241
238 void QBarSeries::setModelMappingBarRange(int bottomBoundry, int topBoundry)
242 void QBarSeries::setModelMappingBarRange(int bottomBoundry, int topBoundry)
239 {
243 {
240 //
244 //
241 }
245 }
242
246
243 #include "moc_qbarseries.cpp"
247 #include "moc_qbarseries.cpp"
244
248
245 QTCOMMERCIALCHART_END_NAMESPACE
249 QTCOMMERCIALCHART_END_NAMESPACE
General Comments 0
You need to be logged in to leave comments. Login now