QGIS API Documentation  3.2.0-Bonn (bc43194)
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 
22 #include "qgsdistancearea.h"
23 #include "qgsvectorlayer.h"
24 #include "qgsvectorlayertools.h"
25 #include "qgis_gui.h"
26 #include "qgsproject.h"
27 
28 class QgsMapCanvas;
29 
37 class GUI_EXPORT QgsAttributeEditorContext
38 {
39  public:
40 
45  {
48  Single
49  };
50 
51  enum FormMode
52  {
55  Popup
56  };
57 
59  QgsAttributeEditorContext() = default;
60 
62  : mParentContext( &parentContext )
63  , mVectorLayerTools( parentContext.mVectorLayerTools )
64  , mMapCanvas( parentContext.mMapCanvas )
65  , mDistanceArea( parentContext.mDistanceArea )
66  , mFormFeature( parentContext.mFormFeature )
67  , mFormMode( formMode )
68  {
69  Q_ASSERT( parentContext.vectorLayerTools() );
70  }
71 
72  QgsAttributeEditorContext( const QgsAttributeEditorContext &parentContext, const QgsRelation &relation, RelationMode relationMode, FormMode widgetMode )
73  : mParentContext( &parentContext )
74  , mVectorLayerTools( parentContext.mVectorLayerTools )
75  , mMapCanvas( parentContext.mMapCanvas )
76  , mDistanceArea( parentContext.mDistanceArea )
77  , mRelation( relation )
78  , mRelationMode( relationMode )
79  , mFormMode( widgetMode )
80  {
81  Q_ASSERT( parentContext.vectorLayerTools() );
82  }
83 
89  inline void setDistanceArea( const QgsDistanceArea &distanceArea )
90  {
91  if ( mLayer )
92  {
93  mDistanceArea = distanceArea;
94  mDistanceArea.setSourceCrs( mLayer->crs(), QgsProject::instance()->transformContext() );
95  }
96  }
97 
103  inline const QgsDistanceArea &distanceArea() const { return mDistanceArea; }
104 
110  inline void setMapCanvas( QgsMapCanvas *mapCanvas ) { mMapCanvas = mapCanvas; }
111 
117  inline QgsMapCanvas *mapCanvas() const { return mMapCanvas; }
118 
125  inline void setVectorLayerTools( QgsVectorLayerTools *vlTools ) { mVectorLayerTools = vlTools; }
126  // TODO QGIS 4.0 - rename vlTools to tools
127 
133  inline const QgsVectorLayerTools *vectorLayerTools() const { return mVectorLayerTools; }
134 
143  inline void setRelation( const QgsRelation &relation, RelationMode mode ) { mRelation = relation; mRelationMode = mode; }
144 
151  inline const QgsRelation &relation() const { return mRelation; }
152 
159  inline RelationMode relationMode() const { return mRelationMode; }
160 
165  inline FormMode formMode() const { return mFormMode; }
166 
173  inline void setFormMode( FormMode mode ) { mFormMode = mode; }
174 
180  bool allowCustomUi() const { return mAllowCustomUi; }
181 
189  void setAllowCustomUi( bool allow ) { mAllowCustomUi = allow; }
190 
191  inline const QgsAttributeEditorContext *parentContext() const { return mParentContext; }
192 
198  QgsFeature formFeature() const { return mFormFeature; }
199 
205  void setFormFeature( const QgsFeature &feature ) { mFormFeature = feature ; }
206 
207 
208  private:
209  const QgsAttributeEditorContext *mParentContext = nullptr;
210  QgsVectorLayer *mLayer = nullptr;
211  QgsVectorLayerTools *mVectorLayerTools = nullptr;
212  QgsMapCanvas *mMapCanvas = nullptr;
213  QgsDistanceArea mDistanceArea;
214  QgsRelation mRelation;
215  RelationMode mRelationMode = Undefined;
217  QgsFeature mFormFeature;
218  FormMode mFormMode = Embed;
219  bool mAllowCustomUi = true;
220 };
221 
222 #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.
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.
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:62
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:74
void setFormFeature(const QgsFeature &feature)
Set current feature for the currently edited form or table row.
QgsCoordinateTransformContext transformContext() const
Returns a copy of the project&#39;s coordinate transform context, which stores various information regard...
Definition: qgsproject.cpp:543
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.
const QgsAttributeEditorContext * parentContext() const
FormMode formMode() const
Returns the form mode.
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.
static QgsProject * instance()
Returns the QgsProject singleton instance.
Definition: qgsproject.cpp:391
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.
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.