QGIS API Documentation  3.14.0-Pi (9f7028fd23)
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,
55  IdentifyMode
56  };
57  Q_ENUM( Mode )
58 
59 
63  {
66  Single
67  };
68 
69  enum FormMode
70  {
73  Popup
74  };
75 
77  QgsAttributeEditorContext() = default;
78 
80  : mParentContext( &parentContext )
81  , mVectorLayerTools( parentContext.mVectorLayerTools )
82  , mMapCanvas( parentContext.mMapCanvas )
83  , mMainMessageBar( parentContext.mMainMessageBar )
84  , mCadDockWidget( parentContext.mCadDockWidget )
85  , mDistanceArea( parentContext.mDistanceArea )
86  , mFormFeature( parentContext.mFormFeature )
87  , mFormMode( formMode )
88  {
89  Q_ASSERT( parentContext.vectorLayerTools() );
90  }
91 
92  QgsAttributeEditorContext( const QgsAttributeEditorContext &parentContext, const QgsRelation &relation, RelationMode relationMode, FormMode widgetMode )
93  : mParentContext( &parentContext )
94  , mVectorLayerTools( parentContext.mVectorLayerTools )
95  , mMapCanvas( parentContext.mMapCanvas )
96  , mMainMessageBar( parentContext.mMainMessageBar )
97  , mCadDockWidget( parentContext.mCadDockWidget )
98  , mDistanceArea( parentContext.mDistanceArea )
99  , mRelation( relation )
100  , mRelationMode( relationMode )
101  , mFormMode( widgetMode )
102  {
103  Q_ASSERT( parentContext.vectorLayerTools() );
104  }
105 
111  inline void setDistanceArea( const QgsDistanceArea &distanceArea )
112  {
113  if ( mLayer )
114  {
115  mDistanceArea = distanceArea;
116  mDistanceArea.setSourceCrs( mLayer->crs(), QgsProject::instance()->transformContext() );
117  }
118  }
119 
125  inline const QgsDistanceArea &distanceArea() const { return mDistanceArea; }
126 
132  inline void setMapCanvas( QgsMapCanvas *mapCanvas ) { mMapCanvas = mapCanvas; }
133 
139  inline QgsMapCanvas *mapCanvas() const { return mMapCanvas; }
140 
147  void setCadDockWidget( QgsAdvancedDigitizingDockWidget *cadDockWidget );
148 
155  QgsAdvancedDigitizingDockWidget *cadDockWidget() const { return mCadDockWidget; }
156 
163  inline void setVectorLayerTools( QgsVectorLayerTools *vlTools ) { mVectorLayerTools = vlTools; }
164  // TODO QGIS 4.0 - rename vlTools to tools
165 
171  inline const QgsVectorLayerTools *vectorLayerTools() const { return mVectorLayerTools; }
172 
181  inline void setRelation( const QgsRelation &relation, RelationMode mode ) { mRelation = relation; mRelationMode = mode; }
182 
189  inline const QgsRelation &relation() const { return mRelation; }
190 
197  inline RelationMode relationMode() const { return mRelationMode; }
198 
203  inline FormMode formMode() const { return mFormMode; }
204 
211  inline void setFormMode( FormMode mode ) { mFormMode = mode; }
212 
218  bool allowCustomUi() const { return mAllowCustomUi; }
219 
227  void setAllowCustomUi( bool allow ) { mAllowCustomUi = allow; }
228 
229  inline const QgsAttributeEditorContext *parentContext() const { return mParentContext; }
230 
236  QgsFeature formFeature() const { return mFormFeature; }
237 
243  void setFormFeature( const QgsFeature &feature ) { mFormFeature = feature ; }
244 
250  QgsFeature parentFormFeature() const { return mParentFormFeature; }
251 
257  void setParentFormFeature( const QgsFeature &feature ) { mParentFormFeature = feature ; }
258 
263  Mode attributeFormMode() const { return mAttributeFormMode; }
264 
269  void setAttributeFormMode( const Mode &attributeFormMode ) { mAttributeFormMode = attributeFormMode; }
270 
275  QString attributeFormModeString() const
276  {
277  const QMetaEnum metaEnum( QMetaEnum::fromType<Mode>() );
278  return metaEnum.valueToKey( static_cast<int>( mAttributeFormMode ) );
279  }
280 
285  void setMainMessageBar( QgsMessageBar *messageBar ) { mMainMessageBar = messageBar; }
286 
291  QgsMessageBar *mainMessageBar() { return mMainMessageBar; }
292 
293  private:
294  const QgsAttributeEditorContext *mParentContext = nullptr;
295  QgsVectorLayer *mLayer = nullptr;
296  QgsVectorLayerTools *mVectorLayerTools = nullptr;
297  QgsMapCanvas *mMapCanvas = nullptr;
298  QgsMessageBar *mMainMessageBar = nullptr;
299  QgsAdvancedDigitizingDockWidget *mCadDockWidget = nullptr;
300  QgsDistanceArea mDistanceArea;
301  QgsRelation mRelation;
302  RelationMode mRelationMode = Undefined;
304  QgsFeature mFormFeature;
306  QgsFeature mParentFormFeature;
307  FormMode mFormMode = Embed;
308  bool mAllowCustomUi = true;
309  Mode mAttributeFormMode = SingleEditMode;
310 };
311 
312 #endif // QGSATTRIBUTEEDITORCONTEXT_H
QgsAttributeEditorContext::mapCanvas
QgsMapCanvas * mapCanvas() const
Returns the associated map canvas (e.g.
Definition: qgsattributeeditorcontext.h:139
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:257
QgsAttributeEditorContext::allowCustomUi
bool allowCustomUi() const
Returns true if the attribute editor should permit use of custom UI forms.
Definition: qgsattributeeditorcontext.h:218
QgsAttributeEditorContext::setFormMode
void setFormMode(FormMode mode)
Sets the form mode.
Definition: qgsattributeeditorcontext.h:211
QgsAttributeEditorContext::cadDockWidget
QgsAdvancedDigitizingDockWidget * cadDockWidget() const
Returns the associated CAD dock widget (e.g.
Definition: qgsattributeeditorcontext.h:155
QgsAttributeEditorContext::setMainMessageBar
void setMainMessageBar(QgsMessageBar *messageBar)
Set current messageBar as the main message bar.
Definition: qgsattributeeditorcontext.h:285
QgsAttributeEditorContext::Undefined
@ Undefined
This context is not defined by a relation.
Definition: qgsattributeeditorcontext.h:64
QgsMapCanvas
Definition: qgsmapcanvas.h:83
QgsAttributeEditorContext::relationMode
RelationMode relationMode() const
Returns the attribute relation mode.
Definition: qgsattributeeditorcontext.h:197
QgsProject::transformContext
QgsCoordinateTransformContext transformContext
Definition: qgsproject.h:99
QgsVectorLayerTools
Definition: qgsvectorlayertools.h:39
QgsProject::instance
static QgsProject * instance()
Returns the QgsProject singleton instance.
Definition: qgsproject.cpp:458
QgsAttributeEditorContext::QgsAttributeEditorContext
QgsAttributeEditorContext(const QgsAttributeEditorContext &parentContext, FormMode formMode)
Definition: qgsattributeeditorcontext.h:79
QgsAttributeEditorContext::SearchMode
@ SearchMode
Form values are used for searching/filtering the layer.
Definition: qgsattributeeditorcontext.h:53
QgsAttributeEditorContext::Embed
@ Embed
A form was embedded as a widget on another form.
Definition: qgsattributeeditorcontext.h:71
QgsAttributeEditorContext::QgsAttributeEditorContext
QgsAttributeEditorContext(const QgsAttributeEditorContext &parentContext, const QgsRelation &relation, RelationMode relationMode, FormMode widgetMode)
Definition: qgsattributeeditorcontext.h:92
QgsAttributeEditorContext::FormMode
FormMode
Definition: qgsattributeeditorcontext.h:69
QgsAttributeEditorContext::relation
const QgsRelation & relation() const
Returns the attribute relation.
Definition: qgsattributeeditorcontext.h:189
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:236
QgsAttributeEditorContext::attributeFormMode
Mode attributeFormMode() const
Returns current attributeFormMode.
Definition: qgsattributeeditorcontext.h:263
QgsAttributeEditorContext::StandaloneDialog
@ StandaloneDialog
A form was opened as a new dialog.
Definition: qgsattributeeditorcontext.h:72
QgsAttributeEditorContext::MultiEditMode
@ MultiEditMode
Multi edit mode, for editing fields of multiple features at once.
Definition: qgsattributeeditorcontext.h:52
QgsMessageBar
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:250
QgsAttributeEditorContext::setVectorLayerTools
void setVectorLayerTools(QgsVectorLayerTools *vlTools)
Sets the associated vector layer tools.
Definition: qgsattributeeditorcontext.h:163
QgsDistanceArea::setSourceCrs
void setSourceCrs(const QgsCoordinateReferenceSystem &crs, const QgsCoordinateTransformContext &context)
Sets source spatial reference system crs.
Definition: qgsdistancearea.cpp:60
QgsAttributeEditorContext::setDistanceArea
void setDistanceArea(const QgsDistanceArea &distanceArea)
Sets distance area object, distanceArea, for area/length calculations.
Definition: qgsattributeeditorcontext.h:111
QgsAttributeEditorContext::formMode
FormMode formMode() const
Returns the form mode.
Definition: qgsattributeeditorcontext.h:203
QgsAdvancedDigitizingDockWidget
The QgsAdvancedDigitizingDockWidget class is a dockable widget used to handle the CAD tools on top of...
Definition: qgsadvanceddigitizingdockwidget.h:48
qgsvectorlayer.h
QgsVectorLayer
Definition: qgsvectorlayer.h:385
QgsAttributeEditorContext::distanceArea
const QgsDistanceArea & distanceArea() const
Returns the distance area object used for area/length calculations.
Definition: qgsattributeeditorcontext.h:125
QgsAttributeEditorContext::RelationMode
RelationMode
Determines in which direction a relation was resolved.
Definition: qgsattributeeditorcontext.h:62
QgsRelation
Definition: qgsrelation.h:41
QgsDistanceArea
Definition: qgsdistancearea.h:49
qgsdistancearea.h
QgsFeature
Definition: qgsfeature.h:55
QgsAttributeEditorContext::AggregateSearchMode
@ AggregateSearchMode
Form is in aggregate search mode, show each widget in this mode.
Definition: qgsattributeeditorcontext.h:54
QgsAttributeEditorContext::setRelation
void setRelation(const QgsRelation &relation, RelationMode mode)
Set attribute relation and mode.
Definition: qgsattributeeditorcontext.h:181
QgsAttributeEditorContext::parentContext
const QgsAttributeEditorContext * parentContext() const
Definition: qgsattributeeditorcontext.h:229
QgsAttributeEditorContext
Definition: qgsattributeeditorcontext.h:40
QgsAttributeEditorContext::setMapCanvas
void setMapCanvas(QgsMapCanvas *mapCanvas)
Sets the associated map canvas, mapCanvas, (e.g.
Definition: qgsattributeeditorcontext.h:132
QgsAttributeEditorContext::mainMessageBar
QgsMessageBar * mainMessageBar()
Returns the main message bar.
Definition: qgsattributeeditorcontext.h:291
QgsAttributeEditorContext::Multiple
@ Multiple
When showing a list of features (e.g. houses as an embedded form in a district form)
Definition: qgsattributeeditorcontext.h:65
QgsAttributeEditorContext::setAttributeFormMode
void setAttributeFormMode(const Mode &attributeFormMode)
Set attributeFormMode for the edited form.
Definition: qgsattributeeditorcontext.h:269
qgsproject.h
QgsAttributeEditorContext::vectorLayerTools
const QgsVectorLayerTools * vectorLayerTools() const
Returns the associated vector layer tools.
Definition: qgsattributeeditorcontext.h:171
QgsAttributeEditorContext::setAllowCustomUi
void setAllowCustomUi(bool allow)
Sets whether the attribute editor should permit use of custom UI forms.
Definition: qgsattributeeditorcontext.h:227
QgsAttributeEditorContext::attributeFormModeString
QString attributeFormModeString() const
Returns given attributeFormMode as string.
Definition: qgsattributeeditorcontext.h:275
QgsAttributeEditorContext::setFormFeature
void setFormFeature(const QgsFeature &feature)
Set current feature for the currently edited form or table row.
Definition: qgsattributeeditorcontext.h:243