23#include "moc_qgsfeatureselectionmodel.cpp"
26 : QItemSelectionModel( model, parent )
27 , mFeatureModel( featureModel )
34 mSyncEnabled = enable;
38 if ( mClearAndSelectBuffer )
40 mFeatureSelectionManager->setSelectedFeatures( mSelectedBuffer );
44 mFeatureSelectionManager->select( mSelectedBuffer );
45 mFeatureSelectionManager->deselect( mDeselectedBuffer );
48 mSelectedBuffer.clear();
49 mDeselectedBuffer.clear();
50 mClearAndSelectBuffer =
false;
56 if ( mSelectedBuffer.contains( fid ) )
59 if ( mDeselectedBuffer.contains( fid ) )
62 if ( !mClearAndSelectBuffer && mFeatureSelectionManager->selectedFeatureIds().contains( fid ) )
77 QgsDebugMsgLevel( QStringLiteral(
"Index count: %1" ).arg( selection.indexes().size() ), 2 );
79 const auto constIndexes = selection.indexes();
80 for (
const QModelIndex &index : constIndexes )
89 if ( command.testFlag( QItemSelectionModel::ClearAndSelect ) )
93 mClearAndSelectBuffer =
true;
94 const auto constIds = ids;
97 if ( !mDeselectedBuffer.remove(
id ) )
99 mSelectedBuffer.insert(
id );
105 mFeatureSelectionManager->setSelectedFeatures( ids );
108 else if ( command.testFlag( QItemSelectionModel::Select ) )
112 const auto constIds = ids;
115 if ( !mDeselectedBuffer.remove(
id ) )
117 mSelectedBuffer.insert(
id );
123 mFeatureSelectionManager->select( ids );
126 else if ( command.testFlag( QItemSelectionModel::Deselect ) )
130 const auto constIds = ids;
133 if ( !mSelectedBuffer.remove(
id ) )
135 mDeselectedBuffer.insert(
id );
141 mFeatureSelectionManager->deselect( ids );
147 QModelIndexList updatedIndexes;
148 const auto indexes = selection.indexes();
149 for (
const QModelIndex &idx : indexes )
151 updatedIndexes.append( expandIndexToRow( idx ) );
159 if ( mFeatureSelectionManager )
162 mFeatureSelectionManager = featureSelectionManager;
167void QgsFeatureSelectionModel::layerSelectionChanged(
const QgsFeatureIds &selected,
const QgsFeatureIds &deselected,
bool clearAndSelect )
169 if ( clearAndSelect )
175 QModelIndexList updatedIndexes;
176 const auto constSelected = selected;
179 updatedIndexes.append( expandIndexToRow( mFeatureModel->fidToIndex( fid ) ) );
182 const auto constDeselected = deselected;
185 updatedIndexes.append( expandIndexToRow( mFeatureModel->fidToIndex( fid ) ) );
192QModelIndexList QgsFeatureSelectionModel::expandIndexToRow(
const QModelIndex &index )
const
194 QModelIndexList indexes;
195 const QAbstractItemModel *model = index.model();
196 const int row = index.row();
201 const int columns = model->columnCount();
202 indexes.reserve( columns );
203 for (
int column = 0; column < columns; ++column )
205 indexes.append( model->index( row, column ) );
@ FeatureId
Get the feature id of the feature in this row.
Base class for feature models.
void enableSync(bool enable)
Enables or disables synchronisation to the QgsVectorLayer When synchronisation is disabled,...
virtual void selectFeatures(const QItemSelection &selection, QItemSelectionModel::SelectionFlags command)
Select features on this table.
virtual bool isSelected(QgsFeatureId fid)
Returns the selection status of a given feature id.
QgsFeatureSelectionModel(QAbstractItemModel *model, QgsFeatureModel *featureModel, QgsIFeatureSelectionManager *featureSelectionHandler, QObject *parent)
virtual void setFeatureSelectionManager(QgsIFeatureSelectionManager *featureSelectionManager)
void requestRepaint()
Request a repaint of the visible items of connected views.
Is an interface class to abstract feature selection handling.
void selectionChanged(const QgsFeatureIds &selected, const QgsFeatureIds &deselected, bool clearAndSelect)
Emitted when selection was changed.
QSet< QgsFeatureId > QgsFeatureIds
qint64 QgsFeatureId
64 bit feature ids negative numbers are used for uncommitted/newly added features
#define QgsDebugMsgLevel(str, level)