QGIS API Documentation  3.18.1-Zürich (202f1bf7e5)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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
6  email : ivan@opengis.ch
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 <QWidget>
22 #include "qobjectuniqueptr.h"
23 
25 #include "qgsrelation.h"
26 #include "qgis_sip.h"
27 #include "qgis_gui.h"
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 
36 class QgsFeature;
37 class QgsVectorLayer;
38 
45 class GUI_EXPORT QgsAbstractRelationEditorWidget : public QWidget
46 {
47 
48 #ifdef SIP_RUN
50  if ( qobject_cast<QgsRelationEditorWidget *>( sipCpp ) )
51  sipType = sipType_QgsRelationEditorWidget;
52  else
53  sipType = 0;
54  SIP_END
55 #endif
56 
57  Q_OBJECT
58 
59  public:
60 
61 
65  QgsAbstractRelationEditorWidget( const QVariantMap &config, QWidget *parent SIP_TRANSFERTHIS = nullptr );
66 
70  void setRelationFeature( const QgsRelation &relation, const QgsFeature &feature );
71 
81  void setRelations( const QgsRelation &relation, const QgsRelation &nmrelation );
82 
87  QgsRelation relation() const {return mRelation;}
88 
92  void setFeature( const QgsFeature &feature, bool update = true );
93 
99  virtual void setEditorContext( const QgsAttributeEditorContext &context );
100 
104  QgsAttributeEditorContext editorContext( ) const;
105 
109  bool showLabel() const;
110 
114  void setShowLabel( bool showLabel );
115 
119  QVariant nmRelationId() const;
120 
125  void setNmRelationId( const QVariant &nmRelationId = QVariant() );
126 
130  QString label() const;
131 
136  void setLabel( const QString &label = QString() );
137 
141  QgsFeature feature() const;
142 
146  bool forceSuppressFormPopup() const;
147 
152  void setForceSuppressFormPopup( bool forceSuppressFormPopup );
153 
157  virtual QVariantMap config() const = 0;
158 
162  virtual void setConfig( const QVariantMap &config ) = 0;
163 
164  public slots:
165 
169  virtual void parentFormValueChanged( const QString &attribute, const QVariant &newValue ) = 0;
170 
171  protected slots:
172 
176  void toggleEditing( bool state );
177 
181  void saveEdits();
182 
186  void addFeature( const QgsGeometry &geometry = QgsGeometry() );
187 
191  void deleteFeature( QgsFeatureId fid = QgsFeatureId() );
192 
196  void linkFeature();
197 
201  void onLinkFeatureDlgAccepted();
202 
206  void unlinkFeature( QgsFeatureId fid = QgsFeatureId() );
207 
211  void duplicateFeature( const QgsFeatureId &fid );
212 
216  void duplicateFeatures( const QgsFeatureIds &fids );
217 
218  protected:
219 
224 
225  bool mShowLabel = true;
226  bool mLayerInSameTransactionGroup = false;
227 
228  bool mForceSuppressFormPopup = false;
229  QVariant mNmRelationId;
230  QString mLabel;
231 
235  void updateTitle();
236 
240  void deleteFeatures( const QgsFeatureIds &fids );
241 
245  void unlinkFeatures( const QgsFeatureIds &fids );
246 
247  // Following virtual methods need to be protected so they can be overridden in bindings
248 
255  virtual void updateUi();
256 
261  virtual void setTitle( const QString &title );
262 
267  virtual void beforeSetRelationFeature( const QgsRelation &newRelation, const QgsFeature &newFeature );
268 
273  virtual void afterSetRelationFeature();
274 
279  virtual void beforeSetRelations( const QgsRelation &newRelation, const QgsRelation &newNmRelation );
280 
285  virtual void afterSetRelations();
286 };
287 
288 
298 class GUI_EXPORT QgsAbstractRelationEditorConfigWidget : public QWidget
299 {
300 
301 #ifdef SIP_RUN
303  if ( qobject_cast<QgsRelationEditorConfigWidget *>( sipCpp ) )
304  sipType = sipType_QgsRelationEditorConfigWidget;
305  else
306  sipType = 0;
307  SIP_END
308 #endif
309 
310  Q_OBJECT
311  public:
312 
319  explicit QgsAbstractRelationEditorConfigWidget( const QgsRelation &relation, QWidget *parent SIP_TRANSFERTHIS );
320 
326  virtual QVariantMap config() = 0;
327 
333  virtual void setConfig( const QVariantMap &config ) = 0;
334 
340  QgsVectorLayer *layer();
341 
347  QgsRelation relation() const;
348 
349 
350  private:
351  QgsVectorLayer *mLayer = nullptr;
352  QgsRelation mRelation;
353 };
354 
355 
357 
358 
366 {
367  public:
368 
373 
375 
379  virtual QString type() const = 0;
380 
384  virtual QString name() const = 0;
385 
396  virtual QgsAbstractRelationEditorWidget *create( const QVariantMap &config, QWidget *parent = nullptr ) const = 0 SIP_FACTORY;
397 
407  virtual QgsAbstractRelationEditorConfigWidget *configWidget( const QgsRelation &relation, QWidget *parent ) const = 0 SIP_FACTORY;
408 };
409 
410 #endif // QGSABSTRACTRELATIONEDITORWIDGET_H
This class should be subclassed for every configurable relation widget type.
virtual QVariantMap config()=0
Create a configuration from the current GUI state.
virtual void setConfig(const QVariantMap &config)=0
Update the configuration widget to represent the given configuration.
Factory class for creating relation widgets and their corresponding config widgets.
virtual QString type() const =0
Returns the machine 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 QString name() const =0
Returns the human readable identifier name of this widget type.
virtual ~QgsAbstractRelationEditorWidgetFactory()=default
Base class to build new relation widgets.
virtual void setConfig(const QVariantMap &config)=0
Defines the widget configuration.
QgsRelation relation() const
Returns the relation.
virtual QVariantMap config() const =0
Returns the widget configuration.
virtual void parentFormValueChanged(const QString &attribute, const QVariant &newValue)=0
Called when an attribute value in the parent widget has changed to newValue.
This class contains context information for attribute editor widgets.
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:56
A geometry is the spatial representation of a feature.
Definition: qgsgeometry.h:124
Represents a vector layer which manages a vector based data sets.
#define SIP_CONVERT_TO_SUBCLASS_CODE(code)
Definition: qgis_sip.h:177
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:53
#define SIP_FACTORY
Definition: qgis_sip.h:76
#define SIP_END
Definition: qgis_sip.h:194
QSet< QgsFeatureId > QgsFeatureIds
Definition: qgsfeatureid.h:37
qint64 QgsFeatureId
64 bit feature ids negative numbers are used for uncommitted/newly added features
Definition: qgsfeatureid.h:28