QGIS API Documentation  3.6.0-Noosa (5873452)
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 
138  void currentEditSelectionChanged( QgsFeature &feat );
139 
144  void displayExpressionChanged( const QString &expression );
145 
147  void aboutToChangeEditSelection( bool &ok ) SIP_SKIP;
148 
154  void willShowContextMenu( QgsActionMenu *menu, const QModelIndex &atIndex );
155 
156  public slots:
157 
163  void setEditSelection( const QgsFeatureIds &fids );
164 
171  void setEditSelection( const QModelIndex &index, QItemSelectionModel::SelectionFlags command );
172 
176  void selectAll() override;
177 
178  void repaintRequested( const QModelIndexList &indexes );
179  void repaintRequested();
180 
181  private slots:
182  void editSelectionChanged( const QItemSelection &deselected, const QItemSelection &selected );
183 
190  void ensureEditSelection( bool inSelection = false );
191 
192  private:
193  void selectRow( const QModelIndex &index, bool anchor );
194 
195 
196  QgsFeatureListModel *mModel = nullptr;
197  QItemSelectionModel *mCurrentEditSelectionModel = nullptr;
198  QgsFeatureSelectionModel *mFeatureSelectionModel = nullptr;
199  QgsIFeatureSelectionManager *mFeatureSelectionManager = nullptr;
200  QgsFeatureListViewDelegate *mItemDelegate = nullptr;
201  bool mEditSelectionDrag = false; // Is set to true when the user initiated a left button click over an edit button and still keeps pressing //!< TODO
202  int mRowAnchor = 0;
203  QItemSelectionModel::SelectionFlags mCtrlDragSelectionFlag;
204 
205  QTimer mUpdateEditSelectionTimer;
206 };
207 
208 #endif
QSet< QgsFeatureId > QgsFeatureIds
Definition: qgsfeatureid.h:34
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:46
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.
QgsFeatureListModel * featureListModel()
Gets the featureListModel used by this view.
#define SIP_SKIP
Definition: qgis_sip.h:119
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
This class caches features of a given QgsVectorLayer.
Is an interface class to abstract feature selection handling.
Represents a vector layer which manages a vector based data sets.