QGIS API Documentation  2.18.21-Las Palmas (9fba24a)
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 
26 
33 class GUI_EXPORT QgsAttributeEditorContext
34 {
35  public:
40  {
43  Single
44  };
45 
46  enum FormMode
47  {
50  Popup
51  };
52 
54  : mParentContext( nullptr )
55  , mLayer( nullptr )
56  , mVectorLayerTools( nullptr )
57  , mRelationMode( Undefined )
58  , mFormMode( Embed )
59  , mAllowCustomUi( true )
60  {}
61 
63  : mParentContext( &parentContext )
64  , mLayer( nullptr )
65  , mVectorLayerTools( parentContext.mVectorLayerTools )
66  , mDistanceArea( parentContext.mDistanceArea )
67  , mRelationMode( Undefined )
68  , mFormMode( formMode )
69  , mAllowCustomUi( true )
70  {
71  Q_ASSERT( parentContext.vectorLayerTools() );
72  }
73 
74  QgsAttributeEditorContext( const QgsAttributeEditorContext& parentContext, const QgsRelation& relation, RelationMode relationMode, FormMode widgetMode )
75  : mParentContext( &parentContext )
76  , mLayer( nullptr )
77  , mVectorLayerTools( parentContext.mVectorLayerTools )
78  , mDistanceArea( parentContext.mDistanceArea )
79  , mRelation( relation )
80  , mRelationMode( relationMode )
81  , mFormMode( widgetMode )
82  , mAllowCustomUi( true )
83  {
84  Q_ASSERT( parentContext.vectorLayerTools() );
85  }
86 
87  inline void setDistanceArea( const QgsDistanceArea& distanceArea )
88  {
89  if ( mLayer )
90  {
91  mDistanceArea = distanceArea;
92  mDistanceArea.setSourceCrs( mLayer->crs() );
93  }
94  }
95 
96  inline const QgsDistanceArea& distanceArea() const { return mDistanceArea; }
97 
98  inline void setVectorLayerTools( QgsVectorLayerTools* vlTools ) { mVectorLayerTools = vlTools; }
99  inline const QgsVectorLayerTools* vectorLayerTools() const { return mVectorLayerTools; }
100 
101  inline void setRelation( const QgsRelation& relation, RelationMode mode ) { mRelation = relation; mRelationMode = mode; }
102  inline const QgsRelation& relation() const { return mRelation; }
103  inline RelationMode relationMode() const { return mRelationMode; }
104 
108  inline FormMode formMode() const { return mFormMode; }
109 
115  inline void setFormMode( FormMode mode ) { mFormMode = mode; }
116 
121  bool allowCustomUi() const { return mAllowCustomUi; }
122 
129  void setAllowCustomUi( bool allow ) { mAllowCustomUi = allow; }
130 
131  inline const QgsAttributeEditorContext* parentContext() const { return mParentContext; }
132 
133  private:
134  const QgsAttributeEditorContext* mParentContext;
135  QgsVectorLayer* mLayer;
136  QgsVectorLayerTools* mVectorLayerTools;
137  QgsDistanceArea mDistanceArea;
138  QgsRelation mRelation;
139  RelationMode mRelationMode;
140  FormMode mFormMode;
141  bool mAllowCustomUi;
142 };
143 
144 #endif // QGSATTRIBUTEEDITORCONTEXT_H
Methods in this class are used to handle basic operations on vector layers.
const QgsVectorLayerTools * vectorLayerTools() const
This class contains context information for attribute editor widgets.
QgsAttributeEditorContext(const QgsAttributeEditorContext &parentContext, FormMode formMode)
void setSourceCrs(long srsid)
sets source spatial reference system (by QGIS CRS)
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)
void setAllowCustomUi(bool allow)
Sets whether the attribute editor should permit use of custom UI forms.
This context is not defined by a relation.
RelationMode
Determines in which direction a relation was resolved.
const QgsRelation & relation() const
void setDistanceArea(const QgsDistanceArea &distanceArea)
const QgsAttributeEditorContext * parentContext() const
FormMode formMode() const
Returns the form mode.
General purpose distance and area calculator.
void setFormMode(FormMode mode)
Sets the form mode.
bool allowCustomUi() const
Returns true if the attribute editor should permit use of custom UI forms.
const QgsDistanceArea & distanceArea() const
Represents a vector layer which manages a vector based data sets.
void setRelation(const QgsRelation &relation, RelationMode mode)
A form was embedded as a widget on another form.