QGIS API Documentation  3.10.0-A Coruña (6c816b4204)
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_sip.h"
21 #include "qgsfeature.h"
22 #include "qobjectuniqueptr.h"
23 
24 #include <QComboBox>
25 #include <QToolButton>
26 #include <QLineEdit>
27 #include <QHBoxLayout>
28 #include <QStandardItemModel>
29 #include "qgis_gui.h"
30 
31 class QgsAttributeForm;
33 class QgsMapCanvas;
34 class QgsMessageBar;
35 class QgsHighlight;
36 class QgsMapTool;
39 class QgsMessageBarItem;
42 class QLabel;
43 
44 #ifdef SIP_RUN
45 % ModuleHeaderCode
46 // fix to allow compilation with sip that for some reason
47 // doesn't add this include to the file where the code from
48 // ConvertToSubClassCode goes.
50 % End
51 #endif
52 
57 class GUI_EXPORT QgsRelationReferenceWidget : public QWidget
58 {
59 
60 #ifdef SIP_RUN
62  if ( qobject_cast<QgsRelationReferenceWidget *>( sipCpp ) )
63  sipType = sipType_QgsRelationReferenceWidget;
64  else
65  sipType = NULL;
66  SIP_END
67 #endif
68 
69  Q_OBJECT
70  Q_PROPERTY( bool openFormButtonVisible READ openFormButtonVisible WRITE setOpenFormButtonVisible )
71 
72  public:
73 
75  {
77  Pan,
78  Scale
79  };
80 
81  explicit QgsRelationReferenceWidget( QWidget *parent SIP_TRANSFERTHIS );
82 
83  ~QgsRelationReferenceWidget() override;
84 
85  void setRelation( const QgsRelation &relation, bool allowNullValue );
86 
87  void setRelationEditable( bool editable );
88 
93  Q_DECL_DEPRECATED void setForeignKey( const QVariant &value ) SIP_DEPRECATED;
94 
99  void setForeignKeys( const QVariantList &values );
100 
105  Q_DECL_DEPRECATED QVariant foreignKey() const SIP_DEPRECATED;
106 
108 
113  QVariantList foreignKeys() const;
114 
115  void setEditorContext( const QgsAttributeEditorContext &context, QgsMapCanvas *canvas, QgsMessageBar *messageBar );
116 
118  bool embedForm() { return mEmbedForm; }
119  void setEmbedForm( bool display );
120 
122  bool readOnlySelector() { return mReadOnlySelector; }
123  void setReadOnlySelector( bool readOnly );
124 
126  bool allowMapIdentification() { return mAllowMapIdentification; }
127  void setAllowMapIdentification( bool allowMapIdentification );
128 
130  bool orderByValue() { return mOrderByValue; }
132  void setOrderByValue( bool orderByValue );
134  void setFilterFields( const QStringList &filterFields );
135 
137  bool openFormButtonVisible() { return mOpenFormButtonVisible; }
138  void setOpenFormButtonVisible( bool openFormButtonVisible );
139 
145  bool chainFilters() const { return mChainFilters; }
146 
153  void setChainFilters( bool chainFilters );
154 
159  QgsFeature referencedFeature() const;
160 
165  void showIndeterminateState();
166 
172  bool allowAddFeatures() const;
173 
179  void setAllowAddFeatures( bool allowAddFeatures );
180 
185  QgsRelation relation() const;
186 
192  void setFormFeature( const QgsFeature &formFeature );
193 
194  public slots:
196  void openForm();
197 
199  void mapIdentification();
200 
202  void deleteForeignKeys();
203 
204  protected:
205  void showEvent( QShowEvent *e ) override;
206 
207  void init();
208 
209  signals:
210 
215  Q_DECL_DEPRECATED void foreignKeyChanged( const QVariant & ) SIP_DEPRECATED;
216 
221  void foreignKeysChanged( const QVariantList & );
222 
223  private slots:
224  void highlightActionTriggered( QAction *action );
225  void deleteHighlight();
226  void comboReferenceChanged( int index );
227  void featureIdentified( const QgsFeature &feature );
228  void setMapTool( QgsMapTool *mapTool );
229  void unsetMapTool();
230  void mapToolDeactivated();
231  void filterChanged();
232  void addEntry();
233  void updateAddEntryButton();
234  void entryAdded( const QgsFeature &f );
235  void onKeyPressed( QKeyEvent *e );
236 
241  void updateIndex();
242 
243  private:
244  void highlightFeature( QgsFeature f = QgsFeature(), CanvasExtent canvasExtent = Fixed );
245  void updateAttributeEditorFrame( const QgsFeature &feature );
246  void disableChainedComboBoxes( const QComboBox *cb );
247  void emitForeignKeysChanged( const QVariantList &foreignKeys, bool force = false );
248 
249  // initialized
250  QgsAttributeEditorContext mEditorContext;
251  QgsMapCanvas *mCanvas = nullptr;
252  QgsMessageBar *mMessageBar = nullptr;
253  QVariantList mForeignKeys;
254  QgsFeature mFeature;
255  QgsFeature mFormFeature;
256  // Index of the referenced layer key
257  QStringList mReferencedFields;
258  bool mAllowNull = true;
259  QgsHighlight *mHighlight = nullptr;
260  QgsMapTool *mCurrentMapTool = nullptr;
263  QgsMessageBarItem *mMessageBarItem = nullptr;
264  QgsAttributeForm *mReferencedAttributeForm = nullptr;
265  QgsVectorLayer *mReferencedLayer = nullptr;
266  QgsVectorLayer *mReferencingLayer = nullptr;
267  QgsFeatureListComboBox *mComboBox = nullptr;
268  QList<QComboBox *> mFilterComboBoxes;
269  QWidget *mWindowWidget = nullptr;
270  bool mShown = false;
271  QgsRelation mRelation;
272  bool mIsEditable = true;
273  QStringList mFilterFields;
274  QMap<QString, QMap<QString, QSet<QString> > > mFilterCache;
275  bool mInitialized = false;
276 
277  // Q_PROPERTY
278  bool mEmbedForm = false;
279  bool mReadOnlySelector = false;
280  bool mAllowMapIdentification = false;
281  bool mOrderByValue = false;
282  bool mOpenFormButtonVisible = true;
283  bool mChainFilters = false;
284  bool mAllowAddFeatures = false;
285 
286  // UI
287  QVBoxLayout *mTopLayout = nullptr;
288  QToolButton *mMapIdentificationButton = nullptr;
289  QToolButton *mRemoveFKButton = nullptr;
290  QToolButton *mOpenFormButton = nullptr;
291  QToolButton *mHighlightFeatureButton = nullptr;
292  QToolButton *mAddEntryButton = nullptr;
293  QAction *mHighlightFeatureAction = nullptr;
294  QAction *mScaleHighlightFeatureAction = nullptr;
295  QAction *mPanHighlightFeatureAction = nullptr;
296  QWidget *mChooserContainer = nullptr;
297  QWidget *mFilterContainer = nullptr;
298  QHBoxLayout *mFilterLayout = nullptr;
299  QgsCollapsibleGroupBox *mAttributeEditorFrame = nullptr;
300  QVBoxLayout *mAttributeEditorLayout = nullptr;
301  QLineEdit *mLineEdit = nullptr;
302  QLabel *mInvalidLabel = nullptr;
303 
304  friend class TestQgsRelationReferenceWidget;
305 };
306 
307 #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:53
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:55
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:75
bool allowMapIdentification()
determines if the widget offers the possibility to select the related feature on the map (using a ded...
A class for highlight features on the map.
Definition: qgshighlight.h:56
#define SIP_END
Definition: qgis_sip.h:189
#define SIP_DEPRECATED
Definition: qgis_sip.h:106
Abstract base class for all map tools.
Definition: qgsmaptool.h:62
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:172
This tool digitizes geometry of new point/line/polygon features on already existing vector layers Onc...
Represents a vector layer which manages a vector based data sets.
bool openFormButtonVisible()
determines the open form button is visible in the widget