QGIS API Documentation  3.20.0-Odense (decaadbb31)
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 
70  virtual void setModel( QgsFeatureListModel *featureListModel );
71 
77  QgsFeatureListModel *featureListModel() { return mModel; }
78 
87  bool setDisplayExpression( const QString &displayExpression );
88 
96  const QString displayExpression() const;
97 
103  QString parserErrorString();
104 
110  QgsFeatureIds currentEditSelection();
111 
117  void setCurrentFeatureEdited( bool state );
118 
123  void setFeatureSelectionManager( QgsIFeatureSelectionManager *featureSelectionManager );
124 
125  protected:
126  void mouseMoveEvent( QMouseEvent *event ) override;
127  void mousePressEvent( QMouseEvent *event ) override;
128  void mouseReleaseEvent( QMouseEvent *event ) override;
129  void keyPressEvent( QKeyEvent *event ) override;
130  void contextMenuEvent( QContextMenuEvent *event ) override;
131 
132  signals:
133 
139 
146  void currentEditSelectionProgressChanged( int progress, int count );
147 
152  void displayExpressionChanged( const QString &expression );
153 
156 
162  void willShowContextMenu( QgsActionMenu *menu, const QModelIndex &atIndex );
163 
164  public slots:
165 
171  void setEditSelection( const QgsFeatureIds &fids );
172 
179  void setEditSelection( const QModelIndex &index, QItemSelectionModel::SelectionFlags command );
180 
184  void selectAll() override;
185 
186  void repaintRequested( const QModelIndexList &indexes );
187  void repaintRequested();
188 
193  void editFirstFeature() {editOtherFeature( First );}
194 
199  void editNextFeature() {editOtherFeature( Next );}
200 
205  void editPreviousFeature() {editOtherFeature( Previous );}
206 
211  void editLastFeature() {editOtherFeature( Last );}
212 
213 
214 
215  private slots:
216  void editSelectionChanged( const QItemSelection &deselected, const QItemSelection &selected );
217 
224  void ensureEditSelection( bool inSelection = false );
225 
226  private:
227  void selectRow( const QModelIndex &index, bool anchor );
228 
229  enum PositionInList
230  {
231  First,
232  Next,
233  Previous,
234  Last
235  };
236 
237  void editOtherFeature( PositionInList positionInList );
238 
239 
240  QgsFeatureListModel *mModel = nullptr;
241  QItemSelectionModel *mCurrentEditSelectionModel = nullptr;
242  QgsFeatureSelectionModel *mFeatureSelectionModel = nullptr;
243  QgsIFeatureSelectionManager *mOwnedFeatureSelectionManager = nullptr;
244  QgsIFeatureSelectionManager *mFeatureSelectionManager = nullptr;
245  QgsFeatureListViewDelegate *mItemDelegate = nullptr;
246  bool mEditSelectionDrag = false; // Is set to true when the user initiated a left button click over an edit button and still keeps pressing //!< TODO
247  int mRowAnchor = 0;
248  QItemSelectionModel::SelectionFlags mCtrlDragSelectionFlag;
249 
250  QTimer mUpdateEditSelectionTimer;
251 
252  friend class QgsDualView;
253 };
254 
255 #endif
This class is a menu that is populated automatically with the actions defined for a given layer.
Definition: qgsactionmenu.h:38
A model backed by a QgsVectorLayerCache which is able to provide feature/attribute information to a Q...
This widget is used to show the attributes of a set of features of a QgsVectorLayer.
Definition: qgsdualview.h:45
Shows a list of features and renders a edit button next to each feature.
QgsFeatureListModel * featureListModel()
Gets the featureListModel used by this view.
void currentEditSelectionProgressChanged(int progress, int count)
Emitted whenever the current edit selection has been changed.
void editNextFeature()
editNextFeature will try to edit next feature of the list
void editLastFeature()
editLastFeature will try to edit the last feature of the list
void editFirstFeature()
editFirstFeature will try to edit the first feature of the list
void displayExpressionChanged(const QString &expression)
Emitted whenever the display expression is successfully changed.
void editPreviousFeature()
editPreviousFeature will try to edit previous feature of the list
void willShowContextMenu(QgsActionMenu *menu, const QModelIndex &atIndex)
Emitted when the context menu is created to add the specific actions to it.
void currentEditSelectionChanged(QgsFeature &feat)
Emitted whenever the current edit selection has been changed.
void aboutToChangeEditSelection(bool &ok)
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
Definition: qgsfeature.h:56
Is an interface class to abstract feature selection handling.
This class caches features of a given QgsVectorLayer.
Represents a vector layer which manages a vector based data sets.
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:53
#define SIP_SKIP
Definition: qgis_sip.h:126
QSet< QgsFeatureId > QgsFeatureIds
Definition: qgsfeatureid.h:37