|
@@
-1,633
+1,633
|
|
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. This class is used to create a connection between QBarSeries and QAbstractItemModel derived model object.
|
|
36
|
The instance of this class cannot be created directly. QHBarModelMapper of QVBarModelMapper should be used instead.
|
|
37
|
Curently it is NOT possible to use both QAbstractItemModel and QBarSeries model API.
|
|
37
|
This class is used to create a connection between QBarSeries and QAbstractItemModel derived model object.
|
|
38
|
When the series is set to the mapper the QBarSeries and QBarSet API that affect the data (append, setValue, remove) should not be used.
|
|
38
|
Model mapper maintains equal size of all the BarSets.
|
|
39
|
The model and the QBarSeries won't be kept in sync. Model API should be used to insert,remove,modify BarSets.
|
|
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
|
/*!
|
|
43
|
/*!
|
|
44
|
\property QBarModelMapper::series
|
|
44
|
\property QBarModelMapper::series
|
|
45
|
\brief Defines the QPieSeries object that is used by the mapper.
|
|
45
|
\brief Defines the QPieSeries object that is used by the mapper.
|
|
46
|
|
|
46
|
|
|
47
|
All the data in the series is discarded when it is set to the mapper.
|
|
47
|
All the data in the series is discarded when it is set to the mapper.
|
|
48
|
When new series is specified the old series is disconnected (it preserves its data)
|
|
48
|
When new series is specified the old series is disconnected (it preserves its data)
|
|
49
|
*/
|
|
49
|
*/
|
|
50
|
|
|
50
|
|
|
51
|
/*!
|
|
51
|
/*!
|
|
52
|
\property QBarModelMapper::model
|
|
52
|
\property QBarModelMapper::model
|
|
53
|
\brief Defines the model that is used by the mapper.
|
|
53
|
\brief Defines the model that is used by the mapper.
|
|
54
|
*/
|
|
54
|
*/
|
|
55
|
|
|
55
|
|
|
56
|
/*!
|
|
56
|
/*!
|
|
57
|
\property QBarModelMapper::first
|
|
57
|
\property QBarModelMapper::first
|
|
58
|
\brief Defines which item of the model's row/column should be mapped as the value of the first QBarSet in the series.
|
|
58
|
\brief Defines which item of the model's row/column should be mapped as the value of the first QBarSet in the series.
|
|
59
|
|
|
59
|
|
|
60
|
Minimal and default value is: 0
|
|
60
|
Minimal and default value is: 0
|
|
61
|
*/
|
|
61
|
*/
|
|
62
|
|
|
62
|
|
|
63
|
/*!
|
|
63
|
/*!
|
|
64
|
\property QBarModelMapper::count
|
|
64
|
\property QBarModelMapper::count
|
|
65
|
\brief Defines the number of rows/columns of the model that are mapped as the data for QBarSeries
|
|
65
|
\brief Defines the number of rows/columns of the model that are mapped as the data for QBarSeries
|
|
66
|
|
|
66
|
|
|
67
|
Minimal and default value is: -1 (count limited by the number of rows/columns in the model)
|
|
67
|
Minimal and default value is: -1 (count limited by the number of rows/columns in the model)
|
|
68
|
*/
|
|
68
|
*/
|
|
69
|
|
|
69
|
|
|
70
|
/*!
|
|
70
|
/*!
|
|
71
|
\fn void QBarModelMapper::seriesReplaced()
|
|
71
|
\fn void QBarModelMapper::seriesReplaced()
|
|
72
|
|
|
72
|
|
|
73
|
Emitted when the series to which mapper is connected to has changed.
|
|
73
|
Emitted when the series to which mapper is connected to has changed.
|
|
74
|
*/
|
|
74
|
*/
|
|
75
|
|
|
75
|
|
|
76
|
/*!
|
|
76
|
/*!
|
|
77
|
\fn void QBarModelMapper::modelReplaced()
|
|
77
|
\fn void QBarModelMapper::modelReplaced()
|
|
78
|
|
|
78
|
|
|
79
|
Emitted when the model to which mapper is connected to has changed.
|
|
79
|
Emitted when the model to which mapper is connected to has changed.
|
|
80
|
*/
|
|
80
|
*/
|
|
81
|
|
|
81
|
|
|
82
|
/*!
|
|
82
|
/*!
|
|
83
|
\fn void QBarModelMapper::firstChanged()
|
|
83
|
\fn void QBarModelMapper::firstChanged()
|
|
84
|
|
|
84
|
|
|
85
|
Emitted when the value for the first has changed.
|
|
85
|
Emitted when the value for the first has changed.
|
|
86
|
*/
|
|
86
|
*/
|
|
87
|
|
|
87
|
|
|
88
|
/*!
|
|
88
|
/*!
|
|
89
|
\fn void QBarModelMapper::countChanged()
|
|
89
|
\fn void QBarModelMapper::countChanged()
|
|
90
|
|
|
90
|
|
|
91
|
Emitted when the value for the count has changed.
|
|
91
|
Emitted when the value for the count has changed.
|
|
92
|
*/
|
|
92
|
*/
|
|
93
|
|
|
93
|
|
|
94
|
/*!
|
|
94
|
/*!
|
|
95
|
Constructs a mapper object which is a child of \a parent.
|
|
95
|
Constructs a mapper object which is a child of \a parent.
|
|
96
|
*/
|
|
96
|
*/
|
|
97
|
QBarModelMapper::QBarModelMapper(QObject *parent) :
|
|
97
|
QBarModelMapper::QBarModelMapper(QObject *parent) :
|
|
98
|
QObject(parent),
|
|
98
|
QObject(parent),
|
|
99
|
d_ptr(new QBarModelMapperPrivate(this))
|
|
99
|
d_ptr(new QBarModelMapperPrivate(this))
|
|
100
|
{
|
|
100
|
{
|
|
101
|
}
|
|
101
|
}
|
|
102
|
|
|
102
|
|
|
103
|
QAbstractItemModel* QBarModelMapper::model() const
|
|
103
|
QAbstractItemModel* QBarModelMapper::model() const
|
|
104
|
{
|
|
104
|
{
|
|
105
|
Q_D(const QBarModelMapper);
|
|
105
|
Q_D(const QBarModelMapper);
|
|
106
|
return d->m_model;
|
|
106
|
return d->m_model;
|
|
107
|
}
|
|
107
|
}
|
|
108
|
|
|
108
|
|
|
109
|
void QBarModelMapper::setModel(QAbstractItemModel *model)
|
|
109
|
void QBarModelMapper::setModel(QAbstractItemModel *model)
|
|
110
|
{
|
|
110
|
{
|
|
111
|
if (model == 0)
|
|
111
|
if (model == 0)
|
|
112
|
return;
|
|
112
|
return;
|
|
113
|
|
|
113
|
|
|
114
|
Q_D(QBarModelMapper);
|
|
114
|
Q_D(QBarModelMapper);
|
|
115
|
if (d->m_model) {
|
|
115
|
if (d->m_model) {
|
|
116
|
disconnect(d->m_model, 0, d, 0);
|
|
116
|
disconnect(d->m_model, 0, d, 0);
|
|
117
|
}
|
|
117
|
}
|
|
118
|
|
|
118
|
|
|
119
|
d->m_model = model;
|
|
119
|
d->m_model = model;
|
|
120
|
d->initializeBarFromModel();
|
|
120
|
d->initializeBarFromModel();
|
|
121
|
// connect signals from the model
|
|
121
|
// connect signals from the model
|
|
122
|
connect(d->m_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), d, SLOT(modelUpdated(QModelIndex,QModelIndex)));
|
|
122
|
connect(d->m_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), d, SLOT(modelUpdated(QModelIndex,QModelIndex)));
|
|
123
|
connect(d->m_model, SIGNAL(headerDataChanged(Qt::Orientation,int,int)), d, SLOT(modelHeaderDataUpdated(Qt::Orientation,int,int)));
|
|
123
|
connect(d->m_model, SIGNAL(headerDataChanged(Qt::Orientation,int,int)), d, SLOT(modelHeaderDataUpdated(Qt::Orientation,int,int)));
|
|
124
|
connect(d->m_model, SIGNAL(rowsInserted(QModelIndex,int,int)), d, SLOT(modelRowsAdded(QModelIndex,int,int)));
|
|
124
|
connect(d->m_model, SIGNAL(rowsInserted(QModelIndex,int,int)), d, SLOT(modelRowsAdded(QModelIndex,int,int)));
|
|
125
|
connect(d->m_model, SIGNAL(rowsRemoved(QModelIndex,int,int)), d, SLOT(modelRowsRemoved(QModelIndex,int,int)));
|
|
125
|
connect(d->m_model, SIGNAL(rowsRemoved(QModelIndex,int,int)), d, SLOT(modelRowsRemoved(QModelIndex,int,int)));
|
|
126
|
connect(d->m_model, SIGNAL(columnsInserted(QModelIndex,int,int)), d, SLOT(modelColumnsAdded(QModelIndex,int,int)));
|
|
126
|
connect(d->m_model, SIGNAL(columnsInserted(QModelIndex,int,int)), d, SLOT(modelColumnsAdded(QModelIndex,int,int)));
|
|
127
|
connect(d->m_model, SIGNAL(columnsRemoved(QModelIndex,int,int)), d, SLOT(modelColumnsRemoved(QModelIndex,int,int)));
|
|
127
|
connect(d->m_model, SIGNAL(columnsRemoved(QModelIndex,int,int)), d, SLOT(modelColumnsRemoved(QModelIndex,int,int)));
|
|
128
|
|
|
128
|
|
|
129
|
emit modelReplaced();
|
|
129
|
emit modelReplaced();
|
|
130
|
}
|
|
130
|
}
|
|
131
|
|
|
131
|
|
|
132
|
QBarSeries* QBarModelMapper::series() const
|
|
132
|
QBarSeries* QBarModelMapper::series() const
|
|
133
|
{
|
|
133
|
{
|
|
134
|
Q_D(const QBarModelMapper);
|
|
134
|
Q_D(const QBarModelMapper);
|
|
135
|
return d->m_series;
|
|
135
|
return d->m_series;
|
|
136
|
}
|
|
136
|
}
|
|
137
|
|
|
137
|
|
|
138
|
void QBarModelMapper::setSeries(QBarSeries *series)
|
|
138
|
void QBarModelMapper::setSeries(QBarSeries *series)
|
|
139
|
{
|
|
139
|
{
|
|
140
|
Q_D(QBarModelMapper);
|
|
140
|
Q_D(QBarModelMapper);
|
|
141
|
if (d->m_series) {
|
|
141
|
if (d->m_series) {
|
|
142
|
disconnect(d->m_series, 0, d, 0);
|
|
142
|
disconnect(d->m_series, 0, d, 0);
|
|
143
|
}
|
|
143
|
}
|
|
144
|
|
|
144
|
|
|
145
|
if (series == 0)
|
|
145
|
if (series == 0)
|
|
146
|
return;
|
|
146
|
return;
|
|
147
|
|
|
147
|
|
|
148
|
d->m_series = series;
|
|
148
|
d->m_series = series;
|
|
149
|
d->initializeBarFromModel();
|
|
149
|
d->initializeBarFromModel();
|
|
150
|
// connect the signals from the series
|
|
150
|
// connect the signals from the series
|
|
151
|
connect(d->m_series, SIGNAL(barsetsAdded(QList<QBarSet*>)), d, SLOT(barSetsAdded(QList<QBarSet*>)));
|
|
151
|
connect(d->m_series, SIGNAL(barsetsAdded(QList<QBarSet*>)), d, SLOT(barSetsAdded(QList<QBarSet*>)));
|
|
152
|
connect(d->m_series, SIGNAL(barsetsRemoved(QList<QBarSet*>)), d, SLOT(barSetsRemoved(QList<QBarSet*>)));
|
|
152
|
connect(d->m_series, SIGNAL(barsetsRemoved(QList<QBarSet*>)), d, SLOT(barSetsRemoved(QList<QBarSet*>)));
|
|
153
|
|
|
153
|
|
|
154
|
emit seriesReplaced();
|
|
154
|
emit seriesReplaced();
|
|
155
|
}
|
|
155
|
}
|
|
156
|
|
|
156
|
|
|
157
|
int QBarModelMapper::first() const
|
|
157
|
int QBarModelMapper::first() const
|
|
158
|
{
|
|
158
|
{
|
|
159
|
Q_D(const QBarModelMapper);
|
|
159
|
Q_D(const QBarModelMapper);
|
|
160
|
return d->m_first;
|
|
160
|
return d->m_first;
|
|
161
|
}
|
|
161
|
}
|
|
162
|
|
|
162
|
|
|
163
|
void QBarModelMapper::setFirst(int first)
|
|
163
|
void QBarModelMapper::setFirst(int first)
|
|
164
|
{
|
|
164
|
{
|
|
165
|
Q_D(QBarModelMapper);
|
|
165
|
Q_D(QBarModelMapper);
|
|
166
|
if (first != d->m_first) {
|
|
166
|
if (first != d->m_first) {
|
|
167
|
d->m_first = qMax(first, 0);
|
|
167
|
d->m_first = qMax(first, 0);
|
|
168
|
d->initializeBarFromModel();
|
|
168
|
d->initializeBarFromModel();
|
|
169
|
|
|
169
|
|
|
170
|
emit firstChanged();
|
|
170
|
emit firstChanged();
|
|
171
|
}
|
|
171
|
}
|
|
172
|
}
|
|
172
|
}
|
|
173
|
|
|
173
|
|
|
174
|
int QBarModelMapper::count() const
|
|
174
|
int QBarModelMapper::count() const
|
|
175
|
{
|
|
175
|
{
|
|
176
|
Q_D(const QBarModelMapper);
|
|
176
|
Q_D(const QBarModelMapper);
|
|
177
|
return d->m_count;
|
|
177
|
return d->m_count;
|
|
178
|
}
|
|
178
|
}
|
|
179
|
|
|
179
|
|
|
180
|
void QBarModelMapper::setCount(int count)
|
|
180
|
void QBarModelMapper::setCount(int count)
|
|
181
|
{
|
|
181
|
{
|
|
182
|
Q_D(QBarModelMapper);
|
|
182
|
Q_D(QBarModelMapper);
|
|
183
|
if (count != d->m_count) {
|
|
183
|
if (count != d->m_count) {
|
|
184
|
d->m_count = qMax(count, -1);
|
|
184
|
d->m_count = qMax(count, -1);
|
|
185
|
d->initializeBarFromModel();
|
|
185
|
d->initializeBarFromModel();
|
|
186
|
|
|
186
|
|
|
187
|
emit countChanged();
|
|
187
|
emit countChanged();
|
|
188
|
}
|
|
188
|
}
|
|
189
|
}
|
|
189
|
}
|
|
190
|
|
|
190
|
|
|
191
|
/*!
|
|
191
|
/*!
|
|
192
|
Returns the orientation that is used when QBarModelMapper accesses the model.
|
|
192
|
Returns the orientation that is used when QBarModelMapper accesses the model.
|
|
193
|
This mean whether the consecutive values of the bar set are read from row (Qt::Horizontal)
|
|
193
|
This mean whether the consecutive values of the bar set are read from row (Qt::Horizontal)
|
|
194
|
or from columns (Qt::Vertical)
|
|
194
|
or from columns (Qt::Vertical)
|
|
195
|
*/
|
|
195
|
*/
|
|
196
|
Qt::Orientation QBarModelMapper::orientation() const
|
|
196
|
Qt::Orientation QBarModelMapper::orientation() const
|
|
197
|
{
|
|
197
|
{
|
|
198
|
Q_D(const QBarModelMapper);
|
|
198
|
Q_D(const QBarModelMapper);
|
|
199
|
return d->m_orientation;
|
|
199
|
return d->m_orientation;
|
|
200
|
}
|
|
200
|
}
|
|
201
|
|
|
201
|
|
|
202
|
/*!
|
|
202
|
/*!
|
|
203
|
Returns the \a orientation that is used when QBarModelMapper accesses the model.
|
|
203
|
Returns the \a orientation that is used when QBarModelMapper accesses the model.
|
|
204
|
This mean whether the consecutive values of the pie are read from row (Qt::Horizontal)
|
|
204
|
This mean whether the consecutive values of the pie are read from row (Qt::Horizontal)
|
|
205
|
or from columns (Qt::Vertical)
|
|
205
|
or from columns (Qt::Vertical)
|
|
206
|
*/
|
|
206
|
*/
|
|
207
|
void QBarModelMapper::setOrientation(Qt::Orientation orientation)
|
|
207
|
void QBarModelMapper::setOrientation(Qt::Orientation orientation)
|
|
208
|
{
|
|
208
|
{
|
|
209
|
Q_D(QBarModelMapper);
|
|
209
|
Q_D(QBarModelMapper);
|
|
210
|
d->m_orientation = orientation;
|
|
210
|
d->m_orientation = orientation;
|
|
211
|
d->initializeBarFromModel();
|
|
211
|
d->initializeBarFromModel();
|
|
212
|
}
|
|
212
|
}
|
|
213
|
|
|
213
|
|
|
214
|
/*!
|
|
214
|
/*!
|
|
215
|
Returns which section of the model is used as the data source for the first bar set
|
|
215
|
Returns which section of the model is used as the data source for the first bar set
|
|
216
|
*/
|
|
216
|
*/
|
|
217
|
int QBarModelMapper::firstBarSetSection() const
|
|
217
|
int QBarModelMapper::firstBarSetSection() const
|
|
218
|
{
|
|
218
|
{
|
|
219
|
Q_D(const QBarModelMapper);
|
|
219
|
Q_D(const QBarModelMapper);
|
|
220
|
return d->m_firstBarSetSection;
|
|
220
|
return d->m_firstBarSetSection;
|
|
221
|
}
|
|
221
|
}
|
|
222
|
|
|
222
|
|
|
223
|
/*!
|
|
223
|
/*!
|
|
224
|
Sets the model section that is used as the data source for the first bar set
|
|
224
|
Sets the model section that is used as the data source for the first bar set
|
|
225
|
Parameter \a firstBarSetSection specifies the section of the model.
|
|
225
|
Parameter \a firstBarSetSection specifies the section of the model.
|
|
226
|
*/
|
|
226
|
*/
|
|
227
|
void QBarModelMapper::setFirstBarSetSection(int firstBarSetSection)
|
|
227
|
void QBarModelMapper::setFirstBarSetSection(int firstBarSetSection)
|
|
228
|
{
|
|
228
|
{
|
|
229
|
Q_D(QBarModelMapper);
|
|
229
|
Q_D(QBarModelMapper);
|
|
230
|
d->m_firstBarSetSection = qMax(-1, firstBarSetSection);
|
|
230
|
d->m_firstBarSetSection = qMax(-1, firstBarSetSection);
|
|
231
|
d->initializeBarFromModel();
|
|
231
|
d->initializeBarFromModel();
|
|
232
|
}
|
|
232
|
}
|
|
233
|
|
|
233
|
|
|
234
|
/*!
|
|
234
|
/*!
|
|
235
|
Returns which section of the model is used as the data source for the last bar set
|
|
235
|
Returns which section of the model is used as the data source for the last bar set
|
|
236
|
*/
|
|
236
|
*/
|
|
237
|
int QBarModelMapper::lastBarSetSection() const
|
|
237
|
int QBarModelMapper::lastBarSetSection() const
|
|
238
|
{
|
|
238
|
{
|
|
239
|
Q_D(const QBarModelMapper);
|
|
239
|
Q_D(const QBarModelMapper);
|
|
240
|
return d->m_lastBarSetSection;
|
|
240
|
return d->m_lastBarSetSection;
|
|
241
|
}
|
|
241
|
}
|
|
242
|
|
|
242
|
|
|
243
|
/*!
|
|
243
|
/*!
|
|
244
|
Sets the model section that is used as the data source for the last bar set
|
|
244
|
Sets the model section that is used as the data source for the last bar set
|
|
245
|
Parameter \a lastBarSetSection specifies the section of the model.
|
|
245
|
Parameter \a lastBarSetSection specifies the section of the model.
|
|
246
|
*/
|
|
246
|
*/
|
|
247
|
void QBarModelMapper::setLastBarSetSection(int lastBarSetSection)
|
|
247
|
void QBarModelMapper::setLastBarSetSection(int lastBarSetSection)
|
|
248
|
{
|
|
248
|
{
|
|
249
|
Q_D(QBarModelMapper);
|
|
249
|
Q_D(QBarModelMapper);
|
|
250
|
d->m_lastBarSetSection = qMax(-1, lastBarSetSection);
|
|
250
|
d->m_lastBarSetSection = qMax(-1, lastBarSetSection);
|
|
251
|
d->initializeBarFromModel();
|
|
251
|
d->initializeBarFromModel();
|
|
252
|
}
|
|
252
|
}
|
|
253
|
|
|
253
|
|
|
254
|
/*!
|
|
254
|
/*!
|
|
255
|
Resets the QBarModelMapper to the default state.
|
|
255
|
Resets the QBarModelMapper to the default state.
|
|
256
|
first: 0; count: -1; firstBarSetSection: -1; lastBarSetSection: -1; categoriesSection: -1
|
|
256
|
first: 0; count: -1; firstBarSetSection: -1; lastBarSetSection: -1; categoriesSection: -1
|
|
257
|
*/
|
|
257
|
*/
|
|
258
|
void QBarModelMapper::reset()
|
|
258
|
void QBarModelMapper::reset()
|
|
259
|
{
|
|
259
|
{
|
|
260
|
Q_D(QBarModelMapper);
|
|
260
|
Q_D(QBarModelMapper);
|
|
261
|
d->m_first = 0;
|
|
261
|
d->m_first = 0;
|
|
262
|
d->m_count = -1;
|
|
262
|
d->m_count = -1;
|
|
263
|
d->m_firstBarSetSection = -1;
|
|
263
|
d->m_firstBarSetSection = -1;
|
|
264
|
d->m_lastBarSetSection = -1;
|
|
264
|
d->m_lastBarSetSection = -1;
|
|
265
|
d->initializeBarFromModel();
|
|
265
|
d->initializeBarFromModel();
|
|
266
|
}
|
|
266
|
}
|
|
267
|
|
|
267
|
|
|
268
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
268
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
269
|
|
|
269
|
|
|
270
|
QBarModelMapperPrivate::QBarModelMapperPrivate(QBarModelMapper *q) :
|
|
270
|
QBarModelMapperPrivate::QBarModelMapperPrivate(QBarModelMapper *q) :
|
|
271
|
m_series(0),
|
|
271
|
m_series(0),
|
|
272
|
m_model(0),
|
|
272
|
m_model(0),
|
|
273
|
m_first(0),
|
|
273
|
m_first(0),
|
|
274
|
m_count(-1),
|
|
274
|
m_count(-1),
|
|
275
|
m_orientation(Qt::Vertical),
|
|
275
|
m_orientation(Qt::Vertical),
|
|
276
|
m_firstBarSetSection(-1),
|
|
276
|
m_firstBarSetSection(-1),
|
|
277
|
m_lastBarSetSection(-1),
|
|
277
|
m_lastBarSetSection(-1),
|
|
278
|
m_seriesSignalsBlock(false),
|
|
278
|
m_seriesSignalsBlock(false),
|
|
279
|
m_modelSignalsBlock(false),
|
|
279
|
m_modelSignalsBlock(false),
|
|
280
|
q_ptr(q)
|
|
280
|
q_ptr(q)
|
|
281
|
{
|
|
281
|
{
|
|
282
|
}
|
|
282
|
}
|
|
283
|
|
|
283
|
|
|
284
|
void QBarModelMapperPrivate::blockModelSignals(bool block)
|
|
284
|
void QBarModelMapperPrivate::blockModelSignals(bool block)
|
|
285
|
{
|
|
285
|
{
|
|
286
|
m_modelSignalsBlock = block;
|
|
286
|
m_modelSignalsBlock = block;
|
|
287
|
}
|
|
287
|
}
|
|
288
|
|
|
288
|
|
|
289
|
void QBarModelMapperPrivate::blockSeriesSignals(bool block)
|
|
289
|
void QBarModelMapperPrivate::blockSeriesSignals(bool block)
|
|
290
|
{
|
|
290
|
{
|
|
291
|
m_seriesSignalsBlock = block;
|
|
291
|
m_seriesSignalsBlock = block;
|
|
292
|
}
|
|
292
|
}
|
|
293
|
|
|
293
|
|
|
294
|
QBarSet* QBarModelMapperPrivate::barSet(QModelIndex index)
|
|
294
|
QBarSet* QBarModelMapperPrivate::barSet(QModelIndex index)
|
|
295
|
{
|
|
295
|
{
|
|
296
|
if (!index.isValid())
|
|
296
|
if (!index.isValid())
|
|
297
|
return 0;
|
|
297
|
return 0;
|
|
298
|
|
|
298
|
|
|
299
|
if (m_orientation == Qt::Vertical && index.column() >= m_firstBarSetSection && index.column() <= m_lastBarSetSection) {
|
|
299
|
if (m_orientation == Qt::Vertical && index.column() >= m_firstBarSetSection && index.column() <= m_lastBarSetSection) {
|
|
300
|
if (index.row() >= m_first && (m_count == - 1 || index.row() < m_first + m_count)) {
|
|
300
|
if (index.row() >= m_first && (m_count == - 1 || index.row() < m_first + m_count)) {
|
|
301
|
// if (m_model->index(index.row(), m_valuesSection).isValid() && m_model->index(index.row(), m_labelsSection).isValid())
|
|
301
|
// if (m_model->index(index.row(), m_valuesSection).isValid() && m_model->index(index.row(), m_labelsSection).isValid())
|
|
302
|
return m_series->barSets().at(index.column() - m_firstBarSetSection);
|
|
302
|
return m_series->barSets().at(index.column() - m_firstBarSetSection);
|
|
303
|
// else
|
|
303
|
// else
|
|
304
|
// return 0;
|
|
304
|
// return 0;
|
|
305
|
}
|
|
305
|
}
|
|
306
|
} else if (m_orientation == Qt::Horizontal && index.row() >= m_firstBarSetSection && index.row() <= m_lastBarSetSection) {
|
|
306
|
} else if (m_orientation == Qt::Horizontal && index.row() >= m_firstBarSetSection && index.row() <= m_lastBarSetSection) {
|
|
307
|
if (index.column() >= m_first && (m_count == - 1 || index.column() < m_first + m_count))
|
|
307
|
if (index.column() >= m_first && (m_count == - 1 || index.column() < m_first + m_count))
|
|
308
|
return m_series->barSets().at(index.row() - m_firstBarSetSection);
|
|
308
|
return m_series->barSets().at(index.row() - m_firstBarSetSection);
|
|
309
|
}
|
|
309
|
}
|
|
310
|
return 0; // This part of model has not been mapped to any slice
|
|
310
|
return 0; // This part of model has not been mapped to any slice
|
|
311
|
}
|
|
311
|
}
|
|
312
|
|
|
312
|
|
|
313
|
QModelIndex QBarModelMapperPrivate::barModelIndex(int barSection, int posInBar)
|
|
313
|
QModelIndex QBarModelMapperPrivate::barModelIndex(int barSection, int posInBar)
|
|
314
|
{
|
|
314
|
{
|
|
315
|
if (m_count != -1 && posInBar >= m_count)
|
|
315
|
if (m_count != -1 && posInBar >= m_count)
|
|
316
|
return QModelIndex(); // invalid
|
|
316
|
return QModelIndex(); // invalid
|
|
317
|
|
|
317
|
|
|
318
|
if (barSection < m_firstBarSetSection || barSection > m_lastBarSetSection)
|
|
318
|
if (barSection < m_firstBarSetSection || barSection > m_lastBarSetSection)
|
|
319
|
return QModelIndex(); // invalid
|
|
319
|
return QModelIndex(); // invalid
|
|
320
|
|
|
320
|
|
|
321
|
if (m_orientation == Qt::Vertical)
|
|
321
|
if (m_orientation == Qt::Vertical)
|
|
322
|
return m_model->index(posInBar + m_first, barSection);
|
|
322
|
return m_model->index(posInBar + m_first, barSection);
|
|
323
|
else
|
|
323
|
else
|
|
324
|
return m_model->index(barSection, posInBar + m_first);
|
|
324
|
return m_model->index(barSection, posInBar + m_first);
|
|
325
|
}
|
|
325
|
}
|
|
326
|
|
|
326
|
|
|
327
|
void QBarModelMapperPrivate::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight)
|
|
327
|
void QBarModelMapperPrivate::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight)
|
|
328
|
{
|
|
328
|
{
|
|
329
|
Q_UNUSED(topLeft)
|
|
329
|
Q_UNUSED(topLeft)
|
|
330
|
Q_UNUSED(bottomRight)
|
|
330
|
Q_UNUSED(bottomRight)
|
|
331
|
|
|
331
|
|
|
332
|
if (m_model == 0 || m_series == 0)
|
|
332
|
if (m_model == 0 || m_series == 0)
|
|
333
|
return;
|
|
333
|
return;
|
|
334
|
|
|
334
|
|
|
335
|
if (m_modelSignalsBlock)
|
|
335
|
if (m_modelSignalsBlock)
|
|
336
|
return;
|
|
336
|
return;
|
|
337
|
|
|
337
|
|
|
338
|
blockSeriesSignals();
|
|
338
|
blockSeriesSignals();
|
|
339
|
QModelIndex index;
|
|
339
|
QModelIndex index;
|
|
340
|
for (int row = topLeft.row(); row <= bottomRight.row(); row++) {
|
|
340
|
for (int row = topLeft.row(); row <= bottomRight.row(); row++) {
|
|
341
|
for (int column = topLeft.column(); column <= bottomRight.column(); column++) {
|
|
341
|
for (int column = topLeft.column(); column <= bottomRight.column(); column++) {
|
|
342
|
index = topLeft.sibling(row, column);
|
|
342
|
index = topLeft.sibling(row, column);
|
|
343
|
QBarSet* bar = barSet(index);
|
|
343
|
QBarSet* bar = barSet(index);
|
|
344
|
if (bar) {
|
|
344
|
if (bar) {
|
|
345
|
if (m_orientation == Qt::Vertical)
|
|
345
|
if (m_orientation == Qt::Vertical)
|
|
346
|
bar->replace(row - m_first, m_model->data(index).toReal());
|
|
346
|
bar->replace(row - m_first, m_model->data(index).toReal());
|
|
347
|
else
|
|
347
|
else
|
|
348
|
bar->replace(column - m_first, m_model->data(index).toReal());
|
|
348
|
bar->replace(column - m_first, m_model->data(index).toReal());
|
|
349
|
}
|
|
349
|
}
|
|
350
|
}
|
|
350
|
}
|
|
351
|
}
|
|
351
|
}
|
|
352
|
blockSeriesSignals(false);
|
|
352
|
blockSeriesSignals(false);
|
|
353
|
}
|
|
353
|
}
|
|
354
|
|
|
354
|
|
|
355
|
void QBarModelMapperPrivate::modelHeaderDataUpdated(Qt::Orientation orientation, int first, int last)
|
|
355
|
void QBarModelMapperPrivate::modelHeaderDataUpdated(Qt::Orientation orientation, int first, int last)
|
|
356
|
{
|
|
356
|
{
|
|
357
|
if (m_model == 0 || m_series == 0)
|
|
357
|
if (m_model == 0 || m_series == 0)
|
|
358
|
return;
|
|
358
|
return;
|
|
359
|
|
|
359
|
|
|
360
|
if (m_modelSignalsBlock)
|
|
360
|
if (m_modelSignalsBlock)
|
|
361
|
return;
|
|
361
|
return;
|
|
362
|
|
|
362
|
|
|
363
|
blockSeriesSignals();
|
|
363
|
blockSeriesSignals();
|
|
364
|
if (orientation != m_orientation) {
|
|
364
|
if (orientation != m_orientation) {
|
|
365
|
for (int section = first; section <= last; section++) {
|
|
365
|
for (int section = first; section <= last; section++) {
|
|
366
|
if (section >= m_firstBarSetSection && section <= m_lastBarSetSection) {
|
|
366
|
if (section >= m_firstBarSetSection && section <= m_lastBarSetSection) {
|
|
367
|
QBarSet* bar = m_series->barSets().at(section - m_firstBarSetSection);
|
|
367
|
QBarSet* bar = m_series->barSets().at(section - m_firstBarSetSection);
|
|
368
|
if (bar)
|
|
368
|
if (bar)
|
|
369
|
bar->setLabel(m_model->headerData(section, orientation).toString());
|
|
369
|
bar->setLabel(m_model->headerData(section, orientation).toString());
|
|
370
|
}
|
|
370
|
}
|
|
371
|
}
|
|
371
|
}
|
|
372
|
}
|
|
372
|
}
|
|
373
|
blockSeriesSignals(false);
|
|
373
|
blockSeriesSignals(false);
|
|
374
|
}
|
|
374
|
}
|
|
375
|
|
|
375
|
|
|
376
|
void QBarModelMapperPrivate::modelRowsAdded(QModelIndex parent, int start, int end)
|
|
376
|
void QBarModelMapperPrivate::modelRowsAdded(QModelIndex parent, int start, int end)
|
|
377
|
{
|
|
377
|
{
|
|
378
|
Q_UNUSED(parent);
|
|
378
|
Q_UNUSED(parent);
|
|
379
|
Q_UNUSED(end)
|
|
379
|
Q_UNUSED(end)
|
|
380
|
if (m_modelSignalsBlock)
|
|
380
|
if (m_modelSignalsBlock)
|
|
381
|
return;
|
|
381
|
return;
|
|
382
|
|
|
382
|
|
|
383
|
blockSeriesSignals();
|
|
383
|
blockSeriesSignals();
|
|
384
|
if (m_orientation == Qt::Vertical)
|
|
384
|
if (m_orientation == Qt::Vertical)
|
|
385
|
// insertData(start, end);
|
|
385
|
// insertData(start, end);
|
|
386
|
initializeBarFromModel();
|
|
386
|
initializeBarFromModel();
|
|
387
|
else if (start <= m_firstBarSetSection || start <= m_lastBarSetSection) // if the changes affect the map - reinitialize
|
|
387
|
else if (start <= m_firstBarSetSection || start <= m_lastBarSetSection) // if the changes affect the map - reinitialize
|
|
388
|
initializeBarFromModel();
|
|
388
|
initializeBarFromModel();
|
|
389
|
blockSeriesSignals(false);
|
|
389
|
blockSeriesSignals(false);
|
|
390
|
}
|
|
390
|
}
|
|
391
|
|
|
391
|
|
|
392
|
void QBarModelMapperPrivate::modelRowsRemoved(QModelIndex parent, int start, int end)
|
|
392
|
void QBarModelMapperPrivate::modelRowsRemoved(QModelIndex parent, int start, int end)
|
|
393
|
{
|
|
393
|
{
|
|
394
|
Q_UNUSED(parent);
|
|
394
|
Q_UNUSED(parent);
|
|
395
|
Q_UNUSED(end)
|
|
395
|
Q_UNUSED(end)
|
|
396
|
if (m_modelSignalsBlock)
|
|
396
|
if (m_modelSignalsBlock)
|
|
397
|
return;
|
|
397
|
return;
|
|
398
|
|
|
398
|
|
|
399
|
blockSeriesSignals();
|
|
399
|
blockSeriesSignals();
|
|
400
|
if (m_orientation == Qt::Vertical)
|
|
400
|
if (m_orientation == Qt::Vertical)
|
|
401
|
// removeData(start, end);
|
|
401
|
// removeData(start, end);
|
|
402
|
initializeBarFromModel();
|
|
402
|
initializeBarFromModel();
|
|
403
|
else if (start <= m_firstBarSetSection || start <= m_lastBarSetSection) // if the changes affect the map - reinitialize
|
|
403
|
else if (start <= m_firstBarSetSection || start <= m_lastBarSetSection) // if the changes affect the map - reinitialize
|
|
404
|
initializeBarFromModel();
|
|
404
|
initializeBarFromModel();
|
|
405
|
blockSeriesSignals(false);
|
|
405
|
blockSeriesSignals(false);
|
|
406
|
}
|
|
406
|
}
|
|
407
|
|
|
407
|
|
|
408
|
void QBarModelMapperPrivate::modelColumnsAdded(QModelIndex parent, int start, int end)
|
|
408
|
void QBarModelMapperPrivate::modelColumnsAdded(QModelIndex parent, int start, int end)
|
|
409
|
{
|
|
409
|
{
|
|
410
|
Q_UNUSED(parent);
|
|
410
|
Q_UNUSED(parent);
|
|
411
|
Q_UNUSED(end)
|
|
411
|
Q_UNUSED(end)
|
|
412
|
if (m_modelSignalsBlock)
|
|
412
|
if (m_modelSignalsBlock)
|
|
413
|
return;
|
|
413
|
return;
|
|
414
|
|
|
414
|
|
|
415
|
blockSeriesSignals();
|
|
415
|
blockSeriesSignals();
|
|
416
|
if (m_orientation == Qt::Horizontal)
|
|
416
|
if (m_orientation == Qt::Horizontal)
|
|
417
|
// insertData(start, end);
|
|
417
|
// insertData(start, end);
|
|
418
|
initializeBarFromModel();
|
|
418
|
initializeBarFromModel();
|
|
419
|
else if (start <= m_firstBarSetSection || start <= m_lastBarSetSection) // if the changes affect the map - reinitialize
|
|
419
|
else if (start <= m_firstBarSetSection || start <= m_lastBarSetSection) // if the changes affect the map - reinitialize
|
|
420
|
initializeBarFromModel();
|
|
420
|
initializeBarFromModel();
|
|
421
|
blockSeriesSignals(false);
|
|
421
|
blockSeriesSignals(false);
|
|
422
|
}
|
|
422
|
}
|
|
423
|
|
|
423
|
|
|
424
|
void QBarModelMapperPrivate::modelColumnsRemoved(QModelIndex parent, int start, int end)
|
|
424
|
void QBarModelMapperPrivate::modelColumnsRemoved(QModelIndex parent, int start, int end)
|
|
425
|
{
|
|
425
|
{
|
|
426
|
Q_UNUSED(parent);
|
|
426
|
Q_UNUSED(parent);
|
|
427
|
Q_UNUSED(end)
|
|
427
|
Q_UNUSED(end)
|
|
428
|
if (m_modelSignalsBlock)
|
|
428
|
if (m_modelSignalsBlock)
|
|
429
|
return;
|
|
429
|
return;
|
|
430
|
|
|
430
|
|
|
431
|
blockSeriesSignals();
|
|
431
|
blockSeriesSignals();
|
|
432
|
if (m_orientation == Qt::Horizontal)
|
|
432
|
if (m_orientation == Qt::Horizontal)
|
|
433
|
// removeData(start, end);
|
|
433
|
// removeData(start, end);
|
|
434
|
initializeBarFromModel();
|
|
434
|
initializeBarFromModel();
|
|
435
|
else if (start <= m_firstBarSetSection || start <= m_lastBarSetSection) // if the changes affect the map - reinitialize
|
|
435
|
else if (start <= m_firstBarSetSection || start <= m_lastBarSetSection) // if the changes affect the map - reinitialize
|
|
436
|
initializeBarFromModel();
|
|
436
|
initializeBarFromModel();
|
|
437
|
blockSeriesSignals(false);
|
|
437
|
blockSeriesSignals(false);
|
|
438
|
}
|
|
438
|
}
|
|
439
|
|
|
439
|
|
|
440
|
void QBarModelMapperPrivate::insertData(int start, int end)
|
|
440
|
void QBarModelMapperPrivate::insertData(int start, int end)
|
|
441
|
{
|
|
441
|
{
|
|
442
|
Q_UNUSED(end)
|
|
442
|
Q_UNUSED(end)
|
|
443
|
Q_UNUSED(start)
|
|
443
|
Q_UNUSED(start)
|
|
444
|
Q_UNUSED(end)
|
|
444
|
Q_UNUSED(end)
|
|
445
|
// To be implemented
|
|
445
|
// To be implemented
|
|
446
|
}
|
|
446
|
}
|
|
447
|
|
|
447
|
|
|
448
|
void QBarModelMapperPrivate::removeData(int start, int end)
|
|
448
|
void QBarModelMapperPrivate::removeData(int start, int end)
|
|
449
|
{
|
|
449
|
{
|
|
450
|
Q_UNUSED(end)
|
|
450
|
Q_UNUSED(end)
|
|
451
|
Q_UNUSED(start)
|
|
451
|
Q_UNUSED(start)
|
|
452
|
Q_UNUSED(end)
|
|
452
|
Q_UNUSED(end)
|
|
453
|
// To be implemented
|
|
453
|
// To be implemented
|
|
454
|
}
|
|
454
|
}
|
|
455
|
|
|
455
|
|
|
456
|
void QBarModelMapperPrivate::barSetsAdded(QList<QBarSet*> sets)
|
|
456
|
void QBarModelMapperPrivate::barSetsAdded(QList<QBarSet*> sets)
|
|
457
|
{
|
|
457
|
{
|
|
458
|
if (m_seriesSignalsBlock)
|
|
458
|
if (m_seriesSignalsBlock)
|
|
459
|
return;
|
|
459
|
return;
|
|
460
|
|
|
460
|
|
|
461
|
if (sets.count() == 0)
|
|
461
|
if (sets.count() == 0)
|
|
462
|
return;
|
|
462
|
return;
|
|
463
|
|
|
463
|
|
|
464
|
int firstIndex = m_series->barSets().indexOf(sets.at(0));
|
|
464
|
int firstIndex = m_series->barSets().indexOf(sets.at(0));
|
|
465
|
if (firstIndex == -1)
|
|
465
|
if (firstIndex == -1)
|
|
466
|
return;
|
|
466
|
return;
|
|
467
|
|
|
467
|
|
|
468
|
int maxCount = 0;
|
|
468
|
int maxCount = 0;
|
|
469
|
for(int i = 0; i < sets.count(); i++)
|
|
469
|
for(int i = 0; i < sets.count(); i++)
|
|
470
|
if (sets.at(i)->count() > m_count)
|
|
470
|
if (sets.at(i)->count() > m_count)
|
|
471
|
maxCount = sets.at(i)->count();
|
|
471
|
maxCount = sets.at(i)->count();
|
|
472
|
|
|
472
|
|
|
473
|
if (m_count != -1 && m_count < maxCount)
|
|
473
|
if (m_count != -1 && m_count < maxCount)
|
|
474
|
m_count = maxCount;
|
|
474
|
m_count = maxCount;
|
|
475
|
|
|
475
|
|
|
476
|
m_lastBarSetSection += sets.count();
|
|
476
|
m_lastBarSetSection += sets.count();
|
|
477
|
|
|
477
|
|
|
478
|
blockModelSignals();
|
|
478
|
blockModelSignals();
|
|
479
|
int modelCapacity = m_orientation == Qt::Vertical ? m_model->rowCount() - m_first : m_model->columnCount() - m_first;
|
|
479
|
int modelCapacity = m_orientation == Qt::Vertical ? m_model->rowCount() - m_first : m_model->columnCount() - m_first;
|
|
480
|
if (maxCount > modelCapacity) {
|
|
480
|
if (maxCount > modelCapacity) {
|
|
481
|
if (m_orientation == Qt::Vertical)
|
|
481
|
if (m_orientation == Qt::Vertical)
|
|
482
|
m_model->insertRows(m_model->rowCount(), maxCount - modelCapacity);
|
|
482
|
m_model->insertRows(m_model->rowCount(), maxCount - modelCapacity);
|
|
483
|
else
|
|
483
|
else
|
|
484
|
m_model->insertColumns(m_model->columnCount(), maxCount - modelCapacity);
|
|
484
|
m_model->insertColumns(m_model->columnCount(), maxCount - modelCapacity);
|
|
485
|
}
|
|
485
|
}
|
|
486
|
|
|
486
|
|
|
487
|
if (m_orientation == Qt::Vertical)
|
|
487
|
if (m_orientation == Qt::Vertical)
|
|
488
|
m_model->insertColumns(firstIndex + m_firstBarSetSection, sets.count());
|
|
488
|
m_model->insertColumns(firstIndex + m_firstBarSetSection, sets.count());
|
|
489
|
else
|
|
489
|
else
|
|
490
|
m_model->insertRows(firstIndex + m_firstBarSetSection, sets.count());
|
|
490
|
m_model->insertRows(firstIndex + m_firstBarSetSection, sets.count());
|
|
491
|
|
|
491
|
|
|
492
|
|
|
492
|
|
|
493
|
for(int i = firstIndex + m_firstBarSetSection; i < firstIndex + m_firstBarSetSection + sets.count(); i++) {
|
|
493
|
for(int i = firstIndex + m_firstBarSetSection; i < firstIndex + m_firstBarSetSection + sets.count(); i++) {
|
|
494
|
m_model->setHeaderData(i, m_orientation == Qt::Vertical ? Qt::Horizontal : Qt::Vertical, sets.at(i - firstIndex - m_firstBarSetSection)->label());
|
|
494
|
m_model->setHeaderData(i, m_orientation == Qt::Vertical ? Qt::Horizontal : Qt::Vertical, sets.at(i - firstIndex - m_firstBarSetSection)->label());
|
|
495
|
for (int j = 0; j < sets.at(i - firstIndex - m_firstBarSetSection)->count(); j++)
|
|
495
|
for (int j = 0; j < sets.at(i - firstIndex - m_firstBarSetSection)->count(); j++)
|
|
496
|
m_model->setData(barModelIndex(i, j), sets.at(i - firstIndex - m_firstBarSetSection)->at(j).y());
|
|
496
|
m_model->setData(barModelIndex(i, j), sets.at(i - firstIndex - m_firstBarSetSection)->at(j).y());
|
|
497
|
}
|
|
497
|
}
|
|
498
|
blockModelSignals(false);
|
|
498
|
blockModelSignals(false);
|
|
499
|
initializeBarFromModel();
|
|
499
|
initializeBarFromModel();
|
|
500
|
}
|
|
500
|
}
|
|
501
|
|
|
501
|
|
|
502
|
void QBarModelMapperPrivate::barSetsRemoved(QList<QBarSet*> sets)
|
|
502
|
void QBarModelMapperPrivate::barSetsRemoved(QList<QBarSet*> sets)
|
|
503
|
{
|
|
503
|
{
|
|
504
|
if (m_seriesSignalsBlock)
|
|
504
|
if (m_seriesSignalsBlock)
|
|
505
|
return;
|
|
505
|
return;
|
|
506
|
|
|
506
|
|
|
507
|
if (sets.count() == 0)
|
|
507
|
if (sets.count() == 0)
|
|
508
|
return;
|
|
508
|
return;
|
|
509
|
|
|
509
|
|
|
510
|
int firstIndex = m_barSets.indexOf(sets.at(0));
|
|
510
|
int firstIndex = m_barSets.indexOf(sets.at(0));
|
|
511
|
if (firstIndex == -1)
|
|
511
|
if (firstIndex == -1)
|
|
512
|
return;
|
|
512
|
return;
|
|
513
|
|
|
513
|
|
|
514
|
m_lastBarSetSection -= sets.count();
|
|
514
|
m_lastBarSetSection -= sets.count();
|
|
515
|
|
|
515
|
|
|
516
|
for (int i = firstIndex + sets.count() - 1; i >= firstIndex; i--)
|
|
516
|
for (int i = firstIndex + sets.count() - 1; i >= firstIndex; i--)
|
|
517
|
m_barSets.removeAt(i);
|
|
517
|
m_barSets.removeAt(i);
|
|
518
|
|
|
518
|
|
|
519
|
blockModelSignals();
|
|
519
|
blockModelSignals();
|
|
520
|
if (m_orientation == Qt::Vertical)
|
|
520
|
if (m_orientation == Qt::Vertical)
|
|
521
|
m_model->removeColumns(firstIndex + m_firstBarSetSection, sets.count());
|
|
521
|
m_model->removeColumns(firstIndex + m_firstBarSetSection, sets.count());
|
|
522
|
else
|
|
522
|
else
|
|
523
|
m_model->removeRows(firstIndex + m_firstBarSetSection, sets.count());
|
|
523
|
m_model->removeRows(firstIndex + m_firstBarSetSection, sets.count());
|
|
524
|
blockModelSignals(false);
|
|
524
|
blockModelSignals(false);
|
|
525
|
initializeBarFromModel();
|
|
525
|
initializeBarFromModel();
|
|
526
|
}
|
|
526
|
}
|
|
527
|
|
|
527
|
|
|
528
|
void QBarModelMapperPrivate::valuesAdded(int index, int count)
|
|
528
|
void QBarModelMapperPrivate::valuesAdded(int index, int count)
|
|
529
|
{
|
|
529
|
{
|
|
530
|
if (m_seriesSignalsBlock)
|
|
530
|
if (m_seriesSignalsBlock)
|
|
531
|
return;
|
|
531
|
return;
|
|
532
|
|
|
532
|
|
|
533
|
if (m_count != -1)
|
|
533
|
if (m_count != -1)
|
|
534
|
m_count += count;
|
|
534
|
m_count += count;
|
|
535
|
|
|
535
|
|
|
536
|
int barSetIndex = m_barSets.indexOf(qobject_cast<QBarSet *>(QObject::sender()));
|
|
536
|
int barSetIndex = m_barSets.indexOf(qobject_cast<QBarSet *>(QObject::sender()));
|
|
537
|
|
|
537
|
|
|
538
|
blockModelSignals();
|
|
538
|
blockModelSignals();
|
|
539
|
if (m_orientation == Qt::Vertical)
|
|
539
|
if (m_orientation == Qt::Vertical)
|
|
540
|
m_model->insertRows(index + m_first, count);
|
|
540
|
m_model->insertRows(index + m_first, count);
|
|
541
|
else
|
|
541
|
else
|
|
542
|
m_model->insertColumns(index + m_first, count);
|
|
542
|
m_model->insertColumns(index + m_first, count);
|
|
543
|
|
|
543
|
|
|
544
|
for (int j = index; j < index + count; j++)
|
|
544
|
for (int j = index; j < index + count; j++)
|
|
545
|
m_model->setData(barModelIndex(barSetIndex + m_firstBarSetSection, j), m_barSets.at(barSetIndex)->at(j).y());
|
|
545
|
m_model->setData(barModelIndex(barSetIndex + m_firstBarSetSection, j), m_barSets.at(barSetIndex)->at(j).y());
|
|
546
|
|
|
546
|
|
|
547
|
blockModelSignals(false);
|
|
547
|
blockModelSignals(false);
|
|
548
|
initializeBarFromModel();
|
|
548
|
initializeBarFromModel();
|
|
549
|
}
|
|
549
|
}
|
|
550
|
|
|
550
|
|
|
551
|
void QBarModelMapperPrivate::valuesRemoved(int index, int count)
|
|
551
|
void QBarModelMapperPrivate::valuesRemoved(int index, int count)
|
|
552
|
{
|
|
552
|
{
|
|
553
|
if (m_seriesSignalsBlock)
|
|
553
|
if (m_seriesSignalsBlock)
|
|
554
|
return;
|
|
554
|
return;
|
|
555
|
|
|
555
|
|
|
556
|
if (m_count != -1)
|
|
556
|
if (m_count != -1)
|
|
557
|
m_count -= count;
|
|
557
|
m_count -= count;
|
|
558
|
|
|
558
|
|
|
559
|
blockModelSignals();
|
|
559
|
blockModelSignals();
|
|
560
|
if (m_orientation == Qt::Vertical)
|
|
560
|
if (m_orientation == Qt::Vertical)
|
|
561
|
m_model->removeRows(index + m_first, count);
|
|
561
|
m_model->removeRows(index + m_first, count);
|
|
562
|
else
|
|
562
|
else
|
|
563
|
m_model->removeColumns(index + m_first, count);
|
|
563
|
m_model->removeColumns(index + m_first, count);
|
|
564
|
|
|
564
|
|
|
565
|
blockModelSignals(false);
|
|
565
|
blockModelSignals(false);
|
|
566
|
initializeBarFromModel();
|
|
566
|
initializeBarFromModel();
|
|
567
|
}
|
|
567
|
}
|
|
568
|
|
|
568
|
|
|
569
|
void QBarModelMapperPrivate::barLabelChanged()
|
|
569
|
void QBarModelMapperPrivate::barLabelChanged()
|
|
570
|
{
|
|
570
|
{
|
|
571
|
if (m_seriesSignalsBlock)
|
|
571
|
if (m_seriesSignalsBlock)
|
|
572
|
return;
|
|
572
|
return;
|
|
573
|
|
|
573
|
|
|
574
|
int barSetIndex = m_barSets.indexOf(qobject_cast<QBarSet *>(QObject::sender()));
|
|
574
|
int barSetIndex = m_barSets.indexOf(qobject_cast<QBarSet *>(QObject::sender()));
|
|
575
|
|
|
575
|
|
|
576
|
blockModelSignals();
|
|
576
|
blockModelSignals();
|
|
577
|
m_model->setHeaderData(barSetIndex + m_firstBarSetSection, m_orientation == Qt::Vertical ? Qt::Horizontal : Qt::Vertical, m_barSets.at(barSetIndex)->label());
|
|
577
|
m_model->setHeaderData(barSetIndex + m_firstBarSetSection, m_orientation == Qt::Vertical ? Qt::Horizontal : Qt::Vertical, m_barSets.at(barSetIndex)->label());
|
|
578
|
blockModelSignals(false);
|
|
578
|
blockModelSignals(false);
|
|
579
|
initializeBarFromModel();
|
|
579
|
initializeBarFromModel();
|
|
580
|
}
|
|
580
|
}
|
|
581
|
|
|
581
|
|
|
582
|
void QBarModelMapperPrivate::barValueChanged(int index)
|
|
582
|
void QBarModelMapperPrivate::barValueChanged(int index)
|
|
583
|
{
|
|
583
|
{
|
|
584
|
if (m_seriesSignalsBlock)
|
|
584
|
if (m_seriesSignalsBlock)
|
|
585
|
return;
|
|
585
|
return;
|
|
586
|
|
|
586
|
|
|
587
|
int barSetIndex = m_barSets.indexOf(qobject_cast<QBarSet *>(QObject::sender()));
|
|
587
|
int barSetIndex = m_barSets.indexOf(qobject_cast<QBarSet *>(QObject::sender()));
|
|
588
|
|
|
588
|
|
|
589
|
blockModelSignals();
|
|
589
|
blockModelSignals();
|
|
590
|
m_model->setData(barModelIndex(barSetIndex + m_firstBarSetSection, index), m_barSets.at(barSetIndex)->at(index).y());
|
|
590
|
m_model->setData(barModelIndex(barSetIndex + m_firstBarSetSection, index), m_barSets.at(barSetIndex)->at(index).y());
|
|
591
|
blockModelSignals(false);
|
|
591
|
blockModelSignals(false);
|
|
592
|
initializeBarFromModel();
|
|
592
|
initializeBarFromModel();
|
|
593
|
}
|
|
593
|
}
|
|
594
|
|
|
594
|
|
|
595
|
void QBarModelMapperPrivate::initializeBarFromModel()
|
|
595
|
void QBarModelMapperPrivate::initializeBarFromModel()
|
|
596
|
{
|
|
596
|
{
|
|
597
|
if (m_model == 0 || m_series == 0)
|
|
597
|
if (m_model == 0 || m_series == 0)
|
|
598
|
return;
|
|
598
|
return;
|
|
599
|
|
|
599
|
|
|
600
|
blockSeriesSignals();
|
|
600
|
blockSeriesSignals();
|
|
601
|
// clear current content
|
|
601
|
// clear current content
|
|
602
|
m_series->clear();
|
|
602
|
m_series->clear();
|
|
603
|
m_barSets.clear();
|
|
603
|
m_barSets.clear();
|
|
604
|
|
|
604
|
|
|
605
|
// create the initial bar sets
|
|
605
|
// create the initial bar sets
|
|
606
|
for (int i = m_firstBarSetSection; i <= m_lastBarSetSection; i++) {
|
|
606
|
for (int i = m_firstBarSetSection; i <= m_lastBarSetSection; i++) {
|
|
607
|
int posInBar = 0;
|
|
607
|
int posInBar = 0;
|
|
608
|
QModelIndex barIndex = barModelIndex(i, posInBar);
|
|
608
|
QModelIndex barIndex = barModelIndex(i, posInBar);
|
|
609
|
// check if there is such model index
|
|
609
|
// check if there is such model index
|
|
610
|
if (barIndex.isValid()) {
|
|
610
|
if (barIndex.isValid()) {
|
|
611
|
QBarSet *barSet = new QBarSet(m_model->headerData(i, m_orientation == Qt::Vertical ? Qt::Horizontal : Qt::Vertical).toString());
|
|
611
|
QBarSet *barSet = new QBarSet(m_model->headerData(i, m_orientation == Qt::Vertical ? Qt::Horizontal : Qt::Vertical).toString());
|
|
612
|
while (barIndex.isValid()) {
|
|
612
|
while (barIndex.isValid()) {
|
|
613
|
barSet->append(m_model->data(barIndex, Qt::DisplayRole).toDouble());
|
|
613
|
barSet->append(m_model->data(barIndex, Qt::DisplayRole).toDouble());
|
|
614
|
posInBar++;
|
|
614
|
posInBar++;
|
|
615
|
barIndex = barModelIndex(i, posInBar);
|
|
615
|
barIndex = barModelIndex(i, posInBar);
|
|
616
|
}
|
|
616
|
}
|
|
617
|
connect(barSet, SIGNAL(valuesAdded(int, int)), this, SLOT(valuesAdded(int, int)));
|
|
617
|
connect(barSet, SIGNAL(valuesAdded(int, int)), this, SLOT(valuesAdded(int, int)));
|
|
618
|
connect(barSet, SIGNAL(valuesRemoved(int, int)), this, SLOT(valuesRemoved(int, int)));
|
|
618
|
connect(barSet, SIGNAL(valuesRemoved(int, int)), this, SLOT(valuesRemoved(int, int)));
|
|
619
|
connect(barSet, SIGNAL(valueChanged(int)), this, SLOT(barValueChanged(int)));
|
|
619
|
connect(barSet, SIGNAL(valueChanged(int)), this, SLOT(barValueChanged(int)));
|
|
620
|
connect(barSet, SIGNAL(labelChanged()), this, SLOT(barLabelChanged()));
|
|
620
|
connect(barSet, SIGNAL(labelChanged()), this, SLOT(barLabelChanged()));
|
|
621
|
m_series->append(barSet);
|
|
621
|
m_series->append(barSet);
|
|
622
|
m_barSets.append(barSet);
|
|
622
|
m_barSets.append(barSet);
|
|
623
|
} else {
|
|
623
|
} else {
|
|
624
|
break;
|
|
624
|
break;
|
|
625
|
}
|
|
625
|
}
|
|
626
|
}
|
|
626
|
}
|
|
627
|
blockSeriesSignals(false);
|
|
627
|
blockSeriesSignals(false);
|
|
628
|
}
|
|
628
|
}
|
|
629
|
|
|
629
|
|
|
630
|
#include "moc_qbarmodelmapper.cpp"
|
|
630
|
#include "moc_qbarmodelmapper.cpp"
|
|
631
|
#include "moc_qbarmodelmapper_p.cpp"
|
|
631
|
#include "moc_qbarmodelmapper_p.cpp"
|
|
632
|
|
|
632
|
|
|
633
|
QTCOMMERCIALCHART_END_NAMESPACE
|
|
633
|
QTCOMMERCIALCHART_END_NAMESPACE
|