QGIS API Documentation  3.0.2-Girona (307d082)
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 #include "qgsproject.h"
27 
35 class GUI_EXPORT QgsAttributeEditorContext
36 {
37  public:
38 
43  {
46  Single
47  };
48 
49  enum FormMode
50  {
53  Popup
54  };
55 
57  QgsAttributeEditorContext() = default;
58 
60  : mParentContext( &parentContext )
61  , mVectorLayerTools( parentContext.mVectorLayerTools )
62  , mDistanceArea( parentContext.mDistanceArea )
63  , mFormMode( formMode )
64  {
65  Q_ASSERT( parentContext.vectorLayerTools() );
66  }
67 
68  QgsAttributeEditorContext( const QgsAttributeEditorContext &parentContext, const QgsRelation &relation, RelationMode relationMode, FormMode widgetMode )
69  : mParentContext( &parentContext )
70  , mVectorLayerTools( parentContext.mVectorLayerTools )
71  , mDistanceArea( parentContext.mDistanceArea )
72  , mRelation( relation )
73  , mRelationMode( relationMode )
74  , mFormMode( widgetMode )
75  {
76  Q_ASSERT( parentContext.vectorLayerTools() );
77  }
78 
79  inline void setDistanceArea( const QgsDistanceArea &distanceArea )
80  {
81  if ( mLayer )
82  {
83  mDistanceArea = distanceArea;
84  mDistanceArea.setSourceCrs( mLayer->crs(), QgsProject::instance()->transformContext() );
85  }
86  }
87 
88  inline const QgsDistanceArea &distanceArea() const { return mDistanceArea; }
89 
90  inline void setVectorLayerTools( QgsVectorLayerTools *vlTools ) { mVectorLayerTools = vlTools; }
91  inline const QgsVectorLayerTools *vectorLayerTools() const { return mVectorLayerTools; }
92 
93  inline void setRelation( const QgsRelation &relation, RelationMode mode ) { mRelation = relation; mRelationMode = mode; }
94  inline const QgsRelation &relation() const { return mRelation; }
95  inline RelationMode relationMode() const { return mRelationMode; }
96 
101  inline FormMode formMode() const { return mFormMode; }
102 
109  inline void setFormMode( FormMode mode ) { mFormMode = mode; }
110 
116  bool allowCustomUi() const { return mAllowCustomUi; }
117 
125  void setAllowCustomUi( bool allow ) { mAllowCustomUi = allow; }
126 
127  inline const QgsAttributeEditorContext *parentContext() const { return mParentContext; }
128 
129  private:
130  const QgsAttributeEditorContext *mParentContext = nullptr;
131  QgsVectorLayer *mLayer = nullptr;
132  QgsVectorLayerTools *mVectorLayerTools = nullptr;
133  QgsDistanceArea mDistanceArea;
134  QgsRelation mRelation;
135  RelationMode mRelationMode = Undefined;
136  FormMode mFormMode = Embed;
137  bool mAllowCustomUi = true;
138 };
139 
140 #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.
QgsCoordinateTransformContext transformContext() const
Returns a copy of the project&#39;s coordinate transform context, which stores various information regard...
Definition: qgsproject.cpp:474
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.
static QgsProject * instance()
Returns the QgsProject singleton instance.
Definition: qgsproject.cpp:383
const QgsDistanceArea & distanceArea() const
void setSourceCrs(const QgsCoordinateReferenceSystem &crs, const QgsCoordinateTransformContext &context)
Sets source spatial reference system crs.
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.