@@ -0,0 +1,96 | |||
|
1 | #ifndef QBARSERIESPRIVATE_P_H | |
|
2 | #define QBARSERIESPRIVATE_P_H | |
|
3 | ||
|
4 | #include "qbarseries.h" | |
|
5 | #include <QStringList> | |
|
6 | #include <QSeries> | |
|
7 | ||
|
8 | class QModelIndex; | |
|
9 | ||
|
10 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
|
11 | ||
|
12 | typedef QStringList QBarCategories; | |
|
13 | ||
|
14 | class QBarSeries; | |
|
15 | class QBarSet; | |
|
16 | class BarChartModel; | |
|
17 | class BarCategory; | |
|
18 | ||
|
19 | // Container for series | |
|
20 | class QBarSeriesPrivate : public QObject | |
|
21 | { | |
|
22 | Q_OBJECT | |
|
23 | Q_DECLARE_PUBLIC(QBarSeries) | |
|
24 | public: | |
|
25 | QBarSeriesPrivate(QStringList categories, QBarSeries *parent); | |
|
26 | ||
|
27 | virtual QSeries::QSeriesType type() const { return QSeries::SeriesTypeBar; } | |
|
28 | ||
|
29 | void appendBarSet(QBarSet *set); // Takes ownership of set | |
|
30 | void removeBarSet(QBarSet *set); // Releases ownership, doesn't delete set | |
|
31 | void appendBarSets(QList<QBarSet* > sets); | |
|
32 | void removeBarSets(QList<QBarSet* > sets); | |
|
33 | void insertBarSet(int i, QBarSet *set); | |
|
34 | void insertCategory(int i, QString category); | |
|
35 | void removeCategory(int i); | |
|
36 | int barsetCount() const; | |
|
37 | int categoryCount() const; | |
|
38 | QList<QBarSet*> barSets() const; | |
|
39 | QBarCategories categories() const; | |
|
40 | ||
|
41 | void setLabelsVisible(bool visible = true); | |
|
42 | ||
|
43 | bool setModel(QAbstractItemModel *model); | |
|
44 | void setModelMapping(int categories, int bottomBoundry, int topBoundry, Qt::Orientation orientation = Qt::Vertical); | |
|
45 | ||
|
46 | QBarSet* barsetAt(int index); | |
|
47 | QString categoryName(int category); | |
|
48 | qreal min(); | |
|
49 | qreal max(); | |
|
50 | qreal valueAt(int set, int category); | |
|
51 | qreal percentageAt(int set, int category); | |
|
52 | qreal categorySum(int category); | |
|
53 | qreal absoluteCategorySum(int category); | |
|
54 | qreal maxCategorySum(); | |
|
55 | BarChartModel& modelInternal(); | |
|
56 | ||
|
57 | static QBarSeriesPrivate &data(QBarSeries *barseries) | |
|
58 | { | |
|
59 | Q_ASSERT(barseries); | |
|
60 | return *barseries->d_ptr; | |
|
61 | } | |
|
62 | ||
|
63 | Q_SIGNALS: | |
|
64 | void clicked(QBarSet *barset, QString category, Qt::MouseButtons button); // Up to user of api, what to do with these signals | |
|
65 | void selected(); | |
|
66 | void updatedBars(); | |
|
67 | void restructuredBars(); | |
|
68 | void showToolTip(QPoint pos, QString tip); | |
|
69 | ||
|
70 | public Q_SLOTS: | |
|
71 | void setToolTipEnabled(bool enabled = true); // enables tooltips | |
|
72 | void barsetClicked(QString category, Qt::MouseButtons button); | |
|
73 | ||
|
74 | private Q_SLOTS: | |
|
75 | // slots for updating bars when data in model changes | |
|
76 | void modelUpdated(QModelIndex topLeft, QModelIndex bottomRight); | |
|
77 | void modelDataAdded(QModelIndex parent, int start, int end); | |
|
78 | void modelDataRemoved(QModelIndex parent, int start, int end); | |
|
79 | void barsetChanged(); | |
|
80 | ||
|
81 | protected: | |
|
82 | QBarSeries * const q_ptr; | |
|
83 | ||
|
84 | BarChartModel *m_internalModel; // TODO: this may change... current "2 models" situation doesn't look good. | |
|
85 | QAbstractItemModel* m_model; | |
|
86 | int m_mapCategories; | |
|
87 | int m_mapBarBottom; | |
|
88 | int m_mapBarTop; | |
|
89 | int m_mapFirst; | |
|
90 | int m_mapCount; | |
|
91 | Qt::Orientation m_mapOrientation; | |
|
92 | }; | |
|
93 | ||
|
94 | QTCOMMERCIALCHART_END_NAMESPACE | |
|
95 | ||
|
96 | #endif // QBARSERIESPRIVATE_P_H |
@@ -0,0 +1,80 | |||
|
1 | #ifndef QBARSETPRIVATE_P_H | |
|
2 | #define QBARSETPRIVATE_P_H | |
|
3 | ||
|
4 | #include "qbarset.h" | |
|
5 | ||
|
6 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
|
7 | ||
|
8 | class QBarSetPrivate : public QObject | |
|
9 | { | |
|
10 | Q_OBJECT | |
|
11 | Q_DECLARE_PUBLIC(QBarSet) | |
|
12 | ||
|
13 | public: | |
|
14 | QBarSetPrivate(QString name, QBarSet *parent); | |
|
15 | ~QBarSetPrivate(); | |
|
16 | ||
|
17 | void setName(QString name); | |
|
18 | QString name() const; | |
|
19 | QBarSetPrivate& operator << (const qreal &value); // appends new value to set | |
|
20 | void insertValue(int i, qreal value); | |
|
21 | void removeValue(int i); | |
|
22 | int count() const; | |
|
23 | qreal valueAt(int index) const; | |
|
24 | void setValue(int index, qreal value); | |
|
25 | qreal sum() const; | |
|
26 | ||
|
27 | void setPen(const QPen &pen); | |
|
28 | QPen pen() const; | |
|
29 | ||
|
30 | void setBrush(const QBrush &brush); | |
|
31 | QBrush brush() const; | |
|
32 | ||
|
33 | void setLabelPen(const QPen &pen); | |
|
34 | QPen labelPen() const; | |
|
35 | ||
|
36 | void setLabelBrush(const QBrush &brush); | |
|
37 | QBrush labelBrush() const; | |
|
38 | ||
|
39 | void setLabelFont(const QFont &font); | |
|
40 | QFont labelFont() const; | |
|
41 | ||
|
42 | void setLabelsVisible(bool visible = true); | |
|
43 | bool labelsVisible() const; | |
|
44 | ||
|
45 | static QBarSetPrivate &pimpl(QBarSet *barset) | |
|
46 | { | |
|
47 | Q_ASSERT(barset); | |
|
48 | return *barset->d_ptr; | |
|
49 | } | |
|
50 | ||
|
51 | Q_SIGNALS: | |
|
52 | void clicked(QString category, Qt::MouseButtons button); | |
|
53 | void structureChanged(); | |
|
54 | void valueChanged(); | |
|
55 | void hoverEnter(QPoint pos); | |
|
56 | void hoverLeave(); | |
|
57 | void showToolTip(QPoint pos, QString tip); | |
|
58 | void labelsVisibleChanged(bool visible); | |
|
59 | ||
|
60 | public Q_SLOTS: | |
|
61 | void barHoverEnterEvent(QPoint pos); | |
|
62 | void barHoverLeaveEvent(); | |
|
63 | ||
|
64 | public: | |
|
65 | QBarSet * const q_ptr; | |
|
66 | ||
|
67 | QString m_name; | |
|
68 | QList<qreal> m_values; // TODO: replace with map (category, value) | |
|
69 | QMap<QString, qreal> m_mappedValues; | |
|
70 | QPen m_pen; | |
|
71 | QBrush m_brush; | |
|
72 | QPen m_labelPen; | |
|
73 | QBrush m_labelBrush; | |
|
74 | QFont m_labelFont; | |
|
75 | bool m_labelsVisible; | |
|
76 | }; | |
|
77 | ||
|
78 | QTCOMMERCIALCHART_END_NAMESPACE | |
|
79 | ||
|
80 | #endif // QBARSETPRIVATE_P_H |
@@ -88,7 +88,7 int main(int argc, char *argv[]) | |||
|
88 | 88 | // Get the drilldown series from season series and add crop to it. |
|
89 | 89 | seasonSeries->drilldownSeries(month)->appendBarSet(weeklyCrop); |
|
90 | 90 | seasonSeries->drilldownSeries(month)->setToolTipEnabled(true); |
|
91 |
*monthlyCrop << weeklyCrop-> |
|
|
91 | *monthlyCrop << weeklyCrop->sum(); | |
|
92 | 92 | } |
|
93 | 93 | seasonSeries->appendBarSet(monthlyCrop); |
|
94 | 94 | } |
@@ -19,7 +19,9 PRIVATE_HEADERS += \ | |||
|
19 | 19 | $$PWD/barchartitem_p.h \ |
|
20 | 20 | $$PWD/percentbarchartitem_p.h \ |
|
21 | 21 | $$PWD/stackedbarchartitem_p.h \ |
|
22 | $$PWD/barlabel_p.h | |
|
22 | $$PWD/barlabel_p.h \ | |
|
23 | $$PWD/qbarsetprivate_p.h \ | |
|
24 | $$PWD/qbarseriesprivate_p.h | |
|
23 | 25 | |
|
24 | 26 | PUBLIC_HEADERS += \ |
|
25 | 27 | $$PWD/qbarseries.h \ |
@@ -22,11 +22,320 | |||
|
22 | 22 | #include "qbarseries.h" |
|
23 | 23 | #include "qbarset.h" |
|
24 | 24 | #include "barchartmodel_p.h" |
|
25 | #include "qbarseriesprivate_p.h" | |
|
26 | #include "qbarsetprivate_p.h" | |
|
25 | 27 | #include <QAbstractItemModel> |
|
26 | 28 | #include <QModelIndex> |
|
27 | 29 | |
|
28 | 30 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
29 | 31 | |
|
32 | QBarSeriesPrivate::QBarSeriesPrivate(QBarCategories categories, QBarSeries *parent) : QObject(parent), | |
|
33 | q_ptr(parent), | |
|
34 | m_internalModel(new BarChartModel(categories,this)) | |
|
35 | { | |
|
36 | m_model = 0; | |
|
37 | m_mapCategories = -1; | |
|
38 | m_mapBarBottom = -1; | |
|
39 | m_mapBarTop = -1; | |
|
40 | m_mapFirst = 0; | |
|
41 | m_mapCount = 0; | |
|
42 | m_mapOrientation = Qt::Vertical; | |
|
43 | } | |
|
44 | ||
|
45 | void QBarSeriesPrivate::appendBarSet(QBarSet *set) | |
|
46 | { | |
|
47 | m_internalModel->appendBarSet(set); | |
|
48 | // connect(set, SIGNAL(clicked(QString,Qt::MouseButtons)), this, SLOT(barsetClicked(QString,Qt::MouseButtons))); | |
|
49 | // connect(set, SIGNAL(valueChanged()), this, SLOT(barsetChanged())); | |
|
50 | emit restructuredBars(); | |
|
51 | } | |
|
52 | ||
|
53 | void QBarSeriesPrivate::removeBarSet(QBarSet *set) | |
|
54 | { | |
|
55 | // disconnect(set, SIGNAL(clicked(QString,Qt::MouseButtons)), this, SLOT(barsetClicked(QString,Qt::MouseButtons))); | |
|
56 | m_internalModel->removeBarSet(set); | |
|
57 | emit restructuredBars(); | |
|
58 | } | |
|
59 | void QBarSeriesPrivate::appendBarSets(QList<QBarSet* > sets) | |
|
60 | { | |
|
61 | foreach (QBarSet* barset, sets) { | |
|
62 | m_internalModel->appendBarSet(barset); | |
|
63 | connect(barset, SIGNAL(clicked(QString,Qt::MouseButtons)), this, SLOT(barsetClicked(QString,Qt::MouseButtons))); | |
|
64 | connect(barset, SIGNAL(valueChanged()), this, SLOT(barsetChanged())); | |
|
65 | } | |
|
66 | emit restructuredBars(); | |
|
67 | } | |
|
68 | ||
|
69 | void QBarSeriesPrivate::removeBarSets(QList<QBarSet* > sets) | |
|
70 | { | |
|
71 | foreach (QBarSet* barset, sets) { | |
|
72 | disconnect(barset, SIGNAL(clicked(QString,Qt::MouseButtons)), this, SLOT(barsetClicked(QString,Qt::MouseButtons))); | |
|
73 | m_internalModel->removeBarSet(barset); | |
|
74 | } | |
|
75 | emit restructuredBars(); | |
|
76 | } | |
|
77 | ||
|
78 | void QBarSeriesPrivate::insertBarSet(int i, QBarSet *set) | |
|
79 | { | |
|
80 | m_internalModel->insertBarSet(i, set); | |
|
81 | // emit barsetChanged(); | |
|
82 | } | |
|
83 | ||
|
84 | void QBarSeriesPrivate::insertCategory(int i, QString category) | |
|
85 | { | |
|
86 | m_internalModel->insertCategory(i, category); | |
|
87 | } | |
|
88 | ||
|
89 | void QBarSeriesPrivate::removeCategory(int i) | |
|
90 | { | |
|
91 | m_internalModel->removeCategory(i); | |
|
92 | } | |
|
93 | ||
|
94 | int QBarSeriesPrivate::barsetCount() const | |
|
95 | { | |
|
96 | // if(m_model) | |
|
97 | // return m_mapBarTop - m_mapBarBottom; | |
|
98 | // else | |
|
99 | return m_internalModel->barsetCount(); | |
|
100 | } | |
|
101 | ||
|
102 | int QBarSeriesPrivate::categoryCount() const | |
|
103 | { | |
|
104 | return m_internalModel->categoryCount(); | |
|
105 | } | |
|
106 | ||
|
107 | QList<QBarSet*> QBarSeriesPrivate::barSets() const | |
|
108 | { | |
|
109 | return m_internalModel->barSets(); | |
|
110 | } | |
|
111 | ||
|
112 | QBarSet* QBarSeriesPrivate::barsetAt(int index) | |
|
113 | { | |
|
114 | return m_internalModel->barsetAt(index); | |
|
115 | } | |
|
116 | ||
|
117 | QString QBarSeriesPrivate::categoryName(int category) | |
|
118 | { | |
|
119 | return m_internalModel->categoryName(category); | |
|
120 | } | |
|
121 | ||
|
122 | void QBarSeriesPrivate::setToolTipEnabled(bool enabled) | |
|
123 | { | |
|
124 | // TODO: what if we add sets after call to this function? Those sets won't have tooltip enabled. | |
|
125 | if (enabled) { | |
|
126 | for (int i=0; i<m_internalModel->barsetCount(); i++) { | |
|
127 | QBarSet *set = m_internalModel->barsetAt(i); | |
|
128 | connect(set, SIGNAL(showToolTip(QPoint,QString)), this, SIGNAL(showToolTip(QPoint,QString))); | |
|
129 | } | |
|
130 | } else { | |
|
131 | for (int i=0; i<m_internalModel->barsetCount(); i++) { | |
|
132 | QBarSet *set = m_internalModel->barsetAt(i); | |
|
133 | disconnect(set, SIGNAL(showToolTip(QPoint,QString)), this, SIGNAL(showToolTip(QPoint,QString))); | |
|
134 | } | |
|
135 | } | |
|
136 | } | |
|
137 | ||
|
138 | void QBarSeriesPrivate::barsetClicked(QString category, Qt::MouseButtons button) | |
|
139 | { | |
|
140 | emit clicked(qobject_cast<QBarSet*>(sender()), category, button); | |
|
141 | } | |
|
142 | ||
|
143 | qreal QBarSeriesPrivate::min() | |
|
144 | { | |
|
145 | return m_internalModel->min(); | |
|
146 | } | |
|
147 | ||
|
148 | qreal QBarSeriesPrivate::max() | |
|
149 | { | |
|
150 | return m_internalModel->max(); | |
|
151 | } | |
|
152 | ||
|
153 | qreal QBarSeriesPrivate::valueAt(int set, int category) | |
|
154 | { | |
|
155 | return m_internalModel->valueAt(set, category); | |
|
156 | } | |
|
157 | ||
|
158 | qreal QBarSeriesPrivate::percentageAt(int set, int category) | |
|
159 | { | |
|
160 | return m_internalModel->percentageAt(set, category); | |
|
161 | } | |
|
162 | ||
|
163 | qreal QBarSeriesPrivate::categorySum(int category) | |
|
164 | { | |
|
165 | return m_internalModel->categorySum(category); | |
|
166 | } | |
|
167 | ||
|
168 | qreal QBarSeriesPrivate::absoluteCategorySum(int category) | |
|
169 | { | |
|
170 | return m_internalModel->absoluteCategorySum(category); | |
|
171 | } | |
|
172 | ||
|
173 | qreal QBarSeriesPrivate::maxCategorySum() | |
|
174 | { | |
|
175 | return m_internalModel->maxCategorySum(); | |
|
176 | } | |
|
177 | ||
|
178 | BarChartModel& QBarSeriesPrivate::modelInternal() | |
|
179 | { | |
|
180 | return *m_internalModel; | |
|
181 | } | |
|
182 | ||
|
183 | bool QBarSeriesPrivate::setModel(QAbstractItemModel *model) | |
|
184 | { | |
|
185 | // disconnect signals from old model | |
|
186 | if(m_model) | |
|
187 | { | |
|
188 | disconnect(m_model, 0, this, 0); | |
|
189 | m_mapCategories = -1; | |
|
190 | m_mapBarBottom = -1; | |
|
191 | m_mapBarTop = -1; | |
|
192 | m_mapFirst = 0; | |
|
193 | m_mapCount = 0; | |
|
194 | m_mapOrientation = Qt::Vertical; | |
|
195 | } | |
|
196 | ||
|
197 | // set new model | |
|
198 | if(model) | |
|
199 | { | |
|
200 | m_model = model; | |
|
201 | return true; | |
|
202 | } | |
|
203 | else | |
|
204 | { | |
|
205 | m_model = 0; | |
|
206 | return false; | |
|
207 | } | |
|
208 | } | |
|
209 | ||
|
210 | void QBarSeriesPrivate::setModelMapping(int categories, int bottomBoundry, int topBoundry, Qt::Orientation orientation) | |
|
211 | { | |
|
212 | if (!m_model) | |
|
213 | return; | |
|
214 | ||
|
215 | m_mapCategories = categories; | |
|
216 | m_mapBarBottom = bottomBoundry; | |
|
217 | m_mapBarTop = topBoundry; | |
|
218 | // m_mapFirst = 1; | |
|
219 | m_mapOrientation = orientation; | |
|
220 | ||
|
221 | // connect the signals | |
|
222 | if (m_mapOrientation == Qt::Vertical) { | |
|
223 | m_mapCount = m_model->rowCount() - m_mapFirst; | |
|
224 | connect(m_model,SIGNAL(dataChanged(QModelIndex,QModelIndex)), | |
|
225 | this, SLOT(modelUpdated(QModelIndex, QModelIndex))); | |
|
226 | connect(m_model,SIGNAL(rowsInserted(QModelIndex, int, int)), | |
|
227 | this, SLOT(modelDataAdded(QModelIndex,int,int))); | |
|
228 | connect(m_model, SIGNAL(rowsRemoved(QModelIndex, int, int)), | |
|
229 | this, SLOT(modelDataRemoved(QModelIndex,int,int))); | |
|
230 | } else { | |
|
231 | m_mapCount = m_model->columnCount() - m_mapFirst; | |
|
232 | connect(m_model,SIGNAL(dataChanged(QModelIndex,QModelIndex)), | |
|
233 | this, SLOT(modelUpdated(QModelIndex, QModelIndex))); | |
|
234 | connect(m_model,SIGNAL(columnsInserted(QModelIndex, int, int)), | |
|
235 | this, SLOT(modelDataAdded(QModelIndex,int,int))); | |
|
236 | connect(m_model, SIGNAL(columnsRemoved(QModelIndex, int, int)), | |
|
237 | this, SLOT(modelDataRemoved(QModelIndex,int,int))); | |
|
238 | } | |
|
239 | ||
|
240 | // create the initial bars | |
|
241 | delete m_internalModel; | |
|
242 | if (m_mapOrientation == Qt::Vertical) { | |
|
243 | QStringList categories; | |
|
244 | for (int k = m_mapFirst; k < m_mapFirst + m_mapCount; k++) | |
|
245 | categories << m_model->data(m_model->index(k, m_mapCategories), Qt::DisplayRole).toString(); | |
|
246 | m_internalModel = new BarChartModel(categories, this); | |
|
247 | ||
|
248 | for (int i = m_mapBarBottom; i <= m_mapBarTop; i++) { | |
|
249 | QBarSet* barSet = new QBarSet(QString("Column: %1").arg(i + 1)); | |
|
250 | for(int m = m_mapFirst; m < m_mapFirst + m_mapCount; m++) | |
|
251 | *barSet << m_model->data(m_model->index(m, i), Qt::DisplayRole).toDouble(); | |
|
252 | appendBarSet(barSet); | |
|
253 | } | |
|
254 | } else { | |
|
255 | QStringList categories; | |
|
256 | for (int k = m_mapFirst; k < m_mapFirst + m_mapCount; k++) | |
|
257 | categories << m_model->data(m_model->index(m_mapCategories, k), Qt::DisplayRole).toString(); | |
|
258 | m_internalModel = new BarChartModel(categories, this); | |
|
259 | ||
|
260 | for (int i = m_mapBarBottom; i <= m_mapBarTop; i++) { | |
|
261 | QBarSet* barSet = new QBarSet(QString("Row: %1").arg(i + 1)); | |
|
262 | for(int m = m_mapFirst; m < m_mapFirst + m_mapCount; m++) | |
|
263 | *barSet << m_model->data(m_model->index(i, m), Qt::DisplayRole).toDouble(); | |
|
264 | appendBarSet(barSet); | |
|
265 | } | |
|
266 | } | |
|
267 | } | |
|
268 | ||
|
269 | void QBarSeriesPrivate::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight) | |
|
270 | { | |
|
271 | Q_UNUSED(bottomRight) | |
|
272 | ||
|
273 | if (m_mapOrientation == Qt::Vertical) | |
|
274 | { | |
|
275 | // model update is relevant to BarSeries if the change was made to the part of the model that was mapped to BarSeries | |
|
276 | if (topLeft.column() >= m_mapBarBottom && topLeft.column() <= m_mapBarTop && topLeft.row() >= m_mapFirst && topLeft.row() < m_mapFirst + m_mapCount) | |
|
277 | barsetAt(topLeft.column() - m_mapBarBottom)->setValue(topLeft.row() - m_mapFirst, m_model->data(topLeft, Qt::DisplayRole).toDouble()); | |
|
278 | } | |
|
279 | else | |
|
280 | { | |
|
281 | // model update is relevant to BarSeries if the change was made to the part of the model that was mapped to BarSeries | |
|
282 | if (topLeft.row() >= m_mapBarBottom && topLeft.row() <= m_mapBarTop && topLeft.column() >= m_mapFirst && topLeft.column() < m_mapFirst + m_mapCount) | |
|
283 | barsetAt(topLeft.row() - m_mapBarBottom)->setValue(topLeft.column() - m_mapFirst, m_model->data(topLeft, Qt::DisplayRole).toDouble()); | |
|
284 | } | |
|
285 | } | |
|
286 | ||
|
287 | void QBarSeriesPrivate::modelDataAdded(QModelIndex /*parent*/, int start, int /*end*/) | |
|
288 | { | |
|
289 | if (m_mapOrientation == Qt::Vertical) { | |
|
290 | insertCategory(start - m_mapFirst, QString("Row: %1").arg(start + 1)); | |
|
291 | for (int i = 0; i <= m_mapBarTop - m_mapBarBottom; i++) { | |
|
292 | barsetAt(i)->insertValue(start - m_mapFirst, m_model->data(m_model->index(start, i), Qt::DisplayRole).toDouble()); | |
|
293 | } | |
|
294 | } else { | |
|
295 | insertCategory(start - m_mapFirst, QString("Column: %1").arg(start + 1)); | |
|
296 | for (int i = 0; i <= m_mapBarTop - m_mapBarBottom; i++) { | |
|
297 | barsetAt(i)->insertValue(start - m_mapFirst, m_model->data(m_model->index(i, start), Qt::DisplayRole).toDouble()); | |
|
298 | } | |
|
299 | } | |
|
300 | emit restructuredBars(); | |
|
301 | } | |
|
302 | ||
|
303 | void QBarSeriesPrivate::modelDataRemoved(QModelIndex parent, int start, int end) | |
|
304 | { | |
|
305 | Q_UNUSED(parent) | |
|
306 | Q_UNUSED(end) | |
|
307 | ||
|
308 | removeCategory(start - m_mapFirst); | |
|
309 | for (int i = 0; i <= m_mapBarTop - m_mapBarBottom; i++) | |
|
310 | { | |
|
311 | barsetAt(i)->removeValue(start - m_mapFirst); | |
|
312 | } | |
|
313 | emit restructuredBars(); | |
|
314 | } | |
|
315 | ||
|
316 | void QBarSeriesPrivate::barsetChanged() | |
|
317 | { | |
|
318 | emit updatedBars(); | |
|
319 | } | |
|
320 | ||
|
321 | QBarCategories QBarSeriesPrivate::categories() const | |
|
322 | { | |
|
323 | QBarCategories categories; | |
|
324 | int count = m_internalModel->categoryCount(); | |
|
325 | for (int i=1; i <= count; i++) { | |
|
326 | categories.insert(i, m_internalModel->categoryName(i - 1)); | |
|
327 | } | |
|
328 | return categories; | |
|
329 | } | |
|
330 | ||
|
331 | void QBarSeriesPrivate::setLabelsVisible(bool visible) | |
|
332 | { | |
|
333 | foreach (QBarSet* s, barSets()) { | |
|
334 | s->setLabelsVisible(visible); | |
|
335 | } | |
|
336 | } | |
|
337 | ||
|
338 | ||
|
30 | 339 | /*! |
|
31 | 340 | \class QBarSeries |
|
32 | 341 | \brief part of QtCommercial chart API. |
@@ -56,15 +365,16 QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||
|
56 | 365 | QBarSeries is QObject which is a child of a \a parent. |
|
57 | 366 | */ |
|
58 | 367 | QBarSeries::QBarSeries(QBarCategories categories, QObject *parent) : QSeries(parent), |
|
59 |
|
|
|
368 | d_ptr(new QBarSeriesPrivate(categories, this)) | |
|
369 | // m_internalModel(new BarChartModel(categories, this)) | |
|
60 | 370 | { |
|
61 | m_model = 0; | |
|
62 | m_mapCategories = -1; | |
|
63 | m_mapBarBottom = -1; | |
|
64 | m_mapBarTop = -1; | |
|
65 | m_mapFirst = 0; | |
|
66 | m_mapCount = 0; | |
|
67 | m_mapOrientation = Qt::Vertical; | |
|
371 | // m_model = 0; | |
|
372 | // m_mapCategories = -1; | |
|
373 | // m_mapBarBottom = -1; | |
|
374 | // m_mapBarTop = -1; | |
|
375 | // m_mapFirst = 0; | |
|
376 | // m_mapCount = 0; | |
|
377 | // m_mapOrientation = Qt::Vertical; | |
|
68 | 378 | } |
|
69 | 379 | |
|
70 | 380 | /*! |
@@ -74,10 +384,16 QBarSeries::QBarSeries(QBarCategories categories, QObject *parent) : QSeries(par | |||
|
74 | 384 | */ |
|
75 | 385 | void QBarSeries::appendBarSet(QBarSet *set) |
|
76 | 386 | { |
|
387 | Q_D(QBarSeries); | |
|
388 | connect(&QBarSetPrivate::pimpl(set), SIGNAL(clicked(QString,Qt::MouseButtons)), d_ptr, SLOT(barsetClicked(QString,Qt::MouseButtons))); | |
|
389 | connect(&QBarSetPrivate::pimpl(set), SIGNAL(valueChanged()), d_ptr, SLOT(barsetChanged())); | |
|
390 | d->appendBarSet(set); | |
|
391 | /* | |
|
77 | 392 | m_internalModel->appendBarSet(set); |
|
78 | 393 | connect(set, SIGNAL(clicked(QString,Qt::MouseButtons)), this, SLOT(barsetClicked(QString,Qt::MouseButtons))); |
|
79 | 394 | connect(set, SIGNAL(valueChanged()), this, SLOT(barsetChanged())); |
|
80 | 395 | emit restructuredBars(); |
|
396 | */ | |
|
81 | 397 | } |
|
82 | 398 | |
|
83 | 399 | /*! |
@@ -87,9 +403,14 void QBarSeries::appendBarSet(QBarSet *set) | |||
|
87 | 403 | */ |
|
88 | 404 | void QBarSeries::removeBarSet(QBarSet *set) |
|
89 | 405 | { |
|
406 | Q_D(QBarSeries); | |
|
407 | disconnect(&QBarSetPrivate::pimpl(set), SIGNAL(clicked(QString,Qt::MouseButtons)), d_ptr, SLOT(barsetClicked(QString,Qt::MouseButtons))); | |
|
408 | d->removeBarSet(set); | |
|
409 | /* | |
|
90 | 410 | disconnect(set, SIGNAL(clicked(QString,Qt::MouseButtons)), this, SLOT(barsetClicked(QString,Qt::MouseButtons))); |
|
91 | 411 | m_internalModel->removeBarSet(set); |
|
92 | 412 | emit restructuredBars(); |
|
413 | */ | |
|
93 | 414 | } |
|
94 | 415 | |
|
95 | 416 | /*! |
@@ -99,12 +420,16 void QBarSeries::removeBarSet(QBarSet *set) | |||
|
99 | 420 | */ |
|
100 | 421 | void QBarSeries::appendBarSets(QList<QBarSet* > sets) |
|
101 | 422 | { |
|
423 | Q_D(QBarSeries); | |
|
424 | d->appendBarSets(sets); | |
|
425 | /* | |
|
102 | 426 | foreach (QBarSet* barset, sets) { |
|
103 | 427 | m_internalModel->appendBarSet(barset); |
|
104 | 428 | connect(barset, SIGNAL(clicked(QString,Qt::MouseButtons)), this, SLOT(barsetClicked(QString,Qt::MouseButtons))); |
|
105 | 429 | connect(barset, SIGNAL(valueChanged()), this, SLOT(barsetChanged())); |
|
106 | 430 | } |
|
107 | 431 | emit restructuredBars(); |
|
432 | */ | |
|
108 | 433 | } |
|
109 | 434 | |
|
110 | 435 | /*! |
@@ -114,11 +439,15 void QBarSeries::appendBarSets(QList<QBarSet* > sets) | |||
|
114 | 439 | */ |
|
115 | 440 | void QBarSeries::removeBarSets(QList<QBarSet* > sets) |
|
116 | 441 | { |
|
442 | Q_D(QBarSeries); | |
|
443 | d->removeBarSets(sets); | |
|
444 | /* | |
|
117 | 445 | foreach (QBarSet* barset, sets) { |
|
118 | 446 | disconnect(barset, SIGNAL(clicked(QString,Qt::MouseButtons)), this, SLOT(barsetClicked(QString,Qt::MouseButtons))); |
|
119 | 447 | m_internalModel->removeBarSet(barset); |
|
120 | 448 | } |
|
121 | 449 | emit restructuredBars(); |
|
450 | */ | |
|
122 | 451 | } |
|
123 | 452 | |
|
124 | 453 | /*! |
@@ -127,8 +456,12 void QBarSeries::removeBarSets(QList<QBarSet* > sets) | |||
|
127 | 456 | */ |
|
128 | 457 | void QBarSeries::insertBarSet(int i, QBarSet *set) |
|
129 | 458 | { |
|
459 | Q_D(QBarSeries); | |
|
460 | d->insertBarSet(i,set); | |
|
461 | /* | |
|
130 | 462 | m_internalModel->insertBarSet(i, set); |
|
131 | 463 | // emit barsetChanged(); |
|
464 | */ | |
|
132 | 465 | } |
|
133 | 466 | |
|
134 | 467 | /*! |
@@ -138,7 +471,9 void QBarSeries::insertBarSet(int i, QBarSet *set) | |||
|
138 | 471 | */ |
|
139 | 472 | void QBarSeries::insertCategory(int i, QString category) |
|
140 | 473 | { |
|
141 | m_internalModel->insertCategory(i, category); | |
|
474 | Q_D(QBarSeries); | |
|
475 | d->insertCategory(i,category); | |
|
476 | //m_internalModel->insertCategory(i, category); | |
|
142 | 477 | } |
|
143 | 478 | |
|
144 | 479 | /*! |
@@ -147,7 +482,9 void QBarSeries::insertCategory(int i, QString category) | |||
|
147 | 482 | */ |
|
148 | 483 | void QBarSeries::removeCategory(int i) |
|
149 | 484 | { |
|
150 | m_internalModel->removeCategory(i); | |
|
485 | Q_D(QBarSeries); | |
|
486 | d->removeCategory(i); | |
|
487 | //m_internalModel->removeCategory(i); | |
|
151 | 488 | } |
|
152 | 489 | |
|
153 | 490 | /*! |
@@ -155,10 +492,14 void QBarSeries::removeCategory(int i) | |||
|
155 | 492 | */ |
|
156 | 493 | int QBarSeries::barsetCount() const |
|
157 | 494 | { |
|
495 | Q_D(const QBarSeries); | |
|
496 | return d->barsetCount(); | |
|
497 | /* | |
|
158 | 498 | // if(m_model) |
|
159 | 499 | // return m_mapBarTop - m_mapBarBottom; |
|
160 | 500 | // else |
|
161 | 501 | return m_internalModel->barsetCount(); |
|
502 | */ | |
|
162 | 503 | } |
|
163 | 504 | |
|
164 | 505 | /*! |
@@ -166,7 +507,9 int QBarSeries::barsetCount() const | |||
|
166 | 507 | */ |
|
167 | 508 | int QBarSeries::categoryCount() const |
|
168 | 509 | { |
|
169 | return m_internalModel->categoryCount(); | |
|
510 | Q_D(const QBarSeries); | |
|
511 | return d->categoryCount(); | |
|
512 | // return m_internalModel->categoryCount(); | |
|
170 | 513 | } |
|
171 | 514 | |
|
172 | 515 | /*! |
@@ -174,7 +517,9 int QBarSeries::categoryCount() const | |||
|
174 | 517 | */ |
|
175 | 518 | QList<QBarSet*> QBarSeries::barSets() const |
|
176 | 519 | { |
|
177 | return m_internalModel->barSets(); | |
|
520 | Q_D(const QBarSeries); | |
|
521 | return d->barSets(); | |
|
522 | // return m_internalModel->barSets(); | |
|
178 | 523 | } |
|
179 | 524 | |
|
180 | 525 | /*! |
@@ -182,7 +527,9 QList<QBarSet*> QBarSeries::barSets() const | |||
|
182 | 527 | */ |
|
183 | 528 | QBarSet* QBarSeries::barsetAt(int index) |
|
184 | 529 | { |
|
185 | return m_internalModel->barsetAt(index); | |
|
530 | Q_D(QBarSeries); | |
|
531 | return d->barsetAt(index); | |
|
532 | // return m_internalModel->barsetAt(index); | |
|
186 | 533 | } |
|
187 | 534 | |
|
188 | 535 | /*! |
@@ -190,7 +537,9 QBarSet* QBarSeries::barsetAt(int index) | |||
|
190 | 537 | */ |
|
191 | 538 | QString QBarSeries::categoryName(int category) |
|
192 | 539 | { |
|
193 | return m_internalModel->categoryName(category); | |
|
540 | Q_D(QBarSeries); | |
|
541 | return d->categoryName(category); | |
|
542 | // return m_internalModel->categoryName(category); | |
|
194 | 543 | } |
|
195 | 544 | |
|
196 | 545 | /*! |
@@ -200,6 +549,9 QString QBarSeries::categoryName(int category) | |||
|
200 | 549 | */ |
|
201 | 550 | void QBarSeries::setToolTipEnabled(bool enabled) |
|
202 | 551 | { |
|
552 | Q_D(QBarSeries); | |
|
553 | d->setToolTipEnabled(enabled); | |
|
554 | /* | |
|
203 | 555 | // TODO: what if we add sets after call to this function? Those sets won't have tooltip enabled. |
|
204 | 556 | if (enabled) { |
|
205 | 557 | for (int i=0; i<m_internalModel->barsetCount(); i++) { |
@@ -212,6 +564,7 void QBarSeries::setToolTipEnabled(bool enabled) | |||
|
212 | 564 | disconnect(set, SIGNAL(showToolTip(QPoint,QString)), this, SIGNAL(showToolTip(QPoint,QString))); |
|
213 | 565 | } |
|
214 | 566 | } |
|
567 | */ | |
|
215 | 568 | } |
|
216 | 569 | |
|
217 | 570 | |
@@ -220,7 +573,9 void QBarSeries::setToolTipEnabled(bool enabled) | |||
|
220 | 573 | */ |
|
221 | 574 | void QBarSeries::barsetClicked(QString category, Qt::MouseButtons button) |
|
222 | 575 | { |
|
223 | emit clicked(qobject_cast<QBarSet*>(sender()), category, button); | |
|
576 | Q_D(QBarSeries); | |
|
577 | d->barsetClicked(category,button); | |
|
578 | // emit clicked(qobject_cast<QBarSet*>(sender()), category, button); | |
|
224 | 579 | } |
|
225 | 580 | |
|
226 | 581 | /*! |
@@ -228,7 +583,9 void QBarSeries::barsetClicked(QString category, Qt::MouseButtons button) | |||
|
228 | 583 | */ |
|
229 | 584 | qreal QBarSeries::min() |
|
230 | 585 | { |
|
231 | return m_internalModel->min(); | |
|
586 | Q_D(QBarSeries); | |
|
587 | return d->min(); | |
|
588 | //return m_internalModel->min(); | |
|
232 | 589 | } |
|
233 | 590 | |
|
234 | 591 | /*! |
@@ -236,7 +593,9 qreal QBarSeries::min() | |||
|
236 | 593 | */ |
|
237 | 594 | qreal QBarSeries::max() |
|
238 | 595 | { |
|
239 | return m_internalModel->max(); | |
|
596 | Q_D(QBarSeries); | |
|
597 | return d->max(); | |
|
598 | // return m_internalModel->max(); | |
|
240 | 599 | } |
|
241 | 600 | |
|
242 | 601 | /*! |
@@ -244,7 +603,9 qreal QBarSeries::max() | |||
|
244 | 603 | */ |
|
245 | 604 | qreal QBarSeries::valueAt(int set, int category) |
|
246 | 605 | { |
|
247 | return m_internalModel->valueAt(set, category); | |
|
606 | Q_D(QBarSeries); | |
|
607 | return d->valueAt(set,category); | |
|
608 | // return m_internalModel->valueAt(set, category); | |
|
248 | 609 | } |
|
249 | 610 | |
|
250 | 611 | /*! |
@@ -252,7 +613,9 qreal QBarSeries::valueAt(int set, int category) | |||
|
252 | 613 | */ |
|
253 | 614 | qreal QBarSeries::percentageAt(int set, int category) |
|
254 | 615 | { |
|
255 | return m_internalModel->percentageAt(set, category); | |
|
616 | Q_D(QBarSeries); | |
|
617 | return d->percentageAt(set,category); | |
|
618 | // return m_internalModel->percentageAt(set, category); | |
|
256 | 619 | } |
|
257 | 620 | |
|
258 | 621 | /*! |
@@ -260,7 +623,9 qreal QBarSeries::percentageAt(int set, int category) | |||
|
260 | 623 | */ |
|
261 | 624 | qreal QBarSeries::categorySum(int category) |
|
262 | 625 | { |
|
263 | return m_internalModel->categorySum(category); | |
|
626 | Q_D(QBarSeries); | |
|
627 | return d->categorySum(category); | |
|
628 | // return m_internalModel->categorySum(category); | |
|
264 | 629 | } |
|
265 | 630 | |
|
266 | 631 | /*! |
@@ -268,7 +633,9 qreal QBarSeries::categorySum(int category) | |||
|
268 | 633 | */ |
|
269 | 634 | qreal QBarSeries::absoluteCategorySum(int category) |
|
270 | 635 | { |
|
271 | return m_internalModel->absoluteCategorySum(category); | |
|
636 | Q_D(QBarSeries); | |
|
637 | return d->absoluteCategorySum(category); | |
|
638 | // return m_internalModel->absoluteCategorySum(category); | |
|
272 | 639 | } |
|
273 | 640 | |
|
274 | 641 | /*! |
@@ -276,7 +643,9 qreal QBarSeries::absoluteCategorySum(int category) | |||
|
276 | 643 | */ |
|
277 | 644 | qreal QBarSeries::maxCategorySum() |
|
278 | 645 | { |
|
279 | return m_internalModel->maxCategorySum(); | |
|
646 | Q_D(QBarSeries); | |
|
647 | return d->maxCategorySum(); | |
|
648 | // return m_internalModel->maxCategorySum(); | |
|
280 | 649 | } |
|
281 | 650 | |
|
282 | 651 | /*! |
@@ -284,7 +653,9 qreal QBarSeries::maxCategorySum() | |||
|
284 | 653 | */ |
|
285 | 654 | BarChartModel& QBarSeries::modelInternal() |
|
286 | 655 | { |
|
287 | return *m_internalModel; | |
|
656 | Q_D(QBarSeries); | |
|
657 | return d->modelInternal(); | |
|
658 | // return *m_internalModel; | |
|
288 | 659 | } |
|
289 | 660 | |
|
290 | 661 | /*! |
@@ -293,6 +664,9 BarChartModel& QBarSeries::modelInternal() | |||
|
293 | 664 | */ |
|
294 | 665 | bool QBarSeries::setModel(QAbstractItemModel *model) |
|
295 | 666 | { |
|
667 | Q_D(QBarSeries); | |
|
668 | return d->setModel(model); | |
|
669 | /* | |
|
296 | 670 | // disconnect signals from old model |
|
297 | 671 | if(m_model) |
|
298 | 672 | { |
@@ -316,6 +690,7 bool QBarSeries::setModel(QAbstractItemModel *model) | |||
|
316 | 690 | m_model = 0; |
|
317 | 691 | return false; |
|
318 | 692 | } |
|
693 | */ | |
|
319 | 694 | } |
|
320 | 695 | |
|
321 | 696 | /*! |
@@ -326,8 +701,11 bool QBarSeries::setModel(QAbstractItemModel *model) | |||
|
326 | 701 | All the columns/rows inbetween those two values are also used as data for bar sets. |
|
327 | 702 | The \a orientation paramater specifies whether the data is in columns or in rows. |
|
328 | 703 | */ |
|
329 | void QBarSeries::setModelMapping(int categories, int bottomBoundry, int topBoundry, Qt::Orientation orientation) | |
|
704 | void QBarSeries::setModelMapping(int categories, int bottomBoundary, int topBoundary, Qt::Orientation orientation) | |
|
330 | 705 | { |
|
706 | Q_D(QBarSeries); | |
|
707 | d->setModelMapping(categories,bottomBoundary,topBoundary,orientation); | |
|
708 | /* | |
|
331 | 709 | if (!m_model) |
|
332 | 710 | return; |
|
333 | 711 |
|
@@ -383,6 +761,7 void QBarSeries::setModelMapping(int categories, int bottomBoundry, int topBound | |||
|
383 | 761 | appendBarSet(barSet); |
|
384 | 762 | } |
|
385 | 763 | } |
|
764 | */ | |
|
386 | 765 | } |
|
387 | 766 | |
|
388 | 767 | /*! |
@@ -390,6 +769,9 void QBarSeries::setModelMapping(int categories, int bottomBoundry, int topBound | |||
|
390 | 769 | */ |
|
391 | 770 | void QBarSeries::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight) |
|
392 | 771 | { |
|
772 | Q_D(QBarSeries); | |
|
773 | d->modelUpdated(topLeft,bottomRight); | |
|
774 | /* | |
|
393 | 775 | Q_UNUSED(bottomRight) |
|
394 | 776 |
|
|
395 | 777 | if (m_mapOrientation == Qt::Vertical) |
@@ -404,13 +786,17 void QBarSeries::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight) | |||
|
404 | 786 | if (topLeft.row() >= m_mapBarBottom && topLeft.row() <= m_mapBarTop && topLeft.column() >= m_mapFirst && topLeft.column() < m_mapFirst + m_mapCount) |
|
405 | 787 | barsetAt(topLeft.row() - m_mapBarBottom)->setValue(topLeft.column() - m_mapFirst, m_model->data(topLeft, Qt::DisplayRole).toDouble()); |
|
406 | 788 | } |
|
789 | */ | |
|
407 | 790 | } |
|
408 | 791 | |
|
409 | 792 | /*! |
|
410 | 793 | \internal |
|
411 | 794 | */ |
|
412 |
void QBarSeries::modelDataAdded(QModelIndex |
|
|
795 | void QBarSeries::modelDataAdded(QModelIndex parent, int start, int end) | |
|
413 | 796 | { |
|
797 | Q_D(QBarSeries); | |
|
798 | d->modelDataAdded(parent,start,end); | |
|
799 | /* | |
|
414 | 800 | if (m_mapOrientation == Qt::Vertical) { |
|
415 | 801 | insertCategory(start - m_mapFirst, QString("Row: %1").arg(start + 1)); |
|
416 | 802 | for (int i = 0; i <= m_mapBarTop - m_mapBarBottom; i++) { |
@@ -423,6 +809,7 void QBarSeries::modelDataAdded(QModelIndex /*parent*/, int start, int /*end*/) | |||
|
423 | 809 | } |
|
424 | 810 | } |
|
425 | 811 | emit restructuredBars(); |
|
812 | */ | |
|
426 | 813 | } |
|
427 | 814 | |
|
428 | 815 | /*! |
@@ -430,6 +817,9 void QBarSeries::modelDataAdded(QModelIndex /*parent*/, int start, int /*end*/) | |||
|
430 | 817 | */ |
|
431 | 818 | void QBarSeries::modelDataRemoved(QModelIndex parent, int start, int end) |
|
432 | 819 | { |
|
820 | Q_D(QBarSeries); | |
|
821 | d->modelDataRemoved(parent,start,end); | |
|
822 | /* | |
|
433 | 823 | Q_UNUSED(parent) |
|
434 | 824 | Q_UNUSED(end) |
|
435 | 825 |
|
@@ -439,21 +829,28 void QBarSeries::modelDataRemoved(QModelIndex parent, int start, int end) | |||
|
439 | 829 | barsetAt(i)->removeValue(start - m_mapFirst); |
|
440 | 830 | } |
|
441 | 831 | emit restructuredBars(); |
|
832 | */ | |
|
442 | 833 | } |
|
443 | 834 | |
|
444 | 835 | void QBarSeries::barsetChanged() |
|
445 | 836 | { |
|
446 | emit updatedBars(); | |
|
837 | Q_D(QBarSeries); | |
|
838 | d->barsetChanged(); | |
|
839 | // emit updatedBars(); | |
|
447 | 840 | } |
|
448 | 841 | |
|
449 | 842 | QBarCategories QBarSeries::categories() const |
|
450 | 843 | { |
|
844 | Q_D(const QBarSeries); | |
|
845 | return d->categories(); | |
|
846 | /* | |
|
451 | 847 | QBarCategories categories; |
|
452 | 848 | int count = m_internalModel->categoryCount(); |
|
453 | 849 | for (int i=1; i <= count; i++) { |
|
454 | 850 | categories.insert(i, m_internalModel->categoryName(i - 1)); |
|
455 | 851 | } |
|
456 | 852 | return categories; |
|
853 | */ | |
|
457 | 854 | } |
|
458 | 855 | |
|
459 | 856 | /*! |
@@ -461,12 +858,17 QBarCategories QBarSeries::categories() const | |||
|
461 | 858 | */ |
|
462 | 859 | void QBarSeries::setLabelsVisible(bool visible) |
|
463 | 860 | { |
|
861 | Q_D(QBarSeries); | |
|
862 | d->setLabelsVisible(visible); | |
|
863 | /* | |
|
464 | 864 | foreach (QBarSet* s, barSets()) { |
|
465 | 865 | s->setLabelsVisible(visible); |
|
466 | 866 | } |
|
867 | */ | |
|
467 | 868 | } |
|
468 | 869 | |
|
469 | 870 | |
|
470 | 871 | #include "moc_qbarseries.cpp" |
|
872 | #include "moc_qbarseriesprivate_p.cpp" | |
|
471 | 873 | |
|
472 | 874 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -33,6 +33,7 typedef QStringList QBarCategories; | |||
|
33 | 33 | class QBarSet; |
|
34 | 34 | class BarChartModel; |
|
35 | 35 | class BarCategory; |
|
36 | class QBarSeriesPrivate; | |
|
36 | 37 | |
|
37 | 38 | // Container for series |
|
38 | 39 | class QTCOMMERCIALCHART_EXPORT QBarSeries : public QSeries |
@@ -58,7 +59,7 public: | |||
|
58 | 59 | void setLabelsVisible(bool visible = true); |
|
59 | 60 | |
|
60 | 61 | bool setModel(QAbstractItemModel *model); |
|
61 |
void setModelMapping(int categories, int bottomBoundry, int topBoundry, Qt::Orientation orientation = Qt::Vertical); |
|
|
62 | void setModelMapping(int categories, int bottomBoundary, int topBoundary, Qt::Orientation orientation = Qt::Vertical); | |
|
62 | 63 | |
|
63 | 64 | public: |
|
64 | 65 | // TODO: Functions below this are not part of api and will be moved |
@@ -85,7 +86,7 Q_SIGNALS: | |||
|
85 | 86 | |
|
86 | 87 | // TODO: internal signals, these to private implementation. |
|
87 | 88 | // TODO: TO PIMPL ---> |
|
88 | void showToolTip(QPoint pos, QString tip); | |
|
89 | // void showToolTip(QPoint pos, QString tip); | |
|
89 | 90 | // <--- TO PIMPL |
|
90 | 91 | |
|
91 | 92 | public Q_SLOTS: |
@@ -103,6 +104,11 private Q_SLOTS: | |||
|
103 | 104 | void barsetChanged(); |
|
104 | 105 | |
|
105 | 106 | protected: |
|
107 | QBarSeriesPrivate * const d_ptr; | |
|
108 | Q_DECLARE_PRIVATE(QBarSeries) | |
|
109 | Q_DISABLE_COPY(QBarSeries) | |
|
110 | ||
|
111 | /* | |
|
106 | 112 | BarChartModel *m_internalModel; // TODO: this may change... current "2 models" situation doesn't look good. |
|
107 | 113 |
|
|
108 | 114 |
|
@@ -112,6 +118,7 protected: | |||
|
112 | 118 | int m_mapFirst; |
|
113 | 119 | int m_mapCount; |
|
114 | 120 | Qt::Orientation m_mapOrientation; |
|
121 | */ | |
|
115 | 122 | }; |
|
116 | 123 | |
|
117 | 124 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -19,11 +19,157 | |||
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #include "qbarset.h" |
|
22 | #include <QDebug> | |
|
22 | #include "qbarsetprivate_p.h" | |
|
23 | //#include <QDebug> | |
|
23 | 24 | #include <QToolTip> |
|
24 | 25 | |
|
25 | 26 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
26 | 27 | |
|
28 | ||
|
29 | QBarSetPrivate::QBarSetPrivate(QString name, QBarSet *parent) : QObject(parent), | |
|
30 | q_ptr(parent), | |
|
31 | m_name(name), | |
|
32 | m_labelsVisible(false) | |
|
33 | { | |
|
34 | ||
|
35 | } | |
|
36 | ||
|
37 | QBarSetPrivate::~QBarSetPrivate() | |
|
38 | { | |
|
39 | ||
|
40 | } | |
|
41 | ||
|
42 | void QBarSetPrivate::setName(QString name) | |
|
43 | { | |
|
44 | m_name = name; | |
|
45 | } | |
|
46 | ||
|
47 | QString QBarSetPrivate::name() const | |
|
48 | { | |
|
49 | return m_name; | |
|
50 | } | |
|
51 | ||
|
52 | QBarSetPrivate& QBarSetPrivate::operator << (const qreal &value) | |
|
53 | { | |
|
54 | m_values.append(value); | |
|
55 | emit structureChanged(); | |
|
56 | return *this; | |
|
57 | } | |
|
58 | ||
|
59 | void QBarSetPrivate::insertValue(int i, qreal value) | |
|
60 | { | |
|
61 | m_values.insert(i, value); | |
|
62 | } | |
|
63 | ||
|
64 | void QBarSetPrivate::removeValue(int i) | |
|
65 | { | |
|
66 | m_values.removeAt(i); | |
|
67 | } | |
|
68 | ||
|
69 | int QBarSetPrivate::count() const | |
|
70 | { | |
|
71 | return m_values.count(); | |
|
72 | } | |
|
73 | ||
|
74 | qreal QBarSetPrivate::valueAt(int index) const | |
|
75 | { | |
|
76 | return m_values.at(index); | |
|
77 | } | |
|
78 | ||
|
79 | void QBarSetPrivate::setValue(int index, qreal value) | |
|
80 | { | |
|
81 | m_values.replace(index,value); | |
|
82 | emit valueChanged(); | |
|
83 | } | |
|
84 | ||
|
85 | qreal QBarSetPrivate::sum() const | |
|
86 | { | |
|
87 | qreal sum(0); | |
|
88 | for (int i=0; i < m_values.count(); i++) { | |
|
89 | sum += m_values.at(i); | |
|
90 | } | |
|
91 | return sum; | |
|
92 | } | |
|
93 | ||
|
94 | void QBarSetPrivate::setPen(const QPen &pen) | |
|
95 | { | |
|
96 | m_pen = pen; | |
|
97 | emit valueChanged(); | |
|
98 | } | |
|
99 | ||
|
100 | QPen QBarSetPrivate::pen() const | |
|
101 | { | |
|
102 | return m_pen; | |
|
103 | } | |
|
104 | ||
|
105 | void QBarSetPrivate::setBrush(const QBrush &brush) | |
|
106 | { | |
|
107 | m_brush = brush; | |
|
108 | emit valueChanged(); | |
|
109 | } | |
|
110 | ||
|
111 | QBrush QBarSetPrivate::brush() const | |
|
112 | { | |
|
113 | return m_brush; | |
|
114 | } | |
|
115 | ||
|
116 | void QBarSetPrivate::setLabelPen(const QPen &pen) | |
|
117 | { | |
|
118 | m_labelPen = pen; | |
|
119 | emit valueChanged(); | |
|
120 | } | |
|
121 | ||
|
122 | QPen QBarSetPrivate::labelPen() const | |
|
123 | { | |
|
124 | return m_labelPen; | |
|
125 | } | |
|
126 | ||
|
127 | void QBarSetPrivate::setLabelBrush(const QBrush &brush) | |
|
128 | { | |
|
129 | m_labelBrush = brush; | |
|
130 | emit valueChanged(); | |
|
131 | } | |
|
132 | ||
|
133 | QBrush QBarSetPrivate::labelBrush() const | |
|
134 | { | |
|
135 | return m_labelBrush; | |
|
136 | } | |
|
137 | ||
|
138 | void QBarSetPrivate::setLabelFont(const QFont &font) | |
|
139 | { | |
|
140 | m_labelFont = font; | |
|
141 | emit valueChanged(); | |
|
142 | } | |
|
143 | ||
|
144 | QFont QBarSetPrivate::labelFont() const | |
|
145 | { | |
|
146 | return m_labelFont; | |
|
147 | } | |
|
148 | ||
|
149 | void QBarSetPrivate::setLabelsVisible(bool visible) | |
|
150 | { | |
|
151 | m_labelsVisible = visible; | |
|
152 | emit labelsVisibleChanged(visible); | |
|
153 | } | |
|
154 | ||
|
155 | bool QBarSetPrivate::labelsVisible() const | |
|
156 | { | |
|
157 | return m_labelsVisible; | |
|
158 | } | |
|
159 | ||
|
160 | void QBarSetPrivate::barHoverEnterEvent(QPoint pos) | |
|
161 | { | |
|
162 | emit showToolTip(pos, m_name); | |
|
163 | emit hoverEnter(pos); | |
|
164 | } | |
|
165 | ||
|
166 | void QBarSetPrivate::barHoverLeaveEvent() | |
|
167 | { | |
|
168 | // Emit signal to user of charts | |
|
169 | emit hoverLeave(); | |
|
170 | } | |
|
171 | ||
|
172 | ||
|
27 | 173 | /*! |
|
28 | 174 | \class QBarSet |
|
29 | 175 | \brief part of QtCommercial chart API. |
@@ -66,8 +212,9 QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||
|
66 | 212 | */ |
|
67 | 213 | QBarSet::QBarSet(QString name, QObject *parent) |
|
68 | 214 | : QObject(parent) |
|
69 | ,m_name(name) | |
|
70 | ,m_labelsVisible(false) | |
|
215 | ,d_ptr(new QBarSetPrivate(name,this)) | |
|
216 | // ,m_name(name) | |
|
217 | // ,m_labelsVisible(false) | |
|
71 | 218 | { |
|
72 | 219 | } |
|
73 | 220 | |
@@ -76,7 +223,8 QBarSet::QBarSet(QString name, QObject *parent) | |||
|
76 | 223 | */ |
|
77 | 224 | void QBarSet::setName(QString name) |
|
78 | 225 | { |
|
79 | m_name = name; | |
|
226 | Q_D(QBarSet); | |
|
227 | d->setName(name); | |
|
80 | 228 | } |
|
81 | 229 | |
|
82 | 230 | /*! |
@@ -84,7 +232,8 void QBarSet::setName(QString name) | |||
|
84 | 232 | */ |
|
85 | 233 | QString QBarSet::name() const |
|
86 | 234 | { |
|
87 | return m_name; | |
|
235 | Q_D(const QBarSet); | |
|
236 | return d->name(); | |
|
88 | 237 | } |
|
89 | 238 | |
|
90 | 239 | /*! |
@@ -92,9 +241,13 QString QBarSet::name() const | |||
|
92 | 241 | */ |
|
93 | 242 | QBarSet& QBarSet::operator << (const qreal &value) |
|
94 | 243 | { |
|
95 | m_values.append(value); | |
|
96 | emit structureChanged(); | |
|
244 | Q_D(QBarSet); | |
|
245 | d->operator <<(value); | |
|
97 | 246 | return *this; |
|
247 | ||
|
248 | // m_values.append(value); | |
|
249 | // emit structureChanged(); | |
|
250 | // return *this; | |
|
98 | 251 | } |
|
99 | 252 | |
|
100 | 253 | /*! |
@@ -104,7 +257,9 QBarSet& QBarSet::operator << (const qreal &value) | |||
|
104 | 257 | */ |
|
105 | 258 | void QBarSet::insertValue(int i, qreal value) |
|
106 | 259 | { |
|
107 | m_values.insert(i, value); | |
|
260 | Q_D(QBarSet); | |
|
261 | d->insertValue(i,value); | |
|
262 | // m_values.insert(i, value); | |
|
108 | 263 | } |
|
109 | 264 | |
|
110 | 265 | /*! |
@@ -113,7 +268,9 void QBarSet::insertValue(int i, qreal value) | |||
|
113 | 268 | */ |
|
114 | 269 | void QBarSet::removeValue(int i) |
|
115 | 270 | { |
|
116 | m_values.removeAt(i); | |
|
271 | Q_D(QBarSet); | |
|
272 | d->removeValue(i); | |
|
273 | // m_values.removeAt(i); | |
|
117 | 274 | } |
|
118 | 275 | |
|
119 | 276 | /*! |
@@ -121,7 +278,9 void QBarSet::removeValue(int i) | |||
|
121 | 278 | */ |
|
122 | 279 | int QBarSet::count() const |
|
123 | 280 | { |
|
124 | return m_values.count(); | |
|
281 | Q_D(const QBarSet); | |
|
282 | return d->count(); | |
|
283 | // return m_values.count(); | |
|
125 | 284 | } |
|
126 | 285 | |
|
127 | 286 | /*! |
@@ -129,7 +288,9 int QBarSet::count() const | |||
|
129 | 288 | */ |
|
130 | 289 | qreal QBarSet::valueAt(int index) const |
|
131 | 290 | { |
|
132 | return m_values.at(index); | |
|
291 | Q_D(const QBarSet); | |
|
292 | return d->valueAt(index); | |
|
293 | // return m_values.at(index); | |
|
133 | 294 | } |
|
134 | 295 | |
|
135 | 296 | /*! |
@@ -137,20 +298,26 qreal QBarSet::valueAt(int index) const | |||
|
137 | 298 | */ |
|
138 | 299 | void QBarSet::setValue(int index, qreal value) |
|
139 | 300 | { |
|
140 | m_values.replace(index,value); | |
|
141 | emit valueChanged(); | |
|
301 | Q_D(QBarSet); | |
|
302 | d->setValue(index,value); | |
|
303 | // m_values.replace(index,value); | |
|
304 | // emit valueChanged(); | |
|
142 | 305 | } |
|
143 | 306 | |
|
144 | 307 | /*! |
|
145 |
Returns |
|
|
308 | Returns sum of all values in barset. | |
|
146 | 309 | */ |
|
147 |
qreal QBarSet:: |
|
|
310 | qreal QBarSet::sum() const | |
|
148 | 311 | { |
|
312 | Q_D(const QBarSet); | |
|
313 | return d->sum(); | |
|
314 | /* | |
|
149 | 315 | qreal total(0); |
|
150 | 316 | for (int i=0; i < m_values.count(); i++) { |
|
151 | 317 | total += m_values.at(i); |
|
152 | 318 | } |
|
153 | 319 | return total; |
|
320 | */ | |
|
154 | 321 | } |
|
155 | 322 | |
|
156 | 323 | /*! |
@@ -158,8 +325,10 qreal QBarSet::total() const | |||
|
158 | 325 | */ |
|
159 | 326 | void QBarSet::setPen(const QPen &pen) |
|
160 | 327 | { |
|
161 | m_pen = pen; | |
|
162 | emit valueChanged(); | |
|
328 | Q_D(QBarSet); | |
|
329 | d->setPen(pen); | |
|
330 | // m_pen = pen; | |
|
331 | // emit valueChanged(); | |
|
163 | 332 | } |
|
164 | 333 | |
|
165 | 334 | /*! |
@@ -167,7 +336,9 void QBarSet::setPen(const QPen &pen) | |||
|
167 | 336 | */ |
|
168 | 337 | QPen QBarSet::pen() const |
|
169 | 338 | { |
|
170 | return m_pen; | |
|
339 | Q_D(const QBarSet); | |
|
340 | return d->pen(); | |
|
341 | // return m_pen; | |
|
171 | 342 | } |
|
172 | 343 | |
|
173 | 344 | /*! |
@@ -175,8 +346,10 QPen QBarSet::pen() const | |||
|
175 | 346 | */ |
|
176 | 347 | void QBarSet::setBrush(const QBrush &brush) |
|
177 | 348 | { |
|
178 | m_brush = brush; | |
|
179 | emit valueChanged(); | |
|
349 | Q_D(QBarSet); | |
|
350 | d->setBrush(brush); | |
|
351 | // m_brush = brush; | |
|
352 | // emit valueChanged(); | |
|
180 | 353 | } |
|
181 | 354 | |
|
182 | 355 | /*! |
@@ -184,7 +357,9 void QBarSet::setBrush(const QBrush &brush) | |||
|
184 | 357 | */ |
|
185 | 358 | QBrush QBarSet::brush() const |
|
186 | 359 | { |
|
187 | return m_brush; | |
|
360 | Q_D(const QBarSet); | |
|
361 | return d->brush(); | |
|
362 | // return m_brush; | |
|
188 | 363 | } |
|
189 | 364 | |
|
190 | 365 | /*! |
@@ -192,8 +367,10 QBrush QBarSet::brush() const | |||
|
192 | 367 | */ |
|
193 | 368 | void QBarSet::setLabelPen(const QPen &pen) |
|
194 | 369 | { |
|
195 | m_labelPen = pen; | |
|
196 | emit valueChanged(); | |
|
370 | Q_D(QBarSet); | |
|
371 | d->setLabelPen(pen); | |
|
372 | // m_labelPen = pen; | |
|
373 | // emit valueChanged(); | |
|
197 | 374 | } |
|
198 | 375 | |
|
199 | 376 | /*! |
@@ -201,7 +378,9 void QBarSet::setLabelPen(const QPen &pen) | |||
|
201 | 378 | */ |
|
202 | 379 | QPen QBarSet::labelPen() const |
|
203 | 380 | { |
|
204 | return m_labelPen; | |
|
381 | Q_D(const QBarSet); | |
|
382 | return d->labelPen(); | |
|
383 | // return m_labelPen; | |
|
205 | 384 | } |
|
206 | 385 | |
|
207 | 386 | /*! |
@@ -209,8 +388,10 QPen QBarSet::labelPen() const | |||
|
209 | 388 | */ |
|
210 | 389 | void QBarSet::setLabelBrush(const QBrush &brush) |
|
211 | 390 | { |
|
212 | m_labelBrush = brush; | |
|
213 | emit valueChanged(); | |
|
391 | Q_D(QBarSet); | |
|
392 | d->setLabelBrush(brush); | |
|
393 | // m_labelBrush = brush; | |
|
394 | // emit valueChanged(); | |
|
214 | 395 | } |
|
215 | 396 | |
|
216 | 397 | /*! |
@@ -218,7 +399,9 void QBarSet::setLabelBrush(const QBrush &brush) | |||
|
218 | 399 | */ |
|
219 | 400 | QBrush QBarSet::labelBrush() const |
|
220 | 401 | { |
|
221 | return m_labelBrush; | |
|
402 | Q_D(const QBarSet); | |
|
403 | return d->labelBrush(); | |
|
404 | // return m_labelBrush; | |
|
222 | 405 | } |
|
223 | 406 | |
|
224 | 407 | /*! |
@@ -226,8 +409,10 QBrush QBarSet::labelBrush() const | |||
|
226 | 409 | */ |
|
227 | 410 | void QBarSet::setLabelFont(const QFont &font) |
|
228 | 411 | { |
|
229 | m_labelFont = font; | |
|
230 | emit valueChanged(); | |
|
412 | Q_D(QBarSet); | |
|
413 | d->setLabelFont(font); | |
|
414 | // m_labelFont = font; | |
|
415 | // emit valueChanged(); | |
|
231 | 416 | } |
|
232 | 417 | |
|
233 | 418 | /*! |
@@ -235,7 +420,9 void QBarSet::setLabelFont(const QFont &font) | |||
|
235 | 420 | */ |
|
236 | 421 | QFont QBarSet::labelFont() const |
|
237 | 422 | { |
|
238 | return m_labelFont; | |
|
423 | Q_D(const QBarSet); | |
|
424 | return d->labelFont(); | |
|
425 | // return m_labelFont; | |
|
239 | 426 | } |
|
240 | 427 | |
|
241 | 428 | /*! |
@@ -244,8 +431,10 QFont QBarSet::labelFont() const | |||
|
244 | 431 | |
|
245 | 432 | void QBarSet::setLabelsVisible(bool visible) |
|
246 | 433 | { |
|
247 | m_labelsVisible = visible; | |
|
248 |
|
|
|
434 | Q_D(QBarSet); | |
|
435 | d->setLabelsVisible(visible); | |
|
436 | // m_labelsVisible = visible; | |
|
437 | // emit labelsVisibleChanged(visible); | |
|
249 | 438 | } |
|
250 | 439 | |
|
251 | 440 | /*! |
@@ -253,27 +442,26 void QBarSet::setLabelsVisible(bool visible) | |||
|
253 | 442 | */ |
|
254 | 443 | bool QBarSet::labelsVisible() const |
|
255 | 444 | { |
|
256 | return m_labelsVisible; | |
|
445 | Q_D(const QBarSet); | |
|
446 | return d->labelsVisible(); | |
|
447 | // return m_labelsVisible; | |
|
257 | 448 | } |
|
258 | 449 | |
|
259 |
/* |
|
|
260 | \internal \a pos | |
|
261 | */ | |
|
450 | /* | |
|
262 | 451 | void QBarSet::barHoverEnterEvent(QPoint pos) |
|
263 | 452 |
|
|
264 | 453 | emit showToolTip(pos, m_name); |
|
265 | 454 | emit hoverEnter(pos); |
|
266 | 455 |
|
|
267 | ||
|
268 | /*! | |
|
269 | \internal | |
|
270 | 456 | */ |
|
457 | /* | |
|
271 | 458 | void QBarSet::barHoverLeaveEvent() |
|
272 | 459 |
|
|
273 | 460 | // Emit signal to user of charts |
|
274 | 461 | emit hoverLeave(); |
|
275 | 462 |
|
|
276 | ||
|
463 | */ | |
|
277 | 464 | #include "moc_qbarset.cpp" |
|
465 | #include "moc_qbarsetprivate_p.cpp" | |
|
278 | 466 | |
|
279 | 467 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -27,6 +27,7 | |||
|
27 | 27 | #include <QFont> |
|
28 | 28 | |
|
29 | 29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
30 | class QBarSetPrivate; | |
|
30 | 31 | |
|
31 | 32 | class QTCOMMERCIALCHART_EXPORT QBarSet : public QObject |
|
32 | 33 | { |
@@ -39,16 +40,10 public: | |||
|
39 | 40 | QBarSet& operator << (const qreal &value); // appends new value to set |
|
40 | 41 | void insertValue(int i, qreal value); |
|
41 | 42 | void removeValue(int i); |
|
42 | ||
|
43 | // TODO: remove indices eventually. Use as internal? | |
|
44 | 43 | int count() const; // count of values in set |
|
45 | 44 |
qreal valueAt(int index) const; |
|
46 | 45 | void setValue(int index, qreal value); // setter for individual value |
|
47 |
qreal |
|
|
48 | ||
|
49 | // TODO: | |
|
50 | //qreal value(QString category); | |
|
51 | //void setValue(QString category, qreal value); | |
|
46 | qreal sum() const; // sum of all values in the set | |
|
52 | 47 | |
|
53 | 48 | void setPen(const QPen &pen); |
|
54 | 49 | QPen pen() const; |
@@ -72,23 +67,26 Q_SIGNALS: | |||
|
72 | 67 | void clicked(QString category, Qt::MouseButtons button); // Clicked and hover signals exposed to user |
|
73 | 68 | |
|
74 | 69 | // TODO: TO PIMPL ---> |
|
75 | void structureChanged(); | |
|
76 | void valueChanged(); | |
|
77 | void hoverEnter(QPoint pos); | |
|
78 | void hoverLeave(); | |
|
79 | void showToolTip(QPoint pos, QString tip); // Private signal | |
|
80 | void labelsVisibleChanged(bool visible); | |
|
70 | // void structureChanged(); | |
|
71 | // void valueChanged(); | |
|
72 | // void hoverEnter(QPoint pos); | |
|
73 | // void hoverLeave(); | |
|
74 | // void showToolTip(QPoint pos, QString tip); // Private signal | |
|
75 | // void labelsVisibleChanged(bool visible); | |
|
81 | 76 | // <--- TO PIMPL |
|
82 | 77 | |
|
83 | 78 | public Q_SLOTS: |
|
84 | 79 | // These are for internal communication |
|
85 | 80 | // TODO: TO PIMPL ---> |
|
86 | void barHoverEnterEvent(QPoint pos); | |
|
87 | void barHoverLeaveEvent(); | |
|
81 | // void barHoverEnterEvent(QPoint pos); | |
|
82 | // void barHoverLeaveEvent(); | |
|
88 | 83 | // <--- TO PIMPL |
|
89 | 84 | |
|
90 | 85 | private: |
|
91 | ||
|
86 | QBarSetPrivate * const d_ptr; | |
|
87 | Q_DECLARE_PRIVATE(QBarSet) | |
|
88 | Q_DISABLE_COPY(QBarSet) | |
|
89 | /* | |
|
92 | 90 | QString m_name; |
|
93 | 91 | QList<qreal> m_values; // TODO: replace with map (category, value) |
|
94 | 92 | QMap<QString, qreal> m_mappedValues; |
@@ -98,6 +96,7 private: | |||
|
98 | 96 | QBrush m_labelBrush; |
|
99 | 97 | QFont m_labelFont; |
|
100 | 98 | bool m_labelsVisible; |
|
99 | */ | |
|
101 | 100 | }; |
|
102 | 101 | |
|
103 | 102 | QTCOMMERCIALCHART_END_NAMESPACE |
General Comments 0
You need to be logged in to leave comments.
Login now