/
qgsfeaturelistview.h
259 lines (214 loc) · 7.68 KB
/
qgsfeaturelistview.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
/***************************************************************************
QgsAttributeListView.h
--------------------------------------
Date : Jan 2012
Copyright : (C) 2013 Matthias Kuhn
Email : matthias at opengis dot ch
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#ifndef QGSFEATURELISTVIEW_H
#define QGSFEATURELISTVIEW_H
#include <QListView>
#include "qgis_sip.h"
#include <qdebug.h>
#include "qgsactionmenu.h"
#include "qgsfeature.h" // For QgsFeatureIds
#include "qgis_gui.h"
class QgsAttributeTableFilterModel;
class QgsFeatureListModel;
class QgsFeatureSelectionModel;
class QgsAttributeTableModel;
class QgsIFeatureSelectionManager;
class QgsVectorLayer;
class QgsVectorLayerCache;
class QgsFeatureListViewDelegate;
class QRect;
/**
* \ingroup gui
* Shows a list of features and renders a edit button next to each feature.
*
* Accepts a display expression to define the way, features are rendered.
* Uses a QgsFeatureListModel as source model.
*
*/
class GUI_EXPORT QgsFeatureListView : public QListView
{
Q_OBJECT
public:
/**
* Creates a feature list view
*
* \param parent owner
*/
explicit QgsFeatureListView( QWidget *parent SIP_TRANSFERTHIS = nullptr );
/**
* Returns the layer cache
* \returns the layer cache used as backend
*/
QgsVectorLayerCache *layerCache();
/**
* Set the QgsFeatureListModel which is used to retrieve information
*
* \param featureListModel The model to use
*/
virtual void setModel( QgsFeatureListModel *featureListModel );
/**
* Gets the featureListModel used by this view
*
* \returns The model in use
*/
QgsFeatureListModel *featureListModel() { return mModel; }
/**
* The display expression is an expression used to render the fields into a single string
* which is displaied.
*
* \param displayExpression The expression used to render the feature
*
* \see QgsExpression
*/
bool setDisplayExpression( const QString &displayExpression );
/**
* Returns the expression which is currently used to render the features.
*
* \returns A string containing the currend display expression
*
* \see QgsExpression
*/
const QString displayExpression() const;
/**
* Returns a detailed message about errors while parsing a QgsExpression.
*
* \returns A message containing information about the parser error.
*/
QString parserErrorString();
/**
* Gets the currentEditSelection
*
* \returns A list of edited feature ids
*/
QgsFeatureIds currentEditSelection();
/**
* Sets if the currently shown form has received any edit events so far.
*
* \param state The state
*/
void setCurrentFeatureEdited( bool state );
/**
* \brief setFeatureSelectionManager
* \param featureSelectionManager
*/
void setFeatureSelectionManager( QgsIFeatureSelectionManager *featureSelectionManager );
protected:
void mouseMoveEvent( QMouseEvent *event ) override;
void mousePressEvent( QMouseEvent *event ) override;
void mouseReleaseEvent( QMouseEvent *event ) override;
void keyPressEvent( QKeyEvent *event ) override;
void contextMenuEvent( QContextMenuEvent *event ) override;
signals:
/**
* Emitted whenever the current edit selection has been changed.
* \param feat the feature, which will be edited.
*/
void currentEditSelectionChanged( QgsFeature &feat );
/**
* Emitted whenever the current edit selection has been changed.
* \param progress the position of the feature in the list
* \param count the number of features in the list
* \since QGIS 3.8
*/
void currentEditSelectionProgressChanged( int progress, int count );
/**
* Emitted whenever the display expression is successfully changed
* \param expression The expression that was applied
*/
void displayExpressionChanged( const QString &expression );
//! \note not available in Python bindings
void aboutToChangeEditSelection( bool &ok ) SIP_SKIP;
/**
* Emitted when the context menu is created to add the specific actions to it
* \param menu is the already created context menu
* \param atIndex is the position of the current feature in the model
*/
void willShowContextMenu( QgsActionMenu *menu, const QModelIndex &atIndex );
public slots:
/**
* Set the feature(s) to be edited
*
* \param fids A list of features to be edited
*/
void setEditSelection( const QgsFeatureIds &fids );
/**
* Set the feature(s) to be edited
*
* \param index The selection to set
* \param command selection update mode
*/
void setEditSelection( const QModelIndex &index, QItemSelectionModel::SelectionFlags command );
/**
* Select all currently visible features
*/
void selectAll() override;
void repaintRequested( const QModelIndexList &indexes );
void repaintRequested();
/**
* editFirstFeature will try to edit the first feature of the list
* \since QGIS 3.8
*/
void editFirstFeature() {editOtherFeature( First );}
/**
* editNextFeature will try to edit next feature of the list
* \since QGIS 3.8
*/
void editNextFeature() {editOtherFeature( Next );}
/**
* editPreviousFeature will try to edit previous feature of the list
* \since QGIS 3.8
*/
void editPreviousFeature() {editOtherFeature( Previous );}
/**
* editLastFeature will try to edit the last feature of the list
* \since QGIS 3.8
*/
void editLastFeature() {editOtherFeature( Last );}
private slots:
void editSelectionChanged( const QItemSelection &deselected, const QItemSelection &selected );
/**
* Emits the signal for the feature and the selection information
*/
void updateEditSelectionDependencies();
/**
* Make sure, there is an edit selection. If there is none, choose the first item.
* If \a inSelection is set to TRUE, the edit selection is done in selected entries if
* there is a selected entry visible.
*
*/
void ensureEditSelection( bool inSelection = false );
private:
void selectRow( const QModelIndex &index, bool anchor );
enum PositionInList
{
First,
Next,
Previous,
Last
};
void editOtherFeature( PositionInList positionInList );
QgsFeatureListModel *mModel = nullptr;
QItemSelectionModel *mCurrentEditSelectionModel = nullptr;
QgsFeatureSelectionModel *mFeatureSelectionModel = nullptr;
QgsIFeatureSelectionManager *mOwnedFeatureSelectionManager = nullptr;
QgsIFeatureSelectionManager *mFeatureSelectionManager = nullptr;
QgsFeatureListViewDelegate *mItemDelegate = nullptr;
bool mEditSelectionDrag = false; // Is set to true when the user initiated a left button click over an edit button and still keeps pressing //!< TODO
int mRowAnchor = 0;
QItemSelectionModel::SelectionFlags mCtrlDragSelectionFlag;
QTimer mUpdateEditSelectionTimer;
friend class QgsDualView;
};
#endif