QGIS API Documentation  3.0.2-Girona (307d082)
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 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 QGSRELATIONREFERENCEWIDGET_H
17 #define QGSRELATIONREFERENCEWIDGET_H
18 
20 #include "qgis.h"
21 #include "qgsfeature.h"
22 
23 #include <QComboBox>
24 #include <QToolButton>
25 #include <QLineEdit>
26 #include <QHBoxLayout>
27 #include <QStandardItemModel>
28 #include "qgis_gui.h"
29 
30 class QgsAttributeForm;
32 class QgsMapCanvas;
33 class QgsMessageBar;
34 class QgsHighlight;
36 class QgsMessageBarItem;
39 class QLabel;
40 
41 #ifdef SIP_RUN
42 % ModuleHeaderCode
43 // fix to allow compilation with sip that for some reason
44 // doesn't add this include to the file where the code from
45 // ConvertToSubClassCode goes.
47 % End
48 #endif
49 
54 class GUI_EXPORT QgsRelationReferenceWidget : public QWidget
55 {
56 
57 #ifdef SIP_RUN
59  if ( qobject_cast<QgsRelationReferenceWidget *>( sipCpp ) )
60  sipType = sipType_QgsRelationReferenceWidget;
61  else
62  sipType = NULL;
63  SIP_END
64 #endif
65 
66  Q_OBJECT
67  Q_PROPERTY( bool openFormButtonVisible READ openFormButtonVisible WRITE setOpenFormButtonVisible )
68 
69  public:
70 
72  {
74  Pan,
75  Scale
76  };
77 
78  explicit QgsRelationReferenceWidget( QWidget *parent SIP_TRANSFERTHIS );
79 
80  ~QgsRelationReferenceWidget() override;
81 
82  void setRelation( const QgsRelation &relation, bool allowNullValue );
83 
84  void setRelationEditable( bool editable );
85 
87  void setForeignKey( const QVariant &value );
88 
90  QVariant foreignKey() const;
91 
92  void setEditorContext( const QgsAttributeEditorContext &context, QgsMapCanvas *canvas, QgsMessageBar *messageBar );
93 
95  bool embedForm() { return mEmbedForm; }
96  void setEmbedForm( bool display );
97 
99  bool readOnlySelector() { return mReadOnlySelector; }
100  void setReadOnlySelector( bool readOnly );
101 
103  bool allowMapIdentification() { return mAllowMapIdentification; }
104  void setAllowMapIdentification( bool allowMapIdentification );
105 
107  bool orderByValue() { return mOrderByValue; }
109  void setOrderByValue( bool orderByValue );
111  void setFilterFields( const QStringList &filterFields );
112 
114  bool openFormButtonVisible() { return mOpenFormButtonVisible; }
115  void setOpenFormButtonVisible( bool openFormButtonVisible );
116 
122  bool chainFilters() const { return mChainFilters; }
123 
130  void setChainFilters( bool chainFilters );
131 
136  QgsFeature referencedFeature() const;
137 
142  void showIndeterminateState();
143 
149  bool allowAddFeatures() const;
150 
156  void setAllowAddFeatures( bool allowAddFeatures );
157 
158  public slots:
160  void openForm();
161 
163  void mapIdentification();
164 
166  void deleteForeignKey();
167 
168  protected:
169  void showEvent( QShowEvent *e ) override;
170 
171  void init();
172 
173  signals:
174  void foreignKeyChanged( const QVariant & );
175 
176  private slots:
177  void highlightActionTriggered( QAction *action );
178  void deleteHighlight();
179  void comboReferenceChanged( int index );
180  void featureIdentified( const QgsFeature &feature );
181  void unsetMapTool();
182  void mapToolDeactivated();
183  void filterChanged();
184  void addEntry();
185  void updateAddEntryButton();
186 
187  private:
188  void highlightFeature( QgsFeature f = QgsFeature(), CanvasExtent canvasExtent = Fixed );
189  void updateAttributeEditorFrame( const QgsFeature &feature );
190  void disableChainedComboBoxes( const QComboBox *cb );
191 
192  // initialized
193  QgsAttributeEditorContext mEditorContext;
194  QgsMapCanvas *mCanvas = nullptr;
195  QgsMessageBar *mMessageBar = nullptr;
196  QVariant mForeignKey;
197  QgsFeature mFeature;
198  // Index of the referenced layer key
199  int mReferencedFieldIdx = -1;
200  QString mReferencedField;
201  int mReferencingFieldIdx = -1;
202  bool mAllowNull = true;
203  QgsHighlight *mHighlight = nullptr;
204  QgsMapToolIdentifyFeature *mMapTool = nullptr;
205  QgsMessageBarItem *mMessageBarItem = nullptr;
206  QString mRelationName;
207  QgsAttributeForm *mReferencedAttributeForm = nullptr;
208  QgsVectorLayer *mReferencedLayer = nullptr;
209  QgsVectorLayer *mReferencingLayer = nullptr;
210  QgsFeatureListComboBox *mComboBox = nullptr;
211  QList<QComboBox *> mFilterComboBoxes;
212  QWidget *mWindowWidget = nullptr;
213  bool mShown = false;
214  QgsRelation mRelation;
215  bool mIsEditable = true;
216  QStringList mFilterFields;
217  QMap<QString, QMap<QString, QSet<QString> > > mFilterCache;
218 
219  // Q_PROPERTY
220  bool mEmbedForm = false;
221  bool mReadOnlySelector = false;
222  bool mAllowMapIdentification = false;
223  bool mOrderByValue = false;
224  bool mOpenFormButtonVisible = true;
225  bool mChainFilters = false;
226  bool mAllowAddFeatures = false;
227 
228  // UI
229  QVBoxLayout *mTopLayout = nullptr;
230  QToolButton *mMapIdentificationButton = nullptr;
231  QToolButton *mRemoveFKButton = nullptr;
232  QToolButton *mOpenFormButton = nullptr;
233  QToolButton *mHighlightFeatureButton = nullptr;
234  QToolButton *mAddEntryButton = nullptr;
235  QAction *mHighlightFeatureAction = nullptr;
236  QAction *mScaleHighlightFeatureAction = nullptr;
237  QAction *mPanHighlightFeatureAction = nullptr;
238  QWidget *mChooserContainer = nullptr;
239  QWidget *mFilterContainer = nullptr;
240  QHBoxLayout *mFilterLayout = nullptr;
241  QgsCollapsibleGroupBox *mAttributeEditorFrame = nullptr;
242  QVBoxLayout *mAttributeEditorLayout = nullptr;
243  QLineEdit *mLineEdit = nullptr;
244  QLabel *mInvalidLabel = nullptr;
245 
246  friend class TestQgsRelationReferenceWidget;
247 };
248 
249 #endif // QGSRELATIONREFERENCEWIDGET_H
Methods in this class are used to handle basic operations on vector layers.
This offers a combobox with autocompleter that allows selecting features from a layer.
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:46
bool chainFilters() const
Determines if the filters are chained.
A groupbox that collapses/expands when toggled and can save its collapsed and checked states...
This class contains context information for attribute editor widgets.
A bar for displaying non-blocking messages to the user.
Definition: qgsmessagebar.h:45
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:62
bool orderByValue()
If the widget will order the combobox entries by value.
Map canvas is a class for displaying all GIS data types on a canvas.
Definition: qgsmapcanvas.h:74
bool allowMapIdentification()
determines if the widge offers the possibility to select the related feature on the map (using a dedi...
bool embedForm()
determines if the form of the related feature will be shown
A class for highlight features on the map.
Definition: qgshighlight.h:49
#define SIP_END
Definition: qgis_sip.h:175
The QgsMapToolIdentifyFeature class is a map tool to identify a feature on a chosen layer...
bool readOnlySelector()
determines if the foreign key is shown in a combox box or a read-only line edit
#define SIP_CONVERT_TO_SUBCLASS_CODE(code)
Definition: qgis_sip.h:165
Represents a vector layer which manages a vector based data sets.
bool openFormButtonVisible()
determines the open form button is visible in the widget