From 99b2f41bb95e2390ff645bea8375a4ee836038ef 2012-06-18 07:43:00 From: Marek Rosa Date: 2012-06-18 07:43:00 Subject: [PATCH] Added NOTIFY to PieModelMapper class properties --- diff --git a/src/piechart/qhpiemodelmapper.cpp b/src/piechart/qhpiemodelmapper.cpp index 387253d..bc50bea 100644 --- a/src/piechart/qhpiemodelmapper.cpp +++ b/src/piechart/qhpiemodelmapper.cpp @@ -70,7 +70,10 @@ int QHPieModelMapper::valuesRow() const */ void QHPieModelMapper::setValuesRow(int valuesRow) { - QPieModelMapper::setValuesSection(valuesRow); + if (valuesRow != valuesSection()) { + QPieModelMapper::setValuesSection(valuesRow); + emit valuesRowChanged(); + } } /*! @@ -87,7 +90,10 @@ int QHPieModelMapper::labelsRow() const */ void QHPieModelMapper::setLabelsRow(int labelsRow) { - QPieModelMapper::setLabelsSection(labelsRow); + if (labelsRow != labelsSection()) { + QPieModelMapper::setLabelsSection(labelsRow); + emit labelsRowChanged(); + } } #include "moc_qhpiemodelmapper.cpp" diff --git a/src/piechart/qhpiemodelmapper.h b/src/piechart/qhpiemodelmapper.h index 30463e7..1c04877 100644 --- a/src/piechart/qhpiemodelmapper.h +++ b/src/piechart/qhpiemodelmapper.h @@ -28,8 +28,8 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE class QTCOMMERCIALCHART_EXPORT QHPieModelMapper : public QPieModelMapper { Q_OBJECT - Q_PROPERTY(int valuesRow READ valuesRow WRITE setValuesRow) - Q_PROPERTY(int labelsRow READ labelsRow WRITE setLabelsRow) + Q_PROPERTY(int valuesRow READ valuesRow WRITE setValuesRow NOTIFY valuesRowChanged) + Q_PROPERTY(int labelsRow READ labelsRow WRITE setLabelsRow NOTIFY labelsRowChanged) public: explicit QHPieModelMapper(QObject *parent = 0); @@ -39,6 +39,10 @@ public: int labelsRow() const; void setLabelsRow(int labelsRow); + +Q_SIGNALS: + void valuesRowChanged(); + void labelsRowChanged(); }; QTCOMMERCIALCHART_END_NAMESPACE diff --git a/src/piechart/qpiemodelmapper.cpp b/src/piechart/qpiemodelmapper.cpp index 8fe1efc..f77fb3d 100644 --- a/src/piechart/qpiemodelmapper.cpp +++ b/src/piechart/qpiemodelmapper.cpp @@ -97,6 +97,8 @@ void QPieModelMapper::setModel(QAbstractItemModel *model) connect(d->m_model, SIGNAL(rowsRemoved(QModelIndex,int,int)), d, SLOT(modelRowsRemoved(QModelIndex,int,int))); connect(d->m_model, SIGNAL(columnsInserted(QModelIndex,int,int)), d, SLOT(modelColumnsAdded(QModelIndex,int,int))); connect(d->m_model, SIGNAL(columnsRemoved(QModelIndex,int,int)), d, SLOT(modelColumnsRemoved(QModelIndex,int,int))); + + emit modelReplaced(); } QPieSeries* QPieModelMapper::series() const @@ -120,6 +122,8 @@ void QPieModelMapper::setSeries(QPieSeries *series) // connect the signals from the series connect(d->m_series, SIGNAL(added(QList)), d, SLOT(slicesAdded(QList))); connect(d->m_series, SIGNAL(removed(QList)), d, SLOT(slicesRemoved(QList))); + + emit seriesReplaced(); } int QPieModelMapper::first() const @@ -131,8 +135,12 @@ int QPieModelMapper::first() const void QPieModelMapper::setFirst(int first) { Q_D(QPieModelMapper); - d->m_first = qMax(first, 0); - d->initializePieFromModel(); + if (first != d->m_first) { + d->m_first = qMax(first, 0); + d->initializePieFromModel(); + + emit firstChanged(); + } } int QPieModelMapper::count() const @@ -144,8 +152,12 @@ int QPieModelMapper::count() const void QPieModelMapper::setCount(int count) { Q_D(QPieModelMapper); - d->m_count = qMax(count, -1); - d->initializePieFromModel(); + if (count != d->m_count) { + d->m_count = qMax(count, -1); + d->initializePieFromModel(); + + emit countChanged(); + } } /*! @@ -500,7 +512,7 @@ void QPieModelMapperPrivate::insertData(int start, int end) if (valueIndex.isValid() && labelIndex.isValid()) { QPieSlice *slice = new QPieSlice; slice->setValue(m_model->data(valueIndex, Qt::DisplayRole).toDouble()); - slice->setLabel(m_model->data(labelIndex, Qt::DisplayRole).toString()); + slice->setLabel(m_model->data(labelIndex, Qt::DisplayRole).toString()); connect(slice, SIGNAL(labelChanged()), this, SLOT(sliceLabelChanged())); connect(slice, SIGNAL(valueChanged()), this, SLOT(sliceValueChanged())); m_series->insert(i - m_first, slice); @@ -583,7 +595,7 @@ void QPieModelMapperPrivate::initializePieFromModel() slicePos++; valueIndex = valueModelIndex(slicePos); labelIndex = labelModelIndex(slicePos); - } + } blockSeriesSignals(false); } diff --git a/src/piechart/qpiemodelmapper.h b/src/piechart/qpiemodelmapper.h index d4e93e3..20934a0 100644 --- a/src/piechart/qpiemodelmapper.h +++ b/src/piechart/qpiemodelmapper.h @@ -34,10 +34,10 @@ class QPieSeries; class QTCOMMERCIALCHART_EXPORT QPieModelMapper : public QObject { Q_OBJECT - Q_PROPERTY(QPieSeries *series READ series WRITE setSeries) - Q_PROPERTY(QAbstractItemModel *model READ model WRITE setModel) - Q_PROPERTY(int first READ first WRITE setFirst) - Q_PROPERTY(int count READ count WRITE setCount) + Q_PROPERTY(QPieSeries *series READ series WRITE setSeries NOTIFY seriesReplaced) + Q_PROPERTY(QAbstractItemModel *model READ model WRITE setModel NOTIFY modelReplaced) + Q_PROPERTY(int first READ first WRITE setFirst NOTIFY firstChanged) + Q_PROPERTY(int count READ count WRITE setCount NOTIFY countChanged) Q_ENUMS(Qt::Orientation) protected: @@ -68,6 +68,12 @@ protected: Qt::Orientation orientation() const; void setOrientation(Qt::Orientation orientation); +Q_SIGNALS: + void seriesReplaced(); + void modelReplaced(); + void firstChanged(); + void countChanged(); + protected: QPieModelMapperPrivate * const d_ptr; Q_DECLARE_PRIVATE(QPieModelMapper) diff --git a/src/piechart/qvpiemodelmapper.cpp b/src/piechart/qvpiemodelmapper.cpp index 27f1c8b..a1bfe2a 100644 --- a/src/piechart/qvpiemodelmapper.cpp +++ b/src/piechart/qvpiemodelmapper.cpp @@ -70,7 +70,10 @@ int QVPieModelMapper::valuesColumn() const */ void QVPieModelMapper::setValuesColumn(int valuesColumn) { - QPieModelMapper::setValuesSection(valuesColumn); + if (valuesColumn != valuesSection()) { + QPieModelMapper::setValuesSection(valuesColumn); + emit valuesColumnChanged(); + } } /*! @@ -87,7 +90,10 @@ int QVPieModelMapper::labelsColumn() const */ void QVPieModelMapper::setLabelsColumn(int labelsColumn) { - QPieModelMapper::setLabelsSection(labelsColumn); + if (labelsColumn != labelsSection()) { + QPieModelMapper::setLabelsSection(labelsColumn); + emit labelsColumnChanged(); + } } #include "moc_qvpiemodelmapper.cpp" diff --git a/src/piechart/qvpiemodelmapper.h b/src/piechart/qvpiemodelmapper.h index 9ec0a7b..4321094 100644 --- a/src/piechart/qvpiemodelmapper.h +++ b/src/piechart/qvpiemodelmapper.h @@ -28,8 +28,8 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE class QTCOMMERCIALCHART_EXPORT QVPieModelMapper : public QPieModelMapper { Q_OBJECT - Q_PROPERTY(int valuesColumn READ valuesColumn WRITE setValuesColumn) - Q_PROPERTY(int labelsColumn READ labelsColumn WRITE setLabelsColumn) + Q_PROPERTY(int valuesColumn READ valuesColumn WRITE setValuesColumn NOTIFY valuesColumnChanged) + Q_PROPERTY(int labelsColumn READ labelsColumn WRITE setLabelsColumn NOTIFY labelsColumnChanged) public: explicit QVPieModelMapper(QObject *parent = 0); @@ -39,6 +39,10 @@ public: int labelsColumn() const; void setLabelsColumn(int labelsColumn); + +Q_SIGNALS: + void valuesColumnChanged(); + void labelsColumnChanged(); }; QTCOMMERCIALCHART_END_NAMESPACE