From 7ed6749a4b0d694b98e73a1978e9697976b60926 2012-03-19 14:59:00 From: Marek Rosa Date: 2012-03-19 14:59:00 Subject: [PATCH] Barchart updates on BarSet->SetValue now --- diff --git a/examples/tablemodelchart/tablewidget.cpp b/examples/tablemodelchart/tablewidget.cpp index 4b12fb8..d95943f 100644 --- a/examples/tablemodelchart/tablewidget.cpp +++ b/examples/tablemodelchart/tablewidget.cpp @@ -194,7 +194,7 @@ void TableWidget::updateChartType() // pie 1 QPieSeries* pieSeries = new QPieSeries; pieSeries->setModel(m_model); - pieSeries->setModelMapping(0,0, Qt::Horizontal); + pieSeries->setModelMapping(0,0, Qt::Vertical); pieSeries->setLabelsVisible(true); pieSeries->setPieSize(0.4); pieSeries->setPiePosition(0.2, 0.35); @@ -203,7 +203,7 @@ void TableWidget::updateChartType() // pie 2 pieSeries = new QPieSeries; pieSeries->setModel(m_model); - pieSeries->setModelMapping(1,1, Qt::Horizontal); + pieSeries->setModelMapping(1,1, Qt::Vertical); pieSeries->setLabelsVisible(true); pieSeries->setPieSize(0.4); pieSeries->setPiePosition(0.8, 0.35); @@ -212,7 +212,7 @@ void TableWidget::updateChartType() // pie 3 pieSeries = new QPieSeries; pieSeries->setModel(m_model); - pieSeries->setModelMapping(2,2, Qt::Horizontal); + pieSeries->setModelMapping(2,2, Qt::Vertical); pieSeries->setLabelsVisible(true); pieSeries->setPieSize(0.4); pieSeries->setPiePosition(0.5, 0.65); diff --git a/src/barchart/barpresenter.cpp b/src/barchart/barpresenter.cpp index 83018bb..661a332 100644 --- a/src/barchart/barpresenter.cpp +++ b/src/barchart/barpresenter.cpp @@ -8,7 +8,8 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE BarPresenter::BarPresenter(QBarSeries *series, QChart *parent) : BarPresenterBase(series, parent) -{ +{ + connect(series, SIGNAL(updatedBars()), this, SLOT(layoutChanged())); } void BarPresenter::layoutChanged() @@ -78,6 +79,7 @@ void BarPresenter::layoutChanged() xPos += mBarWidth; } } + update(); } #include "moc_barpresenter_p.cpp" diff --git a/src/barchart/barpresenterbase_p.h b/src/barchart/barpresenterbase_p.h index 636916f..c21dc1e 100644 --- a/src/barchart/barpresenterbase_p.h +++ b/src/barchart/barpresenterbase_p.h @@ -30,6 +30,7 @@ public: // TODO: Consider the domain for layoutChanged. May be use case, may not be. If it is, then the derived classes need to implement it virtual void dataChanged(); // data of series has changed -> need to recalculate bar sizes +private slots: virtual void layoutChanged() = 0; // layout has changed -> need to recalculate bar sizes protected: diff --git a/src/barchart/qbarseries.cpp b/src/barchart/qbarseries.cpp index 94d054d..b6460f8 100644 --- a/src/barchart/qbarseries.cpp +++ b/src/barchart/qbarseries.cpp @@ -54,7 +54,7 @@ void QBarSeries::addBarSet(QBarSet *set) mModel->addBarSet(set); connect(set,SIGNAL(clicked(QString)),this,SLOT(barsetClicked(QString))); connect(set,SIGNAL(rightClicked(QString)),this,SLOT(barsetRightClicked(QString))); - connect(set, SIGNAL(changed()), this, SLOT(barsetChanged())); + connect(set, SIGNAL(valueChanged()), this, SLOT(barsetChanged())); } /*! @@ -323,7 +323,7 @@ void QBarSeries::modelDataRemoved(QModelIndex /*parent*/, int /*start*/, int /*e void QBarSeries::barsetChanged() { -// mModel-> + emit updatedBars(); } #include "moc_qbarseries.cpp" diff --git a/src/barchart/qbarseries.h b/src/barchart/qbarseries.h index 7d321cb..f4cdebd 100644 --- a/src/barchart/qbarseries.h +++ b/src/barchart/qbarseries.h @@ -49,6 +49,9 @@ signals: void clicked(QBarSet* barset, QString category); // Up to user of api, what to do with these signals void rightClicked(QBarSet* barset, QString category); + // + void updatedBars(); + // TODO: internal signals, these to private implementation. // TODO: TO PIMPL ---> void showToolTip(QPoint pos, QString tip); @@ -72,7 +75,7 @@ private Q_SLOTS: protected: BarChartModel* mModel; - QAbstractItemModel* m_model; +// QAbstractItemModel* m_model; int m_mapCategories; int m_mapBarBottom; int m_mapBarTop; diff --git a/src/barchart/qbarset.cpp b/src/barchart/qbarset.cpp index fa088c9..d98de32 100644 --- a/src/barchart/qbarset.cpp +++ b/src/barchart/qbarset.cpp @@ -82,6 +82,7 @@ QString QBarSet::name() QBarSet& QBarSet::operator << (const qreal &value) { mValues.append(value); + emit structureChanged(); return *this; } @@ -107,7 +108,7 @@ qreal QBarSet::valueAt(int index) void QBarSet::setValue(int index, qreal value) { mValues.replace(index,value); - emit changed(); + emit valueChanged(); } /*! @@ -128,7 +129,7 @@ qreal QBarSet::total() void QBarSet::setPen(const QPen pen) { mPen = pen; - emit changed(); + emit valueChanged(); } /*! @@ -145,7 +146,7 @@ QPen QBarSet::pen() const void QBarSet::setBrush(const QBrush brush) { mBrush = brush; - emit changed(); + emit valueChanged(); } /*! diff --git a/src/barchart/qbarset.h b/src/barchart/qbarset.h index 9ea805b..5c1ef93 100644 --- a/src/barchart/qbarset.h +++ b/src/barchart/qbarset.h @@ -43,7 +43,8 @@ Q_SIGNALS: // TODO: Expose this to user or not? // TODO: TO PIMPL ---> - void changed(); + void structureChanged(); + void valueChanged(); void hoverEnter(QPoint pos); void hoverLeave(); void showToolTip(QPoint pos, QString tip); // Private signal