QGIS API Documentation  2.99.0-Master (6c64c5a)
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 #include "qgis.h"
21 
22 #include "ui_qgsdualviewbase.h"
23 
26 #include "qgsdistancearea.h"
27 #include "qgsattributeform.h"
28 #include "qgis_gui.h"
29 
30 class QgsFeatureRequest;
31 class QSignalMapper;
32 class QgsMapLayerAction;
33 class QgsScrollArea;
34 
43 class GUI_EXPORT QgsDualView : public QStackedWidget, private Ui::QgsDualViewBase
44 {
45  Q_OBJECT
46 
47  public:
48 
54  enum ViewMode
55  {
56 
60  AttributeTable = 0,
61 
67  AttributeEditor = 1
68  };
69 
70  Q_ENUM( ViewMode );
71 
76  explicit QgsDualView( QWidget *parent SIP_TRANSFERTHIS = nullptr );
77 
89  void init( QgsVectorLayer *layer, QgsMapCanvas *mapCanvas, const QgsFeatureRequest &request = QgsFeatureRequest(), const QgsAttributeEditorContext &context = QgsAttributeEditorContext(),
90  bool loadFeatures = true );
91 
98  void setView( ViewMode view );
99 
105  ViewMode view() const;
106 
112  void setFilterMode( QgsAttributeTableFilterModel::FilterMode filterMode );
113 
119  QgsAttributeTableFilterModel::FilterMode filterMode() { return mFilterModel->filterMode(); }
120 
127  void setSelectedOnTop( bool selectedOnTop );
128 
134  int featureCount();
135 
142  int filteredFeatureCount();
143 
150  void setFilteredFeatures( const QgsFeatureIds &filteredFeatures );
151 
155  QgsFeatureIds filteredFeatures() { return mFilterModel->filteredFeatures(); }
156 
162  QgsAttributeTableModel *masterModel() const { return mMasterModel; }
163 
169  void setRequest( const QgsFeatureRequest &request );
170 
176  void setFeatureSelectionManager( QgsIFeatureSelectionManager *featureSelectionManager );
177 
183  QgsAttributeTableView *tableView() { return mTableView; }
184 
189  void setAttributeTableConfig( const QgsAttributeTableConfig &config );
190 
194  void setSortExpression( const QString &sortExpression, Qt::SortOrder sortOrder = Qt::AscendingOrder );
195 
199  QString sortExpression() const;
200 
201  public slots:
202 
208  void setCurrentEditSelection( const QgsFeatureIds &fids );
209 
216  bool saveEditChanges();
217 
218  void openConditionalStyles();
219 
224  void setMultiEditEnabled( bool enabled );
225 
231  void toggleSearchMode( bool enabled );
232 
237  void copyCellContent() const;
238 
243  void cancelProgress( );
244 
245  signals:
246 
251  void displayExpressionChanged( const QString &expression );
252 
256  void filterChanged();
257 
264  void filterExpressionSet( const QString &expression, QgsAttributeForm::FilterType type );
265 
270  void formModeChanged( QgsAttributeForm::Mode mode );
271 
277  void showContextMenuExternally( QgsActionMenu *menu, const QgsFeatureId fid );
278 
279  protected:
280  void hideEvent( QHideEvent *event ) override;
281 
282  private slots:
283 
284  void mFeatureList_aboutToChangeEditSelection( bool &ok );
285 
291  void mFeatureList_currentEditSelectionChanged( const QgsFeature &feat );
292 
293  void previewExpressionBuilder();
294 
295  void previewColumnChanged( QAction *previewAction, const QString &expression );
296 
297  void viewWillShowContextMenu( QMenu *menu, const QModelIndex &atIndex );
298 
299  void widgetWillShowContextMenu( QgsActionMenu *menu, const QModelIndex &atIndex );
300 
301  void showViewHeaderMenu( QPoint point );
302 
303  void organizeColumns();
304 
305  void tableColumnResized( int column, int width );
306 
307  void hideColumn();
308 
309  void resizeColumn();
310 
311  void autosizeColumn();
312 
313  void modifySort();
314 
315  void previewExpressionChanged( const QString &expression );
316 
317  void onSortColumnChanged();
318 
319  void sortByPreviewExpression();
320 
321  void updateSelectedFeatures();
322 
323  void extentChanged();
324 
330  void featureFormAttributeChanged();
331 
338  virtual void progress( int i, bool &cancel );
339 
344  virtual void finished();
345 
347  void zoomToCurrentFeature();
349  void panToCurrentFeature();
350 
351  void flashCurrentFeature();
352 
353  void rebuildFullLayerCache();
354 
355  private:
356 
360  void columnBoxInit();
361  void initLayerCache( bool cacheGeometry );
362  void initModels( QgsMapCanvas *mapCanvas, const QgsFeatureRequest &request, bool loadFeatures );
363  void restoreRecentDisplayExpressions();
364  void saveRecentDisplayExpressions() const;
365  void setDisplayExpression( const QString &expression );
366  void insertRecentlyUsedDisplayExpression( const QString &expression );
367 
368  QgsAttributeEditorContext mEditorContext;
369  QgsAttributeTableModel *mMasterModel = nullptr;
370  QgsAttributeTableFilterModel *mFilterModel = nullptr;
371  QgsFeatureListModel *mFeatureListModel = nullptr;
372  QgsAttributeForm *mAttributeForm = nullptr;
373  QMenu *mPreviewColumnsMenu = nullptr;
374  QMenu *mPreviewActionMenu = nullptr;
375  QAction *mLastDisplayExpressionAction = nullptr;
376  QMenu *mHorizontalHeaderMenu = nullptr;
377  QgsVectorLayerCache *mLayerCache = nullptr;
378  QPointer< QgsVectorLayer > mLayer = nullptr;
379  QProgressDialog *mProgressDlg = nullptr;
380  QgsIFeatureSelectionManager *mFeatureSelectionManager = nullptr;
381  QgsDistanceArea mDistanceArea;
382  QString mDisplayExpression;
383  QgsAttributeTableConfig mConfig;
384  QgsScrollArea *mAttributeEditorScrollArea = nullptr;
385  QgsMapCanvas *mMapCanvas = nullptr;
386  // If the current feature is set, while the form is still not initialized
387  // we will temporarily save it in here and set it on init
388  QgsFeature mTempAttributeFormFeature;
389 
390  friend class TestQgsDualView;
391  friend class TestQgsAttributeTable;
392 };
393 
398 class GUI_EXPORT QgsAttributeTableAction : public QAction
399 {
400  Q_OBJECT
401 
402  public:
403 
409  QgsAttributeTableAction( const QString &name, QgsDualView *dualView, QUuid action, const QModelIndex &fieldIdx )
410  : QAction( name, dualView )
411  , mDualView( dualView )
412  , mAction( action )
413  , mFieldIdx( fieldIdx )
414  {}
415 
416  public slots:
417  void execute();
418  void featureForm();
419 
420  private:
421  QgsDualView *mDualView = nullptr;
422  QUuid mAction;
423  QModelIndex mFieldIdx;
424 };
425 
430 class GUI_EXPORT QgsAttributeTableMapLayerAction : public QAction
431 {
432  Q_OBJECT
433 
434  public:
435  QgsAttributeTableMapLayerAction( const QString &name, QgsDualView *dualView, QgsMapLayerAction *action, const QModelIndex &fieldIdx )
436  : QAction( name, dualView )
437  , mDualView( dualView )
438  , mAction( action )
439  , mFieldIdx( fieldIdx )
440  {}
441 
442  public slots:
443  void execute();
444 
445  private:
446  QgsDualView *mDualView = nullptr;
447  QgsMapLayerAction *mAction = nullptr;
448  QModelIndex mFieldIdx;
449 };
450 
451 Q_DECLARE_METATYPE( QModelIndex );
452 
453 #endif // QGSDUALVIEW_H
Provides a table view of features of a QgsVectorLayer.
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:46
QgsAttributeTableModel * masterModel() const
Returns the model which has the information about all features (not only filtered) ...
Definition: qgsdualview.h:162
QSet< QgsFeatureId > QgsFeatureIds
Definition: qgsfeature.h:544
This class contains context information for attribute editor widgets.
QgsAttributeTableView * tableView()
Returns the table view.
Definition: qgsdualview.h:183
ViewMode
The view modes, in which this widget can present information.
Definition: qgsdualview.h:54
QgsAttributeTableMapLayerAction(const QString &name, QgsDualView *dualView, QgsMapLayerAction *action, const QModelIndex &fieldIdx)
Definition: qgsdualview.h:435
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:62
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:74
FilterType
Filter types.
FilterMode
The filter mode defines how the rows should be filtered.
This class is a menu that is populated automatically with the actions defined for a given layer...
Definition: qgsactionmenu.h:37
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:155
This class caches features of a given QgsVectorLayer.
QgsAttributeTableFilterModel::FilterMode filterMode()
Get the filter mode.
Definition: qgsdualview.h:119
A general purpose distance and area calculator, capable of performing ellipsoid based calculations...
qint64 QgsFeatureId
Definition: qgsfeature.h:37
This is a container for configuration of the attribute table.
A QScrollArea subclass with improved scrolling behavior.
Definition: qgsscrollarea.h:41
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.
QgsAttributeTableAction(const QString &name, QgsDualView *dualView, QUuid action, const QModelIndex &fieldIdx)
Create a new attribute table action.
Definition: qgsdualview.h:409
This widget is used to show the attributes of a set of features of a QgsVectorLayer.
Definition: qgsdualview.h:43