QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
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 #include <QPointer>
29 #include <QUuid>
30 
31 class QgsFeatureRequest;
32 class QgsMapLayerAction;
33 class QgsScrollArea;
35 
44 class GUI_EXPORT QgsDualView : public QStackedWidget, private Ui::QgsDualViewBase
45 {
46  Q_OBJECT
47 
48  public:
49 
55  enum ViewMode
56  {
57 
61  AttributeTable = 0,
62 
68  AttributeEditor = 1
69  };
70  Q_ENUM( ViewMode )
71 
72 
73 
75  {
76  NoAction = 0,
79  };
80  Q_ENUM( FeatureListBrowsingAction )
81 
82 
86  explicit QgsDualView( QWidget *parent SIP_TRANSFERTHIS = nullptr );
87  ~QgsDualView() override;
88 
101  void init( QgsVectorLayer *layer,
102  QgsMapCanvas *mapCanvas,
103  const QgsFeatureRequest &request = QgsFeatureRequest(),
105  bool loadFeatures = true, bool showFirstFeature = true );
106 
113  void setView( ViewMode view );
114 
120  ViewMode view() const;
121 
127  void setFilterMode( QgsAttributeTableFilterModel::FilterMode filterMode );
128 
134  QgsAttributeTableFilterModel::FilterMode filterMode() { return mFilterModel->filterMode(); }
135 
142  void setSelectedOnTop( bool selectedOnTop );
143 
149  int featureCount();
150 
157  int filteredFeatureCount();
158 
166  Q_DECL_DEPRECATED void setFilteredFeatures( const QgsFeatureIds &filteredFeatures );
167 
174  void filterFeatures( const QgsExpression &filterExpression, const QgsExpressionContext &context );
175 
179  QgsFeatureIds filteredFeatures() { return mFilterModel->filteredFeatures(); }
180 
186  QgsAttributeTableModel *masterModel() const { return mMasterModel; }
187 
193  void setRequest( const QgsFeatureRequest &request );
194 
200  void setFeatureSelectionManager( QgsIFeatureSelectionManager *featureSelectionManager );
201 
207  QgsAttributeTableView *tableView() { return mTableView; }
208 
213  void setAttributeTableConfig( const QgsAttributeTableConfig &config );
214 
218  void setSortExpression( const QString &sortExpression, Qt::SortOrder sortOrder = Qt::AscendingOrder );
219 
223  QString sortExpression() const;
224 
229  QgsAttributeTableConfig attributeTableConfig() const;
230 
231  public slots:
232 
238  void setCurrentEditSelection( const QgsFeatureIds &fids );
239 
246  bool saveEditChanges();
247 
248  void openConditionalStyles();
249 
254  void setMultiEditEnabled( bool enabled );
255 
261  void toggleSearchMode( bool enabled );
262 
267  void copyCellContent() const;
268 
273  void cancelProgress( );
274 
283  void parentFormValueChanged( const QString &attribute, const QVariant &value );
284 
285  signals:
286 
291  void displayExpressionChanged( const QString &expression );
292 
296  void filterChanged();
297 
304  void filterExpressionSet( const QString &expression, QgsAttributeForm::FilterType type );
305 
310  void formModeChanged( QgsAttributeEditorContext::Mode mode );
311 
317  void showContextMenuExternally( QgsActionMenu *menu, QgsFeatureId fid );
318 
319  protected:
320  void hideEvent( QHideEvent *event ) override;
321 
322  private slots:
323 
324  void featureListAboutToChangeEditSelection( bool &ok );
325 
331  void featureListCurrentEditSelectionChanged( const QgsFeature &feat );
332 
333  void previewExpressionBuilder();
334 
335  void previewColumnChanged( QAction *previewAction, const QString &expression );
336 
337  void viewWillShowContextMenu( QMenu *menu, const QModelIndex &atIndex );
338 
339  void widgetWillShowContextMenu( QgsActionMenu *menu, const QModelIndex &atIndex );
340 
341  void showViewHeaderMenu( QPoint point );
342 
343  void organizeColumns();
344 
345  void tableColumnResized( int column, int width );
346 
347  void hideColumn();
348 
349  void resizeColumn();
350 
351  void resizeAllColumns();
352 
353  void autosizeColumn();
354 
355  void autosizeAllColumns();
356 
357  void previewExpressionChanged( const QString &expression );
358 
359  void onSortColumnChanged();
360 
361  void updateSelectedFeatures();
362  void updateEditedAddedFeatures();
363 
364  void extentChanged();
365 
371  void featureFormAttributeChanged( const QString &attribute, const QVariant &value, bool attributeChanged );
372 
379  virtual void progress( int i, bool &cancel );
380 
385  virtual void finished();
386 
388  void zoomToCurrentFeature();
390  void panToCurrentFeature();
391 
392  void flashCurrentFeature();
393 
394  void rebuildFullLayerCache();
395 
396  void panZoomGroupButtonToggled( QAbstractButton *button, bool checked );
397 
398  void flashButtonClicked( bool clicked );
399 
400  void filterError( const QString &errorMessage );
401 
402  private:
403 
409  void initAttributeForm( const QgsFeature &feature );
410 
414  void columnBoxInit();
415  void initLayerCache( bool cacheGeometry );
416  void initModels( QgsMapCanvas *mapCanvas, const QgsFeatureRequest &request, bool loadFeatures );
417  void restoreRecentDisplayExpressions();
418  void saveRecentDisplayExpressions() const;
419  void setDisplayExpression( const QString &expression );
420  void insertRecentlyUsedDisplayExpression( const QString &expression );
421  void updateEditSelectionProgress( int progress, int count );
422  void panOrZoomToFeature( const QgsFeatureIds &featureset );
424  void setBrowsingAutoPanScaleAllowed( bool allowed );
425 
427  bool modifySort();
428 
429 
430  QgsFieldConditionalFormatWidget *mConditionalFormatWidget = nullptr;
431  QgsAttributeEditorContext mEditorContext;
432  QgsAttributeTableModel *mMasterModel = nullptr;
433  QgsAttributeTableFilterModel *mFilterModel = nullptr;
434  QgsFeatureListModel *mFeatureListModel = nullptr;
435  QgsAttributeForm *mAttributeForm = nullptr;
436  QMenu *mPreviewColumnsMenu = nullptr;
437  QMenu *mPreviewActionMenu = nullptr;
438  QAction *mLastDisplayExpressionAction = nullptr;
439  QMenu *mHorizontalHeaderMenu = nullptr;
440  QgsVectorLayerCache *mLayerCache = nullptr;
441  QPointer< QgsVectorLayer > mLayer = nullptr;
442  QProgressDialog *mProgressDlg = nullptr;
443  QgsIFeatureSelectionManager *mFeatureSelectionManager = nullptr;
444  QString mDisplayExpression;
445  QgsAttributeTableConfig mConfig;
446  QgsScrollArea *mAttributeEditorScrollArea = nullptr;
447  QgsFeatureIds mLastFeatureSet;
448  bool mBrowsingAutoPanScaleAllowed = true;
449  ViewMode mPreviousView = AttributeTable;
450 
451  friend class TestQgsDualView;
452  friend class TestQgsAttributeTable;
453 };
454 
459 class GUI_EXPORT QgsAttributeTableAction : public QAction
460 {
461  Q_OBJECT
462 
463  public:
464 
470  QgsAttributeTableAction( const QString &name, QgsDualView *dualView, QUuid action, const QModelIndex &fieldIdx )
471  : QAction( name, dualView )
472  , mDualView( dualView )
473  , mAction( action )
474  , mFieldIdx( fieldIdx )
475  {}
476 
477  public slots:
478  void execute();
479  void featureForm();
480 
481  private:
482  QgsDualView *mDualView = nullptr;
483  QUuid mAction;
484  QModelIndex mFieldIdx;
485 };
486 
491 class GUI_EXPORT QgsAttributeTableMapLayerAction : public QAction
492 {
493  Q_OBJECT
494 
495  public:
496  QgsAttributeTableMapLayerAction( const QString &name, QgsDualView *dualView, QgsMapLayerAction *action, const QModelIndex &fieldIdx )
497  : QAction( name, dualView )
498  , mDualView( dualView )
499  , mAction( action )
500  , mFieldIdx( fieldIdx )
501  {}
502 
503  public slots:
504  void execute();
505 
506  private:
507  QgsDualView *mDualView = nullptr;
508  QgsMapLayerAction *mAction = nullptr;
509  QModelIndex mFieldIdx;
510 };
511 
512 Q_DECLARE_METATYPE( QModelIndex );
513 
514 #endif // QGSDUALVIEW_H
QgsExpressionContext
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
Definition: qgsexpressioncontext.h:406
qgsattributeform.h
QgsMapLayerAction
An action which can run on map layers The class can be used in two manners:
Definition: qgsmaplayeractionregistry.h:38
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:470
QgsDualView::PanToFeature
@ PanToFeature
The map is panned to the center of the feature bounding-box.
Definition: qgsdualview.h:77
QgsMapCanvas
Map canvas is a class for displaying all GIS data types on a canvas.
Definition: qgsmapcanvas.h:89
QgsAttributeTableMapLayerAction::QgsAttributeTableMapLayerAction
QgsAttributeTableMapLayerAction(const QString &name, QgsDualView *dualView, QgsMapLayerAction *action, const QModelIndex &fieldIdx)
Definition: qgsdualview.h:496
QgsDualView
This widget is used to show the attributes of a set of features of a QgsVectorLayer....
Definition: qgsdualview.h:44
QgsFieldConditionalFormatWidget
A widget for customizing conditional formatting options.
Definition: qgsfieldconditionalformatwidget.h:35
QgsDualView::tableView
QgsAttributeTableView * tableView()
Returns the table view.
Definition: qgsdualview.h:207
QgsDualView::FeatureListBrowsingAction
FeatureListBrowsingAction
Action on the map canvas when browsing the list of features.
Definition: qgsdualview.h:74
QgsDualView::masterModel
QgsAttributeTableModel * masterModel() const
Returns the model which has the information about all features (not only filtered)
Definition: qgsdualview.h:186
QgsDualView::filteredFeatures
QgsFeatureIds filteredFeatures()
Gets a list of currently visible feature ids.
Definition: qgsdualview.h:179
QgsAttributeTableConfig
This is a container for configuration of the attribute table. The configuration is specific for one v...
Definition: qgsattributetableconfig.h:36
QgsFeatureRequest
This class wraps a request for features to a vector layer (or directly its vector data provider).
Definition: qgsfeaturerequest.h:83
QgsAttributeEditorContext::Mode
Mode
modes
Definition: qgsattributeeditorcontext.h:47
QgsDualView::ZoomToFeature
@ ZoomToFeature
The map is zoomed to contained the feature bounding-box.
Definition: qgsdualview.h:78
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:49
qgsattributetablefiltermodel.h
QgsAttributeTableAction
Definition: qgsdualview.h:459
QgsDualView::filterMode
QgsAttributeTableFilterModel::FilterMode filterMode()
Gets the filter mode.
Definition: qgsdualview.h:134
QgsActionMenu
This class is a menu that is populated automatically with the actions defined for a given layer.
Definition: qgsactionmenu.h:37
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:55
QgsScrollArea
A QScrollArea subclass with improved scrolling behavior.
Definition: qgsscrollarea.h:41
QgsAttributeTableFilterModel
Definition: qgsattributetablefiltermodel.h:36
QgsAttributeForm::FilterType
FilterType
Filter types.
Definition: qgsattributeform.h:63
QgsFeatureListModel
Definition: qgsfeaturelistmodel.h:39
QgsVectorLayer
Represents a vector layer which manages a vector based data sets.
Definition: qgsvectorlayer.h:391
QgsFeature
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
Definition: qgsfeature.h:55
QgsAttributeForm
Definition: qgsattributeform.h:44
QgsIFeatureSelectionManager
Is an interface class to abstract feature selection handling.
Definition: qgsifeatureselectionmanager.h:31
QgsAttributeTableMapLayerAction
Definition: qgsdualview.h:491
QgsExpression
Class for parsing and evaluation of expressions (formerly called "search strings")....
Definition: qgsexpression.h:102
QgsAttributeTableView
Provides a table view of features of a QgsVectorLayer.
Definition: qgsattributetableview.h:48
QgsAttributeEditorContext
This class contains context information for attribute editor widgets. It will be passed to embedded w...
Definition: qgsattributeeditorcontext.h:40
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
QgsFeatureId
qint64 QgsFeatureId
64 bit feature ids negative numbers are used for uncommitted/newly added features
Definition: qgsfeatureid.h:28