QGIS API Documentation  3.12.1-BucureČ™ti (121cc00ff0)
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  };
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 
161  void setFilteredFeatures( const QgsFeatureIds &filteredFeatures );
162 
166  QgsFeatureIds filteredFeatures() { return mFilterModel->filteredFeatures(); }
167 
173  QgsAttributeTableModel *masterModel() const { return mMasterModel; }
174 
180  void setRequest( const QgsFeatureRequest &request );
181 
187  void setFeatureSelectionManager( QgsIFeatureSelectionManager *featureSelectionManager );
188 
194  QgsAttributeTableView *tableView() { return mTableView; }
195 
200  void setAttributeTableConfig( const QgsAttributeTableConfig &config );
201 
205  void setSortExpression( const QString &sortExpression, Qt::SortOrder sortOrder = Qt::AscendingOrder );
206 
210  QString sortExpression() const;
211 
216  QgsAttributeTableConfig attributeTableConfig() const;
217 
218  public slots:
219 
225  void setCurrentEditSelection( const QgsFeatureIds &fids );
226 
233  bool saveEditChanges();
234 
235  void openConditionalStyles();
236 
241  void setMultiEditEnabled( bool enabled );
242 
248  void toggleSearchMode( bool enabled );
249 
254  void copyCellContent() const;
255 
260  void cancelProgress( );
261 
262  signals:
263 
268  void displayExpressionChanged( const QString &expression );
269 
273  void filterChanged();
274 
281  void filterExpressionSet( const QString &expression, QgsAttributeForm::FilterType type );
282 
287  void formModeChanged( QgsAttributeEditorContext::Mode mode );
288 
294  void showContextMenuExternally( QgsActionMenu *menu, QgsFeatureId fid );
295 
296  protected:
297  void hideEvent( QHideEvent *event ) override;
298 
299  private slots:
300 
301  void featureListAboutToChangeEditSelection( bool &ok );
302 
308  void featureListCurrentEditSelectionChanged( const QgsFeature &feat );
309 
310  void previewExpressionBuilder();
311 
312  void previewColumnChanged( QAction *previewAction, const QString &expression );
313 
314  void viewWillShowContextMenu( QMenu *menu, const QModelIndex &atIndex );
315 
316  void widgetWillShowContextMenu( QgsActionMenu *menu, const QModelIndex &atIndex );
317 
318  void showViewHeaderMenu( QPoint point );
319 
320  void organizeColumns();
321 
322  void tableColumnResized( int column, int width );
323 
324  void hideColumn();
325 
326  void resizeColumn();
327 
328  void autosizeColumn();
329 
330  void modifySort();
331 
332  void previewExpressionChanged( const QString &expression );
333 
334  void onSortColumnChanged();
335 
336  void sortByPreviewExpression();
337 
338  void updateSelectedFeatures();
339 
340  void extentChanged();
341 
347  void featureFormAttributeChanged( const QString &attribute, const QVariant &value, bool attributeChanged );
348 
355  virtual void progress( int i, bool &cancel );
356 
361  virtual void finished();
362 
364  void zoomToCurrentFeature();
366  void panToCurrentFeature();
367 
368  void flashCurrentFeature();
369 
370  void rebuildFullLayerCache();
371 
372  void panZoomGroupButtonToggled( QAbstractButton *button, bool checked );
373 
374  void flashButtonClicked( bool clicked );
375 
376  private:
377 
381  void columnBoxInit();
382  void initLayerCache( bool cacheGeometry );
383  void initModels( QgsMapCanvas *mapCanvas, const QgsFeatureRequest &request, bool loadFeatures );
384  void restoreRecentDisplayExpressions();
385  void saveRecentDisplayExpressions() const;
386  void setDisplayExpression( const QString &expression );
387  void insertRecentlyUsedDisplayExpression( const QString &expression );
388  void updateEditSelectionProgress( int progress, int count );
389  void panOrZoomToFeature( const QgsFeatureIds &featureset );
391  void setBrowsingAutoPanScaleAllowed( bool allowed );
392 
393  QgsFieldConditionalFormatWidget *mConditionalFormatWidget = nullptr;
394  QgsAttributeEditorContext mEditorContext;
395  QgsAttributeTableModel *mMasterModel = nullptr;
396  QgsAttributeTableFilterModel *mFilterModel = nullptr;
397  QgsFeatureListModel *mFeatureListModel = nullptr;
398  QgsAttributeForm *mAttributeForm = nullptr;
399  QMenu *mPreviewColumnsMenu = nullptr;
400  QMenu *mPreviewActionMenu = nullptr;
401  QAction *mLastDisplayExpressionAction = nullptr;
402  QMenu *mHorizontalHeaderMenu = nullptr;
403  QgsVectorLayerCache *mLayerCache = nullptr;
404  QPointer< QgsVectorLayer > mLayer = nullptr;
405  QProgressDialog *mProgressDlg = nullptr;
406  QgsIFeatureSelectionManager *mFeatureSelectionManager = nullptr;
407  QString mDisplayExpression;
408  QgsAttributeTableConfig mConfig;
409  QgsScrollArea *mAttributeEditorScrollArea = nullptr;
410  // If the current feature is set, while the form is still not initialized
411  // we will temporarily save it in here and set it on init
412  QgsFeature mTempAttributeFormFeature;
413  QgsFeatureIds mLastFeatureSet;
414  bool mBrowsingAutoPanScaleAllowed = true;
415 
416  friend class TestQgsDualView;
417  friend class TestQgsAttributeTable;
418 };
419 
424 class GUI_EXPORT QgsAttributeTableAction : public QAction
425 {
426  Q_OBJECT
427 
428  public:
429 
435  QgsAttributeTableAction( const QString &name, QgsDualView *dualView, QUuid 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  void featureForm();
445 
446  private:
447  QgsDualView *mDualView = nullptr;
448  QUuid mAction;
449  QModelIndex mFieldIdx;
450 };
451 
456 class GUI_EXPORT QgsAttributeTableMapLayerAction : public QAction
457 {
458  Q_OBJECT
459 
460  public:
461  QgsAttributeTableMapLayerAction( const QString &name, QgsDualView *dualView, QgsMapLayerAction *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 
471  private:
472  QgsDualView *mDualView = nullptr;
473  QgsMapLayerAction *mAction = nullptr;
474  QModelIndex mFieldIdx;
475 };
476 
477 Q_DECLARE_METATYPE( QModelIndex );
478 
479 #endif // QGSDUALVIEW_H
A widget for customizing conditional formatting options.
Provides a table view of features of a QgsVectorLayer.
QSet< QgsFeatureId > QgsFeatureIds
Definition: qgsfeatureid.h:34
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:53
QgsAttributeTableModel * masterModel() const
Returns the model which has the information about all features (not only filtered) ...
Definition: qgsdualview.h:173
This class contains context information for attribute editor widgets.
QgsAttributeTableView * tableView()
Returns the table view.
Definition: qgsdualview.h:194
ViewMode
The view modes, in which this widget can present information.
Definition: qgsdualview.h:52
qint64 QgsFeatureId
Definition: qgsfeatureid.h:25
QgsAttributeTableMapLayerAction(const QString &name, QgsDualView *dualView, QgsMapLayerAction *action, const QModelIndex &fieldIdx)
Definition: qgsdualview.h:461
The map is zoomed to contained the feature bounding-box.
Definition: qgsdualview.h:75
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:55
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:75
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()
Gets a list of currently visible feature ids.
Definition: qgsdualview.h:166
FeatureListBrowsingAction
Action on the map canvas when browsing the list of features.
Definition: qgsdualview.h:71
This class caches features of a given QgsVectorLayer.
QgsAttributeTableFilterModel::FilterMode filterMode()
Gets the filter mode.
Definition: qgsdualview.h:130
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:435
This widget is used to show the attributes of a set of features of a QgsVectorLayer.
Definition: qgsdualview.h:41
The map is panned to the center of the feature bounding-box.
Definition: qgsdualview.h:74