QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
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->mButtons = mButtons;
100  element->mForceSuppressFormPopup = mForceSuppressFormPopup;
101  element->mNmRelationId = mNmRelationId;
102  element->mLabel = mLabel;
103 
104  return element;
105 }
106 void QgsAttributeEditorField::saveConfiguration( QDomElement &elem ) const
107 {
108  elem.setAttribute( QStringLiteral( "index" ), mIdx );
109 }
110 
111 QString QgsAttributeEditorField::typeIdentifier() const
112 {
113  return QStringLiteral( "attributeEditorField" );
114 }
115 
116 QDomElement QgsAttributeEditorElement::toDomElement( QDomDocument &doc ) const
117 {
118  QDomElement elem = doc.createElement( typeIdentifier() );
119  elem.setAttribute( QStringLiteral( "name" ), mName );
120  elem.setAttribute( QStringLiteral( "showLabel" ), mShowLabel );
121  saveConfiguration( elem );
122  return elem;
123 }
124 
126 {
127  return mShowLabel;
128 }
129 
131 {
133 }
134 
135 void QgsAttributeEditorRelation::saveConfiguration( QDomElement &elem ) const
136 {
137  elem.setAttribute( QStringLiteral( "relation" ), mRelation.id() );
138  elem.setAttribute( QStringLiteral( "buttons" ), qgsFlagValueToKeys( mButtons ) );
139  elem.setAttribute( QStringLiteral( "forceSuppressFormPopup" ), mForceSuppressFormPopup );
140  elem.setAttribute( QStringLiteral( "nmRelationId" ), mNmRelationId.toString() );
141  elem.setAttribute( QStringLiteral( "label" ), mLabel );
142 }
143 
144 QString QgsAttributeEditorRelation::typeIdentifier() const
145 {
146  return QStringLiteral( "attributeEditorRelation" );
147 }
148 
150 {
151  return mButtons.testFlag( Button::Link );
152 }
153 
155 {
156  mButtons.setFlag( Button::Link, showLinkButton );
157 }
158 
160 {
161  return mButtons.testFlag( Button::Unlink );
162 }
163 
165 {
166  mButtons.setFlag( Button::Unlink, showUnlinkButton );
167 }
168 
170 {
171  mButtons.setFlag( Button::SaveChildEdits, showSaveChildEdits );
172 }
173 
175 {
176  return mButtons.testFlag( Button::SaveChildEdits );
177 }
178 
179 void QgsAttributeEditorRelation::setVisibleButtons( const QgsAttributeEditorRelation::Buttons &buttons )
180 {
181  mButtons = buttons;
182 }
183 
184 void QgsAttributeEditorRelation::setForceSuppressFormPopup( bool forceSuppressFormPopup )
185 {
186  mForceSuppressFormPopup = forceSuppressFormPopup;
187 }
188 
190 {
191  return mForceSuppressFormPopup;
192 }
193 
194 void QgsAttributeEditorRelation::setNmRelationId( const QVariant &nmRelationId )
195 {
196  mNmRelationId = nmRelationId;
197 }
198 
200 {
201  return mNmRelationId;
202 }
203 
204 void QgsAttributeEditorRelation::setLabel( const QString &label )
205 {
206  mLabel = label;
207 }
208 
210 {
211  return mLabel;
212 }
213 
215 {
217  element->setQmlCode( mQmlCode );
218 
219  return element;
220 }
221 
223 {
224  return mQmlCode;
225 }
226 
227 void QgsAttributeEditorQmlElement::setQmlCode( const QString &qmlCode )
228 {
229  mQmlCode = qmlCode;
230 }
231 
232 void QgsAttributeEditorQmlElement::saveConfiguration( QDomElement &elem ) const
233 {
234  QDomText codeElem = elem.ownerDocument().createTextNode( mQmlCode );
235  elem.appendChild( codeElem );
236 }
237 
238 QString QgsAttributeEditorQmlElement::typeIdentifier() const
239 {
240  return QStringLiteral( "attributeEditorQmlElement" );
241 }
242 
244 {
246  element->setHtmlCode( mHtmlCode );
247 
248  return element;
249 }
250 
252 {
253  return mHtmlCode;
254 }
255 
256 void QgsAttributeEditorHtmlElement::setHtmlCode( const QString &htmlCode )
257 {
258  mHtmlCode = htmlCode;
259 }
260 
261 void QgsAttributeEditorHtmlElement::saveConfiguration( QDomElement &elem ) const
262 {
263  QDomText codeElem = elem.ownerDocument().createTextNode( mHtmlCode );
264  elem.appendChild( codeElem );
265 }
266 
267 QString QgsAttributeEditorHtmlElement::typeIdentifier() const
268 {
269  return QStringLiteral( "attributeEditorHtmlElement" );
270 }
271 
QgsAttributeEditorHtmlElement::clone
QgsAttributeEditorElement * clone(QgsAttributeEditorElement *parent) const override
Returns a clone of this element.
Definition: qgsattributeeditorelement.cpp:243
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
This is an abstract base class for any elements of a drag and drop form.
Definition: qgsattributeeditorelement.h:40
qgsFlagValueToKeys
QString qgsFlagValueToKeys(const T &value)
Returns the value for the given keys of a flag.
Definition: qgis.h:549
QgsRelationManager
This class manages a set of relations between layers.
Definition: qgsrelationmanager.h:35
QgsAttributeEditorRelation::showLinkButton
Q_DECL_DEPRECATED bool showLinkButton() const
Determines if the "link feature" button should be shown.
Definition: qgsattributeeditorelement.cpp:149
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
This element will load a field's widget onto the form.
Definition: qgsattributeeditorelement.h:302
QgsAttributeEditorElement::setShowLabel
void setShowLabel(bool showLabel)
Controls if this element should be labeled with a title (field, relation or groupname).
Definition: qgsattributeeditorelement.cpp:130
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
Q_DECL_DEPRECATED void setShowUnlinkButton(bool showUnlinkButton)
Determines if the "unlink feature" button should be shown.
Definition: qgsattributeeditorelement.cpp:164
QgsRelationManager::relation
Q_INVOKABLE QgsRelation relation(const QString &id) const
Gets access to a relation by its id.
Definition: qgsrelationmanager.cpp:96
QgsRelation::id
Q_GADGET QString id
Definition: qgsrelation.h:45
QgsAttributeEditorRelation::setVisibleButtons
void setVisibleButtons(const QgsAttributeEditorRelation::Buttons &buttons)
Defines the buttons which are shown.
Definition: qgsattributeeditorelement.cpp:179
QgsAttributeEditorHtmlElement::QgsAttributeEditorHtmlElement
QgsAttributeEditorHtmlElement(const QString &name, QgsAttributeEditorElement *parent)
Creates a new element which can display HTML.
Definition: qgsattributeeditorelement.h:581
QgsAttributeEditorRelation::init
bool init(QgsRelationManager *relManager)
Initializes the relation from the id.
Definition: qgsattributeeditorelement.cpp:89
QgsAttributeEditorRelation::setShowLinkButton
Q_DECL_DEPRECATED void setShowLinkButton(bool showLinkButton)
Determines if the "link feature" button should be shown.
Definition: qgsattributeeditorelement.cpp:154
QgsAttributeEditorRelation::setShowSaveChildEditsButton
Q_DECL_DEPRECATED void setShowSaveChildEditsButton(bool showChildEdits)
Determines if the "Save child layer edits" button should be shown.
Definition: qgsattributeeditorelement.cpp:169
QgsAttributeEditorRelation::setNmRelationId
void setNmRelationId(const QVariant &nmRelationId=QVariant())
Sets nmRelationId for the relation id of the second relation involved in an N:M relation.
Definition: qgsattributeeditorelement.cpp:194
QgsAttributeEditorElement::AeTypeContainer
@ AeTypeContainer
A container.
Definition: qgsattributeeditorelement.h:64
QgsAttributeEditorQmlElement
An attribute editor widget that will represent arbitrary QML code.
Definition: qgsattributeeditorelement.h:531
QgsAttributeEditorElement::showLabel
bool showLabel() const
Controls if this element should be labeled with a title (field, relation or groupname).
Definition: qgsattributeeditorelement.cpp:125
QgsAttributeEditorField::QgsAttributeEditorField
QgsAttributeEditorField(const QString &name, int idx, QgsAttributeEditorElement *parent)
Creates a new attribute editor element which represents a field.
Definition: qgsattributeeditorelement.h:312
QgsAttributeEditorRelation
This element will load a relation editor onto the form.
Definition: qgsattributeeditorelement.h:335
QgsAttributeEditorQmlElement::clone
QgsAttributeEditorElement * clone(QgsAttributeEditorElement *parent) const override
Returns a clone of this element.
Definition: qgsattributeeditorelement.cpp:214
QgsAttributeEditorQmlElement::setQmlCode
void setQmlCode(const QString &qmlCode)
Sets the QML code that will be represented within this widget to qmlCode.
Definition: qgsattributeeditorelement.cpp:227
QgsAttributeEditorQmlElement::qmlCode
QString qmlCode() const
The QML code that will be represented within this widget.
Definition: qgsattributeeditorelement.cpp:222
QgsAttributeEditorRelation::showUnlinkButton
Q_DECL_DEPRECATED bool showUnlinkButton() const
Determines if the "unlink feature" button should be shown.
Definition: qgsattributeeditorelement.cpp:159
QgsAttributeEditorRelation::label
QString label() const
Determines the label of this element.
Definition: qgsattributeeditorelement.cpp:209
QgsAttributeEditorHtmlElement::setHtmlCode
void setHtmlCode(const QString &htmlCode)
Sets the HTML code that will be represented within this widget to htmlCode.
Definition: qgsattributeeditorelement.cpp:256
QgsAttributeEditorRelation::forceSuppressFormPopup
bool forceSuppressFormPopup() const
Determines the force suppress form popup status.
Definition: qgsattributeeditorelement.cpp:189
QgsOptionalExpression
An expression with an additional enabled flag.
Definition: qgsoptionalexpression.h:40
QgsAttributeEditorField::clone
QgsAttributeEditorElement * clone(QgsAttributeEditorElement *parent) const override
Returns a clone of this element.
Definition: qgsattributeeditorelement.cpp:82
qgsrelationmanager.h
QgsAttributeEditorRelation::nmRelationId
QVariant nmRelationId() const
Determines the relation id of the second relation involved in an N:M relation.
Definition: qgsattributeeditorelement.cpp:199
QgsAttributeEditorRelation::QgsAttributeEditorRelation
Q_DECL_DEPRECATED QgsAttributeEditorRelation(const QString &name, const QString &relationId, QgsAttributeEditorElement *parent)
Definition: qgsattributeeditorelement.h:361
QgsAttributeEditorHtmlElement::htmlCode
QString htmlCode() const
The QML code that will be represented within this widget.
Definition: qgsattributeeditorelement.cpp:251
QgsAttributeEditorElement::mName
QString mName
Definition: qgsattributeeditorelement.h:141
QgsAttributeEditorContainer::setBackgroundColor
void setBackgroundColor(const QColor &backgroundColor)
Sets the background color to backgroundColor.
Definition: qgsattributeeditorelement.cpp:48
QgsAttributeEditorRelation::setForceSuppressFormPopup
void setForceSuppressFormPopup(bool forceSuppressFormPopup)
Sets force suppress form popup status to forceSuppressFormPopup.
Definition: qgsattributeeditorelement.cpp:184
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:540
QgsAttributeEditorElement::mShowLabel
bool mShowLabel
Definition: qgsattributeeditorelement.h:143
QgsAttributeEditorContainer
This is a container for attribute editors, used to group them visually in the attribute form if it is...
Definition: qgsattributeeditorelement.h:172
QgsRelation::isValid
bool isValid
Definition: qgsrelation.h:49
QgsAttributeEditorRelation::showSaveChildEditsButton
Q_DECL_DEPRECATED bool showSaveChildEditsButton() const
Determines if the "Save child layer edits" button should be shown.
Definition: qgsattributeeditorelement.cpp:174
QgsAttributeEditorElement::type
AttributeEditorType type() const
The type of this element.
Definition: qgsattributeeditorelement.h:100
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:93
QgsAttributeEditorRelation::setLabel
void setLabel(const QString &label=QString())
Sets label for this element If it's empty it takes the relation id as label.
Definition: qgsattributeeditorelement.cpp:204
QgsAttributeEditorElement::toDomElement
QDomElement toDomElement(QDomDocument &doc) const
Gets the XML Dom element to save this element.
Definition: qgsattributeeditorelement.cpp:116
qgsattributeeditorelement.h
QgsAttributeEditorElement::AttributeEditorType
AttributeEditorType
Definition: qgsattributeeditorelement.h:63
QgsAttributeEditorContainer::addChildElement
virtual void addChildElement(QgsAttributeEditorElement *element)
Add a child element to this container.
Definition: qgsattributeeditorelement.cpp:20
QgsAttributeEditorHtmlElement
An attribute editor widget that will represent arbitrary HTML code.
Definition: qgsattributeeditorelement.h:572
QgsAttributeEditorElement::parent
QgsAttributeEditorElement * parent() const
Gets the parent of this element.
Definition: qgsattributeeditorelement.h:107
QgsAttributeEditorContainer::backgroundColor
QColor backgroundColor() const
backgroundColor
Definition: qgsattributeeditorelement.cpp:43