QGIS API Documentation  3.10.0-A Coruña (6c816b4204)
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;
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  Q_ENUM( ViewMode )
69 
70 
71 
73  {
74  NoAction = 0,
77  };
79 
80 
84  explicit QgsDualView( QWidget *parent SIP_TRANSFERTHIS = nullptr );
85  ~QgsDualView() override;
86 
98  void init( QgsVectorLayer *layer,
99  QgsMapCanvas *mapCanvas,
100  const QgsFeatureRequest &request = QgsFeatureRequest(),
102  bool loadFeatures = true );
103 
110  void setView( ViewMode view );
111 
117  ViewMode view() const;
118 
124  void setFilterMode( QgsAttributeTableFilterModel::FilterMode filterMode );
125 
131  QgsAttributeTableFilterModel::FilterMode filterMode() { return mFilterModel->filterMode(); }
132 
139  void setSelectedOnTop( bool selectedOnTop );
140 
146  int featureCount();
147 
154  int filteredFeatureCount();
155 
162  void setFilteredFeatures( const QgsFeatureIds &filteredFeatures );
163 
167  QgsFeatureIds filteredFeatures() { return mFilterModel->filteredFeatures(); }
168 
174  QgsAttributeTableModel *masterModel() const { return mMasterModel; }
175 
181  void setRequest( const QgsFeatureRequest &request );
182 
188  void setFeatureSelectionManager( QgsIFeatureSelectionManager *featureSelectionManager );
189 
195  QgsAttributeTableView *tableView() { return mTableView; }
196 
201  void setAttributeTableConfig( const QgsAttributeTableConfig &config );
202 
206  void setSortExpression( const QString &sortExpression, Qt::SortOrder sortOrder = Qt::AscendingOrder );
207 
211  QString sortExpression() const;
212 
217  QgsAttributeTableConfig attributeTableConfig() const;
218 
219  public slots:
220 
226  void setCurrentEditSelection( const QgsFeatureIds &fids );
227 
234  bool saveEditChanges();
235 
236  void openConditionalStyles();
237 
242  void setMultiEditEnabled( bool enabled );
243 
249  void toggleSearchMode( bool enabled );
250 
255  void copyCellContent() const;
256 
261  void cancelProgress( );
262 
263  signals:
264 
269  void displayExpressionChanged( const QString &expression );
270 
274  void filterChanged();
275 
282  void filterExpressionSet( const QString &expression, QgsAttributeForm::FilterType type );
283 
288  void formModeChanged( QgsAttributeEditorContext::Mode mode );
289 
295  void showContextMenuExternally( QgsActionMenu *menu, QgsFeatureId fid );
296 
297  protected:
298  void hideEvent( QHideEvent *event ) override;
299 
300  private slots:
301 
302  void featureListAboutToChangeEditSelection( bool &ok );
303 
309  void featureListCurrentEditSelectionChanged( const QgsFeature &feat );
310 
311  void previewExpressionBuilder();
312 
313  void previewColumnChanged( QAction *previewAction, const QString &expression );
314 
315  void viewWillShowContextMenu( QMenu *menu, const QModelIndex &atIndex );
316 
317  void widgetWillShowContextMenu( QgsActionMenu *menu, const QModelIndex &atIndex );
318 
319  void showViewHeaderMenu( QPoint point );
320 
321  void organizeColumns();
322 
323  void tableColumnResized( int column, int width );
324 
325  void hideColumn();
326 
327  void resizeColumn();
328 
329  void autosizeColumn();
330 
331  void modifySort();
332 
333  void previewExpressionChanged( const QString &expression );
334 
335  void onSortColumnChanged();
336 
337  void sortByPreviewExpression();
338 
339  void updateSelectedFeatures();
340 
341  void extentChanged();
342 
348  void featureFormAttributeChanged( const QString &attribute, const QVariant &value, bool attributeChanged );
349 
356  virtual void progress( int i, bool &cancel );
357 
362  virtual void finished();
363 
365  void zoomToCurrentFeature();
367  void panToCurrentFeature();
368 
369  void flashCurrentFeature();
370 
371  void rebuildFullLayerCache();
372 
373  void panZoomGroupButtonToggled( QAbstractButton *button, bool checked );
374 
375  void flashButtonClicked( bool clicked );
376 
377  private:
378 
382  void columnBoxInit();
383  void initLayerCache( bool cacheGeometry );
384  void initModels( QgsMapCanvas *mapCanvas, const QgsFeatureRequest &request, bool loadFeatures );
385  void restoreRecentDisplayExpressions();
386  void saveRecentDisplayExpressions() const;
387  void setDisplayExpression( const QString &expression );
388  void insertRecentlyUsedDisplayExpression( const QString &expression );
389  void updateEditSelectionProgress( int progress, int count );
390  void panOrZoomToFeature( const QgsFeatureIds &featureset );
391 
392  QgsFieldConditionalFormatWidget *mConditionalFormatWidget = nullptr;
393  QgsAttributeEditorContext mEditorContext;
394  QgsAttributeTableModel *mMasterModel = nullptr;
395  QgsAttributeTableFilterModel *mFilterModel = nullptr;
396  QgsFeatureListModel *mFeatureListModel = nullptr;
397  QgsAttributeForm *mAttributeForm = nullptr;
398  QMenu *mPreviewColumnsMenu = nullptr;
399  QMenu *mPreviewActionMenu = nullptr;
400  QAction *mLastDisplayExpressionAction = nullptr;
401  QMenu *mHorizontalHeaderMenu = nullptr;
402  QgsVectorLayerCache *mLayerCache = nullptr;
403  QPointer< QgsVectorLayer > mLayer = nullptr;
404  QProgressDialog *mProgressDlg = nullptr;
405  QgsIFeatureSelectionManager *mFeatureSelectionManager = nullptr;
406  QString mDisplayExpression;
407  QgsAttributeTableConfig mConfig;
408  QgsScrollArea *mAttributeEditorScrollArea = nullptr;
409  // If the current feature is set, while the form is still not initialized
410  // we will temporarily save it in here and set it on init
411  QgsFeature mTempAttributeFormFeature;
412  QgsFeatureIds mLastFeatureSet;
413 
414  friend class TestQgsDualView;
415  friend class TestQgsAttributeTable;
416 };
417 
422 class GUI_EXPORT QgsAttributeTableAction : public QAction
423 {
424  Q_OBJECT
425 
426  public:
427 
433  QgsAttributeTableAction( const QString &name, QgsDualView *dualView, QUuid action, const QModelIndex &fieldIdx )
434  : QAction( name, dualView )
435  , mDualView( dualView )
436  , mAction( action )
437  , mFieldIdx( fieldIdx )
438  {}
439 
440  public slots:
441  void execute();
442  void featureForm();
443 
444  private:
445  QgsDualView *mDualView = nullptr;
446  QUuid mAction;
447  QModelIndex mFieldIdx;
448 };
449 
454 class GUI_EXPORT QgsAttributeTableMapLayerAction : public QAction
455 {
456  Q_OBJECT
457 
458  public:
459  QgsAttributeTableMapLayerAction( const QString &name, QgsDualView *dualView, QgsMapLayerAction *action, const QModelIndex &fieldIdx )
460  : QAction( name, dualView )
461  , mDualView( dualView )
462  , mAction( action )
463  , mFieldIdx( fieldIdx )
464  {}
465 
466  public slots:
467  void execute();
468 
469  private:
470  QgsDualView *mDualView = nullptr;
471  QgsMapLayerAction *mAction = nullptr;
472  QModelIndex mFieldIdx;
473 };
474 
475 Q_DECLARE_METATYPE( QModelIndex );
476 
477 #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:174
This class contains context information for attribute editor widgets.
QgsAttributeTableView * tableView()
Returns the table view.
Definition: qgsdualview.h:195
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:459
The map is zoomed to contained the feature bounding-box.
Definition: qgsdualview.h:76
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: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:167
FeatureListBrowsingAction
Action on the map canvas when browsing the list of features.
Definition: qgsdualview.h:72
This class caches features of a given QgsVectorLayer.
QgsAttributeTableFilterModel::FilterMode filterMode()
Gets the filter mode.
Definition: qgsdualview.h:131
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:433
This widget is used to show the attributes of a set of features of a QgsVectorLayer.
Definition: qgsdualview.h:42
The map is panned to the center of the feature bounding-box.
Definition: qgsdualview.h:75