QGIS API Documentation  3.8.0-Zanzibar (11aff65)
qgsattributeeditorelement.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgsattributeeditorelement.cpp - QgsAttributeEditorElement
3 
4  ---------------------
5  begin : 18.8.2016
6  copyright : (C) 2016 by Matthias Kuhn
7  email : matthias@opengis.ch
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  ***************************************************************************/
17 #include "qgsrelationmanager.h"
18 
20 {
21  mChildren.append( widget );
22 }
23 
25 {
26  mName = name;
27 }
28 
30 {
31  return mVisibilityExpression;
32 }
33 
35 {
36  if ( visibilityExpression == mVisibilityExpression )
37  return;
38 
39  mVisibilityExpression = visibilityExpression;
40 }
41 
43 {
44  return mBackgroundColor;
45 }
46 
48 {
49  mBackgroundColor = backgroundColor;
50 }
51 
53 {
54  QList<QgsAttributeEditorElement *> results;
55 
56  const auto constMChildren = mChildren;
57  for ( QgsAttributeEditorElement *elem : constMChildren )
58  {
59  if ( elem->type() == type )
60  {
61  results.append( elem );
62  }
63 
64  if ( elem->type() == AeTypeContainer )
65  {
66  QgsAttributeEditorContainer *cont = dynamic_cast<QgsAttributeEditorContainer *>( elem );
67  if ( cont )
68  results += cont->findElements( type );
69  }
70  }
71 
72  return results;
73 }
74 
76 {
77  qDeleteAll( mChildren );
78  mChildren.clear();
79 }
80 
82 {
83  QgsAttributeEditorField *element = new QgsAttributeEditorField( name(), mIdx, parent );
84 
85  return element;
86 }
87 
89 {
90  mRelation = relationManager->relation( mRelationId );
91  return mRelation.isValid();
92 }
93 
95 {
96  QgsAttributeEditorRelation *element = new QgsAttributeEditorRelation( mRelationId, parent );
97  element->mRelation = mRelation;
98  element->mShowLinkButton = mShowLinkButton;
99  element->mShowUnlinkButton = mShowUnlinkButton;
100 
101  return element;
102 }
103 void QgsAttributeEditorField::saveConfiguration( QDomElement &elem ) const
104 {
105  elem.setAttribute( QStringLiteral( "index" ), mIdx );
106 }
107 
108 QString QgsAttributeEditorField::typeIdentifier() const
109 {
110  return QStringLiteral( "attributeEditorField" );
111 }
112 
113 QDomElement QgsAttributeEditorElement::toDomElement( QDomDocument &doc ) const
114 {
115  QDomElement elem = doc.createElement( typeIdentifier() );
116  elem.setAttribute( QStringLiteral( "name" ), mName );
117  elem.setAttribute( QStringLiteral( "showLabel" ), mShowLabel );
118 
119  saveConfiguration( elem );
120  return elem;
121 }
122 
124 {
125  return mShowLabel;
126 }
127 
129 {
131 }
132 
133 void QgsAttributeEditorRelation::saveConfiguration( QDomElement &elem ) const
134 {
135  elem.setAttribute( QStringLiteral( "relation" ), mRelation.id() );
136  elem.setAttribute( QStringLiteral( "showLinkButton" ), mShowLinkButton );
137  elem.setAttribute( QStringLiteral( "showUnlinkButton" ), mShowUnlinkButton );
138 }
139 
140 QString QgsAttributeEditorRelation::typeIdentifier() const
141 {
142  return QStringLiteral( "attributeEditorRelation" );
143 }
144 
146 {
147  return mShowLinkButton;
148 }
149 
151 {
152  mShowLinkButton = showLinkButton;
153 }
154 
156 {
157  return mShowUnlinkButton;
158 }
159 
161 {
162  mShowUnlinkButton = showUnlinkButton;
163 }
164 
166 {
168  element->setQmlCode( mQmlCode );
169 
170  return element;
171 }
172 
174 {
175  return mQmlCode;
176 }
177 
178 void QgsAttributeEditorQmlElement::setQmlCode( const QString &qmlCode )
179 {
180  mQmlCode = qmlCode;
181 }
182 
183 void QgsAttributeEditorQmlElement::saveConfiguration( QDomElement &elem ) const
184 {
185  QDomText codeElem = elem.ownerDocument().createTextNode( mQmlCode );
186  elem.appendChild( codeElem );
187 }
188 
189 QString QgsAttributeEditorQmlElement::typeIdentifier() const
190 {
191  return QStringLiteral( "attributeEditorQmlElement" );
192 }
193 
195 {
197  element->setHtmlCode( mHtmlCode );
198 
199  return element;
200 }
201 
203 {
204  return mHtmlCode;
205 }
206 
207 void QgsAttributeEditorHtmlElement::setHtmlCode( const QString &htmlCode )
208 {
209  mHtmlCode = htmlCode;
210 }
211 
212 void QgsAttributeEditorHtmlElement::saveConfiguration( QDomElement &elem ) const
213 {
214  QDomText codeElem = elem.ownerDocument().createTextNode( mHtmlCode );
215  elem.appendChild( codeElem );
216 }
217 
218 QString QgsAttributeEditorHtmlElement::typeIdentifier() const
219 {
220  return QStringLiteral( "attributeEditorHtmlElement" );
221 }
222 
void clear()
Clear all children from this container.
An attribute editor widget that will represent arbitrary QML code.
bool init(QgsRelationManager *relManager)
Initializes the relation from the id.
void setName(const QString &name)
Change the name of this container.
This is an abstract base class for any elements of a drag and drop form.
void setVisibilityExpression(const QgsOptionalExpression &visibilityExpression)
The visibility expression is used in the attribute form to show or hide this container based on an ex...
QgsAttributeEditorElement * clone(QgsAttributeEditorElement *parent) const override
Returns a clone of this element.
QgsAttributeEditorElement * clone(QgsAttributeEditorElement *parent) const override
Returns a clone of this element.
virtual QList< QgsAttributeEditorElement * > findElements(AttributeEditorType type) const
Traverses the element tree to find any element of the specified type.
This element will load a field&#39;s widget onto the form.
QDomElement toDomElement(QDomDocument &doc) const
Gets the XML Dom element to save this element.
QgsAttributeEditorElement * clone(QgsAttributeEditorElement *parent) const override
Returns a clone of this element.
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.
void setBackgroundColor(const QColor &backgroundColor)
Sets the background color to backgroundColor.
void setQmlCode(const QString &qmlCode)
Sets the QML code that will be represented within this widget to qmlCode.
An expression with an additional enabled flag.
void setShowLabel(bool showLabel)
Controls if this element should be labeled with a title (field, relation or groupname).
bool showUnlinkButton() const
Determines if the "unlink feature" button should be shown.
bool showLabel() const
Controls if this element should be labeled with a title (field, relation or groupname).
QgsAttributeEditorElement * parent() const
Gets the parent of this element.
QgsOptionalExpression visibilityExpression() const
The visibility expression is used in the attribute form to show or hide this container based on an ex...
QString qmlCode() const
The QML code that will be represented within this widget.
QString htmlCode() const
The QML code that will be represented within this widget.
void setShowLinkButton(bool showLinkButton)
Determines if the "link feature" button should be shown.
void setShowUnlinkButton(bool showUnlinkButton)
Determines if the "unlink feature" button should be shown.
QColor backgroundColor() const
backgroundColor
void setHtmlCode(const QString &htmlCode)
Sets the HTML code that will be represented within this widget to htmlCode.
bool isValid
Definition: qgsrelation.h:49
This class manages a set of relations between layers.
QgsAttributeEditorElement * clone(QgsAttributeEditorElement *parent) const override
Returns a clone of this element.
This is a container for attribute editors, used to group them visually in the attribute form if it is...
virtual void addChildElement(QgsAttributeEditorElement *element)
Add a child element to this container.
bool showLinkButton() const
Determines if the "link feature" button should be shown.
Q_INVOKABLE QgsRelation relation(const QString &id) const
Gets access to a relation by its id.
QString name() const
Returns the name of this element.