QGIS API Documentation  2.99.0-Master (90ae728)
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 QScrollArea;
33 
41 class GUI_EXPORT QgsDualView : public QStackedWidget, private Ui::QgsDualViewBase
42 {
43  Q_OBJECT
44  Q_ENUMS( ViewMode )
45 
46  public:
47 
53  enum ViewMode
54  {
55 
59  AttributeTable = 0,
60 
66  AttributeEditor = 1
67  };
68 
73  explicit QgsDualView( QWidget* parent = nullptr );
74 
84  void init( QgsVectorLayer* layer, QgsMapCanvas* mapCanvas, const QgsFeatureRequest& request = QgsFeatureRequest(), const QgsAttributeEditorContext& context = QgsAttributeEditorContext() );
85 
92  void setView( ViewMode view );
93 
99  ViewMode view() const;
100 
106  void setFilterMode( QgsAttributeTableFilterModel::FilterMode filterMode );
107 
113  QgsAttributeTableFilterModel::FilterMode filterMode() { return mFilterModel->filterMode(); }
114 
121  void setSelectedOnTop( bool selectedOnTop );
122 
128  int featureCount();
129 
136  int filteredFeatureCount();
137 
144  void setFilteredFeatures( const QgsFeatureIds& filteredFeatures );
145 
149  QgsFeatureIds filteredFeatures() { return mFilterModel->filteredFeatures(); }
150 
156  QgsAttributeTableModel* masterModel() const { return mMasterModel; }
157 
163  void setRequest( const QgsFeatureRequest& request );
164 
170  void setFeatureSelectionManager( QgsIFeatureSelectionManager* featureSelectionManager );
171 
177  QgsAttributeTableView* tableView() { return mTableView; }
178 
183  void setAttributeTableConfig( const QgsAttributeTableConfig& config );
184 
188  void setSortExpression( const QString& sortExpression , Qt::SortOrder sortOrder = Qt::AscendingOrder );
189 
193  QString sortExpression() const;
194 
195  protected:
196 
200  void columnBoxInit();
201 
202  public slots:
203 
209  void setCurrentEditSelection( const QgsFeatureIds& fids );
210 
217  bool saveEditChanges();
218 
219  void openConditionalStyles();
220 
224  void setMultiEditEnabled( bool enabled );
225 
230  void toggleSearchMode( bool enabled );
231 
236  void copyCellContent() const;
237 
238  signals:
239 
244  void displayExpressionChanged( const QString& expression );
245 
249  void filterChanged();
250 
256  void filterExpressionSet( const QString& expression, QgsAttributeForm::FilterType type );
257 
261  void formModeChanged( QgsAttributeForm::Mode mode );
262 
263  private slots:
264 
265  void on_mFeatureList_aboutToChangeEditSelection( bool& ok );
266 
272  void on_mFeatureList_currentEditSelectionChanged( const QgsFeature& feat );
273 
274  void previewExpressionBuilder();
275 
276  void previewColumnChanged( QObject* previewAction );
277 
278  void viewWillShowContextMenu( QMenu* menu, const QModelIndex& atIndex );
279 
280  void showViewHeaderMenu( QPoint point );
281 
282  void organizeColumns();
283 
284  void tableColumnResized( int column, int width );
285 
286  void hideColumn();
287 
288  void resizeColumn();
289 
290  void autosizeColumn();
291 
292  void modifySort();
293 
294  void previewExpressionChanged( const QString& expression );
295 
296  void onSortColumnChanged();
297 
298  void sortByPreviewExpression();
299 
305  void featureFormAttributeChanged();
306 
313  virtual void progress( int i, bool &cancel );
314 
319  virtual void finished();
320 
322  void zoomToCurrentFeature();
324  void panToCurrentFeature();
325 
326  private:
327  void initLayerCache( QgsVectorLayer *layer, bool cacheGeometry );
328  void initModels( QgsMapCanvas* mapCanvas, const QgsFeatureRequest& request );
329 
330  QgsAttributeEditorContext mEditorContext;
331  QgsAttributeTableModel* mMasterModel = nullptr;
332  QgsAttributeTableFilterModel* mFilterModel = nullptr;
333  QgsFeatureListModel* mFeatureListModel = nullptr;
334  QgsAttributeForm* mAttributeForm = nullptr;
335  QSignalMapper* mPreviewActionMapper = nullptr;
336  QMenu* mPreviewColumnsMenu = nullptr;
337  QMenu* mHorizontalHeaderMenu = nullptr;
338  QgsVectorLayerCache* mLayerCache = nullptr;
339  QProgressDialog* mProgressDlg = nullptr;
340  QgsIFeatureSelectionManager* mFeatureSelectionManager = nullptr;
341  QgsDistanceArea mDistanceArea;
342  QString mDisplayExpression;
343  QgsAttributeTableConfig mConfig;
344  QScrollArea* mAttributeEditorScrollArea = nullptr;
345 
346  friend class TestQgsDualView;
347 };
348 
352 class GUI_EXPORT QgsAttributeTableAction : public QAction
353 {
354  Q_OBJECT
355 
356  public:
357 
363  QgsAttributeTableAction( const QString& name, QgsDualView* dualView, const QUuid& action, const QModelIndex& fieldIdx )
364  : QAction( name, dualView )
365  , mDualView( dualView )
366  , mAction( action )
367  , mFieldIdx( fieldIdx )
368  {}
369 
370  public slots:
371  void execute();
372  void featureForm();
373 
374  private:
375  QgsDualView* mDualView = nullptr;
376  QUuid mAction;
377  QModelIndex mFieldIdx;
378 };
379 
383 class GUI_EXPORT QgsAttributeTableMapLayerAction : public QAction
384 {
385  Q_OBJECT
386 
387  public:
388  QgsAttributeTableMapLayerAction( const QString &name, QgsDualView *dualView, QgsMapLayerAction* action, const QModelIndex &fieldIdx )
389  : QAction( name, dualView )
390  , mDualView( dualView )
391  , mAction( action )
392  , mFieldIdx( fieldIdx )
393  {}
394 
395  public slots:
396  void execute();
397 
398  private:
399  QgsDualView* mDualView = nullptr;
400  QgsMapLayerAction* mAction = nullptr;
401  QModelIndex mFieldIdx;
402 };
403 
404 Q_DECLARE_METATYPE( QModelIndex );
405 
406 #endif // QGSDUALVIEW_H
Provides a table view of features of a QgsVectorLayer.
QgsAttributeTableModel * masterModel() const
Returns the model which has the information about all features (not only filtered) ...
Definition: qgsdualview.h:156
QSet< QgsFeatureId > QgsFeatureIds
Definition: qgsfeature.h:355
This class contains context information for attribute editor widgets.
QgsAttributeTableView * tableView()
Returns the table view.
Definition: qgsdualview.h:177
ViewMode
The view modes, in which this widget can present information.
Definition: qgsdualview.h:53
QgsAttributeTableMapLayerAction(const QString &name, QgsDualView *dualView, QgsMapLayerAction *action, const QModelIndex &fieldIdx)
Definition: qgsdualview.h:388
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:136
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:72
FilterType
Filter types.
FilterMode
The filter mode defines how the rows should be filtered.
This class wraps a request for features to a vector layer (or directly its vector data provider)...
QgsFeatureIds filteredFeatures()
Get a list of currently visible feature ids.
Definition: qgsdualview.h:149
This class caches features of a given QgsVectorLayer.
QgsAttributeTableFilterModel::FilterMode filterMode()
Get the filter mode.
Definition: qgsdualview.h:113
General purpose distance and area calculator.
QgsAttributeTableAction(const QString &name, QgsDualView *dualView, const QUuid &action, const QModelIndex &fieldIdx)
Create a new attribute table action.
Definition: qgsdualview.h:363
This is a container for configuration of the attribute table.
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.
This widget is used to show the attributes of a set of features of a QgsVectorLayer.
Definition: qgsdualview.h:41