QGIS API Documentation  3.2.0-Bonn (bc43194)
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 
191  void updateIndex();
192 
193  private:
194  void highlightFeature( QgsFeature f = QgsFeature(), CanvasExtent canvasExtent = Fixed );
195  void updateAttributeEditorFrame( const QgsFeature &feature );
196  void disableChainedComboBoxes( const QComboBox *cb );
197  void emitForeignKeyChanged( const QVariant &foreignKey );
198 
199  // initialized
200  QgsAttributeEditorContext mEditorContext;
201  QgsMapCanvas *mCanvas = nullptr;
202  QgsMessageBar *mMessageBar = nullptr;
203  QVariant mForeignKey;
204  QgsFeature mFeature;
205  // Index of the referenced layer key
206  int mReferencedFieldIdx = -1;
207  QString mReferencedField;
208  int mReferencingFieldIdx = -1;
209  bool mAllowNull = true;
210  QgsHighlight *mHighlight = nullptr;
211  QgsMapToolIdentifyFeature *mMapTool = nullptr;
212  QgsMessageBarItem *mMessageBarItem = nullptr;
213  QString mRelationName;
214  QgsAttributeForm *mReferencedAttributeForm = nullptr;
215  QgsVectorLayer *mReferencedLayer = nullptr;
216  QgsVectorLayer *mReferencingLayer = nullptr;
217  QgsFeatureListComboBox *mComboBox = nullptr;
218  QList<QComboBox *> mFilterComboBoxes;
219  QWidget *mWindowWidget = nullptr;
220  bool mShown = false;
221  QgsRelation mRelation;
222  bool mIsEditable = true;
223  QStringList mFilterFields;
224  QMap<QString, QMap<QString, QSet<QString> > > mFilterCache;
225 
226  // Q_PROPERTY
227  bool mEmbedForm = false;
228  bool mReadOnlySelector = false;
229  bool mAllowMapIdentification = false;
230  bool mOrderByValue = false;
231  bool mOpenFormButtonVisible = true;
232  bool mChainFilters = false;
233  bool mAllowAddFeatures = false;
234 
235  // UI
236  QVBoxLayout *mTopLayout = nullptr;
237  QToolButton *mMapIdentificationButton = nullptr;
238  QToolButton *mRemoveFKButton = nullptr;
239  QToolButton *mOpenFormButton = nullptr;
240  QToolButton *mHighlightFeatureButton = nullptr;
241  QToolButton *mAddEntryButton = nullptr;
242  QAction *mHighlightFeatureAction = nullptr;
243  QAction *mScaleHighlightFeatureAction = nullptr;
244  QAction *mPanHighlightFeatureAction = nullptr;
245  QWidget *mChooserContainer = nullptr;
246  QWidget *mFilterContainer = nullptr;
247  QHBoxLayout *mFilterLayout = nullptr;
248  QgsCollapsibleGroupBox *mAttributeEditorFrame = nullptr;
249  QVBoxLayout *mAttributeEditorLayout = nullptr;
250  QLineEdit *mLineEdit = nullptr;
251  QLabel *mInvalidLabel = nullptr;
252 
253  friend class TestQgsRelationReferenceWidget;
254 };
255 
256 #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:182
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