QGIS API Documentation  2.18.21-Las Palmas (9fba24a)
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 
27 #include "qgsdistancearea.h"
28 #include "qgsattributeform.h"
29 
30 class QgsAttributeForm;
31 class QgsFeatureRequest;
32 class QSignalMapper;
33 class QgsMapLayerAction;
34 class QScrollArea;
35 
43 class GUI_EXPORT QgsDualView : public QStackedWidget, private Ui::QgsDualViewBase
44 {
45  Q_OBJECT
46  Q_ENUMS( ViewMode )
47 
48  public:
49 
55  enum ViewMode
56  {
60  AttributeTable = 0,
66  AttributeEditor = 1
67  };
68 
73  explicit QgsDualView( QWidget* parent = nullptr );
74 
86  void init( QgsVectorLayer *layer, QgsMapCanvas *mapCanvas, const QgsFeatureRequest &request = QgsFeatureRequest(), const QgsAttributeEditorContext &context = QgsAttributeEditorContext(),
87  bool loadFeatures = true );
88 
95  void setView( ViewMode view );
96 
102  ViewMode view() const;
103 
109  void setFilterMode( QgsAttributeTableFilterModel::FilterMode filterMode );
110 
116  QgsAttributeTableFilterModel::FilterMode filterMode() { return mFilterModel->filterMode(); }
117 
124  void setSelectedOnTop( bool selectedOnTop );
125 
131  int featureCount();
132 
139  int filteredFeatureCount();
140 
147  void setFilteredFeatures( const QgsFeatureIds& filteredFeatures );
148 
152  QgsFeatureIds filteredFeatures() { return mFilterModel->filteredFeatures(); }
153 
159  QgsAttributeTableModel* masterModel() const { return mMasterModel; }
160 
166  void setRequest( const QgsFeatureRequest& request );
167 
173  void setFeatureSelectionManager( QgsIFeatureSelectionManager* featureSelectionManager );
174 
180  QgsAttributeTableView* tableView() { return mTableView; }
181 
186  void setAttributeTableConfig( const QgsAttributeTableConfig& config );
187 
191  void setSortExpression( const QString& sortExpression , Qt::SortOrder sortOrder = Qt::AscendingOrder );
192 
196  QString sortExpression() const;
197 
198  protected:
202  void columnBoxInit();
203 
204  public slots:
210  void setCurrentEditSelection( const QgsFeatureIds& fids );
211 
218  bool saveEditChanges();
219 
220  void openConditionalStyles();
221 
225  void setMultiEditEnabled( bool enabled );
226 
231  void toggleSearchMode( bool enabled );
232 
237  void copyCellContent() const;
238 
239  signals:
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 
300  void updateSelectedFeatures();
301 
302  void extentChanged();
303 
309  void featureFormAttributeChanged();
310 
317  virtual void progress( int i, bool &cancel );
318 
323  virtual void finished();
324 
326  void zoomToCurrentFeature();
327 
328  void rebuildFullLayerCache();
329 
330  private:
331  void initLayerCache( bool cacheGeometry );
332  void initModels( QgsMapCanvas* mapCanvas, const QgsFeatureRequest& request, bool loadFeatures );
333 
334  QgsAttributeEditorContext mEditorContext;
335  QgsAttributeTableModel* mMasterModel;
336  QgsAttributeTableFilterModel* mFilterModel;
337  QgsFeatureListModel* mFeatureListModel;
338  QgsAttributeForm* mAttributeForm;
339  QSignalMapper* mPreviewActionMapper;
340  QMenu* mPreviewColumnsMenu;
341  QMenu* mHorizontalHeaderMenu;
342  QgsVectorLayerCache* mLayerCache;
343  QgsVectorLayer *mLayer;
344  QProgressDialog* mProgressDlg;
345  QgsIFeatureSelectionManager* mFeatureSelectionManager;
346  QgsDistanceArea mDistanceArea;
347  QString mDisplayExpression;
348  QgsAttributeTableConfig mConfig;
349  QScrollArea* mAttributeEditorScrollArea;
350  QgsMapCanvas *mMapCanvas;
351 
352  friend class TestQgsDualView;
353  friend class TestQgsAttributeTable;
354 };
355 
359 class GUI_EXPORT QgsAttributeTableAction : public QAction
360 {
361  Q_OBJECT
362 
363  public:
364  QgsAttributeTableAction( const QString &name, QgsDualView *dualView, int action, const QModelIndex &fieldIdx )
365  : QAction( name, dualView )
366  , mDualView( dualView )
367  , mAction( action )
368  , mFieldIdx( fieldIdx )
369  {}
370 
371  public slots:
372  void execute();
373  void featureForm();
374 
375  private:
376  QgsDualView* mDualView;
377  int mAction;
378  QModelIndex mFieldIdx;
379 };
380 
384 class GUI_EXPORT QgsAttributeTableMapLayerAction : public QAction
385 {
386  Q_OBJECT
387 
388  public:
389  QgsAttributeTableMapLayerAction( const QString &name, QgsDualView *dualView, QgsMapLayerAction* action, const QModelIndex &fieldIdx )
390  : QAction( name, dualView )
391  , mDualView( dualView )
392  , mAction( action )
393  , mFieldIdx( fieldIdx )
394  {}
395 
396  public slots:
397  void execute();
398 
399  private:
400  QgsDualView* mDualView;
401  QgsMapLayerAction* mAction;
402  QModelIndex mFieldIdx;
403 };
404 
406 
407 #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:159
This class contains context information for attribute editor widgets.
QgsAttributeTableView * tableView()
Returns the table view.
Definition: qgsdualview.h:180
ViewMode
The view modes, in which this widget can present information.
Definition: qgsdualview.h:55
QgsAttributeTableAction(const QString &name, QgsDualView *dualView, int action, const QModelIndex &fieldIdx)
Definition: qgsdualview.h:364
QgsAttributeTableMapLayerAction(const QString &name, QgsDualView *dualView, QgsMapLayerAction *action, const QModelIndex &fieldIdx)
Definition: qgsdualview.h:389
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:187
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:109
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:152
This class caches features of a given QgsVectorLayer.
QgsAttributeTableFilterModel::FilterMode filterMode()
Get the filter mode.
Definition: qgsdualview.h:116
General purpose distance and area calculator.
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:43