QGIS API Documentation  3.14.0-Pi (9f7028fd23)
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 : [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  ***************************************************************************/
17 #include "qgsrelationmanager.h"
18 
19 
21 {
22  mChildren.append( widget );
23 }
24 
25 void QgsAttributeEditorContainer::setName( const QString &name )
26 {
27  mName = name;
28 }
29 
31 {
32  return mVisibilityExpression;
33 }
34 
36 {
37  if ( visibilityExpression == mVisibilityExpression )
38  return;
39 
40  mVisibilityExpression = visibilityExpression;
41 }
42 
44 {
45  return mBackgroundColor;
46 }
47 
48 void QgsAttributeEditorContainer::setBackgroundColor( const QColor &backgroundColor )
49 {
50  mBackgroundColor = backgroundColor;
51 }
52 
54 {
55  QList<QgsAttributeEditorElement *> results;
56 
57  const auto constMChildren = mChildren;
58  for ( QgsAttributeEditorElement *elem : constMChildren )
59  {
60  if ( elem->type() == type )
61  {
62  results.append( elem );
63  }
64 
65  if ( elem->type() == AeTypeContainer )
66  {
67  QgsAttributeEditorContainer *cont = dynamic_cast<QgsAttributeEditorContainer *>( elem );
68  if ( cont )
69  results += cont->findElements( type );
70  }
71  }
72 
73  return results;
74 }
75 
77 {
78  qDeleteAll( mChildren );
79  mChildren.clear();
80 }
81 
83 {
85 
86  return element;
87 }
88 
90 {
91  mRelation = relationManager->relation( mRelationId );
92  return mRelation.isValid();
93 }
94 
96 {
97  QgsAttributeEditorRelation *element = new QgsAttributeEditorRelation( mRelationId, parent );
98  element->mRelation = mRelation;
99  element->mShowLinkButton = mShowLinkButton;
100  element->mShowUnlinkButton = mShowUnlinkButton;
101 
102  return element;
103 }
104 void QgsAttributeEditorField::saveConfiguration( QDomElement &elem ) const
105 {
106  elem.setAttribute( QStringLiteral( "index" ), mIdx );
107 }
108 
109 QString QgsAttributeEditorField::typeIdentifier() const
110 {
111  return QStringLiteral( "attributeEditorField" );
112 }
113 
114 QDomElement QgsAttributeEditorElement::toDomElement( QDomDocument &doc ) const
115 {
116  QDomElement elem = doc.createElement( typeIdentifier() );
117  elem.setAttribute( QStringLiteral( "name" ), mName );
118  elem.setAttribute( QStringLiteral( "showLabel" ), mShowLabel );
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  elem.setAttribute( QStringLiteral( "showSaveChildEditsButton" ), mShowSaveChildEditsButton );
139 }
140 
141 QString QgsAttributeEditorRelation::typeIdentifier() const
142 {
143  return QStringLiteral( "attributeEditorRelation" );
144 }
145 
147 {
148  return mShowLinkButton;
149 }
150 
152 {
153  mShowLinkButton = showLinkButton;
154 }
155 
157 {
158  return mShowUnlinkButton;
159 }
160 
162 {
163  mShowUnlinkButton = showUnlinkButton;
164 }
165 
167 {
168  mShowSaveChildEditsButton = showSaveChildEdits;
169 }
170 
172 {
173  return mShowSaveChildEditsButton;
174 }
175 
177 {
179  element->setQmlCode( mQmlCode );
180 
181  return element;
182 }
183 
185 {
186  return mQmlCode;
187 }
188 
189 void QgsAttributeEditorQmlElement::setQmlCode( const QString &qmlCode )
190 {
191  mQmlCode = qmlCode;
192 }
193 
194 void QgsAttributeEditorQmlElement::saveConfiguration( QDomElement &elem ) const
195 {
196  QDomText codeElem = elem.ownerDocument().createTextNode( mQmlCode );
197  elem.appendChild( codeElem );
198 }
199 
200 QString QgsAttributeEditorQmlElement::typeIdentifier() const
201 {
202  return QStringLiteral( "attributeEditorQmlElement" );
203 }
204 
206 {
208  element->setHtmlCode( mHtmlCode );
209 
210  return element;
211 }
212 
214 {
215  return mHtmlCode;
216 }
217 
218 void QgsAttributeEditorHtmlElement::setHtmlCode( const QString &htmlCode )
219 {
220  mHtmlCode = htmlCode;
221 }
222 
223 void QgsAttributeEditorHtmlElement::saveConfiguration( QDomElement &elem ) const
224 {
225  QDomText codeElem = elem.ownerDocument().createTextNode( mHtmlCode );
226  elem.appendChild( codeElem );
227 }
228 
229 QString QgsAttributeEditorHtmlElement::typeIdentifier() const
230 {
231  return QStringLiteral( "attributeEditorHtmlElement" );
232 }
233 
QgsAttributeEditorHtmlElement::clone
QgsAttributeEditorElement * clone(QgsAttributeEditorElement *parent) const override
Returns a clone of this element.
Definition: qgsattributeeditorelement.cpp:205
QgsAttributeEditorContainer::setVisibilityExpression
void setVisibilityExpression(const QgsOptionalExpression &visibilityExpression)
The visibility expression is used in the attribute form to show or hide this container based on an ex...
Definition: qgsattributeeditorelement.cpp:35
QgsAttributeEditorElement
Definition: qgsattributeeditorelement.h:38
QgsRelationManager
Definition: qgsrelationmanager.h:34
QgsAttributeEditorRelation::showLinkButton
bool showLinkButton() const
Determines if the "link feature" button should be shown.
Definition: qgsattributeeditorelement.cpp:146
QgsAttributeEditorContainer::findElements
virtual QList< QgsAttributeEditorElement * > findElements(AttributeEditorType type) const
Traverses the element tree to find any element of the specified type.
Definition: qgsattributeeditorelement.cpp:53
QgsAttributeEditorField
Definition: qgsattributeeditorelement.h:300
QgsAttributeEditorElement::setShowLabel
void setShowLabel(bool showLabel)
Controls if this element should be labeled with a title (field, relation or groupname).
Definition: qgsattributeeditorelement.cpp:128
QgsAttributeEditorRelation::clone
QgsAttributeEditorElement * clone(QgsAttributeEditorElement *parent) const override
Returns a clone of this element.
Definition: qgsattributeeditorelement.cpp:95
QgsAttributeEditorContainer::setName
void setName(const QString &name)
Change the name of this container.
Definition: qgsattributeeditorelement.cpp:25
QgsAttributeEditorRelation::setShowUnlinkButton
void setShowUnlinkButton(bool showUnlinkButton)
Determines if the "unlink feature" button should be shown.
Definition: qgsattributeeditorelement.cpp:161
QgsAttributeEditorRelation::setShowSaveChildEditsButton
void setShowSaveChildEditsButton(bool showSaveChildEditsButton)
Determines if the "save child layer edits" button should be shown.
Definition: qgsattributeeditorelement.cpp:166
QgsRelationManager::relation
Q_INVOKABLE QgsRelation relation(const QString &id) const
Gets access to a relation by its id.
Definition: qgsrelationmanager.cpp:96
QgsAttributeEditorHtmlElement::QgsAttributeEditorHtmlElement
QgsAttributeEditorHtmlElement(const QString &name, QgsAttributeEditorElement *parent)
Creates a new element which can display HTML.
Definition: qgsattributeeditorelement.h:505
QgsAttributeEditorRelation::init
bool init(QgsRelationManager *relManager)
Initializes the relation from the id.
Definition: qgsattributeeditorelement.cpp:89
QgsRelation::id
QString id
Definition: qgsrelation.h:45
QgsAttributeEditorRelation::setShowLinkButton
void setShowLinkButton(bool showLinkButton)
Determines if the "link feature" button should be shown.
Definition: qgsattributeeditorelement.cpp:151
QgsAttributeEditorElement::AeTypeContainer
@ AeTypeContainer
A container.
Definition: qgsattributeeditorelement.h:63
QgsAttributeEditorQmlElement
Definition: qgsattributeeditorelement.h:454
QgsAttributeEditorElement::showLabel
bool showLabel() const
Controls if this element should be labeled with a title (field, relation or groupname).
Definition: qgsattributeeditorelement.cpp:123
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
QgsAttributeEditorQmlElement::clone
QgsAttributeEditorElement * clone(QgsAttributeEditorElement *parent) const override
Returns a clone of this element.
Definition: qgsattributeeditorelement.cpp:176
QgsAttributeEditorQmlElement::setQmlCode
void setQmlCode(const QString &qmlCode)
Sets the QML code that will be represented within this widget to qmlCode.
Definition: qgsattributeeditorelement.cpp:189
QgsAttributeEditorQmlElement::qmlCode
QString qmlCode() const
The QML code that will be represented within this widget.
Definition: qgsattributeeditorelement.cpp:184
QgsAttributeEditorRelation::showUnlinkButton
bool showUnlinkButton() const
Determines if the "unlink feature" button should be shown.
Definition: qgsattributeeditorelement.cpp:156
QgsAttributeEditorHtmlElement::setHtmlCode
void setHtmlCode(const QString &htmlCode)
Sets the HTML code that will be represented within this widget to htmlCode.
Definition: qgsattributeeditorelement.cpp:218
QgsOptionalExpression
Definition: qgsoptionalexpression.h:39
QgsAttributeEditorField::clone
QgsAttributeEditorElement * clone(QgsAttributeEditorElement *parent) const override
Returns a clone of this element.
Definition: qgsattributeeditorelement.cpp:82
qgsrelationmanager.h
QgsAttributeEditorRelation::QgsAttributeEditorRelation
Q_DECL_DEPRECATED QgsAttributeEditorRelation(const QString &name, const QString &relationId, QgsAttributeEditorElement *parent)
Definition: qgsattributeeditorelement.h:340
QgsAttributeEditorHtmlElement::htmlCode
QString htmlCode() const
The QML code that will be represented within this widget.
Definition: qgsattributeeditorelement.cpp:213
QgsAttributeEditorElement::mName
QString mName
Definition: qgsattributeeditorelement.h:140
QgsAttributeEditorContainer::setBackgroundColor
void setBackgroundColor(const QColor &backgroundColor)
Sets the background color to backgroundColor.
Definition: qgsattributeeditorelement.cpp:48
QgsAttributeEditorContainer::clear
void clear()
Clear all children from this container.
Definition: qgsattributeeditorelement.cpp:76
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
QgsRelation::isValid
bool isValid
Definition: qgsrelation.h:49
QgsAttributeEditorRelation::showSaveChildEditsButton
bool showSaveChildEditsButton() const
Returns true if the "save child layer edits" button should be shown.
Definition: qgsattributeeditorelement.cpp:171
QgsAttributeEditorElement::type
AttributeEditorType type() const
The type of this element.
Definition: qgsattributeeditorelement.h:99
QgsAttributeEditorContainer::visibilityExpression
QgsOptionalExpression visibilityExpression() const
The visibility expression is used in the attribute form to show or hide this container based on an ex...
Definition: qgsattributeeditorelement.cpp:30
QgsAttributeEditorElement::name
QString name() const
Returns the name of this element.
Definition: qgsattributeeditorelement.h:92
QgsAttributeEditorElement::toDomElement
QDomElement toDomElement(QDomDocument &doc) const
Gets the XML Dom element to save this element.
Definition: qgsattributeeditorelement.cpp:114
qgsattributeeditorelement.h
QgsAttributeEditorElement::AttributeEditorType
AttributeEditorType
Definition: qgsattributeeditorelement.h:61
QgsAttributeEditorContainer::addChildElement
virtual void addChildElement(QgsAttributeEditorElement *element)
Add a child element to this container.
Definition: qgsattributeeditorelement.cpp:20
QgsAttributeEditorHtmlElement
Definition: qgsattributeeditorelement.h:495
QgsAttributeEditorElement::parent
QgsAttributeEditorElement * parent() const
Gets the parent of this element.
Definition: qgsattributeeditorelement.h:106
QgsAttributeEditorContainer::backgroundColor
QColor backgroundColor() const
backgroundColor
Definition: qgsattributeeditorelement.cpp:43