#include <KDChartDatasetProxyModel.h>
The resulting model will only contain the part of the model that is selected by the dataset, and the according row and column header data.
Currently, this model is implemented for table models only. The way it would work with models representing a tree is to be decided.
The column selection is configured by passing a dataset description vector to the model. This vector (of integers) is supposed to have one value for each column of the original model. If the value at position x is -1, column x of the original model is not included in the dataset. If it is between 0 and (columnCount() -1), it is the column the source column is mapped to in the resulting model. Any other value is an error.
Definition at line 58 of file KDChartDatasetProxyModel.h.
Public Slots | |
void | resetDatasetDescriptions () |
Reset all dataset description. | |
void | setDatasetColumnDescriptionVector (const DatasetDescriptionVector &columnConfig) |
Configure the dataset selection for the columns. | |
void | setDatasetDescriptionVectors (const DatasetDescriptionVector &rowConfig, const DatasetDescriptionVector &columnConfig) |
Convenience method to configure rows and columns in one step. | |
void | setDatasetRowDescriptionVector (const DatasetDescriptionVector &rowConfig) |
Configure the dataset selection for the rows. | |
Public Member Functions | |
QModelIndex | buddy (const QModelIndex &index) const |
QVariant | data (const QModelIndex &index, int role) const |
Overloaded from base class. | |
DatasetProxyModel (QObject *parent=0) | |
Create a DatasetProxyModel. | |
Qt::ItemFlags | flags (const QModelIndex &index) const |
QVariant | headerData (int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const |
Overloaded from base class. | |
QModelIndex | index (int row, int column, const QModelIndex &parent=QModelIndex()) const |
QModelIndex | mapFromSource (const QModelIndex &sourceIndex) const |
Implements the mapping from the source to the proxy indexes. | |
QModelIndex | mapToSource (const QModelIndex &proxyIndex) const |
Implements the mapping from the proxy to the source indexes. | |
QModelIndex | parent (const QModelIndex &child) const |
bool | setData (const QModelIndex &index, const QVariant &value, int role) |
Overloaded from base class. | |
void | setSourceModel (QAbstractItemModel *sourceModel) |
Overloaded from base class. | |
void | setSourceRootIndex (const QModelIndex &rootIdx) |
Set the root index of the table in the source model. | |
Protected Member Functions | |
bool | filterAcceptsColumn (int sourceColumn, const QModelIndex &) const |
Decide whether the column is accepted. | |
bool | filterAcceptsRow (int source_row, const QModelIndex &source_parent) const |
Decide whether the row is accepted. |
DatasetProxyModel::DatasetProxyModel | ( | QObject * | parent = 0 |
) | [explicit] |
Create a DatasetProxyModel.
Without further configuration, this model is invalid.
Definition at line 35 of file KDChartDatasetProxyModel.cpp.
00036 : QSortFilterProxyModel ( parent ) 00037 { 00038 }
QModelIndex DatasetProxyModel::buddy | ( | const QModelIndex & | index | ) | const |
QVariant DatasetProxyModel::data | ( | const QModelIndex & | index, | |
int | role | |||
) | const |
Overloaded from base class.
Definition at line 219 of file KDChartDatasetProxyModel.cpp.
References mapToSource().
00220 { 00221 return sourceModel()->data( mapToSource ( index ), role ); 00222 }
bool DatasetProxyModel::filterAcceptsColumn | ( | int | sourceColumn, | |
const QModelIndex & | ||||
) | const [protected] |
Decide whether the column is accepted.
Definition at line 146 of file KDChartDatasetProxyModel.cpp.
00148 { 00149 if ( mColSrcToProxyMap.isEmpty() ) 00150 { // no column mapping set up yet, all columns are passed down: 00151 return true; 00152 } else { 00153 Q_ASSERT ( sourceModel() ); 00154 Q_ASSERT ( mColSrcToProxyMap.size() == sourceModel()->columnCount(mRootIndex) ); 00155 if ( mColSrcToProxyMap[sourceColumn] == -1 ) 00156 { // this column is explicitly not accepted: 00157 return false; 00158 } else { 00159 Q_ASSERT ( mColSrcToProxyMap[sourceColumn] >= 0 00160 && mColSrcToProxyMap[sourceColumn] < mColSrcToProxyMap.size() ); 00161 return true; 00162 } 00163 } 00164 }
bool DatasetProxyModel::filterAcceptsRow | ( | int | source_row, | |
const QModelIndex & | source_parent | |||
) | const [protected] |
Decide whether the row is accepted.
Definition at line 126 of file KDChartDatasetProxyModel.cpp.
00128 { 00129 if ( mRowSrcToProxyMap.isEmpty() ) 00130 { // no row mapping set, all rows are passed down: 00131 return true; 00132 } else { 00133 Q_ASSERT ( sourceModel() ); 00134 Q_ASSERT ( mRowSrcToProxyMap.size() == sourceModel()->rowCount(mRootIndex) ); 00135 if ( mRowSrcToProxyMap[sourceRow] == -1 ) 00136 { // this row is explicitly not accepted: 00137 return false; 00138 } else { 00139 Q_ASSERT ( mRowSrcToProxyMap[sourceRow] >= 0 00140 && mRowSrcToProxyMap[sourceRow] < mRowSrcToProxyMap.size() ); 00141 return true; 00142 } 00143 } 00144 }
Qt::ItemFlags DatasetProxyModel::flags | ( | const QModelIndex & | index | ) | const |
Definition at line 45 of file KDChartDatasetProxyModel.cpp.
References mapToSource().
00046 { 00047 return sourceModel()->flags( mapToSource( index ) ); 00048 }
QVariant DatasetProxyModel::headerData | ( | int | section, | |
Qt::Orientation | orientation, | |||
int | role = Qt::DisplayRole | |||
) | const |
Overloaded from base class.
Definition at line 229 of file KDChartDatasetProxyModel.cpp.
00230 { 00231 if ( orientation == Qt::Horizontal ) 00232 { 00233 if ( mapProxyColumnToSource ( section ) == -1 ) 00234 { 00235 return QVariant(); 00236 } else { 00237 return sourceModel()->headerData ( mapProxyColumnToSource ( section ), 00238 orientation, role ); 00239 } 00240 } else { 00241 if ( mapProxyRowToSource ( section ) == -1 ) 00242 { 00243 return QVariant(); 00244 } else { 00245 return sourceModel()->headerData ( mapProxyRowToSource ( section ), 00246 orientation, role ); 00247 } 00248 } 00249 }
QModelIndex DatasetProxyModel::index | ( | int | row, | |
int | column, | |||
const QModelIndex & | parent = QModelIndex() | |||
) | const |
Definition at line 78 of file KDChartDatasetProxyModel.cpp.
References mapFromSource().
00080 { 00081 return mapFromSource( sourceModel()->index( mapProxyRowToSource(row), 00082 mapProxyColumnToSource(column), 00083 parent ) ); 00084 }
QModelIndex DatasetProxyModel::mapFromSource | ( | const QModelIndex & | sourceIndex | ) | const |
Implements the mapping from the source to the proxy indexes.
Definition at line 92 of file KDChartDatasetProxyModel.cpp.
Referenced by index(), and parent().
00093 { 00094 Q_ASSERT_X ( sourceModel(), "DatasetProxyModel::mapFromSource", "A source " 00095 "model must be set before the selection can be configured." ); 00096 00097 if ( !sourceIndex.isValid() ) return sourceIndex; 00098 00099 if ( mRowSrcToProxyMap.isEmpty() && mColSrcToProxyMap.isEmpty() ) 00100 { 00101 return createIndex ( sourceIndex.row(), sourceIndex.column(), 00102 sourceIndex.internalPointer() ); 00103 } else { 00104 int row = mapSourceRowToProxy ( sourceIndex.row() ); 00105 int column = mapSourceColumnToProxy ( sourceIndex.column() ); 00106 return createIndex ( row, column, sourceIndex.internalPointer() ); 00107 } 00108 }
QModelIndex DatasetProxyModel::mapToSource | ( | const QModelIndex & | proxyIndex | ) | const |
Implements the mapping from the proxy to the source indexes.
Definition at line 110 of file KDChartDatasetProxyModel.cpp.
Referenced by data(), flags(), parent(), and setData().
00111 { 00112 Q_ASSERT_X ( sourceModel(), "DatasetProxyModel::mapToSource", "A source " 00113 "model must be set before the selection can be configured." ); 00114 00115 if ( !proxyIndex.isValid() ) return proxyIndex; 00116 if ( mRowSrcToProxyMap.isEmpty() && mColSrcToProxyMap.isEmpty() ) 00117 { 00118 return sourceModel()->index( proxyIndex.row(), proxyIndex.column(), mRootIndex ); 00119 } else { 00120 int row = mapProxyRowToSource ( proxyIndex.row() ); 00121 int column = mapProxyColumnToSource ( proxyIndex.column() ); 00122 return sourceModel()->index( row, column, mRootIndex ); 00123 } 00124 }
QModelIndex DatasetProxyModel::parent | ( | const QModelIndex & | child | ) | const |
Definition at line 86 of file KDChartDatasetProxyModel.cpp.
References mapFromSource(), and mapToSource().
00087 { 00088 // return mapFromSource( sourceModel()->parent( child ) ); 00089 return mapFromSource( sourceModel()->parent( mapToSource( child ) ) ); 00090 }
void DatasetProxyModel::resetDatasetDescriptions | ( | ) | [slot] |
Reset all dataset description.
After that, the result of the proxying is an empty model (a new dataset description needs to be set to achieve a non-empty result).
Definition at line 210 of file KDChartDatasetProxyModel.cpp.
Referenced by setSourceModel(), and setSourceRootIndex().
00211 { 00212 mRowSrcToProxyMap.clear(); 00213 mRowProxyToSrcMap.clear(); 00214 mColSrcToProxyMap.clear(); 00215 mColProxyToSrcMap.clear(); 00216 clear(); 00217 }
bool DatasetProxyModel::setData | ( | const QModelIndex & | index, | |
const QVariant & | value, | |||
int | role | |||
) |
Overloaded from base class.
Definition at line 224 of file KDChartDatasetProxyModel.cpp.
References mapToSource().
00225 { 00226 return sourceModel()->setData( mapToSource( index ), value, role ); 00227 }
void DatasetProxyModel::setDatasetColumnDescriptionVector | ( | const DatasetDescriptionVector & | columnConfig | ) | [slot] |
Configure the dataset selection for the columns.
Every call to this method resets the previous dataset description.
Definition at line 60 of file KDChartDatasetProxyModel.cpp.
Referenced by setDatasetDescriptionVectors().
00062 { 00063 Q_ASSERT_X ( sourceModel(), "DatasetProxyModel::setDatasetColumnDescriptionVector", 00064 "A source model must be set before the selection can be configured." ); 00065 initializeDatasetDecriptors ( configuration, sourceModel()->columnCount(mRootIndex), 00066 mColSrcToProxyMap, mColProxyToSrcMap ); 00067 clear(); // clear emits layoutChanged() 00068 }
void DatasetProxyModel::setDatasetDescriptionVectors | ( | const DatasetDescriptionVector & | rowConfig, | |
const DatasetDescriptionVector & | columnConfig | |||
) | [slot] |
Convenience method to configure rows and columns in one step.
Definition at line 70 of file KDChartDatasetProxyModel.cpp.
References setDatasetColumnDescriptionVector(), and setDatasetRowDescriptionVector().
00073 { 00074 setDatasetRowDescriptionVector( rowConfig ); 00075 setDatasetColumnDescriptionVector ( columnConfig ); 00076 }
void DatasetProxyModel::setDatasetRowDescriptionVector | ( | const DatasetDescriptionVector & | rowConfig | ) | [slot] |
Configure the dataset selection for the rows.
Every call to this method resets the previous dataset description.
Definition at line 50 of file KDChartDatasetProxyModel.cpp.
Referenced by setDatasetDescriptionVectors().
00052 { 00053 Q_ASSERT_X ( sourceModel(), "DatasetProxyModel::setDatasetRowDescriptionVector", 00054 "A source model must be set before the selection can be configured." ); 00055 initializeDatasetDecriptors ( configuration, sourceModel()->rowCount(mRootIndex), 00056 mRowSrcToProxyMap, mRowProxyToSrcMap ); 00057 clear(); // clear emits layoutChanged() 00058 }
void DatasetProxyModel::setSourceModel | ( | QAbstractItemModel * | sourceModel | ) |
Overloaded from base class.
Definition at line 283 of file KDChartDatasetProxyModel.cpp.
References resetDatasetDescriptions().
00284 { 00285 QSortFilterProxyModel::setSourceModel ( sourceModel ); 00286 mRootIndex = QModelIndex(); 00287 connect ( sourceModel, SIGNAL ( layoutChanged() ), 00288 SLOT( resetDatasetDescriptions() ) ); 00289 00290 resetDatasetDescriptions(); 00291 }
void DatasetProxyModel::setSourceRootIndex | ( | const QModelIndex & | rootIdx | ) |
Set the root index of the table in the source model.
Definition at line 293 of file KDChartDatasetProxyModel.cpp.
References resetDatasetDescriptions().
00294 { 00295 mRootIndex = rootIdx; 00296 resetDatasetDescriptions(); 00297 }