QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
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 "qgsattributeform.h"
26 #include "qgis_gui.h"
27 
28 class QgsFeatureRequest;
29 class QgsMapLayerAction;
30 class QgsScrollArea;
32 
41 class GUI_EXPORT QgsDualView : public QStackedWidget, private Ui::QgsDualViewBase
42 {
43  Q_OBJECT
44 
45  public:
46 
52  enum ViewMode
53  {
54 
58  AttributeTable = 0,
59 
65  AttributeEditor = 1
66  };
67  Q_ENUM( ViewMode )
68 
69 
70 
72  {
73  NoAction = 0,
76  };
77  Q_ENUM( FeatureListBrowsingAction )
78 
79 
83  explicit QgsDualView( QWidget *parent SIP_TRANSFERTHIS = nullptr );
84  ~QgsDualView() override;
85 
97  void init( QgsVectorLayer *layer,
98  QgsMapCanvas *mapCanvas,
99  const QgsFeatureRequest &request = QgsFeatureRequest(),
101  bool loadFeatures = true );
102 
109  void setView( ViewMode view );
110 
116  ViewMode view() const;
117 
123  void setFilterMode( QgsAttributeTableFilterModel::FilterMode filterMode );
124 
130  QgsAttributeTableFilterModel::FilterMode filterMode() { return mFilterModel->filterMode(); }
131 
138  void setSelectedOnTop( bool selectedOnTop );
139 
145  int featureCount();
146 
153  int filteredFeatureCount();
154 
162  Q_DECL_DEPRECATED void setFilteredFeatures( const QgsFeatureIds &filteredFeatures );
163 
170  void filterFeatures( const QgsExpression &filterExpression, const QgsExpressionContext &context );
171 
175  QgsFeatureIds filteredFeatures() { return mFilterModel->filteredFeatures(); }
176 
182  QgsAttributeTableModel *masterModel() const { return mMasterModel; }
183 
189  void setRequest( const QgsFeatureRequest &request );
190 
196  void setFeatureSelectionManager( QgsIFeatureSelectionManager *featureSelectionManager );
197 
203  QgsAttributeTableView *tableView() { return mTableView; }
204 
209  void setAttributeTableConfig( const QgsAttributeTableConfig &config );
210 
214  void setSortExpression( const QString &sortExpression, Qt::SortOrder sortOrder = Qt::AscendingOrder );
215 
219  QString sortExpression() const;
220 
225  QgsAttributeTableConfig attributeTableConfig() const;
226 
227  public slots:
228 
234  void setCurrentEditSelection( const QgsFeatureIds &fids );
235 
242  bool saveEditChanges();
243 
244  void openConditionalStyles();
245 
250  void setMultiEditEnabled( bool enabled );
251 
257  void toggleSearchMode( bool enabled );
258 
263  void copyCellContent() const;
264 
269  void cancelProgress( );
270 
279  void parentFormValueChanged( const QString &attribute, const QVariant &value );
280 
281  signals:
282 
287  void displayExpressionChanged( const QString &expression );
288 
293 
300  void filterExpressionSet( const QString &expression, QgsAttributeForm::FilterType type );
301 
307 
314 
315  protected:
316  void hideEvent( QHideEvent *event ) override;
317 
318  private slots:
319 
320  void featureListAboutToChangeEditSelection( bool &ok );
321 
327  void featureListCurrentEditSelectionChanged( const QgsFeature &feat );
328 
329  void previewExpressionBuilder();
330 
331  void previewColumnChanged( QAction *previewAction, const QString &expression );
332 
333  void viewWillShowContextMenu( QMenu *menu, const QModelIndex &atIndex );
334 
335  void widgetWillShowContextMenu( QgsActionMenu *menu, const QModelIndex &atIndex );
336 
337  void showViewHeaderMenu( QPoint point );
338 
339  void organizeColumns();
340 
341  void tableColumnResized( int column, int width );
342 
343  void hideColumn();
344 
345  void resizeColumn();
346 
347  void autosizeColumn();
348 
349  void previewExpressionChanged( const QString &expression );
350 
351  void onSortColumnChanged();
352 
353  void updateSelectedFeatures();
354 
355  void extentChanged();
356 
362  void featureFormAttributeChanged( const QString &attribute, const QVariant &value, bool attributeChanged );
363 
370  virtual void progress( int i, bool &cancel );
371 
376  virtual void finished();
377 
379  void zoomToCurrentFeature();
381  void panToCurrentFeature();
382 
383  void flashCurrentFeature();
384 
385  void rebuildFullLayerCache();
386 
387  void panZoomGroupButtonToggled( QAbstractButton *button, bool checked );
388 
389  void flashButtonClicked( bool clicked );
390 
391  private:
392 
396  void columnBoxInit();
397  void initLayerCache( bool cacheGeometry );
398  void initModels( QgsMapCanvas *mapCanvas, const QgsFeatureRequest &request, bool loadFeatures );
399  void restoreRecentDisplayExpressions();
400  void saveRecentDisplayExpressions() const;
401  void setDisplayExpression( const QString &expression );
402  void insertRecentlyUsedDisplayExpression( const QString &expression );
403  void updateEditSelectionProgress( int progress, int count );
404  void panOrZoomToFeature( const QgsFeatureIds &featureset );
406  void setBrowsingAutoPanScaleAllowed( bool allowed );
407 
409  bool modifySort();
410 
411 
412  QgsFieldConditionalFormatWidget *mConditionalFormatWidget = nullptr;
413  QgsAttributeEditorContext mEditorContext;
414  QgsAttributeTableModel *mMasterModel = nullptr;
415  QgsAttributeTableFilterModel *mFilterModel = nullptr;
416  QgsFeatureListModel *mFeatureListModel = nullptr;
417  QgsAttributeForm *mAttributeForm = nullptr;
418  QMenu *mPreviewColumnsMenu = nullptr;
419  QMenu *mPreviewActionMenu = nullptr;
420  QAction *mLastDisplayExpressionAction = nullptr;
421  QMenu *mHorizontalHeaderMenu = nullptr;
422  QgsVectorLayerCache *mLayerCache = nullptr;
423  QPointer< QgsVectorLayer > mLayer = nullptr;
424  QProgressDialog *mProgressDlg = nullptr;
425  QgsIFeatureSelectionManager *mFeatureSelectionManager = nullptr;
426  QString mDisplayExpression;
427  QgsAttributeTableConfig mConfig;
428  QgsScrollArea *mAttributeEditorScrollArea = nullptr;
429  // If the current feature is set, while the form is still not initialized
430  // we will temporarily save it in here and set it on init
431  QgsFeature mTempAttributeFormFeature;
432  QgsFeatureIds mLastFeatureSet;
433  bool mBrowsingAutoPanScaleAllowed = true;
434  ViewMode mPreviousView = AttributeTable;
435 
436  friend class TestQgsDualView;
437  friend class TestQgsAttributeTable;
438 };
439 
444 class GUI_EXPORT QgsAttributeTableAction : public QAction
445 {
446  Q_OBJECT
447 
448  public:
449 
455  QgsAttributeTableAction( const QString &name, QgsDualView *dualView, QUuid action, const QModelIndex &fieldIdx )
456  : QAction( name, dualView )
457  , mDualView( dualView )
458  , mAction( action )
459  , mFieldIdx( fieldIdx )
460  {}
461 
462  public slots:
463  void execute();
464  void featureForm();
465 
466  private:
467  QgsDualView *mDualView = nullptr;
468  QUuid mAction;
469  QModelIndex mFieldIdx;
470 };
471 
476 class GUI_EXPORT QgsAttributeTableMapLayerAction : public QAction
477 {
478  Q_OBJECT
479 
480  public:
481  QgsAttributeTableMapLayerAction( const QString &name, QgsDualView *dualView, QgsMapLayerAction *action, const QModelIndex &fieldIdx )
482  : QAction( name, dualView )
483  , mDualView( dualView )
484  , mAction( action )
485  , mFieldIdx( fieldIdx )
486  {}
487 
488  public slots:
489  void execute();
490 
491  private:
492  QgsDualView *mDualView = nullptr;
493  QgsMapLayerAction *mAction = nullptr;
494  QModelIndex mFieldIdx;
495 };
496 
497 Q_DECLARE_METATYPE( QModelIndex );
498 
499 #endif // QGSDUALVIEW_H
QgsExpressionContext
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
Definition: qgsexpressioncontext.h:370
qgsattributeform.h
QgsMapLayerAction
An action which can run on map layers.
Definition: qgsmaplayeractionregistry.h:35
QgsVectorLayerCache
This class caches features of a given QgsVectorLayer.
Definition: qgsvectorlayercache.h:46
QgsAttributeTableAction::QgsAttributeTableAction
QgsAttributeTableAction(const QString &name, QgsDualView *dualView, QUuid action, const QModelIndex &fieldIdx)
Create a new attribute table action.
Definition: qgsdualview.h:455
QgsDualView::formModeChanged
void formModeChanged(QgsAttributeEditorContext::Mode mode)
Emitted when the form changes mode.
QgsDualView::PanToFeature
@ PanToFeature
The map is panned to the center of the feature bounding-box.
Definition: qgsdualview.h:74
QgsMapCanvas
Map canvas is a class for displaying all GIS data types on a canvas.
Definition: qgsmapcanvas.h:85
QgsDualView::filterChanged
void filterChanged()
Emitted whenever the filter changes.
QgsAttributeTableMapLayerAction::QgsAttributeTableMapLayerAction
QgsAttributeTableMapLayerAction(const QString &name, QgsDualView *dualView, QgsMapLayerAction *action, const QModelIndex &fieldIdx)
Definition: qgsdualview.h:481
QgsDualView
This widget is used to show the attributes of a set of features of a QgsVectorLayer.
Definition: qgsdualview.h:42
QgsFieldConditionalFormatWidget
A widget for customizing conditional formatting options.
Definition: qgsfieldconditionalformatwidget.h:36
QgsDualView::tableView
QgsAttributeTableView * tableView()
Returns the table view.
Definition: qgsdualview.h:203
QgsDualView::FeatureListBrowsingAction
FeatureListBrowsingAction
Action on the map canvas when browsing the list of features.
Definition: qgsdualview.h:72
QgsDualView::masterModel
QgsAttributeTableModel * masterModel() const
Returns the model which has the information about all features (not only filtered)
Definition: qgsdualview.h:182
QgsDualView::filteredFeatures
QgsFeatureIds filteredFeatures()
Gets a list of currently visible feature ids.
Definition: qgsdualview.h:175
QgsAttributeTableConfig
This is a container for configuration of the attribute table.
Definition: qgsattributetableconfig.h:37
QgsFeatureRequest
This class wraps a request for features to a vector layer (or directly its vector data provider).
Definition: qgsfeaturerequest.h:76
QgsAttributeEditorContext::Mode
Mode
modes
Definition: qgsattributeeditorcontext.h:48
QgsDualView::ZoomToFeature
@ ZoomToFeature
The map is zoomed to contained the feature bounding-box.
Definition: qgsdualview.h:75
Q_DECLARE_METATYPE
Q_DECLARE_METATYPE(QModelIndex)
QgsAttributeTableModel
A model backed by a QgsVectorLayerCache which is able to provide feature/attribute information to a Q...
Definition: qgsattributetablemodel.h:50
qgsattributetablefiltermodel.h
QgsAttributeTableAction
Definition: qgsdualview.h:445
QgsDualView::filterMode
QgsAttributeTableFilterModel::FilterMode filterMode()
Gets the filter mode.
Definition: qgsdualview.h:130
QgsActionMenu
This class is a menu that is populated automatically with the actions defined for a given layer.
Definition: qgsactionmenu.h:38
qgsattributeeditorcontext.h
QgsFeatureIds
QSet< QgsFeatureId > QgsFeatureIds
Definition: qgsfeatureid.h:37
QgsDualView::ViewMode
ViewMode
The view modes, in which this widget can present information.
Definition: qgsdualview.h:53
QgsScrollArea
A QScrollArea subclass with improved scrolling behavior.
Definition: qgsscrollarea.h:42
QgsAttributeTableFilterModel
Definition: qgsattributetablefiltermodel.h:36
QgsAttributeForm::FilterType
FilterType
Filter types.
Definition: qgsattributeform.h:64
QgsFeatureListModel
Definition: qgsfeaturelistmodel.h:39
QgsVectorLayer
Represents a vector layer which manages a vector based data sets.
Definition: qgsvectorlayer.h:387
QgsFeature
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:56
QgsDualView::filterExpressionSet
void filterExpressionSet(const QString &expression, QgsAttributeForm::FilterType type)
Emitted when a filter expression is set using the view.
QgsDualView::showContextMenuExternally
void showContextMenuExternally(QgsActionMenu *menu, QgsFeatureId fid)
Emitted when selecting context menu on the feature list to create the context menu individually.
QgsAttributeForm
Definition: qgsattributeform.h:45
QgsIFeatureSelectionManager
Is an interface class to abstract feature selection handling.
Definition: qgsifeatureselectionmanager.h:32
QgsAttributeTableMapLayerAction
Definition: qgsdualview.h:477
QgsExpression
Class for parsing and evaluation of expressions (formerly called "search strings").
Definition: qgsexpression.h:105
QgsAttributeTableView
Provides a table view of features of a QgsVectorLayer.
Definition: qgsattributetableview.h:49
QgsAttributeEditorContext
This class contains context information for attribute editor widgets.
Definition: qgsattributeeditorcontext.h:41
QgsAttributeTableFilterModel::FilterMode
FilterMode
The filter mode defines how the rows should be filtered.
Definition: qgsattributetablefiltermodel.h:45
SIP_TRANSFERTHIS
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:53
QgsDualView::displayExpressionChanged
void displayExpressionChanged(const QString &expression)
Emitted whenever the display expression is successfully changed.
QgsFeatureId
qint64 QgsFeatureId
64 bit feature ids negative numbers are used for uncommitted/newly added features
Definition: qgsfeatureid.h:28