QGIS API Documentation  2.8.2-Wien
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
qgsrelationreferencewidget.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsrelationreferencewidget.h
3  --------------------------------------
4  Date : 20.4.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 QGSRELATIONREFERENCEWIDGET_H
17 #define QGSRELATIONREFERENCEWIDGET_H
18 
20 #include "qgscollapsiblegroupbox.h"
21 #include "qgsfeature.h"
22 #include "qgshighlight.h"
24 
25 #include <QComboBox>
26 #include <QToolButton>
27 #include <QLineEdit>
28 #include <QVBoxLayout>
29 
30 class QgsAttributeForm;
32 
33 class GUI_EXPORT QgsRelationReferenceWidget : public QWidget
34 {
35  Q_OBJECT
36  Q_PROPERTY( bool openFormButtonVisible READ openFormButtonVisible WRITE setOpenFormButtonVisible )
37 
38  public:
39  typedef QPair < QVariant, QgsFeatureId > ValueRelationItem;
40  typedef QVector < ValueRelationItem > ValueRelationCache;
41 
43  {
45  Pan,
46  Scale
47  };
48 
49  explicit QgsRelationReferenceWidget( QWidget* parent );
50 
52 
53  void setRelation( QgsRelation relation, bool allowNullValue );
54 
55  void setRelationEditable( bool editable );
56 
58  void setForeignKey( const QVariant &value );
59 
61  QVariant foreignKey();
62 
63  void setEditorContext( const QgsAttributeEditorContext& context, QgsMapCanvas* canvas, QgsMessageBar* messageBar );
64 
66  bool embedForm() {return mEmbedForm;}
67  void setEmbedForm( bool display );
68 
70  bool readOnlySelector() {return mReadOnlySelector;}
71  void setReadOnlySelector( bool readOnly );
72 
74  bool allowMapIdentification() {return mAllowMapIdentification;}
75  void setAllowMapIdentification( bool allowMapIdentification );
76 
78  bool orderByValue() { return mOrderByValue; }
80  void setOrderByValue( bool orderByValue );
81 
83  bool openFormButtonVisible() {return mOpenFormButtonVisible;}
84  void setOpenFormButtonVisible( bool openFormButtonVisible );
85 
88  QgsFeature referencedFeature();
89 
90  public slots:
92  void openForm();
93 
95  void mapIdentification();
96 
98  void deleteForeignKey();
99 
100  protected:
101  virtual void showEvent( QShowEvent* e ) override;
102 
103  void init();
104 
105  signals:
106  void foreignKeyChanged( QVariant );
107 
108  private slots:
109  void highlightActionTriggered( QAction* action );
110  void deleteHighlight();
111  void comboReferenceChanged( int index );
112  void featureIdentified( const QgsFeature& feature );
113  void unsetMapTool();
114  void mapToolDeactivated();
115 
116  private:
117  void highlightFeature( QgsFeature f = QgsFeature(), CanvasExtent canvasExtent = Fixed );
118  void updateAttributeEditorFrame( const QgsFeature feature );
119 
120  // initialized
121  QgsAttributeEditorContext mEditorContext;
122  QgsMapCanvas* mCanvas;
123  QgsMessageBar* mMessageBar;
124  QVariant mForeignKey;
125  QgsFeatureId mFeatureId;
126  int mFkeyFieldIdx;
127  bool mAllowNull;
128  QgsHighlight* mHighlight;
129  QgsMapToolIdentifyFeature* mMapTool;
130  QgsMessageBarItem* mMessageBarItem;
131  QString mRelationName;
132  QgsAttributeForm* mReferencedAttributeForm;
133  QgsVectorLayer* mReferencedLayer;
134  QgsVectorLayer* mReferencingLayer;
135  QWidget* mWindowWidget;
136  bool mShown;
137  QgsRelation mRelation;
138  bool mIsEditable;
139 
140  // Q_PROPERTY
141  bool mEmbedForm;
142  bool mReadOnlySelector;
143  bool mAllowMapIdentification;
144  bool mOrderByValue;
145  bool mOpenFormButtonVisible;
146 
147  // UI
148  QVBoxLayout* mTopLayout;
149  QHash<QgsFeatureId, QVariant> mFidFkMap; // Mapping from feature id => foreign key
150  QToolButton* mMapIdentificationButton;
151  QToolButton* mRemoveFKButton;
152  QToolButton* mOpenFormButton;
153  QToolButton* mHighlightFeatureButton;
154  QAction* mHighlightFeatureAction;
155  QAction* mScaleHighlightFeatureAction;
156  QAction* mPanHighlightFeatureAction;
157  QComboBox* mComboBox;
158  QgsCollapsibleGroupBox* mAttributeEditorFrame;
159  QVBoxLayout* mAttributeEditorLayout;
160  QLineEdit* mLineEdit;
161  QLabel* mInvalidLabel;
162 };
163 
164 #endif // QGSRELATIONREFERENCEWIDGET_H