QGIS API Documentation 3.99.0-Master (2fe06baccd8)
Loading...
Searching...
No Matches
qgsabstractrelationeditorwidget.h
Go to the documentation of this file.
1/***************************************************************************
2 qgsabstractrelationeditorwidget.h
3 ----------------------
4 begin : October 2020
5 copyright : (C) 2020 by Ivan Ivanov
7 ***************************************************************************/
8
9/***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 ***************************************************************************/
17
18#ifndef QGSABSTRACTRELATIONEDITORWIDGET_H
19#define QGSABSTRACTRELATIONEDITORWIDGET_H
20
21#include "qgis_gui.h"
22#include "qgis_sip.h"
24#include "qgsrelation.h"
25#include "qobjectuniqueptr.h"
26
27#include <QWidget>
28
29#ifdef SIP_RUN
30// this is needed for the "convert to subclass" code below to compile
31//%ModuleHeaderCode
33//%End
34#endif
35
36class QgsFeature;
37class QgsVectorLayer;
38
45class GUI_EXPORT QgsAbstractRelationEditorWidget : public QWidget
46{
47#ifdef SIP_RUN
49 if ( qobject_cast<QgsRelationEditorWidget *>( sipCpp ) )
50 sipType = sipType_QgsRelationEditorWidget;
51 else
52 sipType = 0;
54#endif
55
56 Q_OBJECT
57
58 public:
62 QgsAbstractRelationEditorWidget( const QVariantMap &config, QWidget *parent SIP_TRANSFERTHIS = nullptr );
63
68
78 void setRelations( const QgsRelation &relation, const QgsRelation &nmrelation );
79
84 QgsRelation relation() const { return mRelation; }
85
91
95 void setFeature( const QgsFeature &feature, bool update = true );
96
102 void setMultiEditFeatureIds( const QgsFeatureIds &fids );
103
109 virtual void setEditorContext( const QgsAttributeEditorContext &context );
110
114 QgsAttributeEditorContext editorContext() const;
115
120 Q_DECL_DEPRECATED bool showLabel() const SIP_DEPRECATED;
121
126 Q_DECL_DEPRECATED void setShowLabel( bool showLabel ) SIP_DEPRECATED;
127
131 QVariant nmRelationId() const;
132
137 void setNmRelationId( const QVariant &nmRelationId = QVariant() );
138
143 Q_DECL_DEPRECATED QString label() const SIP_DEPRECATED;
144
149 void setLabel( const QString &label = QString() );
150
156 QgsFeature feature() const;
157
162 QList<QgsFeature> features() const;
163
167 bool forceSuppressFormPopup() const;
168
173 void setForceSuppressFormPopup( bool forceSuppressFormPopup );
174
178 virtual QVariantMap config() const = 0;
179
183 virtual void setConfig( const QVariantMap &config ) = 0;
184
189 bool multiEditModeActive() const;
190
191 signals:
192
201
202 public slots:
203
207 virtual void parentFormValueChanged( const QString &attribute, const QVariant &newValue ) = 0;
208
209 protected slots:
210
214 void toggleEditing( bool state );
215
219 void saveEdits();
220
225 QgsFeatureIds addFeature( const QgsGeometry &geometry = QgsGeometry() );
226
231
236 void linkFeature( const QString &filterExpression = QString() );
237
242
247
251 void duplicateFeature( const QgsFeatureId &fid );
252
256 void duplicateFeatures( const QgsFeatureIds &fids );
257
258 protected:
263
265
267
271 void showEvent( QShowEvent * ) override;
272
277 Q_DECL_DEPRECATED void updateTitle() SIP_DEPRECATED;
278
282 void deleteFeatures( const QgsFeatureIds &fids );
283
287 void unlinkFeatures( const QgsFeatureIds &fids );
288
289 // Following virtual methods need to be protected so they can be overridden in bindings
290
297 virtual void updateUi();
298
303 Q_DECL_DEPRECATED virtual void setTitle( const QString &title ) SIP_DEPRECATED;
304
309 virtual void beforeSetRelationFeature( const QgsRelation &newRelation, const QgsFeature &newFeature );
310
315 virtual void afterSetRelationFeature();
316
321 virtual void beforeSetRelations( const QgsRelation &newRelation, const QgsRelation &newNmRelation );
322
327 virtual void afterSetRelations();
328};
329
330
340class GUI_EXPORT QgsAbstractRelationEditorConfigWidget : public QWidget
341{
342#ifdef SIP_RUN
344 if ( qobject_cast<QgsRelationEditorConfigWidget *>( sipCpp ) )
345 sipType = sipType_QgsRelationEditorConfigWidget;
346 else
347 sipType = 0;
348 SIP_END
349#endif
350
351 Q_OBJECT
352 public:
360
366 virtual QVariantMap config() = 0;
367
373 virtual void setConfig( const QVariantMap &config ) = 0;
374
381
387 QgsRelation relation() const;
388
394 virtual void setNmRelation( const QgsRelation &nmRelation );
395
401 virtual QgsRelation nmRelation() const;
402
403 private:
404 QgsVectorLayer *mLayer = nullptr;
405 QgsRelation mRelation;
406 QgsRelation mNmRelation;
407};
408
409
411
412
420{
421 public:
426
428
432 virtual QString type() const = 0;
433
437 virtual QString name() const = 0;
438
449 virtual QgsAbstractRelationEditorWidget *create( const QVariantMap &config, QWidget *parent = nullptr ) const = 0 SIP_FACTORY;
450
460 virtual QgsAbstractRelationEditorConfigWidget *configWidget( const QgsRelation &relation, QWidget *parent ) const = 0 SIP_FACTORY;
461};
462
463#endif // QGSABSTRACTRELATIONEDITORWIDGET_H
Abstract base class for configurable relation widget types.
virtual void setNmRelation(const QgsRelation &nmRelation)
Set the nm relation for this widget.
QgsRelation relation() const
Returns the relation for which this configuration widget applies.
virtual QgsRelation nmRelation() const
Returns the nm relation for which this configuration widget applies.
QgsAbstractRelationEditorConfigWidget(const QgsRelation &relation, QWidget *parent)
Create a new configuration widget.
virtual QVariantMap config()=0
Create a configuration from the current GUI state.
QgsVectorLayer * layer()
Returns the layer for which this configuration widget applies.
virtual void setConfig(const QVariantMap &config)=0
Update the configuration widget to represent the given configuration.
virtual QString type() const =0
Returns the machine readable identifier name of this widget type.
virtual QString name() const =0
Returns the human readable identifier name of this widget type.
virtual QgsAbstractRelationEditorConfigWidget * configWidget(const QgsRelation &relation, QWidget *parent) const =0
Override this in your implementation.
virtual QgsAbstractRelationEditorWidget * create(const QVariantMap &config, QWidget *parent=nullptr) const =0
Override this in your implementation.
virtual ~QgsAbstractRelationEditorWidgetFactory()=default
QgsAbstractRelationEditorWidgetFactory()
Creates a new relation widget factory with given name.
Base class to build new relation widgets.
void toggleEditing(bool state)
Toggles editing state of the widget.
QgsFeatureIds addFeature(const QgsGeometry &geometry=QgsGeometry())
Adds new features with given geometry Returns the Id of added features.
void deleteFeatures(const QgsFeatureIds &fids)
Deletes the features with fids.
virtual void setConfig(const QVariantMap &config)=0
Defines the widget configuration.
void onLinkFeatureDlgAccepted()
Called when the link feature dialog is confirmed by the user.
virtual void afterSetRelations()
A hook called right after setRelations() is executed, but before updateUi() is called.
void setRelationFeature(const QgsRelation &relation, const QgsFeature &feature)
Sets the relation and the feature.
virtual Q_DECL_DEPRECATED void setTitle(const QString &title)
Sets the title of the widget, if it is wrapped within a QgsCollapsibleGroupBox.
void linkFeature(const QString &filterExpression=QString())
Links a new feature to the relation.
Q_DECL_DEPRECATED void updateTitle()
Updates the title contents to reflect the current state of the widget.
void showEvent(QShowEvent *) override
Refresh the UI when the widget becomes visible.
QgsAbstractRelationEditorWidget(const QVariantMap &config, QWidget *parent=nullptr)
Constructor.
void relatedFeaturesChanged()
Emit this signal, whenever the related features changed.
void setRelations(const QgsRelation &relation, const QgsRelation &nmrelation)
Sets the relation(s) for this widget If only one relation is set, it will act as a simple 1:N relatio...
virtual void beforeSetRelations(const QgsRelation &newRelation, const QgsRelation &newNmRelation)
A hook called right before setRelations() is executed.
virtual void updateUi()
A hook called every time the state of the relation editor widget has changed via calling its set* met...
QgsRelation relation() const
Returns the relation.
virtual QVariantMap config() const =0
Returns the widget configuration.
virtual void beforeSetRelationFeature(const QgsRelation &newRelation, const QgsFeature &newFeature)
A hook called right before setRelationFeature() is executed.
virtual void parentFormValueChanged(const QString &attribute, const QVariant &newValue)=0
Called when an attribute value in the parent widget has changed to newValue.
void unlinkFeatures(const QgsFeatureIds &fids)
Unlinks the features with fids.
void deleteFeature(QgsFeatureId fid=QgsFeatureId())
Delete a feature with given fid.
QgsFeature feature() const
Returns the widget's current feature If the widget is in multiedit mode only the first is returned.
virtual void afterSetRelationFeature()
A hook called right after setRelationFeature() is executed, but before updateUi() is called.
bool multiEditModeActive() const
Returns true if editing multiple features at a time.
void saveEdits()
Saves the current modifications in the relation.
QgsRelation nmRelation() const
Returns the nm relation.
void unlinkFeature(QgsFeatureId fid=QgsFeatureId())
Unlinks a feature with given fid.
void duplicateFeature(const QgsFeatureId &fid)
Duplicates a feature.
void duplicateFeatures(const QgsFeatureIds &fids)
Duplicates features.
Contains context information for attribute editor widgets.
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
Definition qgsfeature.h:58
A geometry is the spatial representation of a feature.
Represents a relationship between two vector layers.
Definition qgsrelation.h:42
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_FACTORY
Definition qgis_sip.h:84
#define SIP_END
Definition qgis_sip.h:216
QList< QgsFeature > QgsFeatureList
QSet< QgsFeatureId > QgsFeatureIds
qint64 QgsFeatureId
64 bit feature ids negative numbers are used for uncommitted/newly added features