QGIS API Documentation  3.6.0-Noosa (5873452)
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;
30 
38 class GUI_EXPORT QgsAttributeEditorContext
39 {
40  Q_GADGET
41 
42  public:
43 
45  enum Mode
46  {
48  AddFeatureMode,
53  IdentifyMode
54  };
55  Q_ENUM( Mode )
56 
57 
61  {
64  Single
65  };
66 
67  enum FormMode
68  {
71  Popup
72  };
73 
75  QgsAttributeEditorContext() = default;
76 
78  : mParentContext( &parentContext )
79  , mVectorLayerTools( parentContext.mVectorLayerTools )
80  , mMapCanvas( parentContext.mMapCanvas )
81  , mDistanceArea( parentContext.mDistanceArea )
82  , mFormFeature( parentContext.mFormFeature )
83  , mFormMode( formMode )
84  {
85  Q_ASSERT( parentContext.vectorLayerTools() );
86  }
87 
88  QgsAttributeEditorContext( const QgsAttributeEditorContext &parentContext, const QgsRelation &relation, RelationMode relationMode, FormMode widgetMode )
89  : mParentContext( &parentContext )
90  , mVectorLayerTools( parentContext.mVectorLayerTools )
91  , mMapCanvas( parentContext.mMapCanvas )
92  , mDistanceArea( parentContext.mDistanceArea )
93  , mRelation( relation )
94  , mRelationMode( relationMode )
95  , mFormMode( widgetMode )
96  {
97  Q_ASSERT( parentContext.vectorLayerTools() );
98  }
99 
105  inline void setDistanceArea( const QgsDistanceArea &distanceArea )
106  {
107  if ( mLayer )
108  {
109  mDistanceArea = distanceArea;
110  mDistanceArea.setSourceCrs( mLayer->crs(), QgsProject::instance()->transformContext() );
111  }
112  }
113 
119  inline const QgsDistanceArea &distanceArea() const { return mDistanceArea; }
120 
126  inline void setMapCanvas( QgsMapCanvas *mapCanvas ) { mMapCanvas = mapCanvas; }
127 
133  inline QgsMapCanvas *mapCanvas() const { return mMapCanvas; }
134 
141  inline void setVectorLayerTools( QgsVectorLayerTools *vlTools ) { mVectorLayerTools = vlTools; }
142  // TODO QGIS 4.0 - rename vlTools to tools
143 
149  inline const QgsVectorLayerTools *vectorLayerTools() const { return mVectorLayerTools; }
150 
159  inline void setRelation( const QgsRelation &relation, RelationMode mode ) { mRelation = relation; mRelationMode = mode; }
160 
167  inline const QgsRelation &relation() const { return mRelation; }
168 
175  inline RelationMode relationMode() const { return mRelationMode; }
176 
181  inline FormMode formMode() const { return mFormMode; }
182 
189  inline void setFormMode( FormMode mode ) { mFormMode = mode; }
190 
196  bool allowCustomUi() const { return mAllowCustomUi; }
197 
205  void setAllowCustomUi( bool allow ) { mAllowCustomUi = allow; }
206 
207  inline const QgsAttributeEditorContext *parentContext() const { return mParentContext; }
208 
214  QgsFeature formFeature() const { return mFormFeature; }
215 
221  void setFormFeature( const QgsFeature &feature ) { mFormFeature = feature ; }
222 
227  Mode attributeFormMode() const { return mAttributeFormMode; }
228 
233  void setAttributeFormMode( const Mode &attributeFormMode ) { mAttributeFormMode = attributeFormMode; }
234 
239  QString attributeFormModeString() const
240  {
241  const QMetaEnum metaEnum( QMetaEnum::fromType<Mode>() );
242  return metaEnum.valueToKey( static_cast<int>( mAttributeFormMode ) );
243  }
244 
245  private:
246  const QgsAttributeEditorContext *mParentContext = nullptr;
247  QgsVectorLayer *mLayer = nullptr;
248  QgsVectorLayerTools *mVectorLayerTools = nullptr;
249  QgsMapCanvas *mMapCanvas = nullptr;
250  QgsDistanceArea mDistanceArea;
251  QgsRelation mRelation;
252  RelationMode mRelationMode = Undefined;
254  QgsFeature mFormFeature;
255  FormMode mFormMode = Embed;
256  bool mAllowCustomUi = true;
257  Mode mAttributeFormMode = SingleEditMode;
258 };
259 
260 #endif // QGSATTRIBUTEEDITORCONTEXT_H
261 
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:73
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.
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:430
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.
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.