QGIS API Documentation 3.43.0-Master (b60ef06885e)
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
58class GUI_EXPORT QgsRelationReferenceWidget : public QWidget
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:
74 {
77 Scale
78 };
79
80 explicit QgsRelationReferenceWidget( QWidget *parent SIP_TRANSFERTHIS );
81
83
84 void setRelation( const QgsRelation &relation, bool allowNullValue );
85
86 void setRelationEditable( bool editable );
87
92 Q_DECL_DEPRECATED void setForeignKey( const QVariant &value ) SIP_DEPRECATED;
93
98 void setForeignKeys( const QVariantList &values );
99
104 Q_DECL_DEPRECATED QVariant foreignKey() const SIP_DEPRECATED;
105
107
112 QVariantList foreignKeys() const;
113
119 void setEditorContext( const QgsAttributeEditorContext &context, QgsMapCanvas *canvas, QgsMessageBar *messageBar );
120
122 bool embedForm() { return mEmbedForm; }
123 void setEmbedForm( bool display );
124
126 bool readOnlySelector() { return mReadOnlySelector; }
127 void setReadOnlySelector( bool readOnly );
128
130 bool allowMapIdentification() { return mAllowMapIdentification; }
131 void setAllowMapIdentification( bool allowMapIdentification );
132
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
158 QString filterExpression() const { return mFilterExpression; };
159
164 void setFilterExpression( const QString &filterExpression );
165
170 QgsFeature referencedFeature() const;
171
175 void showIndeterminateState();
176
181 bool allowAddFeatures() const;
182
187 void setAllowAddFeatures( bool allowAddFeatures );
188
193 QgsRelation relation() const;
194
200 void setFormFeature( const QgsFeature &formFeature );
201
207 void setParentFormFeature( const QgsFeature &parentFormFeature );
208
213 QString referencedLayerDataSource() const;
214
219 void setReferencedLayerDataSource( const QString &referencedLayerDataSource );
220
225 QString referencedLayerProviderKey() const;
226
231 void setReferencedLayerProviderKey( const QString &referencedLayerProviderKey );
232
237 QString referencedLayerId() const;
238
243 void setReferencedLayerId( const QString &referencedLayerId );
244
249 QString referencedLayerName() const;
250
255 void setReferencedLayerName( const QString &referencedLayerName );
256
261 int fetchLimit() const { return mFetchLimit; }
262
267 void setFetchLimit( int fetchLimit ) { mFetchLimit = fetchLimit; }
268
269 public slots:
271 void openForm();
272
274 void mapIdentification();
275
277 void deleteForeignKeys();
278
285 bool saveReferencedAttributeForm();
286
287 protected:
288 void showEvent( QShowEvent *e ) override;
289
290 void init();
291
292 signals:
293
298 Q_DECL_DEPRECATED void foreignKeyChanged( const QVariant &key ) SIP_DEPRECATED;
299
304 void foreignKeysChanged( const QVariantList &keys );
305
306 private slots:
307 void highlightActionTriggered( QAction *action );
308 void deleteHighlight();
309 void comboReferenceChanged();
310 void comboReferenceFoundChanged( bool found );
311 void featureIdentified( const QgsFeature &feature );
312 void setMapTool( QgsMapTool *mapTool );
313 void unsetMapTool();
314 void mapToolDeactivated();
315 void filterChanged();
316 void addEntry();
317 void updateAddEntryButton();
318 void entryAdded( const QgsFeature &f );
319 void onKeyPressed( QKeyEvent *e );
320
321 private:
322 void highlightFeature( QgsFeature f = QgsFeature(), CanvasExtent canvasExtent = Fixed );
323 void updateAttributeEditorFrame( const QgsFeature &feature );
324 void disableChainedComboBoxes( const QComboBox *cb );
325 void emitForeignKeysChanged( const QVariantList &foreignKeys, bool force = false );
326
327 // initialized
328 QgsAttributeEditorContext mEditorContext;
329 QgsMapCanvas *mCanvas = nullptr;
330 QgsMessageBar *mMessageBar = nullptr;
331 QVariantList mForeignKeys;
332 QgsFeature mFeature;
333 // Index of the referenced layer key
334 QStringList mReferencedFields;
335 bool mAllowNull = true;
336 QgsHighlight *mHighlight = nullptr;
337 QgsMapTool *mCurrentMapTool = nullptr;
340 QgsMessageBarItem *mMessageBarItem = nullptr;
341 QgsAttributeForm *mReferencedAttributeForm = nullptr;
342 QgsVectorLayer *mReferencedLayer = nullptr;
343 QgsVectorLayer *mReferencingLayer = nullptr;
344 QgsFeatureListComboBox *mComboBox = nullptr;
345 QList<QComboBox *> mFilterComboBoxes;
346 QString mFilterExpression;
347 QWidget *mWindowWidget = nullptr;
348 bool mShown = false;
349 QgsRelation mRelation;
350 bool mIsEditable = true;
351 QStringList mFilterFields;
352 QMap<QString, QMap<QString, QSet<QString>>> mFilterCache;
353 bool mInitialized = false;
354 int mFetchLimit = 0;
355
356 // Q_PROPERTY
357 bool mEmbedForm = false;
358 bool mReadOnlySelector = false;
359 bool mAllowMapIdentification = false;
360 bool mOpenFormButtonVisible = true;
361 bool mChainFilters = false;
362 bool mAllowAddFeatures = false;
363 QString mReferencedLayerId;
364 QString mReferencedLayerName;
365 QString mReferencedLayerDataSource;
366 QString mReferencedLayerProviderKey;
367
368 // UI
369 QVBoxLayout *mTopLayout = nullptr;
370 QToolButton *mMapIdentificationButton = nullptr;
371 QToolButton *mRemoveFKButton = nullptr;
372 QToolButton *mOpenFormButton = nullptr;
373 QToolButton *mHighlightFeatureButton = nullptr;
374 QToolButton *mAddEntryButton = nullptr;
375 QAction *mHighlightFeatureAction = nullptr;
376 QAction *mScaleHighlightFeatureAction = nullptr;
377 QAction *mPanHighlightFeatureAction = nullptr;
378 QWidget *mChooserContainer = nullptr;
379 QWidget *mFilterContainer = nullptr;
380 QHBoxLayout *mFilterLayout = nullptr;
381 QgsCollapsibleGroupBox *mAttributeEditorFrame = nullptr;
382 QVBoxLayout *mAttributeEditorLayout = nullptr;
383 QLabel *mInvalidLabel = nullptr;
384
385 friend class TestQgsRelationReferenceWidget;
386};
387
388#endif // QGSRELATIONREFERENCEWIDGET_H
Keeps a pointer to a QObject and deletes it whenever this object is deleted.
Contains context information for attribute editor widgets.
The attribute form widget for vector layer features.
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:58
Highlights features on the map.
Map canvas is a class for displaying all GIS data types on a canvas.
This tool digitizes geometry of new point/line/polygon features on already existing vector layers.
A map tool to identify a feature on a chosen layer.
Abstract base class for all map tools.
Definition qgsmaptool.h:72
Represents an item shown within a QgsMessageBar widget.
A bar for displaying non-blocking messages to the user.
A widget which shows related features.
QString filterExpression() const
Returns the currently set filter expression.
bool openFormButtonVisible()
determines the open form button is visible in the widget
bool allowMapIdentification()
determines if the widget offers the possibility to select the related feature on the map (using a ded...
Q_DECL_DEPRECATED void foreignKeyChanged(const QVariant &key)
Emitted when the foreign key changed.
bool chainFilters() const
Determines if the filters are chained.
void foreignKeysChanged(const QVariantList &keys)
Emitted when the foreign keys changed.
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)
Represents a relationship between two vector layers.
Definition qgsrelation.h:44
Used to handle basic editing operations on vector layers.
Represents a vector layer which manages a vector based dataset.
#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