QGIS API Documentation 3.38.0-Grenoble (exported)
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
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 comboReferenceFoundChanged( bool found );
298 void featureIdentified( const QgsFeature &feature );
299 void setMapTool( QgsMapTool *mapTool );
300 void unsetMapTool();
301 void mapToolDeactivated();
302 void filterChanged();
303 void addEntry();
304 void updateAddEntryButton();
305 void entryAdded( const QgsFeature &f );
306 void onKeyPressed( QKeyEvent *e );
307
308 private:
309 void highlightFeature( QgsFeature f = QgsFeature(), CanvasExtent canvasExtent = Fixed );
310 void updateAttributeEditorFrame( const QgsFeature &feature );
311 void disableChainedComboBoxes( const QComboBox *cb );
312 void emitForeignKeysChanged( const QVariantList &foreignKeys, bool force = false );
313
314 // initialized
315 QgsAttributeEditorContext mEditorContext;
316 QgsMapCanvas *mCanvas = nullptr;
317 QgsMessageBar *mMessageBar = nullptr;
318 QVariantList mForeignKeys;
319 QgsFeature mFeature;
320 QgsFeature mFormFeature;
321 // Index of the referenced layer key
322 QStringList mReferencedFields;
323 bool mAllowNull = true;
324 QgsHighlight *mHighlight = nullptr;
325 QgsMapTool *mCurrentMapTool = nullptr;
328 QgsMessageBarItem *mMessageBarItem = nullptr;
329 QgsAttributeForm *mReferencedAttributeForm = nullptr;
330 QgsVectorLayer *mReferencedLayer = nullptr;
331 QgsVectorLayer *mReferencingLayer = nullptr;
332 QgsFeatureListComboBox *mComboBox = nullptr;
333 QList<QComboBox *> mFilterComboBoxes;
334 QString mFilterExpression;
335 QWidget *mWindowWidget = nullptr;
336 bool mShown = false;
337 QgsRelation mRelation;
338 bool mIsEditable = true;
339 QStringList mFilterFields;
340 QMap<QString, QMap<QString, QSet<QString> > > mFilterCache;
341 bool mInitialized = false;
342 int mFetchLimit = 0;
343
344 // Q_PROPERTY
345 bool mEmbedForm = false;
346 bool mReadOnlySelector = false;
347 bool mAllowMapIdentification = false;
348 bool mOpenFormButtonVisible = true;
349 bool mChainFilters = false;
350 bool mAllowAddFeatures = false;
351 QString mReferencedLayerId;
352 QString mReferencedLayerName;
353 QString mReferencedLayerDataSource;
354 QString mReferencedLayerProviderKey;
355
356 // UI
357 QVBoxLayout *mTopLayout = nullptr;
358 QToolButton *mMapIdentificationButton = nullptr;
359 QToolButton *mRemoveFKButton = nullptr;
360 QToolButton *mOpenFormButton = nullptr;
361 QToolButton *mHighlightFeatureButton = nullptr;
362 QToolButton *mAddEntryButton = nullptr;
363 QAction *mHighlightFeatureAction = nullptr;
364 QAction *mScaleHighlightFeatureAction = nullptr;
365 QAction *mPanHighlightFeatureAction = nullptr;
366 QWidget *mChooserContainer = nullptr;
367 QWidget *mFilterContainer = nullptr;
368 QHBoxLayout *mFilterLayout = nullptr;
369 QgsCollapsibleGroupBox *mAttributeEditorFrame = nullptr;
370 QVBoxLayout *mAttributeEditorLayout = nullptr;
371 QLabel *mInvalidLabel = nullptr;
372
373 friend class TestQgsRelationReferenceWidget;
374};
375
376#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.
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