QGIS API Documentation  3.10.0-A Coruña (6c816b4204)
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 
32 class QgsVectorLayer;
35 class QRect;
36 
45 class GUI_EXPORT QgsFeatureListView : public QListView
46 {
47  Q_OBJECT
48 
49  public:
50 
56  explicit QgsFeatureListView( QWidget *parent SIP_TRANSFERTHIS = nullptr );
57 
62  QgsVectorLayerCache *layerCache();
63 
69  virtual void setModel( QgsFeatureListModel *featureListModel );
70 
76  QgsFeatureListModel *featureListModel() { return mModel; }
77 
86  bool setDisplayExpression( const QString &displayExpression );
87 
95  const QString displayExpression() const;
96 
102  QString parserErrorString();
103 
109  QgsFeatureIds currentEditSelection();
110 
116  void setCurrentFeatureEdited( bool state );
117 
122  void setFeatureSelectionManager( QgsIFeatureSelectionManager *featureSelectionManager SIP_TRANSFER );
123 
124  protected:
125  void mouseMoveEvent( QMouseEvent *event ) override;
126  void mousePressEvent( QMouseEvent *event ) override;
127  void mouseReleaseEvent( QMouseEvent *event ) override;
128  void keyPressEvent( QKeyEvent *event ) override;
129  void contextMenuEvent( QContextMenuEvent *event ) override;
130 
131  signals:
132 
137  void currentEditSelectionChanged( QgsFeature &feat );
138 
145  void currentEditSelectionProgressChanged( int progress, int count );
146 
151  void displayExpressionChanged( const QString &expression );
152 
154  void aboutToChangeEditSelection( bool &ok ) SIP_SKIP;
155 
161  void willShowContextMenu( QgsActionMenu *menu, const QModelIndex &atIndex );
162 
163  public slots:
164 
170  void setEditSelection( const QgsFeatureIds &fids );
171 
178  void setEditSelection( const QModelIndex &index, QItemSelectionModel::SelectionFlags command );
179 
183  void selectAll() override;
184 
185  void repaintRequested( const QModelIndexList &indexes );
186  void repaintRequested();
187 
192  void editFirstFeature() {editOtherFeature( First );}
193 
198  void editNextFeature() {editOtherFeature( Next );}
199 
204  void editPreviousFeature() {editOtherFeature( Previous );}
205 
210  void editLastFeature() {editOtherFeature( Last );}
211 
212 
213 
214  private slots:
215  void editSelectionChanged( const QItemSelection &deselected, const QItemSelection &selected );
216 
223  void ensureEditSelection( bool inSelection = false );
224 
225  private:
226  void selectRow( const QModelIndex &index, bool anchor );
227 
228  enum PositionInList
229  {
230  First,
231  Next,
232  Previous,
233  Last
234  };
235 
236  void editOtherFeature( PositionInList positionInList );
237 
238 
239  QgsFeatureListModel *mModel = nullptr;
240  QItemSelectionModel *mCurrentEditSelectionModel = nullptr;
241  QgsFeatureSelectionModel *mFeatureSelectionModel = nullptr;
242  QgsIFeatureSelectionManager *mFeatureSelectionManager = nullptr;
243  QgsFeatureListViewDelegate *mItemDelegate = nullptr;
244  bool mEditSelectionDrag = false; // Is set to true when the user initiated a left button click over an edit button and still keeps pressing //!< TODO
245  int mRowAnchor = 0;
246  QItemSelectionModel::SelectionFlags mCtrlDragSelectionFlag;
247 
248  QTimer mUpdateEditSelectionTimer;
249 
250  friend class QgsDualView;
251 };
252 
253 #endif
QSet< QgsFeatureId > QgsFeatureIds
Definition: qgsfeatureid.h:34
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:53
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:55
A model backed by a QgsVectorLayerCache which is able to provide feature/attribute information to a Q...
Shows a list of features and renders a edit button next to each feature.
void editFirstFeature()
editFirstFeature will try to edit the first feature of the list
QgsFeatureListModel * featureListModel()
Gets the featureListModel used by this view.
void editNextFeature()
editNextFeature will try to edit next feature of the list
#define SIP_SKIP
Definition: qgis_sip.h:126
This class is a menu that is populated automatically with the actions defined for a given layer...
Definition: qgsactionmenu.h:38
#define SIP_TRANSFER
Definition: qgis_sip.h:36
void editPreviousFeature()
editPreviousFeature will try to edit previous feature of the list
This class caches features of a given QgsVectorLayer.
void editLastFeature()
editLastFeature will try to edit the last feature of the list
Is an interface class to abstract feature selection handling.
Represents a vector layer which manages a vector based data sets.
This widget is used to show the attributes of a set of features of a QgsVectorLayer.
Definition: qgsdualview.h:42