QGIS API Documentation  2.99.0-Master (0cba29c)
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 #include "qgis_gui.h"
26 
27 
34 class GUI_EXPORT QgsAttributeEditorContext
35 {
36  public:
37 
42  {
45  Single
46  };
47 
48  enum FormMode
49  {
52  Popup
53  };
54 
56  : mParentContext( nullptr )
57  , mLayer( nullptr )
58  , mVectorLayerTools( nullptr )
59  , mRelationMode( Undefined )
60  , mFormMode( Embed )
61  , mAllowCustomUi( true )
62  {}
63 
65  : mParentContext( &parentContext )
66  , mLayer( nullptr )
67  , mVectorLayerTools( parentContext.mVectorLayerTools )
68  , mDistanceArea( parentContext.mDistanceArea )
69  , mRelationMode( Undefined )
70  , mFormMode( formMode )
71  , mAllowCustomUi( true )
72  {
73  Q_ASSERT( parentContext.vectorLayerTools() );
74  }
75 
76  QgsAttributeEditorContext( const QgsAttributeEditorContext &parentContext, const QgsRelation &relation, RelationMode relationMode, FormMode widgetMode )
77  : mParentContext( &parentContext )
78  , mLayer( nullptr )
79  , mVectorLayerTools( parentContext.mVectorLayerTools )
80  , mDistanceArea( parentContext.mDistanceArea )
81  , mRelation( relation )
82  , mRelationMode( relationMode )
83  , mFormMode( widgetMode )
84  , mAllowCustomUi( true )
85  {
86  Q_ASSERT( parentContext.vectorLayerTools() );
87  }
88 
89  inline void setDistanceArea( const QgsDistanceArea &distanceArea )
90  {
91  if ( mLayer )
92  {
93  mDistanceArea = distanceArea;
94  mDistanceArea.setSourceCrs( mLayer->crs() );
95  }
96  }
97 
98  inline const QgsDistanceArea &distanceArea() const { return mDistanceArea; }
99 
100  inline void setVectorLayerTools( QgsVectorLayerTools *vlTools ) { mVectorLayerTools = vlTools; }
101  inline const QgsVectorLayerTools *vectorLayerTools() const { return mVectorLayerTools; }
102 
103  inline void setRelation( const QgsRelation &relation, RelationMode mode ) { mRelation = relation; mRelationMode = mode; }
104  inline const QgsRelation &relation() const { return mRelation; }
105  inline RelationMode relationMode() const { return mRelationMode; }
106 
110  inline FormMode formMode() const { return mFormMode; }
111 
117  inline void setFormMode( FormMode mode ) { mFormMode = mode; }
118 
123  bool allowCustomUi() const { return mAllowCustomUi; }
124 
131  void setAllowCustomUi( bool allow ) { mAllowCustomUi = allow; }
132 
133  inline const QgsAttributeEditorContext *parentContext() const { return mParentContext; }
134 
135  private:
136  const QgsAttributeEditorContext *mParentContext = nullptr;
137  QgsVectorLayer *mLayer = nullptr;
138  QgsVectorLayerTools *mVectorLayerTools = nullptr;
139  QgsDistanceArea mDistanceArea;
140  QgsRelation mRelation;
141  RelationMode mRelationMode;
142  FormMode mFormMode;
143  bool mAllowCustomUi;
144 };
145 
146 #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)
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.
A general purpose distance and area calculator, capable of performing ellipsoid based calculations...
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
void setSourceCrs(const QgsCoordinateReferenceSystem &srcCRS)
Sets source spatial reference system.
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.