QGIS API Documentation  2.99.0-Master (01468d0)
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 
46  public:
47 
53  enum ViewMode
54  {
55 
59  AttributeTable = 0,
60 
66  AttributeEditor = 1
67  };
68 
69  Q_ENUM( ViewMode );
70 
75  explicit QgsDualView( QWidget *parent SIP_TRANSFERTHIS = 0 );
76 
88  void init( QgsVectorLayer *layer, QgsMapCanvas *mapCanvas, const QgsFeatureRequest &request = QgsFeatureRequest(), const QgsAttributeEditorContext &context = QgsAttributeEditorContext(),
89  bool loadFeatures = true );
90 
97  void setView( ViewMode view );
98 
104  ViewMode view() const;
105 
111  void setFilterMode( QgsAttributeTableFilterModel::FilterMode filterMode );
112 
118  QgsAttributeTableFilterModel::FilterMode filterMode() { return mFilterModel->filterMode(); }
119 
126  void setSelectedOnTop( bool selectedOnTop );
127 
133  int featureCount();
134 
141  int filteredFeatureCount();
142 
149  void setFilteredFeatures( const QgsFeatureIds &filteredFeatures );
150 
154  QgsFeatureIds filteredFeatures() { return mFilterModel->filteredFeatures(); }
155 
161  QgsAttributeTableModel *masterModel() const { return mMasterModel; }
162 
168  void setRequest( const QgsFeatureRequest &request );
169 
175  void setFeatureSelectionManager( QgsIFeatureSelectionManager *featureSelectionManager );
176 
182  QgsAttributeTableView *tableView() { return mTableView; }
183 
188  void setAttributeTableConfig( const QgsAttributeTableConfig &config );
189 
193  void setSortExpression( const QString &sortExpression, Qt::SortOrder sortOrder = Qt::AscendingOrder );
194 
198  QString sortExpression() const;
199 
200  public slots:
201 
207  void setCurrentEditSelection( const QgsFeatureIds &fids );
208 
215  bool saveEditChanges();
216 
217  void openConditionalStyles();
218 
222  void setMultiEditEnabled( bool enabled );
223 
228  void toggleSearchMode( bool enabled );
229 
234  void copyCellContent() const;
235 
236  signals:
237 
242  void displayExpressionChanged( const QString &expression );
243 
247  void filterChanged();
248 
254  void filterExpressionSet( const QString &expression, QgsAttributeForm::FilterType type );
255 
259  void formModeChanged( QgsAttributeForm::Mode mode );
260 
261  protected:
262  virtual void hideEvent( QHideEvent *event ) override;
263 
264  private slots:
265 
266  void on_mFeatureList_aboutToChangeEditSelection( bool &ok );
267 
273  void on_mFeatureList_currentEditSelectionChanged( const QgsFeature &feat );
274 
275  void previewExpressionBuilder();
276 
277  void previewColumnChanged( QAction *previewAction, const QString &expression );
278 
279  void viewWillShowContextMenu( QMenu *menu, const QModelIndex &atIndex );
280 
281  void showViewHeaderMenu( QPoint point );
282 
283  void organizeColumns();
284 
285  void tableColumnResized( int column, int width );
286 
287  void hideColumn();
288 
289  void resizeColumn();
290 
291  void autosizeColumn();
292 
293  void modifySort();
294 
295  void previewExpressionChanged( const QString &expression );
296 
297  void onSortColumnChanged();
298 
299  void sortByPreviewExpression();
300 
301  void updateSelectedFeatures();
302 
303  void extentChanged();
304 
310  void featureFormAttributeChanged();
311 
318  virtual void progress( int i, bool &cancel );
319 
324  virtual void finished();
325 
327  void zoomToCurrentFeature();
329  void panToCurrentFeature();
330 
331  void rebuildFullLayerCache();
332 
333  private:
334 
338  void columnBoxInit();
339  void initLayerCache( bool cacheGeometry );
340  void initModels( QgsMapCanvas *mapCanvas, const QgsFeatureRequest &request, bool loadFeatures );
341  void restoreRecentDisplayExpressions();
342  void saveRecentDisplayExpressions() const;
343  void setDisplayExpression( const QString &expression );
344  void insertRecentlyUsedDisplayExpression( const QString &expression );
345 
346  QgsAttributeEditorContext mEditorContext;
347  QgsAttributeTableModel *mMasterModel = nullptr;
348  QgsAttributeTableFilterModel *mFilterModel = nullptr;
349  QgsFeatureListModel *mFeatureListModel = nullptr;
350  QgsAttributeForm *mAttributeForm = nullptr;
351  QMenu *mPreviewColumnsMenu = nullptr;
352  QMenu *mPreviewActionMenu = nullptr;
353  QAction *mLastDisplayExpressionAction = nullptr;
354  QMenu *mHorizontalHeaderMenu = nullptr;
355  QgsVectorLayerCache *mLayerCache = nullptr;
356  QgsVectorLayer *mLayer = nullptr;
357  QProgressDialog *mProgressDlg = nullptr;
358  QgsIFeatureSelectionManager *mFeatureSelectionManager = nullptr;
359  QgsDistanceArea mDistanceArea;
360  QString mDisplayExpression;
361  QgsAttributeTableConfig mConfig;
362  QgsScrollArea *mAttributeEditorScrollArea = nullptr;
363  QgsMapCanvas *mMapCanvas = nullptr;
364 
365  friend class TestQgsDualView;
366  friend class TestQgsAttributeTable;
367 };
368 
372 class GUI_EXPORT QgsAttributeTableAction : public QAction
373 {
374  Q_OBJECT
375 
376  public:
377 
383  QgsAttributeTableAction( const QString &name, QgsDualView *dualView, const QUuid &action, const QModelIndex &fieldIdx )
384  : QAction( name, dualView )
385  , mDualView( dualView )
386  , mAction( action )
387  , mFieldIdx( fieldIdx )
388  {}
389 
390  public slots:
391  void execute();
392  void featureForm();
393 
394  private:
395  QgsDualView *mDualView = nullptr;
396  QUuid mAction;
397  QModelIndex mFieldIdx;
398 };
399 
403 class GUI_EXPORT QgsAttributeTableMapLayerAction : public QAction
404 {
405  Q_OBJECT
406 
407  public:
408  QgsAttributeTableMapLayerAction( const QString &name, QgsDualView *dualView, QgsMapLayerAction *action, const QModelIndex &fieldIdx )
409  : QAction( name, dualView )
410  , mDualView( dualView )
411  , mAction( action )
412  , mFieldIdx( fieldIdx )
413  {}
414 
415  public slots:
416  void execute();
417 
418  private:
419  QgsDualView *mDualView = nullptr;
420  QgsMapLayerAction *mAction = nullptr;
421  QModelIndex mFieldIdx;
422 };
423 
424 Q_DECLARE_METATYPE( QModelIndex );
425 
426 #endif // QGSDUALVIEW_H
Provides a table view of features of a QgsVectorLayer.
#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:161
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:182
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:408
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:154
This class caches features of a given QgsVectorLayer.
QgsAttributeTableFilterModel::FilterMode filterMode()
Get the filter mode.
Definition: qgsdualview.h:118
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:383
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