27 #include <KDABLibFakes> 44 return sourceModel()->flags(
mapToSource( index ) );
50 Q_ASSERT_X( sourceModel(),
"DatasetProxyModel::setDatasetRowDescriptionVector",
51 "A source model must be set before the selection can be configured." );
52 initializeDatasetDecriptors( configuration, sourceModel()->rowCount(mRootIndex),
53 mRowSrcToProxyMap, mRowProxyToSrcMap );
60 Q_ASSERT_X( sourceModel(),
"DatasetProxyModel::setDatasetColumnDescriptionVector",
61 "A source model must be set before the selection can be configured." );
62 initializeDatasetDecriptors( configuration, sourceModel()->columnCount(mRootIndex),
63 mColSrcToProxyMap, mColProxyToSrcMap );
76 const QModelIndex &
parent )
const 79 mapProxyColumnToSource(column),
91 Q_ASSERT_X( sourceModel(),
"DatasetProxyModel::mapFromSource",
"A source " 92 "model must be set before the selection can be configured." );
94 if ( !sourceIndex.isValid() )
return sourceIndex;
96 if ( mRowSrcToProxyMap.isEmpty() && mColSrcToProxyMap.isEmpty() )
98 return createIndex( sourceIndex.row(), sourceIndex.column(),
99 sourceIndex.internalPointer() );
101 int row = mapSourceRowToProxy( sourceIndex.row() );
102 int column = mapSourceColumnToProxy( sourceIndex.column() );
103 return createIndex( row, column, sourceIndex.internalPointer() );
109 Q_ASSERT_X( sourceModel(),
"DatasetProxyModel::mapToSource",
"A source " 110 "model must be set before the selection can be configured." );
112 if ( !proxyIndex.isValid() )
return proxyIndex;
113 if ( mRowSrcToProxyMap.isEmpty() && mColSrcToProxyMap.isEmpty() )
115 return sourceModel()->index( proxyIndex.row(), proxyIndex.column(), mRootIndex );
117 int row = mapProxyRowToSource( proxyIndex.row() );
118 int column = mapProxyColumnToSource( proxyIndex.column() );
119 return sourceModel()->index( row, column, mRootIndex );
124 const QModelIndex & )
const 126 if ( mRowSrcToProxyMap.isEmpty() )
130 Q_ASSERT( sourceModel() );
131 Q_ASSERT( mRowSrcToProxyMap.size() == sourceModel()->rowCount(mRootIndex) );
132 if ( mRowSrcToProxyMap[sourceRow] == -1 )
136 Q_ASSERT( mRowSrcToProxyMap[sourceRow] >= 0
137 && mRowSrcToProxyMap[sourceRow] < mRowSrcToProxyMap.size() );
144 const QModelIndex & )
const 146 if ( mColSrcToProxyMap.isEmpty() )
150 Q_ASSERT( sourceModel() );
151 Q_ASSERT( mColSrcToProxyMap.size() == sourceModel()->columnCount(mRootIndex) );
152 if ( mColSrcToProxyMap[sourceColumn] == -1 )
156 Q_ASSERT( mColSrcToProxyMap[sourceColumn] >= 0
157 && mColSrcToProxyMap[sourceColumn] < mColSrcToProxyMap.size() );
163 int DatasetProxyModel::mapProxyRowToSource(
const int& proxyRow )
const 165 if ( mRowProxyToSrcMap.isEmpty() )
169 Q_ASSERT( proxyRow >= 0 && proxyRow < mRowProxyToSrcMap.size() );
170 return mRowProxyToSrcMap[ proxyRow ];
174 int DatasetProxyModel::mapProxyColumnToSource(
const int& proxyColumn )
const 176 if ( mColProxyToSrcMap.isEmpty() )
180 Q_ASSERT( proxyColumn >= 0 && proxyColumn < mColProxyToSrcMap.size() );
181 return mColProxyToSrcMap[ proxyColumn ];
185 int DatasetProxyModel::mapSourceRowToProxy(
const int& sourceRow )
const 187 if ( mRowSrcToProxyMap.isEmpty() )
191 Q_ASSERT( sourceRow >= 0 && sourceRow < mRowSrcToProxyMap.size() );
192 return mRowSrcToProxyMap[sourceRow];
196 int DatasetProxyModel::mapSourceColumnToProxy(
const int& sourceColumn )
const 198 if ( mColSrcToProxyMap.isEmpty() )
202 Q_ASSERT( sourceColumn >= 0 && sourceColumn < mColSrcToProxyMap.size() );
203 return mColSrcToProxyMap.at( sourceColumn ) ;
209 mRowSrcToProxyMap.clear();
210 mRowProxyToSrcMap.clear();
211 mColSrcToProxyMap.clear();
212 mColProxyToSrcMap.clear();
218 return sourceModel()->data(
mapToSource( index ), role );
223 return sourceModel()->setData(
mapToSource( index ), value, role );
228 if ( orientation == Qt::Horizontal )
230 if ( mapProxyColumnToSource ( section ) == -1 )
234 return sourceModel()->headerData( mapProxyColumnToSource( section ), orientation, role );
237 if ( mapProxyRowToSource ( section ) == -1 )
241 return sourceModel()->headerData( mapProxyRowToSource ( section ), orientation, role );
246 void DatasetProxyModel::initializeDatasetDecriptors(
248 const int sourceCount,
254 outProxyToSourceMap = inConfiguration;
255 outSourceToProxyMap.fill( -1, sourceCount );
261 if ( inConfiguration[
index] == -1 ) {
265 Q_ASSERT_X( inConfiguration[
index ] >= 0 && inConfiguration[
index ] < sourceCount,
266 "DatasetProxyModel::initializeDatasetDecriptors",
267 "column index outside of source model" );
268 Q_ASSERT_X( outSourceToProxyMap[ inConfiguration[
index ] ] == -1 ,
269 "DatasetProxyModel::initializeDatasetDecriptors",
270 "no duplicates allowed in mapping configuration, mapping has to be reversible" );
272 outSourceToProxyMap[ inConfiguration[
index ] ] =
index;
278 if ( sourceModel() ) {
279 disconnect( sourceModel(), SIGNAL( layoutChanged() ),
282 QSortFilterProxyModel::setSourceModel( m );
283 mRootIndex = QModelIndex();
285 connect( m, SIGNAL( layoutChanged() ),
287 connect( m, SIGNAL( layoutChanged() ),
this, SIGNAL( layoutChanged() ) );
294 mRootIndex = rootIdx;
DatasetProxyModel(QObject *parent=0)
Create a DatasetProxyModel.
void setDatasetDescriptionVectors(const DatasetDescriptionVector &rowConfig, const DatasetDescriptionVector &columnConfig)
Convenience method to configure rows and columns in one step.
void setSourceModel(QAbstractItemModel *sourceModel) override
Overloaded from base class.
void resetDatasetDescriptions()
Reset all dataset description.
void setDatasetRowDescriptionVector(const DatasetDescriptionVector &rowConfig)
Configure the dataset selection for the rows.
bool filterAcceptsColumn(int sourceColumn, const QModelIndex &) const override
Decide whether the column is accepted.
QModelIndex buddy(const QModelIndex &index) const override
bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const override
Decide whether the row is accepted.
QVariant data(const QModelIndex &index, int role) const override
Overloaded from base class.
bool setData(const QModelIndex &index, const QVariant &value, int role) override
Overloaded from base class.
void setDatasetColumnDescriptionVector(const DatasetDescriptionVector &columnConfig)
Configure the dataset selection for the columns.
QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const override
Overloaded from base class.
Class only listed here to document inheritance of some KDChart classes.
QModelIndex mapFromSource(const QModelIndex &sourceIndex) const override
Implements the mapping from the source to the proxy indexes.
QModelIndex parent(const QModelIndex &child) const override
Class only listed here to document inheritance of some KDChart classes.
void setSourceRootIndex(const QModelIndex &rootIdx)
Set the root index of the table in the source model.
QModelIndex mapToSource(const QModelIndex &proxyIndex) const override
Implements the mapping from the proxy to the source indexes.
Qt::ItemFlags flags(const QModelIndex &index) const override
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const override