16 #include <QHeaderView> 39 , mCurrentEditSelectionModel( 0 )
40 , mFeatureSelectionModel( 0 )
42 , mEditSelectionDrag( false )
45 setSelectionMode( QAbstractItemView::ExtendedSelection );
55 QListView::setModel( featureListModel );
58 delete mFeatureSelectionModel;
60 setSelectionModel( mFeatureSelectionModel );
62 mCurrentEditSelectionModel =
new QItemSelectionModel( mModel->
masterModel(), this );
64 if ( mItemDelegate && mItemDelegate->parent() == this )
71 setItemDelegate( mItemDelegate );
74 connect( mFeatureSelectionModel, SIGNAL( requestRepaint( QModelIndexList ) ),
this, SLOT(
repaintRequested( QModelIndexList ) ) );
75 connect( mFeatureSelectionModel, SIGNAL( requestRepaint() ),
this, SLOT(
repaintRequested() ) );
77 connect( mCurrentEditSelectionModel, SIGNAL( selectionChanged( QItemSelection, QItemSelection ) ), SLOT( editSelectionChanged( QItemSelection, QItemSelection ) ) );
106 Q_FOREACH ( QModelIndex idx, mCurrentEditSelectionModel->selectedIndexes() )
116 viewport()->update( visualRegionForSelection( mCurrentEditSelectionModel->selection() ) );
123 QPoint pos =
event->pos();
125 QModelIndex
index = indexAt( pos );
129 mEditSelectionDrag =
true;
135 selectRow( index,
true );
145 void QgsFeatureListView::editSelectionChanged( QItemSelection deselected, QItemSelection selected )
147 if ( isVisible() && updatesEnabled() )
151 viewport()->update( visualRegionForSelection( localDeselected ) | visualRegionForSelection( localSelected ) );
154 QItemSelection currentSelection = mCurrentEditSelectionModel->selection();
155 if ( currentSelection.size() == 1 )
157 QModelIndexList indexList = currentSelection.indexes();
158 if ( !indexList.isEmpty() )
170 QItemSelection selection;
171 selection.append( QItemSelectionRange( mModel->
index( 0, 0 ), mModel->
index( mModel->
rowCount() - 1, 0 ) ) );
173 mFeatureSelectionModel->
selectFeatures( selection, QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows );
178 QItemSelection selection;
189 mCurrentEditSelectionModel->select( selection, QItemSelectionModel::ClearAndSelect );
198 mCurrentEditSelectionModel->select( index, command );
203 foreach (
const QModelIndex
index, indexes )
211 setDirtyRegion( viewport()->rect() );
222 QPoint pos =
event->pos();
224 QModelIndex
index = indexAt( pos );
226 if ( mEditSelectionDrag )
232 selectRow( index,
false );
247 if ( mEditSelectionDrag )
249 mEditSelectionDrag =
false;
259 if ( Qt::Key_Up == event->key() || Qt::Key_Down ==
event->key() )
262 if ( 0 != mCurrentEditSelectionModel->selectedIndexes().count() )
264 QModelIndex localIndex = mModel->
mapFromMaster( mCurrentEditSelectionModel->selectedIndexes().first() );
265 currentRow = localIndex.row();
268 QModelIndex newLocalIndex;
269 QModelIndex newIndex;
271 switch ( event->key() )
274 newLocalIndex = mModel->
index( currentRow - 1, 0 );
276 if ( newIndex.isValid() )
279 scrollTo( newLocalIndex );
284 newLocalIndex = mModel->
index( currentRow + 1, 0 );
286 if ( newIndex.isValid() )
289 scrollTo( newLocalIndex );
299 QListView::keyPressEvent( event );
305 QModelIndex
index = indexAt( event->pos() );
307 if ( index.isValid() )
312 menu.exec( event->globalPos() );
316 void QgsFeatureListView::selectRow(
const QModelIndex&
index,
bool anchor )
318 QItemSelectionModel::SelectionFlags command = selectionCommand(
index );
319 int row =
index.row();
324 if ( selectionMode() != QListView::SingleSelection
325 && command.testFlag( QItemSelectionModel::Toggle ) )
329 ? QItemSelectionModel::Deselect : QItemSelectionModel::Select;
330 command &= ~QItemSelectionModel::Toggle;
331 command |= mCtrlDragSelectionFlag;
333 command |= QItemSelectionModel::Current;
336 QModelIndex tl = model()->index( qMin( mRowAnchor, row ), 0 );
337 QModelIndex br = model()->index( qMax( mRowAnchor, row ), model()->columnCount() - 1 );
339 mFeatureSelectionModel->
selectFeatures( QItemSelection( tl, br ), command );
virtual bool isSelected(QgsFeatureId fid)
Returns the selection status of a given feature id.
void setCurrentFeatureEdited(bool state)
Sets if the currently shown form has received any edit events so far.
virtual void mouseReleaseEvent(QMouseEvent *event) override
QSet< QgsFeatureId > QgsFeatureIds
virtual QModelIndex mapToMaster(const QModelIndex &proxyIndex) const
virtual int rowCount(const QModelIndex &parent=QModelIndex()) const override
bool featureByIndex(const QModelIndex &index, QgsFeature &feat)
virtual QModelIndex mapFromMaster(const QModelIndex &sourceIndex) const
QgsVectorLayer * layer()
Returns the layer to which this cache belongs.
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
const QString displayExpression() const
Returns the expression which is currently used to render the features.
void enableSync(bool enable)
Enables or disables synchronisation to the QgsVectorLayer When synchronisation is disabled...
QString parserErrorString()
Returns a detailed message about errors while parsing a QgsExpression.
Element positionToElement(const QPoint &pos)
virtual QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const override
QgsFeatureListView(QWidget *parent=0)
Creates a feature list view.
QgsFeatureListModel * featureListModel()
Get the featureListModel used by this view.
void setFeatureSelectionModel(QgsFeatureSelectionModel *featureSelectionModel)
bool setDisplayExpression(const QString expression)
virtual QVariant data(const QModelIndex &index, int role) const override
void aboutToChangeEditSelection(bool &ok)
virtual void selectFeatures(const QItemSelection &selection, SelectionFlags command)
Select features on this table.
QString parserErrorString()
Returns a detailed message about errors while parsing a QgsExpression.
void setCurrentFeatureEdited(bool state)
QgsFeatureIds currentEditSelection()
Get the currentEditSelection.
virtual void mouseMoveEvent(QMouseEvent *event) override
QgsAttributeTableModel * masterModel()
void displayExpressionChanged(const QString expression)
Is emitted, whenever the display expression is successfully changed.
This class caches features of a given QgsVectorLayer.
void setEditSelection(const QgsFeatureIds &fids)
Set the feature(s) to be edited.
bool setDisplayExpression(const QString displayExpression)
The display expression is an expression used to render the fields into a single string which is displ...
virtual void selectAll() override
Select all currently visible features.
virtual void mousePressEvent(QMouseEvent *event) override
virtual void contextMenuEvent(QContextMenuEvent *event) override
virtual void keyPressEvent(QKeyEvent *event) override
QgsVectorLayerCache * layerCache()
QModelIndex fidToIdx(const QgsFeatureId fid) const
void setEditSelectionModel(QItemSelectionModel *editSelectionModel)
void currentEditSelectionChanged(QgsFeature &feat)
Is emitted, whenever the current edit selection has been changed.
virtual QItemSelection mapSelectionFromMaster(const QItemSelection &selection) const
virtual void setModel(QgsFeatureListModel *featureListModel)
Set the QgsFeatureListModel which is used to retrieve information.
QString displayExpression() const
QgsVectorLayerCache * layerCache()
Returns the layer cache.