QGIS API Documentation  2.99.0-Master (f1c3692)
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 
43 class GUI_EXPORT QgsDualView : public QStackedWidget, private Ui::QgsDualViewBase
44 {
45  Q_OBJECT
46 
47  public:
48 
54  enum ViewMode
55  {
56 
60  AttributeTable = 0,
61 
67  AttributeEditor = 1
68  };
69 
70  Q_ENUM( ViewMode );
71 
76  explicit QgsDualView( QWidget *parent SIP_TRANSFERTHIS = 0 );
77 
89  void init( QgsVectorLayer *layer, QgsMapCanvas *mapCanvas, const QgsFeatureRequest &request = QgsFeatureRequest(), const QgsAttributeEditorContext &context = QgsAttributeEditorContext(),
90  bool loadFeatures = true );
91 
98  void setView( ViewMode view );
99 
105  ViewMode view() const;
106 
112  void setFilterMode( QgsAttributeTableFilterModel::FilterMode filterMode );
113 
119  QgsAttributeTableFilterModel::FilterMode filterMode() { return mFilterModel->filterMode(); }
120 
127  void setSelectedOnTop( bool selectedOnTop );
128 
134  int featureCount();
135 
142  int filteredFeatureCount();
143 
150  void setFilteredFeatures( const QgsFeatureIds &filteredFeatures );
151 
155  QgsFeatureIds filteredFeatures() { return mFilterModel->filteredFeatures(); }
156 
162  QgsAttributeTableModel *masterModel() const { return mMasterModel; }
163 
169  void setRequest( const QgsFeatureRequest &request );
170 
176  void setFeatureSelectionManager( QgsIFeatureSelectionManager *featureSelectionManager );
177 
183  QgsAttributeTableView *tableView() { return mTableView; }
184 
189  void setAttributeTableConfig( const QgsAttributeTableConfig &config );
190 
194  void setSortExpression( const QString &sortExpression, Qt::SortOrder sortOrder = Qt::AscendingOrder );
195 
199  QString sortExpression() const;
200 
201  public slots:
202 
208  void setCurrentEditSelection( const QgsFeatureIds &fids );
209 
216  bool saveEditChanges();
217 
218  void openConditionalStyles();
219 
224  void setMultiEditEnabled( bool enabled );
225 
231  void toggleSearchMode( bool enabled );
232 
237  void copyCellContent() const;
238 
239  signals:
240 
245  void displayExpressionChanged( const QString &expression );
246 
250  void filterChanged();
251 
258  void filterExpressionSet( const QString &expression, QgsAttributeForm::FilterType type );
259 
264  void formModeChanged( QgsAttributeForm::Mode mode );
265 
266  protected:
267  virtual void hideEvent( QHideEvent *event ) override;
268 
269  private slots:
270 
271  void mFeatureList_aboutToChangeEditSelection( bool &ok );
272 
278  void mFeatureList_currentEditSelectionChanged( const QgsFeature &feat );
279 
280  void previewExpressionBuilder();
281 
282  void previewColumnChanged( QAction *previewAction, const QString &expression );
283 
284  void viewWillShowContextMenu( QMenu *menu, const QModelIndex &atIndex );
285 
286  void showViewHeaderMenu( QPoint point );
287 
288  void organizeColumns();
289 
290  void tableColumnResized( int column, int width );
291 
292  void hideColumn();
293 
294  void resizeColumn();
295 
296  void autosizeColumn();
297 
298  void modifySort();
299 
300  void previewExpressionChanged( const QString &expression );
301 
302  void onSortColumnChanged();
303 
304  void sortByPreviewExpression();
305 
306  void updateSelectedFeatures();
307 
308  void extentChanged();
309 
315  void featureFormAttributeChanged();
316 
323  virtual void progress( int i, bool &cancel );
324 
329  virtual void finished();
330 
332  void zoomToCurrentFeature();
334  void panToCurrentFeature();
335 
336  void flashCurrentFeature();
337 
338  void rebuildFullLayerCache();
339 
340  private:
341 
345  void columnBoxInit();
346  void initLayerCache( bool cacheGeometry );
347  void initModels( QgsMapCanvas *mapCanvas, const QgsFeatureRequest &request, bool loadFeatures );
348  void restoreRecentDisplayExpressions();
349  void saveRecentDisplayExpressions() const;
350  void setDisplayExpression( const QString &expression );
351  void insertRecentlyUsedDisplayExpression( const QString &expression );
352 
353  QgsAttributeEditorContext mEditorContext;
354  QgsAttributeTableModel *mMasterModel = nullptr;
355  QgsAttributeTableFilterModel *mFilterModel = nullptr;
356  QgsFeatureListModel *mFeatureListModel = nullptr;
357  QgsAttributeForm *mAttributeForm = nullptr;
358  QMenu *mPreviewColumnsMenu = nullptr;
359  QMenu *mPreviewActionMenu = nullptr;
360  QAction *mLastDisplayExpressionAction = nullptr;
361  QMenu *mHorizontalHeaderMenu = nullptr;
362  QgsVectorLayerCache *mLayerCache = nullptr;
363  QgsVectorLayer *mLayer = nullptr;
364  QProgressDialog *mProgressDlg = nullptr;
365  QgsIFeatureSelectionManager *mFeatureSelectionManager = nullptr;
366  QgsDistanceArea mDistanceArea;
367  QString mDisplayExpression;
368  QgsAttributeTableConfig mConfig;
369  QgsScrollArea *mAttributeEditorScrollArea = nullptr;
370  QgsMapCanvas *mMapCanvas = nullptr;
371 
372  friend class TestQgsDualView;
373  friend class TestQgsAttributeTable;
374 };
375 
380 class GUI_EXPORT QgsAttributeTableAction : public QAction
381 {
382  Q_OBJECT
383 
384  public:
385 
391  QgsAttributeTableAction( const QString &name, QgsDualView *dualView, const QUuid &action, const QModelIndex &fieldIdx )
392  : QAction( name, dualView )
393  , mDualView( dualView )
394  , mAction( action )
395  , mFieldIdx( fieldIdx )
396  {}
397 
398  public slots:
399  void execute();
400  void featureForm();
401 
402  private:
403  QgsDualView *mDualView = nullptr;
404  QUuid mAction;
405  QModelIndex mFieldIdx;
406 };
407 
412 class GUI_EXPORT QgsAttributeTableMapLayerAction : public QAction
413 {
414  Q_OBJECT
415 
416  public:
417  QgsAttributeTableMapLayerAction( const QString &name, QgsDualView *dualView, QgsMapLayerAction *action, const QModelIndex &fieldIdx )
418  : QAction( name, dualView )
419  , mDualView( dualView )
420  , mAction( action )
421  , mFieldIdx( fieldIdx )
422  {}
423 
424  public slots:
425  void execute();
426 
427  private:
428  QgsDualView *mDualView = nullptr;
429  QgsMapLayerAction *mAction = nullptr;
430  QModelIndex mFieldIdx;
431 };
432 
433 Q_DECLARE_METATYPE( QModelIndex );
434 
435 #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:162
QSet< QgsFeatureId > QgsFeatureIds
Definition: qgsfeature.h:544
This class contains context information for attribute editor widgets.
QgsAttributeTableView * tableView()
Returns the table view.
Definition: qgsdualview.h:183
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:417
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:62
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:74
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:155
This class caches features of a given QgsVectorLayer.
QgsAttributeTableFilterModel::FilterMode filterMode()
Get the filter mode.
Definition: qgsdualview.h:119
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:391
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:43