47 #include <KDABLibFakes> 53 class AttributesModel::Private
68 AttributesModel::Private::Private()
71 palette(
Palette::defaultPalette() )
100 if ( mapA.count() != mapB.count() ) {
105 for ( ; itA != mapA.constEnd(); ++itA, ++itB ) {
106 if ( itA->count() != itB->count() ) {
111 for ( ; it2A != itA->constEnd(); ++it2A, ++it2B ) {
112 if ( it2A.key() != it2B.key() ) {
125 if ( other ==
this ) {
128 if ( !other ||
d->paletteType != other->d->
paletteType ) {
133 if (
d->dataMap.count() != other->d->dataMap.count() ) {
138 for ( ; itA !=
d->dataMap.constEnd(); ++itA, ++itB ) {
139 if ( itA->count() != itB->count() ) {
144 for ( ; it2A != itA->constEnd(); ++it2A, ++it2B ) {
145 if ( it2A->count() != it2B->count() ) {
150 for ( ; it3A != it2A->constEnd(); ++it3A, ++it3B ) {
151 if ( it3A.key() != it3B.key() ) {
162 if ( !compareHeaderDataMaps(
d->horizontalHeaderDataMap, other->d->horizontalHeaderDataMap ) ||
163 !compareHeaderDataMaps(
d->verticalHeaderDataMap, other->d->verticalHeaderDataMap ) ) {
168 if (
d->modelDataMap.count() != other->d->modelDataMap.count() ) {
173 for ( ; itA !=
d->modelDataMap.constEnd(); ++itA, ++itB ) {
174 if ( itA.key() != itB.key() ) {
186 int role,
const QVariant& a,
const QVariant& b )
const 194 return (a.value<QBrush>() ==
197 return (a.value<QPen>() ==
234 return (a.value<
bool>() ==
250 if ( sourceModel() ) {
251 const QVariant sourceData = sourceModel()->headerData( section, orientation, role );
252 if ( sourceData.isValid() ) {
259 d->horizontalHeaderDataMap :
d->verticalHeaderDataMap;
261 if ( mapIt != map.constEnd() ) {
264 if ( dataMapIt != dataMap.constEnd() ) {
265 return dataMapIt.value();
277 const int dataset = section /
d->dataDimension;
280 case Qt::DisplayRole:
282 return QLatin1String( orientation == Qt::Vertical ?
"Series " :
"Item " ) + QString::number( dataset ) ;
284 return d->palette.getBrush( dataset );
289 return QPen( brush.color() );
307 v = defaultsForRole( role );
319 v =
headerData( column, Qt::Horizontal, role );
332 if ( index.isValid() ) {
333 Q_ASSERT( index.model() == this );
335 if ( !sourceModel() ) {
339 if ( index.isValid() ) {
340 const QVariant sourceData = sourceModel()->data(
mapToSource( index ), role );
341 if ( sourceData.isValid() ) {
347 if (
d->dataMap.contains( index.column() ) ) {
349 if ( colDataMap.contains( index.row() ) ) {
351 if ( dataMap.contains( role ) ) {
352 const QVariant v = dataMap[ role ];
360 if ( index.isValid() ) {
361 return data( index.column(), role );
391 QVariant AttributesModel::defaultsForRole(
int role )
const 394 return d->defaultsMap.value( role );
400 return sourceModel()->setData(
mapToSource(index), value, role );
404 dataMap.insert( role, value );
412 return setData( index, QVariant(), role );
416 const QVariant & value,
int role )
418 if ( sourceModel() &&
headerData( section, orientation, role ) == value ) {
423 return sourceModel()->setHeaderData( section, orientation, value, role );
426 = orientation == Qt::Horizontal ?
d->horizontalHeaderDataMap :
d->verticalHeaderDataMap;
429 dataMap.insert( role, value );
430 if ( sourceModel() ) {
431 int numRows =
rowCount( QModelIndex() );
433 if ( orientation == Qt::Horizontal && numRows > 0 )
435 index( numRows - 1, section, QModelIndex() ) );
436 else if ( orientation == Qt::Vertical && numCols > 0 )
438 index( section, numCols - 1, QModelIndex() ) );
439 emit headerDataChanged( orientation, section, section );
443 if ( section != -1 && numRows > 0 )
444 emit dataChanged(
index( 0, section, QModelIndex() ),
445 index( numRows - 1, section, QModelIndex() ) );
453 return setHeaderData ( section, orientation, QVariant(), role );
458 if (
d->paletteType == type ) {
461 d->paletteType = type;
473 qWarning(
"Unknown palette type!" );
479 return d->paletteType;
484 d->modelDataMap.insert( role, value );
485 int numRows =
rowCount( QModelIndex() );
487 if ( sourceModel() && numRows > 0 && numCols > 0 ) {
489 index( numRows - 1, numCols - 1, QModelIndex() ) );
498 return d->modelDataMap.value( role, QVariant() );
503 if ( sourceModel() ) {
504 return sourceModel()->rowCount(
mapToSource(index) );
512 if ( sourceModel() ) {
513 return sourceModel()->columnCount(
mapToSource(index) );
521 if ( this->sourceModel() != 0 )
523 disconnect( this->sourceModel(), SIGNAL( dataChanged(
const QModelIndex&,
const QModelIndex&)),
524 this, SLOT( slotDataChanged(
const QModelIndex&,
const QModelIndex&)));
525 disconnect( this->sourceModel(), SIGNAL( rowsInserted(
const QModelIndex&,
int,
int ) ),
526 this, SLOT( slotRowsInserted(
const QModelIndex&,
int,
int ) ) );
527 disconnect( this->sourceModel(), SIGNAL( rowsRemoved(
const QModelIndex&,
int,
int ) ),
528 this, SLOT( slotRowsRemoved(
const QModelIndex&,
int,
int ) ) );
529 disconnect( this->sourceModel(), SIGNAL( rowsAboutToBeInserted(
const QModelIndex&,
int,
int ) ),
530 this, SLOT( slotRowsAboutToBeInserted(
const QModelIndex&,
int,
int ) ) );
531 disconnect( this->sourceModel(), SIGNAL( rowsAboutToBeRemoved(
const QModelIndex&,
int,
int ) ),
532 this, SLOT( slotRowsAboutToBeRemoved(
const QModelIndex&,
int,
int ) ) );
533 disconnect( this->sourceModel(), SIGNAL( columnsInserted(
const QModelIndex&,
int,
int ) ),
534 this, SLOT( slotColumnsInserted(
const QModelIndex&,
int,
int ) ) );
535 disconnect( this->sourceModel(), SIGNAL( columnsRemoved(
const QModelIndex&,
int,
int ) ),
536 this, SLOT( slotColumnsRemoved(
const QModelIndex&,
int,
int ) ) );
537 disconnect( this->sourceModel(), SIGNAL( columnsAboutToBeInserted(
const QModelIndex&,
int,
int ) ),
538 this, SLOT( slotColumnsAboutToBeInserted(
const QModelIndex&,
int,
int ) ) );
539 disconnect( this->sourceModel(), SIGNAL( columnsAboutToBeRemoved(
const QModelIndex&,
int,
int ) ),
540 this, SLOT( slotColumnsAboutToBeRemoved(
const QModelIndex&,
int,
int ) ) );
541 disconnect( this->sourceModel(), SIGNAL( modelReset() ),
542 this, SIGNAL( modelReset() ) );
543 disconnect( this->sourceModel(), SIGNAL( layoutChanged() ),
544 this, SIGNAL( layoutChanged() ) );
546 QAbstractProxyModel::setSourceModel( sourceModel );
547 if ( this->sourceModel() != NULL )
549 connect( this->sourceModel(), SIGNAL( dataChanged(
const QModelIndex&,
const QModelIndex&)),
550 this, SLOT( slotDataChanged(
const QModelIndex&,
const QModelIndex&)));
551 connect( this->sourceModel(), SIGNAL( rowsInserted(
const QModelIndex&,
int,
int ) ),
552 this, SLOT( slotRowsInserted(
const QModelIndex&,
int,
int ) ) );
553 connect( this->sourceModel(), SIGNAL( rowsRemoved(
const QModelIndex&,
int,
int ) ),
554 this, SLOT( slotRowsRemoved(
const QModelIndex&,
int,
int ) ) );
555 connect( this->sourceModel(), SIGNAL( rowsAboutToBeInserted(
const QModelIndex&,
int,
int ) ),
556 this, SLOT( slotRowsAboutToBeInserted(
const QModelIndex&,
int,
int ) ) );
557 connect( this->sourceModel(), SIGNAL( rowsAboutToBeRemoved(
const QModelIndex&,
int,
int ) ),
558 this, SLOT( slotRowsAboutToBeRemoved(
const QModelIndex&,
int,
int ) ) );
559 connect( this->sourceModel(), SIGNAL( columnsInserted(
const QModelIndex&,
int,
int ) ),
560 this, SLOT( slotColumnsInserted(
const QModelIndex&,
int,
int ) ) );
561 connect( this->sourceModel(), SIGNAL( columnsRemoved(
const QModelIndex&,
int,
int ) ),
562 this, SLOT( slotColumnsRemoved(
const QModelIndex&,
int,
int ) ) );
563 connect( this->sourceModel(), SIGNAL( columnsAboutToBeInserted(
const QModelIndex&,
int,
int ) ),
564 this, SLOT( slotColumnsAboutToBeInserted(
const QModelIndex&,
int,
int ) ) );
565 connect( this->sourceModel(), SIGNAL( columnsAboutToBeRemoved(
const QModelIndex&,
int,
int ) ),
566 this, SLOT( slotColumnsAboutToBeRemoved(
const QModelIndex&,
int,
int ) ) );
567 connect( this->sourceModel(), SIGNAL( modelReset() ),
568 this, SIGNAL( modelReset() ) );
569 connect( this->sourceModel(), SIGNAL( layoutChanged() ),
570 this, SIGNAL( layoutChanged() ) );
574 void AttributesModel::slotRowsAboutToBeInserted(
const QModelIndex&
parent,
int start,
int end )
579 void AttributesModel::slotColumnsAboutToBeInserted(
const QModelIndex&
parent,
int start,
int end )
584 void AttributesModel::slotRowsInserted(
const QModelIndex&
parent,
int start,
int end )
592 void AttributesModel::slotColumnsInserted(
const QModelIndex&
parent,
int start,
int end )
600 void AttributesModel::slotRowsAboutToBeRemoved(
const QModelIndex&
parent,
int start,
int end )
605 void AttributesModel::slotColumnsAboutToBeRemoved(
const QModelIndex&
parent,
int start,
int end )
610 void AttributesModel::slotRowsRemoved(
const QModelIndex&
parent,
int start,
int end )
618 void AttributesModel::removeEntriesFromDataMap(
int start,
int end )
622 if ( it !=
d->dataMap.end() ) {
625 for (
int i = start; i < end && it !=
d->dataMap.end(); ++i ) {
626 d->dataMap[ i ] = it.value();
627 indexesToDel << it.key();
630 if ( indexesToDel.isEmpty() ) {
631 for (
int i = start; i < end; ++i ) {
635 for (
int i = 0; i < indexesToDel.count(); ++i ) {
636 d->dataMap.remove( indexesToDel[ i ] );
641 void AttributesModel::removeEntriesFromDirectionDataMaps( Qt::Orientation dir,
int start,
int end )
644 = dir == Qt::Horizontal ?
d->horizontalHeaderDataMap :
d->verticalHeaderDataMap;
647 if ( it != sectionDataMap.end() )
650 for (
int i = start; i < end && it != sectionDataMap.end(); ++i )
652 sectionDataMap[ i ] = it.value();
653 indexesToDel << it.key();
656 if ( indexesToDel.isEmpty() )
658 for (
int i = start; i < end; ++i )
663 for (
int i = 0; i < indexesToDel.count(); ++i )
665 sectionDataMap.remove( indexesToDel[ i ] );
670 void AttributesModel::slotColumnsRemoved(
const QModelIndex&
parent,
int start,
int end )
675 Q_ASSERT_X( sourceModel(),
"removeColumn",
"This should only be triggered if a valid source Model exists!" );
676 for (
int i = start; i <= end; ++i ) {
677 d->verticalHeaderDataMap.remove( start );
679 removeEntriesFromDataMap( start, end );
680 removeEntriesFromDirectionDataMaps( Qt::Horizontal, start, end );
681 removeEntriesFromDirectionDataMaps( Qt::Vertical, start, end );
686 void AttributesModel::slotDataChanged(
const QModelIndex& topLeft,
const QModelIndex& bottomRight )
693 if ( value.isValid() ) {
694 d->defaultsMap.insert( role, value );
698 if ( it !=
d->defaultsMap.end() ) {
699 d->defaultsMap.erase( it );
709 d->dataDimension = dimension;
714 return d->dataDimension;
void setPaletteType(PaletteType type)
Sets the palettetype used by this attributesmodel.
bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::DisplayRole) override
[reimplemented]
void setSourceModel(QAbstractItemModel *sourceModel) override
[reimplemented]
QModelIndex mapToSource(const QModelIndex &proxyIndex) const override
A Palette is a set of brushes (or colors) to be used for painting data sets.
bool setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, int role=Qt::DisplayRole) override
[reimplemented]
Diagram attributes dealing with data value labels.
int rowCount(const QModelIndex &) const override
[reimplemented]
void attributesChanged(const QModelIndex &, const QModelIndex &)
Set of attributes for changing the appearance of bar charts.
Declaring the class KDChart::DataValueAttributes.
int datasetDimension() const
QModelIndex index(int row, int col, const QModelIndex &index) const override
static const Palette & rainbowPalette()
QModelIndex mapFromSource(const QModelIndex &sourceIndex) const override
bool resetHeaderData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole)
Remove any explicit attributes settings that might have been specified before.
int columnCount(const QModelIndex &) const override
[reimplemented]
bool compareAttributes(int role, const QVariant &a, const QVariant &b) const
QVariant modelData(int role) const
~AttributesModel() override
QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const override
[reimplemented]
QModelIndex parent(const QModelIndex &index) const override
void setDefaultForRole(int role, const QVariant &value)
Define the default value for a certain role.
bool isKnownAttributesRole(int role) const
Returns whether the given role corresponds to one of the known internally used ones.
Set of attributes for changing the appearance of line charts.
QVariant data(int role) const
Returns the data that were specified at global level, or the default data, or QVariant().
A set of attributes controlling the appearance of pie charts.
virtual QVariant defaultHeaderData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const
Returns default values for the header data.
static const QVariant & defaultAttributesAsVariant()
static const Palette & defaultPalette()
Provide access to the three builtin palettes, one with standard bright colors, one with more subdued ...
bool compare(const AttributesModel *other) const
Returns true if both, all of the attributes set, and the palette set is equal in both of the Attribut...
PaletteType paletteType() const
A proxy model used for decorating data with attributes.
void setDatasetDimension(int dimension)
Set the dimension of the dataset in the source model.
Cell-specific attributes regarding value tracking.
Base class for all proxy models used inside KD Chart.
A set of 3D bar attributes.
A set of 3D pie attributes.
void initFrom(const AttributesModel *other)
Copies the internal data (maps and palette) of another AttributesModel* into this one...
Class only listed here to document inheritance of some KDChart classes.
static const Palette & subduedPalette()
AttributesModel(QAbstractItemModel *model, QObject *parent=0)
bool setModelData(const QVariant value, int role)
bool resetData(const QModelIndex &index, int role=Qt::DisplayRole)
Remove any explicit attributes settings that might have been specified before.
A set of 3D line attributes.
Attributes to customize the appearance of a column in a stock chart.