QGIS API Documentation  2.99.0-Master (08ee180)
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:
36 
41  {
44  Single
45  };
46 
47  enum FormMode
48  {
51  Popup
52  };
53 
55  : mParentContext( nullptr )
56  , mLayer( nullptr )
57  , mVectorLayerTools( nullptr )
58  , mRelationMode( Undefined )
59  , mFormMode( Embed )
60  , mAllowCustomUi( true )
61  {}
62 
64  : mParentContext( &parentContext )
65  , mLayer( nullptr )
66  , mVectorLayerTools( parentContext.mVectorLayerTools )
67  , mDistanceArea( parentContext.mDistanceArea )
68  , mRelationMode( Undefined )
69  , mFormMode( formMode )
70  , mAllowCustomUi( true )
71  {
72  Q_ASSERT( parentContext.vectorLayerTools() );
73  }
74 
75  QgsAttributeEditorContext( const QgsAttributeEditorContext& parentContext, const QgsRelation& relation, RelationMode relationMode, FormMode widgetMode )
76  : mParentContext( &parentContext )
77  , mLayer( nullptr )
78  , mVectorLayerTools( parentContext.mVectorLayerTools )
79  , mDistanceArea( parentContext.mDistanceArea )
80  , mRelation( relation )
81  , mRelationMode( relationMode )
82  , mFormMode( widgetMode )
83  , mAllowCustomUi( true )
84  {
85  Q_ASSERT( parentContext.vectorLayerTools() );
86  }
87 
88  inline void setDistanceArea( const QgsDistanceArea& distanceArea )
89  {
90  if ( mLayer )
91  {
92  mDistanceArea = distanceArea;
93  mDistanceArea.setSourceCrs( mLayer->crs() );
94  }
95  }
96 
97  inline const QgsDistanceArea& distanceArea() const { return mDistanceArea; }
98 
99  inline void setVectorLayerTools( QgsVectorLayerTools* vlTools ) { mVectorLayerTools = vlTools; }
100  inline const QgsVectorLayerTools* vectorLayerTools() const { return mVectorLayerTools; }
101 
102  inline void setRelation( const QgsRelation& relation, RelationMode mode ) { mRelation = relation; mRelationMode = mode; }
103  inline const QgsRelation& relation() const { return mRelation; }
104  inline RelationMode relationMode() const { return mRelationMode; }
105 
109  inline FormMode formMode() const { return mFormMode; }
110 
116  inline void setFormMode( FormMode mode ) { mFormMode = mode; }
117 
122  bool allowCustomUi() const { return mAllowCustomUi; }
123 
130  void setAllowCustomUi( bool allow ) { mAllowCustomUi = allow; }
131 
132  inline const QgsAttributeEditorContext* parentContext() const { return mParentContext; }
133 
134  private:
135  const QgsAttributeEditorContext* mParentContext;
136  QgsVectorLayer* mLayer;
137  QgsVectorLayerTools* mVectorLayerTools;
138  QgsDistanceArea mDistanceArea;
139  QgsRelation mRelation;
140  RelationMode mRelationMode;
141  FormMode mFormMode;
142  bool mAllowCustomUi;
143 };
144 
145 #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.