##// END OF EJS Templates
Fix vs build problems with bar
Jani Honkonen -
r944:6214fa3e1743
parent child
Show More
@@ -1,128 +1,127
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #ifndef BARSERIES_H
22 22 #define BARSERIES_H
23 23
24 24 #include <qseries.h>
25 25 #include <QStringList>
26 26
27 27 class QModelIndex;
28 28
29 29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30 30
31 31 typedef QStringList QBarCategories;
32 32
33 33 class QBarSet;
34 34 class BarChartModel;
35 35 class BarCategory;
36 36 class QBarSeriesPrivate;
37 37
38 38 // Container for series
39 39 class QTCOMMERCIALCHART_EXPORT QBarSeries : public QSeries
40 40 {
41 41 Q_OBJECT
42 42 public:
43 43 QBarSeries(QBarCategories categories, QObject *parent = 0);
44 44
45 45 QSeries::QSeriesType type() const;
46 46
47 47 void appendBarSet(QBarSet *set); // Takes ownership of set
48 48 void removeBarSet(QBarSet *set); // Releases ownership, doesn't delete set
49 49 void appendBarSets(QList<QBarSet* > sets);
50 50 void removeBarSets(QList<QBarSet* > sets);
51 51 void insertBarSet(int i, QBarSet *set);
52 52 void insertCategory(int i, QString category);
53 53 void removeCategory(int i);
54 54 int barsetCount() const;
55 55 int categoryCount() const;
56 56 QList<QBarSet*> barSets() const;
57 57 QBarCategories categories() const;
58 58
59 59 void setLabelsVisible(bool visible = true);
60 60
61 61 bool setModel(QAbstractItemModel *model);
62 62 void setModelMapping(int categories, int bottomBoundary, int topBoundary, Qt::Orientation orientation = Qt::Vertical);
63 63
64 64 public:
65 65 // TODO: Functions below this are not part of api and will be moved
66 66 // to private implementation, when we start using it
67 67 // TODO: TO PIMPL --->
68 68 QBarSet* barsetAt(int index);
69 69 QString categoryName(int category);
70 70 qreal min();
71 71 qreal max();
72 72 qreal valueAt(int set, int category);
73 73 qreal percentageAt(int set, int category);
74 74 qreal categorySum(int category);
75 75 qreal absoluteCategorySum(int category);
76 76 qreal maxCategorySum();
77 77 BarChartModel& modelInternal();
78 78 // <--- TO PIMPL
79 79
80 80 protected:
81 81 explicit QBarSeries(QBarSeriesPrivate &d,QObject *parent = 0);
82 82
83 83 Q_SIGNALS:
84 84 void clicked(QBarSet *barset, QString category, Qt::MouseButtons button); // Up to user of api, what to do with these signals
85 85 void selected();
86 86 //
87 87 void updatedBars();
88 88 void restructuredBars();
89 89
90 90 // TODO: internal signals, these to private implementation.
91 91 // TODO: TO PIMPL --->
92 92 // void showToolTip(QPoint pos, QString tip);
93 93 // <--- TO PIMPL
94 94
95 95 public Q_SLOTS:
96 96 void setToolTipEnabled(bool enabled = true); // enables tooltips
97 97
98 98 // TODO: TO PIMPL --->
99 99 void barsetClicked(QString category, Qt::MouseButtons button);
100 100 // <--- TO PIMPL
101 101
102 102 private Q_SLOTS:
103 103 // slots for updating bars when data in model changes
104 104 void modelUpdated(QModelIndex topLeft, QModelIndex bottomRight);
105 105 void modelDataAdded(QModelIndex parent, int start, int end);
106 106 void modelDataRemoved(QModelIndex parent, int start, int end);
107 107 void barsetChanged();
108 108
109 109 protected:
110 110 Q_DECLARE_PRIVATE(QBarSeries)
111 Q_DISABLE_COPY(QBarSeries)
112 111
113 112 /*
114 113 BarChartModel *m_internalModel; // TODO: this may change... current "2 models" situation doesn't look good.
115 114
116 115 // QAbstractItemModel* m_model;
117 116 int m_mapCategories;
118 117 int m_mapBarBottom;
119 118 int m_mapBarTop;
120 119 int m_mapFirst;
121 120 int m_mapCount;
122 121 Qt::Orientation m_mapOrientation;
123 122 */
124 123 };
125 124
126 125 QTCOMMERCIALCHART_END_NAMESPACE
127 126
128 127 #endif // BARSERIES_H
@@ -1,321 +1,326
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #include "qbarset.h"
22 22 #include "qbarset_p.h"
23 23 #include <QToolTip>
24 24
25 25 QTCOMMERCIALCHART_BEGIN_NAMESPACE
26 26
27 27 /*!
28 28 \class QBarSet
29 29 \brief part of QtCommercial chart API.
30 30
31 31 QBarSet represents one set of bars. Set of bars contains one data value for each category.
32 32 First value of set is assumed to belong to first category, second to second category and so on.
33 33 If set has fewer values than there are categories, then the missing values are assumed to be
34 34 at the end of set. For missing values in middle of a set, numerical value of zero is used.
35 35
36 36 \mainclass
37 37
38 38 \sa QBarSeries, QStackedBarSeries, QPercentBarSeries
39 39 */
40 40
41 41 /*!
42 42 \fn void QBarSet::clicked(QString category, Qt::MouseButtons button)
43 43 \brief signals that set has been clicked
44 44 Parameter \a category describes on which category was clicked
45 45 Parameter \a button mouse button
46 46 */
47 47
48 48 /*!
49 49 \fn void QBarSet::hoverEnter(QPoint pos)
50 50 \brief signals that mouse has entered over the set at position \a pos.
51 51 */
52 52
53 53 /*!
54 54 \fn void QBarSet::hoverLeave()
55 55 \brief signals that mouse has left from the set.
56 56 */
57 57
58 58 /*!
59 59 \fn void QBarSetPrivate::showToolTip(QPoint pos, QString tip)
60 60 \brief \internal \a pos \a tip
61 61 */
62 62
63 63
64 64 /*!
65 65 Constructs QBarSet with a name of \a name and with parent of \a parent
66 66 */
67 67 QBarSet::QBarSet(QString name, QObject *parent)
68 68 : QObject(parent)
69 69 ,d_ptr(new QBarSetPrivate(name,this))
70 70 // ,m_name(name)
71 71 // ,m_labelsVisible(false)
72 72 {
73 73 }
74 74
75 QBarSet::~QBarSet()
76 {
77
78 }
79
75 80 /*!
76 81 Sets new \a name for set.
77 82 */
78 83 void QBarSet::setName(QString name)
79 84 {
80 85 d_ptr->m_name = name;
81 86 }
82 87
83 88 /*!
84 89 Returns name of the set.
85 90 */
86 91 QString QBarSet::name() const
87 92 {
88 93 return d_ptr->m_name;
89 94 }
90 95
91 96 /*!
92 97 Appends new value \a value to the end of set.
93 98 */
94 99 QBarSet& QBarSet::operator << (const qreal &value)
95 100 {
96 101 d_ptr->m_values.append(value);
97 102 emit d_ptr->structureChanged();
98 103 return *this;
99 104 }
100 105
101 106 /*!
102 107 Inserts new \a value on the \a i position.
103 108 The value that is currently at this postion is moved to postion i + 1
104 109 \sa removeValue()
105 110 */
106 111 void QBarSet::insertValue(int i, qreal value)
107 112 {
108 113 d_ptr->m_values.insert(i, value);
109 114 }
110 115
111 116 /*!
112 117 Removes the value specified by \a i
113 118 \sa insertValue()
114 119 */
115 120 void QBarSet::removeValue(int i)
116 121 {
117 122 d_ptr->m_values.removeAt(i);
118 123 }
119 124
120 125 /*!
121 126 Returns count of values in set.
122 127 */
123 128 int QBarSet::count() const
124 129 {
125 130 return d_ptr->m_values.count();
126 131 }
127 132
128 133 /*!
129 134 Returns value of set indexed by \a index
130 135 */
131 136 qreal QBarSet::valueAt(int index) const
132 137 {
133 138 return d_ptr->m_values.at(index);
134 139 }
135 140
136 141 /*!
137 142 Sets a new value \a value to set, indexed by \a index
138 143 */
139 144 void QBarSet::setValue(int index, qreal value)
140 145 {
141 146 d_ptr->m_values.replace(index,value);
142 147 emit d_ptr->valueChanged();
143 148 }
144 149
145 150 /*!
146 151 Returns sum of all values in barset.
147 152 */
148 153 qreal QBarSet::sum() const
149 154 {
150 155 qreal total(0);
151 156 for (int i=0; i < d_ptr->m_values.count(); i++) {
152 157 total += d_ptr->m_values.at(i);
153 158 }
154 159 return total;
155 160 }
156 161
157 162 /*!
158 163 Sets pen for set. Bars of this set are drawn using \a pen
159 164 */
160 165 void QBarSet::setPen(const QPen &pen)
161 166 {
162 167 if(d_ptr->m_pen!=pen){
163 168 d_ptr->m_pen = pen;
164 169 emit d_ptr->valueChanged();
165 170 }
166 171 }
167 172
168 173 /*!
169 174 Returns pen of the set.
170 175 */
171 176 QPen QBarSet::pen() const
172 177 {
173 178 return d_ptr->m_pen;
174 179 }
175 180
176 181 /*!
177 182 Sets brush for the set. Bars of this set are drawn using \a brush
178 183 */
179 184 void QBarSet::setBrush(const QBrush &brush)
180 185 {
181 186 if(d_ptr->m_brush!=brush){
182 187 d_ptr->m_brush = brush;
183 188 emit d_ptr->valueChanged();
184 189 }
185 190 }
186 191
187 192 /*!
188 193 Returns brush of the set.
189 194 */
190 195 QBrush QBarSet::brush() const
191 196 {
192 197 return d_ptr->m_brush;
193 198 }
194 199
195 200 /*!
196 201 Sets \a pen of the values that are drawn on top of this barset
197 202 */
198 203 void QBarSet::setLabelPen(const QPen &pen)
199 204 {
200 205 if(d_ptr->m_labelPen!=pen){
201 206 d_ptr->m_labelPen = pen;
202 207 emit d_ptr->valueChanged();
203 208 }
204 209 }
205 210
206 211 /*!
207 212 Returns pen of the values that are drawn on top of this barset
208 213 */
209 214 QPen QBarSet::labelPen() const
210 215 {
211 216 return d_ptr->m_labelPen;
212 217 }
213 218
214 219 /*!
215 220 Sets \a brush of the values that are drawn on top of this barset
216 221 */
217 222 void QBarSet::setLabelBrush(const QBrush &brush)
218 223 {
219 224 if(d_ptr->m_labelBrush!=brush){
220 225 d_ptr->m_labelBrush = brush;
221 226 emit d_ptr->valueChanged();
222 227 }
223 228 }
224 229
225 230 /*!
226 231 Returns brush of the values that are drawn on top of this barset
227 232 */
228 233 QBrush QBarSet::labelBrush() const
229 234 {
230 235 return d_ptr->m_labelBrush;
231 236 }
232 237
233 238 /*!
234 239 Sets the \a font for values that are drawn on top of this barset
235 240 */
236 241 void QBarSet::setLabelFont(const QFont &font)
237 242 {
238 243 if(d_ptr->m_labelFont!=font) {
239 244 d_ptr->m_labelFont = font;
240 245 emit d_ptr->valueChanged();
241 246 }
242 247
243 248 }
244 249
245 250 /*!
246 251 Returns the pen for values that are drawn on top of this set
247 252 */
248 253 QFont QBarSet::labelFont() const
249 254 {
250 255 return d_ptr->m_labelFont;
251 256 }
252 257
253 258 /*!
254 259 Sets visibility of bar labels. If \a visible is true, labels are drawn on top of barsets.
255 260 */
256 261
257 262 void QBarSet::setLabelsVisible(bool visible)
258 263 {
259 264 if(d_ptr->m_labelsVisible!=visible) {
260 265 d_ptr->m_labelsVisible = visible;
261 266 emit d_ptr->labelsVisibleChanged(visible);
262 267 }
263 268 }
264 269
265 270 /*!
266 271 Returns the visibility of values
267 272 */
268 273 bool QBarSet::labelsVisible() const
269 274 {
270 275 return d_ptr->m_labelsVisible;
271 276 }
272 277
273 278 /*
274 279 void QBarSet::barHoverEnterEvent(QPoint pos)
275 280 {
276 281 emit showToolTip(pos, m_name);
277 282 emit hoverEnter(pos);
278 283 }
279 284 */
280 285 /*
281 286 void QBarSet::barHoverLeaveEvent()
282 287 {
283 288 // Emit signal to user of charts
284 289 emit hoverLeave();
285 290 }
286 291 */
287 292
288 293 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
289 294
290 295 QBarSetPrivate::QBarSetPrivate(QString name, QBarSet *parent) : QObject(parent),
291 296 q_ptr(parent),
292 297 m_name(name),
293 298 m_labelsVisible(false)
294 299 {
295 300
296 301 }
297 302
298 303 QBarSetPrivate::~QBarSetPrivate()
299 304 {
300 305
301 306 }
302 307
303 308
304 309 //TODO: fixme , refactor it and get rid of it
305 310 void QBarSetPrivate::barHoverEnterEvent(QPoint pos)
306 311 {
307 312 emit showToolTip(pos, m_name);
308 313 emit hoverEnter(pos);
309 314 }
310 315
311 316 //TODO: fixme , refactor it and get rid of it
312 317 void QBarSetPrivate::barHoverLeaveEvent()
313 318 {
314 319 // Emit signal to user of charts
315 320 emit hoverLeave();
316 321 }
317 322
318 323 #include "moc_qbarset.cpp"
319 324 #include "moc_qbarset_p.cpp"
320 325
321 326 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,79 +1,80
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #ifndef QBARSET_H
22 22 #define QBARSET_H
23 23
24 24 #include <qchartglobal.h>
25 25 #include <QPen>
26 26 #include <QBrush>
27 27 #include <QFont>
28 28
29 29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30 30 class QBarSetPrivate;
31 31
32 32 class QTCOMMERCIALCHART_EXPORT QBarSet : public QObject
33 33 {
34 34 Q_OBJECT
35 35
36 36 public:
37 37 QBarSet(QString name, QObject *parent = 0);
38 virtual ~QBarSet();
38 39
39 40 void setName(QString name);
40 41 QString name() const;
41 42 QBarSet& operator << (const qreal &value); // appends new value to set
42 43 void insertValue(int i, qreal value);
43 44 void removeValue(int i);
44 45 int count() const; // count of values in set
45 46 qreal valueAt(int index) const; // for modifying individual values
46 47 void setValue(int index, qreal value); // setter for individual value
47 48 qreal sum() const; // sum of all values in the set
48 49
49 50 void setPen(const QPen &pen);
50 51 QPen pen() const;
51 52
52 53 void setBrush(const QBrush &brush);
53 54 QBrush brush() const;
54 55
55 56 void setLabelPen(const QPen &pen);
56 57 QPen labelPen() const;
57 58
58 59 void setLabelBrush(const QBrush &brush);
59 60 QBrush labelBrush() const;
60 61
61 62 void setLabelFont(const QFont &font);
62 63 QFont labelFont() const;
63 64
64 65 void setLabelsVisible(bool visible = true);
65 66 bool labelsVisible() const;
66 67
67 68 Q_SIGNALS:
68 69 void clicked(QString category, Qt::MouseButtons button); // Clicked and hover signals exposed to user
69 70
70 71 private:
71 72 QScopedPointer<QBarSetPrivate> d_ptr;
72 73 Q_DISABLE_COPY(QBarSet)
73 74 friend class QBarSeries;
74 75
75 76 };
76 77
77 78 QTCOMMERCIALCHART_END_NAMESPACE
78 79
79 80 #endif // QBARSET_H
General Comments 0
You need to be logged in to leave comments. Login now