QGIS API Documentation  3.19.0-Master (26212d215f)
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 resizeAllColumns();
348 
349  void autosizeColumn();
350 
351  void autosizeAllColumns();
352 
353  void previewExpressionChanged( const QString &expression );
354 
355  void onSortColumnChanged();
356 
357  void updateSelectedFeatures();
358 
359  void extentChanged();
360 
366  void featureFormAttributeChanged( const QString &attribute, const QVariant &value, bool attributeChanged );
367 
374  virtual void progress( int i, bool &cancel );
375 
380  virtual void finished();
381 
383  void zoomToCurrentFeature();
385  void panToCurrentFeature();
386 
387  void flashCurrentFeature();
388 
389  void rebuildFullLayerCache();
390 
391  void panZoomGroupButtonToggled( QAbstractButton *button, bool checked );
392 
393  void flashButtonClicked( bool clicked );
394 
395  void filterError( const QString &errorMessage );
396 
397  private:
398 
402  void columnBoxInit();
403  void initLayerCache( bool cacheGeometry );
404  void initModels( QgsMapCanvas *mapCanvas, const QgsFeatureRequest &request, bool loadFeatures );
405  void restoreRecentDisplayExpressions();
406  void saveRecentDisplayExpressions() const;
407  void setDisplayExpression( const QString &expression );
408  void insertRecentlyUsedDisplayExpression( const QString &expression );
409  void updateEditSelectionProgress( int progress, int count );
410  void panOrZoomToFeature( const QgsFeatureIds &featureset );
412  void setBrowsingAutoPanScaleAllowed( bool allowed );
413 
415  bool modifySort();
416 
417 
418  QgsFieldConditionalFormatWidget *mConditionalFormatWidget = nullptr;
419  QgsAttributeEditorContext mEditorContext;
420  QgsAttributeTableModel *mMasterModel = nullptr;
421  QgsAttributeTableFilterModel *mFilterModel = nullptr;
422  QgsFeatureListModel *mFeatureListModel = nullptr;
423  QgsAttributeForm *mAttributeForm = nullptr;
424  QMenu *mPreviewColumnsMenu = nullptr;
425  QMenu *mPreviewActionMenu = nullptr;
426  QAction *mLastDisplayExpressionAction = nullptr;
427  QMenu *mHorizontalHeaderMenu = nullptr;
428  QgsVectorLayerCache *mLayerCache = nullptr;
429  QPointer< QgsVectorLayer > mLayer = nullptr;
430  QProgressDialog *mProgressDlg = nullptr;
431  QgsIFeatureSelectionManager *mFeatureSelectionManager = nullptr;
432  QString mDisplayExpression;
433  QgsAttributeTableConfig mConfig;
434  QgsScrollArea *mAttributeEditorScrollArea = nullptr;
435  // If the current feature is set, while the form is still not initialized
436  // we will temporarily save it in here and set it on init
437  QgsFeature mTempAttributeFormFeature;
438  QgsFeatureIds mLastFeatureSet;
439  bool mBrowsingAutoPanScaleAllowed = true;
440  ViewMode mPreviousView = AttributeTable;
441 
442  friend class TestQgsDualView;
443  friend class TestQgsAttributeTable;
444 };
445 
450 class GUI_EXPORT QgsAttributeTableAction : public QAction
451 {
452  Q_OBJECT
453 
454  public:
455 
461  QgsAttributeTableAction( const QString &name, QgsDualView *dualView, QUuid action, const QModelIndex &fieldIdx )
462  : QAction( name, dualView )
463  , mDualView( dualView )
464  , mAction( action )
465  , mFieldIdx( fieldIdx )
466  {}
467 
468  public slots:
469  void execute();
470  void featureForm();
471 
472  private:
473  QgsDualView *mDualView = nullptr;
474  QUuid mAction;
475  QModelIndex mFieldIdx;
476 };
477 
482 class GUI_EXPORT QgsAttributeTableMapLayerAction : public QAction
483 {
484  Q_OBJECT
485 
486  public:
487  QgsAttributeTableMapLayerAction( const QString &name, QgsDualView *dualView, QgsMapLayerAction *action, const QModelIndex &fieldIdx )
488  : QAction( name, dualView )
489  , mDualView( dualView )
490  , mAction( action )
491  , mFieldIdx( fieldIdx )
492  {}
493 
494  public slots:
495  void execute();
496 
497  private:
498  QgsDualView *mDualView = nullptr;
499  QgsMapLayerAction *mAction = nullptr;
500  QModelIndex mFieldIdx;
501 };
502 
503 Q_DECLARE_METATYPE( QModelIndex );
504 
505 #endif // QGSDUALVIEW_H
This class is a menu that is populated automatically with the actions defined for a given layer.
Definition: qgsactionmenu.h:38
This class contains context information for attribute editor widgets.
FilterType
Filter types.
QgsAttributeTableAction(const QString &name, QgsDualView *dualView, QUuid action, const QModelIndex &fieldIdx)
Create a new attribute table action.
Definition: qgsdualview.h:461
This is a container for configuration of the attribute table.
FilterMode
The filter mode defines how the rows should be filtered.
QgsAttributeTableMapLayerAction(const QString &name, QgsDualView *dualView, QgsMapLayerAction *action, const QModelIndex &fieldIdx)
Definition: qgsdualview.h:487
A model backed by a QgsVectorLayerCache which is able to provide feature/attribute information to a Q...
Provides a table view of features of a QgsVectorLayer.
This widget is used to show the attributes of a set of features of a QgsVectorLayer.
Definition: qgsdualview.h:42
void showContextMenuExternally(QgsActionMenu *menu, QgsFeatureId fid)
Emitted when selecting context menu on the feature list to create the context menu individually.
ViewMode
The view modes, in which this widget can present information.
Definition: qgsdualview.h:53
QgsAttributeTableFilterModel::FilterMode filterMode()
Gets the filter mode.
Definition: qgsdualview.h:130
QgsFeatureIds filteredFeatures()
Gets a list of currently visible feature ids.
Definition: qgsdualview.h:175
void filterChanged()
Emitted whenever the filter changes.
void formModeChanged(QgsAttributeEditorContext::Mode mode)
Emitted when the form changes mode.
FeatureListBrowsingAction
Action on the map canvas when browsing the list of features.
Definition: qgsdualview.h:72
@ PanToFeature
The map is panned to the center of the feature bounding-box.
Definition: qgsdualview.h:74
@ ZoomToFeature
The map is zoomed to contained the feature bounding-box.
Definition: qgsdualview.h:75
QgsAttributeTableModel * masterModel() const
Returns the model which has the information about all features (not only filtered)
Definition: qgsdualview.h:182
void filterExpressionSet(const QString &expression, QgsAttributeForm::FilterType type)
Emitted when a filter expression is set using the view.
void displayExpressionChanged(const QString &expression)
Emitted whenever the display expression is successfully changed.
QgsAttributeTableView * tableView()
Returns the table view.
Definition: qgsdualview.h:203
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
Class for parsing and evaluation of expressions (formerly called "search strings").
This class wraps a request for features to a vector layer (or directly its vector data provider).
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:56
A widget for customizing conditional formatting options.
Is an interface class to abstract feature selection handling.
Map canvas is a class for displaying all GIS data types on a canvas.
Definition: qgsmapcanvas.h:86
An action which can run on map layers.
A QScrollArea subclass with improved scrolling behavior.
Definition: qgsscrollarea.h:42
This class caches features of a given QgsVectorLayer.
Represents a vector layer which manages a vector based data sets.
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:53
Q_DECLARE_METATYPE(QModelIndex)
QSet< QgsFeatureId > QgsFeatureIds
Definition: qgsfeatureid.h:37
qint64 QgsFeatureId
64 bit feature ids negative numbers are used for uncommitted/newly added features
Definition: qgsfeatureid.h:28