QGIS API Documentation  3.10.0-A Coruña (6c816b4204)
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 #include <QColor>
23 
24 class QgsRelationManager;
25 
38 {
39 
40 #ifdef SIP_RUN
42  switch ( sipCpp->type() )
43  {
45  sipType = sipType_QgsAttributeEditorContainer;
46  break;
48  sipType = sipType_QgsAttributeEditorField;
49  break;
51  sipType = sipType_QgsAttributeEditorRelation;
52  break;
53  default:
54  sipType = nullptr;
55  break;
56  }
57  SIP_END
58 #endif
59  public:
61  {
67  AeTypeHtmlElement
68  };
69 
77  QgsAttributeEditorElement( AttributeEditorType type, const QString &name, QgsAttributeEditorElement *parent = nullptr )
78  : mType( type )
79  , mName( name )
80  , mParent( parent )
81  , mShowLabel( true )
82  {}
83 
84  virtual ~QgsAttributeEditorElement() = default;
85 
91  QString name() const { return mName; }
92 
98  AttributeEditorType type() const { return mType; }
99 
105  QgsAttributeEditorElement *parent() const { return mParent; }
106 
114  QDomElement toDomElement( QDomDocument &doc ) const;
115 
121  virtual QgsAttributeEditorElement *clone( QgsAttributeEditorElement *parent ) const = 0 SIP_FACTORY;
122 
128  bool showLabel() const;
129 
135  void setShowLabel( bool showLabel );
136 
137  protected:
138 #ifndef SIP_RUN
140  QString mName;
141  QgsAttributeEditorElement *mParent = nullptr;
143 #endif
144 
145  private:
146 
152  virtual void saveConfiguration( QDomElement &elem ) const = 0;
153 
160  virtual QString typeIdentifier() const = 0;
161 };
162 
163 
170 {
171  public:
172 
180  QgsAttributeEditorContainer( const QString &name, QgsAttributeEditorElement *parent, const QColor &backgroundColor = QColor() )
181  : QgsAttributeEditorElement( AeTypeContainer, name, parent )
182  , mIsGroupBox( true )
183  , mColumnCount( 1 )
184  , mBackgroundColor( backgroundColor )
185  {}
186 
187 
188  ~QgsAttributeEditorContainer() override;
189 
195  virtual void addChildElement( QgsAttributeEditorElement *element SIP_TRANSFER );
196 
202  virtual void setIsGroupBox( bool isGroupBox ) { mIsGroupBox = isGroupBox; }
203 
209  virtual bool isGroupBox() const { return mIsGroupBox; }
210 
216  QList<QgsAttributeEditorElement *> children() const { return mChildren; }
217 
225  virtual QList<QgsAttributeEditorElement *> findElements( AttributeEditorType type ) const;
226 
230  void clear();
231 
235  void setName( const QString &name );
236 
240  int columnCount() const;
241 
245  void setColumnCount( int columnCount );
246 
253 
261  QgsOptionalExpression visibilityExpression() const;
262 
270  void setVisibilityExpression( const QgsOptionalExpression &visibilityExpression );
271 
277  QColor backgroundColor() const;
278 
282  void setBackgroundColor( const QColor &backgroundColor );
283 
284  private:
285  void saveConfiguration( QDomElement &elem ) const override;
286  QString typeIdentifier() const override;
287 
288  bool mIsGroupBox;
289  QList<QgsAttributeEditorElement *> mChildren;
290  int mColumnCount;
291  QgsOptionalExpression mVisibilityExpression;
292  QColor mBackgroundColor;
293 };
294 
300 {
301  public:
302 
310  QgsAttributeEditorField( const QString &name, int idx, QgsAttributeEditorElement *parent )
311  : QgsAttributeEditorElement( AeTypeField, name, parent )
312  , mIdx( idx )
313  {}
314 
318  int idx() const { return mIdx; }
319 
321 
322  private:
323  void saveConfiguration( QDomElement &elem ) const override;
324  QString typeIdentifier() const override;
325  int mIdx;
326 };
327 
333 {
334  public:
335 
339  Q_DECL_DEPRECATED QgsAttributeEditorRelation( const QString &name, const QString &relationId, QgsAttributeEditorElement *parent )
340  : QgsAttributeEditorElement( AeTypeRelation, name, parent )
341  , mRelationId( relationId )
342  {}
343 
347  Q_DECL_DEPRECATED QgsAttributeEditorRelation( const QString &name, const QgsRelation &relation, QgsAttributeEditorElement *parent )
348  : QgsAttributeEditorElement( AeTypeRelation, name, parent )
349  , mRelationId( relation.id() )
350  , mRelation( relation )
351  {}
352 
359  QgsAttributeEditorRelation( const QString &relationId, QgsAttributeEditorElement *parent )
360  : QgsAttributeEditorElement( AeTypeRelation, relationId, parent )
361  , mRelationId( relationId )
362  {}
363 
371  : QgsAttributeEditorElement( AeTypeRelation, relation.id(), parent )
372  , mRelationId( relation.id() )
373  , mRelation( relation )
374  {}
375 
376 
382  const QgsRelation &relation() const { return mRelation; }
383 
390  bool init( QgsRelationManager *relManager );
391 
393 
399  bool showLinkButton() const;
400 
406  void setShowLinkButton( bool showLinkButton );
407 
413  bool showUnlinkButton() const;
414 
420  void setShowUnlinkButton( bool showUnlinkButton );
421 
422 
423  private:
424  void saveConfiguration( QDomElement &elem ) const override;
425  QString typeIdentifier() const override;
426  QString mRelationId;
427  QgsRelation mRelation;
428  bool mShowLinkButton = true;
429  bool mShowUnlinkButton = true;
430 };
431 
439 {
440  public:
441 
449  : QgsAttributeEditorElement( AeTypeQmlElement, name, parent )
450  {}
451 
453 
459  QString qmlCode() const;
460 
464  void setQmlCode( const QString &qmlCode );
465 
466  private:
467  void saveConfiguration( QDomElement &elem ) const override;
468  QString typeIdentifier() const override;
469  QString mQmlCode;
470 };
471 
472 
480 {
481  public:
482 
490  : QgsAttributeEditorElement( AeTypeHtmlElement, name, parent )
491  {}
492 
494 
500  QString htmlCode() const;
501 
505  void setHtmlCode( const QString &htmlCode );
506 
507  private:
508  void saveConfiguration( QDomElement &elem ) const override;
509  QString typeIdentifier() const override;
510  QString mHtmlCode;
511 };
512 
513 
514 #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.
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.
QgsAttributeEditorContainer(const QString &name, QgsAttributeEditorElement *parent, const QColor &backgroundColor=QColor())
Creates a new attribute editor container.
This element will load a field&#39;s widget onto the form.
QgsAttributeEditorHtmlElement(const QString &name, QgsAttributeEditorElement *parent)
Creates a new element which can display HTML.
This element will load a relation editor onto the form.
An attribute editor widget that will represent arbitrary HTML code.
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:194
#define SIP_TRANSFER
Definition: qgis_sip.h:36
#define SIP_END
Definition: qgis_sip.h:189
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:76
QList< QgsAttributeEditorElement * > children() const
Gets a list of the children elements of this 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:172
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 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.