QGIS API Documentation  3.10.0-A Coruña (6c816b4204)
qgsattributeeditorcontext.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsattributeeditorcontext.h
3  --------------------------------------
4  Date : 30.7.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 QGSATTRIBUTEEDITORCONTEXT_H
17 #define QGSATTRIBUTEEDITORCONTEXT_H
18 
19 #include <QMap>
20 #include <QWidget>
21 #include <QMetaEnum>
22 
23 #include "qgsdistancearea.h"
24 #include "qgsvectorlayertools.h"
25 #include "qgsvectorlayer.h"
26 #include "qgis_gui.h"
27 #include "qgsproject.h"
28 
29 class QgsMapCanvas;
31 
39 class GUI_EXPORT QgsAttributeEditorContext
40 {
41  Q_GADGET
42 
43  public:
44 
46  enum Mode
47  {
49  AddFeatureMode,
54  IdentifyMode
55  };
56  Q_ENUM( Mode )
57 
58 
62  {
65  Single
66  };
67 
68  enum FormMode
69  {
72  Popup
73  };
74 
76  QgsAttributeEditorContext() = default;
77 
79  : mParentContext( &parentContext )
80  , mVectorLayerTools( parentContext.mVectorLayerTools )
81  , mMapCanvas( parentContext.mMapCanvas )
82  , mDistanceArea( parentContext.mDistanceArea )
83  , mFormFeature( parentContext.mFormFeature )
84  , mFormMode( formMode )
85  {
86  Q_ASSERT( parentContext.vectorLayerTools() );
87  }
88 
89  QgsAttributeEditorContext( const QgsAttributeEditorContext &parentContext, const QgsRelation &relation, RelationMode relationMode, FormMode widgetMode )
90  : mParentContext( &parentContext )
91  , mVectorLayerTools( parentContext.mVectorLayerTools )
92  , mMapCanvas( parentContext.mMapCanvas )
93  , mDistanceArea( parentContext.mDistanceArea )
94  , mRelation( relation )
95  , mRelationMode( relationMode )
96  , mFormMode( widgetMode )
97  {
98  Q_ASSERT( parentContext.vectorLayerTools() );
99  }
100 
106  inline void setDistanceArea( const QgsDistanceArea &distanceArea )
107  {
108  if ( mLayer )
109  {
110  mDistanceArea = distanceArea;
111  mDistanceArea.setSourceCrs( mLayer->crs(), QgsProject::instance()->transformContext() );
112  }
113  }
114 
120  inline const QgsDistanceArea &distanceArea() const { return mDistanceArea; }
121 
127  inline void setMapCanvas( QgsMapCanvas *mapCanvas ) { mMapCanvas = mapCanvas; }
128 
134  inline QgsMapCanvas *mapCanvas() const { return mMapCanvas; }
135 
142  void setCadDockWidget( QgsAdvancedDigitizingDockWidget *cadDockWidget );
143 
150  QgsAdvancedDigitizingDockWidget *cadDockWidget() const { return mCadDockWidget; }
151 
158  inline void setVectorLayerTools( QgsVectorLayerTools *vlTools ) { mVectorLayerTools = vlTools; }
159  // TODO QGIS 4.0 - rename vlTools to tools
160 
166  inline const QgsVectorLayerTools *vectorLayerTools() const { return mVectorLayerTools; }
167 
176  inline void setRelation( const QgsRelation &relation, RelationMode mode ) { mRelation = relation; mRelationMode = mode; }
177 
184  inline const QgsRelation &relation() const { return mRelation; }
185 
192  inline RelationMode relationMode() const { return mRelationMode; }
193 
198  inline FormMode formMode() const { return mFormMode; }
199 
206  inline void setFormMode( FormMode mode ) { mFormMode = mode; }
207 
213  bool allowCustomUi() const { return mAllowCustomUi; }
214 
222  void setAllowCustomUi( bool allow ) { mAllowCustomUi = allow; }
223 
224  inline const QgsAttributeEditorContext *parentContext() const { return mParentContext; }
225 
231  QgsFeature formFeature() const { return mFormFeature; }
232 
238  void setFormFeature( const QgsFeature &feature ) { mFormFeature = feature ; }
239 
244  Mode attributeFormMode() const { return mAttributeFormMode; }
245 
250  void setAttributeFormMode( const Mode &attributeFormMode ) { mAttributeFormMode = attributeFormMode; }
251 
256  QString attributeFormModeString() const
257  {
258  const QMetaEnum metaEnum( QMetaEnum::fromType<Mode>() );
259  return metaEnum.valueToKey( static_cast<int>( mAttributeFormMode ) );
260  }
261 
262  private:
263  const QgsAttributeEditorContext *mParentContext = nullptr;
264  QgsVectorLayer *mLayer = nullptr;
265  QgsVectorLayerTools *mVectorLayerTools = nullptr;
266  QgsMapCanvas *mMapCanvas = nullptr;
267  QgsAdvancedDigitizingDockWidget *mCadDockWidget = nullptr;
268  QgsDistanceArea mDistanceArea;
269  QgsRelation mRelation;
270  RelationMode mRelationMode = Undefined;
272  QgsFeature mFormFeature;
273  FormMode mFormMode = Embed;
274  bool mAllowCustomUi = true;
275  Mode mAttributeFormMode = SingleEditMode;
276 };
277 
278 #endif // QGSATTRIBUTEEDITORCONTEXT_H
Methods in this class are used to handle basic operations on vector layers.
const QgsVectorLayerTools * vectorLayerTools() const
Returns the associated vector layer tools.
void setAttributeFormMode(const Mode &attributeFormMode)
Set attributeFormMode for the edited form.
Form is in aggregate search mode, show each widget in this mode.
This class contains context information for attribute editor widgets.
QgsAttributeEditorContext(const QgsAttributeEditorContext &parentContext, FormMode formMode)
void setMapCanvas(QgsMapCanvas *mapCanvas)
Sets the associated map canvas, mapCanvas, (e.g.
When showing a list of features (e.g. houses as an embedded form in a district form) ...
QgsAttributeEditorContext(const QgsAttributeEditorContext &parentContext, const QgsRelation &relation, RelationMode relationMode, FormMode widgetMode)
void setVectorLayerTools(QgsVectorLayerTools *vlTools)
Sets the associated vector layer tools.
Multi edit mode, for editing fields of multiple features at once.
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:55
void setAllowCustomUi(bool allow)
Sets whether the attribute editor should permit use of custom UI forms.
Map canvas is a class for displaying all GIS data types on a canvas.
Definition: qgsmapcanvas.h:75
void setFormFeature(const QgsFeature &feature)
Set current feature for the currently edited form or table row.
This context is not defined by a relation.
RelationMode
Determines in which direction a relation was resolved.
const QgsRelation & relation() const
Returns the attribute relation.
void setDistanceArea(const QgsDistanceArea &distanceArea)
Sets distance area object, distanceArea, for area/length calculations.
QgsFeature formFeature() const
Returns current feature from the currently edited form or table row.
QgsAdvancedDigitizingDockWidget * cadDockWidget() const
Returns the associated CAD dock widget (e.g.
Mode attributeFormMode() const
Returns current attributeFormMode.
const QgsAttributeEditorContext * parentContext() const
FormMode formMode() const
Returns the form mode.
QgsCoordinateTransformContext transformContext
Definition: qgsproject.h:96
A general purpose distance and area calculator, capable of performing ellipsoid based calculations...
void setFormMode(FormMode mode)
Sets the form mode.
bool allowCustomUi() const
Returns true if the attribute editor should permit use of custom UI forms.
Single edit mode, for editing a single feature.
static QgsProject * instance()
Returns the QgsProject singleton instance.
Definition: qgsproject.cpp:442
QString attributeFormModeString() const
Returns given attributeFormMode as string.
const QgsDistanceArea & distanceArea() const
Returns the distance area object used for area/length calculations.
void setSourceCrs(const QgsCoordinateReferenceSystem &crs, const QgsCoordinateTransformContext &context)
Sets source spatial reference system crs.
RelationMode relationMode() const
Returns the attribute relation mode.
Form values are used for searching/filtering the layer.
The QgsAdvancedDigitizingDockWidget class is a dockable widget used to handle the CAD tools on top of...
Represents a vector layer which manages a vector based data sets.
void setRelation(const QgsRelation &relation, RelationMode mode)
Set attribute relation and mode.
QgsMapCanvas * mapCanvas() const
Returns the associated map canvas (e.g.
A form was embedded as a widget on another form.