QGIS API Documentation  3.0.2-Girona (307d082)
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 
301  int idx() const { return mIdx; }
302 
304 
305  private:
306  void saveConfiguration( QDomElement &elem ) const override;
307  QString typeIdentifier() const override;
308  int mIdx;
309 };
310 
316 {
317  public:
318 
326  QgsAttributeEditorRelation( const QString &name, const QString &relationId, QgsAttributeEditorElement *parent )
327  : QgsAttributeEditorElement( AeTypeRelation, name, parent )
328  , mRelationId( relationId )
329  , mShowLinkButton( true )
330  , mShowUnlinkButton( true )
331  {}
332 
340  QgsAttributeEditorRelation( const QString &name, const QgsRelation &relation, QgsAttributeEditorElement *parent )
341  : QgsAttributeEditorElement( AeTypeRelation, name, parent )
342  , mRelationId( relation.id() )
343  , mRelation( relation )
344  , mShowLinkButton( true )
345  , mShowUnlinkButton( true )
346  {}
347 
353  const QgsRelation &relation() const { return mRelation; }
354 
361  bool init( QgsRelationManager *relManager );
362 
364 
370  bool showLinkButton() const;
371 
377  void setShowLinkButton( bool showLinkButton );
378 
384  bool showUnlinkButton() const;
385 
391  void setShowUnlinkButton( bool showUnlinkButton );
392 
393 
394  private:
395  void saveConfiguration( QDomElement &elem ) const override;
396  QString typeIdentifier() const override;
397  QString mRelationId;
398  QgsRelation mRelation;
399  bool mShowLinkButton;
400  bool mShowUnlinkButton;
401 };
402 
403 
404 #endif // QGSATTRIBUTEEDITORELEMENT_H
This is an abstract base class for any elements of a drag and drop form.
QgsAttributeEditorRelation(const QString &name, const QString &relationId, QgsAttributeEditorElement *parent)
Creates a new element which embeds a relation.
const QgsRelation & relation() const
Get 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.
An expression with an additional enabled flag.
#define SIP_ABSTRACT
Definition: qgis_sip.h:180
QgsAttributeEditorRelation(const QString &name, const QgsRelation &relation, QgsAttributeEditorElement *parent)
Creates a new element which embeds a relation.
#define SIP_TRANSFER
Definition: qgis_sip.h:36
#define SIP_END
Definition: qgis_sip.h:175
QgsAttributeEditorElement * parent() const
Get 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
Return the index of the field.
#define SIP_FACTORY
Definition: qgis_sip.h:69
QList< QgsAttributeEditorElement * > children() const
Get a list of the children elements of this container.
QgsAttributeEditorContainer(const QString &name, QgsAttributeEditorElement *parent)
Creates a new attribute editor container.
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
Return the name of this element.
virtual QgsAttributeEditorElement * clone(QgsAttributeEditorElement *parent) const =0
Returns a clone of this element.