QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
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 class QgsMessageBar;
32 
40 class GUI_EXPORT QgsAttributeEditorContext
41 {
42  Q_GADGET
43 
44  public:
45 
47  enum Mode
48  {
50  AddFeatureMode,
56  IdentifyMode
57  };
58  Q_ENUM( Mode )
59 
60 
64  {
67  Single
68  };
69 
70  enum FormMode
71  {
74  Popup
75  };
76 
78  QgsAttributeEditorContext() = default;
79 
81  : mParentContext( &parentContext )
82  , mVectorLayerTools( parentContext.mVectorLayerTools )
83  , mMapCanvas( parentContext.mMapCanvas )
84  , mMainMessageBar( parentContext.mMainMessageBar )
85  , mCadDockWidget( parentContext.mCadDockWidget )
86  , mDistanceArea( parentContext.mDistanceArea )
87  , mFormFeature( parentContext.mFormFeature )
88  , mFormMode( formMode )
89  {
90  Q_ASSERT( parentContext.vectorLayerTools() );
91  }
92 
93  QgsAttributeEditorContext( const QgsAttributeEditorContext &parentContext, const QgsRelation &relation, RelationMode relationMode, FormMode widgetMode )
94  : mParentContext( &parentContext )
95  , mVectorLayerTools( parentContext.mVectorLayerTools )
96  , mMapCanvas( parentContext.mMapCanvas )
97  , mMainMessageBar( parentContext.mMainMessageBar )
98  , mCadDockWidget( parentContext.mCadDockWidget )
99  , mDistanceArea( parentContext.mDistanceArea )
100  , mRelation( relation )
101  , mRelationMode( relationMode )
102  , mFormMode( widgetMode )
103  {
104  Q_ASSERT( parentContext.vectorLayerTools() );
105  }
106 
112  inline void setDistanceArea( const QgsDistanceArea &distanceArea )
113  {
114  if ( mLayer )
115  {
116  mDistanceArea = distanceArea;
117  mDistanceArea.setSourceCrs( mLayer->crs(), QgsProject::instance()->transformContext() );
118  }
119  }
120 
126  inline const QgsDistanceArea &distanceArea() const { return mDistanceArea; }
127 
133  inline void setMapCanvas( QgsMapCanvas *mapCanvas ) { mMapCanvas = mapCanvas; }
134 
140  inline QgsMapCanvas *mapCanvas() const { return mMapCanvas; }
141 
148  void setCadDockWidget( QgsAdvancedDigitizingDockWidget *cadDockWidget );
149 
156  QgsAdvancedDigitizingDockWidget *cadDockWidget() const { return mCadDockWidget; }
157 
164  inline void setVectorLayerTools( QgsVectorLayerTools *vlTools ) { mVectorLayerTools = vlTools; }
165  // TODO QGIS 4.0 - rename vlTools to tools
166 
172  inline const QgsVectorLayerTools *vectorLayerTools() const { return mVectorLayerTools; }
173 
182  inline void setRelation( const QgsRelation &relation, RelationMode mode ) { mRelation = relation; mRelationMode = mode; }
183 
190  inline const QgsRelation &relation() const { return mRelation; }
191 
198  inline RelationMode relationMode() const { return mRelationMode; }
199 
204  inline FormMode formMode() const { return mFormMode; }
205 
212  inline void setFormMode( FormMode mode ) { mFormMode = mode; }
213 
219  bool allowCustomUi() const { return mAllowCustomUi; }
220 
228  void setAllowCustomUi( bool allow ) { mAllowCustomUi = allow; }
229 
230  inline const QgsAttributeEditorContext *parentContext() const { return mParentContext; }
231 
237  QgsFeature formFeature() const { return mFormFeature; }
238 
244  void setFormFeature( const QgsFeature &feature ) { mFormFeature = feature ; }
245 
251  QgsFeature parentFormFeature() const { return mParentFormFeature; }
252 
258  void setParentFormFeature( const QgsFeature &feature ) { mParentFormFeature = feature ; }
259 
264  Mode attributeFormMode() const { return mAttributeFormMode; }
265 
270  void setAttributeFormMode( const Mode &attributeFormMode ) { mAttributeFormMode = attributeFormMode; }
271 
276  QString attributeFormModeString() const
277  {
278  const QMetaEnum metaEnum( QMetaEnum::fromType<Mode>() );
279  return metaEnum.valueToKey( static_cast<int>( mAttributeFormMode ) );
280  }
281 
286  void setMainMessageBar( QgsMessageBar *messageBar ) { mMainMessageBar = messageBar; }
287 
292  QgsMessageBar *mainMessageBar() { return mMainMessageBar; }
293 
294  private:
295  const QgsAttributeEditorContext *mParentContext = nullptr;
296  QgsVectorLayer *mLayer = nullptr;
297  QgsVectorLayerTools *mVectorLayerTools = nullptr;
298  QgsMapCanvas *mMapCanvas = nullptr;
299  QgsMessageBar *mMainMessageBar = nullptr;
300  QgsAdvancedDigitizingDockWidget *mCadDockWidget = nullptr;
301  QgsDistanceArea mDistanceArea;
302  QgsRelation mRelation;
303  RelationMode mRelationMode = Undefined;
305  QgsFeature mFormFeature;
307  QgsFeature mParentFormFeature;
308  FormMode mFormMode = Embed;
309  bool mAllowCustomUi = true;
310  Mode mAttributeFormMode = SingleEditMode;
311 };
312 
313 #endif // QGSATTRIBUTEEDITORCONTEXT_H
QgsAttributeEditorContext::mapCanvas
QgsMapCanvas * mapCanvas() const
Returns the associated map canvas (e.g.
Definition: qgsattributeeditorcontext.h:140
QgsAttributeEditorContext::SingleEditMode
@ SingleEditMode
Single edit mode, for editing a single feature.
Definition: qgsattributeeditorcontext.h:49
QgsAttributeEditorContext::setParentFormFeature
void setParentFormFeature(const QgsFeature &feature)
Sets the feature of the currently edited parent form.
Definition: qgsattributeeditorcontext.h:258
QgsAttributeEditorContext::allowCustomUi
bool allowCustomUi() const
Returns true if the attribute editor should permit use of custom UI forms.
Definition: qgsattributeeditorcontext.h:219
QgsAttributeEditorContext::setFormMode
void setFormMode(FormMode mode)
Sets the form mode.
Definition: qgsattributeeditorcontext.h:212
QgsAttributeEditorContext::cadDockWidget
QgsAdvancedDigitizingDockWidget * cadDockWidget() const
Returns the associated CAD dock widget (e.g.
Definition: qgsattributeeditorcontext.h:156
QgsAttributeEditorContext::setMainMessageBar
void setMainMessageBar(QgsMessageBar *messageBar)
Set current messageBar as the main message bar.
Definition: qgsattributeeditorcontext.h:286
QgsAttributeEditorContext::Undefined
@ Undefined
This context is not defined by a relation.
Definition: qgsattributeeditorcontext.h:65
QgsMapCanvas
Map canvas is a class for displaying all GIS data types on a canvas.
Definition: qgsmapcanvas.h:89
QgsAttributeEditorContext::relationMode
RelationMode relationMode() const
Returns the attribute relation mode.
Definition: qgsattributeeditorcontext.h:198
QgsProject::transformContext
QgsCoordinateTransformContext transformContext
Definition: qgsproject.h:110
QgsVectorLayerTools
Methods in this class are used to handle basic operations on vector layers. With an implementation of...
Definition: qgsvectorlayertools.h:39
QgsProject::instance
static QgsProject * instance()
Returns the QgsProject singleton instance.
Definition: qgsproject.cpp:480
QgsAttributeEditorContext::QgsAttributeEditorContext
QgsAttributeEditorContext(const QgsAttributeEditorContext &parentContext, FormMode formMode)
Definition: qgsattributeeditorcontext.h:80
QgsAttributeEditorContext::SearchMode
@ SearchMode
Form values are used for searching/filtering the layer.
Definition: qgsattributeeditorcontext.h:54
QgsAttributeEditorContext::Embed
@ Embed
A form was embedded as a widget on another form.
Definition: qgsattributeeditorcontext.h:72
QgsAttributeEditorContext::QgsAttributeEditorContext
QgsAttributeEditorContext(const QgsAttributeEditorContext &parentContext, const QgsRelation &relation, RelationMode relationMode, FormMode widgetMode)
Definition: qgsattributeeditorcontext.h:93
QgsAttributeEditorContext::FormMode
FormMode
Definition: qgsattributeeditorcontext.h:70
QgsAttributeEditorContext::relation
const QgsRelation & relation() const
Returns the attribute relation.
Definition: qgsattributeeditorcontext.h:190
QgsAttributeEditorContext::Mode
Mode
modes
Definition: qgsattributeeditorcontext.h:47
qgsvectorlayertools.h
QgsAttributeEditorContext::formFeature
QgsFeature formFeature() const
Returns current feature from the currently edited form or table row.
Definition: qgsattributeeditorcontext.h:237
QgsAttributeEditorContext::attributeFormMode
Mode attributeFormMode() const
Returns current attributeFormMode.
Definition: qgsattributeeditorcontext.h:264
QgsAttributeEditorContext::StandaloneDialog
@ StandaloneDialog
A form was opened as a new dialog.
Definition: qgsattributeeditorcontext.h:73
QgsAttributeEditorContext::MultiEditMode
@ MultiEditMode
Multi edit mode, for editing fields of multiple features at once.
Definition: qgsattributeeditorcontext.h:53
QgsMessageBar
A bar for displaying non-blocking messages to the user.
Definition: qgsmessagebar.h:60
QgsAttributeEditorContext::parentFormFeature
QgsFeature parentFormFeature() const
Returns the feature of the currently edited parent form in its actual state.
Definition: qgsattributeeditorcontext.h:251
QgsAttributeEditorContext::setVectorLayerTools
void setVectorLayerTools(QgsVectorLayerTools *vlTools)
Sets the associated vector layer tools.
Definition: qgsattributeeditorcontext.h:164
QgsDistanceArea::setSourceCrs
void setSourceCrs(const QgsCoordinateReferenceSystem &crs, const QgsCoordinateTransformContext &context)
Sets source spatial reference system crs.
Definition: qgsdistancearea.cpp:83
QgsAttributeEditorContext::setDistanceArea
void setDistanceArea(const QgsDistanceArea &distanceArea)
Sets distance area object, distanceArea, for area/length calculations.
Definition: qgsattributeeditorcontext.h:112
QgsAttributeEditorContext::formMode
FormMode formMode() const
Returns the form mode.
Definition: qgsattributeeditorcontext.h:204
QgsAdvancedDigitizingDockWidget
The QgsAdvancedDigitizingDockWidget class is a dockable widget used to handle the CAD tools on top of...
Definition: qgsadvanceddigitizingdockwidget.h:50
qgsvectorlayer.h
QgsVectorLayer
Represents a vector layer which manages a vector based data sets.
Definition: qgsvectorlayer.h:391
QgsAttributeEditorContext::distanceArea
const QgsDistanceArea & distanceArea() const
Returns the distance area object used for area/length calculations.
Definition: qgsattributeeditorcontext.h:126
QgsAttributeEditorContext::RelationMode
RelationMode
Determines in which direction a relation was resolved.
Definition: qgsattributeeditorcontext.h:63
QgsRelation
Definition: qgsrelation.h:42
QgsDistanceArea
A general purpose distance and area calculator, capable of performing ellipsoid based calculations.
Definition: qgsdistancearea.h:52
qgsdistancearea.h
QgsFeature
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
Definition: qgsfeature.h:55
QgsAttributeEditorContext::AggregateSearchMode
@ AggregateSearchMode
Form is in aggregate search mode, show each widget in this mode.
Definition: qgsattributeeditorcontext.h:55
QgsAttributeEditorContext::setRelation
void setRelation(const QgsRelation &relation, RelationMode mode)
Set attribute relation and mode.
Definition: qgsattributeeditorcontext.h:182
QgsAttributeEditorContext::parentContext
const QgsAttributeEditorContext * parentContext() const
Definition: qgsattributeeditorcontext.h:230
QgsAttributeEditorContext::FixAttributeMode
@ FixAttributeMode
Fix feature mode, for modifying the feature attributes without saving. The updated feature is availab...
Definition: qgsattributeeditorcontext.h:52
QgsAttributeEditorContext
This class contains context information for attribute editor widgets. It will be passed to embedded w...
Definition: qgsattributeeditorcontext.h:40
QgsAttributeEditorContext::setMapCanvas
void setMapCanvas(QgsMapCanvas *mapCanvas)
Sets the associated map canvas, mapCanvas, (e.g.
Definition: qgsattributeeditorcontext.h:133
QgsAttributeEditorContext::mainMessageBar
QgsMessageBar * mainMessageBar()
Returns the main message bar.
Definition: qgsattributeeditorcontext.h:292
QgsAttributeEditorContext::Multiple
@ Multiple
When showing a list of features (e.g. houses as an embedded form in a district form)
Definition: qgsattributeeditorcontext.h:66
QgsAttributeEditorContext::setAttributeFormMode
void setAttributeFormMode(const Mode &attributeFormMode)
Set attributeFormMode for the edited form.
Definition: qgsattributeeditorcontext.h:270
qgsproject.h
QgsAttributeEditorContext::vectorLayerTools
const QgsVectorLayerTools * vectorLayerTools() const
Returns the associated vector layer tools.
Definition: qgsattributeeditorcontext.h:172
QgsAttributeEditorContext::setAllowCustomUi
void setAllowCustomUi(bool allow)
Sets whether the attribute editor should permit use of custom UI forms.
Definition: qgsattributeeditorcontext.h:228
QgsAttributeEditorContext::attributeFormModeString
QString attributeFormModeString() const
Returns given attributeFormMode as string.
Definition: qgsattributeeditorcontext.h:276
QgsAttributeEditorContext::setFormFeature
void setFormFeature(const QgsFeature &feature)
Set current feature for the currently edited form or table row.
Definition: qgsattributeeditorcontext.h:244