##// END OF EJS Templates
Copyright header changes...
Copyright header changes Copyright header changes for Qt 5.5. Change-Id: I2b8e9356997de2c87a7436bcefd4d0948d566259 Reviewed-by: Miikka Heikkinen <miikka.heikkinen@theqtcompany.com>

File last commit:

r2776:bc1f6aa59d42
r2776:bc1f6aa59d42
Show More
qpiemodelmapper.cpp
566 lines | 18.4 KiB | text/x-c | CppLexer
/ src / charts / piechart / qpiemodelmapper.cpp
Marek Rosa
Added license text to piemodelmapper classes
r1309 /****************************************************************************
**
Titta Heikkala
Copyright header changes...
r2776 ** Copyright (C) 2015 The Qt Company Ltd
Marek Rosa
Added license text to piemodelmapper classes
r1309 ** All rights reserved.
Titta Heikkala
Copyright header changes...
r2776 ** For any questions to The Qt Company, please use contact form at http://qt.io
Marek Rosa
Added license text to piemodelmapper classes
r1309 **
Titta Heikkala
Updated license headers...
r2740 ** This file is part of the Qt Charts module.
Marek Rosa
Added license text to piemodelmapper classes
r1309 **
Titta Heikkala
Updated license headers...
r2740 ** Licensees holding valid commercial license for Qt may use this file in
** accordance with the Qt License Agreement provided with the Software
** or, alternatively, in accordance with the terms contained in a written
Titta Heikkala
Copyright header changes...
r2776 ** agreement between you and The Qt Company.
Marek Rosa
Added license text to piemodelmapper classes
r1309 **
** If you have questions regarding the use of this file, please use
Titta Heikkala
Updated license headers...
r2740 ** contact form at http://qt.io
Marek Rosa
Added license text to piemodelmapper classes
r1309 **
****************************************************************************/
Titta Heikkala
Fix include syntax...
r2714 #include <QtCharts/QPieModelMapper>
#include <private/qpiemodelmapper_p.h>
#include <QtCharts/QPieSeries>
#include <QtCharts/QPieSlice>
#include <QtCore/QAbstractItemModel>
Marek Rosa
Mapper class added for xyseries and pieseries. Model support commented out for barseries for now.
r1164
Titta Heikkala
Qt Charts project file structure change...
r2712 QT_CHARTS_BEGIN_NAMESPACE
Marek Rosa
Mapper class added for xyseries and pieseries. Model support commented out for barseries for now.
r1164
Jani Honkonen
src folder: another massive victory for coding style police
r2131 QPieModelMapper::QPieModelMapper(QObject *parent)
: QObject(parent),
d_ptr(new QPieModelMapperPrivate(this))
Marek Rosa
Mapper class added for xyseries and pieseries. Model support commented out for barseries for now.
r1164 {
}
Jani Honkonen
more coding style fixes for src-folder...
r2104 QAbstractItemModel *QPieModelMapper::model() const
Marek Rosa
All model related methods and members removed from the series. QML stuff commented out where complaining
r1230 {
Q_D(const QPieModelMapper);
return d->m_model;
}
void QPieModelMapper::setModel(QAbstractItemModel *model)
{
if (model == 0)
return;
Q_D(QPieModelMapper);
if (d->m_model) {
disconnect(d->m_model, 0, d, 0);
}
d->m_model = model;
d->initializePieFromModel();
// connect signals from the model
connect(d->m_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), d, SLOT(modelUpdated(QModelIndex,QModelIndex)));
connect(d->m_model, SIGNAL(rowsInserted(QModelIndex,int,int)), d, SLOT(modelRowsAdded(QModelIndex,int,int)));
connect(d->m_model, SIGNAL(rowsRemoved(QModelIndex,int,int)), d, SLOT(modelRowsRemoved(QModelIndex,int,int)));
connect(d->m_model, SIGNAL(columnsInserted(QModelIndex,int,int)), d, SLOT(modelColumnsAdded(QModelIndex,int,int)));
connect(d->m_model, SIGNAL(columnsRemoved(QModelIndex,int,int)), d, SLOT(modelColumnsRemoved(QModelIndex,int,int)));
Marek Rosa
Model mappers now connected to series and model destroy signals
r1656 connect(d->m_model, SIGNAL(destroyed()), d, SLOT(handleModelDestroyed()));
Marek Rosa
All model related methods and members removed from the series. QML stuff commented out where complaining
r1230 }
Jani Honkonen
more coding style fixes for src-folder...
r2104 QPieSeries *QPieModelMapper::series() const
Marek Rosa
All model related methods and members removed from the series. QML stuff commented out where complaining
r1230 {
Q_D(const QPieModelMapper);
return d->m_series;
}
void QPieModelMapper::setSeries(QPieSeries *series)
{
Q_D(QPieModelMapper);
if (d->m_series) {
disconnect(d->m_series, 0, d, 0);
}
Marek Rosa
Added Vertical and Horizontal QXYModelMapper
r1252 if (series == 0)
return;
Marek Rosa
All model related methods and members removed from the series. QML stuff commented out where complaining
r1230 d->m_series = series;
d->initializePieFromModel();
// connect the signals from the series
Marek Rosa
Refactored PieSeriesModelMapper
r1231 connect(d->m_series, SIGNAL(added(QList<QPieSlice*>)), d, SLOT(slicesAdded(QList<QPieSlice*>)));
connect(d->m_series, SIGNAL(removed(QList<QPieSlice*>)), d, SLOT(slicesRemoved(QList<QPieSlice*>)));
Marek Rosa
Model mappers now connected to series and model destroy signals
r1656 connect(d->m_series, SIGNAL(destroyed()), d, SLOT(handleSeriesDestroyed()));
Marek Rosa
All model related methods and members removed from the series. QML stuff commented out where complaining
r1230 }
Marek Rosa
PieModelMapper properties first and count moved to Vertical and Horizontal mappers with more descriptive names
r1499 /*!
Defines which row/column of the model contains the first slice value.
Minimal and default value is: 0
*/
Marek Rosa
Mapper class added for xyseries and pieseries. Model support commented out for barseries for now.
r1164 int QPieModelMapper::first() const
{
Marek Rosa
ModelMapper proposal
r1229 Q_D(const QPieModelMapper);
return d->m_first;
Marek Rosa
Mapper class added for xyseries and pieseries. Model support commented out for barseries for now.
r1164 }
Marek Rosa
PieModelMapper properties first and count moved to Vertical and Horizontal mappers with more descriptive names
r1499 /*!
Sets which row/column of the model contains the \a first slice value.
Minimal and default value is: 0
*/
Marek Rosa
Mapper class added for xyseries and pieseries. Model support commented out for barseries for now.
r1164 void QPieModelMapper::setFirst(int first)
{
Marek Rosa
ModelMapper proposal
r1229 Q_D(QPieModelMapper);
Marek Rosa
PieModelMapper properties first and count moved to Vertical and Horizontal mappers with more descriptive names
r1499 d->m_first = qMax(first, 0);
d->initializePieFromModel();
Marek Rosa
Mapper class added for xyseries and pieseries. Model support commented out for barseries for now.
r1164 }
Marek Rosa
PieModelMapper properties first and count moved to Vertical and Horizontal mappers with more descriptive names
r1499 /*!
Defines the number of rows/columns of the model that are mapped as the data for QPieSeries
Minimal and default value is: -1 (count limited by the number of rows/columns in the model)
*/
Marek Rosa
Mapper class added for xyseries and pieseries. Model support commented out for barseries for now.
r1164 int QPieModelMapper::count() const
{
Marek Rosa
ModelMapper proposal
r1229 Q_D(const QPieModelMapper);
return d->m_count;
Marek Rosa
Mapper class added for xyseries and pieseries. Model support commented out for barseries for now.
r1164 }
Marek Rosa
PieModelMapper properties first and count moved to Vertical and Horizontal mappers with more descriptive names
r1499 /*!
Defines the \a count of rows/columns of the model that are mapped as the data for QPieSeries
Minimal and default value is: -1 (count limited by the number of rows/columns in the model)
*/
Marek Rosa
Mapper class added for xyseries and pieseries. Model support commented out for barseries for now.
r1164 void QPieModelMapper::setCount(int count)
{
Marek Rosa
ModelMapper proposal
r1229 Q_D(QPieModelMapper);
Marek Rosa
PieModelMapper properties first and count moved to Vertical and Horizontal mappers with more descriptive names
r1499 d->m_count = qMax(count, -1);
d->initializePieFromModel();
Marek Rosa
Mapper class added for xyseries and pieseries. Model support commented out for barseries for now.
r1164 }
Marek Rosa
Added documentation for PieModelMapper classes
r1340 /*!
Returns the orientation that is used when QPieModelMapper accesses the model.
This mean whether the consecutive values/labels of the pie are read from row (Qt::Horizontal)
or from columns (Qt::Vertical)
*/
Marek Rosa
Mapper class added for xyseries and pieseries. Model support commented out for barseries for now.
r1164 Qt::Orientation QPieModelMapper::orientation() const
{
Marek Rosa
ModelMapper proposal
r1229 Q_D(const QPieModelMapper);
return d->m_orientation;
Marek Rosa
Mapper class added for xyseries and pieseries. Model support commented out for barseries for now.
r1164 }
Marek Rosa
Added documentation for PieModelMapper classes
r1340 /*!
Returns the \a orientation that is used when QPieModelMapper accesses the model.
This mean whether the consecutive values/labels of the pie are read from row (Qt::Horizontal)
or from columns (Qt::Vertical)
*/
Marek Rosa
Mapper class added for xyseries and pieseries. Model support commented out for barseries for now.
r1164 void QPieModelMapper::setOrientation(Qt::Orientation orientation)
{
Marek Rosa
ModelMapper proposal
r1229 Q_D(QPieModelMapper);
d->m_orientation = orientation;
Marek Rosa
All model related methods and members removed from the series. QML stuff commented out where complaining
r1230 d->initializePieFromModel();
Marek Rosa
Mapper class added for xyseries and pieseries. Model support commented out for barseries for now.
r1164 }
Marek Rosa
Added documentation for PieModelMapper classes
r1340 /*!
Returns which section of the model is kept in sync with the values of the pie's slices
*/
Marek Rosa
Fixed problem with PieModelMapper
r1320 int QPieModelMapper::valuesSection() const
Marek Rosa
Mapper class added for xyseries and pieseries. Model support commented out for barseries for now.
r1164 {
Marek Rosa
ModelMapper proposal
r1229 Q_D(const QPieModelMapper);
Marek Rosa
Fixed problem with PieModelMapper
r1320 return d->m_valuesSection;
Marek Rosa
Mapper class added for xyseries and pieseries. Model support commented out for barseries for now.
r1164 }
Marek Rosa
Added documentation for PieModelMapper classes
r1340 /*!
Sets the model section that is kept in sync with the pie slices values.
Parameter \a valuesSection specifies the section of the model.
*/
Marek Rosa
Fixed problem with PieModelMapper
r1320 void QPieModelMapper::setValuesSection(int valuesSection)
Marek Rosa
Mapper class added for xyseries and pieseries. Model support commented out for barseries for now.
r1164 {
Marek Rosa
ModelMapper proposal
r1229 Q_D(QPieModelMapper);
Marek Rosa
Fixed problem with PieModelMapper
r1320 d->m_valuesSection = qMax(-1, valuesSection);
Marek Rosa
All model related methods and members removed from the series. QML stuff commented out where complaining
r1230 d->initializePieFromModel();
Marek Rosa
Mapper class added for xyseries and pieseries. Model support commented out for barseries for now.
r1164 }
Marek Rosa
Added documentation for PieModelMapper classes
r1340 /*!
Returns which section of the model is kept in sync with the labels of the pie's slices
*/
Marek Rosa
Fixed problem with PieModelMapper
r1320 int QPieModelMapper::labelsSection() const
Marek Rosa
Mapper class added for xyseries and pieseries. Model support commented out for barseries for now.
r1164 {
Marek Rosa
ModelMapper proposal
r1229 Q_D(const QPieModelMapper);
Marek Rosa
Fixed problem with PieModelMapper
r1320 return d->m_labelsSection;
Marek Rosa
Mapper class added for xyseries and pieseries. Model support commented out for barseries for now.
r1164 }
Marek Rosa
Added documentation for PieModelMapper classes
r1340 /*!
Sets the model section that is kept in sync with the pie slices labels.
Parameter \a labelsSection specifies the section of the model.
*/
Marek Rosa
Fixed problem with PieModelMapper
r1320 void QPieModelMapper::setLabelsSection(int labelsSection)
Marek Rosa
Mapper class added for xyseries and pieseries. Model support commented out for barseries for now.
r1164 {
Marek Rosa
ModelMapper proposal
r1229 Q_D(QPieModelMapper);
Marek Rosa
Fixed problem with PieModelMapper
r1320 d->m_labelsSection = qMax(-1, labelsSection);
Marek Rosa
All model related methods and members removed from the series. QML stuff commented out where complaining
r1230 d->initializePieFromModel();
Marek Rosa
Mapper class added for xyseries and pieseries. Model support commented out for barseries for now.
r1164 }
Marek Rosa
ModelMapper proposal
r1229 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
QPieModelMapperPrivate::QPieModelMapperPrivate(QPieModelMapper *q) :
Marek Rosa
Added QDonutGroup class
r1671 QObject(q),
Tero Ahola
Added new model mappers for pie to QML api
r1249 m_series(0),
m_model(0),
m_first(0),
m_count(-1),
m_orientation(Qt::Vertical),
Marek Rosa
Fixed problem with PieModelMapper
r1320 m_valuesSection(-1),
m_labelsSection(-1),
Tero Ahola
Added new model mappers for pie to QML api
r1249 m_seriesSignalsBlock(false),
m_modelSignalsBlock(false),
Marek Rosa
ModelMapper proposal
r1229 q_ptr(q)
Marek Rosa
Mapper class added for xyseries and pieseries. Model support commented out for barseries for now.
r1164 {
Marek Rosa
Refactored PieSeriesModelMapper
r1231 }
void QPieModelMapperPrivate::blockModelSignals(bool block)
{
m_modelSignalsBlock = block;
}
void QPieModelMapperPrivate::blockSeriesSignals(bool block)
{
m_seriesSignalsBlock = block;
Marek Rosa
Mapper class added for xyseries and pieseries. Model support commented out for barseries for now.
r1164 }
Marek Rosa
ModelMapper proposal
r1229
Jani Honkonen
more coding style fixes for src-folder...
r2104 QPieSlice *QPieModelMapperPrivate::pieSlice(QModelIndex index) const
Marek Rosa
All model related methods and members removed from the series. QML stuff commented out where complaining
r1230 {
Marek Rosa
Fixed problem with PieModelMapper
r1320 if (!index.isValid())
return 0; // index is invalid
if (m_orientation == Qt::Vertical && (index.column() == m_valuesSection || index.column() == m_labelsSection)) {
if (index.row() >= m_first && (m_count == - 1 || index.row() < m_first + m_count)) {
if (m_model->index(index.row(), m_valuesSection).isValid() && m_model->index(index.row(), m_labelsSection).isValid())
return m_series->slices().at(index.row() - m_first);
else
return 0;
}
} else if (m_orientation == Qt::Horizontal && (index.row() == m_valuesSection || index.row() == m_labelsSection)) {
if (index.column() >= m_first && (m_count == - 1 || index.column() < m_first + m_count)) {
if (m_model->index(m_valuesSection, index.column()).isValid() && m_model->index(m_labelsSection, index.column()).isValid())
return m_series->slices().at(index.column() - m_first);
else
return 0;
}
Marek Rosa
All model related methods and members removed from the series. QML stuff commented out where complaining
r1230 }
return 0; // This part of model has not been mapped to any slice
Marek Rosa
ModelMapper proposal
r1229 }
Marek Rosa
All model related methods and members removed from the series. QML stuff commented out where complaining
r1230 QModelIndex QPieModelMapperPrivate::valueModelIndex(int slicePos)
Marek Rosa
ModelMapper proposal
r1229 {
Marek Rosa
All model related methods and members removed from the series. QML stuff commented out where complaining
r1230 if (m_count != -1 && slicePos >= m_count)
return QModelIndex(); // invalid
Marek Rosa
ModelMapper proposal
r1229
Marek Rosa
All model related methods and members removed from the series. QML stuff commented out where complaining
r1230 if (m_orientation == Qt::Vertical)
Marek Rosa
Fixed problem with PieModelMapper
r1320 return m_model->index(slicePos + m_first, m_valuesSection);
Marek Rosa
All model related methods and members removed from the series. QML stuff commented out where complaining
r1230 else
Marek Rosa
Fixed problem with PieModelMapper
r1320 return m_model->index(m_valuesSection, slicePos + m_first);
Marek Rosa
All model related methods and members removed from the series. QML stuff commented out where complaining
r1230 }
Marek Rosa
ModelMapper proposal
r1229
Marek Rosa
All model related methods and members removed from the series. QML stuff commented out where complaining
r1230 QModelIndex QPieModelMapperPrivate::labelModelIndex(int slicePos)
{
if (m_count != -1 && slicePos >= m_count)
return QModelIndex(); // invalid
if (m_orientation == Qt::Vertical)
Marek Rosa
Fixed problem with PieModelMapper
r1320 return m_model->index(slicePos + m_first, m_labelsSection);
Marek Rosa
All model related methods and members removed from the series. QML stuff commented out where complaining
r1230 else
Marek Rosa
Fixed problem with PieModelMapper
r1320 return m_model->index(m_labelsSection, slicePos + m_first);
Marek Rosa
ModelMapper proposal
r1229 }
Marek Rosa
Small fixes to piemodelmapper and one more test
r1251 bool QPieModelMapperPrivate::isLabelIndex(QModelIndex index) const
{
Marek Rosa
Fixed problem with PieModelMapper
r1320 if (m_orientation == Qt::Vertical && index.column() == m_labelsSection)
Marek Rosa
Small fixes to piemodelmapper and one more test
r1251 return true;
Marek Rosa
Fixed problem with PieModelMapper
r1320 else if (m_orientation == Qt::Horizontal && index.row() == m_labelsSection)
Marek Rosa
Small fixes to piemodelmapper and one more test
r1251 return true;
return false;
}
bool QPieModelMapperPrivate::isValueIndex(QModelIndex index) const
{
Marek Rosa
Fixed problem with PieModelMapper
r1320 if (m_orientation == Qt::Vertical && index.column() == m_valuesSection)
Marek Rosa
Small fixes to piemodelmapper and one more test
r1251 return true;
Marek Rosa
Fixed problem with PieModelMapper
r1320 else if (m_orientation == Qt::Horizontal && index.row() == m_valuesSection)
Marek Rosa
Small fixes to piemodelmapper and one more test
r1251 return true;
return false;
}
Jani Honkonen
more coding style fixes for src-folder...
r2104 void QPieModelMapperPrivate::slicesAdded(QList<QPieSlice *> slices)
Marek Rosa
ModelMapper proposal
r1229 {
Marek Rosa
Refactored PieSeriesModelMapper
r1231 if (m_seriesSignalsBlock)
return;
if (slices.count() == 0)
return;
int firstIndex = m_series->slices().indexOf(slices.at(0));
if (firstIndex == -1)
return;
Marek Rosa
QPieModelMapper: added support for labelChanged and valueChanged signals from the slice
r1236 if (m_count != -1)
m_count += slices.count();
for (int i = firstIndex; i < firstIndex + slices.count(); i++) {
m_slices.insert(i, slices.at(i - firstIndex));
connect(slices.at(i - firstIndex), SIGNAL(labelChanged()), this, SLOT(sliceLabelChanged()));
connect(slices.at(i - firstIndex), SIGNAL(valueChanged()), this, SLOT(sliceValueChanged()));
}
Marek Rosa
Refactored PieSeriesModelMapper
r1231 blockModelSignals();
if (m_orientation == Qt::Vertical)
m_model->insertRows(firstIndex + m_first, slices.count());
else
m_model->insertColumns(firstIndex + m_first, slices.count());
Jani Honkonen
astyle and manual coding style fixes for src-folder
r2097 for (int i = firstIndex; i < firstIndex + slices.count(); i++) {
Marek Rosa
Refactored PieSeriesModelMapper
r1231 m_model->setData(valueModelIndex(i), slices.at(i - firstIndex)->value());
m_model->setData(labelModelIndex(i), slices.at(i - firstIndex)->label());
}
blockModelSignals(false);
Marek Rosa
ModelMapper proposal
r1229 }
Jani Honkonen
more coding style fixes for src-folder...
r2104 void QPieModelMapperPrivate::slicesRemoved(QList<QPieSlice *> slices)
Marek Rosa
ModelMapper proposal
r1229 {
Marek Rosa
Refactored PieSeriesModelMapper
r1231 if (m_seriesSignalsBlock)
return;
if (slices.count() == 0)
return;
Marek Rosa
QPieModelMapper: added support for labelChanged and valueChanged signals from the slice
r1236 int firstIndex = m_slices.indexOf(slices.at(0));
Marek Rosa
Refactored PieSeriesModelMapper
r1231 if (firstIndex == -1)
return;
Marek Rosa
QPieModelMapper: added support for labelChanged and valueChanged signals from the slice
r1236 if (m_count != -1)
m_count -= slices.count();
for (int i = firstIndex + slices.count() - 1; i >= firstIndex; i--)
m_slices.removeAt(i);
Marek Rosa
Refactored PieSeriesModelMapper
r1231 blockModelSignals();
if (m_orientation == Qt::Vertical)
m_model->removeRows(firstIndex + m_first, slices.count());
else
m_model->removeColumns(firstIndex + m_first, slices.count());
blockModelSignals(false);
Marek Rosa
ModelMapper proposal
r1229 }
Marek Rosa
QPieModelMapper: added support for labelChanged and valueChanged signals from the slice
r1236 void QPieModelMapperPrivate::sliceLabelChanged()
Marek Rosa
ModelMapper proposal
r1229 {
Marek Rosa
QPieModelMapper: added support for labelChanged and valueChanged signals from the slice
r1236 if (m_seriesSignalsBlock)
return;
Marek Rosa
Refactored PieSeriesModelMapper
r1231 blockModelSignals();
Marek Rosa
QPieModelMapper: added support for labelChanged and valueChanged signals from the slice
r1236 QPieSlice *slice = qobject_cast<QPieSlice *>(QObject::sender());
m_model->setData(labelModelIndex(m_series->slices().indexOf(slice)), slice->label());
blockModelSignals(false);
}
void QPieModelMapperPrivate::sliceValueChanged()
{
if (m_seriesSignalsBlock)
return;
blockModelSignals();
QPieSlice *slice = qobject_cast<QPieSlice *>(QObject::sender());
m_model->setData(valueModelIndex(m_series->slices().indexOf(slice)), slice->value());
Marek Rosa
Refactored PieSeriesModelMapper
r1231 blockModelSignals(false);
Marek Rosa
ModelMapper proposal
r1229 }
Marek Rosa
Model mappers now connected to series and model destroy signals
r1656 void QPieModelMapperPrivate::handleSeriesDestroyed()
{
m_series = 0;
}
Marek Rosa
ModelMapper proposal
r1229 void QPieModelMapperPrivate::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight)
{
Marek Rosa
Fix to pie model mapper
r1258 if (m_model == 0 || m_series == 0)
return;
Marek Rosa
Refactored PieSeriesModelMapper
r1231 if (m_modelSignalsBlock)
return;
blockSeriesSignals();
Marek Rosa
All model related methods and members removed from the series. QML stuff commented out where complaining
r1230 QModelIndex index;
QPieSlice *slice;
Marek Rosa
ModelMapper proposal
r1229 for (int row = topLeft.row(); row <= bottomRight.row(); row++) {
for (int column = topLeft.column(); column <= bottomRight.column(); column++) {
Marek Rosa
All model related methods and members removed from the series. QML stuff commented out where complaining
r1230 index = topLeft.sibling(row, column);
slice = pieSlice(index);
if (slice) {
Marek Rosa
Small fixes to piemodelmapper and one more test
r1251 if (isValueIndex(index))
slice->setValue(m_model->data(index, Qt::DisplayRole).toReal());
if (isLabelIndex(index))
slice->setLabel(m_model->data(index, Qt::DisplayRole).toString());
Marek Rosa
ModelMapper proposal
r1229 }
Marek Rosa
All model related methods and members removed from the series. QML stuff commented out where complaining
r1230 }
}
Marek Rosa
Refactored PieSeriesModelMapper
r1231 blockSeriesSignals(false);
Marek Rosa
All model related methods and members removed from the series. QML stuff commented out where complaining
r1230 }
void QPieModelMapperPrivate::modelRowsAdded(QModelIndex parent, int start, int end)
{
Q_UNUSED(parent);
Marek Rosa
Refactored PieSeriesModelMapper
r1231 if (m_modelSignalsBlock)
return;
blockSeriesSignals();
Marek Rosa
All model related methods and members removed from the series. QML stuff commented out where complaining
r1230 if (m_orientation == Qt::Vertical)
insertData(start, end);
Marek Rosa
Fixed problem with PieModelMapper
r1320 else if (start <= m_valuesSection || start <= m_labelsSection) // if the changes affect the map - reinitialize the pie
Marek Rosa
All model related methods and members removed from the series. QML stuff commented out where complaining
r1230 initializePieFromModel();
Marek Rosa
Refactored PieSeriesModelMapper
r1231 blockSeriesSignals(false);
Marek Rosa
All model related methods and members removed from the series. QML stuff commented out where complaining
r1230 }
void QPieModelMapperPrivate::modelRowsRemoved(QModelIndex parent, int start, int end)
{
Q_UNUSED(parent);
Marek Rosa
Refactored PieSeriesModelMapper
r1231 if (m_modelSignalsBlock)
return;
blockSeriesSignals();
Marek Rosa
All model related methods and members removed from the series. QML stuff commented out where complaining
r1230 if (m_orientation == Qt::Vertical)
removeData(start, end);
Marek Rosa
Fixed problem with PieModelMapper
r1320 else if (start <= m_valuesSection || start <= m_labelsSection) // if the changes affect the map - reinitialize the pie
Marek Rosa
All model related methods and members removed from the series. QML stuff commented out where complaining
r1230 initializePieFromModel();
Marek Rosa
Refactored PieSeriesModelMapper
r1231 blockSeriesSignals(false);
Marek Rosa
All model related methods and members removed from the series. QML stuff commented out where complaining
r1230 }
void QPieModelMapperPrivate::modelColumnsAdded(QModelIndex parent, int start, int end)
{
Q_UNUSED(parent);
Marek Rosa
Refactored PieSeriesModelMapper
r1231 if (m_modelSignalsBlock)
return;
blockSeriesSignals();
Marek Rosa
All model related methods and members removed from the series. QML stuff commented out where complaining
r1230 if (m_orientation == Qt::Horizontal)
insertData(start, end);
Marek Rosa
Fixed problem with PieModelMapper
r1320 else if (start <= m_valuesSection || start <= m_labelsSection) // if the changes affect the map - reinitialize the pie
Marek Rosa
All model related methods and members removed from the series. QML stuff commented out where complaining
r1230 initializePieFromModel();
Marek Rosa
Refactored PieSeriesModelMapper
r1231 blockSeriesSignals(false);
Marek Rosa
All model related methods and members removed from the series. QML stuff commented out where complaining
r1230 }
void QPieModelMapperPrivate::modelColumnsRemoved(QModelIndex parent, int start, int end)
{
Q_UNUSED(parent);
Marek Rosa
Refactored PieSeriesModelMapper
r1231 if (m_modelSignalsBlock)
return;
blockSeriesSignals();
Marek Rosa
All model related methods and members removed from the series. QML stuff commented out where complaining
r1230 if (m_orientation == Qt::Horizontal)
removeData(start, end);
Marek Rosa
Fixed problem with PieModelMapper
r1320 else if (start <= m_valuesSection || start <= m_labelsSection) // if the changes affect the map - reinitialize the pie
Marek Rosa
All model related methods and members removed from the series. QML stuff commented out where complaining
r1230 initializePieFromModel();
Marek Rosa
Refactored PieSeriesModelMapper
r1231 blockSeriesSignals(false);
Marek Rosa
All model related methods and members removed from the series. QML stuff commented out where complaining
r1230 }
Marek Rosa
Model mappers now connected to series and model destroy signals
r1656 void QPieModelMapperPrivate::handleModelDestroyed()
{
m_model = 0;
}
Marek Rosa
All model related methods and members removed from the series. QML stuff commented out where complaining
r1230 void QPieModelMapperPrivate::insertData(int start, int end)
{
Marek Rosa
Small fixes to piemodelmapper and one more test
r1251 if (m_model == 0 || m_series == 0)
return;
Marek Rosa
All model related methods and members removed from the series. QML stuff commented out where complaining
r1230 if (m_count != -1 && start >= m_first + m_count) {
return;
} else {
int addedCount = end - start + 1;
if (m_count != -1 && addedCount > m_count)
addedCount = m_count;
int first = qMax(start, m_first);
int last = qMin(first + addedCount - 1, m_orientation == Qt::Vertical ? m_model->rowCount() - 1 : m_model->columnCount() - 1);
for (int i = first; i <= last; i++) {
Marek Rosa
Fixed problem with PieModelMapper
r1320 QModelIndex valueIndex = valueModelIndex(i - m_first);
QModelIndex labelIndex = labelModelIndex(i - m_first);
if (valueIndex.isValid() && labelIndex.isValid()) {
QPieSlice *slice = new QPieSlice;
slice->setValue(m_model->data(valueIndex, Qt::DisplayRole).toDouble());
Marek Rosa
Added NOTIFY to PieModelMapper class properties
r1474 slice->setLabel(m_model->data(labelIndex, Qt::DisplayRole).toString());
Marek Rosa
Fixed problem with PieModelMapper
r1320 connect(slice, SIGNAL(labelChanged()), this, SLOT(sliceLabelChanged()));
connect(slice, SIGNAL(valueChanged()), this, SLOT(sliceValueChanged()));
m_series->insert(i - m_first, slice);
m_slices.insert(i - m_first, slice);
}
Marek Rosa
All model related methods and members removed from the series. QML stuff commented out where complaining
r1230 }
Marek Rosa
Refactored PieSeriesModelMapper
r1231
// remove excess of slices (abouve m_count)
Marek Rosa
All model related methods and members removed from the series. QML stuff commented out where complaining
r1230 if (m_count != -1 && m_series->slices().size() > m_count)
Marek Rosa
QPieModelMapper: added support for labelChanged and valueChanged signals from the slice
r1236 for (int i = m_series->slices().size() - 1; i >= m_count; i--) {
Marek Rosa
All model related methods and members removed from the series. QML stuff commented out where complaining
r1230 m_series->remove(m_series->slices().at(i));
Marek Rosa
QPieModelMapper: added support for labelChanged and valueChanged signals from the slice
r1236 m_slices.removeAt(i);
}
Marek Rosa
All model related methods and members removed from the series. QML stuff commented out where complaining
r1230 }
}
void QPieModelMapperPrivate::removeData(int start, int end)
{
Marek Rosa
Small fixes to piemodelmapper and one more test
r1251 if (m_model == 0 || m_series == 0)
return;
Marek Rosa
All model related methods and members removed from the series. QML stuff commented out where complaining
r1230 int removedCount = end - start + 1;
if (m_count != -1 && start >= m_first + m_count) {
return;
} else {
int toRemove = qMin(m_series->slices().size(), removedCount); // first find how many items can actually be removed
int first = qMax(start, m_first); // get the index of the first item that will be removed.
int last = qMin(first + toRemove - 1, m_series->slices().size() + m_first - 1); // get the index of the last item that will be removed.
Marek Rosa
QPieModelMapper: added support for labelChanged and valueChanged signals from the slice
r1236 for (int i = last; i >= first; i--) {
Marek Rosa
All model related methods and members removed from the series. QML stuff commented out where complaining
r1230 m_series->remove(m_series->slices().at(i - m_first));
Marek Rosa
QPieModelMapper: added support for labelChanged and valueChanged signals from the slice
r1236 m_slices.removeAt(i - m_first);
}
Marek Rosa
All model related methods and members removed from the series. QML stuff commented out where complaining
r1230
if (m_count != -1) {
int itemsAvailable; // check how many are available to be added
if (m_orientation == Qt::Vertical)
itemsAvailable = m_model->rowCount() - m_first - m_series->slices().size();
Marek Rosa
ModelMapper proposal
r1229 else
Marek Rosa
All model related methods and members removed from the series. QML stuff commented out where complaining
r1230 itemsAvailable = m_model->columnCount() - m_first - m_series->slices().size();
int toBeAdded = qMin(itemsAvailable, m_count - m_series->slices().size()); // add not more items than there is space left to be filled.
int currentSize = m_series->slices().size();
if (toBeAdded > 0)
for (int i = m_series->slices().size(); i < currentSize + toBeAdded; i++) {
Marek Rosa
Fixed problem with PieModelMapper
r1320 QModelIndex valueIndex = valueModelIndex(i - m_first);
QModelIndex labelIndex = labelModelIndex(i - m_first);
if (valueIndex.isValid() && labelIndex.isValid()) {
QPieSlice *slice = new QPieSlice;
slice->setValue(m_model->data(valueIndex, Qt::DisplayRole).toDouble());
slice->setLabel(m_model->data(labelIndex, Qt::DisplayRole).toString());
m_series->insert(i, slice);
m_slices.insert(i, slice);
Marek Rosa
All model related methods and members removed from the series. QML stuff commented out where complaining
r1230 }
Marek Rosa
ModelMapper proposal
r1229 }
}
}
}
Marek Rosa
All model related methods and members removed from the series. QML stuff commented out where complaining
r1230 void QPieModelMapperPrivate::initializePieFromModel()
{
if (m_model == 0 || m_series == 0)
return;
Marek Rosa
ModelMapper proposal
r1229
Marek Rosa
Refactored PieSeriesModelMapper
r1231 blockSeriesSignals();
Marek Rosa
QPieModelMapper: added support for labelChanged and valueChanged signals from the slice
r1236 // clear current content
m_series->clear();
m_slices.clear();
Marek Rosa
All model related methods and members removed from the series. QML stuff commented out where complaining
r1230 // create the initial slices set
int slicePos = 0;
QModelIndex valueIndex = valueModelIndex(slicePos);
QModelIndex labelIndex = labelModelIndex(slicePos);
while (valueIndex.isValid() && labelIndex.isValid()) {
Marek Rosa
QPieModelMapper: added support for labelChanged and valueChanged signals from the slice
r1236 QPieSlice *slice = new QPieSlice;
slice->setLabel(m_model->data(labelIndex, Qt::DisplayRole).toString());
slice->setValue(m_model->data(valueIndex, Qt::DisplayRole).toDouble());
connect(slice, SIGNAL(labelChanged()), this, SLOT(sliceLabelChanged()));
connect(slice, SIGNAL(valueChanged()), this, SLOT(sliceValueChanged()));
m_series->append(slice);
m_slices.append(slice);
Marek Rosa
All model related methods and members removed from the series. QML stuff commented out where complaining
r1230 slicePos++;
valueIndex = valueModelIndex(slicePos);
labelIndex = labelModelIndex(slicePos);
Marek Rosa
Added NOTIFY to PieModelMapper class properties
r1474 }
Marek Rosa
Refactored PieSeriesModelMapper
r1231 blockSeriesSignals(false);
Marek Rosa
All model related methods and members removed from the series. QML stuff commented out where complaining
r1230 }
Marek Rosa
ModelMapper proposal
r1229
#include "moc_qpiemodelmapper_p.cpp"
Marek Rosa
Mapper class added for xyseries and pieseries. Model support commented out for barseries for now.
r1164 #include "moc_qpiemodelmapper.cpp"
Titta Heikkala
Qt Charts project file structure change...
r2712 QT_CHARTS_END_NAMESPACE