@@ -29,6 +29,16 void BarChartModel::removeBarSet(QBarSet *set) | |||
|
29 | 29 | } |
|
30 | 30 | } |
|
31 | 31 | |
|
32 | void BarChartModel::insertBarSet(int i, QBarSet *set) | |
|
33 | { | |
|
34 | mDataModel.insert(i, set); | |
|
35 | } | |
|
36 | ||
|
37 | void BarChartModel::insertCategory(int i, QString category) | |
|
38 | { | |
|
39 | mCategory.insert(i, category); | |
|
40 | } | |
|
41 | ||
|
32 | 42 | QBarSet* BarChartModel::setAt(int index) |
|
33 | 43 | { |
|
34 | 44 | return mDataModel.at(index); |
@@ -22,6 +22,8 public: | |||
|
22 | 22 | QStringList category(); |
|
23 | 23 | void addBarSet(QBarSet *set); |
|
24 | 24 | void removeBarSet(QBarSet *set); |
|
25 | void insertBarSet(int i, QBarSet *set); | |
|
26 | void insertCategory(int i, QString category); | |
|
25 | 27 | QBarSet *setAt(int index); |
|
26 | 28 | QList<QBarSet*> barSets(); |
|
27 | 29 |
@@ -10,6 +10,7 BarPresenter::BarPresenter(QBarSeries *series, QChart *parent) : | |||
|
10 | 10 | BarPresenterBase(series, parent) |
|
11 | 11 | { |
|
12 | 12 | connect(series, SIGNAL(updatedBars()), this, SLOT(layoutChanged())); |
|
13 | connect(series, SIGNAL(restructuredBar(int)), this, SLOT(handleModelChanged(int))); | |
|
13 | 14 | } |
|
14 | 15 | |
|
15 | 16 | void BarPresenter::layoutChanged() |
@@ -69,15 +69,26 void QBarSeries::removeBarSet(QBarSet *set) | |||
|
69 | 69 | mModel->removeBarSet(set); |
|
70 | 70 | } |
|
71 | 71 | |
|
72 | void QBarSeries::insertBarSet(int i, QBarSet *set) | |
|
73 | { | |
|
74 | mModel->insertBarSet(i, set); | |
|
75 | // emit barsetChanged(); | |
|
76 | } | |
|
77 | ||
|
78 | void QBarSeries::insertCategory(int i, QString category) | |
|
79 | { | |
|
80 | mModel->insertCategory(i, category); | |
|
81 | } | |
|
82 | ||
|
72 | 83 | /*! |
|
73 | 84 | Returns number of sets in series. |
|
74 | 85 | */ |
|
75 | 86 | int QBarSeries::barsetCount() |
|
76 | 87 | { |
|
77 | // if(m_model) | |
|
78 | // return m_mapBarTop - m_mapBarBottom; | |
|
79 | // else | |
|
80 |
|
|
|
88 | // if(m_model) | |
|
89 | // return m_mapBarTop - m_mapBarBottom; | |
|
90 | // else | |
|
91 | return mModel->barsetCount(); | |
|
81 | 92 | } |
|
82 | 93 | |
|
83 | 94 | /*! |
@@ -299,21 +310,37 void QBarSeries::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight) | |||
|
299 | 310 | { |
|
300 | 311 | if (topLeft.column() >= m_mapBarBottom && topLeft.column() <= m_mapBarTop) |
|
301 | 312 | barsetAt(topLeft.column() - m_mapBarBottom)->setValue(topLeft.row(), m_model->data(topLeft, Qt::DisplayRole).toDouble()); |
|
302 | // else if (topLeft.column() == m_mapCategories) | |
|
303 | // slices().at(topLeft.row())->setLabel(m_model->data(topLeft, Qt::DisplayRole).toString()); | |
|
313 | // else if (topLeft.column() == m_mapCategories) | |
|
314 | // slices().at(topLeft.row())->setLabel(m_model->data(topLeft, Qt::DisplayRole).toString()); | |
|
304 | 315 | } |
|
305 | 316 | else |
|
306 | 317 | { |
|
307 | 318 | if (topLeft.row() >= m_mapBarBottom && topLeft.row() <= m_mapBarTop) |
|
308 | 319 | barsetAt(topLeft.row() - m_mapBarBottom)->setValue(topLeft.column(), m_model->data(topLeft, Qt::DisplayRole).toDouble()); |
|
309 | // else if (topLeft.row() == m_mapCategories) | |
|
310 | // slices().at(topLeft.column())->setLabel(m_model->data(topLeft, Qt::DisplayRole).toString()); | |
|
320 | // else if (topLeft.row() == m_mapCategories) | |
|
321 | // slices().at(topLeft.column())->setLabel(m_model->data(topLeft, Qt::DisplayRole).toString()); | |
|
311 | 322 | } |
|
312 | 323 | } |
|
313 | 324 | |
|
314 |
void QBarSeries::modelDataAdded(QModelIndex /*parent*/, int |
|
|
325 | void QBarSeries::modelDataAdded(QModelIndex /*parent*/, int start, int /*end*/) | |
|
315 | 326 | { |
|
316 | // | |
|
327 | if (m_mapOrientation == Qt::Vertical) | |
|
328 | { | |
|
329 | insertCategory(start, QString("Row: %1").arg(start + 1)); | |
|
330 | for (int i = 0; i <= m_mapBarTop - m_mapBarBottom; i++) | |
|
331 | { | |
|
332 | barsetAt(i)->insertValue(start, m_model->data(m_model->index(start, i), Qt::DisplayRole).toDouble()); | |
|
333 | } | |
|
334 | } | |
|
335 | else | |
|
336 | { | |
|
337 | insertCategory(start, QString("Column: %1").arg(start + 1)); | |
|
338 | for (int i = 0; i <= m_mapBarTop - m_mapBarBottom; i++) | |
|
339 | { | |
|
340 | barsetAt(i)->insertValue(start, m_model->data(m_model->index(i, start), Qt::DisplayRole).toDouble()); | |
|
341 | } | |
|
342 | } | |
|
343 | emit restructuredBar(1); | |
|
317 | 344 | } |
|
318 | 345 | |
|
319 | 346 | void QBarSeries::modelDataRemoved(QModelIndex /*parent*/, int /*start*/, int /*end*/) |
@@ -21,6 +21,8 public: | |||
|
21 | 21 | |
|
22 | 22 | void addBarSet(QBarSet *set); // Takes ownership of set |
|
23 | 23 | void removeBarSet(QBarSet *set); // Releases ownership, doesn't delete set |
|
24 | void insertBarSet(int i, QBarSet *set); | |
|
25 | void insertCategory(int i, QString category); | |
|
24 | 26 | int barsetCount(); |
|
25 | 27 | int categoryCount(); |
|
26 | 28 | QList<QBarSet*> barSets(); |
@@ -51,6 +53,7 signals: | |||
|
51 | 53 | |
|
52 | 54 | // |
|
53 | 55 | void updatedBars(); |
|
56 | void restructuredBar(int); | |
|
54 | 57 | |
|
55 | 58 | // TODO: internal signals, these to private implementation. |
|
56 | 59 | // TODO: TO PIMPL ---> |
@@ -86,6 +86,11 QBarSet& QBarSet::operator << (const qreal &value) | |||
|
86 | 86 | return *this; |
|
87 | 87 | } |
|
88 | 88 | |
|
89 | void QBarSet::insertValue(int i, qreal value) | |
|
90 | { | |
|
91 | mValues.insert(i, value); | |
|
92 | } | |
|
93 | ||
|
89 | 94 | /*! |
|
90 | 95 | Returns count of values in set. |
|
91 | 96 | */ |
@@ -16,6 +16,7 public: | |||
|
16 | 16 | void setName(QString name); |
|
17 | 17 | QString name(); |
|
18 | 18 | QBarSet& operator << (const qreal &value); // appends new value to set |
|
19 | void insertValue(int i, qreal value); | |
|
19 | 20 | |
|
20 | 21 | // TODO: remove indices eventually. Use as internal? |
|
21 | 22 | int count(); // count of values in set |
General Comments 0
You need to be logged in to leave comments.
Login now