QGIS API Documentation  2.12.0-Lyon
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( 0 )
55  , mLayer( 0 )
56  , mVectorLayerTools( 0 )
57  , mRelationMode( Undefined )
58  , mFormMode( Embed )
59  {}
60 
62  : mParentContext( &parentContext )
63  , mLayer( 0 )
64  , mVectorLayerTools( parentContext.mVectorLayerTools )
65  , mDistanceArea( parentContext.mDistanceArea )
66  , mRelationMode( Undefined )
67  , mFormMode( formMode )
68  {
69  Q_ASSERT( parentContext.vectorLayerTools() );
70  }
71 
72  QgsAttributeEditorContext( const QgsAttributeEditorContext& parentContext, const QgsRelation& relation, RelationMode relationMode, FormMode widgetMode )
73  : mParentContext( &parentContext )
74  , mLayer( 0 )
75  , mVectorLayerTools( parentContext.mVectorLayerTools )
76  , mDistanceArea( parentContext.mDistanceArea )
77  , mRelation( relation )
78  , mRelationMode( relationMode )
79  , mFormMode( widgetMode )
80  {
81  Q_ASSERT( parentContext.vectorLayerTools() );
82  }
83 
84  inline void setDistanceArea( const QgsDistanceArea& distanceArea )
85  {
86  if ( mLayer )
87  {
88  mDistanceArea = distanceArea;
89  mDistanceArea.setSourceCrs( mLayer->crs() );
90  }
91  }
92 
93  inline const QgsDistanceArea& distanceArea() const { return mDistanceArea; }
94 
95  inline void setVectorLayerTools( QgsVectorLayerTools* vlTools ) { mVectorLayerTools = vlTools; }
96  inline const QgsVectorLayerTools* vectorLayerTools() const { return mVectorLayerTools; }
97 
98  inline void setRelation( const QgsRelation& relation, RelationMode mode ) { mRelation = relation; mRelationMode = mode; }
99  inline const QgsRelation& relation() const { return mRelation; }
100  inline RelationMode relationMode() const { return mRelationMode; }
101 
102  inline FormMode formMode() const { return mFormMode; }
103 
104  inline const QgsAttributeEditorContext* parentContext() const { return mParentContext; }
105 
106  private:
107  const QgsAttributeEditorContext* mParentContext;
108  QgsVectorLayer* mLayer;
109  QgsVectorLayerTools* mVectorLayerTools;
110  QgsDistanceArea mDistanceArea;
111  QgsRelation mRelation;
112  RelationMode mRelationMode;
113  FormMode mFormMode;
114 };
115 
116 #endif // QGSATTRIBUTEEDITORCONTEXT_H
Methods in this class are used to handle basic operations on vector layers.
const QgsDistanceArea & distanceArea() 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)
This context is not defined by a relation.
RelationMode
Determines in which direction a relation was resolved.
void setDistanceArea(const QgsDistanceArea &distanceArea)
General purpose distance and area calculator.
const QgsRelation & relation() const
const QgsVectorLayerTools * vectorLayerTools() const
const QgsAttributeEditorContext * parentContext() 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.