QGIS API Documentation  2.6.0-Brighton
 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:
40  {
42  Pan,
43  Scale
44  };
45 
46  explicit QgsRelationReferenceWidget( QWidget* parent );
47 
49 
50  void setRelation( QgsRelation relation, bool allowNullValue );
51 
52  void setRelationEditable( bool editable );
53 
55  void setForeignKey( const QVariant &value );
56 
58  QVariant foreignKey();
59 
60  void setEditorContext( QgsAttributeEditorContext context, QgsMapCanvas* canvas, QgsMessageBar* messageBar );
61 
63  bool embedForm() {return mEmbedForm;}
64  void setEmbedForm( bool display );
65 
67  bool readOnlySelector() {return mReadOnlySelector;}
68  void setReadOnlySelector( bool readOnly );
69 
71  bool allowMapIdentification() {return mAllowMapIdentification;}
72  void setAllowMapIdentification( bool allowMapIdentification );
73 
75  bool openFormButtonVisible() {return mOpenFormButtonVisible;}
76  void setOpenFormButtonVisible( bool openFormButtonVisible );
77 
80  QgsFeature referencedFeature();
81 
82  public slots:
84  void openForm();
85 
87  void mapIdentification();
88 
90  void deleteForeignKey();
91 
92  protected:
93  virtual void showEvent( QShowEvent* e );
94 
95  void init();
96 
97  signals:
98  void foreignKeyChanged( QVariant );
99 
100  private slots:
101  void highlightActionTriggered( QAction* action );
102  void deleteHighlight();
103  void comboReferenceChanged( int index );
104  void featureIdentified( const QgsFeature& feature );
105  void unsetMapTool();
106  void mapToolDeactivated();
107 
108  private:
109  void highlightFeature( QgsFeature f = QgsFeature(), CanvasExtent canvasExtent = Fixed );
110  void updateAttributeEditorFrame( const QgsFeature feature );
111 
112  // initialized
113  QgsAttributeEditorContext mEditorContext;
114  QgsMapCanvas* mCanvas;
115  QgsMessageBar* mMessageBar;
116  QVariant mForeignKey;
117  QgsFeatureId mFeatureId;
118  int mFkeyFieldIdx;
119  bool mAllowNull;
120  QgsHighlight* mHighlight;
121  QgsMapToolIdentifyFeature* mMapTool;
122  QgsMessageBarItem* mMessageBarItem;
123  QString mRelationName;
124  QgsAttributeForm* mReferencedAttributeForm;
125  QgsVectorLayer* mReferencedLayer;
126  QgsVectorLayer* mReferencingLayer;
127  QWidget* mWindowWidget;
128  bool mShown;
129  QgsRelation mRelation;
130  bool mIsEditable;
131 
132  // Q_PROPERTY
133  bool mEmbedForm;
134  bool mReadOnlySelector;
135  bool mAllowMapIdentification;
136  bool mOpenFormButtonVisible;
137 
138  // UI
139  QVBoxLayout* mTopLayout;
140  QHash<QgsFeatureId, QVariant> mFidFkMap; // Mapping from feature id => foreign key
141  QToolButton* mMapIdentificationButton;
142  QToolButton* mRemoveFKButton;
143  QToolButton* mOpenFormButton;
144  QToolButton* mHighlightFeatureButton;
145  QAction* mHighlightFeatureAction;
146  QAction* mScaleHighlightFeatureAction;
147  QAction* mPanHighlightFeatureAction;
148  QComboBox* mComboBox;
149  QgsCollapsibleGroupBox* mAttributeEditorFrame;
150  QVBoxLayout* mAttributeEditorLayout;
151  QLineEdit* mLineEdit;
152  QLabel* mInvalidLabel;
153 };
154 
155 #endif // QGSRELATIONREFERENCEWIDGET_H