QGIS API Documentation  3.2.0-Bonn (bc43194)
qgsattributeeditorelement.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsattributeeditorelement.h - QgsAttributeEditorElement
3 
4  ---------------------
5  begin : 18.8.2016
6  copyright : (C) 2016 by Matthias Kuhn
7  email : [email protected]
8  ***************************************************************************
9  * *
10  * This program is free software; you can redistribute it and/or modify *
11  * it under the terms of the GNU General Public License as published by *
12  * the Free Software Foundation; either version 2 of the License, or *
13  * (at your option) any later version. *
14  * *
15  ***************************************************************************/
16 #ifndef QGSATTRIBUTEEDITORELEMENT_H
17 #define QGSATTRIBUTEEDITORELEMENT_H
18 
19 #include "qgis_core.h"
20 #include "qgsrelation.h"
21 #include "qgsoptionalexpression.h"
22 
23 class QgsRelationManager;
24 
37 {
38 
39 #ifdef SIP_RUN
41  switch ( sipCpp->type() )
42  {
44  sipType = sipType_QgsAttributeEditorContainer;
45  break;
47  sipType = sipType_QgsAttributeEditorField;
48  break;
50  sipType = sipType_QgsAttributeEditorRelation;
51  break;
52  default:
53  sipType = nullptr;
54  break;
55  }
56  SIP_END
57 #endif
58  public:
60  {
64  AeTypeInvalid
65  };
66 
74  QgsAttributeEditorElement( AttributeEditorType type, const QString &name, QgsAttributeEditorElement *parent = nullptr )
75  : mType( type )
76  , mName( name )
77  , mParent( parent )
78  , mShowLabel( true )
79  {}
80 
81  virtual ~QgsAttributeEditorElement() = default;
82 
88  QString name() const { return mName; }
89 
95  AttributeEditorType type() const { return mType; }
96 
102  QgsAttributeEditorElement *parent() const { return mParent; }
103 
111  QDomElement toDomElement( QDomDocument &doc ) const;
112 
118  virtual QgsAttributeEditorElement *clone( QgsAttributeEditorElement *parent ) const = 0 SIP_FACTORY;
119 
125  bool showLabel() const;
126 
132  void setShowLabel( bool showLabel );
133 
134  protected:
135 #ifndef SIP_RUN
137  QString mName;
138  QgsAttributeEditorElement *mParent = nullptr;
140 #endif
141 
142  private:
143 
149  virtual void saveConfiguration( QDomElement &elem ) const = 0;
150 
157  virtual QString typeIdentifier() const = 0;
158 };
159 
160 
167 {
168  public:
169 
177  : QgsAttributeEditorElement( AeTypeContainer, name, parent )
178  , mIsGroupBox( true )
179  , mColumnCount( 1 )
180  {}
181 
182 
183  ~QgsAttributeEditorContainer() override;
184 
190  virtual void addChildElement( QgsAttributeEditorElement *element SIP_TRANSFER );
191 
197  virtual void setIsGroupBox( bool isGroupBox ) { mIsGroupBox = isGroupBox; }
198 
204  virtual bool isGroupBox() const { return mIsGroupBox; }
205 
211  QList<QgsAttributeEditorElement *> children() const { return mChildren; }
212 
220  virtual QList<QgsAttributeEditorElement *> findElements( AttributeEditorType type ) const;
221 
225  void clear();
226 
230  void setName( const QString &name );
231 
235  int columnCount() const;
236 
240  void setColumnCount( int columnCount );
241 
248 
256  QgsOptionalExpression visibilityExpression() const;
257 
265  void setVisibilityExpression( const QgsOptionalExpression &visibilityExpression );
266 
267  private:
268  void saveConfiguration( QDomElement &elem ) const override;
269  QString typeIdentifier() const override;
270 
271  bool mIsGroupBox;
272  QList<QgsAttributeEditorElement *> mChildren;
273  int mColumnCount;
274  QgsOptionalExpression mVisibilityExpression;
275 };
276 
282 {
283  public:
284 
292  QgsAttributeEditorField( const QString &name, int idx, QgsAttributeEditorElement *parent )
293  : QgsAttributeEditorElement( AeTypeField, name, parent )
294  , mIdx( idx )
295  {}
296 
300  int idx() const { return mIdx; }
301 
303 
304  private:
305  void saveConfiguration( QDomElement &elem ) const override;
306  QString typeIdentifier() const override;
307  int mIdx;
308 };
309 
315 {
316  public:
317 
321  Q_DECL_DEPRECATED QgsAttributeEditorRelation( const QString &name, const QString &relationId, QgsAttributeEditorElement *parent )
322  : QgsAttributeEditorElement( AeTypeRelation, name, parent )
323  , mRelationId( relationId )
324  {}
325 
329  Q_DECL_DEPRECATED QgsAttributeEditorRelation( const QString &name, const QgsRelation &relation, QgsAttributeEditorElement *parent )
330  : QgsAttributeEditorElement( AeTypeRelation, name, parent )
331  , mRelationId( relation.id() )
332  , mRelation( relation )
333  {}
334 
341  QgsAttributeEditorRelation( const QString &relationId, QgsAttributeEditorElement *parent )
342  : QgsAttributeEditorElement( AeTypeRelation, relationId, parent )
343  , mRelationId( relationId )
344  {}
345 
353  : QgsAttributeEditorElement( AeTypeRelation, relation.id(), parent )
354  , mRelationId( relation.id() )
355  , mRelation( relation )
356  {}
357 
358 
364  const QgsRelation &relation() const { return mRelation; }
365 
372  bool init( QgsRelationManager *relManager );
373 
375 
381  bool showLinkButton() const;
382 
388  void setShowLinkButton( bool showLinkButton );
389 
395  bool showUnlinkButton() const;
396 
402  void setShowUnlinkButton( bool showUnlinkButton );
403 
404 
405  private:
406  void saveConfiguration( QDomElement &elem ) const override;
407  QString typeIdentifier() const override;
408  QString mRelationId;
409  QgsRelation mRelation;
410  bool mShowLinkButton = true;
411  bool mShowUnlinkButton = true;
412 };
413 
414 
415 #endif // QGSATTRIBUTEEDITORELEMENT_H
This is an abstract base class for any elements of a drag and drop form.
QgsAttributeEditorRelation(const QgsRelation &relation, QgsAttributeEditorElement *parent)
Creates a new element which embeds a relation.
const QgsRelation & relation() const
Gets the id of the relation which shall be embedded.
This element will load a field&#39;s widget onto the form.
This element will load a relation editor onto the form.
AttributeEditorType type() const
The type of this element.
Q_DECL_DEPRECATED QgsAttributeEditorRelation(const QString &name, const QString &relationId, QgsAttributeEditorElement *parent)
An expression with an additional enabled flag.
#define SIP_ABSTRACT
Definition: qgis_sip.h:187
#define SIP_TRANSFER
Definition: qgis_sip.h:36
#define SIP_END
Definition: qgis_sip.h:182
QgsAttributeEditorElement * parent() const
Gets the parent of this element.
QgsAttributeEditorField(const QString &name, int idx, QgsAttributeEditorElement *parent)
Creates a new attribute editor element which represents a field.
int idx() const
Returns the index of the field.
QgsAttributeEditorRelation(const QString &relationId, QgsAttributeEditorElement *parent)
Creates a new element which embeds a relation.
#define SIP_FACTORY
Definition: qgis_sip.h:69
QList< QgsAttributeEditorElement * > children() const
Gets a list of the children elements of this container.
QgsAttributeEditorContainer(const QString &name, QgsAttributeEditorElement *parent)
Creates a new attribute editor container.
Q_DECL_DEPRECATED QgsAttributeEditorRelation(const QString &name, const QgsRelation &relation, QgsAttributeEditorElement *parent)
virtual void setIsGroupBox(bool isGroupBox)
Determines if this container is rendered as collapsible group box or tab in a tabwidget.
This class manages a set of relations between layers.
QgsAttributeEditorElement(AttributeEditorType type, const QString &name, QgsAttributeEditorElement *parent=nullptr)
Constructor.
#define SIP_CONVERT_TO_SUBCLASS_CODE(code)
Definition: qgis_sip.h:165
This is a container for attribute editors, used to group them visually in the attribute form if it is...
virtual bool isGroupBox() const
Returns if this container is going to be rendered as a group box.
QString name() const
Returns the name of this element.
virtual QgsAttributeEditorElement * clone(QgsAttributeEditorElement *parent) const =0
Returns a clone of this element.