|
@@
-34,8
+34,8
QPieModelMapper::QPieModelMapper(QObject *parent) :
|
|
34
|
|
|
34
|
|
|
35
|
QPieModelMapper::~QPieModelMapper()
|
|
35
|
QPieModelMapper::~QPieModelMapper()
|
|
36
|
{
|
|
36
|
{
|
|
37
|
// Q_D(QPieModelMapper);
|
|
37
|
// Q_D(QPieModelMapper);
|
|
38
|
// disconnect(d->m_model, 0, d, 0);
|
|
38
|
// disconnect(d->m_model, 0, d, 0);
|
|
39
|
}
|
|
39
|
}
|
|
40
|
|
|
40
|
|
|
41
|
QAbstractItemModel* QPieModelMapper::model() const
|
|
41
|
QAbstractItemModel* QPieModelMapper::model() const
|
|
@@
-126,29
+126,29
void QPieModelMapper::setOrientation(Qt::Orientation orientation)
|
|
126
|
d->initializePieFromModel();
|
|
126
|
d->initializePieFromModel();
|
|
127
|
}
|
|
127
|
}
|
|
128
|
|
|
128
|
|
|
129
|
int QPieModelMapper::valuesIndex() const
|
|
129
|
int QPieModelMapper::valuesSection() const
|
|
130
|
{
|
|
130
|
{
|
|
131
|
Q_D(const QPieModelMapper);
|
|
131
|
Q_D(const QPieModelMapper);
|
|
132
|
return d->m_valuesIndex;
|
|
132
|
return d->m_valuesSection;
|
|
133
|
}
|
|
133
|
}
|
|
134
|
|
|
134
|
|
|
135
|
void QPieModelMapper::setValuesIndex(int valuesIndex)
|
|
135
|
void QPieModelMapper::setValuesSection(int valuesSection)
|
|
136
|
{
|
|
136
|
{
|
|
137
|
Q_D(QPieModelMapper);
|
|
137
|
Q_D(QPieModelMapper);
|
|
138
|
d->m_valuesIndex = qMax(-1, valuesIndex);
|
|
138
|
d->m_valuesSection = qMax(-1, valuesSection);
|
|
139
|
d->initializePieFromModel();
|
|
139
|
d->initializePieFromModel();
|
|
140
|
}
|
|
140
|
}
|
|
141
|
|
|
141
|
|
|
142
|
int QPieModelMapper::labelsIndex() const
|
|
142
|
int QPieModelMapper::labelsSection() const
|
|
143
|
{
|
|
143
|
{
|
|
144
|
Q_D(const QPieModelMapper);
|
|
144
|
Q_D(const QPieModelMapper);
|
|
145
|
return d->m_labelsIndex;
|
|
145
|
return d->m_labelsSection;
|
|
146
|
}
|
|
146
|
}
|
|
147
|
|
|
147
|
|
|
148
|
void QPieModelMapper::setLabelsIndex(int labelsIndex)
|
|
148
|
void QPieModelMapper::setLabelsSection(int labelsSection)
|
|
149
|
{
|
|
149
|
{
|
|
150
|
Q_D(QPieModelMapper);
|
|
150
|
Q_D(QPieModelMapper);
|
|
151
|
d->m_labelsIndex = qMax(-1, labelsIndex);
|
|
151
|
d->m_labelsSection = qMax(-1, labelsSection);
|
|
152
|
d->initializePieFromModel();
|
|
152
|
d->initializePieFromModel();
|
|
153
|
}
|
|
153
|
}
|
|
154
|
|
|
154
|
|
|
@@
-158,8
+158,8
void QPieModelMapper::reset()
|
|
158
|
d->m_first = 0;
|
|
158
|
d->m_first = 0;
|
|
159
|
d->m_count = -1;
|
|
159
|
d->m_count = -1;
|
|
160
|
d->m_orientation = Qt::Vertical;
|
|
160
|
d->m_orientation = Qt::Vertical;
|
|
161
|
d->m_valuesIndex = -1;
|
|
161
|
d->m_valuesSection = -1;
|
|
162
|
d->m_labelsIndex = -1;
|
|
162
|
d->m_labelsSection = -1;
|
|
163
|
}
|
|
163
|
}
|
|
164
|
|
|
164
|
|
|
165
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
165
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
@@
-170,8
+170,8
QPieModelMapperPrivate::QPieModelMapperPrivate(QPieModelMapper *q) :
|
|
170
|
m_first(0),
|
|
170
|
m_first(0),
|
|
171
|
m_count(-1),
|
|
171
|
m_count(-1),
|
|
172
|
m_orientation(Qt::Vertical),
|
|
172
|
m_orientation(Qt::Vertical),
|
|
173
|
m_valuesIndex(-1),
|
|
173
|
m_valuesSection(-1),
|
|
174
|
m_labelsIndex(-1),
|
|
174
|
m_labelsSection(-1),
|
|
175
|
m_seriesSignalsBlock(false),
|
|
175
|
m_seriesSignalsBlock(false),
|
|
176
|
m_modelSignalsBlock(false),
|
|
176
|
m_modelSignalsBlock(false),
|
|
177
|
q_ptr(q)
|
|
177
|
q_ptr(q)
|
|
@@
-191,12
+191,23
void QPieModelMapperPrivate::blockSeriesSignals(bool block)
|
|
191
|
|
|
191
|
|
|
192
|
QPieSlice* QPieModelMapperPrivate::pieSlice(QModelIndex index) const
|
|
192
|
QPieSlice* QPieModelMapperPrivate::pieSlice(QModelIndex index) const
|
|
193
|
{
|
|
193
|
{
|
|
194
|
if (m_orientation == Qt::Vertical && (index.column() == m_valuesIndex || index.column() == m_labelsIndex)) {
|
|
194
|
if (!index.isValid())
|
|
195
|
if (index.row() >= m_first && (m_count == - 1 || index.row() < m_first + m_count))
|
|
195
|
return 0; // index is invalid
|
|
196
|
return m_series->slices().at(index.row() - m_first);
|
|
196
|
|
|
197
|
} else if (m_orientation == Qt::Horizontal && (index.row() == m_valuesIndex || index.row() == m_labelsIndex)) {
|
|
197
|
if (m_orientation == Qt::Vertical && (index.column() == m_valuesSection || index.column() == m_labelsSection)) {
|
|
198
|
if (index.column() >= m_first && (m_count == - 1 || index.column() < m_first + m_count))
|
|
198
|
if (index.row() >= m_first && (m_count == - 1 || index.row() < m_first + m_count)) {
|
|
199
|
return m_series->slices().at(index.column() - m_first);
|
|
199
|
if (m_model->index(index.row(), m_valuesSection).isValid() && m_model->index(index.row(), m_labelsSection).isValid())
|
|
|
|
|
200
|
return m_series->slices().at(index.row() - m_first);
|
|
|
|
|
201
|
else
|
|
|
|
|
202
|
return 0;
|
|
|
|
|
203
|
}
|
|
|
|
|
204
|
} else if (m_orientation == Qt::Horizontal && (index.row() == m_valuesSection || index.row() == m_labelsSection)) {
|
|
|
|
|
205
|
if (index.column() >= m_first && (m_count == - 1 || index.column() < m_first + m_count)) {
|
|
|
|
|
206
|
if (m_model->index(m_valuesSection, index.column()).isValid() && m_model->index(m_labelsSection, index.column()).isValid())
|
|
|
|
|
207
|
return m_series->slices().at(index.column() - m_first);
|
|
|
|
|
208
|
else
|
|
|
|
|
209
|
return 0;
|
|
|
|
|
210
|
}
|
|
200
|
}
|
|
211
|
}
|
|
201
|
return 0; // This part of model has not been mapped to any slice
|
|
212
|
return 0; // This part of model has not been mapped to any slice
|
|
202
|
}
|
|
213
|
}
|
|
@@
-207,9
+218,9
QModelIndex QPieModelMapperPrivate::valueModelIndex(int slicePos)
|
|
207
|
return QModelIndex(); // invalid
|
|
218
|
return QModelIndex(); // invalid
|
|
208
|
|
|
219
|
|
|
209
|
if (m_orientation == Qt::Vertical)
|
|
220
|
if (m_orientation == Qt::Vertical)
|
|
210
|
return m_model->index(slicePos + m_first, m_valuesIndex);
|
|
221
|
return m_model->index(slicePos + m_first, m_valuesSection);
|
|
211
|
else
|
|
222
|
else
|
|
212
|
return m_model->index(m_valuesIndex, slicePos + m_first);
|
|
223
|
return m_model->index(m_valuesSection, slicePos + m_first);
|
|
213
|
}
|
|
224
|
}
|
|
214
|
|
|
225
|
|
|
215
|
QModelIndex QPieModelMapperPrivate::labelModelIndex(int slicePos)
|
|
226
|
QModelIndex QPieModelMapperPrivate::labelModelIndex(int slicePos)
|
|
@@
-218,16
+229,16
QModelIndex QPieModelMapperPrivate::labelModelIndex(int slicePos)
|
|
218
|
return QModelIndex(); // invalid
|
|
229
|
return QModelIndex(); // invalid
|
|
219
|
|
|
230
|
|
|
220
|
if (m_orientation == Qt::Vertical)
|
|
231
|
if (m_orientation == Qt::Vertical)
|
|
221
|
return m_model->index(slicePos + m_first, m_labelsIndex);
|
|
232
|
return m_model->index(slicePos + m_first, m_labelsSection);
|
|
222
|
else
|
|
233
|
else
|
|
223
|
return m_model->index(m_labelsIndex, slicePos + m_first);
|
|
234
|
return m_model->index(m_labelsSection, slicePos + m_first);
|
|
224
|
}
|
|
235
|
}
|
|
225
|
|
|
236
|
|
|
226
|
bool QPieModelMapperPrivate::isLabelIndex(QModelIndex index) const
|
|
237
|
bool QPieModelMapperPrivate::isLabelIndex(QModelIndex index) const
|
|
227
|
{
|
|
238
|
{
|
|
228
|
if (m_orientation == Qt::Vertical && index.column() == m_labelsIndex)
|
|
239
|
if (m_orientation == Qt::Vertical && index.column() == m_labelsSection)
|
|
229
|
return true;
|
|
240
|
return true;
|
|
230
|
else if (m_orientation == Qt::Horizontal && index.row() == m_labelsIndex)
|
|
241
|
else if (m_orientation == Qt::Horizontal && index.row() == m_labelsSection)
|
|
231
|
return true;
|
|
242
|
return true;
|
|
232
|
|
|
243
|
|
|
233
|
return false;
|
|
244
|
return false;
|
|
@@
-235,9
+246,9
bool QPieModelMapperPrivate::isLabelIndex(QModelIndex index) const
|
|
235
|
|
|
246
|
|
|
236
|
bool QPieModelMapperPrivate::isValueIndex(QModelIndex index) const
|
|
247
|
bool QPieModelMapperPrivate::isValueIndex(QModelIndex index) const
|
|
237
|
{
|
|
248
|
{
|
|
238
|
if (m_orientation == Qt::Vertical && index.column() == m_valuesIndex)
|
|
249
|
if (m_orientation == Qt::Vertical && index.column() == m_valuesSection)
|
|
239
|
return true;
|
|
250
|
return true;
|
|
240
|
else if (m_orientation == Qt::Horizontal && index.row() == m_valuesIndex)
|
|
251
|
else if (m_orientation == Qt::Horizontal && index.row() == m_valuesSection)
|
|
241
|
return true;
|
|
252
|
return true;
|
|
242
|
|
|
253
|
|
|
243
|
return false;
|
|
254
|
return false;
|
|
@@
-361,7
+372,7
void QPieModelMapperPrivate::modelRowsAdded(QModelIndex parent, int start, int e
|
|
361
|
blockSeriesSignals();
|
|
372
|
blockSeriesSignals();
|
|
362
|
if (m_orientation == Qt::Vertical)
|
|
373
|
if (m_orientation == Qt::Vertical)
|
|
363
|
insertData(start, end);
|
|
374
|
insertData(start, end);
|
|
364
|
else if (start <= m_valuesIndex || start <= m_labelsIndex) // if the changes affect the map - reinitialize the pie
|
|
375
|
else if (start <= m_valuesSection || start <= m_labelsSection) // if the changes affect the map - reinitialize the pie
|
|
365
|
initializePieFromModel();
|
|
376
|
initializePieFromModel();
|
|
366
|
blockSeriesSignals(false);
|
|
377
|
blockSeriesSignals(false);
|
|
367
|
}
|
|
378
|
}
|
|
@@
-375,7
+386,7
void QPieModelMapperPrivate::modelRowsRemoved(QModelIndex parent, int start, int
|
|
375
|
blockSeriesSignals();
|
|
386
|
blockSeriesSignals();
|
|
376
|
if (m_orientation == Qt::Vertical)
|
|
387
|
if (m_orientation == Qt::Vertical)
|
|
377
|
removeData(start, end);
|
|
388
|
removeData(start, end);
|
|
378
|
else if (start <= m_valuesIndex || start <= m_labelsIndex) // if the changes affect the map - reinitialize the pie
|
|
389
|
else if (start <= m_valuesSection || start <= m_labelsSection) // if the changes affect the map - reinitialize the pie
|
|
379
|
initializePieFromModel();
|
|
390
|
initializePieFromModel();
|
|
380
|
blockSeriesSignals(false);
|
|
391
|
blockSeriesSignals(false);
|
|
381
|
}
|
|
392
|
}
|
|
@@
-389,7
+400,7
void QPieModelMapperPrivate::modelColumnsAdded(QModelIndex parent, int start, in
|
|
389
|
blockSeriesSignals();
|
|
400
|
blockSeriesSignals();
|
|
390
|
if (m_orientation == Qt::Horizontal)
|
|
401
|
if (m_orientation == Qt::Horizontal)
|
|
391
|
insertData(start, end);
|
|
402
|
insertData(start, end);
|
|
392
|
else if (start <= m_valuesIndex || start <= m_labelsIndex) // if the changes affect the map - reinitialize the pie
|
|
403
|
else if (start <= m_valuesSection || start <= m_labelsSection) // if the changes affect the map - reinitialize the pie
|
|
393
|
initializePieFromModel();
|
|
404
|
initializePieFromModel();
|
|
394
|
blockSeriesSignals(false);
|
|
405
|
blockSeriesSignals(false);
|
|
395
|
}
|
|
406
|
}
|
|
@@
-403,7
+414,7
void QPieModelMapperPrivate::modelColumnsRemoved(QModelIndex parent, int start,
|
|
403
|
blockSeriesSignals();
|
|
414
|
blockSeriesSignals();
|
|
404
|
if (m_orientation == Qt::Horizontal)
|
|
415
|
if (m_orientation == Qt::Horizontal)
|
|
405
|
removeData(start, end);
|
|
416
|
removeData(start, end);
|
|
406
|
else if (start <= m_valuesIndex || start <= m_labelsIndex) // if the changes affect the map - reinitialize the pie
|
|
417
|
else if (start <= m_valuesSection || start <= m_labelsSection) // if the changes affect the map - reinitialize the pie
|
|
407
|
initializePieFromModel();
|
|
418
|
initializePieFromModel();
|
|
408
|
blockSeriesSignals(false);
|
|
419
|
blockSeriesSignals(false);
|
|
409
|
}
|
|
420
|
}
|
|
@@
-422,14
+433,18
void QPieModelMapperPrivate::insertData(int start, int end)
|
|
422
|
int first = qMax(start, m_first);
|
|
433
|
int first = qMax(start, m_first);
|
|
423
|
int last = qMin(first + addedCount - 1, m_orientation == Qt::Vertical ? m_model->rowCount() - 1 : m_model->columnCount() - 1);
|
|
434
|
int last = qMin(first + addedCount - 1, m_orientation == Qt::Vertical ? m_model->rowCount() - 1 : m_model->columnCount() - 1);
|
|
424
|
for (int i = first; i <= last; i++) {
|
|
435
|
for (int i = first; i <= last; i++) {
|
|
425
|
QPieSlice *slice = new QPieSlice;
|
|
436
|
QModelIndex valueIndex = valueModelIndex(i - m_first);
|
|
426
|
slice->setValue(m_model->data(valueModelIndex(i - m_first), Qt::DisplayRole).toDouble());
|
|
437
|
QModelIndex labelIndex = labelModelIndex(i - m_first);
|
|
427
|
slice->setLabel(m_model->data(labelModelIndex(i - m_first), Qt::DisplayRole).toString());
|
|
438
|
if (valueIndex.isValid() && labelIndex.isValid()) {
|
|
428
|
slice->setLabelVisible();
|
|
439
|
QPieSlice *slice = new QPieSlice;
|
|
429
|
connect(slice, SIGNAL(labelChanged()), this, SLOT(sliceLabelChanged()));
|
|
440
|
slice->setValue(m_model->data(valueIndex, Qt::DisplayRole).toDouble());
|
|
430
|
connect(slice, SIGNAL(valueChanged()), this, SLOT(sliceValueChanged()));
|
|
441
|
slice->setLabel(m_model->data(labelIndex, Qt::DisplayRole).toString());
|
|
431
|
m_series->insert(i - m_first, slice);
|
|
442
|
slice->setLabelVisible();
|
|
432
|
m_slices.insert(i - m_first, slice);
|
|
443
|
connect(slice, SIGNAL(labelChanged()), this, SLOT(sliceLabelChanged()));
|
|
|
|
|
444
|
connect(slice, SIGNAL(valueChanged()), this, SLOT(sliceValueChanged()));
|
|
|
|
|
445
|
m_series->insert(i - m_first, slice);
|
|
|
|
|
446
|
m_slices.insert(i - m_first, slice);
|
|
|
|
|
447
|
}
|
|
433
|
}
|
|
448
|
}
|
|
434
|
|
|
449
|
|
|
435
|
// remove excess of slices (abouve m_count)
|
|
450
|
// remove excess of slices (abouve m_count)
|
|
@@
-468,17
+483,16
void QPieModelMapperPrivate::removeData(int start, int end)
|
|
468
|
int currentSize = m_series->slices().size();
|
|
483
|
int currentSize = m_series->slices().size();
|
|
469
|
if (toBeAdded > 0)
|
|
484
|
if (toBeAdded > 0)
|
|
470
|
for (int i = m_series->slices().size(); i < currentSize + toBeAdded; i++) {
|
|
485
|
for (int i = m_series->slices().size(); i < currentSize + toBeAdded; i++) {
|
|
471
|
QPieSlice *slice = new QPieSlice;
|
|
486
|
QModelIndex valueIndex = valueModelIndex(i - m_first);
|
|
472
|
if (m_orientation == Qt::Vertical) {
|
|
487
|
QModelIndex labelIndex = labelModelIndex(i - m_first);
|
|
473
|
slice->setValue(m_model->data(m_model->index(i + m_first, m_valuesIndex), Qt::DisplayRole).toDouble());
|
|
488
|
if (valueIndex.isValid() && labelIndex.isValid()) {
|
|
474
|
slice->setLabel(m_model->data(m_model->index(i + m_first, m_labelsIndex), Qt::DisplayRole).toString());
|
|
489
|
QPieSlice *slice = new QPieSlice;
|
|
475
|
} else {
|
|
490
|
slice->setValue(m_model->data(valueIndex, Qt::DisplayRole).toDouble());
|
|
476
|
slice->setValue(m_model->data(m_model->index(m_valuesIndex, i + m_first), Qt::DisplayRole).toDouble());
|
|
491
|
slice->setLabel(m_model->data(labelIndex, Qt::DisplayRole).toString());
|
|
477
|
slice->setLabel(m_model->data(m_model->index(m_labelsIndex, i + m_first), Qt::DisplayRole).toString());
|
|
492
|
slice->setLabelVisible();
|
|
|
|
|
493
|
m_series->insert(i, slice);
|
|
|
|
|
494
|
m_slices.insert(i, slice);
|
|
478
|
}
|
|
495
|
}
|
|
479
|
slice->setLabelVisible();
|
|
|
|
|
480
|
m_series->insert(i, slice);
|
|
|
|
|
481
|
m_slices.insert(i, slice);
|
|
|
|
|
482
|
}
|
|
496
|
}
|
|
483
|
}
|
|
497
|
}
|
|
484
|
}
|
|
498
|
}
|