QGIS API Documentation  2.99.0-Master (f1383e2)
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 #include "qgis.h"
21 
22 #include "ui_qgsdualviewbase.h"
23 
26 #include "qgsdistancearea.h"
27 #include "qgsattributeform.h"
28 #include "qgis_gui.h"
29 
30 class QgsFeatureRequest;
31 class QSignalMapper;
32 class QgsMapLayerAction;
33 class QgsScrollArea;
34 
42 class GUI_EXPORT QgsDualView : public QStackedWidget, private Ui::QgsDualViewBase
43 {
44  Q_OBJECT
45  Q_ENUMS( ViewMode )
46 
47  public:
48 
54  enum ViewMode
55  {
56 
60  AttributeTable = 0,
61 
67  AttributeEditor = 1
68  };
69 
74  explicit QgsDualView( QWidget *parent SIP_TRANSFERTHIS = 0 );
75 
87  void init( QgsVectorLayer *layer, QgsMapCanvas *mapCanvas, const QgsFeatureRequest &request = QgsFeatureRequest(), const QgsAttributeEditorContext &context = QgsAttributeEditorContext(),
88  bool loadFeatures = true );
89 
96  void setView( ViewMode view );
97 
103  ViewMode view() const;
104 
110  void setFilterMode( QgsAttributeTableFilterModel::FilterMode filterMode );
111 
117  QgsAttributeTableFilterModel::FilterMode filterMode() { return mFilterModel->filterMode(); }
118 
125  void setSelectedOnTop( bool selectedOnTop );
126 
132  int featureCount();
133 
140  int filteredFeatureCount();
141 
148  void setFilteredFeatures( const QgsFeatureIds &filteredFeatures );
149 
153  QgsFeatureIds filteredFeatures() { return mFilterModel->filteredFeatures(); }
154 
160  QgsAttributeTableModel *masterModel() const { return mMasterModel; }
161 
167  void setRequest( const QgsFeatureRequest &request );
168 
174  void setFeatureSelectionManager( QgsIFeatureSelectionManager *featureSelectionManager );
175 
181  QgsAttributeTableView *tableView() { return mTableView; }
182 
187  void setAttributeTableConfig( const QgsAttributeTableConfig &config );
188 
192  void setSortExpression( const QString &sortExpression, Qt::SortOrder sortOrder = Qt::AscendingOrder );
193 
197  QString sortExpression() const;
198 
199  protected:
200 
204  void columnBoxInit();
205 
206  public slots:
207 
213  void setCurrentEditSelection( const QgsFeatureIds &fids );
214 
221  bool saveEditChanges();
222 
223  void openConditionalStyles();
224 
228  void setMultiEditEnabled( bool enabled );
229 
234  void toggleSearchMode( bool enabled );
235 
240  void copyCellContent() const;
241 
242  signals:
243 
248  void displayExpressionChanged( const QString &expression );
249 
253  void filterChanged();
254 
260  void filterExpressionSet( const QString &expression, QgsAttributeForm::FilterType type );
261 
265  void formModeChanged( QgsAttributeForm::Mode mode );
266 
267  private slots:
268 
269  void on_mFeatureList_aboutToChangeEditSelection( bool &ok );
270 
276  void on_mFeatureList_currentEditSelectionChanged( const QgsFeature &feat );
277 
278  void previewExpressionBuilder();
279 
280  void previewColumnChanged( QObject *previewAction );
281 
282  void viewWillShowContextMenu( QMenu *menu, const QModelIndex &atIndex );
283 
284  void showViewHeaderMenu( QPoint point );
285 
286  void organizeColumns();
287 
288  void tableColumnResized( int column, int width );
289 
290  void hideColumn();
291 
292  void resizeColumn();
293 
294  void autosizeColumn();
295 
296  void modifySort();
297 
298  void previewExpressionChanged( const QString &expression );
299 
300  void onSortColumnChanged();
301 
302  void sortByPreviewExpression();
303 
304  void updateSelectedFeatures();
305 
306  void extentChanged();
307 
313  void featureFormAttributeChanged();
314 
321  virtual void progress( int i, bool &cancel );
322 
327  virtual void finished();
328 
330  void zoomToCurrentFeature();
332  void panToCurrentFeature();
333 
334  void rebuildFullLayerCache();
335 
336  private:
337  void initLayerCache( bool cacheGeometry );
338  void initModels( QgsMapCanvas *mapCanvas, const QgsFeatureRequest &request, bool loadFeatures );
339 
340  QgsAttributeEditorContext mEditorContext;
341  QgsAttributeTableModel *mMasterModel = nullptr;
342  QgsAttributeTableFilterModel *mFilterModel = nullptr;
343  QgsFeatureListModel *mFeatureListModel = nullptr;
344  QgsAttributeForm *mAttributeForm = nullptr;
345  QSignalMapper *mPreviewActionMapper = nullptr;
346  QMenu *mPreviewColumnsMenu = nullptr;
347  QMenu *mHorizontalHeaderMenu = nullptr;
348  QgsVectorLayerCache *mLayerCache = nullptr;
349  QgsVectorLayer *mLayer = nullptr;
350  QProgressDialog *mProgressDlg = nullptr;
351  QgsIFeatureSelectionManager *mFeatureSelectionManager = nullptr;
352  QgsDistanceArea mDistanceArea;
353  QString mDisplayExpression;
354  QgsAttributeTableConfig mConfig;
355  QgsScrollArea *mAttributeEditorScrollArea = nullptr;
356  QgsMapCanvas *mMapCanvas = nullptr;
357 
358  friend class TestQgsDualView;
359  friend class TestQgsAttributeTable;
360 };
361 
365 class GUI_EXPORT QgsAttributeTableAction : public QAction
366 {
367  Q_OBJECT
368 
369  public:
370 
376  QgsAttributeTableAction( const QString &name, QgsDualView *dualView, const QUuid &action, const QModelIndex &fieldIdx )
377  : QAction( name, dualView )
378  , mDualView( dualView )
379  , mAction( action )
380  , mFieldIdx( fieldIdx )
381  {}
382 
383  public slots:
384  void execute();
385  void featureForm();
386 
387  private:
388  QgsDualView *mDualView = nullptr;
389  QUuid mAction;
390  QModelIndex mFieldIdx;
391 };
392 
396 class GUI_EXPORT QgsAttributeTableMapLayerAction : public QAction
397 {
398  Q_OBJECT
399 
400  public:
401  QgsAttributeTableMapLayerAction( const QString &name, QgsDualView *dualView, QgsMapLayerAction *action, const QModelIndex &fieldIdx )
402  : QAction( name, dualView )
403  , mDualView( dualView )
404  , mAction( action )
405  , mFieldIdx( fieldIdx )
406  {}
407 
408  public slots:
409  void execute();
410 
411  private:
412  QgsDualView *mDualView = nullptr;
413  QgsMapLayerAction *mAction = nullptr;
414  QModelIndex mFieldIdx;
415 };
416 
417 Q_DECLARE_METATYPE( QModelIndex );
418 
419 #endif // QGSDUALVIEW_H
Provides a table view of features of a QgsVectorLayer.
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:34
QgsAttributeTableModel * masterModel() const
Returns the model which has the information about all features (not only filtered) ...
Definition: qgsdualview.h:160
QSet< QgsFeatureId > QgsFeatureIds
Definition: qgsfeature.h:519
This class contains context information for attribute editor widgets.
QgsAttributeTableView * tableView()
Returns the table view.
Definition: qgsdualview.h:181
ViewMode
The view modes, in which this widget can present information.
Definition: qgsdualview.h:54
QgsAttributeTableMapLayerAction(const QString &name, QgsDualView *dualView, QgsMapLayerAction *action, const QModelIndex &fieldIdx)
Definition: qgsdualview.h:401
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:61
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 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:153
This class caches features of a given QgsVectorLayer.
QgsAttributeTableFilterModel::FilterMode filterMode()
Get the filter mode.
Definition: qgsdualview.h:117
A general purpose distance and area calculator, capable of performing ellipsoid based calculations...
QgsAttributeTableAction(const QString &name, QgsDualView *dualView, const QUuid &action, const QModelIndex &fieldIdx)
Create a new attribute table action.
Definition: qgsdualview.h:376
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.
This widget is used to show the attributes of a set of features of a QgsVectorLayer.
Definition: qgsdualview.h:42