QGIS API Documentation  3.0.2-Girona (307d082)
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 
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  QList<QgsAttributeEditorElement *> results;
45 
46  Q_FOREACH ( QgsAttributeEditorElement *elem, mChildren )
47  {
48  if ( elem->type() == type )
49  {
50  results.append( elem );
51  }
52 
53  if ( elem->type() == AeTypeContainer )
54  {
55  QgsAttributeEditorContainer *cont = dynamic_cast<QgsAttributeEditorContainer *>( elem );
56  if ( cont )
57  results += cont->findElements( type );
58  }
59  }
60 
61  return results;
62 }
63 
65 {
66  qDeleteAll( mChildren );
67  mChildren.clear();
68 }
69 
71 {
72  QgsAttributeEditorField *element = new QgsAttributeEditorField( name(), mIdx, parent );
73 
74  return element;
75 }
76 
78 {
79  mRelation = relationManager->relation( mRelationId );
80  return mRelation.isValid();
81 }
82 
84 {
85  QgsAttributeEditorRelation *element = new QgsAttributeEditorRelation( name(), mRelationId, parent );
86  element->mRelation = mRelation;
87  element->mShowLinkButton = mShowLinkButton;
88  element->mShowUnlinkButton = mShowUnlinkButton;
89 
90  return element;
91 }
92 void QgsAttributeEditorField::saveConfiguration( QDomElement &elem ) const
93 {
94  elem.setAttribute( QStringLiteral( "index" ), mIdx );
95 }
96 
97 QString QgsAttributeEditorField::typeIdentifier() const
98 {
99  return QStringLiteral( "attributeEditorField" );
100 }
101 
102 QDomElement QgsAttributeEditorElement::toDomElement( QDomDocument &doc ) const
103 {
104  QDomElement elem = doc.createElement( typeIdentifier() );
105  elem.setAttribute( QStringLiteral( "name" ), mName );
106  elem.setAttribute( QStringLiteral( "showLabel" ), mShowLabel );
107 
108  saveConfiguration( elem );
109  return elem;
110 }
111 
113 {
114  return mShowLabel;
115 }
116 
118 {
120 }
121 
122 void QgsAttributeEditorRelation::saveConfiguration( QDomElement &elem ) const
123 {
124  elem.setAttribute( QStringLiteral( "relation" ), mRelation.id() );
125  elem.setAttribute( QStringLiteral( "showLinkButton" ), mShowLinkButton );
126  elem.setAttribute( QStringLiteral( "showUnlinkButton" ), mShowUnlinkButton );
127 }
128 
129 QString QgsAttributeEditorRelation::typeIdentifier() const
130 {
131  return QStringLiteral( "attributeEditorRelation" );
132 }
133 
135 {
136  return mShowLinkButton;
137 }
138 
140 {
141  mShowLinkButton = showLinkButton;
142 }
143 
145 {
146  return mShowUnlinkButton;
147 }
148 
150 {
151  mShowUnlinkButton = showUnlinkButton;
152 }
void clear()
Clear all children from this container.
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.
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
Get the XML Dom element to save this element.
This element will load a relation editor onto the form.
AttributeEditorType type() const
The type of this element.
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
Get 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...
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.
bool isValid
Definition: qgsrelation.h:46
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
Get access to a relation by its id.
QString name() const
Return the name of this element.