From 64e92d4f29591343736aaecab6f629db2af1e2c0 2012-05-24 14:35:40 From: Marek Rosa Date: 2012-05-24 14:35:40 Subject: [PATCH] Added Vertical and Horizontal PieModelMapper --- diff --git a/src/piechart/piechart.pri b/src/piechart/piechart.pri index 0c39862..ae163e4 100644 --- a/src/piechart/piechart.pri +++ b/src/piechart/piechart.pri @@ -6,7 +6,9 @@ SOURCES += \ $$PWD/piesliceitem.cpp \ $$PWD/piechartitem.cpp \ $$PWD/qpieslice.cpp \ - $$PWD/qpiemodelmapper.cpp + $$PWD/qpiemodelmapper.cpp \ + $$PWD/qvpiemodelmapper.cpp \ + $$PWD/qhpiemodelmapper.cpp PRIVATE_HEADERS += \ $$PWD/pieslicedata_p.h \ @@ -18,4 +20,6 @@ PRIVATE_HEADERS += \ PUBLIC_HEADERS += \ $$PWD/qpieseries.h \ $$PWD/qpieslice.h \ - $$PWD/qpiemodelmapper.h + $$PWD/qpiemodelmapper.h \ + $$PWD/qvpiemodelmapper.h \ + $$PWD/qhpiemodelmapper.h diff --git a/src/piechart/qhpiemodelmapper.cpp b/src/piechart/qhpiemodelmapper.cpp new file mode 100644 index 0000000..2b45edf --- /dev/null +++ b/src/piechart/qhpiemodelmapper.cpp @@ -0,0 +1,33 @@ +#include "qhpiemodelmapper.h" + +QTCOMMERCIALCHART_BEGIN_NAMESPACE + +QHPieModelMapper::QHPieModelMapper(QObject *parent) : + QPieModelMapper(parent) +{ + QPieModelMapper::setOrientation(Qt::Horizontal); +} + +int QHPieModelMapper::valuesRow() const +{ + return QPieModelMapper::valuesIndex(); +} + +void QHPieModelMapper::setValuesRow(int valuesRow) +{ + QPieModelMapper::setValuesIndex(valuesRow); +} + +int QHPieModelMapper::labelsRow() const +{ + return QPieModelMapper::labelsIndex(); +} + +void QHPieModelMapper::setLabelsRow(int labelsRow) +{ + QPieModelMapper::setLabelsIndex(labelsRow); +} + +#include "moc_qhpiemodelmapper.cpp" + +QTCOMMERCIALCHART_END_NAMESPACE diff --git a/src/piechart/qhpiemodelmapper.h b/src/piechart/qhpiemodelmapper.h new file mode 100644 index 0000000..195f713 --- /dev/null +++ b/src/piechart/qhpiemodelmapper.h @@ -0,0 +1,27 @@ +#ifndef QHPIEMODELMAPPER_H +#define QHPIEMODELMAPPER_H + +#include "qpiemodelmapper.h" + +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) + +public: + QHPieModelMapper(QObject *parent = 0); + + int valuesRow() const; + void setValuesRow(int valuesRow); + + int labelsRow() const; + void setLabelsRow(int labelsRow); + +}; + +QTCOMMERCIALCHART_END_NAMESPACE + +#endif // QHPIEMODELMAPPER_H diff --git a/src/piechart/qpiemodelmapper.h b/src/piechart/qpiemodelmapper.h index 38ec0a2..5545c9a 100644 --- a/src/piechart/qpiemodelmapper.h +++ b/src/piechart/qpiemodelmapper.h @@ -1,3 +1,23 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc +** All rights reserved. +** For any questions to Digia, please use contact form at http://qt.digia.com +** +** This file is part of the Qt Commercial Charts Add-on. +** +** $QT_BEGIN_LICENSE$ +** Licensees holding valid Qt Commercial licenses may use this file in +** accordance with the Qt Commercial License Agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. +** +** If you have questions regarding the use of this file, please use +** contact form at http://qt.digia.com +** $QT_END_LICENSE$ +** +****************************************************************************/ + #ifndef QPIEMODELMAPPER_H #define QPIEMODELMAPPER_H @@ -14,16 +34,14 @@ class QPieSeries; class QTCOMMERCIALCHART_EXPORT QPieModelMapper : public QObject { Q_OBJECT - Q_PROPERTY(int valuesIndex READ valuesIndex WRITE setValuesIndex) - Q_PROPERTY(int labelsIndex READ labelsIndex WRITE setLabelsIndex) 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: +protected: QPieModelMapper(QObject *parent = 0); +public: QAbstractItemModel* model() const; void setModel(QAbstractItemModel *model); @@ -36,16 +54,17 @@ public: int count() const; void setCount(int count); - Qt::Orientation orientation() const; - void setOrientation(Qt::Orientation orientation); + void reset(); +protected: int valuesIndex() const; void setValuesIndex(int valuesIndex); int labelsIndex() const; void setLabelsIndex(int labelsIndex); - void reset(); + Qt::Orientation orientation() const; + void setOrientation(Qt::Orientation orientation); protected: QPieModelMapperPrivate * const d_ptr; diff --git a/src/piechart/qvpiemodelmapper.cpp b/src/piechart/qvpiemodelmapper.cpp new file mode 100644 index 0000000..e075b0b --- /dev/null +++ b/src/piechart/qvpiemodelmapper.cpp @@ -0,0 +1,34 @@ +#include "qpiemodelmapper_p.h" +#include "qvpiemodelmapper.h" + +QTCOMMERCIALCHART_BEGIN_NAMESPACE + +QVPieModelMapper::QVPieModelMapper(QObject *parent) : + QPieModelMapper(parent) +{ + QPieModelMapper::setOrientation(Qt::Vertical); +} + +int QVPieModelMapper::valuesColumn() const +{ + return QPieModelMapper::valuesIndex(); +} + +void QVPieModelMapper::setValuesColumn(int valuesColumn) +{ + QPieModelMapper::setValuesIndex(valuesColumn); +} + +int QVPieModelMapper::labelsColumn() const +{ + return QPieModelMapper::labelsIndex(); +} + +void QVPieModelMapper::setLabelsColumn(int labelsColumn) +{ + QPieModelMapper::setLabelsIndex(labelsColumn); +} + +#include "moc_qvpiemodelmapper.cpp" + +QTCOMMERCIALCHART_END_NAMESPACE diff --git a/src/piechart/qvpiemodelmapper.h b/src/piechart/qvpiemodelmapper.h new file mode 100644 index 0000000..0ff1911 --- /dev/null +++ b/src/piechart/qvpiemodelmapper.h @@ -0,0 +1,26 @@ +#ifndef QVPIEMODELMAPPER_H +#define QVPIEMODELMAPPER_H + +#include "qpiemodelmapper.h" + +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) + +public: + explicit QVPieModelMapper(QObject *parent = 0); + + int valuesColumn() const; + void setValuesColumn(int valuesColumn); + + int labelsColumn() const; + void setLabelsColumn(int labelsColumn); +}; + +QTCOMMERCIALCHART_END_NAMESPACE + +#endif // QVPIEMODELMAPPER_H diff --git a/tests/tablemodelchart/tablewidget.cpp b/tests/tablemodelchart/tablewidget.cpp index e2319ea..3fa3420 100644 --- a/tests/tablemodelchart/tablewidget.cpp +++ b/tests/tablemodelchart/tablewidget.cpp @@ -29,7 +29,7 @@ #include #include "customtablemodel.h" #include -#include +#include #include #include #include @@ -349,9 +349,9 @@ void TableWidget::updateChartType(bool toggle) // pie 1 m_pieSeries = new QPieSeries; - m_pieMapper = new QPieModelMapper; - m_pieMapper->setValuesIndex(1); - m_pieMapper->setLabelsIndex(7); + m_pieMapper = new QVPieModelMapper; + m_pieMapper->setValuesColumn(1); + m_pieMapper->setLabelsColumn(7); m_pieMapper->setSeries(m_pieSeries); m_pieMapper->setModel(m_model); m_pieMapper->setFirst(2); diff --git a/tests/tablemodelchart/tablewidget.h b/tests/tablemodelchart/tablewidget.h index 537fa9b..73b96a4 100644 --- a/tests/tablemodelchart/tablewidget.h +++ b/tests/tablemodelchart/tablewidget.h @@ -26,7 +26,7 @@ #include "qchartview.h" //#include "qxyseries.h" #include -#include +#include class CustomTableModel; class QTableView; @@ -68,7 +68,7 @@ public: QRadioButton* m_areaRadioButton; QRadioButton* m_barRadioButton; QSpinBox* m_linesCountSpinBox; - QPieModelMapper *m_pieMapper; + QVPieModelMapper *m_pieMapper; QPieSeries* m_pieSeries; // QPieSeries* specialPie; };