QGIS API Documentation  3.12.1-BucureČ™ti (121cc00ff0)
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 
294  void updateIndex();
295 
296  private:
297  void highlightFeature( QgsFeature f = QgsFeature(), CanvasExtent canvasExtent = Fixed );
298  void updateAttributeEditorFrame( const QgsFeature &feature );
299  void disableChainedComboBoxes( const QComboBox *cb );
300  void emitForeignKeysChanged( const QVariantList &foreignKeys, bool force = false );
301 
302  // initialized
303  QgsAttributeEditorContext mEditorContext;
304  QgsMapCanvas *mCanvas = nullptr;
305  QgsMessageBar *mMessageBar = nullptr;
306  QVariantList mForeignKeys;
307  QgsFeature mFeature;
308  QgsFeature mFormFeature;
309  // Index of the referenced layer key
310  QStringList mReferencedFields;
311  bool mAllowNull = true;
312  QgsHighlight *mHighlight = nullptr;
313  QgsMapTool *mCurrentMapTool = nullptr;
316  QgsMessageBarItem *mMessageBarItem = nullptr;
317  QgsAttributeForm *mReferencedAttributeForm = nullptr;
318  QgsVectorLayer *mReferencedLayer = nullptr;
319  QgsVectorLayer *mReferencingLayer = nullptr;
320  QgsFeatureListComboBox *mComboBox = nullptr;
321  QList<QComboBox *> mFilterComboBoxes;
322  QWidget *mWindowWidget = nullptr;
323  bool mShown = false;
324  QgsRelation mRelation;
325  bool mIsEditable = true;
326  QStringList mFilterFields;
327  QMap<QString, QMap<QString, QSet<QString> > > mFilterCache;
328  bool mInitialized = false;
329 
330  // Q_PROPERTY
331  bool mEmbedForm = false;
332  bool mReadOnlySelector = false;
333  bool mAllowMapIdentification = false;
334  bool mOrderByValue = false;
335  bool mOpenFormButtonVisible = true;
336  bool mChainFilters = false;
337  bool mAllowAddFeatures = false;
338  QString mReferencedLayerId;
339  QString mReferencedLayerName;
340  QString mReferencedLayerDataSource;
341  QString mReferencedLayerProviderKey;
342 
343  // UI
344  QVBoxLayout *mTopLayout = nullptr;
345  QToolButton *mMapIdentificationButton = nullptr;
346  QToolButton *mRemoveFKButton = nullptr;
347  QToolButton *mOpenFormButton = nullptr;
348  QToolButton *mHighlightFeatureButton = nullptr;
349  QToolButton *mAddEntryButton = nullptr;
350  QAction *mHighlightFeatureAction = nullptr;
351  QAction *mScaleHighlightFeatureAction = nullptr;
352  QAction *mPanHighlightFeatureAction = nullptr;
353  QWidget *mChooserContainer = nullptr;
354  QWidget *mFilterContainer = nullptr;
355  QHBoxLayout *mFilterLayout = nullptr;
356  QgsCollapsibleGroupBox *mAttributeEditorFrame = nullptr;
357  QVBoxLayout *mAttributeEditorLayout = nullptr;
358  QLineEdit *mLineEdit = nullptr;
359  QLabel *mInvalidLabel = nullptr;
360 
361  friend class TestQgsRelationReferenceWidget;
362 };
363 
364 #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