QGIS API Documentation  3.8.0-Zanzibar (11aff65)
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 QSignalMapper;
30 class QgsMapLayerAction;
31 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 
96  void init( QgsVectorLayer *layer,
97  QgsMapCanvas *mapCanvas,
98  const QgsFeatureRequest &request = QgsFeatureRequest(),
100  bool loadFeatures = true );
101 
108  void setView( ViewMode view );
109 
115  ViewMode view() const;
116 
122  void setFilterMode( QgsAttributeTableFilterModel::FilterMode filterMode );
123 
129  QgsAttributeTableFilterModel::FilterMode filterMode() { return mFilterModel->filterMode(); }
130 
137  void setSelectedOnTop( bool selectedOnTop );
138 
144  int featureCount();
145 
152  int filteredFeatureCount();
153 
160  void setFilteredFeatures( const QgsFeatureIds &filteredFeatures );
161 
165  QgsFeatureIds filteredFeatures() { return mFilterModel->filteredFeatures(); }
166 
172  QgsAttributeTableModel *masterModel() const { return mMasterModel; }
173 
179  void setRequest( const QgsFeatureRequest &request );
180 
186  void setFeatureSelectionManager( QgsIFeatureSelectionManager *featureSelectionManager );
187 
193  QgsAttributeTableView *tableView() { return mTableView; }
194 
199  void setAttributeTableConfig( const QgsAttributeTableConfig &config );
200 
204  void setSortExpression( const QString &sortExpression, Qt::SortOrder sortOrder = Qt::AscendingOrder );
205 
209  QString sortExpression() const;
210 
215  QgsAttributeTableConfig attributeTableConfig() const;
216 
217  public slots:
218 
224  void setCurrentEditSelection( const QgsFeatureIds &fids );
225 
232  bool saveEditChanges();
233 
234  void openConditionalStyles();
235 
240  void setMultiEditEnabled( bool enabled );
241 
247  void toggleSearchMode( bool enabled );
248 
253  void copyCellContent() const;
254 
259  void cancelProgress( );
260 
261  signals:
262 
267  void displayExpressionChanged( const QString &expression );
268 
272  void filterChanged();
273 
280  void filterExpressionSet( const QString &expression, QgsAttributeForm::FilterType type );
281 
286  void formModeChanged( QgsAttributeEditorContext::Mode mode );
287 
293  void showContextMenuExternally( QgsActionMenu *menu, QgsFeatureId fid );
294 
295  protected:
296  void hideEvent( QHideEvent *event ) override;
297 
298  private slots:
299 
300  void featureListAboutToChangeEditSelection( bool &ok );
301 
307  void featureListCurrentEditSelectionChanged( const QgsFeature &feat );
308 
309  void previewExpressionBuilder();
310 
311  void previewColumnChanged( QAction *previewAction, const QString &expression );
312 
313  void viewWillShowContextMenu( QMenu *menu, const QModelIndex &atIndex );
314 
315  void widgetWillShowContextMenu( QgsActionMenu *menu, const QModelIndex &atIndex );
316 
317  void showViewHeaderMenu( QPoint point );
318 
319  void organizeColumns();
320 
321  void tableColumnResized( int column, int width );
322 
323  void hideColumn();
324 
325  void resizeColumn();
326 
327  void autosizeColumn();
328 
329  void modifySort();
330 
331  void previewExpressionChanged( const QString &expression );
332 
333  void onSortColumnChanged();
334 
335  void sortByPreviewExpression();
336 
337  void updateSelectedFeatures();
338 
339  void extentChanged();
340 
346  void featureFormAttributeChanged( const QString &attribute, const QVariant &value, bool attributeChanged );
347 
354  virtual void progress( int i, bool &cancel );
355 
360  virtual void finished();
361 
363  void zoomToCurrentFeature();
365  void panToCurrentFeature();
366 
367  void flashCurrentFeature();
368 
369  void rebuildFullLayerCache();
370 
371  void panZoomGroupButtonToggled( QAbstractButton *button, bool checked );
372 
373  void flashButtonClicked( bool clicked );
374 
375  private:
376 
380  void columnBoxInit();
381  void initLayerCache( bool cacheGeometry );
382  void initModels( QgsMapCanvas *mapCanvas, const QgsFeatureRequest &request, bool loadFeatures );
383  void restoreRecentDisplayExpressions();
384  void saveRecentDisplayExpressions() const;
385  void setDisplayExpression( const QString &expression );
386  void insertRecentlyUsedDisplayExpression( const QString &expression );
387  void updateEditSelectionProgress( int progress, int count );
388  void panOrZoomToFeature( const QgsFeatureIds &featureset );
389 
390  QgsAttributeEditorContext mEditorContext;
391  QgsAttributeTableModel *mMasterModel = nullptr;
392  QgsAttributeTableFilterModel *mFilterModel = nullptr;
393  QgsFeatureListModel *mFeatureListModel = nullptr;
394  QgsAttributeForm *mAttributeForm = nullptr;
395  QMenu *mPreviewColumnsMenu = nullptr;
396  QMenu *mPreviewActionMenu = nullptr;
397  QAction *mLastDisplayExpressionAction = nullptr;
398  QMenu *mHorizontalHeaderMenu = nullptr;
399  QgsVectorLayerCache *mLayerCache = nullptr;
400  QPointer< QgsVectorLayer > mLayer = nullptr;
401  QProgressDialog *mProgressDlg = nullptr;
402  QgsIFeatureSelectionManager *mFeatureSelectionManager = nullptr;
403  QString mDisplayExpression;
404  QgsAttributeTableConfig mConfig;
405  QgsScrollArea *mAttributeEditorScrollArea = nullptr;
406  // If the current feature is set, while the form is still not initialized
407  // we will temporarily save it in here and set it on init
408  QgsFeature mTempAttributeFormFeature;
409 
410  friend class TestQgsDualView;
411  friend class TestQgsAttributeTable;
412 };
413 
418 class GUI_EXPORT QgsAttributeTableAction : public QAction
419 {
420  Q_OBJECT
421 
422  public:
423 
429  QgsAttributeTableAction( const QString &name, QgsDualView *dualView, QUuid action, const QModelIndex &fieldIdx )
430  : QAction( name, dualView )
431  , mDualView( dualView )
432  , mAction( action )
433  , mFieldIdx( fieldIdx )
434  {}
435 
436  public slots:
437  void execute();
438  void featureForm();
439 
440  private:
441  QgsDualView *mDualView = nullptr;
442  QUuid mAction;
443  QModelIndex mFieldIdx;
444 };
445 
450 class GUI_EXPORT QgsAttributeTableMapLayerAction : public QAction
451 {
452  Q_OBJECT
453 
454  public:
455  QgsAttributeTableMapLayerAction( const QString &name, QgsDualView *dualView, QgsMapLayerAction *action, const QModelIndex &fieldIdx )
456  : QAction( name, dualView )
457  , mDualView( dualView )
458  , mAction( action )
459  , mFieldIdx( fieldIdx )
460  {}
461 
462  public slots:
463  void execute();
464 
465  private:
466  QgsDualView *mDualView = nullptr;
467  QgsMapLayerAction *mAction = nullptr;
468  QModelIndex mFieldIdx;
469 };
470 
471 Q_DECLARE_METATYPE( QModelIndex );
472 
473 #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:172
This class contains context information for attribute editor widgets.
QgsAttributeTableView * tableView()
Returns the table view.
Definition: qgsdualview.h:193
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:455
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: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:165
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:129
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:429
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