QGIS API Documentation 3.41.0-Master (cea29feecf2)
Loading...
Searching...
No Matches
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
29class QgsMapCanvas;
31class QgsMessageBar;
32
41{
42 Q_GADGET
43
44 public:
57 Q_ENUM( Mode )
58
59
63 {
66 Single
67 };
68
70 {
73 Popup
74 };
75
77
79 : mParentContext( &parentContext )
80 , mVectorLayerTools( parentContext.mVectorLayerTools )
81 , mMapCanvas( parentContext.mMapCanvas )
82 , mMainMessageBar( parentContext.mMainMessageBar )
83 , mCadDockWidget( parentContext.mCadDockWidget )
84 , mDistanceArea( parentContext.mDistanceArea )
85 , mFormFeature( parentContext.mFormFeature )
86 , mFormMode( formMode )
87 {
88 Q_ASSERT( parentContext.vectorLayerTools() );
89 }
90
91 QgsAttributeEditorContext( const QgsAttributeEditorContext &parentContext, const QgsRelation &relation, RelationMode relationMode, FormMode widgetMode )
92 : mParentContext( &parentContext )
93 , mVectorLayerTools( parentContext.mVectorLayerTools )
94 , mMapCanvas( parentContext.mMapCanvas )
95 , mMainMessageBar( parentContext.mMainMessageBar )
96 , mCadDockWidget( parentContext.mCadDockWidget )
97 , mDistanceArea( parentContext.mDistanceArea )
98 , mRelation( relation )
99 , mRelationMode( relationMode )
100 , mFormMode( widgetMode )
101 {
102 Q_ASSERT( parentContext.vectorLayerTools() );
103 }
104
109 inline void setDistanceArea( const QgsDistanceArea &distanceArea )
110 {
111 if ( mLayer )
112 {
113 mDistanceArea = distanceArea;
114 mDistanceArea.setSourceCrs( mLayer->crs(), QgsProject::instance()->transformContext() );
115 }
116 }
117
122 inline const QgsDistanceArea &distanceArea() const { return mDistanceArea; }
123
129 inline void setMapCanvas( QgsMapCanvas *mapCanvas ) { mMapCanvas = mapCanvas; }
130
136 inline QgsMapCanvas *mapCanvas() const { return mMapCanvas; }
137
144 void setCadDockWidget( QgsAdvancedDigitizingDockWidget *cadDockWidget );
145
152 QgsAdvancedDigitizingDockWidget *cadDockWidget() const { return mCadDockWidget; }
153
159 inline void setVectorLayerTools( QgsVectorLayerTools *vlTools ) { mVectorLayerTools = vlTools; }
160 // TODO QGIS 4.0 - rename vlTools to tools
161
166 inline const QgsVectorLayerTools *vectorLayerTools() const { return mVectorLayerTools; }
167
175 inline void setRelation( const QgsRelation &relation, RelationMode mode )
176 {
177 mRelation = relation;
178 mRelationMode = mode;
179 }
180
186 inline const QgsRelation &relation() const { return mRelation; }
187
193 inline RelationMode relationMode() const { return mRelationMode; }
194
199 inline FormMode formMode() const { return mFormMode; }
200
206 inline void setFormMode( FormMode mode ) { mFormMode = mode; }
207
212 bool allowCustomUi() const { return mAllowCustomUi; }
213
220 void setAllowCustomUi( bool allow ) { mAllowCustomUi = allow; }
221
222 inline const QgsAttributeEditorContext *parentContext() const { return mParentContext; }
223
229 QgsFeature formFeature() const { return mFormFeature; }
230
236 void setFormFeature( const QgsFeature &feature ) { mFormFeature = feature; }
237
243 QgsFeature parentFormFeature() const { return mParentFormFeature; }
244
250 void setParentFormFeature( const QgsFeature &feature ) { mParentFormFeature = feature; }
251
256 Mode attributeFormMode() const { return mAttributeFormMode; }
257
262 void setAttributeFormMode( const Mode &attributeFormMode ) { mAttributeFormMode = attributeFormMode; }
263
269 {
270 const QMetaEnum metaEnum( QMetaEnum::fromType<Mode>() );
271 return metaEnum.valueToKey( static_cast<int>( mAttributeFormMode ) );
272 }
273
278 void setMainMessageBar( QgsMessageBar *messageBar ) { mMainMessageBar = messageBar; }
279
284 QgsMessageBar *mainMessageBar() { return mMainMessageBar; }
285
286 private:
287 const QgsAttributeEditorContext *mParentContext = nullptr;
288 QgsVectorLayer *mLayer = nullptr;
289 QgsVectorLayerTools *mVectorLayerTools = nullptr;
290 QgsMapCanvas *mMapCanvas = nullptr;
291 QgsMessageBar *mMainMessageBar = nullptr;
292 QgsAdvancedDigitizingDockWidget *mCadDockWidget = nullptr;
293 QgsDistanceArea mDistanceArea;
294 QgsRelation mRelation;
295 RelationMode mRelationMode = Undefined;
297 QgsFeature mFormFeature;
299 QgsFeature mParentFormFeature;
300 FormMode mFormMode = Embed;
301 bool mAllowCustomUi = true;
302 Mode mAttributeFormMode = SingleEditMode;
303};
304
305#endif // QGSATTRIBUTEEDITORCONTEXT_H
The QgsAdvancedDigitizingDockWidget class is a dockable widget used to handle the CAD tools on top of...
This class contains context information for attribute editor widgets.
void setMapCanvas(QgsMapCanvas *mapCanvas)
Sets the associated map canvas, mapCanvas, (e.g.
RelationMode relationMode() const
Returns the attribute relation mode.
QgsAttributeEditorContext()=default
QgsMapCanvas * mapCanvas() const
Returns the associated map canvas (e.g.
FormMode formMode() const
Returns the form mode.
void setFormFeature(const QgsFeature &feature)
Set current feature for the currently edited form or table row.
void setRelation(const QgsRelation &relation, RelationMode mode)
Set attribute relation and mode.
const QgsDistanceArea & distanceArea() const
Returns the distance area object used for area/length calculations.
QgsAdvancedDigitizingDockWidget * cadDockWidget() const
Returns the associated CAD dock widget (e.g.
QString attributeFormModeString() const
Returns given attributeFormMode as string.
RelationMode
Determines in which direction a relation was resolved.
@ Multiple
When showing a list of features (e.g. houses as an embedded form in a district form)
@ Undefined
This context is not defined by a relation.
QgsFeature parentFormFeature() const
Returns the feature of the currently edited parent form in its actual state.
const QgsVectorLayerTools * vectorLayerTools() const
Returns the associated vector layer tools.
@ Embed
A form was embedded as a widget on another form.
@ StandaloneDialog
A form was opened as a new dialog.
void setParentFormFeature(const QgsFeature &feature)
Sets the feature of the currently edited parent form.
QgsAttributeEditorContext(const QgsAttributeEditorContext &parentContext, const QgsRelation &relation, RelationMode relationMode, FormMode widgetMode)
void setFormMode(FormMode mode)
Sets the form mode.
QgsMessageBar * mainMessageBar()
Returns the main message bar.
void setVectorLayerTools(QgsVectorLayerTools *vlTools)
Sets the associated vector layer tools.
void setMainMessageBar(QgsMessageBar *messageBar)
Set current messageBar as the main message bar.
QgsAttributeEditorContext(const QgsAttributeEditorContext &parentContext, FormMode formMode)
bool allowCustomUi() const
Returns true if the attribute editor should permit use of custom UI forms.
@ SearchMode
Form values are used for searching/filtering the layer.
@ FixAttributeMode
Fix feature mode, for modifying the feature attributes without saving. The updated feature is availab...
@ SingleEditMode
Single edit mode, for editing a single feature.
@ AggregateSearchMode
Form is in aggregate search mode, show each widget in this mode.
@ MultiEditMode
Multi edit mode, for editing fields of multiple features at once.
void setAttributeFormMode(const Mode &attributeFormMode)
Set attributeFormMode for the edited form.
QgsFeature formFeature() const
Returns current feature from the currently edited form or table row.
void setAllowCustomUi(bool allow)
Sets whether the attribute editor should permit use of custom UI forms.
const QgsAttributeEditorContext * parentContext() const
const QgsRelation & relation() const
Returns the attribute relation.
Mode attributeFormMode() const
Returns current attributeFormMode.
void setDistanceArea(const QgsDistanceArea &distanceArea)
Sets distance area object, distanceArea, for area/length calculations.
A general purpose distance and area calculator, capable of performing ellipsoid based calculations.
void setSourceCrs(const QgsCoordinateReferenceSystem &crs, const QgsCoordinateTransformContext &context)
Sets source spatial reference system crs.
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
Definition qgsfeature.h:58
Map canvas is a class for displaying all GIS data types on a canvas.
A bar for displaying non-blocking messages to the user.
static QgsProject * instance()
Returns the QgsProject singleton instance.
QgsCoordinateTransformContext transformContext
Definition qgsproject.h:113
Represents a relationship between two vector layers.
Definition qgsrelation.h:44
Methods in this class are used to handle basic operations on vector layers.
Represents a vector layer which manages a vector based data sets.