QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
qgsfeaturelistview.h
Go to the documentation of this file.
1 /***************************************************************************
2  QgsAttributeListView.h
3  --------------------------------------
4  Date : Jan 2012
5  Copyright : (C) 2013 Matthias Kuhn
6  Email : matthias at opengis dot ch
7  ***************************************************************************
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  ***************************************************************************/
15 
16 #ifndef QGSFEATURELISTVIEW_H
17 #define QGSFEATURELISTVIEW_H
18 
19 #include <QListView>
20 #include "qgis_sip.h"
21 #include <qdebug.h>
22 #include "qgsactionmenu.h"
23 
24 #include "qgsfeature.h" // For QgsFeatureIds
25 #include "qgis_gui.h"
26 #include <QTimer>
27 
33 class QgsVectorLayer;
36 class QRect;
37 
46 class GUI_EXPORT QgsFeatureListView : public QListView
47 {
48  Q_OBJECT
49 
50  public:
51 
57  explicit QgsFeatureListView( QWidget *parent SIP_TRANSFERTHIS = nullptr );
58 
63  QgsVectorLayerCache *layerCache();
64 
65 #ifdef __clang__
66 #pragma clang diagnostic push
67 #pragma clang diagnostic ignored "-Woverloaded-virtual"
68 #endif
69 
75  virtual void setModel( QgsFeatureListModel *featureListModel );
76 #ifdef __clang__
77 #pragma clang diagnostic pop
78 #endif
79 
85  QgsFeatureListModel *featureListModel() { return mModel; }
86 
95  bool setDisplayExpression( const QString &displayExpression );
96 
104  const QString displayExpression() const;
105 
111  QString parserErrorString();
112 
118  QgsFeatureIds currentEditSelection();
119 
125  void setCurrentFeatureEdited( bool state );
126 
131  void setFeatureSelectionManager( QgsIFeatureSelectionManager *featureSelectionManager );
132 
133  protected:
134  void mouseMoveEvent( QMouseEvent *event ) override;
135  void mousePressEvent( QMouseEvent *event ) override;
136  void mouseReleaseEvent( QMouseEvent *event ) override;
137  void keyPressEvent( QKeyEvent *event ) override;
138  void contextMenuEvent( QContextMenuEvent *event ) override;
139 
140  signals:
141 
146  void currentEditSelectionChanged( QgsFeature &feat );
147 
154  void currentEditSelectionProgressChanged( int progress, int count );
155 
160  void displayExpressionChanged( const QString &expression );
161 
163  void aboutToChangeEditSelection( bool &ok ) SIP_SKIP;
164 
170  void willShowContextMenu( QgsActionMenu *menu, const QModelIndex &atIndex );
171 
172  public slots:
173 
179  void setEditSelection( const QgsFeatureIds &fids );
180 
187  void setEditSelection( const QModelIndex &index, QItemSelectionModel::SelectionFlags command );
188 
192  void selectAll() override;
193 
194  void repaintRequested( const QModelIndexList &indexes );
195  void repaintRequested();
196 
201  void editFirstFeature() {editOtherFeature( First );}
202 
207  void editNextFeature() {editOtherFeature( Next );}
208 
213  void editPreviousFeature() {editOtherFeature( Previous );}
214 
219  void editLastFeature() {editOtherFeature( Last );}
220 
221 
222 
223  private slots:
224  void editSelectionChanged( const QItemSelection &deselected, const QItemSelection &selected );
225 
232  void ensureEditSelection( bool inSelection = false );
233 
234  private:
235  void selectRow( const QModelIndex &index, bool anchor );
236 
237  enum PositionInList
238  {
239  First,
240  Next,
241  Previous,
242  Last
243  };
244 
245  void editOtherFeature( PositionInList positionInList );
246 
247 
248  QgsFeatureListModel *mModel = nullptr;
249  QItemSelectionModel *mCurrentEditSelectionModel = nullptr;
250  QgsFeatureSelectionModel *mFeatureSelectionModel = nullptr;
251  QgsIFeatureSelectionManager *mOwnedFeatureSelectionManager = nullptr;
252  QgsIFeatureSelectionManager *mFeatureSelectionManager = nullptr;
253  QgsFeatureListViewDelegate *mItemDelegate = nullptr;
254 
255  enum class DragMode
256  {
257  Inactive,
258  ExpandSelection,
259  MoveSelection
260  };
261 
262  DragMode mDragMode = DragMode::Inactive;
263 
264  int mRowAnchor = 0;
265  QItemSelectionModel::SelectionFlags mCtrlDragSelectionFlag;
266 
267  QTimer mUpdateEditSelectionTimer;
268 
269  friend class QgsDualView;
270 };
271 
272 #endif
QgsFeatureListView::editPreviousFeature
void editPreviousFeature()
editPreviousFeature will try to edit previous feature of the list
Definition: qgsfeaturelistview.h:213
QgsVectorLayerCache
This class caches features of a given QgsVectorLayer.
Definition: qgsvectorlayercache.h:46
QgsFeatureSelectionModel
Definition: qgsfeatureselectionmodel.h:31
qgsfeature.h
QgsFeatureListView
Shows a list of features and renders a edit button next to each feature.
Definition: qgsfeaturelistview.h:46
QgsDualView
This widget is used to show the attributes of a set of features of a QgsVectorLayer....
Definition: qgsdualview.h:44
QgsFeatureListView::editLastFeature
void editLastFeature()
editLastFeature will try to edit the last feature of the list
Definition: qgsfeaturelistview.h:219
SIP_SKIP
#define SIP_SKIP
Definition: qgis_sip.h:126
QgsAttributeTableModel
A model backed by a QgsVectorLayerCache which is able to provide feature/attribute information to a Q...
Definition: qgsattributetablemodel.h:49
qgis_sip.h
QgsActionMenu
This class is a menu that is populated automatically with the actions defined for a given layer.
Definition: qgsactionmenu.h:37
QgsFeatureListView::featureListModel
QgsFeatureListModel * featureListModel()
Gets the featureListModel used by this view.
Definition: qgsfeaturelistview.h:85
QgsFeatureIds
QSet< QgsFeatureId > QgsFeatureIds
Definition: qgsfeatureid.h:37
qgsactionmenu.h
QgsAttributeTableFilterModel
Definition: qgsattributetablefiltermodel.h:36
QgsFeatureListModel
Definition: qgsfeaturelistmodel.h:39
QgsVectorLayer
Represents a vector layer which manages a vector based data sets.
Definition: qgsvectorlayer.h:391
QgsFeature
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
Definition: qgsfeature.h:55
QgsFeatureListView::editFirstFeature
void editFirstFeature()
editFirstFeature will try to edit the first feature of the list
Definition: qgsfeaturelistview.h:201
QgsIFeatureSelectionManager
Is an interface class to abstract feature selection handling.
Definition: qgsifeatureselectionmanager.h:31
QgsFeatureListViewDelegate
Definition: qgsfeaturelistviewdelegate.h:31
SIP_TRANSFERTHIS
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:53
QgsFeatureListView::editNextFeature
void editNextFeature()
editNextFeature will try to edit next feature of the list
Definition: qgsfeaturelistview.h:207