QGIS API Documentation  3.4.15-Madeira (e83d02e274)
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 #include "qgis.h"
21 
22 #include "ui_qgsdualviewbase.h"
23 
26 #include "qgsattributeform.h"
27 #include "qgis_gui.h"
28 
29 class QgsFeatureRequest;
30 class QSignalMapper;
31 class QgsMapLayerAction;
32 class QgsScrollArea;
33 
42 class GUI_EXPORT QgsDualView : public QStackedWidget, private Ui::QgsDualViewBase
43 {
44  Q_OBJECT
45 
46  public:
47 
53  enum ViewMode
54  {
55 
59  AttributeTable = 0,
60 
66  AttributeEditor = 1
67  };
68 
69  Q_ENUM( ViewMode )
70 
71 
75  explicit QgsDualView( QWidget *parent SIP_TRANSFERTHIS = nullptr );
76 
88  void init( QgsVectorLayer *layer, QgsMapCanvas *mapCanvas, const QgsFeatureRequest &request = QgsFeatureRequest(), const QgsAttributeEditorContext &context = QgsAttributeEditorContext(),
89  bool loadFeatures = true );
90 
97  void setView( ViewMode view );
98 
104  ViewMode view() const;
105 
111  void setFilterMode( QgsAttributeTableFilterModel::FilterMode filterMode );
112 
118  QgsAttributeTableFilterModel::FilterMode filterMode() { return mFilterModel->filterMode(); }
119 
126  void setSelectedOnTop( bool selectedOnTop );
127 
133  int featureCount();
134 
141  int filteredFeatureCount();
142 
149  void setFilteredFeatures( const QgsFeatureIds &filteredFeatures );
150 
154  QgsFeatureIds filteredFeatures() { return mFilterModel->filteredFeatures(); }
155 
161  QgsAttributeTableModel *masterModel() const { return mMasterModel; }
162 
168  void setRequest( const QgsFeatureRequest &request );
169 
175  void setFeatureSelectionManager( QgsIFeatureSelectionManager *featureSelectionManager );
176 
182  QgsAttributeTableView *tableView() { return mTableView; }
183 
188  void setAttributeTableConfig( const QgsAttributeTableConfig &config );
189 
193  void setSortExpression( const QString &sortExpression, Qt::SortOrder sortOrder = Qt::AscendingOrder );
194 
198  QString sortExpression() const;
199 
204  QgsAttributeTableConfig attributeTableConfig() const;
205 
206  public slots:
207 
213  void setCurrentEditSelection( const QgsFeatureIds &fids );
214 
221  bool saveEditChanges();
222 
223  void openConditionalStyles();
224 
229  void setMultiEditEnabled( bool enabled );
230 
236  void toggleSearchMode( bool enabled );
237 
242  void copyCellContent() const;
243 
248  void cancelProgress( );
249 
250  signals:
251 
256  void displayExpressionChanged( const QString &expression );
257 
261  void filterChanged();
262 
269  void filterExpressionSet( const QString &expression, QgsAttributeForm::FilterType type );
270 
275  void formModeChanged( QgsAttributeEditorContext::Mode mode );
276 
282  void showContextMenuExternally( QgsActionMenu *menu, QgsFeatureId fid );
283 
284  protected:
285  void hideEvent( QHideEvent *event ) override;
286 
287  private slots:
288 
289  void mFeatureList_aboutToChangeEditSelection( bool &ok );
290 
296  void mFeatureList_currentEditSelectionChanged( const QgsFeature &feat );
297 
298  void previewExpressionBuilder();
299 
300  void previewColumnChanged( QAction *previewAction, const QString &expression );
301 
302  void viewWillShowContextMenu( QMenu *menu, const QModelIndex &atIndex );
303 
304  void widgetWillShowContextMenu( QgsActionMenu *menu, const QModelIndex &atIndex );
305 
306  void showViewHeaderMenu( QPoint point );
307 
308  void organizeColumns();
309 
310  void tableColumnResized( int column, int width );
311 
312  void hideColumn();
313 
314  void resizeColumn();
315 
316  void autosizeColumn();
317 
318  void modifySort();
319 
320  void previewExpressionChanged( const QString &expression );
321 
322  void onSortColumnChanged();
323 
324  void sortByPreviewExpression();
325 
326  void updateSelectedFeatures();
327 
328  void extentChanged();
329 
335  void featureFormAttributeChanged( const QString &attribute, const QVariant &value, bool attributeChanged );
336 
343  virtual void progress( int i, bool &cancel );
344 
349  virtual void finished();
350 
352  void zoomToCurrentFeature();
354  void panToCurrentFeature();
355 
356  void flashCurrentFeature();
357 
358  void rebuildFullLayerCache();
359 
360  private:
361 
365  void columnBoxInit();
366  void initLayerCache( bool cacheGeometry );
367  void initModels( QgsMapCanvas *mapCanvas, const QgsFeatureRequest &request, bool loadFeatures );
368  void restoreRecentDisplayExpressions();
369  void saveRecentDisplayExpressions() const;
370  void setDisplayExpression( const QString &expression );
371  void insertRecentlyUsedDisplayExpression( const QString &expression );
372 
373  QgsAttributeEditorContext mEditorContext;
374  QgsAttributeTableModel *mMasterModel = nullptr;
375  QgsAttributeTableFilterModel *mFilterModel = nullptr;
376  QgsFeatureListModel *mFeatureListModel = nullptr;
377  QgsAttributeForm *mAttributeForm = nullptr;
378  QMenu *mPreviewColumnsMenu = nullptr;
379  QMenu *mPreviewActionMenu = nullptr;
380  QAction *mLastDisplayExpressionAction = nullptr;
381  QMenu *mHorizontalHeaderMenu = nullptr;
382  QgsVectorLayerCache *mLayerCache = nullptr;
383  QPointer< QgsVectorLayer > mLayer = nullptr;
384  QProgressDialog *mProgressDlg = nullptr;
385  QgsIFeatureSelectionManager *mFeatureSelectionManager = nullptr;
386  QString mDisplayExpression;
387  QgsAttributeTableConfig mConfig;
388  QgsScrollArea *mAttributeEditorScrollArea = nullptr;
389  // If the current feature is set, while the form is still not initialized
390  // we will temporarily save it in here and set it on init
391  QgsFeature mTempAttributeFormFeature;
392 
393  friend class TestQgsDualView;
394  friend class TestQgsAttributeTable;
395 };
396 
401 class GUI_EXPORT QgsAttributeTableAction : public QAction
402 {
403  Q_OBJECT
404 
405  public:
406 
412  QgsAttributeTableAction( const QString &name, QgsDualView *dualView, QUuid action, const QModelIndex &fieldIdx )
413  : QAction( name, dualView )
414  , mDualView( dualView )
415  , mAction( action )
416  , mFieldIdx( fieldIdx )
417  {}
418 
419  public slots:
420  void execute();
421  void featureForm();
422 
423  private:
424  QgsDualView *mDualView = nullptr;
425  QUuid mAction;
426  QModelIndex mFieldIdx;
427 };
428 
433 class GUI_EXPORT QgsAttributeTableMapLayerAction : public QAction
434 {
435  Q_OBJECT
436 
437  public:
438  QgsAttributeTableMapLayerAction( const QString &name, QgsDualView *dualView, QgsMapLayerAction *action, const QModelIndex &fieldIdx )
439  : QAction( name, dualView )
440  , mDualView( dualView )
441  , mAction( action )
442  , mFieldIdx( fieldIdx )
443  {}
444 
445  public slots:
446  void execute();
447 
448  private:
449  QgsDualView *mDualView = nullptr;
450  QgsMapLayerAction *mAction = nullptr;
451  QModelIndex mFieldIdx;
452 };
453 
454 Q_DECLARE_METATYPE( QModelIndex );
455 
456 #endif // QGSDUALVIEW_H
Provides a table view of features of a QgsVectorLayer.
QSet< QgsFeatureId > QgsFeatureIds
Definition: qgsfeatureid.h:34
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:46
This class contains context information for attribute editor widgets.
QgsAttributeTableView * tableView()
Returns the table view.
Definition: qgsdualview.h:182
ViewMode
The view modes, in which this widget can present information.
Definition: qgsdualview.h:53
qint64 QgsFeatureId
Definition: qgsfeatureid.h:25
QgsAttributeTableMapLayerAction(const QString &name, QgsDualView *dualView, QgsMapLayerAction *action, const QModelIndex &fieldIdx)
Definition: qgsdualview.h:438
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:74
FilterMode filterMode()
The current filterModel.
FilterType
Filter types.
This class is a menu that is populated automatically with the actions defined for a given layer...
Definition: qgsactionmenu.h:38
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:154
This class caches features of a given QgsVectorLayer.
QgsAttributeTableModel * masterModel() const
Returns the model which has the information about all features (not only filtered) ...
Definition: qgsdualview.h:161
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:412
This widget is used to show the attributes of a set of features of a QgsVectorLayer.
Definition: qgsdualview.h:42