##// END OF EJS Templates
Adding data to BarSet through model added
Marek Rosa -
r662:c9f8f8ef7809
parent child
Show More
@@ -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 QBarSet* BarChartModel::setAt(int index)
42 QBarSet* BarChartModel::setAt(int index)
33 {
43 {
34 return mDataModel.at(index);
44 return mDataModel.at(index);
@@ -22,6 +22,8 public:
22 QStringList category();
22 QStringList category();
23 void addBarSet(QBarSet *set);
23 void addBarSet(QBarSet *set);
24 void removeBarSet(QBarSet *set);
24 void removeBarSet(QBarSet *set);
25 void insertBarSet(int i, QBarSet *set);
26 void insertCategory(int i, QString category);
25 QBarSet *setAt(int index);
27 QBarSet *setAt(int index);
26 QList<QBarSet*> barSets();
28 QList<QBarSet*> barSets();
27
29
@@ -10,6 +10,7 BarPresenter::BarPresenter(QBarSeries *series, QChart *parent) :
10 BarPresenterBase(series, parent)
10 BarPresenterBase(series, parent)
11 {
11 {
12 connect(series, SIGNAL(updatedBars()), this, SLOT(layoutChanged()));
12 connect(series, SIGNAL(updatedBars()), this, SLOT(layoutChanged()));
13 connect(series, SIGNAL(restructuredBar(int)), this, SLOT(handleModelChanged(int)));
13 }
14 }
14
15
15 void BarPresenter::layoutChanged()
16 void BarPresenter::layoutChanged()
@@ -69,15 +69,26 void QBarSeries::removeBarSet(QBarSet *set)
69 mModel->removeBarSet(set);
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 Returns number of sets in series.
84 Returns number of sets in series.
74 */
85 */
75 int QBarSeries::barsetCount()
86 int QBarSeries::barsetCount()
76 {
87 {
77 // if(m_model)
88 // if(m_model)
78 // return m_mapBarTop - m_mapBarBottom;
89 // return m_mapBarTop - m_mapBarBottom;
79 // else
90 // else
80 return mModel->barsetCount();
91 return mModel->barsetCount();
81 }
92 }
82
93
83 /*!
94 /*!
@@ -299,21 +310,37 void QBarSeries::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight)
299 {
310 {
300 if (topLeft.column() >= m_mapBarBottom && topLeft.column() <= m_mapBarTop)
311 if (topLeft.column() >= m_mapBarBottom && topLeft.column() <= m_mapBarTop)
301 barsetAt(topLeft.column() - m_mapBarBottom)->setValue(topLeft.row(), m_model->data(topLeft, Qt::DisplayRole).toDouble());
312 barsetAt(topLeft.column() - m_mapBarBottom)->setValue(topLeft.row(), m_model->data(topLeft, Qt::DisplayRole).toDouble());
302 // else if (topLeft.column() == m_mapCategories)
313 // else if (topLeft.column() == m_mapCategories)
303 // slices().at(topLeft.row())->setLabel(m_model->data(topLeft, Qt::DisplayRole).toString());
314 // slices().at(topLeft.row())->setLabel(m_model->data(topLeft, Qt::DisplayRole).toString());
304 }
315 }
305 else
316 else
306 {
317 {
307 if (topLeft.row() >= m_mapBarBottom && topLeft.row() <= m_mapBarTop)
318 if (topLeft.row() >= m_mapBarBottom && topLeft.row() <= m_mapBarTop)
308 barsetAt(topLeft.row() - m_mapBarBottom)->setValue(topLeft.column(), m_model->data(topLeft, Qt::DisplayRole).toDouble());
319 barsetAt(topLeft.row() - m_mapBarBottom)->setValue(topLeft.column(), m_model->data(topLeft, Qt::DisplayRole).toDouble());
309 // else if (topLeft.row() == m_mapCategories)
320 // else if (topLeft.row() == m_mapCategories)
310 // slices().at(topLeft.column())->setLabel(m_model->data(topLeft, Qt::DisplayRole).toString());
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 /*start*/, int /*end*/)
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 void QBarSeries::modelDataRemoved(QModelIndex /*parent*/, int /*start*/, int /*end*/)
346 void QBarSeries::modelDataRemoved(QModelIndex /*parent*/, int /*start*/, int /*end*/)
@@ -21,6 +21,8 public:
21
21
22 void addBarSet(QBarSet *set); // Takes ownership of set
22 void addBarSet(QBarSet *set); // Takes ownership of set
23 void removeBarSet(QBarSet *set); // Releases ownership, doesn't delete set
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 int barsetCount();
26 int barsetCount();
25 int categoryCount();
27 int categoryCount();
26 QList<QBarSet*> barSets();
28 QList<QBarSet*> barSets();
@@ -51,6 +53,7 signals:
51
53
52 //
54 //
53 void updatedBars();
55 void updatedBars();
56 void restructuredBar(int);
54
57
55 // TODO: internal signals, these to private implementation.
58 // TODO: internal signals, these to private implementation.
56 // TODO: TO PIMPL --->
59 // TODO: TO PIMPL --->
@@ -86,6 +86,11 QBarSet& QBarSet::operator << (const qreal &value)
86 return *this;
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 Returns count of values in set.
95 Returns count of values in set.
91 */
96 */
@@ -16,6 +16,7 public:
16 void setName(QString name);
16 void setName(QString name);
17 QString name();
17 QString name();
18 QBarSet& operator << (const qreal &value); // appends new value to set
18 QBarSet& operator << (const qreal &value); // appends new value to set
19 void insertValue(int i, qreal value);
19
20
20 // TODO: remove indices eventually. Use as internal?
21 // TODO: remove indices eventually. Use as internal?
21 int count(); // count of values in set
22 int count(); // count of values in set
General Comments 0
You need to be logged in to leave comments. Login now