QGIS API Documentation 3.37.0-Master (fdefdf9c27f)
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
33class QgsMapCanvas;
34class QgsMessageBar;
35class QgsHighlight;
36class QgsMapTool;
42class 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
57class 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;
67#endif
68
69 Q_OBJECT
70 Q_PROPERTY( bool openFormButtonVisible READ openFormButtonVisible WRITE setOpenFormButtonVisible )
71
72 public:
73
75 {
78 Scale
79 };
80
81 explicit QgsRelationReferenceWidget( QWidget *parent SIP_TRANSFERTHIS );
82
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 void setFilterFields( const QStringList &filterFields );
136
138 bool openFormButtonVisible() { return mOpenFormButtonVisible; }
139 void setOpenFormButtonVisible( bool openFormButtonVisible );
140
146 bool chainFilters() const { return mChainFilters; }
147
154 void setChainFilters( bool chainFilters );
155
159 QString filterExpression() const { return mFilterExpression; };
160
165 void setFilterExpression( const QString &filterExpression );
166
171 QgsFeature referencedFeature() const;
172
176 void showIndeterminateState();
177
182 bool allowAddFeatures() const;
183
188 void setAllowAddFeatures( bool allowAddFeatures );
189
194 QgsRelation relation() const;
195
201 void setFormFeature( const QgsFeature &formFeature );
202
207 QString referencedLayerDataSource() const;
208
213 void setReferencedLayerDataSource( const QString &referencedLayerDataSource );
214
219 QString referencedLayerProviderKey() const;
220
225 void setReferencedLayerProviderKey( const QString &referencedLayerProviderKey );
226
231 QString referencedLayerId() const;
232
237 void setReferencedLayerId( const QString &referencedLayerId );
238
243 QString referencedLayerName() const;
244
249 void setReferencedLayerName( const QString &referencedLayerName );
250
255 int fetchLimit() const {return mFetchLimit; }
256
261 void setFetchLimit( int fetchLimit ) {mFetchLimit = fetchLimit; }
262
263
264 public slots:
266 void openForm();
267
269 void mapIdentification();
270
272 void deleteForeignKeys();
273
274 protected:
275 void showEvent( QShowEvent *e ) override;
276
277 void init();
278
279 signals:
280
285 Q_DECL_DEPRECATED void foreignKeyChanged( const QVariant & ) SIP_DEPRECATED;
286
291 void foreignKeysChanged( const QVariantList & );
292
293 private slots:
294 void highlightActionTriggered( QAction *action );
295 void deleteHighlight();
296 void comboReferenceChanged();
297 void featureIdentified( const QgsFeature &feature );
298 void setMapTool( QgsMapTool *mapTool );
299 void unsetMapTool();
300 void mapToolDeactivated();
301 void filterChanged();
302 void addEntry();
303 void updateAddEntryButton();
304 void entryAdded( const QgsFeature &f );
305 void onKeyPressed( QKeyEvent *e );
306
307 private:
308 void highlightFeature( QgsFeature f = QgsFeature(), CanvasExtent canvasExtent = Fixed );
309 void updateAttributeEditorFrame( const QgsFeature &feature );
310 void disableChainedComboBoxes( const QComboBox *cb );
311 void emitForeignKeysChanged( const QVariantList &foreignKeys, bool force = false );
312
313 // initialized
314 QgsAttributeEditorContext mEditorContext;
315 QgsMapCanvas *mCanvas = nullptr;
316 QgsMessageBar *mMessageBar = nullptr;
317 QVariantList mForeignKeys;
318 QgsFeature mFeature;
319 QgsFeature mFormFeature;
320 // Index of the referenced layer key
321 QStringList mReferencedFields;
322 bool mAllowNull = true;
323 QgsHighlight *mHighlight = nullptr;
324 QgsMapTool *mCurrentMapTool = nullptr;
327 QgsMessageBarItem *mMessageBarItem = nullptr;
328 QgsAttributeForm *mReferencedAttributeForm = nullptr;
329 QgsVectorLayer *mReferencedLayer = nullptr;
330 QgsVectorLayer *mReferencingLayer = nullptr;
331 QgsFeatureListComboBox *mComboBox = nullptr;
332 QList<QComboBox *> mFilterComboBoxes;
333 QString mFilterExpression;
334 QWidget *mWindowWidget = nullptr;
335 bool mShown = false;
336 QgsRelation mRelation;
337 bool mIsEditable = true;
338 QStringList mFilterFields;
339 QMap<QString, QMap<QString, QSet<QString> > > mFilterCache;
340 bool mInitialized = false;
341 int mFetchLimit = 0;
342
343 // Q_PROPERTY
344 bool mEmbedForm = false;
345 bool mReadOnlySelector = false;
346 bool mAllowMapIdentification = false;
347 bool mOpenFormButtonVisible = true;
348 bool mChainFilters = false;
349 bool mAllowAddFeatures = false;
350 QString mReferencedLayerId;
351 QString mReferencedLayerName;
352 QString mReferencedLayerDataSource;
353 QString mReferencedLayerProviderKey;
354
355 // UI
356 QVBoxLayout *mTopLayout = nullptr;
357 QToolButton *mMapIdentificationButton = nullptr;
358 QToolButton *mRemoveFKButton = nullptr;
359 QToolButton *mOpenFormButton = nullptr;
360 QToolButton *mHighlightFeatureButton = nullptr;
361 QToolButton *mAddEntryButton = nullptr;
362 QAction *mHighlightFeatureAction = nullptr;
363 QAction *mScaleHighlightFeatureAction = nullptr;
364 QAction *mPanHighlightFeatureAction = nullptr;
365 QWidget *mChooserContainer = nullptr;
366 QWidget *mFilterContainer = nullptr;
367 QHBoxLayout *mFilterLayout = nullptr;
368 QgsCollapsibleGroupBox *mAttributeEditorFrame = nullptr;
369 QVBoxLayout *mAttributeEditorLayout = nullptr;
370 QLabel *mInvalidLabel = nullptr;
371
372 friend class TestQgsRelationReferenceWidget;
373};
374
375#endif // QGSRELATIONREFERENCEWIDGET_H
This class contains context information for attribute editor widgets.
A groupbox that collapses/expands when toggled and can save its collapsed and checked states.
This offers a combobox with autocompleter that allows selecting features from a layer.
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
Definition: qgsfeature.h:56
A class for highlight features on the map.
Definition: qgshighlight.h:62
Map canvas is a class for displaying all GIS data types on a canvas.
Definition: qgsmapcanvas.h:93
This tool digitizes geometry of new point/line/polygon features on already existing vector layers Onc...
The QgsMapToolIdentifyFeature class is a map tool to identify a feature on a chosen layer.
Abstract base class for all map tools.
Definition: qgsmaptool.h:71
Represents an item shown within a QgsMessageBar widget.
A bar for displaying non-blocking messages to the user.
Definition: qgsmessagebar.h:61
QString filterExpression() const
Returns the currently set filter expression.
void foreignKeysChanged(const QVariantList &)
Emitted when the foreign keys changed.
bool openFormButtonVisible()
determines the open form button is visible in the widget
Q_DECL_DEPRECATED void foreignKeyChanged(const QVariant &)
Emitted when the foreign key changed.
bool allowMapIdentification()
determines if the widget offers the possibility to select the related feature on the map (using a ded...
bool chainFilters() const
Determines if the filters are chained.
int fetchLimit() const
Returns the limit of fetched features (0 means all features)
bool readOnlySelector()
determines if the drop-down is enabled
void setFetchLimit(int fetchLimit)
Set the limit of fetched features (0 means all features)
Methods in this class are used to handle basic operations on vector layers.
Represents a vector layer which manages a vector based data sets.
#define SIP_CONVERT_TO_SUBCLASS_CODE(code)
Definition: qgis_sip.h:191
#define SIP_DEPRECATED
Definition: qgis_sip.h:106
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:53
#define SIP_END
Definition: qgis_sip.h:208