QGIS API Documentation  2.99.0-Master (314842d)
qgsdualview.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsdualview.h
3  --------------------------------------
4  Date : 10.2.2013
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 QGSDUALVIEW_H
17 #define QGSDUALVIEW_H
18 
19 #include <QStackedWidget>
20 
21 #include "ui_qgsdualviewbase.h"
22 
25 #include "qgsdistancearea.h"
26 #include "qgsattributeform.h"
27 #include "qgis_gui.h"
28 
29 class QgsFeatureRequest;
30 class QSignalMapper;
31 class QgsMapLayerAction;
32 class QgsScrollArea;
33 
41 class GUI_EXPORT QgsDualView : public QStackedWidget, private Ui::QgsDualViewBase
42 {
43  Q_OBJECT
44  Q_ENUMS( ViewMode )
45 
46  public:
47 
53  enum ViewMode
54  {
55 
59  AttributeTable = 0,
60 
66  AttributeEditor = 1
67  };
68 
73  explicit QgsDualView( QWidget *parent = nullptr );
74 
86  void init( QgsVectorLayer *layer, QgsMapCanvas *mapCanvas, const QgsFeatureRequest &request = QgsFeatureRequest(), const QgsAttributeEditorContext &context = QgsAttributeEditorContext(),
87  bool loadFeatures = true );
88 
95  void setView( ViewMode view );
96 
102  ViewMode view() const;
103 
109  void setFilterMode( QgsAttributeTableFilterModel::FilterMode filterMode );
110 
116  QgsAttributeTableFilterModel::FilterMode filterMode() { return mFilterModel->filterMode(); }
117 
124  void setSelectedOnTop( bool selectedOnTop );
125 
131  int featureCount();
132 
139  int filteredFeatureCount();
140 
147  void setFilteredFeatures( const QgsFeatureIds &filteredFeatures );
148 
152  QgsFeatureIds filteredFeatures() { return mFilterModel->filteredFeatures(); }
153 
159  QgsAttributeTableModel *masterModel() const { return mMasterModel; }
160 
166  void setRequest( const QgsFeatureRequest &request );
167 
173  void setFeatureSelectionManager( QgsIFeatureSelectionManager *featureSelectionManager );
174 
180  QgsAttributeTableView *tableView() { return mTableView; }
181 
186  void setAttributeTableConfig( const QgsAttributeTableConfig &config );
187 
191  void setSortExpression( const QString &sortExpression, Qt::SortOrder sortOrder = Qt::AscendingOrder );
192 
196  QString sortExpression() const;
197 
198  protected:
199 
203  void columnBoxInit();
204 
205  public slots:
206 
212  void setCurrentEditSelection( const QgsFeatureIds &fids );
213 
220  bool saveEditChanges();
221 
222  void openConditionalStyles();
223 
227  void setMultiEditEnabled( bool enabled );
228 
233  void toggleSearchMode( bool enabled );
234 
239  void copyCellContent() const;
240 
241  signals:
242 
247  void displayExpressionChanged( const QString &expression );
248 
252  void filterChanged();
253 
259  void filterExpressionSet( const QString &expression, QgsAttributeForm::FilterType type );
260 
264  void formModeChanged( QgsAttributeForm::Mode mode );
265 
266  private slots:
267 
268  void on_mFeatureList_aboutToChangeEditSelection( bool &ok );
269 
275  void on_mFeatureList_currentEditSelectionChanged( const QgsFeature &feat );
276 
277  void previewExpressionBuilder();
278 
279  void previewColumnChanged( QObject *previewAction );
280 
281  void viewWillShowContextMenu( QMenu *menu, const QModelIndex &atIndex );
282 
283  void showViewHeaderMenu( QPoint point );
284 
285  void organizeColumns();
286 
287  void tableColumnResized( int column, int width );
288 
289  void hideColumn();
290 
291  void resizeColumn();
292 
293  void autosizeColumn();
294 
295  void modifySort();
296 
297  void previewExpressionChanged( const QString &expression );
298 
299  void onSortColumnChanged();
300 
301  void sortByPreviewExpression();
302 
303  void updateSelectedFeatures();
304 
305  void extentChanged();
306 
312  void featureFormAttributeChanged();
313 
320  virtual void progress( int i, bool &cancel );
321 
326  virtual void finished();
327 
329  void zoomToCurrentFeature();
331  void panToCurrentFeature();
332 
333  void rebuildFullLayerCache();
334 
335  private:
336  void initLayerCache( bool cacheGeometry );
337  void initModels( QgsMapCanvas *mapCanvas, const QgsFeatureRequest &request, bool loadFeatures );
338 
339  QgsAttributeEditorContext mEditorContext;
340  QgsAttributeTableModel *mMasterModel = nullptr;
341  QgsAttributeTableFilterModel *mFilterModel = nullptr;
342  QgsFeatureListModel *mFeatureListModel = nullptr;
343  QgsAttributeForm *mAttributeForm = nullptr;
344  QSignalMapper *mPreviewActionMapper = nullptr;
345  QMenu *mPreviewColumnsMenu = nullptr;
346  QMenu *mHorizontalHeaderMenu = nullptr;
347  QgsVectorLayerCache *mLayerCache = nullptr;
348  QgsVectorLayer *mLayer = nullptr;
349  QProgressDialog *mProgressDlg = nullptr;
350  QgsIFeatureSelectionManager *mFeatureSelectionManager = nullptr;
351  QgsDistanceArea mDistanceArea;
352  QString mDisplayExpression;
353  QgsAttributeTableConfig mConfig;
354  QgsScrollArea *mAttributeEditorScrollArea = nullptr;
355  QgsMapCanvas *mMapCanvas = nullptr;
356 
357  friend class TestQgsDualView;
358 };
359 
363 class GUI_EXPORT QgsAttributeTableAction : public QAction
364 {
365  Q_OBJECT
366 
367  public:
368 
374  QgsAttributeTableAction( const QString &name, QgsDualView *dualView, const QUuid &action, const QModelIndex &fieldIdx )
375  : QAction( name, dualView )
376  , mDualView( dualView )
377  , mAction( action )
378  , mFieldIdx( fieldIdx )
379  {}
380 
381  public slots:
382  void execute();
383  void featureForm();
384 
385  private:
386  QgsDualView *mDualView = nullptr;
387  QUuid mAction;
388  QModelIndex mFieldIdx;
389 };
390 
394 class GUI_EXPORT QgsAttributeTableMapLayerAction : public QAction
395 {
396  Q_OBJECT
397 
398  public:
399  QgsAttributeTableMapLayerAction( const QString &name, QgsDualView *dualView, QgsMapLayerAction *action, const QModelIndex &fieldIdx )
400  : QAction( name, dualView )
401  , mDualView( dualView )
402  , mAction( action )
403  , mFieldIdx( fieldIdx )
404  {}
405 
406  public slots:
407  void execute();
408 
409  private:
410  QgsDualView *mDualView = nullptr;
411  QgsMapLayerAction *mAction = nullptr;
412  QModelIndex mFieldIdx;
413 };
414 
415 Q_DECLARE_METATYPE( QModelIndex );
416 
417 #endif // QGSDUALVIEW_H
Provides a table view of features of a QgsVectorLayer.
QgsAttributeTableModel * masterModel() const
Returns the model which has the information about all features (not only filtered) ...
Definition: qgsdualview.h:159
QSet< QgsFeatureId > QgsFeatureIds
Definition: qgsfeature.h:358
This class contains context information for attribute editor widgets.
QgsAttributeTableView * tableView()
Returns the table view.
Definition: qgsdualview.h:180
ViewMode
The view modes, in which this widget can present information.
Definition: qgsdualview.h:53
QgsAttributeTableMapLayerAction(const QString &name, QgsDualView *dualView, QgsMapLayerAction *action, const QModelIndex &fieldIdx)
Definition: qgsdualview.h:399
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:136
A model backed by a QgsVectorLayerCache which is able to provide feature/attribute information to a Q...
Q_DECLARE_METATYPE(QModelIndex)
Map canvas is a class for displaying all GIS data types on a canvas.
Definition: qgsmapcanvas.h:72
FilterType
Filter types.
FilterMode
The filter mode defines how the rows should be filtered.
This class wraps a request for features to a vector layer (or directly its vector data provider)...
QgsFeatureIds filteredFeatures()
Get a list of currently visible feature ids.
Definition: qgsdualview.h:152
This class caches features of a given QgsVectorLayer.
QgsAttributeTableFilterModel::FilterMode filterMode()
Get the filter mode.
Definition: qgsdualview.h:116
General purpose distance and area calculator.
QgsAttributeTableAction(const QString &name, QgsDualView *dualView, const QUuid &action, const QModelIndex &fieldIdx)
Create a new attribute table action.
Definition: qgsdualview.h:374
This is a container for configuration of the attribute table.
A QScrollArea subclass with improved scrolling behavior.
Definition: qgsscrollarea.h:40
Is an interface class to abstract feature selection handling.
Represents a vector layer which manages a vector based data sets.
An action which can run on map layers.
This widget is used to show the attributes of a set of features of a QgsVectorLayer.
Definition: qgsdualview.h:41