QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
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 );
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 
145  void currentEditSelectionProgressChanged( int progress, int count );
146 
151  void displayExpressionChanged( const QString &expression );
152 
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 *mOwnedFeatureSelectionManager = nullptr;
243  QgsIFeatureSelectionManager *mFeatureSelectionManager = nullptr;
244  QgsFeatureListViewDelegate *mItemDelegate = nullptr;
245  bool mEditSelectionDrag = false; // Is set to true when the user initiated a left button click over an edit button and still keeps pressing //!< TODO
246  int mRowAnchor = 0;
247  QItemSelectionModel::SelectionFlags mCtrlDragSelectionFlag;
248 
249  QTimer mUpdateEditSelectionTimer;
250 
251  friend class QgsDualView;
252 };
253 
254 #endif
QgsFeatureListView::displayExpressionChanged
void displayExpressionChanged(const QString &expression)
Emitted whenever the display expression is successfully changed.
QgsFeatureListView::editPreviousFeature
void editPreviousFeature()
editPreviousFeature will try to edit previous feature of the list
Definition: qgsfeaturelistview.h:204
QgsVectorLayerCache
This class caches features of a given QgsVectorLayer.
Definition: qgsvectorlayercache.h:46
QgsFeatureSelectionModel
Definition: qgsfeatureselectionmodel.h:32
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:42
QgsFeatureListView::editLastFeature
void editLastFeature()
editLastFeature will try to edit the last feature of the list
Definition: qgsfeaturelistview.h:210
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:50
qgis_sip.h
QgsActionMenu
This class is a menu that is populated automatically with the actions defined for a given layer.
Definition: qgsactionmenu.h:38
QgsFeatureListView::featureListModel
QgsFeatureListModel * featureListModel()
Gets the featureListModel used by this view.
Definition: qgsfeaturelistview.h:76
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:387
QgsFeatureListView::currentEditSelectionChanged
void currentEditSelectionChanged(QgsFeature &feat)
Emitted whenever the current edit selection has been changed.
QgsFeatureListView::willShowContextMenu
void willShowContextMenu(QgsActionMenu *menu, const QModelIndex &atIndex)
Emitted when the context menu is created to add the specific actions to it.
QgsFeature
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:56
QgsFeatureListView::editFirstFeature
void editFirstFeature()
editFirstFeature will try to edit the first feature of the list
Definition: qgsfeaturelistview.h:192
QgsIFeatureSelectionManager
Is an interface class to abstract feature selection handling.
Definition: qgsifeatureselectionmanager.h:32
QgsFeatureListViewDelegate
Definition: qgsfeaturelistviewdelegate.h:32
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:198
QgsFeatureListView::currentEditSelectionProgressChanged
void currentEditSelectionProgressChanged(int progress, int count)
Emitted whenever the current edit selection has been changed.
QgsFeatureListView::aboutToChangeEditSelection
void aboutToChangeEditSelection(bool &ok)