QGIS API Documentation  2.17.0-Master (bf77d09)
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 
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:
199  void columnBoxInit();
200 
201  public slots:
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:
241  void displayExpressionChanged( const QString& expression );
242 
246  void filterChanged();
247 
253  void filterExpressionSet( const QString& expression, QgsAttributeForm::FilterType type );
254 
258  void formModeChanged( QgsAttributeForm::Mode mode );
259 
260  private slots:
261 
262  void on_mFeatureList_aboutToChangeEditSelection( bool& ok );
263 
269  void on_mFeatureList_currentEditSelectionChanged( const QgsFeature& feat );
270 
271  void previewExpressionBuilder();
272 
273  void previewColumnChanged( QObject* previewAction );
274 
275  void viewWillShowContextMenu( QMenu* menu, const QModelIndex& atIndex );
276 
277  void showViewHeaderMenu( QPoint point );
278 
279  void organizeColumns();
280 
281  void tableColumnResized( int column, int width );
282 
283  void hideColumn();
284 
285  void resizeColumn();
286 
287  void autosizeColumn();
288 
289  void modifySort();
290 
291  void previewExpressionChanged( const QString& expression );
292 
293  void onSortColumnChanged();
294 
295  void sortByPreviewExpression();
296 
302  void featureFormAttributeChanged();
303 
310  virtual void progress( int i, bool &cancel );
311 
316  virtual void finished();
317 
319  void zoomToCurrentFeature();
320 
321  private:
322  void initLayerCache( QgsVectorLayer *layer, bool cacheGeometry );
323  void initModels( QgsMapCanvas* mapCanvas, const QgsFeatureRequest& request );
324 
325  QgsAttributeEditorContext mEditorContext;
326  QgsAttributeTableModel* mMasterModel;
327  QgsAttributeTableFilterModel* mFilterModel;
328  QgsFeatureListModel* mFeatureListModel;
329  QgsAttributeForm* mAttributeForm;
330  QSignalMapper* mPreviewActionMapper;
331  QMenu* mPreviewColumnsMenu;
332  QMenu* mHorizontalHeaderMenu;
333  QgsVectorLayerCache* mLayerCache;
334  QProgressDialog* mProgressDlg;
335  QgsIFeatureSelectionManager* mFeatureSelectionManager;
336  QgsDistanceArea mDistanceArea;
337  QString mDisplayExpression;
338  QgsAttributeTableConfig mConfig;
339  QScrollArea* mAttributeEditorScrollArea;
340 
341  friend class TestQgsDualView;
342 };
343 
347 class GUI_EXPORT QgsAttributeTableAction : public QAction
348 {
349  Q_OBJECT
350 
351  public:
352  QgsAttributeTableAction( const QString &name, QgsDualView *dualView, int action, const QModelIndex &fieldIdx )
353  : QAction( name, dualView )
354  , mDualView( dualView )
355  , mAction( action )
356  , mFieldIdx( fieldIdx )
357  {}
358 
359  public slots:
360  void execute();
361  void featureForm();
362 
363  private:
364  QgsDualView* mDualView;
365  int mAction;
366  QModelIndex mFieldIdx;
367 };
368 
372 class GUI_EXPORT QgsAttributeTableMapLayerAction : public QAction
373 {
374  Q_OBJECT
375 
376  public:
377  QgsAttributeTableMapLayerAction( const QString &name, QgsDualView *dualView, QgsMapLayerAction* action, const QModelIndex &fieldIdx )
378  : QAction( name, dualView )
379  , mDualView( dualView )
380  , mAction( action )
381  , mFieldIdx( fieldIdx )
382  {}
383 
384  public slots:
385  void execute();
386 
387  private:
388  QgsDualView* mDualView;
389  QgsMapLayerAction* mAction;
390  QModelIndex mFieldIdx;
391 };
392 
394 
395 #endif // QGSDUALVIEW_H
Provides a table view of features of a QgsVectorLayer.
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:55
QgsAttributeTableAction(const QString &name, QgsDualView *dualView, int action, const QModelIndex &fieldIdx)
Definition: qgsdualview.h:352
QgsAttributeTableMapLayerAction(const QString &name, QgsDualView *dualView, QgsMapLayerAction *action, const QModelIndex &fieldIdx)
Definition: qgsdualview.h:377
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:149
This class caches features of a given QgsVectorLayer.
QgsAttributeTableModel * masterModel() const
Returns the model which has the information about all features (not only filtered) ...
Definition: qgsdualview.h:156
QgsAttributeTableFilterModel::FilterMode filterMode()
Get the filter mode.
Definition: qgsdualview.h:113
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