QGIS API Documentation  3.14.0-Pi (9f7028fd23)
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 "qgspropertycollection.h"
23 #include <QColor>
24 
25 class QgsRelationManager;
26 
39 {
40 
41 #ifdef SIP_RUN
43  switch ( sipCpp->type() )
44  {
46  sipType = sipType_QgsAttributeEditorContainer;
47  break;
49  sipType = sipType_QgsAttributeEditorField;
50  break;
52  sipType = sipType_QgsAttributeEditorRelation;
53  break;
54  default:
55  sipType = nullptr;
56  break;
57  }
58  SIP_END
59 #endif
60  public:
62  {
68  AeTypeHtmlElement
69  };
70 
78  QgsAttributeEditorElement( AttributeEditorType type, const QString &name, QgsAttributeEditorElement *parent = nullptr )
79  : mType( type )
80  , mName( name )
81  , mParent( parent )
82  , mShowLabel( true )
83  {}
84 
85  virtual ~QgsAttributeEditorElement() = default;
86 
92  QString name() const { return mName; }
93 
99  AttributeEditorType type() const { return mType; }
100 
106  QgsAttributeEditorElement *parent() const { return mParent; }
107 
115  QDomElement toDomElement( QDomDocument &doc ) const;
116 
122  virtual QgsAttributeEditorElement *clone( QgsAttributeEditorElement *parent ) const = 0 SIP_FACTORY;
123 
129  bool showLabel() const;
130 
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 
164 
171 {
172  public:
173 
181  QgsAttributeEditorContainer( const QString &name, QgsAttributeEditorElement *parent, const QColor &backgroundColor = QColor() )
182  : QgsAttributeEditorElement( AeTypeContainer, name, parent )
183  , mIsGroupBox( true )
184  , mColumnCount( 1 )
185  , mBackgroundColor( backgroundColor )
186  {}
187 
188 
189  ~QgsAttributeEditorContainer() override;
190 
196  virtual void addChildElement( QgsAttributeEditorElement *element SIP_TRANSFER );
197 
203  virtual void setIsGroupBox( bool isGroupBox ) { mIsGroupBox = isGroupBox; }
204 
210  virtual bool isGroupBox() const { return mIsGroupBox; }
211 
217  QList<QgsAttributeEditorElement *> children() const { return mChildren; }
218 
226  virtual QList<QgsAttributeEditorElement *> findElements( AttributeEditorType type ) const;
227 
231  void clear();
232 
236  void setName( const QString &name );
237 
241  int columnCount() const;
242 
246  void setColumnCount( int columnCount );
247 
254 
262  QgsOptionalExpression visibilityExpression() const;
263 
271  void setVisibilityExpression( const QgsOptionalExpression &visibilityExpression );
272 
278  QColor backgroundColor() const;
279 
283  void setBackgroundColor( const QColor &backgroundColor );
284 
285  private:
286  void saveConfiguration( QDomElement &elem ) const override;
287  QString typeIdentifier() const override;
288 
289  bool mIsGroupBox;
290  QList<QgsAttributeEditorElement *> mChildren;
291  int mColumnCount;
292  QgsOptionalExpression mVisibilityExpression;
293  QColor mBackgroundColor;
294 };
295 
301 {
302  public:
303 
311  QgsAttributeEditorField( const QString &name, int idx, QgsAttributeEditorElement *parent )
312  : QgsAttributeEditorElement( AeTypeField, name, parent )
313  , mIdx( idx )
314  {}
315 
319  int idx() const { return mIdx; }
320 
322 
323  private:
324  void saveConfiguration( QDomElement &elem ) const override;
325  QString typeIdentifier() const override;
326  int mIdx;
327 };
328 
334 {
335  public:
336 
340  Q_DECL_DEPRECATED QgsAttributeEditorRelation( const QString &name, const QString &relationId, QgsAttributeEditorElement *parent )
341  : QgsAttributeEditorElement( AeTypeRelation, name, parent )
342  , mRelationId( relationId )
343  {}
344 
348  Q_DECL_DEPRECATED QgsAttributeEditorRelation( const QString &name, const QgsRelation &relation, QgsAttributeEditorElement *parent )
349  : QgsAttributeEditorElement( AeTypeRelation, name, parent )
350  , mRelationId( relation.id() )
351  , mRelation( relation )
352  {}
353 
360  QgsAttributeEditorRelation( const QString &relationId, QgsAttributeEditorElement *parent )
361  : QgsAttributeEditorElement( AeTypeRelation, relationId, parent )
362  , mRelationId( relationId )
363  {}
364 
372  : QgsAttributeEditorElement( AeTypeRelation, relation.id(), parent )
373  , mRelationId( relation.id() )
374  , mRelation( relation )
375  {}
376 
377 
383  const QgsRelation &relation() const { return mRelation; }
384 
391  bool init( QgsRelationManager *relManager );
392 
394 
400  bool showLinkButton() const;
401 
407  void setShowLinkButton( bool showLinkButton );
408 
414  bool showUnlinkButton() const;
415 
421  void setShowUnlinkButton( bool showUnlinkButton );
422 
428  void setShowSaveChildEditsButton( bool showSaveChildEditsButton );
429 
435  bool showSaveChildEditsButton( ) const;
436 
437 
438  private:
439  void saveConfiguration( QDomElement &elem ) const override;
440  QString typeIdentifier() const override;
441  QString mRelationId;
442  QgsRelation mRelation;
443  bool mShowLinkButton = true;
444  bool mShowUnlinkButton = true;
445  bool mShowSaveChildEditsButton = true;
446 };
447 
455 {
456  public:
457 
465  : QgsAttributeEditorElement( AeTypeQmlElement, name, parent )
466  {}
467 
469 
475  QString qmlCode() const;
476 
480  void setQmlCode( const QString &qmlCode );
481 
482  private:
483  void saveConfiguration( QDomElement &elem ) const override;
484  QString typeIdentifier() const override;
485  QString mQmlCode;
486 };
487 
488 
496 {
497  public:
498 
506  : QgsAttributeEditorElement( AeTypeHtmlElement, name, parent )
507  {}
508 
510 
516  QString htmlCode() const;
517 
521  void setHtmlCode( const QString &htmlCode );
522 
523  private:
524  void saveConfiguration( QDomElement &elem ) const override;
525  QString typeIdentifier() const override;
526  QString mHtmlCode;
527 };
528 
529 
530 #endif // QGSATTRIBUTEEDITORELEMENT_H
QgsAttributeEditorElement
Definition: qgsattributeeditorelement.h:38
QgsAttributeEditorRelation::QgsAttributeEditorRelation
QgsAttributeEditorRelation(const QString &relationId, QgsAttributeEditorElement *parent)
Creates a new element which embeds a relation.
Definition: qgsattributeeditorelement.h:360
QgsAttributeEditorContainer::QgsAttributeEditorContainer
QgsAttributeEditorContainer(const QString &name, QgsAttributeEditorElement *parent, const QColor &backgroundColor=QColor())
Creates a new attribute editor container.
Definition: qgsattributeeditorelement.h:181
qgsoptionalexpression.h
QgsRelationManager
Definition: qgsrelationmanager.h:34
QgsAttributeEditorElement::QgsAttributeEditorElement
QgsAttributeEditorElement(AttributeEditorType type, const QString &name, QgsAttributeEditorElement *parent=nullptr)
Constructor.
Definition: qgsattributeeditorelement.h:78
QgsAttributeEditorElement::AeTypeRelation
@ AeTypeRelation
A relation.
Definition: qgsattributeeditorelement.h:65
QgsAttributeEditorField
Definition: qgsattributeeditorelement.h:300
QgsAttributeEditorRelation::QgsAttributeEditorRelation
Q_DECL_DEPRECATED QgsAttributeEditorRelation(const QString &name, const QgsRelation &relation, QgsAttributeEditorElement *parent)
Definition: qgsattributeeditorelement.h:348
QgsAttributeEditorContainer::isGroupBox
virtual bool isGroupBox() const
Returns if this container is going to be rendered as a group box.
Definition: qgsattributeeditorelement.h:210
QgsAttributeEditorElement::mType
AttributeEditorType mType
Definition: qgsattributeeditorelement.h:139
QgsAttributeEditorContainer::children
QList< QgsAttributeEditorElement * > children() const
Gets a list of the children elements of this container.
Definition: qgsattributeeditorelement.h:217
QgsAttributeEditorHtmlElement::QgsAttributeEditorHtmlElement
QgsAttributeEditorHtmlElement(const QString &name, QgsAttributeEditorElement *parent)
Creates a new element which can display HTML.
Definition: qgsattributeeditorelement.h:505
SIP_FACTORY
#define SIP_FACTORY
Definition: qgis_sip.h:76
SIP_CONVERT_TO_SUBCLASS_CODE
#define SIP_CONVERT_TO_SUBCLASS_CODE(code)
Definition: qgis_sip.h:172
QgsAttributeEditorField::idx
int idx() const
Returns the index of the field.
Definition: qgsattributeeditorelement.h:319
QgsAttributeEditorElement::AeTypeContainer
@ AeTypeContainer
A container.
Definition: qgsattributeeditorelement.h:63
QgsAttributeEditorQmlElement
Definition: qgsattributeeditorelement.h:454
QgsAttributeEditorField::QgsAttributeEditorField
QgsAttributeEditorField(const QString &name, int idx, QgsAttributeEditorElement *parent)
Creates a new attribute editor element which represents a field.
Definition: qgsattributeeditorelement.h:311
QgsAttributeEditorRelation
Definition: qgsattributeeditorelement.h:333
SIP_TRANSFER
#define SIP_TRANSFER
Definition: qgis_sip.h:36
QgsAttributeEditorRelation::relation
const QgsRelation & relation() const
Gets the id of the relation which shall be embedded.
Definition: qgsattributeeditorelement.h:383
qgsrelation.h
QgsOptionalExpression
Definition: qgsoptionalexpression.h:39
QgsAttributeEditorContainer::setIsGroupBox
virtual void setIsGroupBox(bool isGroupBox)
Determines if this container is rendered as collapsible group box or tab in a tabwidget.
Definition: qgsattributeeditorelement.h:203
QgsAttributeEditorRelation::QgsAttributeEditorRelation
Q_DECL_DEPRECATED QgsAttributeEditorRelation(const QString &name, const QString &relationId, QgsAttributeEditorElement *parent)
Definition: qgsattributeeditorelement.h:340
QgsAttributeEditorElement::AeTypeQmlElement
@ AeTypeQmlElement
A QML element.
Definition: qgsattributeeditorelement.h:67
QgsAttributeEditorElement::mName
QString mName
Definition: qgsattributeeditorelement.h:140
QgsAttributeEditorQmlElement::QgsAttributeEditorQmlElement
QgsAttributeEditorQmlElement(const QString &name, QgsAttributeEditorElement *parent)
Creates a new element which can display QML.
Definition: qgsattributeeditorelement.h:464
QgsAttributeEditorElement::mShowLabel
bool mShowLabel
Definition: qgsattributeeditorelement.h:142
QgsAttributeEditorContainer
Definition: qgsattributeeditorelement.h:170
QgsAttributeEditorElement::type
AttributeEditorType type() const
The type of this element.
Definition: qgsattributeeditorelement.h:99
QgsAttributeEditorElement::clone
virtual QgsAttributeEditorElement * clone(QgsAttributeEditorElement *parent) const =0
Returns a clone of this element.
qgspropertycollection.h
QgsRelation
Definition: qgsrelation.h:41
QgsAttributeEditorElement::AeTypeInvalid
@ AeTypeInvalid
Invalid.
Definition: qgsattributeeditorelement.h:66
QgsAttributeEditorRelation::QgsAttributeEditorRelation
QgsAttributeEditorRelation(const QgsRelation &relation, QgsAttributeEditorElement *parent)
Creates a new element which embeds a relation.
Definition: qgsattributeeditorelement.h:371
QgsAttributeEditorElement::name
QString name() const
Returns the name of this element.
Definition: qgsattributeeditorelement.h:92
SIP_END
#define SIP_END
Definition: qgis_sip.h:189
QgsAttributeEditorElement::AttributeEditorType
AttributeEditorType
Definition: qgsattributeeditorelement.h:61
QgsAttributeEditorElement::AeTypeField
@ AeTypeField
A field.
Definition: qgsattributeeditorelement.h:64
SIP_ABSTRACT
#define SIP_ABSTRACT
Definition: qgis_sip.h:194
QgsAttributeEditorHtmlElement
Definition: qgsattributeeditorelement.h:495
QgsAttributeEditorElement::parent
QgsAttributeEditorElement * parent() const
Gets the parent of this element.
Definition: qgsattributeeditorelement.h:106