QGIS API Documentation  3.18.1-Zürich (202f1bf7e5)
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 
100  void init( QgsVectorLayer *layer,
101  QgsMapCanvas *mapCanvas,
102  const QgsFeatureRequest &request = QgsFeatureRequest(),
104  bool loadFeatures = true );
105 
112  void setView( ViewMode view );
113 
119  ViewMode view() const;
120 
126  void setFilterMode( QgsAttributeTableFilterModel::FilterMode filterMode );
127 
133  QgsAttributeTableFilterModel::FilterMode filterMode() { return mFilterModel->filterMode(); }
134 
141  void setSelectedOnTop( bool selectedOnTop );
142 
148  int featureCount();
149 
156  int filteredFeatureCount();
157 
165  Q_DECL_DEPRECATED void setFilteredFeatures( const QgsFeatureIds &filteredFeatures );
166 
173  void filterFeatures( const QgsExpression &filterExpression, const QgsExpressionContext &context );
174 
178  QgsFeatureIds filteredFeatures() { return mFilterModel->filteredFeatures(); }
179 
185  QgsAttributeTableModel *masterModel() const { return mMasterModel; }
186 
192  void setRequest( const QgsFeatureRequest &request );
193 
199  void setFeatureSelectionManager( QgsIFeatureSelectionManager *featureSelectionManager );
200 
206  QgsAttributeTableView *tableView() { return mTableView; }
207 
212  void setAttributeTableConfig( const QgsAttributeTableConfig &config );
213 
217  void setSortExpression( const QString &sortExpression, Qt::SortOrder sortOrder = Qt::AscendingOrder );
218 
222  QString sortExpression() const;
223 
228  QgsAttributeTableConfig attributeTableConfig() const;
229 
230  public slots:
231 
237  void setCurrentEditSelection( const QgsFeatureIds &fids );
238 
245  bool saveEditChanges();
246 
247  void openConditionalStyles();
248 
253  void setMultiEditEnabled( bool enabled );
254 
260  void toggleSearchMode( bool enabled );
261 
266  void copyCellContent() const;
267 
272  void cancelProgress( );
273 
282  void parentFormValueChanged( const QString &attribute, const QVariant &value );
283 
284  signals:
285 
290  void displayExpressionChanged( const QString &expression );
291 
296 
303  void filterExpressionSet( const QString &expression, QgsAttributeForm::FilterType type );
304 
310 
317 
318  protected:
319  void hideEvent( QHideEvent *event ) override;
320 
321  private slots:
322 
323  void featureListAboutToChangeEditSelection( bool &ok );
324 
330  void featureListCurrentEditSelectionChanged( const QgsFeature &feat );
331 
332  void previewExpressionBuilder();
333 
334  void previewColumnChanged( QAction *previewAction, const QString &expression );
335 
336  void viewWillShowContextMenu( QMenu *menu, const QModelIndex &atIndex );
337 
338  void widgetWillShowContextMenu( QgsActionMenu *menu, const QModelIndex &atIndex );
339 
340  void showViewHeaderMenu( QPoint point );
341 
342  void organizeColumns();
343 
344  void tableColumnResized( int column, int width );
345 
346  void hideColumn();
347 
348  void resizeColumn();
349 
350  void autosizeColumn();
351 
352  void previewExpressionChanged( const QString &expression );
353 
354  void onSortColumnChanged();
355 
356  void updateSelectedFeatures();
357 
358  void extentChanged();
359 
365  void featureFormAttributeChanged( const QString &attribute, const QVariant &value, bool attributeChanged );
366 
373  virtual void progress( int i, bool &cancel );
374 
379  virtual void finished();
380 
382  void zoomToCurrentFeature();
384  void panToCurrentFeature();
385 
386  void flashCurrentFeature();
387 
388  void rebuildFullLayerCache();
389 
390  void panZoomGroupButtonToggled( QAbstractButton *button, bool checked );
391 
392  void flashButtonClicked( bool clicked );
393 
394  void filterError( const QString &errorMessage );
395 
396  private:
397 
401  void columnBoxInit();
402  void initLayerCache( bool cacheGeometry );
403  void initModels( QgsMapCanvas *mapCanvas, const QgsFeatureRequest &request, bool loadFeatures );
404  void restoreRecentDisplayExpressions();
405  void saveRecentDisplayExpressions() const;
406  void setDisplayExpression( const QString &expression );
407  void insertRecentlyUsedDisplayExpression( const QString &expression );
408  void updateEditSelectionProgress( int progress, int count );
409  void panOrZoomToFeature( const QgsFeatureIds &featureset );
411  void setBrowsingAutoPanScaleAllowed( bool allowed );
412 
414  bool modifySort();
415 
416 
417  QgsFieldConditionalFormatWidget *mConditionalFormatWidget = nullptr;
418  QgsAttributeEditorContext mEditorContext;
419  QgsAttributeTableModel *mMasterModel = nullptr;
420  QgsAttributeTableFilterModel *mFilterModel = nullptr;
421  QgsFeatureListModel *mFeatureListModel = nullptr;
422  QgsAttributeForm *mAttributeForm = nullptr;
423  QMenu *mPreviewColumnsMenu = nullptr;
424  QMenu *mPreviewActionMenu = nullptr;
425  QAction *mLastDisplayExpressionAction = nullptr;
426  QMenu *mHorizontalHeaderMenu = nullptr;
427  QgsVectorLayerCache *mLayerCache = nullptr;
428  QPointer< QgsVectorLayer > mLayer = nullptr;
429  QProgressDialog *mProgressDlg = nullptr;
430  QgsIFeatureSelectionManager *mFeatureSelectionManager = nullptr;
431  QString mDisplayExpression;
432  QgsAttributeTableConfig mConfig;
433  QgsScrollArea *mAttributeEditorScrollArea = nullptr;
434  // If the current feature is set, while the form is still not initialized
435  // we will temporarily save it in here and set it on init
436  QgsFeature mTempAttributeFormFeature;
437  QgsFeatureIds mLastFeatureSet;
438  bool mBrowsingAutoPanScaleAllowed = true;
439  ViewMode mPreviousView = AttributeTable;
440 
441  friend class TestQgsDualView;
442  friend class TestQgsAttributeTable;
443 };
444 
449 class GUI_EXPORT QgsAttributeTableAction : public QAction
450 {
451  Q_OBJECT
452 
453  public:
454 
460  QgsAttributeTableAction( const QString &name, QgsDualView *dualView, QUuid action, const QModelIndex &fieldIdx )
461  : QAction( name, dualView )
462  , mDualView( dualView )
463  , mAction( action )
464  , mFieldIdx( fieldIdx )
465  {}
466 
467  public slots:
468  void execute();
469  void featureForm();
470 
471  private:
472  QgsDualView *mDualView = nullptr;
473  QUuid mAction;
474  QModelIndex mFieldIdx;
475 };
476 
481 class GUI_EXPORT QgsAttributeTableMapLayerAction : public QAction
482 {
483  Q_OBJECT
484 
485  public:
486  QgsAttributeTableMapLayerAction( const QString &name, QgsDualView *dualView, QgsMapLayerAction *action, const QModelIndex &fieldIdx )
487  : QAction( name, dualView )
488  , mDualView( dualView )
489  , mAction( action )
490  , mFieldIdx( fieldIdx )
491  {}
492 
493  public slots:
494  void execute();
495 
496  private:
497  QgsDualView *mDualView = nullptr;
498  QgsMapLayerAction *mAction = nullptr;
499  QModelIndex mFieldIdx;
500 };
501 
502 Q_DECLARE_METATYPE( QModelIndex );
503 
504 #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:460
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:486
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:45
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:56
QgsAttributeTableFilterModel::FilterMode filterMode()
Gets the filter mode.
Definition: qgsdualview.h:133
QgsFeatureIds filteredFeatures()
Gets a list of currently visible feature ids.
Definition: qgsdualview.h:178
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:75
@ PanToFeature
The map is panned to the center of the feature bounding-box.
Definition: qgsdualview.h:77
@ ZoomToFeature
The map is zoomed to contained the feature bounding-box.
Definition: qgsdualview.h:78
QgsAttributeTableModel * masterModel() const
Returns the model which has the information about all features (not only filtered)
Definition: qgsdualview.h:185
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:206
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