QGIS API Documentation 4.3.0-Master (91d4a333d5d)
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 "qgis_gui.h"
20#include "qgsdistancearea.h"
21#include "qgsproject.h"
22#include "qgsvectorlayer.h"
23#include "qgsvectorlayertools.h"
24
25#include <QMap>
26#include <QMetaEnum>
27#include <QWidget>
28
29class QgsMapCanvas;
31class QgsMessageBar;
32
40
42{
43 Q_GADGET
44
48
49 public:
63 Q_ENUM( Mode )
64
65
74
81
83
85 : mParentContext( &parentContext )
86 , mVectorLayerTools( parentContext.mVectorLayerTools )
87 , mMapCanvas( parentContext.mMapCanvas )
88 , mMainMessageBar( parentContext.mMainMessageBar )
89 , mCadDockWidget( parentContext.mCadDockWidget )
90 , mDistanceArea( parentContext.mDistanceArea )
91 , mFormFeature( parentContext.mFormFeature )
92 , mFormMode( formMode )
93 {
94 Q_ASSERT( parentContext.vectorLayerTools() );
95 }
96
98 : mParentContext( &parentContext )
99 , mVectorLayerTools( parentContext.mVectorLayerTools )
100 , mMapCanvas( parentContext.mMapCanvas )
101 , mMainMessageBar( parentContext.mMainMessageBar )
102 , mCadDockWidget( parentContext.mCadDockWidget )
103 , mDistanceArea( parentContext.mDistanceArea )
104 , mRelation( relation )
105 , mRelationMode( relationMode )
106 , mFormMode( widgetMode )
107 {
108 Q_ASSERT( parentContext.vectorLayerTools() );
109 }
110
116 {
117 if ( mLayer )
118 {
119 mDistanceArea = distanceArea;
120 mDistanceArea.setSourceCrs( mLayer->crs(), QgsProject::instance()->transformContext() );
121 }
122 }
123
128 inline const QgsDistanceArea &distanceArea() const { return mDistanceArea; }
129
135 inline void setMapCanvas( QgsMapCanvas *mapCanvas ) { mMapCanvas = mapCanvas; }
136
142 inline QgsMapCanvas *mapCanvas() const { return mMapCanvas; }
143
150 void setCadDockWidget( QgsAdvancedDigitizingDockWidget *cadDockWidget );
151
158 QgsAdvancedDigitizingDockWidget *cadDockWidget() const { return mCadDockWidget; }
159
165 inline void setVectorLayerTools( QgsVectorLayerTools *vlTools ) { mVectorLayerTools = vlTools; }
166 // TODO QGIS 5.0 - rename vlTools to tools
167
172 inline const QgsVectorLayerTools *vectorLayerTools() const { return mVectorLayerTools; }
173
181 inline void setRelation( const QgsRelation &relation, RelationMode mode )
182 {
183 mRelation = relation;
184 mRelationMode = mode;
185 }
186
192 inline const QgsRelation &relation() const { return mRelation; }
193
199 inline RelationMode relationMode() const { return mRelationMode; }
200
205 inline FormMode formMode() const { return mFormMode; }
206
212 inline void setFormMode( FormMode mode ) { mFormMode = mode; }
213
218 bool allowCustomUi() const { return mAllowCustomUi; }
219
226 void setAllowCustomUi( bool allow ) { mAllowCustomUi = allow; }
227
228 inline const QgsAttributeEditorContext *parentContext() const { return mParentContext; }
229
235 QgsFeature formFeature() const { return mFormFeature; }
236
242 void setFormFeature( const QgsFeature &feature ) { mFormFeature = feature; }
243
249 QgsFeature parentFormFeature() const { return mParentFormFeature; }
250
256 void setParentFormFeature( const QgsFeature &feature ) { mParentFormFeature = feature; }
257
262 Mode attributeFormMode() const { return mAttributeFormMode; }
263
268 void setAttributeFormMode( const Mode &attributeFormMode ) { mAttributeFormMode = attributeFormMode; }
269
275 {
276 const QMetaEnum metaEnum( QMetaEnum::fromType<Mode>() );
277 return metaEnum.valueToKey( static_cast<int>( mAttributeFormMode ) );
278 }
279
284 void setMainMessageBar( QgsMessageBar *messageBar ) { mMainMessageBar = messageBar; }
285
290 QgsMessageBar *mainMessageBar() { return mMainMessageBar; }
291
292 private:
293 const QgsAttributeEditorContext *mParentContext = nullptr;
294 QgsVectorLayer *mLayer = nullptr;
295 QgsVectorLayerTools *mVectorLayerTools = nullptr;
296 QgsMapCanvas *mMapCanvas = nullptr;
297 QgsMessageBar *mMainMessageBar = nullptr;
298 QgsAdvancedDigitizingDockWidget *mCadDockWidget = nullptr;
299 QgsDistanceArea mDistanceArea;
300 QgsRelation mRelation;
301 RelationMode mRelationMode = Undefined;
303 QgsFeature mFormFeature;
305 QgsFeature mParentFormFeature;
306 FormMode mFormMode = Embed;
307 bool mAllowCustomUi = true;
308 Mode mAttributeFormMode = SingleEditMode;
309};
310
311#endif // QGSATTRIBUTEEDITORCONTEXT_H
A dockable widget used to handle the CAD tools on top of a selection of map tools.
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).
@ Single
When showing a single feature (e.g. district information when looking at the form of a house).
@ 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.
@ Popup
A widget was opened as a popup (e.g. attribute table editor widget).
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.
QgsAttributeEditorContext::Mode attributeFormMode
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...
@ IdentifyMode
Identify the feature.
@ 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.
@ PreviewMode
Preview mode, for previewing attribute configurations.
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.
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
Definition qgsfeature.h:60
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.
Represents a relationship between two vector layers.
Definition qgsrelation.h:42
Used to handle basic editing operations on vector layers.
Represents a vector layer which manages a vector based dataset.