@@ -1,109 +1,109 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "tablewidget.h" |
|
21 | #include "tablewidget.h" | |
22 | #include "customtablemodel.h" |
|
22 | #include "customtablemodel.h" | |
23 | #include <QGridLayout> |
|
23 | #include <QGridLayout> | |
24 | #include <QTableView> |
|
24 | #include <QTableView> | |
25 | #include <QChart> |
|
25 | #include <QChart> | |
26 | #include <QChartView> |
|
26 | #include <QChartView> | |
27 | #include <QLineSeries> |
|
27 | #include <QLineSeries> | |
28 | #include <QVXYModelMapper> |
|
28 | #include <QVXYModelMapper> | |
29 | #include <QGroupedBarSeries> |
|
29 | #include <QGroupedBarSeries> | |
30 | #include <QBarSet> |
|
30 | #include <QBarSet> | |
31 | #include <QVBarModelMapper> |
|
31 | #include <QVBarModelMapper> | |
32 | #include <QHeaderView> |
|
32 | #include <QHeaderView> | |
33 |
|
33 | |||
34 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
34 | QTCOMMERCIALCHART_USE_NAMESPACE | |
35 |
|
35 | |||
36 | TableWidget::TableWidget(QWidget *parent) |
|
36 | TableWidget::TableWidget(QWidget *parent) | |
37 | : QWidget(parent) |
|
37 | : QWidget(parent) | |
38 | { |
|
38 | { | |
39 | // create simple model for storing data |
|
39 | // create simple model for storing data | |
40 | // user's table data model |
|
40 | // user's table data model | |
41 | //! [1] |
|
41 | //! [1] | |
42 | CustomTableModel *model = new CustomTableModel; |
|
42 | CustomTableModel *model = new CustomTableModel; | |
43 | //! [1] |
|
43 | //! [1] | |
44 |
|
44 | |||
45 | //! [2] |
|
45 | //! [2] | |
46 | // create table view and add model to it |
|
46 | // create table view and add model to it | |
47 | QTableView *tableView = new QTableView; |
|
47 | QTableView *tableView = new QTableView; | |
48 | tableView->setModel(model); |
|
48 | tableView->setModel(model); | |
49 | tableView->setMinimumWidth(300); |
|
49 | tableView->setMinimumWidth(300); | |
50 | tableView->horizontalHeader()->setResizeMode(QHeaderView::Stretch); |
|
50 | tableView->horizontalHeader()->setResizeMode(QHeaderView::Stretch); | |
51 | tableView->verticalHeader()->setResizeMode(QHeaderView::Stretch); |
|
51 | tableView->verticalHeader()->setResizeMode(QHeaderView::Stretch); | |
52 | //! [2] |
|
52 | //! [2] | |
53 |
|
53 | |||
54 | //! [3] |
|
54 | //! [3] | |
55 | QChart *chart = new QChart; |
|
55 | QChart *chart = new QChart; | |
56 | chart->setAnimationOptions(QChart::AllAnimations); |
|
56 | chart->setAnimationOptions(QChart::AllAnimations); | |
57 | //! [3] |
|
57 | //! [3] | |
58 |
|
58 | |||
59 | // series 1 |
|
59 | // series 1 | |
60 | //! [4] |
|
60 | //! [4] | |
61 | QGroupedBarSeries *series = new QGroupedBarSeries; |
|
61 | QGroupedBarSeries *series = new QGroupedBarSeries; | |
62 |
|
62 | |||
63 | int first = 3; |
|
63 | int first = 3; | |
64 | int count = 5; |
|
64 | int count = 5; | |
65 | QVBarModelMapper *mapper = new QVBarModelMapper(this); |
|
65 | QVBarModelMapper *mapper = new QVBarModelMapper(this); | |
66 | mapper->setFirstBarSetColumn(1); |
|
66 | mapper->setFirstBarSetColumn(1); | |
67 | mapper->setLastBarSetColumn(4); |
|
67 | mapper->setLastBarSetColumn(4); | |
68 | mapper->setFirst(first); |
|
68 | mapper->setFirstRow(first); | |
69 | mapper->setCount(count); |
|
69 | mapper->setRowCount(count); | |
70 | mapper->setSeries(series); |
|
70 | mapper->setSeries(series); | |
71 | mapper->setModel(model); |
|
71 | mapper->setModel(model); | |
72 | chart->addSeries(series); |
|
72 | chart->addSeries(series); | |
73 | //! [4] |
|
73 | //! [4] | |
74 |
|
74 | |||
75 | //! [5] |
|
75 | //! [5] | |
76 | // for storing color hex from the series |
|
76 | // for storing color hex from the series | |
77 | QString seriesColorHex = "#000000"; |
|
77 | QString seriesColorHex = "#000000"; | |
78 |
|
78 | |||
79 | // get the color of the series and use it for showing the mapped area |
|
79 | // get the color of the series and use it for showing the mapped area | |
80 | QList<QBarSet*> barsets = series->barSets(); |
|
80 | QList<QBarSet*> barsets = series->barSets(); | |
81 | for (int i = 0; i < barsets.count(); i++) { |
|
81 | for (int i = 0; i < barsets.count(); i++) { | |
82 | seriesColorHex = "#" + QString::number(barsets.at(i)->brush().color().rgb(), 16).right(6).toUpper(); |
|
82 | seriesColorHex = "#" + QString::number(barsets.at(i)->brush().color().rgb(), 16).right(6).toUpper(); | |
83 | model->addMapping(seriesColorHex, QRect(1 + i, first, 1, barsets.at(i)->count())); |
|
83 | model->addMapping(seriesColorHex, QRect(1 + i, first, 1, barsets.at(i)->count())); | |
84 | } |
|
84 | } | |
85 | //! [5] |
|
85 | //! [5] | |
86 |
|
86 | |||
87 | //! [6] |
|
87 | //! [6] | |
88 | QStringList categories; |
|
88 | QStringList categories; | |
89 | categories << "April" << "May" << "June" << "July" << "August"; |
|
89 | categories << "April" << "May" << "June" << "July" << "August"; | |
90 |
|
90 | |||
91 | chart->axisX()->categories()->insert(categories); |
|
91 | chart->axisX()->categories()->insert(categories); | |
92 | //! [6] |
|
92 | //! [6] | |
93 |
|
93 | |||
94 | //! [7] |
|
94 | //! [7] | |
95 | QChartView *chartView = new QChartView(chart); |
|
95 | QChartView *chartView = new QChartView(chart); | |
96 | chartView->setRenderHint(QPainter::Antialiasing); |
|
96 | chartView->setRenderHint(QPainter::Antialiasing); | |
97 | chartView->setMinimumSize(640, 480); |
|
97 | chartView->setMinimumSize(640, 480); | |
98 | //! [7] |
|
98 | //! [7] | |
99 |
|
99 | |||
100 | //! [8] |
|
100 | //! [8] | |
101 | // create main layout |
|
101 | // create main layout | |
102 | QGridLayout* mainLayout = new QGridLayout; |
|
102 | QGridLayout* mainLayout = new QGridLayout; | |
103 | mainLayout->addWidget(tableView, 1, 0); |
|
103 | mainLayout->addWidget(tableView, 1, 0); | |
104 | mainLayout->addWidget(chartView, 1, 1); |
|
104 | mainLayout->addWidget(chartView, 1, 1); | |
105 | mainLayout->setColumnStretch(1, 1); |
|
105 | mainLayout->setColumnStretch(1, 1); | |
106 | mainLayout->setColumnStretch(0, 0); |
|
106 | mainLayout->setColumnStretch(0, 0); | |
107 | setLayout(mainLayout); |
|
107 | setLayout(mainLayout); | |
108 | //! [8] |
|
108 | //! [8] | |
109 | } |
|
109 | } |
@@ -1,654 +1,630 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "qbarmodelmapper.h" |
|
21 | #include "qbarmodelmapper.h" | |
22 | #include "qbarmodelmapper_p.h" |
|
22 | #include "qbarmodelmapper_p.h" | |
23 | #include "qbarseries.h" |
|
23 | #include "qbarseries.h" | |
24 | #include "qbarset.h" |
|
24 | #include "qbarset.h" | |
25 | #include "qchart.h" |
|
25 | #include "qchart.h" | |
26 | #include <QAbstractItemModel> |
|
26 | #include <QAbstractItemModel> | |
27 |
|
27 | |||
28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
29 |
|
29 | |||
30 | /*! |
|
30 | /*! | |
31 | \class QBarModelMapper |
|
31 | \class QBarModelMapper | |
32 | \brief part of QtCommercial chart API. |
|
32 | \brief part of QtCommercial chart API. | |
33 | \mainclass |
|
33 | \mainclass | |
34 |
|
34 | |||
35 | Model mappers allow you to use QAbstractItemModel derived models as a data source for a chart series. |
|
35 | Model mappers allow you to use QAbstractItemModel derived models as a data source for a chart series. | |
36 | The instance of this class cannot be created directly. QHBarModelMapper of QVBarModelMapper should be used instead. |
|
36 | The instance of this class cannot be created directly. QHBarModelMapper of QVBarModelMapper should be used instead. | |
37 | This class is used to create a connection between QBarSeries and QAbstractItemModel derived model object. |
|
37 | This class is used to create a connection between QBarSeries and QAbstractItemModel derived model object. | |
38 | Model mapper maintains equal size of all the BarSets. |
|
38 | Model mapper maintains equal size of all the BarSets. | |
39 | Adding/removing value from the BarSet causes the the same change in the rest of the BarSets added to the same series. |
|
39 | Adding/removing value from the BarSet causes the the same change in the rest of the BarSets added to the same series. | |
40 | NOTE: used model has to support adding/removing rows/columns and modifying the data of the cells. |
|
40 | NOTE: used model has to support adding/removing rows/columns and modifying the data of the cells. | |
41 | */ |
|
41 | */ | |
42 | /*! |
|
42 | /*! | |
43 | \qmlclass BarModelMapper |
|
43 | \qmlclass BarModelMapper | |
44 | Cannot be created by the user. Base for HBarModelMapper and VBarModelMapper. Model mappers allow you to use |
|
44 | Cannot be created by the user. Base for HBarModelMapper and VBarModelMapper. Model mappers allow you to use | |
45 | QAbstractItemModel derived models as a data source for a chart series. Adding/removing value from the BarSet causes |
|
45 | QAbstractItemModel derived models as a data source for a chart series. Adding/removing value from the BarSet causes | |
46 | the the same change in the rest of the BarSets added to the same series. |
|
46 | the the same change in the rest of the BarSets added to the same series. | |
47 | */ |
|
47 | */ | |
48 |
|
48 | |||
49 | /*! |
|
49 | /*! | |
50 | \property QBarModelMapper::series |
|
50 | \property QBarModelMapper::series | |
51 | \brief Defines the QPieSeries object that is used by the mapper. |
|
51 | \brief Defines the QPieSeries object that is used by the mapper. | |
52 | All the data in the series is discarded when it is set to the mapper. |
|
52 | All the data in the series is discarded when it is set to the mapper. | |
53 | When new series is specified the old series is disconnected (it preserves its data) |
|
53 | When new series is specified the old series is disconnected (it preserves its data) | |
54 | */ |
|
54 | */ | |
55 | /*! |
|
55 | /*! | |
56 | \qmlproperty BarSeries BarModelMapper::series |
|
56 | \qmlproperty BarSeries BarModelMapper::series | |
57 | Defines the BarSeries based object that is used by the mapper. All the data in the series is |
|
57 | Defines the BarSeries based object that is used by the mapper. All the data in the series is | |
58 | discarded when it is set to the mapper. When new series is specified the old series is |
|
58 | discarded when it is set to the mapper. When new series is specified the old series is | |
59 | disconnected (it preserves its data). |
|
59 | disconnected (it preserves its data). | |
60 | */ |
|
60 | */ | |
61 |
|
61 | |||
62 | /*! |
|
62 | /*! | |
63 | \property QBarModelMapper::model |
|
63 | \property QBarModelMapper::model | |
64 | \brief Defines the model that is used by the mapper. |
|
64 | \brief Defines the model that is used by the mapper. | |
65 | */ |
|
65 | */ | |
66 | /*! |
|
66 | /*! | |
67 | \qmlproperty Model BarModelMapper::model |
|
67 | \qmlproperty Model BarModelMapper::model | |
68 | The QAbstractItemModel based model that is used by the mapper. You need to implement the model and expose it to |
|
68 | The QAbstractItemModel based model that is used by the mapper. You need to implement the model and expose it to | |
69 | QML as shown in \l {QML Custom Model} demo application. NOTE: the model has to support adding/removing rows/columns |
|
69 | QML as shown in \l {QML Custom Model} demo application. NOTE: the model has to support adding/removing rows/columns | |
70 | and modifying the data of the cells. |
|
70 | and modifying the data of the cells. | |
71 | */ |
|
71 | */ | |
72 |
|
72 | |||
73 | /*! |
|
73 | /*! | |
74 | \property QBarModelMapper::first |
|
|||
75 | \brief Defines which item of the model's row/column should be mapped as the value of the first QBarSet in the series. |
|
|||
76 | Minimal and default value is: 0 |
|
|||
77 | */ |
|
|||
78 | /*! |
|
|||
79 | \qmlproperty int BarModelMapper::first |
|
|||
80 | Defines which item of the model's row/column should be mapped as the value of the first QBarSet in the series. |
|
|||
81 | The default value is 0. |
|
|||
82 | */ |
|
|||
83 |
|
||||
84 | /*! |
|
|||
85 | \property QBarModelMapper::count |
|
|||
86 | \brief Defines the number of rows/columns of the model that are mapped as the data for QBarSeries |
|
|||
87 | Minimal and default value is: -1 (count limited by the number of rows/columns in the model) |
|
|||
88 | */ |
|
|||
89 | /*! |
|
|||
90 | \qmlproperty int BarModelMapper::count |
|
|||
91 | Defines the number of rows/columns of the model that are mapped as the data for QBarSeries. The default value is |
|
|||
92 | -1 (count limited by the number of rows/columns in the model) |
|
|||
93 | */ |
|
|||
94 |
|
||||
95 | /*! |
|
|||
96 | \fn void QBarModelMapper::seriesReplaced() |
|
74 | \fn void QBarModelMapper::seriesReplaced() | |
97 | Emitted when the series to which mapper is connected to has changed. |
|
75 | Emitted when the series to which mapper is connected to has changed. | |
98 | */ |
|
76 | */ | |
99 |
|
77 | |||
100 | /*! |
|
78 | /*! | |
101 | \fn void QBarModelMapper::modelReplaced() |
|
79 | \fn void QBarModelMapper::modelReplaced() | |
102 | Emitted when the model to which mapper is connected to has changed. |
|
80 | Emitted when the model to which mapper is connected to has changed. | |
103 | */ |
|
81 | */ | |
104 |
|
82 | |||
105 | /*! |
|
83 | /*! | |
106 | \fn void QBarModelMapper::firstChanged() |
|
|||
107 | Emitted when the value for the first has changed. |
|
|||
108 | */ |
|
|||
109 |
|
||||
110 | /*! |
|
|||
111 | \fn void QBarModelMapper::countChanged() |
|
|||
112 | Emitted when the value for the count has changed. |
|
|||
113 | */ |
|
|||
114 |
|
||||
115 | /*! |
|
|||
116 | Constructs a mapper object which is a child of \a parent. |
|
84 | Constructs a mapper object which is a child of \a parent. | |
117 | */ |
|
85 | */ | |
118 | QBarModelMapper::QBarModelMapper(QObject *parent) : |
|
86 | QBarModelMapper::QBarModelMapper(QObject *parent) : | |
119 | QObject(parent), |
|
87 | QObject(parent), | |
120 | d_ptr(new QBarModelMapperPrivate(this)) |
|
88 | d_ptr(new QBarModelMapperPrivate(this)) | |
121 | { |
|
89 | { | |
122 | } |
|
90 | } | |
123 |
|
91 | |||
124 | QAbstractItemModel* QBarModelMapper::model() const |
|
92 | QAbstractItemModel* QBarModelMapper::model() const | |
125 | { |
|
93 | { | |
126 | Q_D(const QBarModelMapper); |
|
94 | Q_D(const QBarModelMapper); | |
127 | return d->m_model; |
|
95 | return d->m_model; | |
128 | } |
|
96 | } | |
129 |
|
97 | |||
130 | void QBarModelMapper::setModel(QAbstractItemModel *model) |
|
98 | void QBarModelMapper::setModel(QAbstractItemModel *model) | |
131 | { |
|
99 | { | |
132 | if (model == 0) |
|
100 | if (model == 0) | |
133 | return; |
|
101 | return; | |
134 |
|
102 | |||
135 | Q_D(QBarModelMapper); |
|
103 | Q_D(QBarModelMapper); | |
136 | if (d->m_model) { |
|
104 | if (d->m_model) { | |
137 | disconnect(d->m_model, 0, d, 0); |
|
105 | disconnect(d->m_model, 0, d, 0); | |
138 | } |
|
106 | } | |
139 |
|
107 | |||
140 | d->m_model = model; |
|
108 | d->m_model = model; | |
141 | d->initializeBarFromModel(); |
|
109 | d->initializeBarFromModel(); | |
142 | // connect signals from the model |
|
110 | // connect signals from the model | |
143 | connect(d->m_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), d, SLOT(modelUpdated(QModelIndex,QModelIndex))); |
|
111 | connect(d->m_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), d, SLOT(modelUpdated(QModelIndex,QModelIndex))); | |
144 | connect(d->m_model, SIGNAL(headerDataChanged(Qt::Orientation,int,int)), d, SLOT(modelHeaderDataUpdated(Qt::Orientation,int,int))); |
|
112 | connect(d->m_model, SIGNAL(headerDataChanged(Qt::Orientation,int,int)), d, SLOT(modelHeaderDataUpdated(Qt::Orientation,int,int))); | |
145 | connect(d->m_model, SIGNAL(rowsInserted(QModelIndex,int,int)), d, SLOT(modelRowsAdded(QModelIndex,int,int))); |
|
113 | connect(d->m_model, SIGNAL(rowsInserted(QModelIndex,int,int)), d, SLOT(modelRowsAdded(QModelIndex,int,int))); | |
146 | connect(d->m_model, SIGNAL(rowsRemoved(QModelIndex,int,int)), d, SLOT(modelRowsRemoved(QModelIndex,int,int))); |
|
114 | connect(d->m_model, SIGNAL(rowsRemoved(QModelIndex,int,int)), d, SLOT(modelRowsRemoved(QModelIndex,int,int))); | |
147 | connect(d->m_model, SIGNAL(columnsInserted(QModelIndex,int,int)), d, SLOT(modelColumnsAdded(QModelIndex,int,int))); |
|
115 | connect(d->m_model, SIGNAL(columnsInserted(QModelIndex,int,int)), d, SLOT(modelColumnsAdded(QModelIndex,int,int))); | |
148 | connect(d->m_model, SIGNAL(columnsRemoved(QModelIndex,int,int)), d, SLOT(modelColumnsRemoved(QModelIndex,int,int))); |
|
116 | connect(d->m_model, SIGNAL(columnsRemoved(QModelIndex,int,int)), d, SLOT(modelColumnsRemoved(QModelIndex,int,int))); | |
149 |
|
117 | |||
150 | emit modelReplaced(); |
|
118 | emit modelReplaced(); | |
151 | } |
|
119 | } | |
152 |
|
120 | |||
153 | QBarSeries* QBarModelMapper::series() const |
|
121 | QBarSeries* QBarModelMapper::series() const | |
154 | { |
|
122 | { | |
155 | Q_D(const QBarModelMapper); |
|
123 | Q_D(const QBarModelMapper); | |
156 | return d->m_series; |
|
124 | return d->m_series; | |
157 | } |
|
125 | } | |
158 |
|
126 | |||
159 | void QBarModelMapper::setSeries(QBarSeries *series) |
|
127 | void QBarModelMapper::setSeries(QBarSeries *series) | |
160 | { |
|
128 | { | |
161 | Q_D(QBarModelMapper); |
|
129 | Q_D(QBarModelMapper); | |
162 | if (d->m_series) { |
|
130 | if (d->m_series) { | |
163 | disconnect(d->m_series, 0, d, 0); |
|
131 | disconnect(d->m_series, 0, d, 0); | |
164 | } |
|
132 | } | |
165 |
|
133 | |||
166 | if (series == 0) |
|
134 | if (series == 0) | |
167 | return; |
|
135 | return; | |
168 |
|
136 | |||
169 | d->m_series = series; |
|
137 | d->m_series = series; | |
170 | d->initializeBarFromModel(); |
|
138 | d->initializeBarFromModel(); | |
171 | // connect the signals from the series |
|
139 | // connect the signals from the series | |
172 | connect(d->m_series, SIGNAL(barsetsAdded(QList<QBarSet*>)), d, SLOT(barSetsAdded(QList<QBarSet*>))); |
|
140 | connect(d->m_series, SIGNAL(barsetsAdded(QList<QBarSet*>)), d, SLOT(barSetsAdded(QList<QBarSet*>))); | |
173 | connect(d->m_series, SIGNAL(barsetsRemoved(QList<QBarSet*>)), d, SLOT(barSetsRemoved(QList<QBarSet*>))); |
|
141 | connect(d->m_series, SIGNAL(barsetsRemoved(QList<QBarSet*>)), d, SLOT(barSetsRemoved(QList<QBarSet*>))); | |
174 |
|
142 | |||
175 | emit seriesReplaced(); |
|
143 | emit seriesReplaced(); | |
176 | } |
|
144 | } | |
177 |
|
145 | |||
|
146 | /*! | |||
|
147 | Returns which row/column of the model contains the first values of the QBarSets in the series. | |||
|
148 | The default value is 0. | |||
|
149 | */ | |||
178 | int QBarModelMapper::first() const |
|
150 | int QBarModelMapper::first() const | |
179 | { |
|
151 | { | |
180 | Q_D(const QBarModelMapper); |
|
152 | Q_D(const QBarModelMapper); | |
181 | return d->m_first; |
|
153 | return d->m_first; | |
182 | } |
|
154 | } | |
183 |
|
155 | |||
|
156 | /*! | |||
|
157 | Sets which row of the model contains the \a first values of the QBarSets in the series. | |||
|
158 | The default value is 0. | |||
|
159 | */ | |||
184 | void QBarModelMapper::setFirst(int first) |
|
160 | void QBarModelMapper::setFirst(int first) | |
185 | { |
|
161 | { | |
186 | Q_D(QBarModelMapper); |
|
162 | Q_D(QBarModelMapper); | |
187 | if (first != d->m_first) { |
|
163 | d->m_first = qMax(first, 0); | |
188 | d->m_first = qMax(first, 0); |
|
164 | d->initializeBarFromModel(); | |
189 | d->initializeBarFromModel(); |
|
|||
190 |
|
||||
191 | emit firstChanged(); |
|
|||
192 | } |
|
|||
193 | } |
|
165 | } | |
194 |
|
166 | |||
|
167 | /*! | |||
|
168 | Returns the number of rows/columns of the model that are mapped as the data for QBarSeries | |||
|
169 | Minimal and default value is: -1 (count limited by the number of rows/columns in the model) | |||
|
170 | */ | |||
195 | int QBarModelMapper::count() const |
|
171 | int QBarModelMapper::count() const | |
196 | { |
|
172 | { | |
197 | Q_D(const QBarModelMapper); |
|
173 | Q_D(const QBarModelMapper); | |
198 | return d->m_count; |
|
174 | return d->m_count; | |
199 | } |
|
175 | } | |
200 |
|
176 | |||
|
177 | /*! | |||
|
178 | Sets the \a count of rows/columns of the model that are mapped as the data for QBarSeries | |||
|
179 | Minimal and default value is: -1 (count limited by the number of rows/columns in the model) | |||
|
180 | */ | |||
201 | void QBarModelMapper::setCount(int count) |
|
181 | void QBarModelMapper::setCount(int count) | |
202 | { |
|
182 | { | |
203 | Q_D(QBarModelMapper); |
|
183 | Q_D(QBarModelMapper); | |
204 | if (count != d->m_count) { |
|
184 | d->m_count = qMax(count, -1); | |
205 | d->m_count = qMax(count, -1); |
|
185 | d->initializeBarFromModel(); | |
206 | d->initializeBarFromModel(); |
|
|||
207 |
|
||||
208 | emit countChanged(); |
|
|||
209 | } |
|
|||
210 | } |
|
186 | } | |
211 |
|
187 | |||
212 | /*! |
|
188 | /*! | |
213 | Returns the orientation that is used when QBarModelMapper accesses the model. |
|
189 | Returns the orientation that is used when QBarModelMapper accesses the model. | |
214 | This mean whether the consecutive values of the bar set are read from row (Qt::Horizontal) |
|
190 | This mean whether the consecutive values of the bar set are read from row (Qt::Horizontal) | |
215 | or from columns (Qt::Vertical) |
|
191 | or from columns (Qt::Vertical) | |
216 | */ |
|
192 | */ | |
217 | Qt::Orientation QBarModelMapper::orientation() const |
|
193 | Qt::Orientation QBarModelMapper::orientation() const | |
218 | { |
|
194 | { | |
219 | Q_D(const QBarModelMapper); |
|
195 | Q_D(const QBarModelMapper); | |
220 | return d->m_orientation; |
|
196 | return d->m_orientation; | |
221 | } |
|
197 | } | |
222 |
|
198 | |||
223 | /*! |
|
199 | /*! | |
224 | Returns the \a orientation that is used when QBarModelMapper accesses the model. |
|
200 | Returns the \a orientation that is used when QBarModelMapper accesses the model. | |
225 | This mean whether the consecutive values of the pie are read from row (Qt::Horizontal) |
|
201 | This mean whether the consecutive values of the pie are read from row (Qt::Horizontal) | |
226 | or from columns (Qt::Vertical) |
|
202 | or from columns (Qt::Vertical) | |
227 | */ |
|
203 | */ | |
228 | void QBarModelMapper::setOrientation(Qt::Orientation orientation) |
|
204 | void QBarModelMapper::setOrientation(Qt::Orientation orientation) | |
229 | { |
|
205 | { | |
230 | Q_D(QBarModelMapper); |
|
206 | Q_D(QBarModelMapper); | |
231 | d->m_orientation = orientation; |
|
207 | d->m_orientation = orientation; | |
232 | d->initializeBarFromModel(); |
|
208 | d->initializeBarFromModel(); | |
233 | } |
|
209 | } | |
234 |
|
210 | |||
235 | /*! |
|
211 | /*! | |
236 | Returns which section of the model is used as the data source for the first bar set |
|
212 | Returns which section of the model is used as the data source for the first bar set | |
237 | */ |
|
213 | */ | |
238 | int QBarModelMapper::firstBarSetSection() const |
|
214 | int QBarModelMapper::firstBarSetSection() const | |
239 | { |
|
215 | { | |
240 | Q_D(const QBarModelMapper); |
|
216 | Q_D(const QBarModelMapper); | |
241 | return d->m_firstBarSetSection; |
|
217 | return d->m_firstBarSetSection; | |
242 | } |
|
218 | } | |
243 |
|
219 | |||
244 | /*! |
|
220 | /*! | |
245 | Sets the model section that is used as the data source for the first bar set |
|
221 | Sets the model section that is used as the data source for the first bar set | |
246 | Parameter \a firstBarSetSection specifies the section of the model. |
|
222 | Parameter \a firstBarSetSection specifies the section of the model. | |
247 | */ |
|
223 | */ | |
248 | void QBarModelMapper::setFirstBarSetSection(int firstBarSetSection) |
|
224 | void QBarModelMapper::setFirstBarSetSection(int firstBarSetSection) | |
249 | { |
|
225 | { | |
250 | Q_D(QBarModelMapper); |
|
226 | Q_D(QBarModelMapper); | |
251 | d->m_firstBarSetSection = qMax(-1, firstBarSetSection); |
|
227 | d->m_firstBarSetSection = qMax(-1, firstBarSetSection); | |
252 | d->initializeBarFromModel(); |
|
228 | d->initializeBarFromModel(); | |
253 | } |
|
229 | } | |
254 |
|
230 | |||
255 | /*! |
|
231 | /*! | |
256 | Returns which section of the model is used as the data source for the last bar set |
|
232 | Returns which section of the model is used as the data source for the last bar set | |
257 | */ |
|
233 | */ | |
258 | int QBarModelMapper::lastBarSetSection() const |
|
234 | int QBarModelMapper::lastBarSetSection() const | |
259 | { |
|
235 | { | |
260 | Q_D(const QBarModelMapper); |
|
236 | Q_D(const QBarModelMapper); | |
261 | return d->m_lastBarSetSection; |
|
237 | return d->m_lastBarSetSection; | |
262 | } |
|
238 | } | |
263 |
|
239 | |||
264 | /*! |
|
240 | /*! | |
265 | Sets the model section that is used as the data source for the last bar set |
|
241 | Sets the model section that is used as the data source for the last bar set | |
266 | Parameter \a lastBarSetSection specifies the section of the model. |
|
242 | Parameter \a lastBarSetSection specifies the section of the model. | |
267 | */ |
|
243 | */ | |
268 | void QBarModelMapper::setLastBarSetSection(int lastBarSetSection) |
|
244 | void QBarModelMapper::setLastBarSetSection(int lastBarSetSection) | |
269 | { |
|
245 | { | |
270 | Q_D(QBarModelMapper); |
|
246 | Q_D(QBarModelMapper); | |
271 | d->m_lastBarSetSection = qMax(-1, lastBarSetSection); |
|
247 | d->m_lastBarSetSection = qMax(-1, lastBarSetSection); | |
272 | d->initializeBarFromModel(); |
|
248 | d->initializeBarFromModel(); | |
273 | } |
|
249 | } | |
274 |
|
250 | |||
275 | /*! |
|
251 | /*! | |
276 | Resets the QBarModelMapper to the default state. |
|
252 | Resets the QBarModelMapper to the default state. | |
277 | first: 0; count: -1; firstBarSetSection: -1; lastBarSetSection: -1; categoriesSection: -1 |
|
253 | first: 0; count: -1; firstBarSetSection: -1; lastBarSetSection: -1; categoriesSection: -1 | |
278 | */ |
|
254 | */ | |
279 | void QBarModelMapper::reset() |
|
255 | void QBarModelMapper::reset() | |
280 | { |
|
256 | { | |
281 | Q_D(QBarModelMapper); |
|
257 | Q_D(QBarModelMapper); | |
282 | d->m_first = 0; |
|
258 | d->m_first = 0; | |
283 | d->m_count = -1; |
|
259 | d->m_count = -1; | |
284 | d->m_firstBarSetSection = -1; |
|
260 | d->m_firstBarSetSection = -1; | |
285 | d->m_lastBarSetSection = -1; |
|
261 | d->m_lastBarSetSection = -1; | |
286 | d->initializeBarFromModel(); |
|
262 | d->initializeBarFromModel(); | |
287 | } |
|
263 | } | |
288 |
|
264 | |||
289 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
265 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
290 |
|
266 | |||
291 | QBarModelMapperPrivate::QBarModelMapperPrivate(QBarModelMapper *q) : |
|
267 | QBarModelMapperPrivate::QBarModelMapperPrivate(QBarModelMapper *q) : | |
292 | m_series(0), |
|
268 | m_series(0), | |
293 | m_model(0), |
|
269 | m_model(0), | |
294 | m_first(0), |
|
270 | m_first(0), | |
295 | m_count(-1), |
|
271 | m_count(-1), | |
296 | m_orientation(Qt::Vertical), |
|
272 | m_orientation(Qt::Vertical), | |
297 | m_firstBarSetSection(-1), |
|
273 | m_firstBarSetSection(-1), | |
298 | m_lastBarSetSection(-1), |
|
274 | m_lastBarSetSection(-1), | |
299 | m_seriesSignalsBlock(false), |
|
275 | m_seriesSignalsBlock(false), | |
300 | m_modelSignalsBlock(false), |
|
276 | m_modelSignalsBlock(false), | |
301 | q_ptr(q) |
|
277 | q_ptr(q) | |
302 | { |
|
278 | { | |
303 | } |
|
279 | } | |
304 |
|
280 | |||
305 | void QBarModelMapperPrivate::blockModelSignals(bool block) |
|
281 | void QBarModelMapperPrivate::blockModelSignals(bool block) | |
306 | { |
|
282 | { | |
307 | m_modelSignalsBlock = block; |
|
283 | m_modelSignalsBlock = block; | |
308 | } |
|
284 | } | |
309 |
|
285 | |||
310 | void QBarModelMapperPrivate::blockSeriesSignals(bool block) |
|
286 | void QBarModelMapperPrivate::blockSeriesSignals(bool block) | |
311 | { |
|
287 | { | |
312 | m_seriesSignalsBlock = block; |
|
288 | m_seriesSignalsBlock = block; | |
313 | } |
|
289 | } | |
314 |
|
290 | |||
315 | QBarSet* QBarModelMapperPrivate::barSet(QModelIndex index) |
|
291 | QBarSet* QBarModelMapperPrivate::barSet(QModelIndex index) | |
316 | { |
|
292 | { | |
317 | if (!index.isValid()) |
|
293 | if (!index.isValid()) | |
318 | return 0; |
|
294 | return 0; | |
319 |
|
295 | |||
320 | if (m_orientation == Qt::Vertical && index.column() >= m_firstBarSetSection && index.column() <= m_lastBarSetSection) { |
|
296 | if (m_orientation == Qt::Vertical && index.column() >= m_firstBarSetSection && index.column() <= m_lastBarSetSection) { | |
321 | if (index.row() >= m_first && (m_count == - 1 || index.row() < m_first + m_count)) { |
|
297 | if (index.row() >= m_first && (m_count == - 1 || index.row() < m_first + m_count)) { | |
322 | // if (m_model->index(index.row(), m_valuesSection).isValid() && m_model->index(index.row(), m_labelsSection).isValid()) |
|
298 | // if (m_model->index(index.row(), m_valuesSection).isValid() && m_model->index(index.row(), m_labelsSection).isValid()) | |
323 | return m_series->barSets().at(index.column() - m_firstBarSetSection); |
|
299 | return m_series->barSets().at(index.column() - m_firstBarSetSection); | |
324 | // else |
|
300 | // else | |
325 | // return 0; |
|
301 | // return 0; | |
326 | } |
|
302 | } | |
327 | } else if (m_orientation == Qt::Horizontal && index.row() >= m_firstBarSetSection && index.row() <= m_lastBarSetSection) { |
|
303 | } else if (m_orientation == Qt::Horizontal && index.row() >= m_firstBarSetSection && index.row() <= m_lastBarSetSection) { | |
328 | if (index.column() >= m_first && (m_count == - 1 || index.column() < m_first + m_count)) |
|
304 | if (index.column() >= m_first && (m_count == - 1 || index.column() < m_first + m_count)) | |
329 | return m_series->barSets().at(index.row() - m_firstBarSetSection); |
|
305 | return m_series->barSets().at(index.row() - m_firstBarSetSection); | |
330 | } |
|
306 | } | |
331 | return 0; // This part of model has not been mapped to any slice |
|
307 | return 0; // This part of model has not been mapped to any slice | |
332 | } |
|
308 | } | |
333 |
|
309 | |||
334 | QModelIndex QBarModelMapperPrivate::barModelIndex(int barSection, int posInBar) |
|
310 | QModelIndex QBarModelMapperPrivate::barModelIndex(int barSection, int posInBar) | |
335 | { |
|
311 | { | |
336 | if (m_count != -1 && posInBar >= m_count) |
|
312 | if (m_count != -1 && posInBar >= m_count) | |
337 | return QModelIndex(); // invalid |
|
313 | return QModelIndex(); // invalid | |
338 |
|
314 | |||
339 | if (barSection < m_firstBarSetSection || barSection > m_lastBarSetSection) |
|
315 | if (barSection < m_firstBarSetSection || barSection > m_lastBarSetSection) | |
340 | return QModelIndex(); // invalid |
|
316 | return QModelIndex(); // invalid | |
341 |
|
317 | |||
342 | if (m_orientation == Qt::Vertical) |
|
318 | if (m_orientation == Qt::Vertical) | |
343 | return m_model->index(posInBar + m_first, barSection); |
|
319 | return m_model->index(posInBar + m_first, barSection); | |
344 | else |
|
320 | else | |
345 | return m_model->index(barSection, posInBar + m_first); |
|
321 | return m_model->index(barSection, posInBar + m_first); | |
346 | } |
|
322 | } | |
347 |
|
323 | |||
348 | void QBarModelMapperPrivate::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight) |
|
324 | void QBarModelMapperPrivate::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight) | |
349 | { |
|
325 | { | |
350 | Q_UNUSED(topLeft) |
|
326 | Q_UNUSED(topLeft) | |
351 | Q_UNUSED(bottomRight) |
|
327 | Q_UNUSED(bottomRight) | |
352 |
|
328 | |||
353 | if (m_model == 0 || m_series == 0) |
|
329 | if (m_model == 0 || m_series == 0) | |
354 | return; |
|
330 | return; | |
355 |
|
331 | |||
356 | if (m_modelSignalsBlock) |
|
332 | if (m_modelSignalsBlock) | |
357 | return; |
|
333 | return; | |
358 |
|
334 | |||
359 | blockSeriesSignals(); |
|
335 | blockSeriesSignals(); | |
360 | QModelIndex index; |
|
336 | QModelIndex index; | |
361 | for (int row = topLeft.row(); row <= bottomRight.row(); row++) { |
|
337 | for (int row = topLeft.row(); row <= bottomRight.row(); row++) { | |
362 | for (int column = topLeft.column(); column <= bottomRight.column(); column++) { |
|
338 | for (int column = topLeft.column(); column <= bottomRight.column(); column++) { | |
363 | index = topLeft.sibling(row, column); |
|
339 | index = topLeft.sibling(row, column); | |
364 | QBarSet* bar = barSet(index); |
|
340 | QBarSet* bar = barSet(index); | |
365 | if (bar) { |
|
341 | if (bar) { | |
366 | if (m_orientation == Qt::Vertical) |
|
342 | if (m_orientation == Qt::Vertical) | |
367 | bar->replace(row - m_first, m_model->data(index).toReal()); |
|
343 | bar->replace(row - m_first, m_model->data(index).toReal()); | |
368 | else |
|
344 | else | |
369 | bar->replace(column - m_first, m_model->data(index).toReal()); |
|
345 | bar->replace(column - m_first, m_model->data(index).toReal()); | |
370 | } |
|
346 | } | |
371 | } |
|
347 | } | |
372 | } |
|
348 | } | |
373 | blockSeriesSignals(false); |
|
349 | blockSeriesSignals(false); | |
374 | } |
|
350 | } | |
375 |
|
351 | |||
376 | void QBarModelMapperPrivate::modelHeaderDataUpdated(Qt::Orientation orientation, int first, int last) |
|
352 | void QBarModelMapperPrivate::modelHeaderDataUpdated(Qt::Orientation orientation, int first, int last) | |
377 | { |
|
353 | { | |
378 | if (m_model == 0 || m_series == 0) |
|
354 | if (m_model == 0 || m_series == 0) | |
379 | return; |
|
355 | return; | |
380 |
|
356 | |||
381 | if (m_modelSignalsBlock) |
|
357 | if (m_modelSignalsBlock) | |
382 | return; |
|
358 | return; | |
383 |
|
359 | |||
384 | blockSeriesSignals(); |
|
360 | blockSeriesSignals(); | |
385 | if (orientation != m_orientation) { |
|
361 | if (orientation != m_orientation) { | |
386 | for (int section = first; section <= last; section++) { |
|
362 | for (int section = first; section <= last; section++) { | |
387 | if (section >= m_firstBarSetSection && section <= m_lastBarSetSection) { |
|
363 | if (section >= m_firstBarSetSection && section <= m_lastBarSetSection) { | |
388 | QBarSet* bar = m_series->barSets().at(section - m_firstBarSetSection); |
|
364 | QBarSet* bar = m_series->barSets().at(section - m_firstBarSetSection); | |
389 | if (bar) |
|
365 | if (bar) | |
390 | bar->setLabel(m_model->headerData(section, orientation).toString()); |
|
366 | bar->setLabel(m_model->headerData(section, orientation).toString()); | |
391 | } |
|
367 | } | |
392 | } |
|
368 | } | |
393 | } |
|
369 | } | |
394 | blockSeriesSignals(false); |
|
370 | blockSeriesSignals(false); | |
395 | } |
|
371 | } | |
396 |
|
372 | |||
397 | void QBarModelMapperPrivate::modelRowsAdded(QModelIndex parent, int start, int end) |
|
373 | void QBarModelMapperPrivate::modelRowsAdded(QModelIndex parent, int start, int end) | |
398 | { |
|
374 | { | |
399 | Q_UNUSED(parent); |
|
375 | Q_UNUSED(parent); | |
400 | Q_UNUSED(end) |
|
376 | Q_UNUSED(end) | |
401 | if (m_modelSignalsBlock) |
|
377 | if (m_modelSignalsBlock) | |
402 | return; |
|
378 | return; | |
403 |
|
379 | |||
404 | blockSeriesSignals(); |
|
380 | blockSeriesSignals(); | |
405 | if (m_orientation == Qt::Vertical) |
|
381 | if (m_orientation == Qt::Vertical) | |
406 | // insertData(start, end); |
|
382 | // insertData(start, end); | |
407 | initializeBarFromModel(); |
|
383 | initializeBarFromModel(); | |
408 | else if (start <= m_firstBarSetSection || start <= m_lastBarSetSection) // if the changes affect the map - reinitialize |
|
384 | else if (start <= m_firstBarSetSection || start <= m_lastBarSetSection) // if the changes affect the map - reinitialize | |
409 | initializeBarFromModel(); |
|
385 | initializeBarFromModel(); | |
410 | blockSeriesSignals(false); |
|
386 | blockSeriesSignals(false); | |
411 | } |
|
387 | } | |
412 |
|
388 | |||
413 | void QBarModelMapperPrivate::modelRowsRemoved(QModelIndex parent, int start, int end) |
|
389 | void QBarModelMapperPrivate::modelRowsRemoved(QModelIndex parent, int start, int end) | |
414 | { |
|
390 | { | |
415 | Q_UNUSED(parent); |
|
391 | Q_UNUSED(parent); | |
416 | Q_UNUSED(end) |
|
392 | Q_UNUSED(end) | |
417 | if (m_modelSignalsBlock) |
|
393 | if (m_modelSignalsBlock) | |
418 | return; |
|
394 | return; | |
419 |
|
395 | |||
420 | blockSeriesSignals(); |
|
396 | blockSeriesSignals(); | |
421 | if (m_orientation == Qt::Vertical) |
|
397 | if (m_orientation == Qt::Vertical) | |
422 | // removeData(start, end); |
|
398 | // removeData(start, end); | |
423 | initializeBarFromModel(); |
|
399 | initializeBarFromModel(); | |
424 | else if (start <= m_firstBarSetSection || start <= m_lastBarSetSection) // if the changes affect the map - reinitialize |
|
400 | else if (start <= m_firstBarSetSection || start <= m_lastBarSetSection) // if the changes affect the map - reinitialize | |
425 | initializeBarFromModel(); |
|
401 | initializeBarFromModel(); | |
426 | blockSeriesSignals(false); |
|
402 | blockSeriesSignals(false); | |
427 | } |
|
403 | } | |
428 |
|
404 | |||
429 | void QBarModelMapperPrivate::modelColumnsAdded(QModelIndex parent, int start, int end) |
|
405 | void QBarModelMapperPrivate::modelColumnsAdded(QModelIndex parent, int start, int end) | |
430 | { |
|
406 | { | |
431 | Q_UNUSED(parent); |
|
407 | Q_UNUSED(parent); | |
432 | Q_UNUSED(end) |
|
408 | Q_UNUSED(end) | |
433 | if (m_modelSignalsBlock) |
|
409 | if (m_modelSignalsBlock) | |
434 | return; |
|
410 | return; | |
435 |
|
411 | |||
436 | blockSeriesSignals(); |
|
412 | blockSeriesSignals(); | |
437 | if (m_orientation == Qt::Horizontal) |
|
413 | if (m_orientation == Qt::Horizontal) | |
438 | // insertData(start, end); |
|
414 | // insertData(start, end); | |
439 | initializeBarFromModel(); |
|
415 | initializeBarFromModel(); | |
440 | else if (start <= m_firstBarSetSection || start <= m_lastBarSetSection) // if the changes affect the map - reinitialize |
|
416 | else if (start <= m_firstBarSetSection || start <= m_lastBarSetSection) // if the changes affect the map - reinitialize | |
441 | initializeBarFromModel(); |
|
417 | initializeBarFromModel(); | |
442 | blockSeriesSignals(false); |
|
418 | blockSeriesSignals(false); | |
443 | } |
|
419 | } | |
444 |
|
420 | |||
445 | void QBarModelMapperPrivate::modelColumnsRemoved(QModelIndex parent, int start, int end) |
|
421 | void QBarModelMapperPrivate::modelColumnsRemoved(QModelIndex parent, int start, int end) | |
446 | { |
|
422 | { | |
447 | Q_UNUSED(parent); |
|
423 | Q_UNUSED(parent); | |
448 | Q_UNUSED(end) |
|
424 | Q_UNUSED(end) | |
449 | if (m_modelSignalsBlock) |
|
425 | if (m_modelSignalsBlock) | |
450 | return; |
|
426 | return; | |
451 |
|
427 | |||
452 | blockSeriesSignals(); |
|
428 | blockSeriesSignals(); | |
453 | if (m_orientation == Qt::Horizontal) |
|
429 | if (m_orientation == Qt::Horizontal) | |
454 | // removeData(start, end); |
|
430 | // removeData(start, end); | |
455 | initializeBarFromModel(); |
|
431 | initializeBarFromModel(); | |
456 | else if (start <= m_firstBarSetSection || start <= m_lastBarSetSection) // if the changes affect the map - reinitialize |
|
432 | else if (start <= m_firstBarSetSection || start <= m_lastBarSetSection) // if the changes affect the map - reinitialize | |
457 | initializeBarFromModel(); |
|
433 | initializeBarFromModel(); | |
458 | blockSeriesSignals(false); |
|
434 | blockSeriesSignals(false); | |
459 | } |
|
435 | } | |
460 |
|
436 | |||
461 | void QBarModelMapperPrivate::insertData(int start, int end) |
|
437 | void QBarModelMapperPrivate::insertData(int start, int end) | |
462 | { |
|
438 | { | |
463 | Q_UNUSED(end) |
|
439 | Q_UNUSED(end) | |
464 | Q_UNUSED(start) |
|
440 | Q_UNUSED(start) | |
465 | Q_UNUSED(end) |
|
441 | Q_UNUSED(end) | |
466 | // To be implemented |
|
442 | // To be implemented | |
467 | } |
|
443 | } | |
468 |
|
444 | |||
469 | void QBarModelMapperPrivate::removeData(int start, int end) |
|
445 | void QBarModelMapperPrivate::removeData(int start, int end) | |
470 | { |
|
446 | { | |
471 | Q_UNUSED(end) |
|
447 | Q_UNUSED(end) | |
472 | Q_UNUSED(start) |
|
448 | Q_UNUSED(start) | |
473 | Q_UNUSED(end) |
|
449 | Q_UNUSED(end) | |
474 | // To be implemented |
|
450 | // To be implemented | |
475 | } |
|
451 | } | |
476 |
|
452 | |||
477 | void QBarModelMapperPrivate::barSetsAdded(QList<QBarSet*> sets) |
|
453 | void QBarModelMapperPrivate::barSetsAdded(QList<QBarSet*> sets) | |
478 | { |
|
454 | { | |
479 | if (m_seriesSignalsBlock) |
|
455 | if (m_seriesSignalsBlock) | |
480 | return; |
|
456 | return; | |
481 |
|
457 | |||
482 | if (sets.count() == 0) |
|
458 | if (sets.count() == 0) | |
483 | return; |
|
459 | return; | |
484 |
|
460 | |||
485 | int firstIndex = m_series->barSets().indexOf(sets.at(0)); |
|
461 | int firstIndex = m_series->barSets().indexOf(sets.at(0)); | |
486 | if (firstIndex == -1) |
|
462 | if (firstIndex == -1) | |
487 | return; |
|
463 | return; | |
488 |
|
464 | |||
489 | int maxCount = 0; |
|
465 | int maxCount = 0; | |
490 | for(int i = 0; i < sets.count(); i++) |
|
466 | for(int i = 0; i < sets.count(); i++) | |
491 | if (sets.at(i)->count() > m_count) |
|
467 | if (sets.at(i)->count() > m_count) | |
492 | maxCount = sets.at(i)->count(); |
|
468 | maxCount = sets.at(i)->count(); | |
493 |
|
469 | |||
494 | if (m_count != -1 && m_count < maxCount) |
|
470 | if (m_count != -1 && m_count < maxCount) | |
495 | m_count = maxCount; |
|
471 | m_count = maxCount; | |
496 |
|
472 | |||
497 | m_lastBarSetSection += sets.count(); |
|
473 | m_lastBarSetSection += sets.count(); | |
498 |
|
474 | |||
499 | blockModelSignals(); |
|
475 | blockModelSignals(); | |
500 | int modelCapacity = m_orientation == Qt::Vertical ? m_model->rowCount() - m_first : m_model->columnCount() - m_first; |
|
476 | int modelCapacity = m_orientation == Qt::Vertical ? m_model->rowCount() - m_first : m_model->columnCount() - m_first; | |
501 | if (maxCount > modelCapacity) { |
|
477 | if (maxCount > modelCapacity) { | |
502 | if (m_orientation == Qt::Vertical) |
|
478 | if (m_orientation == Qt::Vertical) | |
503 | m_model->insertRows(m_model->rowCount(), maxCount - modelCapacity); |
|
479 | m_model->insertRows(m_model->rowCount(), maxCount - modelCapacity); | |
504 | else |
|
480 | else | |
505 | m_model->insertColumns(m_model->columnCount(), maxCount - modelCapacity); |
|
481 | m_model->insertColumns(m_model->columnCount(), maxCount - modelCapacity); | |
506 | } |
|
482 | } | |
507 |
|
483 | |||
508 | if (m_orientation == Qt::Vertical) |
|
484 | if (m_orientation == Qt::Vertical) | |
509 | m_model->insertColumns(firstIndex + m_firstBarSetSection, sets.count()); |
|
485 | m_model->insertColumns(firstIndex + m_firstBarSetSection, sets.count()); | |
510 | else |
|
486 | else | |
511 | m_model->insertRows(firstIndex + m_firstBarSetSection, sets.count()); |
|
487 | m_model->insertRows(firstIndex + m_firstBarSetSection, sets.count()); | |
512 |
|
488 | |||
513 |
|
489 | |||
514 | for(int i = firstIndex + m_firstBarSetSection; i < firstIndex + m_firstBarSetSection + sets.count(); i++) { |
|
490 | for(int i = firstIndex + m_firstBarSetSection; i < firstIndex + m_firstBarSetSection + sets.count(); i++) { | |
515 | m_model->setHeaderData(i, m_orientation == Qt::Vertical ? Qt::Horizontal : Qt::Vertical, sets.at(i - firstIndex - m_firstBarSetSection)->label()); |
|
491 | m_model->setHeaderData(i, m_orientation == Qt::Vertical ? Qt::Horizontal : Qt::Vertical, sets.at(i - firstIndex - m_firstBarSetSection)->label()); | |
516 | for (int j = 0; j < sets.at(i - firstIndex - m_firstBarSetSection)->count(); j++) |
|
492 | for (int j = 0; j < sets.at(i - firstIndex - m_firstBarSetSection)->count(); j++) | |
517 | m_model->setData(barModelIndex(i, j), sets.at(i - firstIndex - m_firstBarSetSection)->at(j).y()); |
|
493 | m_model->setData(barModelIndex(i, j), sets.at(i - firstIndex - m_firstBarSetSection)->at(j).y()); | |
518 | } |
|
494 | } | |
519 | blockModelSignals(false); |
|
495 | blockModelSignals(false); | |
520 | initializeBarFromModel(); |
|
496 | initializeBarFromModel(); | |
521 | } |
|
497 | } | |
522 |
|
498 | |||
523 | void QBarModelMapperPrivate::barSetsRemoved(QList<QBarSet*> sets) |
|
499 | void QBarModelMapperPrivate::barSetsRemoved(QList<QBarSet*> sets) | |
524 | { |
|
500 | { | |
525 | if (m_seriesSignalsBlock) |
|
501 | if (m_seriesSignalsBlock) | |
526 | return; |
|
502 | return; | |
527 |
|
503 | |||
528 | if (sets.count() == 0) |
|
504 | if (sets.count() == 0) | |
529 | return; |
|
505 | return; | |
530 |
|
506 | |||
531 | int firstIndex = m_barSets.indexOf(sets.at(0)); |
|
507 | int firstIndex = m_barSets.indexOf(sets.at(0)); | |
532 | if (firstIndex == -1) |
|
508 | if (firstIndex == -1) | |
533 | return; |
|
509 | return; | |
534 |
|
510 | |||
535 | m_lastBarSetSection -= sets.count(); |
|
511 | m_lastBarSetSection -= sets.count(); | |
536 |
|
512 | |||
537 | for (int i = firstIndex + sets.count() - 1; i >= firstIndex; i--) |
|
513 | for (int i = firstIndex + sets.count() - 1; i >= firstIndex; i--) | |
538 | m_barSets.removeAt(i); |
|
514 | m_barSets.removeAt(i); | |
539 |
|
515 | |||
540 | blockModelSignals(); |
|
516 | blockModelSignals(); | |
541 | if (m_orientation == Qt::Vertical) |
|
517 | if (m_orientation == Qt::Vertical) | |
542 | m_model->removeColumns(firstIndex + m_firstBarSetSection, sets.count()); |
|
518 | m_model->removeColumns(firstIndex + m_firstBarSetSection, sets.count()); | |
543 | else |
|
519 | else | |
544 | m_model->removeRows(firstIndex + m_firstBarSetSection, sets.count()); |
|
520 | m_model->removeRows(firstIndex + m_firstBarSetSection, sets.count()); | |
545 | blockModelSignals(false); |
|
521 | blockModelSignals(false); | |
546 | initializeBarFromModel(); |
|
522 | initializeBarFromModel(); | |
547 | } |
|
523 | } | |
548 |
|
524 | |||
549 | void QBarModelMapperPrivate::valuesAdded(int index, int count) |
|
525 | void QBarModelMapperPrivate::valuesAdded(int index, int count) | |
550 | { |
|
526 | { | |
551 | if (m_seriesSignalsBlock) |
|
527 | if (m_seriesSignalsBlock) | |
552 | return; |
|
528 | return; | |
553 |
|
529 | |||
554 | if (m_count != -1) |
|
530 | if (m_count != -1) | |
555 | m_count += count; |
|
531 | m_count += count; | |
556 |
|
532 | |||
557 | int barSetIndex = m_barSets.indexOf(qobject_cast<QBarSet *>(QObject::sender())); |
|
533 | int barSetIndex = m_barSets.indexOf(qobject_cast<QBarSet *>(QObject::sender())); | |
558 |
|
534 | |||
559 | blockModelSignals(); |
|
535 | blockModelSignals(); | |
560 | if (m_orientation == Qt::Vertical) |
|
536 | if (m_orientation == Qt::Vertical) | |
561 | m_model->insertRows(index + m_first, count); |
|
537 | m_model->insertRows(index + m_first, count); | |
562 | else |
|
538 | else | |
563 | m_model->insertColumns(index + m_first, count); |
|
539 | m_model->insertColumns(index + m_first, count); | |
564 |
|
540 | |||
565 | for (int j = index; j < index + count; j++) |
|
541 | for (int j = index; j < index + count; j++) | |
566 | m_model->setData(barModelIndex(barSetIndex + m_firstBarSetSection, j), m_barSets.at(barSetIndex)->at(j).y()); |
|
542 | m_model->setData(barModelIndex(barSetIndex + m_firstBarSetSection, j), m_barSets.at(barSetIndex)->at(j).y()); | |
567 |
|
543 | |||
568 | blockModelSignals(false); |
|
544 | blockModelSignals(false); | |
569 | initializeBarFromModel(); |
|
545 | initializeBarFromModel(); | |
570 | } |
|
546 | } | |
571 |
|
547 | |||
572 | void QBarModelMapperPrivate::valuesRemoved(int index, int count) |
|
548 | void QBarModelMapperPrivate::valuesRemoved(int index, int count) | |
573 | { |
|
549 | { | |
574 | if (m_seriesSignalsBlock) |
|
550 | if (m_seriesSignalsBlock) | |
575 | return; |
|
551 | return; | |
576 |
|
552 | |||
577 | if (m_count != -1) |
|
553 | if (m_count != -1) | |
578 | m_count -= count; |
|
554 | m_count -= count; | |
579 |
|
555 | |||
580 | blockModelSignals(); |
|
556 | blockModelSignals(); | |
581 | if (m_orientation == Qt::Vertical) |
|
557 | if (m_orientation == Qt::Vertical) | |
582 | m_model->removeRows(index + m_first, count); |
|
558 | m_model->removeRows(index + m_first, count); | |
583 | else |
|
559 | else | |
584 | m_model->removeColumns(index + m_first, count); |
|
560 | m_model->removeColumns(index + m_first, count); | |
585 |
|
561 | |||
586 | blockModelSignals(false); |
|
562 | blockModelSignals(false); | |
587 | initializeBarFromModel(); |
|
563 | initializeBarFromModel(); | |
588 | } |
|
564 | } | |
589 |
|
565 | |||
590 | void QBarModelMapperPrivate::barLabelChanged() |
|
566 | void QBarModelMapperPrivate::barLabelChanged() | |
591 | { |
|
567 | { | |
592 | if (m_seriesSignalsBlock) |
|
568 | if (m_seriesSignalsBlock) | |
593 | return; |
|
569 | return; | |
594 |
|
570 | |||
595 | int barSetIndex = m_barSets.indexOf(qobject_cast<QBarSet *>(QObject::sender())); |
|
571 | int barSetIndex = m_barSets.indexOf(qobject_cast<QBarSet *>(QObject::sender())); | |
596 |
|
572 | |||
597 | blockModelSignals(); |
|
573 | blockModelSignals(); | |
598 | m_model->setHeaderData(barSetIndex + m_firstBarSetSection, m_orientation == Qt::Vertical ? Qt::Horizontal : Qt::Vertical, m_barSets.at(barSetIndex)->label()); |
|
574 | m_model->setHeaderData(barSetIndex + m_firstBarSetSection, m_orientation == Qt::Vertical ? Qt::Horizontal : Qt::Vertical, m_barSets.at(barSetIndex)->label()); | |
599 | blockModelSignals(false); |
|
575 | blockModelSignals(false); | |
600 | initializeBarFromModel(); |
|
576 | initializeBarFromModel(); | |
601 | } |
|
577 | } | |
602 |
|
578 | |||
603 | void QBarModelMapperPrivate::barValueChanged(int index) |
|
579 | void QBarModelMapperPrivate::barValueChanged(int index) | |
604 | { |
|
580 | { | |
605 | if (m_seriesSignalsBlock) |
|
581 | if (m_seriesSignalsBlock) | |
606 | return; |
|
582 | return; | |
607 |
|
583 | |||
608 | int barSetIndex = m_barSets.indexOf(qobject_cast<QBarSet *>(QObject::sender())); |
|
584 | int barSetIndex = m_barSets.indexOf(qobject_cast<QBarSet *>(QObject::sender())); | |
609 |
|
585 | |||
610 | blockModelSignals(); |
|
586 | blockModelSignals(); | |
611 | m_model->setData(barModelIndex(barSetIndex + m_firstBarSetSection, index), m_barSets.at(barSetIndex)->at(index).y()); |
|
587 | m_model->setData(barModelIndex(barSetIndex + m_firstBarSetSection, index), m_barSets.at(barSetIndex)->at(index).y()); | |
612 | blockModelSignals(false); |
|
588 | blockModelSignals(false); | |
613 | initializeBarFromModel(); |
|
589 | initializeBarFromModel(); | |
614 | } |
|
590 | } | |
615 |
|
591 | |||
616 | void QBarModelMapperPrivate::initializeBarFromModel() |
|
592 | void QBarModelMapperPrivate::initializeBarFromModel() | |
617 | { |
|
593 | { | |
618 | if (m_model == 0 || m_series == 0) |
|
594 | if (m_model == 0 || m_series == 0) | |
619 | return; |
|
595 | return; | |
620 |
|
596 | |||
621 | blockSeriesSignals(); |
|
597 | blockSeriesSignals(); | |
622 | // clear current content |
|
598 | // clear current content | |
623 | m_series->clear(); |
|
599 | m_series->clear(); | |
624 | m_barSets.clear(); |
|
600 | m_barSets.clear(); | |
625 |
|
601 | |||
626 | // create the initial bar sets |
|
602 | // create the initial bar sets | |
627 | for (int i = m_firstBarSetSection; i <= m_lastBarSetSection; i++) { |
|
603 | for (int i = m_firstBarSetSection; i <= m_lastBarSetSection; i++) { | |
628 | int posInBar = 0; |
|
604 | int posInBar = 0; | |
629 | QModelIndex barIndex = barModelIndex(i, posInBar); |
|
605 | QModelIndex barIndex = barModelIndex(i, posInBar); | |
630 | // check if there is such model index |
|
606 | // check if there is such model index | |
631 | if (barIndex.isValid()) { |
|
607 | if (barIndex.isValid()) { | |
632 | QBarSet *barSet = new QBarSet(m_model->headerData(i, m_orientation == Qt::Vertical ? Qt::Horizontal : Qt::Vertical).toString()); |
|
608 | QBarSet *barSet = new QBarSet(m_model->headerData(i, m_orientation == Qt::Vertical ? Qt::Horizontal : Qt::Vertical).toString()); | |
633 | while (barIndex.isValid()) { |
|
609 | while (barIndex.isValid()) { | |
634 | barSet->append(m_model->data(barIndex, Qt::DisplayRole).toDouble()); |
|
610 | barSet->append(m_model->data(barIndex, Qt::DisplayRole).toDouble()); | |
635 | posInBar++; |
|
611 | posInBar++; | |
636 | barIndex = barModelIndex(i, posInBar); |
|
612 | barIndex = barModelIndex(i, posInBar); | |
637 | } |
|
613 | } | |
638 | connect(barSet, SIGNAL(valuesAdded(int, int)), this, SLOT(valuesAdded(int, int))); |
|
614 | connect(barSet, SIGNAL(valuesAdded(int, int)), this, SLOT(valuesAdded(int, int))); | |
639 | connect(barSet, SIGNAL(valuesRemoved(int, int)), this, SLOT(valuesRemoved(int, int))); |
|
615 | connect(barSet, SIGNAL(valuesRemoved(int, int)), this, SLOT(valuesRemoved(int, int))); | |
640 | connect(barSet, SIGNAL(valueChanged(int)), this, SLOT(barValueChanged(int))); |
|
616 | connect(barSet, SIGNAL(valueChanged(int)), this, SLOT(barValueChanged(int))); | |
641 | connect(barSet, SIGNAL(labelChanged()), this, SLOT(barLabelChanged())); |
|
617 | connect(barSet, SIGNAL(labelChanged()), this, SLOT(barLabelChanged())); | |
642 | m_series->append(barSet); |
|
618 | m_series->append(barSet); | |
643 | m_barSets.append(barSet); |
|
619 | m_barSets.append(barSet); | |
644 | } else { |
|
620 | } else { | |
645 | break; |
|
621 | break; | |
646 | } |
|
622 | } | |
647 | } |
|
623 | } | |
648 | blockSeriesSignals(false); |
|
624 | blockSeriesSignals(false); | |
649 | } |
|
625 | } | |
650 |
|
626 | |||
651 | #include "moc_qbarmodelmapper.cpp" |
|
627 | #include "moc_qbarmodelmapper.cpp" | |
652 | #include "moc_qbarmodelmapper_p.cpp" |
|
628 | #include "moc_qbarmodelmapper_p.cpp" | |
653 |
|
629 | |||
654 | QTCOMMERCIALCHART_END_NAMESPACE |
|
630 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,85 +1,81 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #ifndef QBARMODELMAPPER_H |
|
21 | #ifndef QBARMODELMAPPER_H | |
22 | #define QBARMODELMAPPER_H |
|
22 | #define QBARMODELMAPPER_H | |
23 |
|
23 | |||
24 | #include "qchartglobal.h" |
|
24 | #include "qchartglobal.h" | |
25 | #include <QObject> |
|
25 | #include <QObject> | |
26 |
|
26 | |||
27 | class QAbstractItemModel; |
|
27 | class QAbstractItemModel; | |
28 |
|
28 | |||
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
30 |
|
30 | |||
31 | class QBarModelMapperPrivate; |
|
31 | class QBarModelMapperPrivate; | |
32 | class QBarSeries; |
|
32 | class QBarSeries; | |
33 | class QChart; |
|
33 | class QChart; | |
34 |
|
34 | |||
35 | class QTCOMMERCIALCHART_EXPORT QBarModelMapper : public QObject |
|
35 | class QTCOMMERCIALCHART_EXPORT QBarModelMapper : public QObject | |
36 | { |
|
36 | { | |
37 | Q_OBJECT |
|
37 | Q_OBJECT | |
38 | Q_PROPERTY(QBarSeries *series READ series WRITE setSeries NOTIFY seriesReplaced) |
|
38 | Q_PROPERTY(QBarSeries *series READ series WRITE setSeries NOTIFY seriesReplaced) | |
39 | Q_PROPERTY(QAbstractItemModel *model READ model WRITE setModel NOTIFY modelReplaced) |
|
39 | Q_PROPERTY(QAbstractItemModel *model READ model WRITE setModel NOTIFY modelReplaced) | |
40 | Q_PROPERTY(int first READ first WRITE setFirst NOTIFY firstChanged) |
|
|||
41 | Q_PROPERTY(int count READ count WRITE setCount NOTIFY countChanged) |
|
|||
42 | Q_ENUMS(Qt::Orientation) |
|
40 | Q_ENUMS(Qt::Orientation) | |
43 |
|
41 | |||
44 | protected: |
|
42 | protected: | |
45 | explicit QBarModelMapper(QObject *parent = 0); |
|
43 | explicit QBarModelMapper(QObject *parent = 0); | |
46 |
|
44 | |||
47 | public: |
|
45 | public: | |
48 | QAbstractItemModel* model() const; |
|
46 | QAbstractItemModel* model() const; | |
49 | void setModel(QAbstractItemModel *model); |
|
47 | void setModel(QAbstractItemModel *model); | |
50 |
|
48 | |||
51 | QBarSeries* series() const; |
|
49 | QBarSeries* series() const; | |
52 | void setSeries(QBarSeries *series); |
|
50 | void setSeries(QBarSeries *series); | |
53 |
|
51 | |||
|
52 | void reset(); | |||
|
53 | ||||
|
54 | protected: | |||
54 | int first() const; |
|
55 | int first() const; | |
55 | void setFirst(int first); |
|
56 | void setFirst(int first); | |
56 |
|
57 | |||
57 | int count() const; |
|
58 | int count() const; | |
58 | void setCount(int count); |
|
59 | void setCount(int count); | |
59 |
|
60 | |||
60 | void reset(); |
|
|||
61 |
|
||||
62 | protected: |
|
|||
63 | int firstBarSetSection() const; |
|
61 | int firstBarSetSection() const; | |
64 | void setFirstBarSetSection(int firstBarSetSection); |
|
62 | void setFirstBarSetSection(int firstBarSetSection); | |
65 |
|
63 | |||
66 | int lastBarSetSection() const; |
|
64 | int lastBarSetSection() const; | |
67 | void setLastBarSetSection(int lastBarSetSection); |
|
65 | void setLastBarSetSection(int lastBarSetSection); | |
68 |
|
66 | |||
69 | Qt::Orientation orientation() const; |
|
67 | Qt::Orientation orientation() const; | |
70 | void setOrientation(Qt::Orientation orientation); |
|
68 | void setOrientation(Qt::Orientation orientation); | |
71 |
|
69 | |||
72 | Q_SIGNALS: |
|
70 | Q_SIGNALS: | |
73 | void seriesReplaced(); |
|
71 | void seriesReplaced(); | |
74 | void modelReplaced(); |
|
72 | void modelReplaced(); | |
75 | void firstChanged(); |
|
|||
76 | void countChanged(); |
|
|||
77 |
|
73 | |||
78 | protected: |
|
74 | protected: | |
79 | QBarModelMapperPrivate * const d_ptr; |
|
75 | QBarModelMapperPrivate * const d_ptr; | |
80 | Q_DECLARE_PRIVATE(QBarModelMapper) |
|
76 | Q_DECLARE_PRIVATE(QBarModelMapper) | |
81 | }; |
|
77 | }; | |
82 |
|
78 | |||
83 | QTCOMMERCIALCHART_END_NAMESPACE |
|
79 | QTCOMMERCIALCHART_END_NAMESPACE | |
84 |
|
80 | |||
85 | #endif // QBARMODELMAPPER_H |
|
81 | #endif // QBARMODELMAPPER_H |
@@ -1,120 +1,178 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "qhbarmodelmapper.h" |
|
21 | #include "qhbarmodelmapper.h" | |
22 |
|
22 | |||
23 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
23 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
24 |
|
24 | |||
25 | /*! |
|
25 | /*! | |
26 | \class QHBarModelMapper |
|
26 | \class QHBarModelMapper | |
27 | \brief part of QtCommercial chart API. |
|
27 | \brief part of QtCommercial chart API. | |
28 | \mainclass |
|
28 | \mainclass | |
29 |
|
29 | |||
30 | Model mappers allow you to use QAbstractItemModel derived models as a data source for a chart series. |
|
30 | Model mappers allow you to use QAbstractItemModel derived models as a data source for a chart series. | |
31 | Horizontal model mapper is used to create a connection between QBarSeries and QAbstractItemModel derived model object. |
|
31 | Horizontal model mapper is used to create a connection between QBarSeries and QAbstractItemModel derived model object. | |
32 | Model mapper maintains equal size of all the BarSets. |
|
32 | Model mapper maintains equal size of all the BarSets. | |
33 | Adding/removing value from the BarSet causes the the same change in the rest of the BarSets added to the same series. |
|
33 | Adding/removing value from the BarSet causes the the same change in the rest of the BarSets added to the same series. | |
34 | NOTE: used model has to support adding/removing rows/columns and modifying the data of the cells. |
|
34 | NOTE: used model has to support adding/removing rows/columns and modifying the data of the cells. | |
35 | */ |
|
35 | */ | |
36 | /*! |
|
36 | /*! | |
37 | \qmlclass HBarModelMapper |
|
37 | \qmlclass HBarModelMapper | |
38 | \inherits BarModelMapper |
|
38 | \inherits BarModelMapper | |
39 | \mainclass |
|
39 | \mainclass | |
40 |
|
40 | |||
41 | HBarModelMapper allows you to use your own QAbstractItemModel derived model with data in rows as a data source |
|
41 | HBarModelMapper allows you to use your own QAbstractItemModel derived model with data in rows as a data source | |
42 | for any bar series. The following QML example would create a bar series with three bar sets (assuming the model has |
|
42 | for any bar series. The following QML example would create a bar series with three bar sets (assuming the model has | |
43 | at least four rows). Each bar set would contain data starting from column 1. The name of a set would be defined |
|
43 | at least four rows). Each bar set would contain data starting from column 1. The name of a set would be defined | |
44 | by the vertical header (of the row). |
|
44 | by the vertical header (of the row). | |
45 | \code |
|
45 | \code | |
46 | BarSeries { |
|
46 | BarSeries { | |
47 | HBarModelMapper { |
|
47 | HBarModelMapper { | |
48 | model: myCustomModel |
|
48 | model: myCustomModel | |
49 | firstBarSetRow: 1 |
|
49 | firstBarSetRow: 1 | |
50 | lastBarSetRow: 3 |
|
50 | lastBarSetRow: 3 | |
51 | first: 1 |
|
51 | first: 1 | |
52 | } |
|
52 | } | |
53 | } |
|
53 | } | |
54 | \endcode |
|
54 | \endcode | |
55 | */ |
|
55 | */ | |
56 |
|
56 | |||
57 | /*! |
|
57 | /*! | |
58 | \property QHBarModelMapper::firstBarSetRow |
|
58 | \property QHBarModelMapper::firstBarSetRow | |
59 | \brief Defines which column of the model is used as the data source for the first bar set |
|
59 | \brief Defines which column of the model is used as the data source for the first bar set | |
60 |
|
60 | |||
61 | Default value is: -1 (invalid mapping) |
|
61 | Default value is: -1 (invalid mapping) | |
62 | */ |
|
62 | */ | |
63 |
|
63 | |||
64 | /*! |
|
64 | /*! | |
65 | \property QHBarModelMapper::lastBarSetRow |
|
65 | \property QHBarModelMapper::lastBarSetRow | |
66 | \brief Defines which column of the model is used as the data source for the last bar set |
|
66 | \brief Defines which column of the model is used as the data source for the last bar set | |
67 |
|
67 | |||
68 | Default value is: -1 (invalid mapping) |
|
68 | Default value is: -1 (invalid mapping) | |
69 | */ |
|
69 | */ | |
70 |
|
70 | |||
71 | /*! |
|
71 | /*! | |
|
72 | \property QHBarModelMapper::firstColumn | |||
|
73 | \brief Defines which column of the model contains the first values of the QBarSets in the series. | |||
|
74 | Minimal and default value is: 0 | |||
|
75 | */ | |||
|
76 | /*! | |||
|
77 | \qmlproperty int BarModelMapper::first | |||
|
78 | Defines which column of the model contains the first values of the QBarSets in the series. | |||
|
79 | The default value is 0. | |||
|
80 | */ | |||
|
81 | ||||
|
82 | /*! | |||
|
83 | \property QHBarModelMapper::columnCount | |||
|
84 | \brief Defines the number of rows of the model that are mapped as the data for QBarSeries | |||
|
85 | Minimal and default value is: -1 (count limited by the number of rows in the model) | |||
|
86 | */ | |||
|
87 | /*! | |||
|
88 | \qmlproperty int BarModelMapper::count | |||
|
89 | Defines the number of rows of the model that are mapped as the data for QBarSeries. The default value is | |||
|
90 | -1 (count limited by the number of rows in the model) | |||
|
91 | */ | |||
|
92 | ||||
|
93 | /*! | |||
72 | \fn void QHBarModelMapper::firstBarSetRowChanged() |
|
94 | \fn void QHBarModelMapper::firstBarSetRowChanged() | |
73 |
|
95 | |||
74 | Emitted when the firstBarSetRow has changed. |
|
96 | Emitted when the firstBarSetRow has changed. | |
75 | */ |
|
97 | */ | |
76 |
|
98 | |||
77 | /*! |
|
99 | /*! | |
78 | \fn void QHBarModelMapper::lastBarSetRowChanged() |
|
100 | \fn void QHBarModelMapper::lastBarSetRowChanged() | |
79 |
|
101 | |||
80 | Emitted when the lastBarSetRow has changed. |
|
102 | Emitted when the lastBarSetRow has changed. | |
81 | */ |
|
103 | */ | |
82 |
|
104 | |||
83 | /*! |
|
105 | /*! | |
|
106 | \fn void QHBarModelMapper::firstColumnChanged() | |||
|
107 | Emitted when the firstColumn has changed. | |||
|
108 | */ | |||
|
109 | ||||
|
110 | /*! | |||
|
111 | \fn void QHBarModelMapper::columnCountChanged() | |||
|
112 | Emitted when the columnCount has changed. | |||
|
113 | */ | |||
|
114 | ||||
|
115 | /*! | |||
84 | Constructs a mapper object which is a child of \a parent. |
|
116 | Constructs a mapper object which is a child of \a parent. | |
85 | */ |
|
117 | */ | |
86 | QHBarModelMapper::QHBarModelMapper(QObject *parent) : |
|
118 | QHBarModelMapper::QHBarModelMapper(QObject *parent) : | |
87 | QBarModelMapper(parent) |
|
119 | QBarModelMapper(parent) | |
88 | { |
|
120 | { | |
89 | QBarModelMapper::setOrientation(Qt::Horizontal); |
|
121 | QBarModelMapper::setOrientation(Qt::Horizontal); | |
90 | } |
|
122 | } | |
91 |
|
123 | |||
92 | int QHBarModelMapper::firstBarSetRow() const |
|
124 | int QHBarModelMapper::firstBarSetRow() const | |
93 | { |
|
125 | { | |
94 | return QBarModelMapper::firstBarSetSection(); |
|
126 | return QBarModelMapper::firstBarSetSection(); | |
95 | } |
|
127 | } | |
96 |
|
128 | |||
97 | void QHBarModelMapper::setFirstBarSetRow(int firstBarSetRow) |
|
129 | void QHBarModelMapper::setFirstBarSetRow(int firstBarSetRow) | |
98 | { |
|
130 | { | |
99 | if (firstBarSetRow != firstBarSetSection()) { |
|
131 | if (firstBarSetRow != firstBarSetSection()) { | |
100 |
|
|
132 | QBarModelMapper::setFirstBarSetSection(firstBarSetRow); | |
101 | emit firstBarSetRowChanged(); |
|
133 | emit firstBarSetRowChanged(); | |
102 | } |
|
134 | } | |
103 | } |
|
135 | } | |
104 |
|
136 | |||
105 | int QHBarModelMapper::lastBarSetRow() const |
|
137 | int QHBarModelMapper::lastBarSetRow() const | |
106 | { |
|
138 | { | |
107 | return QBarModelMapper::lastBarSetSection(); |
|
139 | return QBarModelMapper::lastBarSetSection(); | |
108 | } |
|
140 | } | |
109 |
|
141 | |||
110 | void QHBarModelMapper::setLastBarSetRow(int lastBarSetRow) |
|
142 | void QHBarModelMapper::setLastBarSetRow(int lastBarSetRow) | |
111 | { |
|
143 | { | |
112 | if (lastBarSetRow != lastBarSetSection()) { |
|
144 | if (lastBarSetRow != lastBarSetSection()) { | |
113 |
|
|
145 | QBarModelMapper::setLastBarSetSection(lastBarSetRow); | |
114 | emit lastBarSetRowChanged(); |
|
146 | emit lastBarSetRowChanged(); | |
115 | } |
|
147 | } | |
116 | } |
|
148 | } | |
117 |
|
149 | |||
|
150 | int QHBarModelMapper::firstColumn() const | |||
|
151 | { | |||
|
152 | return QBarModelMapper::first(); | |||
|
153 | } | |||
|
154 | ||||
|
155 | void QHBarModelMapper::setFirstColumn(int firstColumn) | |||
|
156 | { | |||
|
157 | if (firstColumn != first()) { | |||
|
158 | QBarModelMapper::setFirst(firstColumn); | |||
|
159 | emit firstColumnChanged(); | |||
|
160 | } | |||
|
161 | } | |||
|
162 | ||||
|
163 | int QHBarModelMapper::columnCount() const | |||
|
164 | { | |||
|
165 | return QBarModelMapper::count(); | |||
|
166 | } | |||
|
167 | ||||
|
168 | void QHBarModelMapper::setColumnCount(int columnCount) | |||
|
169 | { | |||
|
170 | if (columnCount != count()) { | |||
|
171 | QBarModelMapper::setCount(columnCount); | |||
|
172 | emit firstColumnChanged(); | |||
|
173 | } | |||
|
174 | } | |||
|
175 | ||||
118 | #include "moc_qhbarmodelmapper.cpp" |
|
176 | #include "moc_qhbarmodelmapper.cpp" | |
119 |
|
177 | |||
120 | QTCOMMERCIALCHART_END_NAMESPACE |
|
178 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,50 +1,60 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #ifndef QHBARMODELMAPPER_H |
|
21 | #ifndef QHBARMODELMAPPER_H | |
22 | #define QHBARMODELMAPPER_H |
|
22 | #define QHBARMODELMAPPER_H | |
23 |
|
23 | |||
24 | #include <QBarModelMapper> |
|
24 | #include <QBarModelMapper> | |
25 |
|
25 | |||
26 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
26 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
27 |
|
27 | |||
28 | class QTCOMMERCIALCHART_EXPORT QHBarModelMapper : public QBarModelMapper |
|
28 | class QTCOMMERCIALCHART_EXPORT QHBarModelMapper : public QBarModelMapper | |
29 | { |
|
29 | { | |
30 | Q_OBJECT |
|
30 | Q_OBJECT | |
31 | Q_PROPERTY(int firstBarSetRow READ firstBarSetRow WRITE setFirstBarSetRow NOTIFY firstBarSetRowChanged) |
|
31 | Q_PROPERTY(int firstBarSetRow READ firstBarSetRow WRITE setFirstBarSetRow NOTIFY firstBarSetRowChanged) | |
32 | Q_PROPERTY(int lastBarSetRow READ lastBarSetRow WRITE setLastBarSetRow NOTIFY lastBarSetRowChanged) |
|
32 | Q_PROPERTY(int lastBarSetRow READ lastBarSetRow WRITE setLastBarSetRow NOTIFY lastBarSetRowChanged) | |
|
33 | Q_PROPERTY(int firstColumn READ firstColumn WRITE setFirstColumn NOTIFY firstColumnChanged) | |||
|
34 | Q_PROPERTY(int columnCount READ columnCount WRITE setColumnCount NOTIFY columnCountChanged) | |||
33 |
|
35 | |||
34 | public: |
|
36 | public: | |
35 | explicit QHBarModelMapper(QObject *parent = 0); |
|
37 | explicit QHBarModelMapper(QObject *parent = 0); | |
36 |
|
38 | |||
37 | int firstBarSetRow() const; |
|
39 | int firstBarSetRow() const; | |
38 | void setFirstBarSetRow(int firstBarSetRow); |
|
40 | void setFirstBarSetRow(int firstBarSetRow); | |
39 |
|
41 | |||
40 | int lastBarSetRow() const; |
|
42 | int lastBarSetRow() const; | |
41 | void setLastBarSetRow(int lastBarSetRow); |
|
43 | void setLastBarSetRow(int lastBarSetRow); | |
42 |
|
44 | |||
|
45 | int firstColumn() const; | |||
|
46 | void setFirstColumn(int firstColumn); | |||
|
47 | ||||
|
48 | int columnCount() const; | |||
|
49 | void setColumnCount(int columnCount); | |||
|
50 | ||||
43 | Q_SIGNALS: |
|
51 | Q_SIGNALS: | |
44 | void firstBarSetRowChanged(); |
|
52 | void firstBarSetRowChanged(); | |
45 | void lastBarSetRowChanged(); |
|
53 | void lastBarSetRowChanged(); | |
|
54 | void firstColumnChanged(); | |||
|
55 | void columnCountChanged(); | |||
46 | }; |
|
56 | }; | |
47 |
|
57 | |||
48 | QTCOMMERCIALCHART_END_NAMESPACE |
|
58 | QTCOMMERCIALCHART_END_NAMESPACE | |
49 |
|
59 | |||
50 | #endif // QHBARMODELMAPPER_H |
|
60 | #endif // QHBARMODELMAPPER_H |
@@ -1,126 +1,184 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "qvbarmodelmapper.h" |
|
21 | #include "qvbarmodelmapper.h" | |
22 |
|
22 | |||
23 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
23 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
24 |
|
24 | |||
25 | /*! |
|
25 | /*! | |
26 | \class QVBarModelMapper |
|
26 | \class QVBarModelMapper | |
27 | \brief part of QtCommercial chart API. |
|
27 | \brief part of QtCommercial chart API. | |
28 | \mainclass |
|
28 | \mainclass | |
29 |
|
29 | |||
30 | Model mappers allow you to use QAbstractItemModel derived models as a data source for a chart series. |
|
30 | Model mappers allow you to use QAbstractItemModel derived models as a data source for a chart series. | |
31 | Vertical model mapper is used to create a connection between QBarSeries and QAbstractItemModel derived model object. |
|
31 | Vertical model mapper is used to create a connection between QBarSeries and QAbstractItemModel derived model object. | |
32 | Model mapper maintains equal size of all the BarSets. |
|
32 | Model mapper maintains equal size of all the BarSets. | |
33 | Adding/removing value from the BarSet causes the the same change in the rest of the BarSets added to the same series. |
|
33 | Adding/removing value from the BarSet causes the the same change in the rest of the BarSets added to the same series. | |
34 | NOTE: used model has to support adding/removing rows/columns and modifying the data of the cells. |
|
34 | NOTE: used model has to support adding/removing rows/columns and modifying the data of the cells. | |
35 | */ |
|
35 | */ | |
36 | /*! |
|
36 | /*! | |
37 | \qmlclass VBarModelMapper |
|
37 | \qmlclass VBarModelMapper | |
38 | \inherits BarModelMapper |
|
38 | \inherits BarModelMapper | |
39 | \mainclass |
|
39 | \mainclass | |
40 |
|
40 | |||
41 | VBarModelMapper allows you to use your own QAbstractItemModel derived model with data in columns as a data source |
|
41 | VBarModelMapper allows you to use your own QAbstractItemModel derived model with data in columns as a data source | |
42 | for any bar series. The following QML example would create a bar series with three bar sets (assuming the model has |
|
42 | for any bar series. The following QML example would create a bar series with three bar sets (assuming the model has | |
43 | at least four columns). Each bar set would contain data starting from row 1. The name of a set would be defined |
|
43 | at least four columns). Each bar set would contain data starting from row 1. The name of a set would be defined | |
44 | by the horizontal header (of the column). |
|
44 | by the horizontal header (of the column). | |
45 | \code |
|
45 | \code | |
46 | GroupedBarSeries { |
|
46 | GroupedBarSeries { | |
47 | VBarModelMapper { |
|
47 | VBarModelMapper { | |
48 | model: myCustomModel |
|
48 | model: myCustomModel | |
49 | firstBarSetColumn: 1 |
|
49 | firstBarSetColumn: 1 | |
50 | lastBarSetColumn: 3 |
|
50 | lastBarSetColumn: 3 | |
51 | first: 1 |
|
51 | first: 1 | |
52 | } |
|
52 | } | |
53 | } |
|
53 | } | |
54 | \endcode |
|
54 | \endcode | |
55 | */ |
|
55 | */ | |
56 |
|
56 | |||
57 | /*! |
|
57 | /*! | |
58 | \property QVBarModelMapper::firstBarSetColumn |
|
58 | \property QVBarModelMapper::firstBarSetColumn | |
59 | \brief Defines which column of the model is used as the data source for the first bar set |
|
59 | \brief Defines which column of the model is used as the data source for the first bar set | |
60 | Default value is: -1 (invalid mapping) |
|
60 | Default value is: -1 (invalid mapping) | |
61 | */ |
|
61 | */ | |
62 | /*! |
|
62 | /*! | |
63 | \qmlproperty int VBarModelMapper::firstBarSetColumn |
|
63 | \qmlproperty int VBarModelMapper::firstBarSetColumn | |
64 | Defines which column of the model is used as the data source for the first bar set. Default value |
|
64 | Defines which column of the model is used as the data source for the first bar set. Default value | |
65 | is: -1 (invalid mapping). |
|
65 | is: -1 (invalid mapping). | |
66 | */ |
|
66 | */ | |
67 |
|
67 | |||
68 | /*! |
|
68 | /*! | |
69 | \property QVBarModelMapper::lastBarSetColumn |
|
69 | \property QVBarModelMapper::lastBarSetColumn | |
70 | \brief Defines which column of the model is used as the data source for the last bar set |
|
70 | \brief Defines which column of the model is used as the data source for the last bar set | |
71 | Default value is: -1 (invalid mapping) |
|
71 | Default value is: -1 (invalid mapping) | |
72 | */ |
|
72 | */ | |
73 | /*! |
|
73 | /*! | |
74 | \qmlproperty int VBarModelMapper::lastBarSetColumn |
|
74 | \qmlproperty int VBarModelMapper::lastBarSetColumn | |
75 | Defines which column of the model is used as the data source for the last bar set. Default |
|
75 | Defines which column of the model is used as the data source for the last bar set. Default | |
76 | value is: -1 (invalid mapping). |
|
76 | value is: -1 (invalid mapping). | |
77 | */ |
|
77 | */ | |
78 |
|
78 | |||
79 | /*! |
|
79 | /*! | |
|
80 | \property QVBarModelMapper::firstRow | |||
|
81 | \brief Defines which row of the model contains the first values of the QBarSets in the series. | |||
|
82 | Minimal and default value is: 0 | |||
|
83 | */ | |||
|
84 | /*! | |||
|
85 | \qmlproperty int BarModelMapper::first | |||
|
86 | Defines which row of the model contains the first values of the QBarSets in the series. | |||
|
87 | The default value is 0. | |||
|
88 | */ | |||
|
89 | ||||
|
90 | /*! | |||
|
91 | \property QVBarModelMapper::rowCount | |||
|
92 | \brief Defines the number of rows of the model that are mapped as the data for QBarSeries | |||
|
93 | Minimal and default value is: -1 (count limited by the number of rows in the model) | |||
|
94 | */ | |||
|
95 | /*! | |||
|
96 | \qmlproperty int BarModelMapper::count | |||
|
97 | Defines the number of rows of the model that are mapped as the data for QBarSeries. The default value is | |||
|
98 | -1 (count limited by the number of rows in the model) | |||
|
99 | */ | |||
|
100 | ||||
|
101 | /*! | |||
80 | \fn void QVBarModelMapper::firstBarSetColumnChanged() |
|
102 | \fn void QVBarModelMapper::firstBarSetColumnChanged() | |
81 | Emitted when the firstBarSetColumn has changed. |
|
103 | Emitted when the firstBarSetColumn has changed. | |
82 | */ |
|
104 | */ | |
83 |
|
105 | |||
84 | /*! |
|
106 | /*! | |
85 | \fn void QVBarModelMapper::lastBarSetColumnChanged() |
|
107 | \fn void QVBarModelMapper::lastBarSetColumnChanged() | |
86 | Emitted when the lastBarSetColumn has changed. |
|
108 | Emitted when the lastBarSetColumn has changed. | |
87 | */ |
|
109 | */ | |
88 |
|
110 | |||
89 | /*! |
|
111 | /*! | |
|
112 | \fn void QVBarModelMapper::firstRowChanged() | |||
|
113 | Emitted when the firstRow has changed. | |||
|
114 | */ | |||
|
115 | ||||
|
116 | /*! | |||
|
117 | \fn void QVBarModelMapper::rowCountChanged() | |||
|
118 | Emitted when the rowCount has changed. | |||
|
119 | */ | |||
|
120 | ||||
|
121 | /*! | |||
90 | Constructs a mapper object which is a child of \a parent. |
|
122 | Constructs a mapper object which is a child of \a parent. | |
91 | */ |
|
123 | */ | |
92 | QVBarModelMapper::QVBarModelMapper(QObject *parent) : |
|
124 | QVBarModelMapper::QVBarModelMapper(QObject *parent) : | |
93 | QBarModelMapper(parent) |
|
125 | QBarModelMapper(parent) | |
94 | { |
|
126 | { | |
95 | QBarModelMapper::setOrientation(Qt::Vertical); |
|
127 | QBarModelMapper::setOrientation(Qt::Vertical); | |
96 | } |
|
128 | } | |
97 |
|
129 | |||
98 | int QVBarModelMapper::firstBarSetColumn() const |
|
130 | int QVBarModelMapper::firstBarSetColumn() const | |
99 | { |
|
131 | { | |
100 | return QBarModelMapper::firstBarSetSection(); |
|
132 | return QBarModelMapper::firstBarSetSection(); | |
101 | } |
|
133 | } | |
102 |
|
134 | |||
103 | void QVBarModelMapper::setFirstBarSetColumn(int firstBarSetColumn) |
|
135 | void QVBarModelMapper::setFirstBarSetColumn(int firstBarSetColumn) | |
104 | { |
|
136 | { | |
105 | if (firstBarSetColumn != firstBarSetSection()) { |
|
137 | if (firstBarSetColumn != firstBarSetSection()) { | |
106 |
|
|
138 | QBarModelMapper::setFirstBarSetSection(firstBarSetColumn); | |
107 | emit firstBarSetColumnChanged(); |
|
139 | emit firstBarSetColumnChanged(); | |
108 | } |
|
140 | } | |
109 | } |
|
141 | } | |
110 |
|
142 | |||
111 | int QVBarModelMapper::lastBarSetColumn() const |
|
143 | int QVBarModelMapper::lastBarSetColumn() const | |
112 | { |
|
144 | { | |
113 | return QBarModelMapper::lastBarSetSection(); |
|
145 | return QBarModelMapper::lastBarSetSection(); | |
114 | } |
|
146 | } | |
115 |
|
147 | |||
116 | void QVBarModelMapper::setLastBarSetColumn(int lastBarSetColumn) |
|
148 | void QVBarModelMapper::setLastBarSetColumn(int lastBarSetColumn) | |
117 | { |
|
149 | { | |
118 | if (lastBarSetColumn != lastBarSetSection()) { |
|
150 | if (lastBarSetColumn != lastBarSetSection()) { | |
119 |
|
|
151 | QBarModelMapper::setLastBarSetSection(lastBarSetColumn); | |
120 | emit lastBarSetColumnChanged(); |
|
152 | emit lastBarSetColumnChanged(); | |
121 | } |
|
153 | } | |
122 | } |
|
154 | } | |
123 |
|
155 | |||
|
156 | int QVBarModelMapper::firstRow() const | |||
|
157 | { | |||
|
158 | return QBarModelMapper::first(); | |||
|
159 | } | |||
|
160 | ||||
|
161 | void QVBarModelMapper::setFirstRow(int firstRow) | |||
|
162 | { | |||
|
163 | if (firstRow != first()) { | |||
|
164 | QBarModelMapper::setFirst(firstRow); | |||
|
165 | emit firstRowChanged(); | |||
|
166 | } | |||
|
167 | } | |||
|
168 | ||||
|
169 | int QVBarModelMapper::rowCount() const | |||
|
170 | { | |||
|
171 | return QBarModelMapper::count(); | |||
|
172 | } | |||
|
173 | ||||
|
174 | void QVBarModelMapper::setRowCount(int rowCount) | |||
|
175 | { | |||
|
176 | if (rowCount != count()) { | |||
|
177 | QBarModelMapper::setCount(rowCount); | |||
|
178 | emit firstRowChanged(); | |||
|
179 | } | |||
|
180 | } | |||
|
181 | ||||
124 | #include "moc_qvbarmodelmapper.cpp" |
|
182 | #include "moc_qvbarmodelmapper.cpp" | |
125 |
|
183 | |||
126 | QTCOMMERCIALCHART_END_NAMESPACE |
|
184 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,50 +1,60 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #ifndef QVBARMODELMAPPER_H |
|
21 | #ifndef QVBARMODELMAPPER_H | |
22 | #define QVBARMODELMAPPER_H |
|
22 | #define QVBARMODELMAPPER_H | |
23 |
|
23 | |||
24 | #include <QBarModelMapper> |
|
24 | #include <QBarModelMapper> | |
25 |
|
25 | |||
26 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
26 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
27 |
|
27 | |||
28 | class QTCOMMERCIALCHART_EXPORT QVBarModelMapper : public QBarModelMapper |
|
28 | class QTCOMMERCIALCHART_EXPORT QVBarModelMapper : public QBarModelMapper | |
29 | { |
|
29 | { | |
30 | Q_OBJECT |
|
30 | Q_OBJECT | |
31 | Q_PROPERTY(int firstBarSetColumn READ firstBarSetColumn WRITE setFirstBarSetColumn NOTIFY firstBarSetColumnChanged) |
|
31 | Q_PROPERTY(int firstBarSetColumn READ firstBarSetColumn WRITE setFirstBarSetColumn NOTIFY firstBarSetColumnChanged) | |
32 | Q_PROPERTY(int lastBarSetColumn READ lastBarSetColumn WRITE setLastBarSetColumn NOTIFY lastBarSetColumnChanged) |
|
32 | Q_PROPERTY(int lastBarSetColumn READ lastBarSetColumn WRITE setLastBarSetColumn NOTIFY lastBarSetColumnChanged) | |
|
33 | Q_PROPERTY(int firstRow READ firstRow WRITE setFirstRow NOTIFY firstRowChanged) | |||
|
34 | Q_PROPERTY(int rowCount READ rowCount WRITE setRowCount NOTIFY rowCountChanged) | |||
33 |
|
35 | |||
34 | public: |
|
36 | public: | |
35 | explicit QVBarModelMapper(QObject *parent = 0); |
|
37 | explicit QVBarModelMapper(QObject *parent = 0); | |
36 |
|
38 | |||
37 | int firstBarSetColumn() const; |
|
39 | int firstBarSetColumn() const; | |
38 | void setFirstBarSetColumn(int firstBarSetColumn); |
|
40 | void setFirstBarSetColumn(int firstBarSetColumn); | |
39 |
|
41 | |||
40 | int lastBarSetColumn() const; |
|
42 | int lastBarSetColumn() const; | |
41 | void setLastBarSetColumn(int lastBarSetColumn); |
|
43 | void setLastBarSetColumn(int lastBarSetColumn); | |
42 |
|
44 | |||
|
45 | int firstRow() const; | |||
|
46 | void setFirstRow(int firstRow); | |||
|
47 | ||||
|
48 | int rowCount() const; | |||
|
49 | void setRowCount(int rowCount); | |||
|
50 | ||||
43 | Q_SIGNALS: |
|
51 | Q_SIGNALS: | |
44 | void firstBarSetColumnChanged(); |
|
52 | void firstBarSetColumnChanged(); | |
45 | void lastBarSetColumnChanged(); |
|
53 | void lastBarSetColumnChanged(); | |
|
54 | void firstRowChanged(); | |||
|
55 | void rowCountChanged(); | |||
46 | }; |
|
56 | }; | |
47 |
|
57 | |||
48 | QTCOMMERCIALCHART_END_NAMESPACE |
|
58 | QTCOMMERCIALCHART_END_NAMESPACE | |
49 |
|
59 | |||
50 | #endif // QVBARMODELMAPPER_H |
|
60 | #endif // QVBARMODELMAPPER_H |
@@ -1,614 +1,614 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include <QtCore/QString> |
|
21 | #include <QtCore/QString> | |
22 | #include <QtTest/QtTest> |
|
22 | #include <QtTest/QtTest> | |
23 |
|
23 | |||
24 | #include <qchart.h> |
|
24 | #include <qchart.h> | |
25 | #include <qchartview.h> |
|
25 | #include <qchartview.h> | |
26 | #include <qgroupedbarseries.h> |
|
26 | #include <qgroupedbarseries.h> | |
27 | #include <qbarset.h> |
|
27 | #include <qbarset.h> | |
28 | #include <qvbarmodelmapper.h> |
|
28 | #include <qvbarmodelmapper.h> | |
29 | #include <qhbarmodelmapper.h> |
|
29 | #include <qhbarmodelmapper.h> | |
30 | #include <QStandardItemModel> |
|
30 | #include <QStandardItemModel> | |
31 |
|
31 | |||
32 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
32 | QTCOMMERCIALCHART_USE_NAMESPACE | |
33 |
|
33 | |||
34 | class tst_qbarmodelmapper : public QObject |
|
34 | class tst_qbarmodelmapper : public QObject | |
35 | { |
|
35 | { | |
36 | Q_OBJECT |
|
36 | Q_OBJECT | |
37 |
|
37 | |||
38 | public: |
|
38 | public: | |
39 | tst_qbarmodelmapper(); |
|
39 | tst_qbarmodelmapper(); | |
40 | void createVerticalMapper(); |
|
40 | void createVerticalMapper(); | |
41 | void createHorizontalMapper(); |
|
41 | void createHorizontalMapper(); | |
42 |
|
42 | |||
43 | private Q_SLOTS: |
|
43 | private Q_SLOTS: | |
44 | void initTestCase(); |
|
44 | void initTestCase(); | |
45 | void cleanupTestCase(); |
|
45 | void cleanupTestCase(); | |
46 | void init(); |
|
46 | void init(); | |
47 | void cleanup(); |
|
47 | void cleanup(); | |
48 | void verticalMapper_data(); |
|
48 | void verticalMapper_data(); | |
49 | void verticalMapper(); |
|
49 | void verticalMapper(); | |
50 | void verticalMapperCustomMapping_data(); |
|
50 | void verticalMapperCustomMapping_data(); | |
51 | void verticalMapperCustomMapping(); |
|
51 | void verticalMapperCustomMapping(); | |
52 | void horizontalMapper_data(); |
|
52 | void horizontalMapper_data(); | |
53 | void horizontalMapper(); |
|
53 | void horizontalMapper(); | |
54 | void horizontalMapperCustomMapping_data(); |
|
54 | void horizontalMapperCustomMapping_data(); | |
55 | void horizontalMapperCustomMapping(); |
|
55 | void horizontalMapperCustomMapping(); | |
56 | void seriesUpdated(); |
|
56 | void seriesUpdated(); | |
57 | void verticalModelInsertRows(); |
|
57 | void verticalModelInsertRows(); | |
58 | void verticalModelRemoveRows(); |
|
58 | void verticalModelRemoveRows(); | |
59 | void verticalModelInsertColumns(); |
|
59 | void verticalModelInsertColumns(); | |
60 | void verticalModelRemoveColumns(); |
|
60 | void verticalModelRemoveColumns(); | |
61 | void horizontalModelInsertRows(); |
|
61 | void horizontalModelInsertRows(); | |
62 | void horizontalModelRemoveRows(); |
|
62 | void horizontalModelRemoveRows(); | |
63 | void horizontalModelInsertColumns(); |
|
63 | void horizontalModelInsertColumns(); | |
64 | void horizontalModelRemoveColumns(); |
|
64 | void horizontalModelRemoveColumns(); | |
65 | void modelUpdateCell(); |
|
65 | void modelUpdateCell(); | |
66 |
|
66 | |||
67 | private: |
|
67 | private: | |
68 | QStandardItemModel *m_model; |
|
68 | QStandardItemModel *m_model; | |
69 | int m_modelRowCount; |
|
69 | int m_modelRowCount; | |
70 | int m_modelColumnCount; |
|
70 | int m_modelColumnCount; | |
71 |
|
71 | |||
72 | QVBarModelMapper *m_vMapper; |
|
72 | QVBarModelMapper *m_vMapper; | |
73 | QHBarModelMapper *m_hMapper; |
|
73 | QHBarModelMapper *m_hMapper; | |
74 |
|
74 | |||
75 | QGroupedBarSeries *m_series; |
|
75 | QGroupedBarSeries *m_series; | |
76 | QChart *m_chart; |
|
76 | QChart *m_chart; | |
77 | }; |
|
77 | }; | |
78 |
|
78 | |||
79 | tst_qbarmodelmapper::tst_qbarmodelmapper(): |
|
79 | tst_qbarmodelmapper::tst_qbarmodelmapper(): | |
80 | m_model(0), |
|
80 | m_model(0), | |
81 | m_modelRowCount(10), |
|
81 | m_modelRowCount(10), | |
82 | m_modelColumnCount(8), |
|
82 | m_modelColumnCount(8), | |
83 | m_vMapper(0), |
|
83 | m_vMapper(0), | |
84 | m_hMapper(0), |
|
84 | m_hMapper(0), | |
85 | m_series(0), |
|
85 | m_series(0), | |
86 | m_chart(0) |
|
86 | m_chart(0) | |
87 | { |
|
87 | { | |
88 | } |
|
88 | } | |
89 |
|
89 | |||
90 | void tst_qbarmodelmapper::createVerticalMapper() |
|
90 | void tst_qbarmodelmapper::createVerticalMapper() | |
91 | { |
|
91 | { | |
92 | m_vMapper = new QVBarModelMapper; |
|
92 | m_vMapper = new QVBarModelMapper; | |
93 | QVERIFY(m_vMapper->model() == 0); |
|
93 | QVERIFY(m_vMapper->model() == 0); | |
94 | m_vMapper->setFirstBarSetColumn(0); |
|
94 | m_vMapper->setFirstBarSetColumn(0); | |
95 | m_vMapper->setLastBarSetColumn(4); |
|
95 | m_vMapper->setLastBarSetColumn(4); | |
96 | m_vMapper->setModel(m_model); |
|
96 | m_vMapper->setModel(m_model); | |
97 | m_vMapper->setSeries(m_series); |
|
97 | m_vMapper->setSeries(m_series); | |
98 | } |
|
98 | } | |
99 |
|
99 | |||
100 | void tst_qbarmodelmapper::createHorizontalMapper() |
|
100 | void tst_qbarmodelmapper::createHorizontalMapper() | |
101 | { |
|
101 | { | |
102 | m_hMapper = new QHBarModelMapper; |
|
102 | m_hMapper = new QHBarModelMapper; | |
103 | QVERIFY(m_hMapper->model() == 0); |
|
103 | QVERIFY(m_hMapper->model() == 0); | |
104 | m_hMapper->setFirstBarSetRow(0); |
|
104 | m_hMapper->setFirstBarSetRow(0); | |
105 | m_hMapper->setLastBarSetRow(4); |
|
105 | m_hMapper->setLastBarSetRow(4); | |
106 | m_hMapper->setModel(m_model); |
|
106 | m_hMapper->setModel(m_model); | |
107 | m_hMapper->setSeries(m_series); |
|
107 | m_hMapper->setSeries(m_series); | |
108 | } |
|
108 | } | |
109 |
|
109 | |||
110 | void tst_qbarmodelmapper::init() |
|
110 | void tst_qbarmodelmapper::init() | |
111 | { |
|
111 | { | |
112 | m_series = new QGroupedBarSeries; |
|
112 | m_series = new QGroupedBarSeries; | |
113 | m_chart->addSeries(m_series); |
|
113 | m_chart->addSeries(m_series); | |
114 |
|
114 | |||
115 | m_model = new QStandardItemModel(m_modelRowCount, m_modelColumnCount, this); |
|
115 | m_model = new QStandardItemModel(m_modelRowCount, m_modelColumnCount, this); | |
116 | for (int row = 0; row < m_modelRowCount; ++row) { |
|
116 | for (int row = 0; row < m_modelRowCount; ++row) { | |
117 | for (int column = 0; column < m_modelColumnCount; column++) { |
|
117 | for (int column = 0; column < m_modelColumnCount; column++) { | |
118 | m_model->setData(m_model->index(row, column), row * column); |
|
118 | m_model->setData(m_model->index(row, column), row * column); | |
119 | } |
|
119 | } | |
120 | } |
|
120 | } | |
121 | } |
|
121 | } | |
122 |
|
122 | |||
123 | void tst_qbarmodelmapper::cleanup() |
|
123 | void tst_qbarmodelmapper::cleanup() | |
124 | { |
|
124 | { | |
125 | m_chart->removeSeries(m_series); |
|
125 | m_chart->removeSeries(m_series); | |
126 | delete m_series; |
|
126 | delete m_series; | |
127 | m_series = 0; |
|
127 | m_series = 0; | |
128 |
|
128 | |||
129 | m_model->clear(); |
|
129 | m_model->clear(); | |
130 | m_model->deleteLater(); |
|
130 | m_model->deleteLater(); | |
131 | m_model = 0; |
|
131 | m_model = 0; | |
132 |
|
132 | |||
133 | if (m_vMapper) { |
|
133 | if (m_vMapper) { | |
134 | m_vMapper->deleteLater(); |
|
134 | m_vMapper->deleteLater(); | |
135 | m_vMapper = 0; |
|
135 | m_vMapper = 0; | |
136 | } |
|
136 | } | |
137 |
|
137 | |||
138 | if (m_hMapper) { |
|
138 | if (m_hMapper) { | |
139 | m_hMapper->deleteLater(); |
|
139 | m_hMapper->deleteLater(); | |
140 | m_hMapper = 0; |
|
140 | m_hMapper = 0; | |
141 | } |
|
141 | } | |
142 | } |
|
142 | } | |
143 |
|
143 | |||
144 | void tst_qbarmodelmapper::initTestCase() |
|
144 | void tst_qbarmodelmapper::initTestCase() | |
145 | { |
|
145 | { | |
146 | m_chart = new QChart; |
|
146 | m_chart = new QChart; | |
147 | QChartView *chartView = new QChartView(m_chart); |
|
147 | QChartView *chartView = new QChartView(m_chart); | |
148 | chartView->show(); |
|
148 | chartView->show(); | |
149 | } |
|
149 | } | |
150 |
|
150 | |||
151 | void tst_qbarmodelmapper::cleanupTestCase() |
|
151 | void tst_qbarmodelmapper::cleanupTestCase() | |
152 | { |
|
152 | { | |
153 | } |
|
153 | } | |
154 |
|
154 | |||
155 | void tst_qbarmodelmapper::verticalMapper_data() |
|
155 | void tst_qbarmodelmapper::verticalMapper_data() | |
156 | { |
|
156 | { | |
157 | QTest::addColumn<int>("firstBarSetColumn"); |
|
157 | QTest::addColumn<int>("firstBarSetColumn"); | |
158 | QTest::addColumn<int>("lastBarSetColumn"); |
|
158 | QTest::addColumn<int>("lastBarSetColumn"); | |
159 | QTest::addColumn<int>("expectedBarSetCount"); |
|
159 | QTest::addColumn<int>("expectedBarSetCount"); | |
160 | QTest::newRow("lastBarSetColumn greater than firstBarSetColumn") << 0 << 1 << 2; |
|
160 | QTest::newRow("lastBarSetColumn greater than firstBarSetColumn") << 0 << 1 << 2; | |
161 | QTest::newRow("lastBarSetColumn equal to firstBarSetColumn") << 1 << 1 << 1; |
|
161 | QTest::newRow("lastBarSetColumn equal to firstBarSetColumn") << 1 << 1 << 1; | |
162 | QTest::newRow("lastBarSetColumn lesser than firstBarSetColumn") << 1 << 0 << 0; |
|
162 | QTest::newRow("lastBarSetColumn lesser than firstBarSetColumn") << 1 << 0 << 0; | |
163 | QTest::newRow("invalid firstBarSetColumn and correct lastBarSetColumn") << -3 << 1 << 0; |
|
163 | QTest::newRow("invalid firstBarSetColumn and correct lastBarSetColumn") << -3 << 1 << 0; | |
164 | QTest::newRow("firstBarSetColumn beyond the size of model and correct lastBarSetColumn") << m_modelColumnCount << 1 << 0; |
|
164 | QTest::newRow("firstBarSetColumn beyond the size of model and correct lastBarSetColumn") << m_modelColumnCount << 1 << 0; | |
165 | QTest::newRow("firstBarSetColumn beyond the size of model and invalid lastBarSetColumn") << m_modelColumnCount << -1 << 0; |
|
165 | QTest::newRow("firstBarSetColumn beyond the size of model and invalid lastBarSetColumn") << m_modelColumnCount << -1 << 0; | |
166 | } |
|
166 | } | |
167 |
|
167 | |||
168 | void tst_qbarmodelmapper::verticalMapper() |
|
168 | void tst_qbarmodelmapper::verticalMapper() | |
169 | { |
|
169 | { | |
170 | QFETCH(int, firstBarSetColumn); |
|
170 | QFETCH(int, firstBarSetColumn); | |
171 | QFETCH(int, lastBarSetColumn); |
|
171 | QFETCH(int, lastBarSetColumn); | |
172 | QFETCH(int, expectedBarSetCount); |
|
172 | QFETCH(int, expectedBarSetCount); | |
173 |
|
173 | |||
174 | m_series = new QGroupedBarSeries; |
|
174 | m_series = new QGroupedBarSeries; | |
175 |
|
175 | |||
176 | QVBarModelMapper *mapper = new QVBarModelMapper; |
|
176 | QVBarModelMapper *mapper = new QVBarModelMapper; | |
177 | mapper->setFirstBarSetColumn(firstBarSetColumn); |
|
177 | mapper->setFirstBarSetColumn(firstBarSetColumn); | |
178 | mapper->setLastBarSetColumn(lastBarSetColumn); |
|
178 | mapper->setLastBarSetColumn(lastBarSetColumn); | |
179 | mapper->setModel(m_model); |
|
179 | mapper->setModel(m_model); | |
180 | mapper->setSeries(m_series); |
|
180 | mapper->setSeries(m_series); | |
181 |
|
181 | |||
182 | m_chart->addSeries(m_series); |
|
182 | m_chart->addSeries(m_series); | |
183 |
|
183 | |||
184 | QCOMPARE(m_series->count(), expectedBarSetCount); |
|
184 | QCOMPARE(m_series->count(), expectedBarSetCount); | |
185 | QCOMPARE(mapper->firstBarSetColumn(), qMax(-1, firstBarSetColumn)); |
|
185 | QCOMPARE(mapper->firstBarSetColumn(), qMax(-1, firstBarSetColumn)); | |
186 | QCOMPARE(mapper->lastBarSetColumn(), qMax(-1, lastBarSetColumn)); |
|
186 | QCOMPARE(mapper->lastBarSetColumn(), qMax(-1, lastBarSetColumn)); | |
187 |
|
187 | |||
188 | delete mapper; |
|
188 | delete mapper; | |
189 | mapper = 0; |
|
189 | mapper = 0; | |
190 | } |
|
190 | } | |
191 |
|
191 | |||
192 | void tst_qbarmodelmapper::verticalMapperCustomMapping_data() |
|
192 | void tst_qbarmodelmapper::verticalMapperCustomMapping_data() | |
193 | { |
|
193 | { | |
194 | QTest::addColumn<int>("first"); |
|
194 | QTest::addColumn<int>("first"); | |
195 | QTest::addColumn<int>("countLimit"); |
|
195 | QTest::addColumn<int>("countLimit"); | |
196 | QTest::addColumn<int>("expectedBarSetCount"); |
|
196 | QTest::addColumn<int>("expectedBarSetCount"); | |
197 | QTest::addColumn<int>("expectedCount"); |
|
197 | QTest::addColumn<int>("expectedCount"); | |
198 | QTest::newRow("first: 0, unlimited count") << 0 << -1 << 2 << m_modelRowCount; |
|
198 | QTest::newRow("first: 0, unlimited count") << 0 << -1 << 2 << m_modelRowCount; | |
199 | QTest::newRow("first: 3, unlimited count") << 3 << -1 << 2 << m_modelRowCount - 3; |
|
199 | QTest::newRow("first: 3, unlimited count") << 3 << -1 << 2 << m_modelRowCount - 3; | |
200 | QTest::newRow("first: 0, count: 5") << 0 << 5 << 2 << qMin(5, m_modelRowCount); |
|
200 | QTest::newRow("first: 0, count: 5") << 0 << 5 << 2 << qMin(5, m_modelRowCount); | |
201 | QTest::newRow("first: 3, count: 5") << 3 << 5 << 2 << qMin(5, m_modelRowCount - 3); |
|
201 | QTest::newRow("first: 3, count: 5") << 3 << 5 << 2 << qMin(5, m_modelRowCount - 3); | |
202 | QTest::newRow("first: +1 greater then the number of rows in the model, unlimited count") << m_modelRowCount + 1 << -1 << 0 << 0; |
|
202 | QTest::newRow("first: +1 greater then the number of rows in the model, unlimited count") << m_modelRowCount + 1 << -1 << 0 << 0; | |
203 | QTest::newRow("first: +1 greater then the number of rows in the model, count: 5") << m_modelRowCount + 1 << 5 << 0 << 0; |
|
203 | QTest::newRow("first: +1 greater then the number of rows in the model, count: 5") << m_modelRowCount + 1 << 5 << 0 << 0; | |
204 | QTest::newRow("first: 0, count: +3 greater than the number of rows in the model (should limit to the size of model)") << 0 << m_modelRowCount + 3 << 2 << m_modelRowCount; |
|
204 | QTest::newRow("first: 0, count: +3 greater than the number of rows in the model (should limit to the size of model)") << 0 << m_modelRowCount + 3 << 2 << m_modelRowCount; | |
205 | QTest::newRow("first: -3(invalid - should default to 0), unlimited count") << -3 << -1 << 2 << m_modelRowCount; |
|
205 | QTest::newRow("first: -3(invalid - should default to 0), unlimited count") << -3 << -1 << 2 << m_modelRowCount; | |
206 | QTest::newRow("first: 0, count: -3 (invalid - shlould default to -1)") << 0 << -3 << 2 << m_modelRowCount; |
|
206 | QTest::newRow("first: 0, count: -3 (invalid - shlould default to -1)") << 0 << -3 << 2 << m_modelRowCount; | |
207 | QTest::newRow("first: -3(invalid - should default to 0), count: -3 (invalid - shlould default to -1)") << -3 << -3 << 2 << m_modelRowCount; |
|
207 | QTest::newRow("first: -3(invalid - should default to 0), count: -3 (invalid - shlould default to -1)") << -3 << -3 << 2 << m_modelRowCount; | |
208 | } |
|
208 | } | |
209 |
|
209 | |||
210 | void tst_qbarmodelmapper::verticalMapperCustomMapping() |
|
210 | void tst_qbarmodelmapper::verticalMapperCustomMapping() | |
211 | { |
|
211 | { | |
212 | QFETCH(int, first); |
|
212 | QFETCH(int, first); | |
213 | QFETCH(int, countLimit); |
|
213 | QFETCH(int, countLimit); | |
214 | QFETCH(int, expectedBarSetCount); |
|
214 | QFETCH(int, expectedBarSetCount); | |
215 | QFETCH(int, expectedCount); |
|
215 | QFETCH(int, expectedCount); | |
216 |
|
216 | |||
217 | m_series = new QGroupedBarSeries; |
|
217 | m_series = new QGroupedBarSeries; | |
218 |
|
218 | |||
219 | QCOMPARE(m_series->count(), 0); |
|
219 | QCOMPARE(m_series->count(), 0); | |
220 |
|
220 | |||
221 | QVBarModelMapper *mapper = new QVBarModelMapper; |
|
221 | QVBarModelMapper *mapper = new QVBarModelMapper; | |
222 | mapper->setFirstBarSetColumn(0); |
|
222 | mapper->setFirstBarSetColumn(0); | |
223 | mapper->setLastBarSetColumn(1); |
|
223 | mapper->setLastBarSetColumn(1); | |
224 | mapper->setModel(m_model); |
|
224 | mapper->setModel(m_model); | |
225 | mapper->setSeries(m_series); |
|
225 | mapper->setSeries(m_series); | |
226 | mapper->setFirst(first); |
|
226 | mapper->setFirstRow(first); | |
227 | mapper->setCount(countLimit); |
|
227 | mapper->setRowCount(countLimit); | |
228 | m_chart->addSeries(m_series); |
|
228 | m_chart->addSeries(m_series); | |
229 |
|
229 | |||
230 | QCOMPARE(m_series->count(), expectedBarSetCount); |
|
230 | QCOMPARE(m_series->count(), expectedBarSetCount); | |
231 |
|
231 | |||
232 | if (expectedBarSetCount > 0) |
|
232 | if (expectedBarSetCount > 0) | |
233 | QCOMPARE(m_series->barSets().first()->count(), expectedCount); |
|
233 | QCOMPARE(m_series->barSets().first()->count(), expectedCount); | |
234 |
|
234 | |||
235 | // change values column mapping to invalid |
|
235 | // change values column mapping to invalid | |
236 | mapper->setFirstBarSetColumn(-1); |
|
236 | mapper->setFirstBarSetColumn(-1); | |
237 | mapper->setLastBarSetColumn(1); |
|
237 | mapper->setLastBarSetColumn(1); | |
238 |
|
238 | |||
239 | QCOMPARE(m_series->count(), 0); |
|
239 | QCOMPARE(m_series->count(), 0); | |
240 |
|
240 | |||
241 | delete mapper; |
|
241 | delete mapper; | |
242 | mapper = 0; |
|
242 | mapper = 0; | |
243 | } |
|
243 | } | |
244 |
|
244 | |||
245 | void tst_qbarmodelmapper::horizontalMapper_data() |
|
245 | void tst_qbarmodelmapper::horizontalMapper_data() | |
246 | { |
|
246 | { | |
247 | QTest::addColumn<int>("firstBarSetRow"); |
|
247 | QTest::addColumn<int>("firstBarSetRow"); | |
248 | QTest::addColumn<int>("lastBarSetRow"); |
|
248 | QTest::addColumn<int>("lastBarSetRow"); | |
249 | QTest::addColumn<int>("expectedBarSetCount"); |
|
249 | QTest::addColumn<int>("expectedBarSetCount"); | |
250 | QTest::newRow("lastBarSetRow greater than firstBarSetRow") << 0 << 1 << 2; |
|
250 | QTest::newRow("lastBarSetRow greater than firstBarSetRow") << 0 << 1 << 2; | |
251 | QTest::newRow("lastBarSetRow equal to firstBarSetRow") << 1 << 1 << 1; |
|
251 | QTest::newRow("lastBarSetRow equal to firstBarSetRow") << 1 << 1 << 1; | |
252 | QTest::newRow("lastBarSetRow lesser than firstBarSetRow") << 1 << 0 << 0; |
|
252 | QTest::newRow("lastBarSetRow lesser than firstBarSetRow") << 1 << 0 << 0; | |
253 | QTest::newRow("invalid firstBarSetRow and correct lastBarSetRow") << -3 << 1 << 0; |
|
253 | QTest::newRow("invalid firstBarSetRow and correct lastBarSetRow") << -3 << 1 << 0; | |
254 | QTest::newRow("firstBarSetRow beyond the size of model and correct lastBarSetRow") << m_modelRowCount << 1 << 0; |
|
254 | QTest::newRow("firstBarSetRow beyond the size of model and correct lastBarSetRow") << m_modelRowCount << 1 << 0; | |
255 | QTest::newRow("firstBarSetRow beyond the size of model and invalid lastBarSetRow") << m_modelRowCount << -1 << 0; |
|
255 | QTest::newRow("firstBarSetRow beyond the size of model and invalid lastBarSetRow") << m_modelRowCount << -1 << 0; | |
256 | } |
|
256 | } | |
257 |
|
257 | |||
258 | void tst_qbarmodelmapper::horizontalMapper() |
|
258 | void tst_qbarmodelmapper::horizontalMapper() | |
259 | { |
|
259 | { | |
260 | QFETCH(int, firstBarSetRow); |
|
260 | QFETCH(int, firstBarSetRow); | |
261 | QFETCH(int, lastBarSetRow); |
|
261 | QFETCH(int, lastBarSetRow); | |
262 | QFETCH(int, expectedBarSetCount); |
|
262 | QFETCH(int, expectedBarSetCount); | |
263 |
|
263 | |||
264 | m_series = new QGroupedBarSeries; |
|
264 | m_series = new QGroupedBarSeries; | |
265 |
|
265 | |||
266 | QHBarModelMapper *mapper = new QHBarModelMapper; |
|
266 | QHBarModelMapper *mapper = new QHBarModelMapper; | |
267 | mapper->setFirstBarSetRow(firstBarSetRow); |
|
267 | mapper->setFirstBarSetRow(firstBarSetRow); | |
268 | mapper->setLastBarSetRow(lastBarSetRow); |
|
268 | mapper->setLastBarSetRow(lastBarSetRow); | |
269 | mapper->setModel(m_model); |
|
269 | mapper->setModel(m_model); | |
270 | mapper->setSeries(m_series); |
|
270 | mapper->setSeries(m_series); | |
271 |
|
271 | |||
272 | m_chart->addSeries(m_series); |
|
272 | m_chart->addSeries(m_series); | |
273 |
|
273 | |||
274 | QCOMPARE(m_series->count(), expectedBarSetCount); |
|
274 | QCOMPARE(m_series->count(), expectedBarSetCount); | |
275 | QCOMPARE(mapper->firstBarSetRow(), qMax(-1, firstBarSetRow)); |
|
275 | QCOMPARE(mapper->firstBarSetRow(), qMax(-1, firstBarSetRow)); | |
276 | QCOMPARE(mapper->lastBarSetRow(), qMax(-1, lastBarSetRow)); |
|
276 | QCOMPARE(mapper->lastBarSetRow(), qMax(-1, lastBarSetRow)); | |
277 |
|
277 | |||
278 | delete mapper; |
|
278 | delete mapper; | |
279 | mapper = 0; |
|
279 | mapper = 0; | |
280 | } |
|
280 | } | |
281 |
|
281 | |||
282 | void tst_qbarmodelmapper::horizontalMapperCustomMapping_data() |
|
282 | void tst_qbarmodelmapper::horizontalMapperCustomMapping_data() | |
283 | { |
|
283 | { | |
284 | QTest::addColumn<int>("first"); |
|
284 | QTest::addColumn<int>("first"); | |
285 | QTest::addColumn<int>("countLimit"); |
|
285 | QTest::addColumn<int>("countLimit"); | |
286 | QTest::addColumn<int>("expectedBarSetCount"); |
|
286 | QTest::addColumn<int>("expectedBarSetCount"); | |
287 | QTest::addColumn<int>("expectedCount"); |
|
287 | QTest::addColumn<int>("expectedCount"); | |
288 | QTest::newRow("first: 0, unlimited count") << 0 << -1 << 2 << m_modelColumnCount; |
|
288 | QTest::newRow("first: 0, unlimited count") << 0 << -1 << 2 << m_modelColumnCount; | |
289 | QTest::newRow("first: 3, unlimited count") << 3 << -1 << 2 << m_modelColumnCount - 3; |
|
289 | QTest::newRow("first: 3, unlimited count") << 3 << -1 << 2 << m_modelColumnCount - 3; | |
290 | QTest::newRow("first: 0, count: 5") << 0 << 5 << 2 << qMin(5, m_modelColumnCount); |
|
290 | QTest::newRow("first: 0, count: 5") << 0 << 5 << 2 << qMin(5, m_modelColumnCount); | |
291 | QTest::newRow("first: 3, count: 5") << 3 << 5 << 2 << qMin(5, m_modelColumnCount - 3); |
|
291 | QTest::newRow("first: 3, count: 5") << 3 << 5 << 2 << qMin(5, m_modelColumnCount - 3); | |
292 | QTest::newRow("first: +1 greater then the number of rows in the model, unlimited count") << m_modelColumnCount + 1 << -1 << 0 << 0; |
|
292 | QTest::newRow("first: +1 greater then the number of rows in the model, unlimited count") << m_modelColumnCount + 1 << -1 << 0 << 0; | |
293 | QTest::newRow("first: +1 greater then the number of rows in the model, count: 5") << m_modelColumnCount + 1 << 5 << 0 << 0; |
|
293 | QTest::newRow("first: +1 greater then the number of rows in the model, count: 5") << m_modelColumnCount + 1 << 5 << 0 << 0; | |
294 | QTest::newRow("first: 0, count: +3 greater than the number of rows in the model (should limit to the size of model)") << 0 << m_modelColumnCount + 3 << 2 << m_modelColumnCount; |
|
294 | QTest::newRow("first: 0, count: +3 greater than the number of rows in the model (should limit to the size of model)") << 0 << m_modelColumnCount + 3 << 2 << m_modelColumnCount; | |
295 | QTest::newRow("first: -3(invalid - should default to 0), unlimited count") << -3 << -1 << 2 << m_modelColumnCount; |
|
295 | QTest::newRow("first: -3(invalid - should default to 0), unlimited count") << -3 << -1 << 2 << m_modelColumnCount; | |
296 | QTest::newRow("first: 0, count: -3 (invalid - shlould default to -1)") << 0 << -3 << 2 << m_modelColumnCount; |
|
296 | QTest::newRow("first: 0, count: -3 (invalid - shlould default to -1)") << 0 << -3 << 2 << m_modelColumnCount; | |
297 | QTest::newRow("first: -3(invalid - should default to 0), count: -3 (invalid - shlould default to -1)") << -3 << -3 << 2 << m_modelColumnCount; |
|
297 | QTest::newRow("first: -3(invalid - should default to 0), count: -3 (invalid - shlould default to -1)") << -3 << -3 << 2 << m_modelColumnCount; | |
298 | } |
|
298 | } | |
299 |
|
299 | |||
300 | void tst_qbarmodelmapper::horizontalMapperCustomMapping() |
|
300 | void tst_qbarmodelmapper::horizontalMapperCustomMapping() | |
301 | { |
|
301 | { | |
302 | QFETCH(int, first); |
|
302 | QFETCH(int, first); | |
303 | QFETCH(int, countLimit); |
|
303 | QFETCH(int, countLimit); | |
304 | QFETCH(int, expectedBarSetCount); |
|
304 | QFETCH(int, expectedBarSetCount); | |
305 | QFETCH(int, expectedCount); |
|
305 | QFETCH(int, expectedCount); | |
306 |
|
306 | |||
307 | m_series = new QGroupedBarSeries; |
|
307 | m_series = new QGroupedBarSeries; | |
308 |
|
308 | |||
309 | QCOMPARE(m_series->count(), 0); |
|
309 | QCOMPARE(m_series->count(), 0); | |
310 |
|
310 | |||
311 | QHBarModelMapper *mapper = new QHBarModelMapper; |
|
311 | QHBarModelMapper *mapper = new QHBarModelMapper; | |
312 | mapper->setFirstBarSetRow(0); |
|
312 | mapper->setFirstBarSetRow(0); | |
313 | mapper->setLastBarSetRow(1); |
|
313 | mapper->setLastBarSetRow(1); | |
314 | mapper->setModel(m_model); |
|
314 | mapper->setModel(m_model); | |
315 | mapper->setSeries(m_series); |
|
315 | mapper->setSeries(m_series); | |
316 | mapper->setFirst(first); |
|
316 | mapper->setFirstColumn(first); | |
317 | mapper->setCount(countLimit); |
|
317 | mapper->setColumnCount(countLimit); | |
318 | m_chart->addSeries(m_series); |
|
318 | m_chart->addSeries(m_series); | |
319 |
|
319 | |||
320 | QCOMPARE(m_series->count(), expectedBarSetCount); |
|
320 | QCOMPARE(m_series->count(), expectedBarSetCount); | |
321 |
|
321 | |||
322 | if (expectedBarSetCount > 0) |
|
322 | if (expectedBarSetCount > 0) | |
323 | QCOMPARE(m_series->barSets().first()->count(), expectedCount); |
|
323 | QCOMPARE(m_series->barSets().first()->count(), expectedCount); | |
324 |
|
324 | |||
325 | // change values column mapping to invalid |
|
325 | // change values column mapping to invalid | |
326 | mapper->setFirstBarSetRow(-1); |
|
326 | mapper->setFirstBarSetRow(-1); | |
327 | mapper->setLastBarSetRow(1); |
|
327 | mapper->setLastBarSetRow(1); | |
328 |
|
328 | |||
329 | QCOMPARE(m_series->count(), 0); |
|
329 | QCOMPARE(m_series->count(), 0); | |
330 |
|
330 | |||
331 | delete mapper; |
|
331 | delete mapper; | |
332 | mapper = 0; |
|
332 | mapper = 0; | |
333 | } |
|
333 | } | |
334 |
|
334 | |||
335 | void tst_qbarmodelmapper::seriesUpdated() |
|
335 | void tst_qbarmodelmapper::seriesUpdated() | |
336 | { |
|
336 | { | |
337 | // setup the mapper |
|
337 | // setup the mapper | |
338 | createVerticalMapper(); |
|
338 | createVerticalMapper(); | |
339 | QCOMPARE(m_series->barSets().first()->count(), m_modelRowCount); |
|
339 | QCOMPARE(m_series->barSets().first()->count(), m_modelRowCount); | |
340 |
QCOMPARE(m_vMapper-> |
|
340 | QCOMPARE(m_vMapper->rowCount(), -1); | |
341 |
|
341 | |||
342 | m_series->barSets().first()->append(123); |
|
342 | m_series->barSets().first()->append(123); | |
343 | QCOMPARE(m_model->rowCount(), m_modelRowCount + 1); |
|
343 | QCOMPARE(m_model->rowCount(), m_modelRowCount + 1); | |
344 |
QCOMPARE(m_vMapper-> |
|
344 | QCOMPARE(m_vMapper->rowCount(), -1); // the value should not change as it indicates 'all' items there are in the model | |
345 |
|
345 | |||
346 | m_series->barSets().last()->remove(0, m_modelRowCount); |
|
346 | m_series->barSets().last()->remove(0, m_modelRowCount); | |
347 | QCOMPARE(m_model->rowCount(), 1); |
|
347 | QCOMPARE(m_model->rowCount(), 1); | |
348 |
QCOMPARE(m_vMapper-> |
|
348 | QCOMPARE(m_vMapper->rowCount(), -1); // the value should not change as it indicates 'all' items there are in the model | |
349 |
|
349 | |||
350 | m_series->barSets().first()->replace(0, 444.0); |
|
350 | m_series->barSets().first()->replace(0, 444.0); | |
351 | QCOMPARE(m_model->data(m_model->index(0, 0)).toReal(), 444.0); |
|
351 | QCOMPARE(m_model->data(m_model->index(0, 0)).toReal(), 444.0); | |
352 |
|
352 | |||
353 | m_series->barSets().first()->setLabel("Hello"); |
|
353 | m_series->barSets().first()->setLabel("Hello"); | |
354 | QCOMPARE(m_model->headerData(0, Qt::Horizontal).toString(), QString("Hello")); |
|
354 | QCOMPARE(m_model->headerData(0, Qt::Horizontal).toString(), QString("Hello")); | |
355 |
|
355 | |||
356 | QList<qreal> newValues; |
|
356 | QList<qreal> newValues; | |
357 | newValues << 15 << 27 << 35 << 49; |
|
357 | newValues << 15 << 27 << 35 << 49; | |
358 | m_series->barSets().first()->append(newValues); |
|
358 | m_series->barSets().first()->append(newValues); | |
359 | QCOMPARE(m_model->rowCount(), 1 + newValues.count()); |
|
359 | QCOMPARE(m_model->rowCount(), 1 + newValues.count()); | |
360 |
|
360 | |||
361 | QList<QBarSet* > newBarSets; |
|
361 | QList<QBarSet* > newBarSets; | |
362 | QBarSet* newBarSet_1 = new QBarSet("New_1"); |
|
362 | QBarSet* newBarSet_1 = new QBarSet("New_1"); | |
363 | newBarSet_1->append(101); |
|
363 | newBarSet_1->append(101); | |
364 | newBarSet_1->append(102); |
|
364 | newBarSet_1->append(102); | |
365 | newBarSet_1->append(103); |
|
365 | newBarSet_1->append(103); | |
366 | newBarSets.append(newBarSet_1); |
|
366 | newBarSets.append(newBarSet_1); | |
367 |
|
367 | |||
368 | QBarSet* newBarSet_2 = new QBarSet("New_1"); |
|
368 | QBarSet* newBarSet_2 = new QBarSet("New_1"); | |
369 | newBarSet_2->append(201); |
|
369 | newBarSet_2->append(201); | |
370 | newBarSet_2->append(202); |
|
370 | newBarSet_2->append(202); | |
371 | newBarSet_2->append(203); |
|
371 | newBarSet_2->append(203); | |
372 | newBarSets.append(newBarSet_2); |
|
372 | newBarSets.append(newBarSet_2); | |
373 |
|
373 | |||
374 | m_series->append(newBarSets); |
|
374 | m_series->append(newBarSets); | |
375 | QCOMPARE(m_model->columnCount(), m_modelColumnCount + newBarSets.count()); |
|
375 | QCOMPARE(m_model->columnCount(), m_modelColumnCount + newBarSets.count()); | |
376 | } |
|
376 | } | |
377 |
|
377 | |||
378 | void tst_qbarmodelmapper::verticalModelInsertRows() |
|
378 | void tst_qbarmodelmapper::verticalModelInsertRows() | |
379 | { |
|
379 | { | |
380 | // setup the mapper |
|
380 | // setup the mapper | |
381 | createVerticalMapper(); |
|
381 | createVerticalMapper(); | |
382 | QCOMPARE(m_series->count(), m_vMapper->lastBarSetColumn() - m_vMapper->firstBarSetColumn() + 1); |
|
382 | QCOMPARE(m_series->count(), m_vMapper->lastBarSetColumn() - m_vMapper->firstBarSetColumn() + 1); | |
383 | QCOMPARE(m_series->barSets().first()->count(), m_modelRowCount); |
|
383 | QCOMPARE(m_series->barSets().first()->count(), m_modelRowCount); | |
384 | QVERIFY(m_vMapper->model() != 0); |
|
384 | QVERIFY(m_vMapper->model() != 0); | |
385 |
|
385 | |||
386 | int insertCount = 4; |
|
386 | int insertCount = 4; | |
387 | m_model->insertRows(3, insertCount); |
|
387 | m_model->insertRows(3, insertCount); | |
388 | QCOMPARE(m_series->count(), m_vMapper->lastBarSetColumn() - m_vMapper->firstBarSetColumn() + 1); |
|
388 | QCOMPARE(m_series->count(), m_vMapper->lastBarSetColumn() - m_vMapper->firstBarSetColumn() + 1); | |
389 | QCOMPARE(m_series->barSets().first()->count(), m_modelRowCount + insertCount); |
|
389 | QCOMPARE(m_series->barSets().first()->count(), m_modelRowCount + insertCount); | |
390 |
|
390 | |||
391 | int first = 3; |
|
391 | int first = 3; | |
392 | m_vMapper->setFirst(3); |
|
392 | m_vMapper->setFirstRow(3); | |
393 | QCOMPARE(m_series->count(), m_vMapper->lastBarSetColumn() - m_vMapper->firstBarSetColumn() + 1); |
|
393 | QCOMPARE(m_series->count(), m_vMapper->lastBarSetColumn() - m_vMapper->firstBarSetColumn() + 1); | |
394 | QCOMPARE(m_series->barSets().first()->count(), m_modelRowCount + insertCount - first); |
|
394 | QCOMPARE(m_series->barSets().first()->count(), m_modelRowCount + insertCount - first); | |
395 |
|
395 | |||
396 | m_model->insertRows(3, insertCount); |
|
396 | m_model->insertRows(3, insertCount); | |
397 | QCOMPARE(m_series->count(), m_vMapper->lastBarSetColumn() - m_vMapper->firstBarSetColumn() + 1); |
|
397 | QCOMPARE(m_series->count(), m_vMapper->lastBarSetColumn() - m_vMapper->firstBarSetColumn() + 1); | |
398 | QCOMPARE(m_series->barSets().first()->count(), m_modelRowCount + 2 * insertCount - first); |
|
398 | QCOMPARE(m_series->barSets().first()->count(), m_modelRowCount + 2 * insertCount - first); | |
399 |
|
399 | |||
400 | int countLimit = 6; |
|
400 | int countLimit = 6; | |
401 | m_vMapper->setCount(countLimit); |
|
401 | m_vMapper->setRowCount(countLimit); | |
402 | QCOMPARE(m_series->count(), m_vMapper->lastBarSetColumn() - m_vMapper->firstBarSetColumn() + 1); |
|
402 | QCOMPARE(m_series->count(), m_vMapper->lastBarSetColumn() - m_vMapper->firstBarSetColumn() + 1); | |
403 | QCOMPARE(m_series->barSets().first()->count(), qMin(countLimit, m_modelRowCount + 2 * insertCount - first)); |
|
403 | QCOMPARE(m_series->barSets().first()->count(), qMin(countLimit, m_modelRowCount + 2 * insertCount - first)); | |
404 |
|
404 | |||
405 | m_model->insertRows(3, insertCount); |
|
405 | m_model->insertRows(3, insertCount); | |
406 | QCOMPARE(m_series->count(), m_vMapper->lastBarSetColumn() - m_vMapper->firstBarSetColumn() + 1); |
|
406 | QCOMPARE(m_series->count(), m_vMapper->lastBarSetColumn() - m_vMapper->firstBarSetColumn() + 1); | |
407 | QCOMPARE(m_series->barSets().first()->count(), qMin(countLimit, m_modelRowCount + 3 * insertCount - first)); |
|
407 | QCOMPARE(m_series->barSets().first()->count(), qMin(countLimit, m_modelRowCount + 3 * insertCount - first)); | |
408 |
|
408 | |||
409 | m_vMapper->setFirst(0); |
|
409 | m_vMapper->setFirstRow(0); | |
410 | QCOMPARE(m_series->count(), m_vMapper->lastBarSetColumn() - m_vMapper->firstBarSetColumn() + 1); |
|
410 | QCOMPARE(m_series->count(), m_vMapper->lastBarSetColumn() - m_vMapper->firstBarSetColumn() + 1); | |
411 | QCOMPARE(m_series->barSets().first()->count(), qMin(countLimit, m_modelRowCount + 3 * insertCount)); |
|
411 | QCOMPARE(m_series->barSets().first()->count(), qMin(countLimit, m_modelRowCount + 3 * insertCount)); | |
412 |
|
412 | |||
413 | m_vMapper->setCount(-1); |
|
413 | m_vMapper->setRowCount(-1); | |
414 | QCOMPARE(m_series->count(), m_vMapper->lastBarSetColumn() - m_vMapper->firstBarSetColumn() + 1); |
|
414 | QCOMPARE(m_series->count(), m_vMapper->lastBarSetColumn() - m_vMapper->firstBarSetColumn() + 1); | |
415 | QCOMPARE(m_series->barSets().first()->count(), m_modelRowCount + 3 * insertCount); |
|
415 | QCOMPARE(m_series->barSets().first()->count(), m_modelRowCount + 3 * insertCount); | |
416 | } |
|
416 | } | |
417 |
|
417 | |||
418 | void tst_qbarmodelmapper::verticalModelRemoveRows() |
|
418 | void tst_qbarmodelmapper::verticalModelRemoveRows() | |
419 | { |
|
419 | { | |
420 | // setup the mapper |
|
420 | // setup the mapper | |
421 | createVerticalMapper(); |
|
421 | createVerticalMapper(); | |
422 | QCOMPARE(m_series->count(), m_vMapper->lastBarSetColumn() - m_vMapper->firstBarSetColumn() + 1); |
|
422 | QCOMPARE(m_series->count(), m_vMapper->lastBarSetColumn() - m_vMapper->firstBarSetColumn() + 1); | |
423 | QCOMPARE(m_series->barSets().first()->count(), m_modelRowCount); |
|
423 | QCOMPARE(m_series->barSets().first()->count(), m_modelRowCount); | |
424 | QVERIFY(m_vMapper->model() != 0); |
|
424 | QVERIFY(m_vMapper->model() != 0); | |
425 |
|
425 | |||
426 | int removeCount = 2; |
|
426 | int removeCount = 2; | |
427 | m_model->removeRows(1, removeCount); |
|
427 | m_model->removeRows(1, removeCount); | |
428 | QCOMPARE(m_series->count(), m_vMapper->lastBarSetColumn() - m_vMapper->firstBarSetColumn() + 1); |
|
428 | QCOMPARE(m_series->count(), m_vMapper->lastBarSetColumn() - m_vMapper->firstBarSetColumn() + 1); | |
429 | QCOMPARE(m_series->barSets().first()->count(), m_modelRowCount - removeCount); |
|
429 | QCOMPARE(m_series->barSets().first()->count(), m_modelRowCount - removeCount); | |
430 |
|
430 | |||
431 | int first = 1; |
|
431 | int first = 1; | |
432 | m_vMapper->setFirst(first); |
|
432 | m_vMapper->setFirstRow(first); | |
433 | QCOMPARE(m_series->count(), m_vMapper->lastBarSetColumn() - m_vMapper->firstBarSetColumn() + 1); |
|
433 | QCOMPARE(m_series->count(), m_vMapper->lastBarSetColumn() - m_vMapper->firstBarSetColumn() + 1); | |
434 | QCOMPARE(m_series->barSets().first()->count(), m_modelRowCount - removeCount - first); |
|
434 | QCOMPARE(m_series->barSets().first()->count(), m_modelRowCount - removeCount - first); | |
435 |
|
435 | |||
436 | m_model->removeRows(1, removeCount); |
|
436 | m_model->removeRows(1, removeCount); | |
437 | QCOMPARE(m_series->count(), m_vMapper->lastBarSetColumn() - m_vMapper->firstBarSetColumn() + 1); |
|
437 | QCOMPARE(m_series->count(), m_vMapper->lastBarSetColumn() - m_vMapper->firstBarSetColumn() + 1); | |
438 | QCOMPARE(m_series->barSets().first()->count(), m_modelRowCount - 2 * removeCount - first); |
|
438 | QCOMPARE(m_series->barSets().first()->count(), m_modelRowCount - 2 * removeCount - first); | |
439 |
|
439 | |||
440 | int countLimit = 3; |
|
440 | int countLimit = 3; | |
441 | m_vMapper->setCount(countLimit); |
|
441 | m_vMapper->setRowCount(countLimit); | |
442 | QCOMPARE(m_series->count(), m_vMapper->lastBarSetColumn() - m_vMapper->firstBarSetColumn() + 1); |
|
442 | QCOMPARE(m_series->count(), m_vMapper->lastBarSetColumn() - m_vMapper->firstBarSetColumn() + 1); | |
443 | QCOMPARE(m_series->barSets().first()->count(), qMin(countLimit, m_modelRowCount - 2 * removeCount - first)); |
|
443 | QCOMPARE(m_series->barSets().first()->count(), qMin(countLimit, m_modelRowCount - 2 * removeCount - first)); | |
444 |
|
444 | |||
445 | m_model->removeRows(1, removeCount); |
|
445 | m_model->removeRows(1, removeCount); | |
446 | QCOMPARE(m_series->count(), m_vMapper->lastBarSetColumn() - m_vMapper->firstBarSetColumn() + 1); |
|
446 | QCOMPARE(m_series->count(), m_vMapper->lastBarSetColumn() - m_vMapper->firstBarSetColumn() + 1); | |
447 | QCOMPARE(m_series->barSets().first()->count(), qMin(countLimit, m_modelRowCount - 3 * removeCount - first)); |
|
447 | QCOMPARE(m_series->barSets().first()->count(), qMin(countLimit, m_modelRowCount - 3 * removeCount - first)); | |
448 |
|
448 | |||
449 | m_vMapper->setFirst(0); |
|
449 | m_vMapper->setFirstRow(0); | |
450 | QCOMPARE(m_series->count(), m_vMapper->lastBarSetColumn() - m_vMapper->firstBarSetColumn() + 1); |
|
450 | QCOMPARE(m_series->count(), m_vMapper->lastBarSetColumn() - m_vMapper->firstBarSetColumn() + 1); | |
451 | QCOMPARE(m_series->barSets().first()->count(), qMin(countLimit, m_modelRowCount - 3 * removeCount)); |
|
451 | QCOMPARE(m_series->barSets().first()->count(), qMin(countLimit, m_modelRowCount - 3 * removeCount)); | |
452 |
|
452 | |||
453 | m_vMapper->setCount(-1); |
|
453 | m_vMapper->setRowCount(-1); | |
454 | QCOMPARE(m_series->count(), m_vMapper->lastBarSetColumn() - m_vMapper->firstBarSetColumn() + 1); |
|
454 | QCOMPARE(m_series->count(), m_vMapper->lastBarSetColumn() - m_vMapper->firstBarSetColumn() + 1); | |
455 | QCOMPARE(m_series->barSets().first()->count(), m_modelRowCount - 3 * removeCount); |
|
455 | QCOMPARE(m_series->barSets().first()->count(), m_modelRowCount - 3 * removeCount); | |
456 | } |
|
456 | } | |
457 |
|
457 | |||
458 | void tst_qbarmodelmapper::verticalModelInsertColumns() |
|
458 | void tst_qbarmodelmapper::verticalModelInsertColumns() | |
459 | { |
|
459 | { | |
460 | // setup the mapper |
|
460 | // setup the mapper | |
461 | createVerticalMapper(); |
|
461 | createVerticalMapper(); | |
462 | QCOMPARE(m_series->count(), m_vMapper->lastBarSetColumn() - m_vMapper->firstBarSetColumn() + 1); |
|
462 | QCOMPARE(m_series->count(), m_vMapper->lastBarSetColumn() - m_vMapper->firstBarSetColumn() + 1); | |
463 | QCOMPARE(m_series->barSets().first()->count(), m_modelRowCount); |
|
463 | QCOMPARE(m_series->barSets().first()->count(), m_modelRowCount); | |
464 | QVERIFY(m_vMapper->model() != 0); |
|
464 | QVERIFY(m_vMapper->model() != 0); | |
465 |
|
465 | |||
466 | int insertCount = 4; |
|
466 | int insertCount = 4; | |
467 | m_model->insertColumns(3, insertCount); |
|
467 | m_model->insertColumns(3, insertCount); | |
468 | QCOMPARE(m_series->count(), m_vMapper->lastBarSetColumn() - m_vMapper->firstBarSetColumn() + 1); |
|
468 | QCOMPARE(m_series->count(), m_vMapper->lastBarSetColumn() - m_vMapper->firstBarSetColumn() + 1); | |
469 | QCOMPARE(m_series->barSets().first()->count(), m_modelRowCount); |
|
469 | QCOMPARE(m_series->barSets().first()->count(), m_modelRowCount); | |
470 | } |
|
470 | } | |
471 |
|
471 | |||
472 | void tst_qbarmodelmapper::verticalModelRemoveColumns() |
|
472 | void tst_qbarmodelmapper::verticalModelRemoveColumns() | |
473 | { |
|
473 | { | |
474 | // setup the mapper |
|
474 | // setup the mapper | |
475 | createVerticalMapper(); |
|
475 | createVerticalMapper(); | |
476 | QCOMPARE(m_series->count(), qMin(m_model->columnCount(), m_vMapper->lastBarSetColumn() - m_vMapper->firstBarSetColumn() + 1)); |
|
476 | QCOMPARE(m_series->count(), qMin(m_model->columnCount(), m_vMapper->lastBarSetColumn() - m_vMapper->firstBarSetColumn() + 1)); | |
477 | QCOMPARE(m_series->barSets().first()->count(), m_modelRowCount); |
|
477 | QCOMPARE(m_series->barSets().first()->count(), m_modelRowCount); | |
478 | QVERIFY(m_vMapper->model() != 0); |
|
478 | QVERIFY(m_vMapper->model() != 0); | |
479 |
|
479 | |||
480 | int removeCount = m_modelColumnCount - 2; |
|
480 | int removeCount = m_modelColumnCount - 2; | |
481 | m_model->removeColumns(0, removeCount); |
|
481 | m_model->removeColumns(0, removeCount); | |
482 | QCOMPARE(m_series->count(), qMin(m_model->columnCount(), m_vMapper->lastBarSetColumn() - m_vMapper->firstBarSetColumn() + 1)); |
|
482 | QCOMPARE(m_series->count(), qMin(m_model->columnCount(), m_vMapper->lastBarSetColumn() - m_vMapper->firstBarSetColumn() + 1)); | |
483 | QCOMPARE(m_series->barSets().first()->count(), m_modelRowCount); |
|
483 | QCOMPARE(m_series->barSets().first()->count(), m_modelRowCount); | |
484 |
|
484 | |||
485 | // leave all the columns |
|
485 | // leave all the columns | |
486 | m_model->removeColumns(0, m_modelColumnCount - removeCount); |
|
486 | m_model->removeColumns(0, m_modelColumnCount - removeCount); | |
487 | QCOMPARE(m_series->count(), 0); |
|
487 | QCOMPARE(m_series->count(), 0); | |
488 | } |
|
488 | } | |
489 |
|
489 | |||
490 | void tst_qbarmodelmapper::horizontalModelInsertRows() |
|
490 | void tst_qbarmodelmapper::horizontalModelInsertRows() | |
491 | { |
|
491 | { | |
492 | // setup the mapper |
|
492 | // setup the mapper | |
493 | createHorizontalMapper(); |
|
493 | createHorizontalMapper(); | |
494 | QCOMPARE(m_series->count(), m_hMapper->lastBarSetRow() - m_hMapper->firstBarSetRow() + 1); |
|
494 | QCOMPARE(m_series->count(), m_hMapper->lastBarSetRow() - m_hMapper->firstBarSetRow() + 1); | |
495 | QCOMPARE(m_series->barSets().first()->count(), m_modelColumnCount); |
|
495 | QCOMPARE(m_series->barSets().first()->count(), m_modelColumnCount); | |
496 | QVERIFY(m_hMapper->model() != 0); |
|
496 | QVERIFY(m_hMapper->model() != 0); | |
497 |
|
497 | |||
498 | int insertCount = 4; |
|
498 | int insertCount = 4; | |
499 | m_model->insertRows(3, insertCount); |
|
499 | m_model->insertRows(3, insertCount); | |
500 | QCOMPARE(m_series->count(), m_hMapper->lastBarSetRow() - m_hMapper->firstBarSetRow() + 1); |
|
500 | QCOMPARE(m_series->count(), m_hMapper->lastBarSetRow() - m_hMapper->firstBarSetRow() + 1); | |
501 | QCOMPARE(m_series->barSets().first()->count(), m_modelColumnCount); |
|
501 | QCOMPARE(m_series->barSets().first()->count(), m_modelColumnCount); | |
502 | } |
|
502 | } | |
503 |
|
503 | |||
504 | void tst_qbarmodelmapper::horizontalModelRemoveRows() |
|
504 | void tst_qbarmodelmapper::horizontalModelRemoveRows() | |
505 | { |
|
505 | { | |
506 | // setup the mapper |
|
506 | // setup the mapper | |
507 | createHorizontalMapper(); |
|
507 | createHorizontalMapper(); | |
508 | QCOMPARE(m_series->count(), qMin(m_model->rowCount(), m_hMapper->lastBarSetRow() - m_hMapper->firstBarSetRow() + 1)); |
|
508 | QCOMPARE(m_series->count(), qMin(m_model->rowCount(), m_hMapper->lastBarSetRow() - m_hMapper->firstBarSetRow() + 1)); | |
509 | QCOMPARE(m_series->barSets().first()->count(), m_modelColumnCount); |
|
509 | QCOMPARE(m_series->barSets().first()->count(), m_modelColumnCount); | |
510 | QVERIFY(m_hMapper->model() != 0); |
|
510 | QVERIFY(m_hMapper->model() != 0); | |
511 |
|
511 | |||
512 | int removeCount = m_modelRowCount - 2; |
|
512 | int removeCount = m_modelRowCount - 2; | |
513 | m_model->removeRows(0, removeCount); |
|
513 | m_model->removeRows(0, removeCount); | |
514 | QCOMPARE(m_series->count(), qMin(m_model->rowCount(), m_hMapper->lastBarSetRow() - m_hMapper->firstBarSetRow() + 1)); |
|
514 | QCOMPARE(m_series->count(), qMin(m_model->rowCount(), m_hMapper->lastBarSetRow() - m_hMapper->firstBarSetRow() + 1)); | |
515 | QCOMPARE(m_series->barSets().first()->count(), m_modelColumnCount); |
|
515 | QCOMPARE(m_series->barSets().first()->count(), m_modelColumnCount); | |
516 |
|
516 | |||
517 | // leave all the columns |
|
517 | // leave all the columns | |
518 | m_model->removeRows(0, m_modelRowCount - removeCount); |
|
518 | m_model->removeRows(0, m_modelRowCount - removeCount); | |
519 | QCOMPARE(m_series->count(), 0); |
|
519 | QCOMPARE(m_series->count(), 0); | |
520 | } |
|
520 | } | |
521 |
|
521 | |||
522 | void tst_qbarmodelmapper::horizontalModelInsertColumns() |
|
522 | void tst_qbarmodelmapper::horizontalModelInsertColumns() | |
523 | { |
|
523 | { | |
524 | // setup the mapper |
|
524 | // setup the mapper | |
525 | createHorizontalMapper(); |
|
525 | createHorizontalMapper(); | |
526 | QCOMPARE(m_series->count(), m_hMapper->lastBarSetRow() - m_hMapper->firstBarSetRow() + 1); |
|
526 | QCOMPARE(m_series->count(), m_hMapper->lastBarSetRow() - m_hMapper->firstBarSetRow() + 1); | |
527 | QCOMPARE(m_series->barSets().first()->count(), m_modelColumnCount); |
|
527 | QCOMPARE(m_series->barSets().first()->count(), m_modelColumnCount); | |
528 | QVERIFY(m_hMapper->model() != 0); |
|
528 | QVERIFY(m_hMapper->model() != 0); | |
529 |
|
529 | |||
530 | int insertCount = 4; |
|
530 | int insertCount = 4; | |
531 | m_model->insertColumns(3, insertCount); |
|
531 | m_model->insertColumns(3, insertCount); | |
532 | QCOMPARE(m_series->count(), m_hMapper->lastBarSetRow() - m_hMapper->firstBarSetRow() + 1); |
|
532 | QCOMPARE(m_series->count(), m_hMapper->lastBarSetRow() - m_hMapper->firstBarSetRow() + 1); | |
533 | QCOMPARE(m_series->barSets().first()->count(), m_modelColumnCount + insertCount); |
|
533 | QCOMPARE(m_series->barSets().first()->count(), m_modelColumnCount + insertCount); | |
534 |
|
534 | |||
535 | int first = 3; |
|
535 | int first = 3; | |
536 | m_hMapper->setFirst(3); |
|
536 | m_hMapper->setFirstColumn(3); | |
537 | QCOMPARE(m_series->count(), m_hMapper->lastBarSetRow() - m_hMapper->firstBarSetRow() + 1); |
|
537 | QCOMPARE(m_series->count(), m_hMapper->lastBarSetRow() - m_hMapper->firstBarSetRow() + 1); | |
538 | QCOMPARE(m_series->barSets().first()->count(), m_modelColumnCount + insertCount - first); |
|
538 | QCOMPARE(m_series->barSets().first()->count(), m_modelColumnCount + insertCount - first); | |
539 |
|
539 | |||
540 | m_model->insertColumns(3, insertCount); |
|
540 | m_model->insertColumns(3, insertCount); | |
541 | QCOMPARE(m_series->count(), m_hMapper->lastBarSetRow() - m_hMapper->firstBarSetRow() + 1); |
|
541 | QCOMPARE(m_series->count(), m_hMapper->lastBarSetRow() - m_hMapper->firstBarSetRow() + 1); | |
542 | QCOMPARE(m_series->barSets().first()->count(), m_modelColumnCount + 2 * insertCount - first); |
|
542 | QCOMPARE(m_series->barSets().first()->count(), m_modelColumnCount + 2 * insertCount - first); | |
543 |
|
543 | |||
544 | int countLimit = 6; |
|
544 | int countLimit = 6; | |
545 | m_hMapper->setCount(countLimit); |
|
545 | m_hMapper->setColumnCount(countLimit); | |
546 | QCOMPARE(m_series->count(), m_hMapper->lastBarSetRow() - m_hMapper->firstBarSetRow() + 1); |
|
546 | QCOMPARE(m_series->count(), m_hMapper->lastBarSetRow() - m_hMapper->firstBarSetRow() + 1); | |
547 | QCOMPARE(m_series->barSets().first()->count(), qMin(countLimit, m_modelColumnCount + 2 * insertCount - first)); |
|
547 | QCOMPARE(m_series->barSets().first()->count(), qMin(countLimit, m_modelColumnCount + 2 * insertCount - first)); | |
548 |
|
548 | |||
549 | m_model->insertColumns(3, insertCount); |
|
549 | m_model->insertColumns(3, insertCount); | |
550 | QCOMPARE(m_series->count(), m_hMapper->lastBarSetRow() - m_hMapper->firstBarSetRow() + 1); |
|
550 | QCOMPARE(m_series->count(), m_hMapper->lastBarSetRow() - m_hMapper->firstBarSetRow() + 1); | |
551 | QCOMPARE(m_series->barSets().first()->count(), qMin(countLimit, m_modelColumnCount + 3 * insertCount - first)); |
|
551 | QCOMPARE(m_series->barSets().first()->count(), qMin(countLimit, m_modelColumnCount + 3 * insertCount - first)); | |
552 |
|
552 | |||
553 | m_hMapper->setFirst(0); |
|
553 | m_hMapper->setFirstColumn(0); | |
554 | QCOMPARE(m_series->count(), m_hMapper->lastBarSetRow() - m_hMapper->firstBarSetRow() + 1); |
|
554 | QCOMPARE(m_series->count(), m_hMapper->lastBarSetRow() - m_hMapper->firstBarSetRow() + 1); | |
555 | QCOMPARE(m_series->barSets().first()->count(), qMin(countLimit, m_modelColumnCount + 3 * insertCount)); |
|
555 | QCOMPARE(m_series->barSets().first()->count(), qMin(countLimit, m_modelColumnCount + 3 * insertCount)); | |
556 |
|
556 | |||
557 | m_hMapper->setCount(-1); |
|
557 | m_hMapper->setColumnCount(-1); | |
558 | QCOMPARE(m_series->count(), m_hMapper->lastBarSetRow() - m_hMapper->firstBarSetRow() + 1); |
|
558 | QCOMPARE(m_series->count(), m_hMapper->lastBarSetRow() - m_hMapper->firstBarSetRow() + 1); | |
559 | QCOMPARE(m_series->barSets().first()->count(), m_modelColumnCount + 3 * insertCount); |
|
559 | QCOMPARE(m_series->barSets().first()->count(), m_modelColumnCount + 3 * insertCount); | |
560 | } |
|
560 | } | |
561 |
|
561 | |||
562 | void tst_qbarmodelmapper::horizontalModelRemoveColumns() |
|
562 | void tst_qbarmodelmapper::horizontalModelRemoveColumns() | |
563 | { |
|
563 | { | |
564 | // setup the mapper |
|
564 | // setup the mapper | |
565 | createHorizontalMapper(); |
|
565 | createHorizontalMapper(); | |
566 | QCOMPARE(m_series->count(), m_hMapper->lastBarSetRow() - m_hMapper->firstBarSetRow() + 1); |
|
566 | QCOMPARE(m_series->count(), m_hMapper->lastBarSetRow() - m_hMapper->firstBarSetRow() + 1); | |
567 | QCOMPARE(m_series->barSets().first()->count(), m_modelColumnCount); |
|
567 | QCOMPARE(m_series->barSets().first()->count(), m_modelColumnCount); | |
568 | QVERIFY(m_hMapper->model() != 0); |
|
568 | QVERIFY(m_hMapper->model() != 0); | |
569 |
|
569 | |||
570 | int removeCount = 2; |
|
570 | int removeCount = 2; | |
571 | m_model->removeColumns(1, removeCount); |
|
571 | m_model->removeColumns(1, removeCount); | |
572 | QCOMPARE(m_series->count(), m_hMapper->lastBarSetRow() - m_hMapper->firstBarSetRow() + 1); |
|
572 | QCOMPARE(m_series->count(), m_hMapper->lastBarSetRow() - m_hMapper->firstBarSetRow() + 1); | |
573 | QCOMPARE(m_series->barSets().first()->count(), m_modelColumnCount - removeCount); |
|
573 | QCOMPARE(m_series->barSets().first()->count(), m_modelColumnCount - removeCount); | |
574 |
|
574 | |||
575 | int first = 1; |
|
575 | int first = 1; | |
576 | m_hMapper->setFirst(first); |
|
576 | m_hMapper->setFirstColumn(first); | |
577 | QCOMPARE(m_series->count(), m_hMapper->lastBarSetRow() - m_hMapper->firstBarSetRow() + 1); |
|
577 | QCOMPARE(m_series->count(), m_hMapper->lastBarSetRow() - m_hMapper->firstBarSetRow() + 1); | |
578 | QCOMPARE(m_series->barSets().first()->count(), m_modelColumnCount - removeCount - first); |
|
578 | QCOMPARE(m_series->barSets().first()->count(), m_modelColumnCount - removeCount - first); | |
579 |
|
579 | |||
580 | m_model->removeColumns(1, removeCount); |
|
580 | m_model->removeColumns(1, removeCount); | |
581 | QCOMPARE(m_series->count(), m_hMapper->lastBarSetRow() - m_hMapper->firstBarSetRow() + 1); |
|
581 | QCOMPARE(m_series->count(), m_hMapper->lastBarSetRow() - m_hMapper->firstBarSetRow() + 1); | |
582 | QCOMPARE(m_series->barSets().first()->count(), m_modelColumnCount - 2 * removeCount - first); |
|
582 | QCOMPARE(m_series->barSets().first()->count(), m_modelColumnCount - 2 * removeCount - first); | |
583 |
|
583 | |||
584 | int countLimit = 3; |
|
584 | int countLimit = 3; | |
585 | m_hMapper->setCount(countLimit); |
|
585 | m_hMapper->setColumnCount(countLimit); | |
586 | QCOMPARE(m_series->count(), m_hMapper->lastBarSetRow() - m_hMapper->firstBarSetRow() + 1); |
|
586 | QCOMPARE(m_series->count(), m_hMapper->lastBarSetRow() - m_hMapper->firstBarSetRow() + 1); | |
587 | QCOMPARE(m_series->barSets().first()->count(), qMin(countLimit, m_modelColumnCount - 2 * removeCount - first)); |
|
587 | QCOMPARE(m_series->barSets().first()->count(), qMin(countLimit, m_modelColumnCount - 2 * removeCount - first)); | |
588 |
|
588 | |||
589 | m_model->removeColumns(1, removeCount); |
|
589 | m_model->removeColumns(1, removeCount); | |
590 | QCOMPARE(m_series->count(), m_hMapper->lastBarSetRow() - m_hMapper->firstBarSetRow() + 1); |
|
590 | QCOMPARE(m_series->count(), m_hMapper->lastBarSetRow() - m_hMapper->firstBarSetRow() + 1); | |
591 | QCOMPARE(m_series->barSets().first()->count(), qMin(countLimit, m_modelColumnCount - 3 * removeCount - first)); |
|
591 | QCOMPARE(m_series->barSets().first()->count(), qMin(countLimit, m_modelColumnCount - 3 * removeCount - first)); | |
592 |
|
592 | |||
593 | m_hMapper->setFirst(0); |
|
593 | m_hMapper->setFirstColumn(0); | |
594 | QCOMPARE(m_series->count(), m_hMapper->lastBarSetRow() - m_hMapper->firstBarSetRow() + 1); |
|
594 | QCOMPARE(m_series->count(), m_hMapper->lastBarSetRow() - m_hMapper->firstBarSetRow() + 1); | |
595 | QCOMPARE(m_series->barSets().first()->count(), qMin(countLimit, m_modelColumnCount - 3 * removeCount)); |
|
595 | QCOMPARE(m_series->barSets().first()->count(), qMin(countLimit, m_modelColumnCount - 3 * removeCount)); | |
596 |
|
596 | |||
597 | m_hMapper->setCount(-1); |
|
597 | m_hMapper->setColumnCount(-1); | |
598 | QCOMPARE(m_series->count(), m_hMapper->lastBarSetRow() - m_hMapper->firstBarSetRow() + 1); |
|
598 | QCOMPARE(m_series->count(), m_hMapper->lastBarSetRow() - m_hMapper->firstBarSetRow() + 1); | |
599 | QCOMPARE(m_series->barSets().first()->count(), m_modelColumnCount - 3 * removeCount); |
|
599 | QCOMPARE(m_series->barSets().first()->count(), m_modelColumnCount - 3 * removeCount); | |
600 | } |
|
600 | } | |
601 |
|
601 | |||
602 | void tst_qbarmodelmapper::modelUpdateCell() |
|
602 | void tst_qbarmodelmapper::modelUpdateCell() | |
603 | { |
|
603 | { | |
604 | // setup the mapper |
|
604 | // setup the mapper | |
605 | createVerticalMapper(); |
|
605 | createVerticalMapper(); | |
606 |
|
606 | |||
607 | QVERIFY(m_model->setData(m_model->index(1, 0), 44)); |
|
607 | QVERIFY(m_model->setData(m_model->index(1, 0), 44)); | |
608 | QCOMPARE(m_series->barSets().at(0)->at(1).y(), 44.0); |
|
608 | QCOMPARE(m_series->barSets().at(0)->at(1).y(), 44.0); | |
609 | QCOMPARE(m_model->data(m_model->index(1, 0)).toReal(), 44.0); |
|
609 | QCOMPARE(m_model->data(m_model->index(1, 0)).toReal(), 44.0); | |
610 | } |
|
610 | } | |
611 |
|
611 | |||
612 | QTEST_MAIN(tst_qbarmodelmapper) |
|
612 | QTEST_MAIN(tst_qbarmodelmapper) | |
613 |
|
613 | |||
614 | #include "tst_qbarmodelmapper.moc" |
|
614 | #include "tst_qbarmodelmapper.moc" |
General Comments 0
You need to be logged in to leave comments.
Login now