QGIS API Documentation  3.14.0-Pi (9f7028fd23)
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 
164  QgsFeature referencedFeature() const;
165 
170  void showIndeterminateState();
171 
177  bool allowAddFeatures() const;
178 
184  void setAllowAddFeatures( bool allowAddFeatures );
185 
190  QgsRelation relation() const;
191 
197  void setFormFeature( const QgsFeature &formFeature );
198 
203  QString referencedLayerDataSource() const;
204 
209  void setReferencedLayerDataSource( const QString &referencedLayerDataSource );
210 
215  QString referencedLayerProviderKey() const;
216 
221  void setReferencedLayerProviderKey( const QString &referencedLayerProviderKey );
222 
227  QString referencedLayerId() const;
228 
233  void setReferencedLayerId( const QString &referencedLayerId );
234 
239  QString referencedLayerName() const;
240 
245  void setReferencedLayerName( const QString &referencedLayerName );
246 
247  public slots:
249  void openForm();
250 
252  void mapIdentification();
253 
255  void deleteForeignKeys();
256 
257  protected:
258  void showEvent( QShowEvent *e ) override;
259 
260  void init();
261 
262  signals:
263 
268  Q_DECL_DEPRECATED void foreignKeyChanged( const QVariant & ) SIP_DEPRECATED;
269 
274  void foreignKeysChanged( const QVariantList & );
275 
276  private slots:
277  void highlightActionTriggered( QAction *action );
278  void deleteHighlight();
279  void comboReferenceChanged( int index );
280  void featureIdentified( const QgsFeature &feature );
281  void setMapTool( QgsMapTool *mapTool );
282  void unsetMapTool();
283  void mapToolDeactivated();
284  void filterChanged();
285  void addEntry();
286  void updateAddEntryButton();
287  void entryAdded( const QgsFeature &f );
288  void onKeyPressed( QKeyEvent *e );
289 
290  private:
291  void highlightFeature( QgsFeature f = QgsFeature(), CanvasExtent canvasExtent = Fixed );
292  void updateAttributeEditorFrame( const QgsFeature &feature );
293  void disableChainedComboBoxes( const QComboBox *cb );
294  void emitForeignKeysChanged( const QVariantList &foreignKeys, bool force = false );
295 
296  // initialized
297  QgsAttributeEditorContext mEditorContext;
298  QgsMapCanvas *mCanvas = nullptr;
299  QgsMessageBar *mMessageBar = nullptr;
300  QVariantList mForeignKeys;
301  QgsFeature mFeature;
302  QgsFeature mFormFeature;
303  // Index of the referenced layer key
304  QStringList mReferencedFields;
305  bool mAllowNull = true;
306  QgsHighlight *mHighlight = nullptr;
307  QgsMapTool *mCurrentMapTool = nullptr;
310  QgsMessageBarItem *mMessageBarItem = nullptr;
311  QgsAttributeForm *mReferencedAttributeForm = nullptr;
312  QgsVectorLayer *mReferencedLayer = nullptr;
313  QgsVectorLayer *mReferencingLayer = nullptr;
314  QgsFeatureListComboBox *mComboBox = nullptr;
315  QList<QComboBox *> mFilterComboBoxes;
316  QWidget *mWindowWidget = nullptr;
317  bool mShown = false;
318  QgsRelation mRelation;
319  bool mIsEditable = true;
320  QStringList mFilterFields;
321  QMap<QString, QMap<QString, QSet<QString> > > mFilterCache;
322  bool mInitialized = false;
323 
324  // Q_PROPERTY
325  bool mEmbedForm = false;
326  bool mReadOnlySelector = false;
327  bool mAllowMapIdentification = false;
328  bool mOrderByValue = false;
329  bool mOpenFormButtonVisible = true;
330  bool mChainFilters = false;
331  bool mAllowAddFeatures = false;
332  QString mReferencedLayerId;
333  QString mReferencedLayerName;
334  QString mReferencedLayerDataSource;
335  QString mReferencedLayerProviderKey;
336 
337  // UI
338  QVBoxLayout *mTopLayout = nullptr;
339  QToolButton *mMapIdentificationButton = nullptr;
340  QToolButton *mRemoveFKButton = nullptr;
341  QToolButton *mOpenFormButton = nullptr;
342  QToolButton *mHighlightFeatureButton = nullptr;
343  QToolButton *mAddEntryButton = nullptr;
344  QAction *mHighlightFeatureAction = nullptr;
345  QAction *mScaleHighlightFeatureAction = nullptr;
346  QAction *mPanHighlightFeatureAction = nullptr;
347  QWidget *mChooserContainer = nullptr;
348  QWidget *mFilterContainer = nullptr;
349  QHBoxLayout *mFilterLayout = nullptr;
350  QgsCollapsibleGroupBox *mAttributeEditorFrame = nullptr;
351  QVBoxLayout *mAttributeEditorLayout = nullptr;
352  QLineEdit *mLineEdit = nullptr;
353  QLabel *mInvalidLabel = nullptr;
354 
355  friend class TestQgsRelationReferenceWidget;
356 };
357 
358 #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
Definition: qgsmapcanvas.h:83
qgsfeature.h
QgsVectorLayerTools
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
Definition: qgscollapsiblegroupbox.h:178
QgsRelationReferenceWidget::chainFilters
bool chainFilters() const
Determines if the filters are chained.
Definition: qgsrelationreferencewidget.h:150
QgsHighlight
Definition: qgshighlight.h:57
QgsMapTool
Definition: qgsmaptool.h:63
SIP_DEPRECATED
#define SIP_DEPRECATED
Definition: qgis_sip.h:106
QgsRelationReferenceWidget::readOnlySelector
bool readOnlySelector()
determines if the foreign key is shown in a combox box or a read-only line edit
Definition: qgsrelationreferencewidget.h:127
SIP_CONVERT_TO_SUBCLASS_CODE
#define SIP_CONVERT_TO_SUBCLASS_CODE(code)
Definition: qgis_sip.h:172
QObjectUniquePtr< QgsMapToolIdentifyFeature >
QgsMessageBarItem
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
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
Definition: qgsfeaturelistcombobox.h:39
qgsattributeeditorcontext.h
QgsVectorLayer
Definition: qgsvectorlayer.h:385
QgsRelationReferenceWidget::CanvasExtent
CanvasExtent
Definition: qgsrelationreferencewidget.h:74
QgsRelation
Definition: qgsrelation.h:41
QgsFeature
Definition: qgsfeature.h:55
QgsAttributeForm
Definition: qgsattributeform.h:44
qgsrelationreferencewidget.h
QgsAttributeEditorContext
Definition: qgsattributeeditorcontext.h:40
SIP_END
#define SIP_END
Definition: qgis_sip.h:189
SIP_TRANSFERTHIS
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:53