From 436d384fa9437f5cfc3e7c0fbd94c18765fcd92a 2012-06-19 14:30:35 From: Marek Rosa Date: 2012-06-19 14:30:35 Subject: [PATCH] PieModelMapper properties first and count moved to Vertical and Horizontal mappers with more descriptive names --- diff --git a/demos/qmlcustommodel/qml/qmlcustommodel/main.qml b/demos/qmlcustommodel/qml/qmlcustommodel/main.qml index cbcb77f..31d3145 100644 --- a/demos/qmlcustommodel/qml/qmlcustommodel/main.qml +++ b/demos/qmlcustommodel/qml/qmlcustommodel/main.qml @@ -149,7 +149,7 @@ Rectangle { model: customModel labelsColumn: 1 valuesColumn: 2 - first: 1 + firstRow: 1 } } } diff --git a/src/piechart/qhpiemodelmapper.cpp b/src/piechart/qhpiemodelmapper.cpp index 8869424..94173cc 100644 --- a/src/piechart/qhpiemodelmapper.cpp +++ b/src/piechart/qhpiemodelmapper.cpp @@ -48,6 +48,28 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE */ /*! + \property QHPieModelMapper::firstColumn + \brief Defines which column of the model contains the first slice value. + Minimal and default value is: 0 +*/ +/*! + \qmlproperty int QHPieModelMapper::firstColumn + Defines which column of the model contains the first slice value. + The default value is 0. +*/ + +/*! + \property QHPieModelMapper::columnCount + \brief Defines the number of columns of the model that are mapped as the data for QPieSeries + Minimal and default value is: -1 (count limited by the number of columns in the model) +*/ +/*! + \qmlproperty int QHPieModelMapper::columnCount + Defines the number of columns of the model that are mapped as the data for QPieSeries. The default value is + -1 (count limited by the number of columns in the model) +*/ + +/*! \fn void QHPieModelMapper::valuesRowChanged() Emitted when the valuesRow has changed. @@ -60,12 +82,22 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE */ /*! + \fn void QHPieModelMapper::firstColumnChanged() + Emitted when the firstColumn has changed. +*/ + +/*! + \fn void QHPieModelMapper::columnCountChanged() + Emitted when the columnCount has changed. +*/ + +/*! Constructs a mapper object which is a child of \a parent. */ QHPieModelMapper::QHPieModelMapper(QObject *parent) : QPieModelMapper(parent) { - QPieModelMapper::setOrientation(Qt::Horizontal); + setOrientation(Qt::Horizontal); } /*! @@ -73,7 +105,7 @@ QHPieModelMapper::QHPieModelMapper(QObject *parent) : */ int QHPieModelMapper::valuesRow() const { - return QPieModelMapper::valuesSection(); + return valuesSection(); } /*! @@ -83,7 +115,7 @@ int QHPieModelMapper::valuesRow() const void QHPieModelMapper::setValuesRow(int valuesRow) { if (valuesRow != valuesSection()) { - QPieModelMapper::setValuesSection(valuesRow); + setValuesSection(valuesRow); emit valuesRowChanged(); } } @@ -93,7 +125,7 @@ void QHPieModelMapper::setValuesRow(int valuesRow) */ int QHPieModelMapper::labelsRow() const { - return QPieModelMapper::labelsSection(); + return labelsSection(); } /*! @@ -103,11 +135,37 @@ int QHPieModelMapper::labelsRow() const void QHPieModelMapper::setLabelsRow(int labelsRow) { if (labelsRow != labelsSection()) { - QPieModelMapper::setLabelsSection(labelsRow); + setLabelsSection(labelsRow); emit labelsRowChanged(); } } +int QHPieModelMapper::firstColumn() const +{ + return first(); +} + +void QHPieModelMapper::setFirstColumn(int firstColumn) +{ + if (firstColumn != first()) { + setFirst(firstColumn); + emit firstColumnChanged(); + } +} + +int QHPieModelMapper::columnCount() const +{ + return count(); +} + +void QHPieModelMapper::setColumnCount(int columnCount) +{ + if (columnCount != count()) { + setCount(columnCount); + emit firstColumnChanged(); + } +} + #include "moc_qhpiemodelmapper.cpp" QTCOMMERCIALCHART_END_NAMESPACE diff --git a/src/piechart/qhpiemodelmapper.h b/src/piechart/qhpiemodelmapper.h index 1c04877..ae5bff1 100644 --- a/src/piechart/qhpiemodelmapper.h +++ b/src/piechart/qhpiemodelmapper.h @@ -30,6 +30,8 @@ class QTCOMMERCIALCHART_EXPORT QHPieModelMapper : public QPieModelMapper Q_OBJECT Q_PROPERTY(int valuesRow READ valuesRow WRITE setValuesRow NOTIFY valuesRowChanged) Q_PROPERTY(int labelsRow READ labelsRow WRITE setLabelsRow NOTIFY labelsRowChanged) + Q_PROPERTY(int firstColumn READ firstColumn WRITE setFirstColumn NOTIFY firstColumnChanged) + Q_PROPERTY(int columnCount READ columnCount WRITE setColumnCount NOTIFY columnCountChanged) public: explicit QHPieModelMapper(QObject *parent = 0); @@ -40,9 +42,17 @@ public: int labelsRow() const; void setLabelsRow(int labelsRow); + int firstColumn() const; + void setFirstColumn(int firstColumn); + + int columnCount() const; + void setColumnCount(int columnCount); + Q_SIGNALS: void valuesRowChanged(); void labelsRowChanged(); + void firstColumnChanged(); + void columnCountChanged(); }; QTCOMMERCIALCHART_END_NAMESPACE diff --git a/src/piechart/qpiemodelmapper.cpp b/src/piechart/qpiemodelmapper.cpp index 6a67816..3647bb4 100644 --- a/src/piechart/qpiemodelmapper.cpp +++ b/src/piechart/qpiemodelmapper.cpp @@ -51,20 +51,6 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE */ /*! - \property QPieModelMapper::first - \brief Defines which item of the model's row/column should be mapped as the value/label of the first slice of the pie - - Minimal and default value is: 0 -*/ - -/*! - \property QPieModelMapper::count - \brief Defines the number of rows/columns of the model that are mapped as the data for the pie. - - Minimal and default value is: -1 (count limited by the number of rows/columns in the model) -*/ - -/*! \fn void QPieModelMapper::seriesReplaced() Emitted when the series to which mapper is connected to has changed. @@ -77,18 +63,6 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE */ /*! - \fn void QPieModelMapper::firstChanged() - - Emitted when the value for the first has changed. -*/ - -/*! - \fn void QPieModelMapper::countChanged() - - Emitted when the value for the count has changed. -*/ - -/*! Constructs a mapper object which is a child of \a parent. */ QPieModelMapper::QPieModelMapper(QObject *parent) : @@ -150,38 +124,46 @@ void QPieModelMapper::setSeries(QPieSeries *series) emit seriesReplaced(); } +/*! + Defines which row/column of the model contains the first slice value. + Minimal and default value is: 0 +*/ int QPieModelMapper::first() const { Q_D(const QPieModelMapper); return d->m_first; } +/*! + Sets which row/column of the model contains the \a first slice value. + Minimal and default value is: 0 +*/ void QPieModelMapper::setFirst(int first) { Q_D(QPieModelMapper); - if (first != d->m_first) { - d->m_first = qMax(first, 0); - d->initializePieFromModel(); - - emit firstChanged(); - } + d->m_first = qMax(first, 0); + d->initializePieFromModel(); } +/*! + Defines the number of rows/columns of the model that are mapped as the data for QPieSeries + Minimal and default value is: -1 (count limited by the number of rows/columns in the model) +*/ int QPieModelMapper::count() const { Q_D(const QPieModelMapper); return d->m_count; } +/*! + Defines the \a count of rows/columns of the model that are mapped as the data for QPieSeries + Minimal and default value is: -1 (count limited by the number of rows/columns in the model) +*/ void QPieModelMapper::setCount(int count) { Q_D(QPieModelMapper); - if (count != d->m_count) { - d->m_count = qMax(count, -1); - d->initializePieFromModel(); - - emit countChanged(); - } + d->m_count = qMax(count, -1); + d->initializePieFromModel(); } /*! diff --git a/src/piechart/qpiemodelmapper.h b/src/piechart/qpiemodelmapper.h index 20934a0..5599bda 100644 --- a/src/piechart/qpiemodelmapper.h +++ b/src/piechart/qpiemodelmapper.h @@ -36,8 +36,6 @@ class QTCOMMERCIALCHART_EXPORT QPieModelMapper : public QObject Q_OBJECT 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: @@ -50,15 +48,15 @@ public: QPieSeries* series() const; void setSeries(QPieSeries *series); + void reset(); + +protected: int first() const; void setFirst(int first); int count() const; void setCount(int count); - void reset(); - -protected: int valuesSection() const; void setValuesSection(int valuesSection); @@ -71,8 +69,6 @@ protected: Q_SIGNALS: void seriesReplaced(); void modelReplaced(); - void firstChanged(); - void countChanged(); protected: QPieModelMapperPrivate * const d_ptr; diff --git a/src/piechart/qvpiemodelmapper.cpp b/src/piechart/qvpiemodelmapper.cpp index 2f155d0..93731a4 100644 --- a/src/piechart/qvpiemodelmapper.cpp +++ b/src/piechart/qvpiemodelmapper.cpp @@ -48,6 +48,28 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE */ /*! + \property QVPieModelMapper::firstRow + \brief Defines which row of the model contains the first slice value. + Minimal and default value is: 0 +*/ +/*! + \qmlproperty int QVPieModelMapper::firstRow + Defines which row of the model contains the first slice value. + The default value is 0. +*/ + +/*! + \property QVPieModelMapper::rowCount + \brief Defines the number of rows of the model that are mapped as the data for QPieSeries + Minimal and default value is: -1 (count limited by the number of rows in the model) +*/ +/*! + \qmlproperty int QVPieModelMapper::columnCount + Defines the number of rows of the model that are mapped as the data for QPieSeries. The default value is + -1 (count limited by the number of rows in the model) +*/ + +/*! \fn void QVPieModelMapper::valuesColumnChanged() Emitted when the valuesColumn has changed. @@ -60,6 +82,16 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE */ /*! + \fn void QVPieModelMapper::firstRowChanged() + Emitted when the firstRow has changed. +*/ + +/*! + \fn void QVPieModelMapper::rowCountChanged() + Emitted when the rowCount has changed. +*/ + +/*! Constructs a mapper object which is a child of \a parent. */ QVPieModelMapper::QVPieModelMapper(QObject *parent) : @@ -108,6 +140,32 @@ void QVPieModelMapper::setLabelsColumn(int labelsColumn) } } +int QVPieModelMapper::firstRow() const +{ + return first(); +} + +void QVPieModelMapper::setFirstRow(int firstRow) +{ + if (firstRow != first()) { + setFirst(firstRow); + emit firstRowChanged(); + } +} + +int QVPieModelMapper::rowCount() const +{ + return count(); +} + +void QVPieModelMapper::setRowCount(int rowCount) +{ + if (rowCount != count()) { + setCount(rowCount); + emit firstRowChanged(); + } +} + #include "moc_qvpiemodelmapper.cpp" QTCOMMERCIALCHART_END_NAMESPACE diff --git a/src/piechart/qvpiemodelmapper.h b/src/piechart/qvpiemodelmapper.h index 4321094..b0afdf9 100644 --- a/src/piechart/qvpiemodelmapper.h +++ b/src/piechart/qvpiemodelmapper.h @@ -30,6 +30,8 @@ class QTCOMMERCIALCHART_EXPORT QVPieModelMapper : public QPieModelMapper Q_OBJECT Q_PROPERTY(int valuesColumn READ valuesColumn WRITE setValuesColumn NOTIFY valuesColumnChanged) Q_PROPERTY(int labelsColumn READ labelsColumn WRITE setLabelsColumn NOTIFY labelsColumnChanged) + Q_PROPERTY(int firstRow READ firstRow WRITE setFirstRow NOTIFY firstRowChanged) + Q_PROPERTY(int rowCount READ rowCount WRITE setRowCount NOTIFY rowCountChanged) public: explicit QVPieModelMapper(QObject *parent = 0); @@ -40,9 +42,17 @@ public: int labelsColumn() const; void setLabelsColumn(int labelsColumn); + int firstRow() const; + void setFirstRow(int firstRow); + + int rowCount() const; + void setRowCount(int rowCount); + Q_SIGNALS: void valuesColumnChanged(); void labelsColumnChanged(); + void firstRowChanged(); + void rowCountChanged(); }; QTCOMMERCIALCHART_END_NAMESPACE diff --git a/tests/auto/qpiemodelmapper/tst_qpiemodelmapper.cpp b/tests/auto/qpiemodelmapper/tst_qpiemodelmapper.cpp index 4b2ef1c..675425b 100644 --- a/tests/auto/qpiemodelmapper/tst_qpiemodelmapper.cpp +++ b/tests/auto/qpiemodelmapper/tst_qpiemodelmapper.cpp @@ -215,8 +215,8 @@ void tst_qpiemodelmapper::verticalMapperCustomMapping() mapper->setLabelsColumn(1); mapper->setModel(m_model); mapper->setSeries(m_series); - mapper->setFirst(first); - mapper->setCount(countLimit); + mapper->setFirstRow(first); + mapper->setRowCount(countLimit); QCOMPARE(m_series->count(), expectedCount); @@ -292,8 +292,8 @@ void tst_qpiemodelmapper::horizontalMapperCustomMapping() mapper->setLabelsRow(1); mapper->setModel(m_model); mapper->setSeries(m_series); - mapper->setFirst(first); - mapper->setCount(countLimit); + mapper->setFirstColumn(first); + mapper->setColumnCount(countLimit); QCOMPARE(m_series->count(), expectedCount); @@ -312,15 +312,15 @@ void tst_qpiemodelmapper::seriesUpdated() // setup the mapper createVerticalMapper(); QCOMPARE(m_series->count(), m_modelRowCount); - QCOMPARE(m_vMapper->count(), -1); + QCOMPARE(m_vMapper->rowCount(), -1); m_series->append("1000", 1000); QCOMPARE(m_series->count(), m_modelRowCount + 1); - QCOMPARE(m_vMapper->count(), -1); // the value should not change as it indicates 'all' items there are in the model + QCOMPARE(m_vMapper->rowCount(), -1); // the value should not change as it indicates 'all' items there are in the model m_series->remove(m_series->slices().last()); QCOMPARE(m_series->count(), m_modelRowCount); - QCOMPARE(m_vMapper->count(), -1); // the value should not change as it indicates 'all' items there are in the model + QCOMPARE(m_vMapper->rowCount(), -1); // the value should not change as it indicates 'all' items there are in the model QPieSlice *slice = m_series->slices().first(); slice->setValue(25.0); @@ -341,23 +341,23 @@ void tst_qpiemodelmapper::verticalModelInsertRows() QCOMPARE(m_series->count(), m_modelRowCount + insertCount); int first = 3; - m_vMapper->setFirst(3); + m_vMapper->setFirstRow(3); QCOMPARE(m_series->count(), m_modelRowCount + insertCount - first); m_model->insertRows(3, insertCount); QCOMPARE(m_series->count(), m_modelRowCount + 2 * insertCount - first); int countLimit = 6; - m_vMapper->setCount(countLimit); + m_vMapper->setRowCount(countLimit); QCOMPARE(m_series->count(), qMin(countLimit, m_modelRowCount + 2 * insertCount - first)); m_model->insertRows(3, insertCount); QCOMPARE(m_series->count(), qMin(countLimit, m_modelRowCount + 3 * insertCount - first)); - m_vMapper->setFirst(0); + m_vMapper->setFirstRow(0); QCOMPARE(m_series->count(), qMin(countLimit, m_modelRowCount + 3 * insertCount)); - m_vMapper->setCount(-1); + m_vMapper->setRowCount(-1); QCOMPARE(m_series->count(), m_modelRowCount + 3 * insertCount); } @@ -373,23 +373,23 @@ void tst_qpiemodelmapper::verticalModelRemoveRows() QCOMPARE(m_series->count(), m_modelRowCount - removeCount); int first = 1; - m_vMapper->setFirst(first); + m_vMapper->setFirstRow(first); QCOMPARE(m_series->count(), m_modelRowCount - removeCount - first); m_model->removeRows(1, removeCount); QCOMPARE(m_series->count(), m_modelRowCount - 2 * removeCount - first); int countLimit = 3; - m_vMapper->setCount(countLimit); + m_vMapper->setRowCount(countLimit); QCOMPARE(m_series->count(), qMin(countLimit, m_modelRowCount - 2 * removeCount - first)); m_model->removeRows(1, removeCount); QCOMPARE(m_series->count(), qMin(countLimit, m_modelRowCount - 3 * removeCount - first)); - m_vMapper->setFirst(0); + m_vMapper->setFirstRow(0); QCOMPARE(m_series->count(), qMin(countLimit, m_modelRowCount - 3 * removeCount)); - m_vMapper->setCount(-1); + m_vMapper->setRowCount(-1); QCOMPARE(m_series->count(), m_modelRowCount - 3 * removeCount); } @@ -461,23 +461,23 @@ void tst_qpiemodelmapper::horizontalModelInsertColumns() QCOMPARE(m_series->count(), m_modelColumnCount + insertCount); int first = 3; - m_hMapper->setFirst(3); + m_hMapper->setFirstColumn(3); QCOMPARE(m_series->count(), m_modelColumnCount + insertCount - first); m_model->insertColumns(3, insertCount); QCOMPARE(m_series->count(), m_modelColumnCount + 2 * insertCount - first); int countLimit = 6; - m_hMapper->setCount(countLimit); + m_hMapper->setColumnCount(countLimit); QCOMPARE(m_series->count(), qMin(countLimit, m_modelColumnCount + 2 * insertCount - first)); m_model->insertColumns(3, insertCount); QCOMPARE(m_series->count(), qMin(countLimit, m_modelColumnCount + 3 * insertCount - first)); - m_hMapper->setFirst(0); + m_hMapper->setFirstColumn(0); QCOMPARE(m_series->count(), qMin(countLimit, m_modelColumnCount + 3 * insertCount)); - m_hMapper->setCount(-1); + m_hMapper->setColumnCount(-1); QCOMPARE(m_series->count(), m_modelColumnCount + 3 * insertCount); } @@ -493,23 +493,23 @@ void tst_qpiemodelmapper::horizontalModelRemoveColumns() QCOMPARE(m_series->count(), m_modelColumnCount - removeCount); int first = 1; - m_hMapper->setFirst(first); + m_hMapper->setFirstColumn(first); QCOMPARE(m_series->count(), m_modelColumnCount - removeCount - first); m_model->removeColumns(1, removeCount); QCOMPARE(m_series->count(), m_modelColumnCount - 2 * removeCount - first); int countLimit = 3; - m_hMapper->setCount(countLimit); + m_hMapper->setColumnCount(countLimit); QCOMPARE(m_series->count(), qMin(countLimit, m_modelColumnCount - 2 * removeCount - first)); m_model->removeColumns(1, removeCount); QCOMPARE(m_series->count(), qMin(countLimit, m_modelColumnCount - 3 * removeCount - first)); - m_hMapper->setFirst(0); + m_hMapper->setFirstColumn(0); QCOMPARE(m_series->count(), qMin(countLimit, m_modelColumnCount - 3 * removeCount)); - m_hMapper->setCount(-1); + m_hMapper->setColumnCount(-1); QCOMPARE(m_series->count(), m_modelColumnCount - 3 * removeCount); }