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 mFeatureSelectionManager = featureSelectionManager;
163 void QgsFeatureSelectionModel::layerSelectionChanged(
const QgsFeatureIds &selected,
const QgsFeatureIds &deselected,
bool clearAndSelect )
165 if ( clearAndSelect )
171 QModelIndexList updatedIndexes;
172 const auto constSelected = selected;
175 updatedIndexes.append( expandIndexToRow( mFeatureModel->
fidToIndex( fid ) ) );
178 const auto constDeselected = deselected;
181 updatedIndexes.append( expandIndexToRow( mFeatureModel->
fidToIndex( fid ) ) );
188 QModelIndexList QgsFeatureSelectionModel::expandIndexToRow(
const QModelIndex &index )
const 190 QModelIndexList indexes;
191 const QAbstractItemModel *model = index.model();
192 int row = index.row();
197 int columns = model->columnCount();
198 indexes.reserve( columns );
199 for (
int column = 0; column < columns; ++column )
201 indexes.append( model->index( row, column ) );
virtual bool isSelected(QgsFeatureId fid)
Returns the selection status of a given feature id.
QSet< QgsFeatureId > QgsFeatureIds
virtual void selectFeatures(const QItemSelection &selection, QItemSelectionModel::SelectionFlags command)
Select features on this table.
virtual void setSelectedFeatures(const QgsFeatureIds &ids)=0
Change selection to the new set of features.
void selectionChanged(const QgsFeatureIds &selected, const QgsFeatureIds &deselected, bool clearAndSelect)
Emitted when selection was changed.
void enableSync(bool enable)
Enables or disables synchronisation to the QgsVectorLayer When synchronisation is disabled...
virtual QModelIndex fidToIndex(QgsFeatureId fid)=0
Get the feature id of the feature in this row.
virtual void deselect(const QgsFeatureIds &ids)=0
Deselect features by feature ids.
void requestRepaint()
Request a repaint of the visible items of connected views.
virtual const QgsFeatureIds & selectedFeatureIds() const =0
Returns reference to identifiers of selected features.
virtual void setFeatureSelectionManager(QgsIFeatureSelectionManager *featureSelectionManager)
QgsFeatureSelectionModel(QAbstractItemModel *model, QgsFeatureModel *featureModel, QgsIFeatureSelectionManager *featureSelectionHandler, QObject *parent)
Is an interface class to abstract feature selection handling.
virtual void select(const QgsFeatureIds &ids)=0
Select features by feature ids.