QGIS API Documentation 3.99.0-Master (26c88405ac0)
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:
59
63 QgsAbstractRelationEditorWidget( const QVariantMap &config, QWidget *parent SIP_TRANSFERTHIS = nullptr );
64
69
79 void setRelations( const QgsRelation &relation, const QgsRelation &nmrelation );
80
85 QgsRelation relation() const { return mRelation; }
86
92
96 void setFeature( const QgsFeature &feature, bool update = true );
97
103 void setMultiEditFeatureIds( const QgsFeatureIds &fids );
104
110 virtual void setEditorContext( const QgsAttributeEditorContext &context );
111
115 QgsAttributeEditorContext editorContext() const;
116
121 Q_DECL_DEPRECATED bool showLabel() const SIP_DEPRECATED;
122
127 Q_DECL_DEPRECATED void setShowLabel( bool showLabel ) SIP_DEPRECATED;
128
132 QVariant nmRelationId() const;
133
138 void setNmRelationId( const QVariant &nmRelationId = QVariant() );
139
144 Q_DECL_DEPRECATED QString label() const SIP_DEPRECATED;
145
150 void setLabel( const QString &label = QString() );
151
157 QgsFeature feature() const;
158
163 QList<QgsFeature> features() const;
164
168 bool forceSuppressFormPopup() const;
169
174 void setForceSuppressFormPopup( bool forceSuppressFormPopup );
175
179 virtual QVariantMap config() const = 0;
180
184 virtual void setConfig( const QVariantMap &config ) = 0;
185
190 bool multiEditModeActive() const;
191
192 signals:
193
202
203 public slots:
204
208 virtual void parentFormValueChanged( const QString &attribute, const QVariant &newValue ) = 0;
209
210 protected slots:
211
215 void toggleEditing( bool state );
216
220 void saveEdits();
221
226 QgsFeatureIds addFeature( const QgsGeometry &geometry = QgsGeometry() );
227
232
237 void linkFeature( const QString &filterExpression = QString() );
238
243
248
252 void duplicateFeature( const QgsFeatureId &fid );
253
257 void duplicateFeatures( const QgsFeatureIds &fids );
258
259 protected:
264
266
268
272 void showEvent( QShowEvent * ) override;
273
278 Q_DECL_DEPRECATED void updateTitle() SIP_DEPRECATED;
279
283 void deleteFeatures( const QgsFeatureIds &fids );
284
288 void unlinkFeatures( const QgsFeatureIds &fids );
289
290 // Following virtual methods need to be protected so they can be overridden in bindings
291
298 virtual void updateUi();
299
304 Q_DECL_DEPRECATED virtual void setTitle( const QString &title ) SIP_DEPRECATED;
305
310 virtual void beforeSetRelationFeature( const QgsRelation &newRelation, const QgsFeature &newFeature );
311
316 virtual void afterSetRelationFeature();
317
322 virtual void beforeSetRelations( const QgsRelation &newRelation, const QgsRelation &newNmRelation );
323
328 virtual void afterSetRelations();
329};
330
331
341class GUI_EXPORT QgsAbstractRelationEditorConfigWidget : public QWidget
342{
343#ifdef SIP_RUN
345 if ( qobject_cast<QgsRelationEditorConfigWidget *>( sipCpp ) )
346 sipType = sipType_QgsRelationEditorConfigWidget;
347 else
348 sipType = 0;
349 SIP_END
350#endif
351
352 Q_OBJECT
353 public:
354
362
368 virtual QVariantMap config() = 0;
369
375 virtual void setConfig( const QVariantMap &config ) = 0;
376
383
389 QgsRelation relation() const;
390
396 virtual void setNmRelation( const QgsRelation &nmRelation );
397
403 virtual QgsRelation nmRelation() const;
404
405 private:
406 QgsVectorLayer *mLayer = nullptr;
407 QgsRelation mRelation;
408 QgsRelation mNmRelation;
409};
410
411
413
414
422{
423 public:
424
429
431
435 virtual QString type() const = 0;
436
440 virtual QString name() const = 0;
441
452 virtual QgsAbstractRelationEditorWidget *create( const QVariantMap &config, QWidget *parent = nullptr ) const = 0 SIP_FACTORY;
453
463 virtual QgsAbstractRelationEditorConfigWidget *configWidget( const QgsRelation &relation, QWidget *parent ) const = 0 SIP_FACTORY;
464};
465
466#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