35#include <KDABLibFakes>
39class AttributesModel::Private
49 int dataDimension = 1;
54AttributesModel::Private::Private()
55 : palette(
Palette::defaultPalette())
90 if (
itA->count() !=
itB->count()) {
112 if (!
other ||
d->paletteType !=
other->d->paletteType) {
117 if (
d->dataMap.count() !=
other->d->dataMap.count()) {
122 for (;
itA !=
d->dataMap.constEnd(); ++
itA, ++
itB) {
123 if (
itA->count() !=
itB->count()) {
129 if (
it2A->count() !=
it2B->count()) {
146 if (!compareHeaderDataMaps(
d->horizontalHeaderDataMap,
other->d->horizontalHeaderDataMap) || !compareHeaderDataMaps(
d->verticalHeaderDataMap,
other->d->verticalHeaderDataMap)) {
151 if (
d->modelDataMap.count() !=
other->d->modelDataMap.count()) {
156 for (;
itA !=
d->modelDataMap.constEnd(); ++
itA, ++
itB) {
157 if (
itA.key() !=
itB.key()) {
245 const int dataset = section /
d->dataDimension;
252 return d->palette.getBrush(
dataset);
274 v = defaultsForRole(role);
355QVariant AttributesModel::defaultsForRole(
int role)
const
358 return d->defaultsMap.
value(role);
368 dataMap.
insert(role, value);
387 return sourceModel()->setHeaderData(section, orientation, value, role);
392 dataMap.
insert(role, value);
406 if (section != -1 &&
numRows > 0)
421 if (
d->paletteType == type) {
424 d->paletteType = type;
442 return d->paletteType;
447 d->modelDataMap.insert(role, value);
450 if (sourceModel() && numRows > 0 && numCols > 0) {
451 Q_EMIT attributesChanged(index(0, 0,
QModelIndex()),
487 this, &AttributesModel::slotDataChanged);
489 this, &AttributesModel::slotRowsInserted);
491 this, &AttributesModel::slotRowsRemoved);
493 this, &AttributesModel::slotRowsAboutToBeInserted);
495 this, &AttributesModel::slotRowsAboutToBeRemoved);
497 this, &AttributesModel::slotColumnsInserted);
499 this, &AttributesModel::slotColumnsRemoved);
501 this, &AttributesModel::slotColumnsAboutToBeInserted);
503 this, &AttributesModel::slotColumnsAboutToBeRemoved);
514 this, &AttributesModel::slotDataChanged);
516 this, &AttributesModel::slotRowsInserted);
518 this, &AttributesModel::slotRowsRemoved);
520 this, &AttributesModel::slotRowsAboutToBeInserted);
522 this, &AttributesModel::slotRowsAboutToBeRemoved);
524 this, &AttributesModel::slotColumnsInserted);
526 this, &AttributesModel::slotColumnsRemoved);
528 this, &AttributesModel::slotColumnsAboutToBeInserted);
530 this, &AttributesModel::slotColumnsAboutToBeRemoved);
540void AttributesModel::slotRowsAboutToBeInserted(
const QModelIndex &parent,
int start,
int end)
545void AttributesModel::slotColumnsAboutToBeInserted(
const QModelIndex &parent,
int start,
int end)
550void AttributesModel::slotRowsInserted(
const QModelIndex &parent,
int start,
int end)
558void AttributesModel::slotColumnsInserted(
const QModelIndex &parent,
int start,
int end)
566void AttributesModel::slotRowsAboutToBeRemoved(
const QModelIndex &parent,
int start,
int end)
571void AttributesModel::slotColumnsAboutToBeRemoved(
const QModelIndex &parent,
int start,
int end)
576void AttributesModel::slotRowsRemoved(
const QModelIndex &parent,
int start,
int end)
584void AttributesModel::removeEntriesFromDataMap(
int start,
int end)
588 if (
it !=
d->dataMap.end()) {
591 for (
int i = start;
i < end &&
it !=
d->dataMap.end(); ++
i) {
597 for (
int i = start;
i < end; ++
i) {
607void AttributesModel::removeEntriesFromDirectionDataMaps(
Qt::Orientation dir,
int start,
int end)
620 for (
int i = start;
i < end; ++
i) {
630void AttributesModel::slotColumnsRemoved(
const QModelIndex &parent,
int start,
int end)
635 Q_ASSERT_X(
sourceModel(),
"removeColumn",
"This should only be triggered if a valid source Model exists!");
636 for (
int i = start;
i <= end; ++
i) {
637 d->verticalHeaderDataMap.remove(start);
639 removeEntriesFromDataMap(start, end);
641 removeEntriesFromDirectionDataMaps(
Qt::Vertical, start, end);
654 d->defaultsMap.insert(role, value);
658 if (
it !=
d->defaultsMap.end()) {
659 d->defaultsMap.erase(
it);
674 return d->dataDimension;
Declaring the class KDChart::DataValueAttributes.
Base class for all proxy models used inside KD Chart.
QModelIndex index(int row, int col, const QModelIndex &index) const override
Reimplemented for internal purposes.
QModelIndex mapToSource(const QModelIndex &proxyIndex) const override
Reimplemented for internal purposes.
QModelIndex mapFromSource(const QModelIndex &sourceIndex) const override
Reimplemented for internal purposes.
A proxy model used for decorating data with attributes.
virtual QVariant defaultHeaderData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const
int datasetDimension() const
void attributesChanged(const QModelIndex &, const QModelIndex &)
AttributesModel(QAbstractItemModel *model, QObject *parent=nullptr)
PaletteType paletteType() const
QVariant data(int role) const
int rowCount(const QModelIndex &) const override
bool compareAttributes(int role, const QVariant &a, const QVariant &b) const
void setDatasetDimension(int dimension)
~AttributesModel() override
bool resetHeaderData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole)
bool setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, int role=Qt::DisplayRole) override
QVariant modelData(int role) const
void setPaletteType(PaletteType type)
void setSourceModel(QAbstractItemModel *sourceModel) override
bool resetData(const QModelIndex &index, int role=Qt::DisplayRole)
void setDefaultForRole(int role, const QVariant &value)
void initFrom(const AttributesModel *other)
bool compare(const AttributesModel *other) const
bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::DisplayRole) override
bool isKnownAttributesRole(int role) const
QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const override
int columnCount(const QModelIndex &) const override
bool setModelData(const QVariant value, int role)
Set of attributes for changing the appearance of bar charts.
Diagram attributes dealing with data value labels.
static const QVariant & defaultAttributesAsVariant()
Set of attributes for changing the appearance of line charts.
A Palette is a set of brushes (or colors) to be used for painting data sets.
static const Palette & subduedPalette()
static const Palette & defaultPalette()
static const Palette & rainbowPalette()
A set of attributes controlling the appearance of pie charts.
Attributes to customize the appearance of a column in a stock chart.
A set of 3D bar attributes.
A set of 3D line attributes.
A set of 3D pie attributes.
Cell-specific attributes regarding value tracking.
@ DataValueLabelAttributesRole
@ ThreeDLineAttributesRole
@ ThreeDBarAttributesRole
@ ThreeDPieAttributesRole
@ ValueTrackerAttributesRole
void beginInsertColumns(const QModelIndex &parent, int first, int last)
void beginInsertRows(const QModelIndex &parent, int first, int last)
void beginRemoveColumns(const QModelIndex &parent, int first, int last)
void beginRemoveRows(const QModelIndex &parent, int first, int last)
void columnsAboutToBeInserted(const QModelIndex &parent, int first, int last)
void columnsAboutToBeRemoved(const QModelIndex &parent, int first, int last)
void columnsInserted(const QModelIndex &parent, int first, int last)
void columnsRemoved(const QModelIndex &parent, int first, int last)
void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector< int > &roles)
void layoutChanged(const QList< QPersistentModelIndex > &parents, QAbstractItemModel::LayoutChangeHint hint)
void modelAboutToBeReset()
void rowsAboutToBeInserted(const QModelIndex &parent, int start, int end)
void rowsAboutToBeRemoved(const QModelIndex &parent, int first, int last)
void rowsInserted(const QModelIndex &parent, int first, int last)
void rowsRemoved(const QModelIndex &parent, int first, int last)
virtual void setSourceModel(QAbstractItemModel *sourceModel)
const QColor & color() const const
QMap::const_iterator constBegin() const const
QMap::const_iterator constEnd() const const
bool contains(const Key &key) const const
QMap::iterator find(const Key &key)
QMap::iterator insert(const Key &key, const T &value)
QMap::iterator upperBound(const Key &key)
const T value(const Key &key, const T &defaultValue) const const
bool isValid() const const
const QAbstractItemModel * model() const const
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
bool disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *method)
QObject * parent() const const
T qobject_cast(QObject *object)
QString number(int n, int base)
bool isValid() const const
T value(int i) const const