From 4e92004ccd6b739b7428184937df95330fcf34ff 2012-05-28 06:59:36 From: Marek Rosa Date: 2012-05-28 06:59:36 Subject: [PATCH] Added Vertical and Horizontal QXYModelMapper --- diff --git a/plugins/declarative/declarativemodel.cpp b/plugins/declarative/declarativemodel.cpp index 0c672b3..8b03543 100644 --- a/plugins/declarative/declarativemodel.cpp +++ b/plugins/declarative/declarativemodel.cpp @@ -101,8 +101,9 @@ void DeclarativeTableModel::appendPoint(QXYModelMapper *mapper, DeclarativeXyPoi { // qDebug() << "DeclarativeTableModel::appendPoint:" << point; QVariantList values; - values.insert(mapper->mapX(), point->x()); - values.insert(mapper->mapY(), point->y()); + // TODO: XYModelMapper implementation has change, this code has to be updated. +// values.insert(mapper->mapX(), point->x()); +// values.insert(mapper->mapY(), point->y()); append(values); } diff --git a/plugins/declarative/declarativexyseries.cpp b/plugins/declarative/declarativexyseries.cpp index 47b1e22..1ade5b2 100644 --- a/plugins/declarative/declarativexyseries.cpp +++ b/plugins/declarative/declarativexyseries.cpp @@ -29,15 +29,17 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE DeclarativeXySeries::DeclarativeXySeries() { + // TODO: XYModelMapper implementation has changed, this code has to be updated + // All the inherited objects must be of type QXYSeries, so it is safe to cast - QXYSeries *series = reinterpret_cast(this); - // TODO: mapper should be available on the series by default - QXYModelMapper *mapper = new QXYModelMapper(series); - mapper->setMapX(0); - mapper->setMapY(1); - mapper->setFirst(0); - mapper->setCount(-1); - mapper->setOrientation(Qt::Vertical); +// QXYSeries *series = reinterpret_cast(this); +// // TODO: mapper should be available on the series by default +// QXYModelMapper *mapper = new QXYModelMapper(series); +// mapper->setMapX(0); +// mapper->setMapY(1); +// mapper->setFirst(0); +// mapper->setCount(-1); +// mapper->setOrientation(Qt::Vertical); // series->setModelMapper(mapper); } diff --git a/src/piechart/qpiemodelmapper.cpp b/src/piechart/qpiemodelmapper.cpp index 6ec9eda..2de1a54 100644 --- a/src/piechart/qpiemodelmapper.cpp +++ b/src/piechart/qpiemodelmapper.cpp @@ -46,20 +46,19 @@ QPieSeries* QPieModelMapper::series() const void QPieModelMapper::setSeries(QPieSeries *series) { - if (series == 0) - return; - Q_D(QPieModelMapper); if (d->m_series) { disconnect(d->m_series, 0, d, 0); } + if (series == 0) + return; + d->m_series = series; d->initializePieFromModel(); // 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))); - // connect(d->m_model, SIGNAL(), d, SLOT()); } int QPieModelMapper::first() const diff --git a/src/xychart/qhxymodelmapper.cpp b/src/xychart/qhxymodelmapper.cpp new file mode 100644 index 0000000..5634dbb --- /dev/null +++ b/src/xychart/qhxymodelmapper.cpp @@ -0,0 +1,32 @@ +#include "qhxymodelmapper.h" + +QTCOMMERCIALCHART_BEGIN_NAMESPACE + +QHXYModelMapper::QHXYModelMapper(QObject *parent) : + QXYModelMapper(parent) +{ +} + +int QHXYModelMapper::xRow() const +{ + return QXYModelMapper::xSection(); +} + +void QHXYModelMapper::setXRow(int xRow) +{ + return QXYModelMapper::setXSection(xRow); +} + +int QHXYModelMapper::yRow() const +{ + return QXYModelMapper::ySection(); +} + +void QHXYModelMapper::setYRow(int yRow) +{ + return QXYModelMapper::setYSection(yRow); +} + +#include "moc_qhxymodelmapper.cpp" + +QTCOMMERCIALCHART_END_NAMESPACE diff --git a/src/xychart/qhxymodelmapper.h b/src/xychart/qhxymodelmapper.h new file mode 100644 index 0000000..f946377 --- /dev/null +++ b/src/xychart/qhxymodelmapper.h @@ -0,0 +1,27 @@ +#ifndef QHXYMODELMAPPER_H +#define QHXYMODELMAPPER_H + +#include + +QTCOMMERCIALCHART_BEGIN_NAMESPACE + +class QTCOMMERCIALCHART_EXPORT QHXYModelMapper : public QXYModelMapper +{ + Q_OBJECT + Q_PROPERTY(int xRow READ xRow WRITE setXRow) + Q_PROPERTY(int yRow READ yRow WRITE setYRow) + +public: + explicit QHXYModelMapper(QObject *parent = 0); + + int xRow() const; + void setXRow(int xRow); + + int yRow() const; + void setYRow(int yRow); + +}; + +QTCOMMERCIALCHART_END_NAMESPACE + +#endif // QHXYMODELMAPPER_H diff --git a/src/xychart/qvxymodelmapper.cpp b/src/xychart/qvxymodelmapper.cpp new file mode 100644 index 0000000..a740093 --- /dev/null +++ b/src/xychart/qvxymodelmapper.cpp @@ -0,0 +1,32 @@ +#include "qvxymodelmapper.h" + +QTCOMMERCIALCHART_BEGIN_NAMESPACE + +QVXYModelMapper::QVXYModelMapper(QObject *parent) : + QXYModelMapper(parent) +{ +} + +int QVXYModelMapper::xColumn() const +{ + return QXYModelMapper::xSection(); +} + +void QVXYModelMapper::setXColumn(int xColumn) +{ + return QXYModelMapper::setXSection(xColumn); +} + +int QVXYModelMapper::yColumn() const +{ + return QXYModelMapper::ySection(); +} + +void QVXYModelMapper::setYColumn(int yColumn) +{ + return QXYModelMapper::setYSection(yColumn); +} + +#include "moc_qvxymodelmapper.cpp" + +QTCOMMERCIALCHART_END_NAMESPACE diff --git a/src/xychart/qvxymodelmapper.h b/src/xychart/qvxymodelmapper.h new file mode 100644 index 0000000..02f383f --- /dev/null +++ b/src/xychart/qvxymodelmapper.h @@ -0,0 +1,27 @@ +#ifndef QVXYMODELMAPPER_H +#define QVXYMODELMAPPER_H + +#include + +QTCOMMERCIALCHART_BEGIN_NAMESPACE + +class QTCOMMERCIALCHART_EXPORT QVXYModelMapper : public QXYModelMapper +{ + Q_OBJECT + Q_PROPERTY(int xColumn READ xColumn WRITE setXColumn) + Q_PROPERTY(int yColumn READ yColumn WRITE setYColumn) + +public: + explicit QVXYModelMapper(QObject *parent = 0); + + int xColumn() const; + void setXColumn(int xColumn); + + int yColumn() const; + void setYColumn(int yColumn); + +}; + +QTCOMMERCIALCHART_END_NAMESPACE + +#endif // QVXYMODELMAPPER_H diff --git a/src/xychart/qxymodelmapper.cpp b/src/xychart/qxymodelmapper.cpp index 5374eac..d66793c 100644 --- a/src/xychart/qxymodelmapper.cpp +++ b/src/xychart/qxymodelmapper.cpp @@ -7,8 +7,8 @@ QXYModelMapper::QXYModelMapper(QObject *parent): m_first(0), m_count(-1), m_orientation(Qt::Vertical), - m_mapX(-1), - m_mapY(-1) + m_xSection(-1), + m_ySection(-1) { } @@ -20,7 +20,7 @@ int QXYModelMapper::first() const void QXYModelMapper::setFirst(int first) { m_first = qMax(first, 0); - emit updated(); +// emit updated(); } int QXYModelMapper::count() const @@ -31,7 +31,7 @@ int QXYModelMapper::count() const void QXYModelMapper::setCount(int count) { m_count = qMax(count, -1); - emit updated(); +// emit updated(); } Qt::Orientation QXYModelMapper::orientation() const @@ -42,29 +42,29 @@ Qt::Orientation QXYModelMapper::orientation() const void QXYModelMapper::setOrientation(Qt::Orientation orientation) { m_orientation = orientation; - emit updated(); +// emit updated(); } -int QXYModelMapper::mapX() const +int QXYModelMapper::xSection() const { - return m_mapX; + return m_xSection; } -void QXYModelMapper::setMapX(int mapX) +void QXYModelMapper::setXSection(int xSection) { - m_mapX = mapX; - emit updated(); + m_xSection = xSection; +// emit updated(); } -int QXYModelMapper::mapY() const +int QXYModelMapper::ySection() const { - return m_mapY; + return m_ySection; } -void QXYModelMapper::setMapY(int mapY) +void QXYModelMapper::setYSection(int ySection) { - m_mapY = mapY; - emit updated(); + m_ySection = ySection; +// emit updated(); } void QXYModelMapper::reset() @@ -72,8 +72,8 @@ void QXYModelMapper::reset() m_first = 0; m_count = -1; m_orientation = Qt::Vertical; - m_mapX = -1; - m_mapY = -1; + m_xSection = -1; + m_ySection = -1; } #include "moc_qxymodelmapper.cpp" diff --git a/src/xychart/qxymodelmapper.h b/src/xychart/qxymodelmapper.h index db35de7..3d58044 100644 --- a/src/xychart/qxymodelmapper.h +++ b/src/xychart/qxymodelmapper.h @@ -9,30 +9,31 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE class QTCOMMERCIALCHART_EXPORT QXYModelMapper : public QObject { Q_OBJECT - Q_PROPERTY(int mapX READ mapX WRITE setMapX) - Q_PROPERTY(int mapY READ mapY WRITE setMapY) + Q_PROPERTY(int xSection READ xSection WRITE setXSection) + Q_PROPERTY(int ySection READ ySection WRITE setYSection) Q_PROPERTY(int first READ first WRITE setFirst) Q_PROPERTY(int count READ count WRITE setCount) Q_PROPERTY(Qt::Orientation orientation READ orientation WRITE setOrientation) Q_ENUMS(Qt::Orientation) public: - explicit QXYModelMapper(QObject *parent = 0); - int first() const; void setFirst(int first); int count() const; void setCount(int count); +protected: + explicit QXYModelMapper(QObject *parent = 0); + Qt::Orientation orientation() const; void setOrientation(Qt::Orientation orientation); - int mapX() const; - void setMapX(int mapX); + int xSection() const; + void setXSection(int xSection); - int mapY() const; - void setMapY(int mapY); + int ySection() const; + void setYSection(int ySection); void reset(); @@ -43,8 +44,8 @@ private: int m_first; int m_count; Qt::Orientation m_orientation; - int m_mapX; - int m_mapY; + int m_xSection; + int m_ySection; }; QTCOMMERCIALCHART_END_NAMESPACE diff --git a/src/xychart/xychart.pri b/src/xychart/xychart.pri index 8913527..16cf7d8 100644 --- a/src/xychart/xychart.pri +++ b/src/xychart/xychart.pri @@ -4,7 +4,9 @@ DEPENDPATH += $$PWD SOURCES += \ $$PWD/xychart.cpp \ $$PWD/qxyseries.cpp \ - $$PWD/qxymodelmapper.cpp + $$PWD/qxymodelmapper.cpp \ + $$PWD/qvxymodelmapper.cpp \ + $$PWD/qhxymodelmapper.cpp PRIVATE_HEADERS += \ $$PWD/xychart_p.h \ @@ -13,4 +15,7 @@ PRIVATE_HEADERS += \ PUBLIC_HEADERS += \ $$PWD/qxyseries.h \ - $$PWD/qxymodelmapper.h + $$PWD/qxymodelmapper.h \ + $$PWD/qvxymodelmapper.h \ + $$PWD/qhxymodelmapper.h + diff --git a/tests/auto/qpiemodelmapper/tst_qpiemodelmapper.cpp b/tests/auto/qpiemodelmapper/tst_qpiemodelmapper.cpp index bb49b03..57ed461 100644 --- a/tests/auto/qpiemodelmapper/tst_qpiemodelmapper.cpp +++ b/tests/auto/qpiemodelmapper/tst_qpiemodelmapper.cpp @@ -253,12 +253,15 @@ void tst_piemodelmapper::seriesUpdated() mapper->setModel(otherModel); mapper->setSeries(m_series); QCOMPARE(m_series->count(), m_modelRowCount); + QCOMPARE(mapper->count(), -1); m_series->append("1000", 1000); QCOMPARE(m_series->count(), m_modelRowCount + 1); + QCOMPARE(mapper->count(), -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(mapper->count(), -1); // the value should not change as it indicates 'all' items there are in the model otherModel->clear(); delete otherModel;