QGIS API Documentation  3.6.0-Noosa (5873452)
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 "qgsdistancearea.h"
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  QgsDistanceArea mDistanceArea;
387  QString mDisplayExpression;
388  QgsAttributeTableConfig mConfig;
389  QgsScrollArea *mAttributeEditorScrollArea = nullptr;
390  // If the current feature is set, while the form is still not initialized
391  // we will temporarily save it in here and set it on init
392  QgsFeature mTempAttributeFormFeature;
393 
394  friend class TestQgsDualView;
395  friend class TestQgsAttributeTable;
396 };
397 
402 class GUI_EXPORT QgsAttributeTableAction : public QAction
403 {
404  Q_OBJECT
405 
406  public:
407 
413  QgsAttributeTableAction( const QString &name, QgsDualView *dualView, QUuid action, const QModelIndex &fieldIdx )
414  : QAction( name, dualView )
415  , mDualView( dualView )
416  , mAction( action )
417  , mFieldIdx( fieldIdx )
418  {}
419 
420  public slots:
421  void execute();
422  void featureForm();
423 
424  private:
425  QgsDualView *mDualView = nullptr;
426  QUuid mAction;
427  QModelIndex mFieldIdx;
428 };
429 
434 class GUI_EXPORT QgsAttributeTableMapLayerAction : public QAction
435 {
436  Q_OBJECT
437 
438  public:
439  QgsAttributeTableMapLayerAction( const QString &name, QgsDualView *dualView, QgsMapLayerAction *action, const QModelIndex &fieldIdx )
440  : QAction( name, dualView )
441  , mDualView( dualView )
442  , mAction( action )
443  , mFieldIdx( fieldIdx )
444  {}
445 
446  public slots:
447  void execute();
448 
449  private:
450  QgsDualView *mDualView = nullptr;
451  QgsMapLayerAction *mAction = nullptr;
452  QModelIndex mFieldIdx;
453 };
454 
455 Q_DECLARE_METATYPE( QModelIndex );
456 
457 #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
QgsAttributeTableModel * masterModel() const
Returns the model which has the information about all features (not only filtered) ...
Definition: qgsdualview.h:161
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:439
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:73
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: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.
QgsAttributeTableFilterModel::FilterMode filterMode()
Gets the filter mode.
Definition: qgsdualview.h:118
A general purpose distance and area calculator, capable of performing ellipsoid based calculations...
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:413
This widget is used to show the attributes of a set of features of a QgsVectorLayer.
Definition: qgsdualview.h:42