QGIS API Documentation 3.99.0-Master (26c88405ac0)
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
19#include "qgis_gui.h"
20#include "qgis_sip.h"
22#include "qgsfeature.h"
23#include "qobjectuniqueptr.h"
24
25#include <QComboBox>
26#include <QHBoxLayout>
27#include <QLineEdit>
28#include <QStandardItemModel>
29#include <QToolButton>
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
71
72 public:
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() const { return mEmbedForm; }
123 void setEmbedForm( bool display );
124
126 bool readOnlySelector() const { return mReadOnlySelector; }
127 void setReadOnlySelector( bool readOnly );
128
130 bool allowMapIdentification() const { return mAllowMapIdentification; }
131 void setAllowMapIdentification( bool allowMapIdentification );
132
134 void setFilterFields( const QStringList &filterFields );
135
137 bool openFormButtonVisible() const { 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
274 QString orderExpression() const { return mOrderExpression; }
275
281 void setOrderExpression( const QString &orderExpression ) { mOrderExpression = orderExpression; }
282
288 Qt::SortOrder sortOrder() const { return mSortOrder; }
289
295 void setSortOrder( const Qt::SortOrder sortOrder ) { mSortOrder = sortOrder; }
296
297 public slots:
299 void openForm();
300
302 void mapIdentification();
303
305 void deleteForeignKeys();
306
313 bool saveReferencedAttributeForm();
314
315 protected:
316 void showEvent( QShowEvent *e ) override;
317
318 void init();
319
320 signals:
321
326 Q_DECL_DEPRECATED void foreignKeyChanged( const QVariant &key ) SIP_DEPRECATED;
327
332 void foreignKeysChanged( const QVariantList &keys );
333
334 private slots:
335 void highlightActionTriggered( QAction *action );
336 void deleteHighlight();
337 void comboReferenceChanged();
338 void comboReferenceFoundChanged( bool found );
339 void featureIdentified( const QgsFeature &feature );
340 void setMapTool( QgsMapTool *mapTool );
341 void unsetMapTool();
342 void mapToolDeactivated();
343 void filterChanged();
344 void addEntry();
345 void updateAddEntryButton();
346 void entryAdded( const QgsFeature &f );
347 void onKeyPressed( QKeyEvent *e );
348
349 private:
350 void highlightFeature( QgsFeature f = QgsFeature(), CanvasExtent canvasExtent = Fixed );
351 void updateAttributeEditorFrame( const QgsFeature &feature );
352 void disableChainedComboBoxes( const QComboBox *cb );
353 void emitForeignKeysChanged( const QVariantList &foreignKeys, bool force = false );
354
355 // initialized
356 QgsAttributeEditorContext mEditorContext;
357 QgsMapCanvas *mCanvas = nullptr;
358 QgsMessageBar *mMessageBar = nullptr;
359 QVariantList mForeignKeys;
360 QgsFeature mFeature;
361 // Index of the referenced layer key
362 QStringList mReferencedFields;
363 bool mAllowNull = true;
364 QgsHighlight *mHighlight = nullptr;
365 QgsMapTool *mCurrentMapTool = nullptr;
368 QgsMessageBarItem *mMessageBarItem = nullptr;
369 QgsAttributeForm *mReferencedAttributeForm = nullptr;
370 QgsVectorLayer *mReferencedLayer = nullptr;
371 QgsVectorLayer *mReferencingLayer = nullptr;
372 QgsFeatureListComboBox *mComboBox = nullptr;
373 QList<QComboBox *> mFilterComboBoxes;
374 QString mFilterExpression;
375 QWidget *mWindowWidget = nullptr;
376 bool mShown = false;
377 QgsRelation mRelation;
378 bool mIsEditable = true;
379 QStringList mFilterFields;
380 QMap<QString, QMap<QString, QSet<QString>>> mFilterCache;
381 bool mInitialized = false;
382 int mFetchLimit = 0;
383
384 // Q_PROPERTY
385 bool mEmbedForm = false;
386 bool mReadOnlySelector = false;
387 bool mAllowMapIdentification = false;
388 bool mOpenFormButtonVisible = true;
389 bool mChainFilters = false;
390 bool mAllowAddFeatures = false;
391 QString mReferencedLayerId;
392 QString mReferencedLayerName;
393 QString mReferencedLayerDataSource;
394 QString mReferencedLayerProviderKey;
395 QString mOrderExpression;
396 Qt::SortOrder mSortOrder = Qt::AscendingOrder;
397
398 // UI
399 QVBoxLayout *mTopLayout = nullptr;
400 QToolButton *mMapIdentificationButton = nullptr;
401 QToolButton *mRemoveFKButton = nullptr;
402 QToolButton *mOpenFormButton = nullptr;
403 QToolButton *mHighlightFeatureButton = nullptr;
404 QToolButton *mAddEntryButton = nullptr;
405 QAction *mHighlightFeatureAction = nullptr;
406 QAction *mScaleHighlightFeatureAction = nullptr;
407 QAction *mPanHighlightFeatureAction = nullptr;
408 QWidget *mChooserContainer = nullptr;
409 QWidget *mFilterContainer = nullptr;
410 QHBoxLayout *mFilterLayout = nullptr;
411 QgsCollapsibleGroupBox *mAttributeEditorFrame = nullptr;
412 QVBoxLayout *mAttributeEditorLayout = nullptr;
413 QLabel *mInvalidLabel = nullptr;
414
416};
417
418#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.
bool readOnlySelector() const
determines if the drop-down is enabled
bool allowMapIdentification() const
determines if the widget offers the possibility to select the related feature on the map (using a ded...
Qt::SortOrder sortOrder() const
Returns the order direction The order direction will be used for sort values in the combobox.
bool embedForm() const
determines if the form of the related feature will be shown
QString filterExpression() const
Returns the currently set filter expression.
bool openFormButtonVisible() const
determines the open form button is visible in the widget
void setSortOrder(const Qt::SortOrder sortOrder)
Set the order direction The order direction will be used for sort values in the combobox.
Q_DECL_DEPRECATED void foreignKeyChanged(const QVariant &key)
Emitted when the foreign key changed.
bool chainFilters() const
Determines if the filters are chained.
QVariantList foreignKeys() const
returns the related feature foreign key
QString orderExpression() const
Returns the string of the order expression The order expression will be used for sort values in the c...
void foreignKeysChanged(const QVariantList &keys)
Emitted when the foreign keys changed.
void setOpenFormButtonVisible(bool openFormButtonVisible)
int fetchLimit() const
Returns the limit of fetched features (0 means all features).
void setOrderExpression(const QString &orderExpression)
Set the string of the order expression The order expression will be used for sort values in the combo...
void setFetchLimit(int fetchLimit)
Set the limit of fetched features (0 means all features).
Represents a relationship between two vector layers.
Definition qgsrelation.h:42
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:199
#define SIP_DEPRECATED
Definition qgis_sip.h:114
#define SIP_TRANSFERTHIS
Definition qgis_sip.h:53
#define SIP_END
Definition qgis_sip.h:216