QGIS API Documentation  2.6.0-Brighton
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 dot kuhn at gmx 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  {}
59 
61  : mParentContext( &parentContext )
62  , mLayer( 0 )
63  , mVectorLayerTools( parentContext.mVectorLayerTools )
64  , mDistanceArea( parentContext.mDistanceArea )
65  , mRelationMode( Undefined )
66  , mFormMode( formMode )
67  {
68  Q_ASSERT( parentContext.vectorLayerTools() );
69  }
70 
71  QgsAttributeEditorContext( const QgsAttributeEditorContext& parentContext, const QgsRelation& relation, RelationMode relationMode, FormMode widgetMode )
72  : mParentContext( &parentContext )
73  , mLayer( 0 )
74  , mVectorLayerTools( parentContext.mVectorLayerTools )
75  , mDistanceArea( parentContext.mDistanceArea )
76  , mRelation( relation )
77  , mRelationMode( relationMode )
78  , mFormMode( widgetMode )
79  {
80  Q_ASSERT( parentContext.vectorLayerTools() );
81  }
82 
83  inline void setDistanceArea( const QgsDistanceArea& distanceArea )
84  {
85  if ( mLayer )
86  {
87  mDistanceArea = distanceArea;
88  mDistanceArea.setSourceCrs( mLayer->crs() );
89  }
90  }
91 
92  inline const QgsDistanceArea& distanceArea() const { return mDistanceArea; }
93 
94  inline void setVectorLayerTools( QgsVectorLayerTools* vlTools ) { mVectorLayerTools = vlTools; }
95  inline const QgsVectorLayerTools* vectorLayerTools() const { return mVectorLayerTools; }
96 
97  inline void setRelation( const QgsRelation& relation, RelationMode mode ) { mRelation = relation; mRelationMode = mode; }
98  inline const QgsRelation& relation() const { return mRelation; }
99  inline RelationMode relationMode() const { return mRelationMode; }
100 
101  inline FormMode formMode() const { return mFormMode; }
102 
103  inline const QgsAttributeEditorContext* parentContext() const { return mParentContext; }
104 
105  private:
106  const QgsAttributeEditorContext* mParentContext;
107  QgsVectorLayer* mLayer;
108  QgsVectorLayerTools* mVectorLayerTools;
109  QgsDistanceArea mDistanceArea;
110  QgsRelation mRelation;
111  RelationMode mRelationMode;
112  FormMode mFormMode;
113 };
114 
115 #endif // QGSATTRIBUTEEDITORCONTEXT_H