23 : QItemSelectionModel( model, parent )
24 , mFeatureModel( featureModel )
25 , mSyncEnabled( true )
26 , mClearAndSelectBuffer( false )
33 mSyncEnabled = enable;
37 if ( mClearAndSelectBuffer )
43 mFeatureSelectionManager->
select( mSelectedBuffer );
44 mFeatureSelectionManager->
deselect( mDeselectedBuffer );
47 mSelectedBuffer.clear();
48 mDeselectedBuffer.clear();
49 mClearAndSelectBuffer =
false;
55 if ( mSelectedBuffer.contains( fid ) )
58 if ( mDeselectedBuffer.contains( fid ) )
61 if ( !mClearAndSelectBuffer && mFeatureSelectionManager->
selectedFeatureIds().contains( fid ) )
76 QgsDebugMsg( QStringLiteral(
"Index count: %1" ).arg( selection.indexes().size() ) );
78 const auto constIndexes = selection.indexes();
79 for (
const QModelIndex &index : constIndexes )
88 if ( command.testFlag( QItemSelectionModel::ClearAndSelect ) )
92 mClearAndSelectBuffer =
true;
93 const auto constIds = ids;
96 if ( !mDeselectedBuffer.remove(
id ) )
98 mSelectedBuffer.insert(
id );
107 else if ( command.testFlag( QItemSelectionModel::Select ) )
111 const auto constIds = ids;
114 if ( !mDeselectedBuffer.remove(
id ) )
116 mSelectedBuffer.insert(
id );
122 mFeatureSelectionManager->
select( ids );
125 else if ( command.testFlag( QItemSelectionModel::Deselect ) )
129 const auto constIds = ids;
132 if ( !mSelectedBuffer.remove(
id ) )
134 mDeselectedBuffer.insert(
id );
140 mFeatureSelectionManager->
deselect( ids );
146 QModelIndexList updatedIndexes;
147 const auto indexes = selection.indexes();
148 for (
const QModelIndex &idx : indexes )
150 updatedIndexes.append( expandIndexToRow( idx ) );
158 if ( mFeatureSelectionManager )
161 mFeatureSelectionManager = featureSelectionManager;
166 void QgsFeatureSelectionModel::layerSelectionChanged(
const QgsFeatureIds &selected,
const QgsFeatureIds &deselected,
bool clearAndSelect )
168 if ( clearAndSelect )
174 QModelIndexList updatedIndexes;
175 const auto constSelected = selected;
178 updatedIndexes.append( expandIndexToRow( mFeatureModel->
fidToIndex( fid ) ) );
181 const auto constDeselected = deselected;
184 updatedIndexes.append( expandIndexToRow( mFeatureModel->
fidToIndex( fid ) ) );
191 QModelIndexList QgsFeatureSelectionModel::expandIndexToRow(
const QModelIndex &index )
const
193 QModelIndexList indexes;
194 const QAbstractItemModel *model = index.model();
195 int row = index.row();
200 int columns = model->columnCount();
201 indexes.reserve( columns );
202 for (
int column = 0; column < columns; ++column )
204 indexes.append( model->index( row, column ) );