QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
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 
120  void setEditorContext( const QgsAttributeEditorContext &context, QgsMapCanvas *canvas, QgsMessageBar *messageBar );
121 
123  bool embedForm() { return mEmbedForm; }
124  void setEmbedForm( bool display );
125 
127  bool readOnlySelector() { return mReadOnlySelector; }
128  void setReadOnlySelector( bool readOnly );
129 
131  bool allowMapIdentification() { return mAllowMapIdentification; }
132  void setAllowMapIdentification( bool allowMapIdentification );
133 
135  bool orderByValue() { return mOrderByValue; }
137  void setOrderByValue( bool orderByValue );
139  void setFilterFields( const QStringList &filterFields );
140 
142  bool openFormButtonVisible() { return mOpenFormButtonVisible; }
143  void setOpenFormButtonVisible( bool openFormButtonVisible );
144 
150  bool chainFilters() const { return mChainFilters; }
151 
158  void setChainFilters( bool chainFilters );
159 
163  QString filterExpression() const { return mFilterExpression; };
164 
169  void setFilterExpression( const QString &filterExpression );
170 
175  QgsFeature referencedFeature() const;
176 
181  void showIndeterminateState();
182 
188  bool allowAddFeatures() const;
189 
195  void setAllowAddFeatures( bool allowAddFeatures );
196 
201  QgsRelation relation() const;
202 
208  void setFormFeature( const QgsFeature &formFeature );
209 
214  QString referencedLayerDataSource() const;
215 
220  void setReferencedLayerDataSource( const QString &referencedLayerDataSource );
221 
226  QString referencedLayerProviderKey() const;
227 
232  void setReferencedLayerProviderKey( const QString &referencedLayerProviderKey );
233 
238  QString referencedLayerId() const;
239 
244  void setReferencedLayerId( const QString &referencedLayerId );
245 
250  QString referencedLayerName() const;
251 
256  void setReferencedLayerName( const QString &referencedLayerName );
257 
258  public slots:
260  void openForm();
261 
263  void mapIdentification();
264 
266  void deleteForeignKeys();
267 
268  protected:
269  void showEvent( QShowEvent *e ) override;
270 
271  void init();
272 
273  signals:
274 
279  Q_DECL_DEPRECATED void foreignKeyChanged( const QVariant & ) SIP_DEPRECATED;
280 
285  void foreignKeysChanged( const QVariantList & );
286 
287  private slots:
288  void highlightActionTriggered( QAction *action );
289  void deleteHighlight();
290  void comboReferenceChanged();
291  void featureIdentified( const QgsFeature &feature );
292  void setMapTool( QgsMapTool *mapTool );
293  void unsetMapTool();
294  void mapToolDeactivated();
295  void filterChanged();
296  void addEntry();
297  void updateAddEntryButton();
298  void entryAdded( const QgsFeature &f );
299  void onKeyPressed( QKeyEvent *e );
300 
301  private:
302  void highlightFeature( QgsFeature f = QgsFeature(), CanvasExtent canvasExtent = Fixed );
303  void updateAttributeEditorFrame( const QgsFeature &feature );
304  void disableChainedComboBoxes( const QComboBox *cb );
305  void emitForeignKeysChanged( const QVariantList &foreignKeys, bool force = false );
306 
307  // initialized
308  QgsAttributeEditorContext mEditorContext;
309  QgsMapCanvas *mCanvas = nullptr;
310  QgsMessageBar *mMessageBar = nullptr;
311  QVariantList mForeignKeys;
312  QgsFeature mFeature;
313  QgsFeature mFormFeature;
314  // Index of the referenced layer key
315  QStringList mReferencedFields;
316  bool mAllowNull = true;
317  QgsHighlight *mHighlight = nullptr;
318  QgsMapTool *mCurrentMapTool = nullptr;
321  QgsMessageBarItem *mMessageBarItem = nullptr;
322  QgsAttributeForm *mReferencedAttributeForm = nullptr;
323  QgsVectorLayer *mReferencedLayer = nullptr;
324  QgsVectorLayer *mReferencingLayer = nullptr;
325  QgsFeatureListComboBox *mComboBox = nullptr;
326  QList<QComboBox *> mFilterComboBoxes;
327  QString mFilterExpression;
328  QWidget *mWindowWidget = nullptr;
329  bool mShown = false;
330  QgsRelation mRelation;
331  bool mIsEditable = true;
332  QStringList mFilterFields;
333  QMap<QString, QMap<QString, QSet<QString> > > mFilterCache;
334  bool mInitialized = false;
335 
336  // Q_PROPERTY
337  bool mEmbedForm = false;
338  bool mReadOnlySelector = false;
339  bool mAllowMapIdentification = false;
340  bool mOrderByValue = false;
341  bool mOpenFormButtonVisible = true;
342  bool mChainFilters = false;
343  bool mAllowAddFeatures = false;
344  QString mReferencedLayerId;
345  QString mReferencedLayerName;
346  QString mReferencedLayerDataSource;
347  QString mReferencedLayerProviderKey;
348 
349  // UI
350  QVBoxLayout *mTopLayout = nullptr;
351  QToolButton *mMapIdentificationButton = nullptr;
352  QToolButton *mRemoveFKButton = nullptr;
353  QToolButton *mOpenFormButton = nullptr;
354  QToolButton *mHighlightFeatureButton = nullptr;
355  QToolButton *mAddEntryButton = nullptr;
356  QAction *mHighlightFeatureAction = nullptr;
357  QAction *mScaleHighlightFeatureAction = nullptr;
358  QAction *mPanHighlightFeatureAction = nullptr;
359  QWidget *mChooserContainer = nullptr;
360  QWidget *mFilterContainer = nullptr;
361  QHBoxLayout *mFilterLayout = nullptr;
362  QgsCollapsibleGroupBox *mAttributeEditorFrame = nullptr;
363  QVBoxLayout *mAttributeEditorLayout = nullptr;
364  QLabel *mInvalidLabel = nullptr;
365 
366  friend class TestQgsRelationReferenceWidget;
367 };
368 
369 #endif // QGSRELATIONREFERENCEWIDGET_H
QgsRelationReferenceWidget
Definition: qgsrelationreferencewidget.h:57
QgsRelationReferenceWidget::Pan
@ Pan
Definition: qgsrelationreferencewidget.h:77
QgsRelationReferenceWidget::allowMapIdentification
bool allowMapIdentification()
determines if the widget offers the possibility to select the related feature on the map (using a ded...
Definition: qgsrelationreferencewidget.h:131
QgsMapCanvas
Map canvas is a class for displaying all GIS data types on a canvas.
Definition: qgsmapcanvas.h:89
qgsfeature.h
QgsVectorLayerTools
Methods in this class are used to handle basic operations on vector layers. With an implementation of...
Definition: qgsvectorlayertools.h:39
QgsRelationReferenceWidget::Fixed
@ Fixed
Definition: qgsrelationreferencewidget.h:76
QgsMapToolIdentifyFeature
The QgsMapToolIdentifyFeature class is a map tool to identify a feature on a chosen layer....
Definition: qgsmaptoolidentifyfeature.h:28
QgsCollapsibleGroupBox
A groupbox that collapses/expands when toggled and can save its collapsed and checked states....
Definition: qgscollapsiblegroupbox.h:185
QgsRelationReferenceWidget::filterExpression
QString filterExpression() const
Returns the currently set filter expression.
Definition: qgsrelationreferencewidget.h:163
QgsRelationReferenceWidget::chainFilters
bool chainFilters() const
Determines if the filters are chained.
Definition: qgsrelationreferencewidget.h:150
QgsHighlight
A class for highlight features on the map.
Definition: qgshighlight.h:61
QgsMapTool
Abstract base class for all map tools. Map tools are user interactive tools for manipulating the map ...
Definition: qgsmaptool.h:70
SIP_DEPRECATED
#define SIP_DEPRECATED
Definition: qgis_sip.h:106
QgsRelationReferenceWidget::readOnlySelector
bool readOnlySelector()
determines if the drop-down is enabled
Definition: qgsrelationreferencewidget.h:127
SIP_CONVERT_TO_SUBCLASS_CODE
#define SIP_CONVERT_TO_SUBCLASS_CODE(code)
Definition: qgis_sip.h:186
QObjectUniquePtr< QgsMapToolIdentifyFeature >
QgsMessageBarItem
Represents an item shown within a QgsMessageBar widget.
Definition: qgsmessagebaritem.h:38
QgsRelationReferenceWidget::orderByValue
bool orderByValue()
If the widget will order the combobox entries by value.
Definition: qgsrelationreferencewidget.h:135
QgsRelationReferenceWidget::openFormButtonVisible
bool openFormButtonVisible()
determines the open form button is visible in the widget
Definition: qgsrelationreferencewidget.h:142
qobjectuniqueptr.h
qgis_sip.h
QgsMessageBar
A bar for displaying non-blocking messages to the user.
Definition: qgsmessagebar.h:60
QgsMapToolDigitizeFeature
This tool digitizes geometry of new point/line/polygon features on already existing vector layers Onc...
Definition: qgsmaptooldigitizefeature.h:31
QgsFeatureListComboBox
This offers a combobox with autocompleter that allows selecting features from a layer.
Definition: qgsfeaturelistcombobox.h:39
qgsattributeeditorcontext.h
QgsVectorLayer
Represents a vector layer which manages a vector based data sets.
Definition: qgsvectorlayer.h:391
QgsRelationReferenceWidget::CanvasExtent
CanvasExtent
Definition: qgsrelationreferencewidget.h:74
QgsRelation
Definition: qgsrelation.h:42
QgsFeature
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
Definition: qgsfeature.h:55
QgsAttributeForm
Definition: qgsattributeform.h:44
qgsrelationreferencewidget.h
QgsAttributeEditorContext
This class contains context information for attribute editor widgets. It will be passed to embedded w...
Definition: qgsattributeeditorcontext.h:40
SIP_END
#define SIP_END
Definition: qgis_sip.h:203
SIP_TRANSFERTHIS
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:53