QGIS API Documentation 3.41.0-Master (af5edcb665c)
Loading...
Searching...
No Matches
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#ifdef SIP_RUN
61 if ( qobject_cast<QgsRelationReferenceWidget *>( sipCpp ) )
62 sipType = sipType_QgsRelationReferenceWidget;
63 else
64 sipType = NULL;
66#endif
67
68 Q_OBJECT
69 Q_PROPERTY( bool openFormButtonVisible READ openFormButtonVisible WRITE setOpenFormButtonVisible )
70
71 public:
73 {
76 Scale
77 };
78
79 explicit QgsRelationReferenceWidget( QWidget *parent SIP_TRANSFERTHIS );
80
82
83 void setRelation( const QgsRelation &relation, bool allowNullValue );
84
85 void setRelationEditable( bool editable );
86
91 Q_DECL_DEPRECATED void setForeignKey( const QVariant &value ) SIP_DEPRECATED;
92
97 void setForeignKeys( const QVariantList &values );
98
103 Q_DECL_DEPRECATED QVariant foreignKey() const SIP_DEPRECATED;
104
106
111 QVariantList foreignKeys() const;
112
118 void setEditorContext( const QgsAttributeEditorContext &context, QgsMapCanvas *canvas, QgsMessageBar *messageBar );
119
121 bool embedForm() { return mEmbedForm; }
122 void setEmbedForm( bool display );
123
125 bool readOnlySelector() { return mReadOnlySelector; }
126 void setReadOnlySelector( bool readOnly );
127
129 bool allowMapIdentification() { return mAllowMapIdentification; }
130 void setAllowMapIdentification( bool allowMapIdentification );
131
133 void setFilterFields( const QStringList &filterFields );
134
136 bool openFormButtonVisible() { return mOpenFormButtonVisible; }
137 void setOpenFormButtonVisible( bool openFormButtonVisible );
138
144 bool chainFilters() const { return mChainFilters; }
145
152 void setChainFilters( bool chainFilters );
153
157 QString filterExpression() const { return mFilterExpression; };
158
163 void setFilterExpression( const QString &filterExpression );
164
169 QgsFeature referencedFeature() const;
170
174 void showIndeterminateState();
175
180 bool allowAddFeatures() const;
181
186 void setAllowAddFeatures( bool allowAddFeatures );
187
192 QgsRelation relation() const;
193
199 void setFormFeature( const QgsFeature &formFeature );
200
205 QString referencedLayerDataSource() const;
206
211 void setReferencedLayerDataSource( const QString &referencedLayerDataSource );
212
217 QString referencedLayerProviderKey() const;
218
223 void setReferencedLayerProviderKey( const QString &referencedLayerProviderKey );
224
229 QString referencedLayerId() const;
230
235 void setReferencedLayerId( const QString &referencedLayerId );
236
241 QString referencedLayerName() const;
242
247 void setReferencedLayerName( const QString &referencedLayerName );
248
253 int fetchLimit() const { return mFetchLimit; }
254
259 void setFetchLimit( int fetchLimit ) { mFetchLimit = fetchLimit; }
260
261
262 public slots:
264 void openForm();
265
267 void mapIdentification();
268
270 void deleteForeignKeys();
271
272 protected:
273 void showEvent( QShowEvent *e ) override;
274
275 void init();
276
277 signals:
278
283 Q_DECL_DEPRECATED void foreignKeyChanged( const QVariant &key ) SIP_DEPRECATED;
284
289 void foreignKeysChanged( const QVariantList &keys );
290
291 private slots:
292 void highlightActionTriggered( QAction *action );
293 void deleteHighlight();
294 void comboReferenceChanged();
295 void comboReferenceFoundChanged( bool found );
296 void featureIdentified( const QgsFeature &feature );
297 void setMapTool( QgsMapTool *mapTool );
298 void unsetMapTool();
299 void mapToolDeactivated();
300 void filterChanged();
301 void addEntry();
302 void updateAddEntryButton();
303 void entryAdded( const QgsFeature &f );
304 void onKeyPressed( QKeyEvent *e );
305
306 private:
307 void highlightFeature( QgsFeature f = QgsFeature(), CanvasExtent canvasExtent = Fixed );
308 void updateAttributeEditorFrame( const QgsFeature &feature );
309 void disableChainedComboBoxes( const QComboBox *cb );
310 void emitForeignKeysChanged( const QVariantList &foreignKeys, bool force = false );
311
312 // initialized
313 QgsAttributeEditorContext mEditorContext;
314 QgsMapCanvas *mCanvas = nullptr;
315 QgsMessageBar *mMessageBar = nullptr;
316 QVariantList mForeignKeys;
317 QgsFeature mFeature;
318 QgsFeature mFormFeature;
319 // Index of the referenced layer key
320 QStringList mReferencedFields;
321 bool mAllowNull = true;
322 QgsHighlight *mHighlight = nullptr;
323 QgsMapTool *mCurrentMapTool = nullptr;
326 QgsMessageBarItem *mMessageBarItem = nullptr;
327 QgsAttributeForm *mReferencedAttributeForm = nullptr;
328 QgsVectorLayer *mReferencedLayer = nullptr;
329 QgsVectorLayer *mReferencingLayer = nullptr;
330 QgsFeatureListComboBox *mComboBox = nullptr;
331 QList<QComboBox *> mFilterComboBoxes;
332 QString mFilterExpression;
333 QWidget *mWindowWidget = nullptr;
334 bool mShown = false;
335 QgsRelation mRelation;
336 bool mIsEditable = true;
337 QStringList mFilterFields;
338 QMap<QString, QMap<QString, QSet<QString>>> mFilterCache;
339 bool mInitialized = false;
340 int mFetchLimit = 0;
341
342 // Q_PROPERTY
343 bool mEmbedForm = false;
344 bool mReadOnlySelector = false;
345 bool mAllowMapIdentification = false;
346 bool mOpenFormButtonVisible = true;
347 bool mChainFilters = false;
348 bool mAllowAddFeatures = false;
349 QString mReferencedLayerId;
350 QString mReferencedLayerName;
351 QString mReferencedLayerDataSource;
352 QString mReferencedLayerProviderKey;
353
354 // UI
355 QVBoxLayout *mTopLayout = nullptr;
356 QToolButton *mMapIdentificationButton = nullptr;
357 QToolButton *mRemoveFKButton = nullptr;
358 QToolButton *mOpenFormButton = nullptr;
359 QToolButton *mHighlightFeatureButton = nullptr;
360 QToolButton *mAddEntryButton = nullptr;
361 QAction *mHighlightFeatureAction = nullptr;
362 QAction *mScaleHighlightFeatureAction = nullptr;
363 QAction *mPanHighlightFeatureAction = nullptr;
364 QWidget *mChooserContainer = nullptr;
365 QWidget *mFilterContainer = nullptr;
366 QHBoxLayout *mFilterLayout = nullptr;
367 QgsCollapsibleGroupBox *mAttributeEditorFrame = nullptr;
368 QVBoxLayout *mAttributeEditorLayout = nullptr;
369 QLabel *mInvalidLabel = nullptr;
370
371 friend class TestQgsRelationReferenceWidget;
372};
373
374#endif // QGSRELATIONREFERENCEWIDGET_H
Keeps a pointer to a QObject and deletes it whenever this object is deleted.
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:58
A class for highlight 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 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.
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
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