QGIS API Documentation  3.4.15-Madeira (e83d02e274)
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  {
65  AeTypeQmlElement
66  };
67 
75  QgsAttributeEditorElement( AttributeEditorType type, const QString &name, QgsAttributeEditorElement *parent = nullptr )
76  : mType( type )
77  , mName( name )
78  , mParent( parent )
79  , mShowLabel( true )
80  {}
81 
82  virtual ~QgsAttributeEditorElement() = default;
83 
89  QString name() const { return mName; }
90 
96  AttributeEditorType type() const { return mType; }
97 
103  QgsAttributeEditorElement *parent() const { return mParent; }
104 
112  QDomElement toDomElement( QDomDocument &doc ) const;
113 
119  virtual QgsAttributeEditorElement *clone( QgsAttributeEditorElement *parent ) const = 0 SIP_FACTORY;
120 
126  bool showLabel() const;
127 
133  void setShowLabel( bool showLabel );
134 
135  protected:
136 #ifndef SIP_RUN
138  QString mName;
139  QgsAttributeEditorElement *mParent = nullptr;
141 #endif
142 
143  private:
144 
150  virtual void saveConfiguration( QDomElement &elem ) const = 0;
151 
158  virtual QString typeIdentifier() const = 0;
159 };
160 
161 
168 {
169  public:
170 
178  : QgsAttributeEditorElement( AeTypeContainer, name, parent )
179  , mIsGroupBox( true )
180  , mColumnCount( 1 )
181  {}
182 
183 
184  ~QgsAttributeEditorContainer() override;
185 
191  virtual void addChildElement( QgsAttributeEditorElement *element SIP_TRANSFER );
192 
198  virtual void setIsGroupBox( bool isGroupBox ) { mIsGroupBox = isGroupBox; }
199 
205  virtual bool isGroupBox() const { return mIsGroupBox; }
206 
212  QList<QgsAttributeEditorElement *> children() const { return mChildren; }
213 
221  virtual QList<QgsAttributeEditorElement *> findElements( AttributeEditorType type ) const;
222 
226  void clear();
227 
231  void setName( const QString &name );
232 
236  int columnCount() const;
237 
241  void setColumnCount( int columnCount );
242 
249 
257  QgsOptionalExpression visibilityExpression() const;
258 
266  void setVisibilityExpression( const QgsOptionalExpression &visibilityExpression );
267 
268  private:
269  void saveConfiguration( QDomElement &elem ) const override;
270  QString typeIdentifier() const override;
271 
272  bool mIsGroupBox;
273  QList<QgsAttributeEditorElement *> mChildren;
274  int mColumnCount;
275  QgsOptionalExpression mVisibilityExpression;
276 };
277 
283 {
284  public:
285 
293  QgsAttributeEditorField( const QString &name, int idx, QgsAttributeEditorElement *parent )
294  : QgsAttributeEditorElement( AeTypeField, name, parent )
295  , mIdx( idx )
296  {}
297 
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 
322  Q_DECL_DEPRECATED QgsAttributeEditorRelation( const QString &name, const QString &relationId, QgsAttributeEditorElement *parent )
323  : QgsAttributeEditorElement( AeTypeRelation, name, parent )
324  , mRelationId( relationId )
325  {}
326 
330  Q_DECL_DEPRECATED QgsAttributeEditorRelation( const QString &name, const QgsRelation &relation, QgsAttributeEditorElement *parent )
331  : QgsAttributeEditorElement( AeTypeRelation, name, parent )
332  , mRelationId( relation.id() )
333  , mRelation( relation )
334  {}
335 
342  QgsAttributeEditorRelation( const QString &relationId, QgsAttributeEditorElement *parent )
343  : QgsAttributeEditorElement( AeTypeRelation, relationId, parent )
344  , mRelationId( relationId )
345  {}
346 
354  : QgsAttributeEditorElement( AeTypeRelation, relation.id(), parent )
355  , mRelationId( relation.id() )
356  , mRelation( relation )
357  {}
358 
359 
365  const QgsRelation &relation() const { return mRelation; }
366 
373  bool init( QgsRelationManager *relManager );
374 
376 
382  bool showLinkButton() const;
383 
389  void setShowLinkButton( bool showLinkButton );
390 
396  bool showUnlinkButton() const;
397 
403  void setShowUnlinkButton( bool showUnlinkButton );
404 
405 
406  private:
407  void saveConfiguration( QDomElement &elem ) const override;
408  QString typeIdentifier() const override;
409  QString mRelationId;
410  QgsRelation mRelation;
411  bool mShowLinkButton = true;
412  bool mShowUnlinkButton = true;
413 };
414 
422 {
423  public:
424 
432  : QgsAttributeEditorElement( AeTypeQmlElement, name, parent )
433  {}
434 
436 
442  QString qmlCode() const;
443 
449  void setQmlCode( const QString &qmlCode );
450 
451  private:
452  void saveConfiguration( QDomElement &elem ) const override;
453  QString typeIdentifier() const override;
454  QString mQmlCode;
455 };
456 
457 #endif // QGSATTRIBUTEEDITORELEMENT_H
An attribute editor widget that will represent arbitrary QML code.
This is an abstract base class for any elements of a drag and drop form.
virtual bool isGroupBox() const
Returns if this container is going to be rendered as a group box.
QgsAttributeEditorElement * parent() const
Gets the parent of this element.
QgsAttributeEditorRelation(const QgsRelation &relation, QgsAttributeEditorElement *parent)
Creates a new element which embeds a relation.
This element will load a field&#39;s widget onto the form.
This element will load a relation editor onto the form.
const QgsRelation & relation() const
Gets the id of the relation which shall be embedded.
int idx() const
Returns the index of the field.
QString name() const
Returns the name 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
AttributeEditorType type() const
The type of this element.
QgsAttributeEditorField(const QString &name, int idx, QgsAttributeEditorElement *parent)
Creates a new attribute editor element which represents a field.
QgsAttributeEditorRelation(const QString &relationId, QgsAttributeEditorElement *parent)
Creates a new element which embeds a relation.
#define SIP_FACTORY
Definition: qgis_sip.h:69
QgsAttributeEditorContainer(const QString &name, QgsAttributeEditorElement *parent)
Creates a new attribute editor container.
Q_DECL_DEPRECATED QgsAttributeEditorRelation(const QString &name, const QgsRelation &relation, QgsAttributeEditorElement *parent)
QList< QgsAttributeEditorElement * > children() const
Gets a list of the children elements of this 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...
QgsAttributeEditorQmlElement(const QString &name, QgsAttributeEditorElement *parent)
Creates a new element which can display QML.
virtual QgsAttributeEditorElement * clone(QgsAttributeEditorElement *parent) const =0
Returns a clone of this element.