#include <KDChartAttributesModel.h>
Definition at line 43 of file KDChartAttributesModel.h.
Public Types | |
enum | PaletteType { PaletteTypeDefault = 0, PaletteTypeRainbow = 1, PaletteTypeSubdued = 2 } |
Signals | |
void | attributesChanged (const QModelIndex &, const QModelIndex &) |
Public Member Functions | |
AttributesModel (QAbstractItemModel *model, QObject *parent=0) | |
int | columnCount (const QModelIndex &) const |
[reimplemented] | |
bool | compare (const AttributesModel *other) const |
bool | compareAttributes (int role, const QVariant &a, const QVariant &b) const |
QVariant | data (const QModelIndex &, int role=Qt::DisplayRole) const |
[reimplemented] | |
QVariant | data (int column, int role) const |
Returns the data that were specified at per column level, or the globally set data, or the default data, or QVariant(). | |
QVariant | data (int role) const |
Returns the data that were specified at global level, or the default data, or QVariant(). | |
QVariant | headerData (int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const |
[reimplemented] | |
QModelIndex | index (int row, int col, const QModelIndex &index) const |
void | initFrom (const AttributesModel *other) |
bool | isKnownAttributesRole (int role) const |
Returns whether the given role corresponds to one of the known internally used ones. | |
QModelIndex | mapFromSource (const QModelIndex &sourceIndex) const |
QModelIndex | mapToSource (const QModelIndex &proxyIndex) const |
QVariant | modelData (int role) const |
PaletteType | paletteType () const |
QModelIndex | parent (const QModelIndex &index) const |
bool | resetData (const QModelIndex &index, int role=Qt::DisplayRole) |
Remove any explicit attributes settings that might have been specified before. | |
bool | resetHeaderData (int section, Qt::Orientation orientation, int role=Qt::DisplayRole) |
Remove any explicit attributes settings that might have been specified before. | |
int | rowCount (const QModelIndex &) const |
[reimplemented] | |
bool | setData (const QModelIndex &index, const QVariant &value, int role=Qt::DisplayRole) |
[reimplemented] | |
void | setDefaultForRole (int role, const QVariant &value) |
Define the default value for a certain role. | |
bool | setHeaderData (int section, Qt::Orientation orientation, const QVariant &value, int role=Qt::DisplayRole) |
[reimplemented] | |
bool | setModelData (const QVariant value, int role) |
void | setPaletteType (PaletteType type) |
Sets the palettetype used by this attributesmodel. | |
void | setSourceModel (QAbstractItemModel *sourceModel) |
[reimplemented] | |
~AttributesModel () | |
Protected Member Functions | |
const QMap< int, QMap< int, QMap< int, QVariant > > > | dataMap () const |
needed for serialization | |
const QMap< int, QMap< int, QVariant > > | horizontalHeaderDataMap () const |
needed for serialization | |
const QMap< int, QVariant > | modelDataMap () const |
needed for serialization | |
void | setDataMap (const QMap< int, QMap< int, QMap< int, QVariant > > > map) |
needed for serialization | |
void | setHorizontalHeaderDataMap (const QMap< int, QMap< int, QVariant > > map) |
needed for serialization | |
void | setModelDataMap (const QMap< int, QVariant > map) |
needed for serialization | |
void | setVerticalHeaderDataMap (const QMap< int, QMap< int, QVariant > > map) |
needed for serialization | |
const QMap< int, QMap< int, QVariant > > | verticalHeaderDataMap () const |
needed for serialization |
Definition at line 50 of file KDChartAttributesModel.h.
00050 { 00051 PaletteTypeDefault = 0, 00052 PaletteTypeRainbow = 1, 00053 PaletteTypeSubdued = 2 00054 };
AttributesModel::AttributesModel | ( | QAbstractItemModel * | model, | |
QObject * | parent = 0 | |||
) | [explicit] |
Definition at line 59 of file KDChartAttributesModel.cpp.
References KDChart::DataValueLabelAttributesRole, KDChart::DataValueAttributes::defaultAttributesAsVariant(), setDefaultForRole(), and setSourceModel().
00060 : AbstractProxyModel( parent ), 00061 mPaletteType( PaletteTypeDefault ) 00062 { 00063 setSourceModel(model); 00064 setDefaultForRole( KDChart::DataValueLabelAttributesRole, 00065 DataValueAttributes::defaultAttributesAsVariant() ); 00066 }
AttributesModel::~AttributesModel | ( | ) |
void KDChart::AttributesModel::attributesChanged | ( | const QModelIndex & | , | |
const QModelIndex & | ||||
) | [signal] |
Referenced by setData(), setHeaderData(), and setModelData().
int AttributesModel::columnCount | ( | const QModelIndex & | index | ) | const |
[reimplemented]
Definition at line 532 of file KDChartAttributesModel.cpp.
References KDChart::AbstractProxyModel::mapToSource().
Referenced by StockDiagram::calculateDataBoundaries(), KDChart::AbstractDiagram::datasetBrushes(), KDChart::AbstractDiagram::datasetLabels(), KDChart::AbstractDiagram::datasetMarkers(), KDChart::AbstractDiagram::datasetPens(), and setModelData().
00533 { 00534 if ( sourceModel() ) { 00535 return sourceModel()->columnCount( mapToSource(index) ); 00536 } else { 00537 return 0; 00538 } 00539 }
bool AttributesModel::compare | ( | const AttributesModel * | other | ) | const |
Definition at line 85 of file KDChartAttributesModel.cpp.
References compareAttributes(), mDataMap, mHorizontalHeaderDataMap, mModelDataMap, mVerticalHeaderDataMap, and paletteType().
Referenced by KDChart::AbstractDiagram::compare().
00086 { 00087 if( other == this ) return true; 00088 if( ! other ){ 00089 //qDebug() << "AttributesModel::compare() cannot compare to Null pointer"; 00090 return false; 00091 } 00092 00093 { 00094 if (mDataMap.count() != other->mDataMap.count()){ 00095 //qDebug() << "AttributesModel::compare() dataMap have different sizes"; 00096 return false; 00097 } 00098 QMap<int, QMap<int, QMap<int, QVariant> > >::const_iterator itA = mDataMap.constBegin(); 00099 QMap<int, QMap<int, QMap<int, QVariant> > >::const_iterator itB = other->mDataMap.constBegin(); 00100 while (itA != mDataMap.constEnd()) { 00101 if ((*itA).count() != (*itB).count()){ 00102 //qDebug() << "AttributesModel::compare() dataMap/map have different sizes"; 00103 return false; 00104 } 00105 QMap<int, QMap<int, QVariant> >::const_iterator it2A = (*itA).constBegin(); 00106 QMap<int, QMap<int, QVariant> >::const_iterator it2B = (*itB).constBegin(); 00107 while (it2A != itA->constEnd()) { 00108 if ((*it2A).count() != (*it2B).count()){ 00109 //qDebug() << "AttributesModel::compare() dataMap/map/map have different sizes:" 00110 // << (*it2A).count() << (*it2B).count(); 00111 return false; 00112 } 00113 QMap<int, QVariant>::const_iterator it3A = (*it2A).constBegin(); 00114 QMap<int, QVariant>::const_iterator it3B = (*it2B).constBegin(); 00115 while (it3A != it2A->constEnd()) { 00116 if ( it3A.key() != it3B.key() ){ 00117 //qDebug( "AttributesModel::compare()\n" 00118 // " dataMap[%i, %i] values have different types. A: %x B: %x", 00119 // itA.key(), it2A.key(), it3A.key(), it3B.key()); 00120 return false; 00121 } 00122 if ( ! compareAttributes( it3A.key(), it3A.value(), it3B.value() ) ){ 00123 //qDebug( "AttributesModel::compare()\n" 00124 // " dataMap[%i, %i] values are different. Role: %x", itA.key(), it2A.key(), it3A.key()); 00125 return false; 00126 } 00127 ++it3A; 00128 ++it3B; 00129 } 00130 ++it2A; 00131 ++it2B; 00132 } 00133 ++itA; 00134 ++itB; 00135 } 00136 } 00137 { 00138 if (mHorizontalHeaderDataMap.count() != other->mHorizontalHeaderDataMap.count()){ 00139 //qDebug() << "AttributesModel::compare() horizontalHeaderDataMap have different sizes"; 00140 return false; 00141 } 00142 QMap<int, QMap<int, QVariant> >::const_iterator itA = mHorizontalHeaderDataMap.constBegin(); 00143 QMap<int, QMap<int, QVariant> >::const_iterator itB = other->mHorizontalHeaderDataMap.constBegin(); 00144 while (itA != mHorizontalHeaderDataMap.constEnd()) { 00145 if ((*itA).count() != (*itB).count()){ 00146 //qDebug() << "AttributesModel::compare() horizontalHeaderDataMap/map have different sizes"; 00147 return false; 00148 } 00149 QMap<int, QVariant>::const_iterator it2A = (*itA).constBegin(); 00150 QMap<int, QVariant>::const_iterator it2B = (*itB).constBegin(); 00151 while (it2A != itA->constEnd()) { 00152 if ( it2A.key() != it2B.key() ){ 00153 //qDebug( "AttributesModel::compare()\n" 00154 // " horizontalHeaderDataMap[ %i ] values have different types. A: %x B: %x", 00155 // itA.key(), it2A.key(), it2B.key()); 00156 return false; 00157 } 00158 if ( ! compareAttributes( it2A.key(), it2A.value(), it2B.value() ) ){ 00159 //qDebug( "AttributesModel::compare()\n" 00160 // " horizontalHeaderDataMap[ %i ] values are different. Role: %x", itA.key(), it2A.key() ); 00161 return false; 00162 } 00163 ++it2A; 00164 ++it2B; 00165 } 00166 ++itA; 00167 ++itB; 00168 } 00169 } 00170 { 00171 if (mVerticalHeaderDataMap.count() != other->mVerticalHeaderDataMap.count()){ 00172 //qDebug() << "AttributesModel::compare() verticalHeaderDataMap have different sizes"; 00173 return false; 00174 } 00175 QMap<int, QMap<int, QVariant> >::const_iterator itA = mVerticalHeaderDataMap.constBegin(); 00176 QMap<int, QMap<int, QVariant> >::const_iterator itB = other->mVerticalHeaderDataMap.constBegin(); 00177 while (itA != mVerticalHeaderDataMap.constEnd()) { 00178 if ((*itA).count() != (*itB).count()){ 00179 //qDebug() << "AttributesModel::compare() verticalHeaderDataMap/map have different sizes"; 00180 return false; 00181 } 00182 QMap<int, QVariant>::const_iterator it2A = (*itA).constBegin(); 00183 QMap<int, QVariant>::const_iterator it2B = (*itB).constBegin(); 00184 while (it2A != itA->constEnd()) { 00185 if ( it2A.key() != it2B.key() ){ 00186 //qDebug( "AttributesModel::compare()\n" 00187 // " verticalHeaderDataMap[ %i ] values have different types. A: %x B: %x", 00188 // itA.key(), it2A.key(), it2B.key()); 00189 return false; 00190 } 00191 if ( ! compareAttributes( it2A.key(), it2A.value(), it2B.value() ) ){ 00192 //qDebug( "AttributesModel::compare()\n" 00193 // " verticalHeaderDataMap[ %i ] values are different. Role: %x", itA.key(), it2A.key() ); 00194 return false; 00195 } 00196 ++it2A; 00197 ++it2B; 00198 } 00199 ++itA; 00200 ++itB; 00201 } 00202 } 00203 { 00204 if (mModelDataMap.count() != other->mModelDataMap.count()){ 00205 //qDebug() << "AttributesModel::compare() modelDataMap have different sizes:" << mModelDataMap.count() << other->mModelDataMap.count(); 00206 return false; 00207 } 00208 QMap<int, QVariant>::const_iterator itA = mModelDataMap.constBegin(); 00209 QMap<int, QVariant>::const_iterator itB = other->mModelDataMap.constBegin(); 00210 while (itA != mModelDataMap.constEnd()) { 00211 if ( itA.key() != itB.key() ){ 00212 //qDebug( "AttributesModel::compare()\n" 00213 // " modelDataMap values have different types. A: %x B: %x", 00214 // itA.key(), itB.key()); 00215 return false; 00216 } 00217 if ( ! compareAttributes( itA.key(), itA.value(), itB.value() ) ){ 00218 //qDebug( "AttributesModel::compare()\n" 00219 // " modelDataMap values are different. Role: %x", itA.key() ); 00220 return false; 00221 } 00222 ++itA; 00223 ++itB; 00224 } 00225 } 00226 if (paletteType() != other->paletteType()){ 00227 //qDebug() << "AttributesModel::compare() palette types are different"; 00228 return false; 00229 } 00230 return true; 00231 }
bool AttributesModel::compareAttributes | ( | int | role, | |
const QVariant & | a, | |||
const QVariant & | b | |||
) | const |
Definition at line 233 of file KDChartAttributesModel.cpp.
References KDChart::BarAttributesRole, KDChart::DataHiddenRole, KDChart::DatasetBrushRole, KDChart::DatasetPenRole, KDChart::DataValueLabelAttributesRole, isKnownAttributesRole(), KDChart::LineAttributesRole, KDChart::PieAttributesRole, KDChart::StockBarAttributesRole, KDChart::ThreeDAttributesRole, KDChart::ThreeDBarAttributesRole, KDChart::ThreeDLineAttributesRole, KDChart::ThreeDPieAttributesRole, and KDChart::ValueTrackerAttributesRole.
Referenced by compare().
00235 { 00236 if( isKnownAttributesRole( role ) ){ 00237 switch( role ) { 00238 case DataValueLabelAttributesRole: 00239 return (qVariantValue<DataValueAttributes>( a ) == 00240 qVariantValue<DataValueAttributes>( b )); 00241 case DatasetBrushRole: 00242 return (qVariantValue<QBrush>( a ) == 00243 qVariantValue<QBrush>( b )); 00244 case DatasetPenRole: 00245 return (qVariantValue<QPen>( a ) == 00246 qVariantValue<QPen>( b )); 00247 case ThreeDAttributesRole: 00248 // As of yet there is no ThreeDAttributes class, 00249 // and the AbstractThreeDAttributes class is pure virtual, 00250 // so we ignore this role for now. 00251 // (khz, 04.04.2007) 00252 /* 00253 return (qVariantValue<ThreeDAttributes>( a ) == 00254 qVariantValue<ThreeDAttributes>( b )); 00255 */ 00256 break; 00257 case LineAttributesRole: 00258 return (qVariantValue<LineAttributes>( a ) == 00259 qVariantValue<LineAttributes>( b )); 00260 case ThreeDLineAttributesRole: 00261 return (qVariantValue<ThreeDLineAttributes>( a ) == 00262 qVariantValue<ThreeDLineAttributes>( b )); 00263 case BarAttributesRole: 00264 return (qVariantValue<BarAttributes>( a ) == 00265 qVariantValue<BarAttributes>( b )); 00266 case StockBarAttributesRole: 00267 return (qVariantValue<StockBarAttributes>( a ) == 00268 qVariantValue<StockBarAttributes>( b )); 00269 case ThreeDBarAttributesRole: 00270 return (qVariantValue<ThreeDBarAttributes>( a ) == 00271 qVariantValue<ThreeDBarAttributes>( b )); 00272 case PieAttributesRole: 00273 return (qVariantValue<PieAttributes>( a ) == 00274 qVariantValue<PieAttributes>( b )); 00275 case ThreeDPieAttributesRole: 00276 return (qVariantValue<ThreeDPieAttributes>( a ) == 00277 qVariantValue<ThreeDPieAttributes>( b )); 00278 case ValueTrackerAttributesRole: 00279 return (qVariantValue<ValueTrackerAttributes>( a ) == 00280 qVariantValue<ValueTrackerAttributes>( b )); 00281 case DataHiddenRole: 00282 return (qVariantValue<bool>( a ) == 00283 qVariantValue<bool>( b )); 00284 default: 00285 Q_ASSERT( false ); // all of our own roles need to be handled 00286 break; 00287 } 00288 }else{ 00289 return (a == b); 00290 } 00291 return true; 00292 }
QVariant AttributesModel::data | ( | const QModelIndex & | index, | |
int | role = Qt::DisplayRole | |||
) | const |
[reimplemented]
Definition at line 381 of file KDChartAttributesModel.cpp.
References data(), dataMap(), and KDChart::AbstractProxyModel::mapToSource().
00382 { 00383 //qDebug() << "AttributesModel::data(" << index << role << ")"; 00384 if( index.isValid() ) { 00385 Q_ASSERT( index.model() == this ); 00386 } 00387 00388 if( sourceModel() == 0 ) 00389 return QVariant(); 00390 00391 if( index.isValid() ) 00392 { 00393 const QVariant sourceData = sourceModel()->data( mapToSource(index), role ); 00394 if( sourceData.isValid() ) 00395 return sourceData; 00396 } 00397 00398 // check if we are storing a value for this role at this cell index 00399 if( mDataMap.contains( index.column() ) ) 00400 { 00401 const QMap< int, QMap< int, QVariant > >& colDataMap = mDataMap[ index.column() ]; 00402 if( colDataMap.contains( index.row() ) ) 00403 { 00404 const QMap< int, QVariant >& dataMap = colDataMap[ index.row() ]; 00405 if( dataMap.contains( role ) ) 00406 { 00407 const QVariant v = dataMap[ role ]; 00408 if( v.isValid() ) 00409 return v; 00410 } 00411 } 00412 } 00413 // check if there is something set for the column (dataset), or at global level 00414 if( index.isValid() ) 00415 return data( index.column(), role ); // includes automatic fallback to default 00416 00417 return QVariant(); 00418 }
QVariant AttributesModel::data | ( | int | column, | |
int | role | |||
) | const |
Returns the data that were specified at per column level, or the globally set data, or the default data, or QVariant().
Definition at line 365 of file KDChartAttributesModel.cpp.
References data(), headerData(), and isKnownAttributesRole().
00366 { 00367 if ( isKnownAttributesRole( role ) ) { 00368 // check if there is something set for the column (dataset) 00369 QVariant v; 00370 v = headerData( column, Qt::Vertical, role ); 00371 00372 // check if there is something set at global level 00373 if ( !v.isValid() ) 00374 v = data( role ); // includes automatic fallback to default 00375 return v; 00376 } 00377 return QVariant(); 00378 }
QVariant AttributesModel::data | ( | int | role | ) | const |
Returns the data that were specified at global level, or the default data, or QVariant().
Definition at line 347 of file KDChartAttributesModel.cpp.
References isKnownAttributesRole(), and modelData().
Referenced by KDChart::AbstractDiagram::brush(), data(), KDChart::AbstractDiagram::dataValueAttributes(), KDChart::AbstractDiagram::isHidden(), and KDChart::AbstractDiagram::pen().
00348 { 00349 if ( isKnownAttributesRole( role ) ) { 00350 // check if there is something set at global level 00351 QVariant v = modelData( role ); 00352 00353 // else return the default setting, if any 00354 if ( !v.isValid() ) 00355 v = defaultsForRole( role ); 00356 return v; 00357 } 00358 return QVariant(); 00359 }
const QMap< int, QMap< int, QMap< int, QVariant > > > AttributesModel::dataMap | ( | ) | const [protected] |
needed for serialization
Definition at line 654 of file KDChartAttributesModel.cpp.
Referenced by data(), headerData(), setData(), and setHeaderData().
QVariant AttributesModel::headerData | ( | int | section, | |
Qt::Orientation | orientation, | |||
int | role = Qt::DisplayRole | |||
) | const |
[reimplemented]
Definition at line 295 of file KDChartAttributesModel.cpp.
References dataMap(), KDChart::DatasetBrushRole, KDChart::DatasetPenRole, KDChart::Palette::defaultPalette(), KDChart::Palette::getBrush(), modelData(), paletteType(), PaletteTypeDefault, PaletteTypeRainbow, PaletteTypeSubdued, KDChart::Palette::rainbowPalette(), and KDChart::Palette::subduedPalette().
Referenced by data(), KDChart::AbstractDiagram::datasetLabels(), KDChart::AbstractDiagram::itemRowLabels(), KDChart::PolarDiagram::paint(), and setHeaderData().
00298 { 00299 if( sourceModel() ) { 00300 QVariant sourceData = sourceModel()->headerData( section, orientation, role ); 00301 if ( sourceData.isValid() ) return sourceData; 00302 } 00303 00304 // the source model didn't have data set, let's use our stored values 00305 const QMap<int, QMap<int, QVariant> >& map = orientation == Qt::Horizontal ? mHorizontalHeaderDataMap : mVerticalHeaderDataMap; 00306 if ( map.contains( section ) ) { 00307 const QMap<int, QVariant> &dataMap = map[ section ]; 00308 if ( dataMap.contains( role ) ) { 00309 return dataMap[ role ]; 00310 } 00311 } 00312 00313 // Default values if nothing else matches 00314 switch ( role ) { 00315 case Qt::DisplayRole: 00316 return QLatin1String( orientation == Qt::Vertical ? "Series " : "Item " ) + QString::number( section ) ; 00317 00318 case KDChart::DatasetBrushRole: { 00319 if ( paletteType() == PaletteTypeSubdued ) 00320 return Palette::subduedPalette().getBrush( section ); 00321 else if ( paletteType() == PaletteTypeRainbow ) 00322 return Palette::rainbowPalette().getBrush( section ); 00323 else if ( paletteType() == PaletteTypeDefault ) 00324 return Palette::defaultPalette().getBrush( section ); 00325 else 00326 qWarning("Unknown type of fallback palette!"); 00327 } 00328 case KDChart::DatasetPenRole: { 00329 // default to the color set for the brush (or it's defaults) 00330 // but only if no per model override was set 00331 if ( !modelData( role ).isValid() ) { 00332 QBrush brush = qVariantValue<QBrush>( headerData( section, orientation, DatasetBrushRole ) ); 00333 return QPen( brush.color() ); 00334 } 00335 } 00336 default: 00337 break; 00338 } 00339 00340 return QVariant(); 00341 }
const QMap< int, QMap< int, QVariant > > AttributesModel::horizontalHeaderDataMap | ( | ) | const [protected] |
QModelIndex KDChart::AbstractProxyModel::index | ( | int | row, | |
int | col, | |||
const QModelIndex & | index | |||
) | const [inherited] |
[reimplemented]
Definition at line 84 of file KDChartAbstractProxyModel.cpp.
References KDChart::AbstractProxyModel::mapFromSource(), and KDChart::AbstractProxyModel::mapToSource().
Referenced by setHeaderData(), and setModelData().
00085 { 00086 Q_ASSERT(sourceModel()); 00087 return mapFromSource(sourceModel()->index( row, col, mapToSource(index) )); 00088 }
void AttributesModel::initFrom | ( | const AttributesModel * | other | ) |
Definition at line 72 of file KDChartAttributesModel.cpp.
References mDataMap, mDefaultsMap, mHorizontalHeaderDataMap, mModelDataMap, mVerticalHeaderDataMap, paletteType(), and setPaletteType().
Referenced by KDChart::AbstractDiagram::setModel().
00073 { 00074 if( other == this || ! other ) return; 00075 00076 mDataMap = other->mDataMap; 00077 mHorizontalHeaderDataMap = other->mHorizontalHeaderDataMap; 00078 mVerticalHeaderDataMap = other->mVerticalHeaderDataMap; 00079 mModelDataMap = other->mModelDataMap; 00080 mDefaultsMap = other->mDefaultsMap; 00081 00082 setPaletteType( other->paletteType() ); 00083 }
bool AttributesModel::isKnownAttributesRole | ( | int | role | ) | const |
Returns whether the given role corresponds to one of the known internally used ones.
Definition at line 421 of file KDChartAttributesModel.cpp.
References KDChart::BarAttributesRole, KDChart::DataHiddenRole, KDChart::DatasetBrushRole, KDChart::DatasetPenRole, KDChart::DataValueLabelAttributesRole, KDChart::LineAttributesRole, KDChart::PieAttributesRole, KDChart::StockBarAttributesRole, KDChart::ThreeDAttributesRole, KDChart::ThreeDBarAttributesRole, KDChart::ThreeDLineAttributesRole, KDChart::ThreeDPieAttributesRole, and KDChart::ValueTrackerAttributesRole.
Referenced by compareAttributes(), data(), setData(), and setHeaderData().
00422 { 00423 bool oneOfOurs = false; 00424 switch( role ) { 00425 // fallthrough intended 00426 case DataValueLabelAttributesRole: 00427 case DatasetBrushRole: 00428 case DatasetPenRole: 00429 case ThreeDAttributesRole: 00430 case LineAttributesRole: 00431 case ThreeDLineAttributesRole: 00432 case BarAttributesRole: 00433 case StockBarAttributesRole: 00434 case ThreeDBarAttributesRole: 00435 case PieAttributesRole: 00436 case ThreeDPieAttributesRole: 00437 case ValueTrackerAttributesRole: 00438 case DataHiddenRole: 00439 oneOfOurs = true; 00440 default: 00441 break; 00442 } 00443 return oneOfOurs; 00444 }
QModelIndex KDChart::AbstractProxyModel::mapFromSource | ( | const QModelIndex & | sourceIndex | ) | const [inherited] |
[reimplemented]
Definition at line 52 of file KDChartAbstractProxyModel.cpp.
Referenced by KDChart::AbstractProxyModel::index(), and KDChart::AbstractProxyModel::parent().
00053 { 00054 if ( !sourceIndex.isValid() ) 00055 return QModelIndex(); 00056 //qDebug() << "sourceIndex.model()="<<sourceIndex.model(); 00057 //qDebug() << "model()="<<sourceModel(); 00058 Q_ASSERT( sourceIndex.model() == sourceModel() ); 00059 00060 // Create an index that preserves the internal pointer from the source; 00061 // this way AbstractProxyModel preserves the structure of the source model 00062 return createIndex( sourceIndex.row(), sourceIndex.column(), sourceIndex.internalPointer() ); 00063 }
QModelIndex KDChart::AbstractProxyModel::mapToSource | ( | const QModelIndex & | proxyIndex | ) | const [inherited] |
[reimplemented]
Definition at line 65 of file KDChartAbstractProxyModel.cpp.
Referenced by columnCount(), data(), KDChart::AbstractProxyModel::index(), KDChart::AbstractProxyModel::parent(), rowCount(), and setData().
00066 { 00067 if ( !proxyIndex.isValid() ) 00068 return QModelIndex(); 00069 if( proxyIndex.model() != this ) 00070 qDebug() << proxyIndex.model() << this; 00071 Q_ASSERT( proxyIndex.model() == this ); 00072 // So here we need to create a source index which holds that internal pointer. 00073 // No way to pass it to sourceModel()->index... so we have to do the ugly way: 00074 QModelIndex sourceIndex; 00075 KDPrivateModelIndex* hack = reinterpret_cast<KDPrivateModelIndex*>(&sourceIndex); 00076 hack->r = proxyIndex.row(); 00077 hack->c = proxyIndex.column(); 00078 hack->p = proxyIndex.internalPointer(); 00079 hack->m = sourceModel(); 00080 Q_ASSERT( sourceIndex.isValid() ); 00081 return sourceIndex; 00082 }
QVariant KDChart::AttributesModel::modelData | ( | int | role | ) | const |
Definition at line 518 of file KDChartAttributesModel.cpp.
Referenced by data(), KDChart::AbstractDiagram::dataValueAttributes(), headerData(), KDChart::AbstractDiagram::isHidden(), StockDiagram::stockBarAttributes(), and StockDiagram::threeDBarAttributes().
const QMap< int, QVariant > AttributesModel::modelDataMap | ( | ) | const [protected] |
AttributesModel::PaletteType AttributesModel::paletteType | ( | ) | const |
Definition at line 502 of file KDChartAttributesModel.cpp.
Referenced by compare(), headerData(), and initFrom().
QModelIndex KDChart::AbstractProxyModel::parent | ( | const QModelIndex & | index | ) | const [inherited] |
[reimplemented]
Definition at line 90 of file KDChartAbstractProxyModel.cpp.
References KDChart::AbstractProxyModel::mapFromSource(), and KDChart::AbstractProxyModel::mapToSource().
00091 { 00092 Q_ASSERT(sourceModel()); 00093 return mapFromSource(sourceModel()->parent( mapToSource(index) )); 00094 }
bool AttributesModel::resetData | ( | const QModelIndex & | index, | |
int | role = Qt::DisplayRole | |||
) |
Remove any explicit attributes settings that might have been specified before.
Definition at line 466 of file KDChartAttributesModel.cpp.
References setData().
bool AttributesModel::resetHeaderData | ( | int | section, | |
Qt::Orientation | orientation, | |||
int | role = Qt::DisplayRole | |||
) |
Remove any explicit attributes settings that might have been specified before.
Definition at line 492 of file KDChartAttributesModel.cpp.
References setHeaderData().
00493 { 00494 return setHeaderData ( section, orientation, QVariant(), role ); 00495 }
int AttributesModel::rowCount | ( | const QModelIndex & | index | ) | const |
[reimplemented]
Definition at line 523 of file KDChartAttributesModel.cpp.
References KDChart::AbstractProxyModel::mapToSource().
Referenced by StockDiagram::calculateDataBoundaries(), KDChart::AbstractDiagram::itemRowLabels(), StockDiagram::paint(), setHeaderData(), and setModelData().
00524 { 00525 if ( sourceModel() ) { 00526 return sourceModel()->rowCount( mapToSource(index) ); 00527 } else { 00528 return 0; 00529 } 00530 }
bool AttributesModel::setData | ( | const QModelIndex & | index, | |
const QVariant & | value, | |||
int | role = Qt::DisplayRole | |||
) |
[reimplemented]
Definition at line 452 of file KDChartAttributesModel.cpp.
References attributesChanged(), dataMap(), isKnownAttributesRole(), and KDChart::AbstractProxyModel::mapToSource().
Referenced by resetData(), KDChart::BarDiagram::setBarAttributes(), KDChart::AbstractDiagram::setBrush(), and KDChart::AbstractDiagram::setPen().
00453 { 00454 if ( !isKnownAttributesRole( role ) ) { 00455 return sourceModel()->setData( mapToSource(index), value, role ); 00456 } else { 00457 QMap< int, QMap< int, QVariant> > &colDataMap = mDataMap[ index.column() ]; 00458 QMap<int, QVariant> &dataMap = colDataMap[ index.row() ]; 00459 //qDebug() << "AttributesModel::setData" <<"role" << role << "value" << value; 00460 dataMap.insert( role, value ); 00461 emit attributesChanged( index, index ); 00462 return true; 00463 } 00464 }
void AttributesModel::setDataMap | ( | const QMap< int, QMap< int, QMap< int, QVariant > > > | map | ) | [protected] |
void AttributesModel::setDefaultForRole | ( | int | role, | |
const QVariant & | value | |||
) |
Define the default value for a certain role.
Passing a default-constructed QVariant is equivalent to removing the default.
Definition at line 695 of file KDChartAttributesModel.cpp.
Referenced by AttributesModel(), and KDChart::TernaryLineDiagram::TernaryLineDiagram().
00696 { 00697 if ( value.isValid() ) { 00698 mDefaultsMap.insert( role, value ); 00699 } else { 00700 // erase the possibily existing value to not let the map grow: 00701 QMap<int, QVariant>::iterator it = mDefaultsMap.find( role ); 00702 if ( it != mDefaultsMap.end() ) { 00703 mDefaultsMap.erase( it ); 00704 } 00705 } 00706 00707 Q_ASSERT( defaultsForRole( role ) == value ); 00708 }
bool AttributesModel::setHeaderData | ( | int | section, | |
Qt::Orientation | orientation, | |||
const QVariant & | value, | |||
int | role = Qt::DisplayRole | |||
) |
[reimplemented]
Definition at line 471 of file KDChartAttributesModel.cpp.
References attributesChanged(), dataMap(), headerData(), KDChart::AbstractProxyModel::index(), isKnownAttributesRole(), and rowCount().
Referenced by resetHeaderData(), KDChart::AbstractDiagram::setBrush(), KDChart::AbstractDiagram::setPen(), StockDiagram::setStockBarAttributes(), and StockDiagram::setThreeDBarAttributes().
00473 { 00474 if( sourceModel() != 0 && headerData( section, orientation, role ) == value ) 00475 return true; 00476 if ( !isKnownAttributesRole( role ) ) { 00477 return sourceModel()->setHeaderData( section, orientation, value, role ); 00478 } else { 00479 QMap<int, QMap<int, QVariant> > §ionDataMap 00480 = orientation == Qt::Horizontal ? mHorizontalHeaderDataMap : mVerticalHeaderDataMap; 00481 QMap<int, QVariant> &dataMap = sectionDataMap[ section ]; 00482 dataMap.insert( role, value ); 00483 if( sourceModel() ){ 00484 emit attributesChanged( index( 0, section, QModelIndex() ), 00485 index( rowCount( QModelIndex() ), section, QModelIndex() ) ); 00486 emit headerDataChanged( orientation, section, section ); 00487 } 00488 return true; 00489 } 00490 }
void AttributesModel::setHorizontalHeaderDataMap | ( | const QMap< int, QMap< int, QVariant > > | map | ) | [protected] |
bool KDChart::AttributesModel::setModelData | ( | const QVariant | value, | |
int | role | |||
) |
Definition at line 507 of file KDChartAttributesModel.cpp.
References attributesChanged(), columnCount(), KDChart::AbstractProxyModel::index(), and rowCount().
Referenced by KDChart::AbstractDiagram::setBrush(), KDChart::AbstractDiagram::setPen(), StockDiagram::setStockBarAttributes(), and StockDiagram::setThreeDBarAttributes().
00508 { 00509 mModelDataMap.insert( role, value ); 00510 if( sourceModel() ){ 00511 emit attributesChanged( index( 0, 0, QModelIndex() ), 00512 index( rowCount( QModelIndex() ), 00513 columnCount( QModelIndex() ), QModelIndex() ) ); 00514 } 00515 return true; 00516 }
void AttributesModel::setModelDataMap | ( | const QMap< int, QVariant > | map | ) | [protected] |
void AttributesModel::setPaletteType | ( | AttributesModel::PaletteType | type | ) |
Sets the palettetype used by this attributesmodel.
Definition at line 497 of file KDChartAttributesModel.cpp.
Referenced by initFrom().
00498 { 00499 mPaletteType = type; 00500 }
void AttributesModel::setSourceModel | ( | QAbstractItemModel * | sourceModel | ) |
[reimplemented]
Definition at line 541 of file KDChartAttributesModel.cpp.
Referenced by AttributesModel().
00542 { 00543 if( this->sourceModel() != 0 ) 00544 { 00545 disconnect( this->sourceModel(), SIGNAL( dataChanged( const QModelIndex&, const QModelIndex&)), 00546 this, SLOT( slotDataChanged( const QModelIndex&, const QModelIndex&))); 00547 disconnect( this->sourceModel(), SIGNAL( rowsInserted( const QModelIndex&, int, int ) ), 00548 this, SLOT( slotRowsInserted( const QModelIndex&, int, int ) ) ); 00549 disconnect( this->sourceModel(), SIGNAL( rowsRemoved( const QModelIndex&, int, int ) ), 00550 this, SLOT( slotRowsRemoved( const QModelIndex&, int, int ) ) ); 00551 disconnect( this->sourceModel(), SIGNAL( rowsAboutToBeInserted( const QModelIndex&, int, int ) ), 00552 this, SLOT( slotRowsAboutToBeInserted( const QModelIndex&, int, int ) ) ); 00553 disconnect( this->sourceModel(), SIGNAL( rowsAboutToBeRemoved( const QModelIndex&, int, int ) ), 00554 this, SLOT( slotRowsAboutToBeRemoved( const QModelIndex&, int, int ) ) ); 00555 disconnect( this->sourceModel(), SIGNAL( columnsInserted( const QModelIndex&, int, int ) ), 00556 this, SLOT( slotColumnsInserted( const QModelIndex&, int, int ) ) ); 00557 disconnect( this->sourceModel(), SIGNAL( columnsRemoved( const QModelIndex&, int, int ) ), 00558 this, SLOT( slotColumnsRemoved( const QModelIndex&, int, int ) ) ); 00559 disconnect( this->sourceModel(), SIGNAL( columnsAboutToBeInserted( const QModelIndex&, int, int ) ), 00560 this, SLOT( slotColumnsAboutToBeInserted( const QModelIndex&, int, int ) ) ); 00561 disconnect( this->sourceModel(), SIGNAL( columnsAboutToBeRemoved( const QModelIndex&, int, int ) ), 00562 this, SLOT( slotColumnsAboutToBeRemoved( const QModelIndex&, int, int ) ) ); 00563 disconnect( this->sourceModel(), SIGNAL( modelReset() ), 00564 this, SIGNAL( modelReset() ) ); 00565 disconnect( this->sourceModel(), SIGNAL( layoutChanged() ), 00566 this, SIGNAL( layoutChanged() ) ); 00567 } 00568 QAbstractProxyModel::setSourceModel( sourceModel ); 00569 if( this->sourceModel() != NULL ) 00570 { 00571 connect( this->sourceModel(), SIGNAL( dataChanged( const QModelIndex&, const QModelIndex&)), 00572 this, SLOT( slotDataChanged( const QModelIndex&, const QModelIndex&))); 00573 connect( this->sourceModel(), SIGNAL( rowsInserted( const QModelIndex&, int, int ) ), 00574 this, SLOT( slotRowsInserted( const QModelIndex&, int, int ) ) ); 00575 connect( this->sourceModel(), SIGNAL( rowsRemoved( const QModelIndex&, int, int ) ), 00576 this, SLOT( slotRowsRemoved( const QModelIndex&, int, int ) ) ); 00577 connect( this->sourceModel(), SIGNAL( rowsAboutToBeInserted( const QModelIndex&, int, int ) ), 00578 this, SLOT( slotRowsAboutToBeInserted( const QModelIndex&, int, int ) ) ); 00579 connect( this->sourceModel(), SIGNAL( rowsAboutToBeRemoved( const QModelIndex&, int, int ) ), 00580 this, SLOT( slotRowsAboutToBeRemoved( const QModelIndex&, int, int ) ) ); 00581 connect( this->sourceModel(), SIGNAL( columnsInserted( const QModelIndex&, int, int ) ), 00582 this, SLOT( slotColumnsInserted( const QModelIndex&, int, int ) ) ); 00583 connect( this->sourceModel(), SIGNAL( columnsRemoved( const QModelIndex&, int, int ) ), 00584 this, SLOT( slotColumnsRemoved( const QModelIndex&, int, int ) ) ); 00585 connect( this->sourceModel(), SIGNAL( columnsAboutToBeInserted( const QModelIndex&, int, int ) ), 00586 this, SLOT( slotColumnsAboutToBeInserted( const QModelIndex&, int, int ) ) ); 00587 connect( this->sourceModel(), SIGNAL( columnsAboutToBeRemoved( const QModelIndex&, int, int ) ), 00588 this, SLOT( slotColumnsAboutToBeRemoved( const QModelIndex&, int, int ) ) ); 00589 connect( this->sourceModel(), SIGNAL( modelReset() ), 00590 this, SIGNAL( modelReset() ) ); 00591 connect( this->sourceModel(), SIGNAL( layoutChanged() ), 00592 this, SIGNAL( layoutChanged() ) ); 00593 } 00594 }
void AttributesModel::setVerticalHeaderDataMap | ( | const QMap< int, QMap< int, QVariant > > | map | ) | [protected] |
const QMap< int, QMap< int, QVariant > > AttributesModel::verticalHeaderDataMap | ( | ) | const [protected] |