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