QGIS API Documentation  3.24.2-Tisler (13c1a02865)
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  ***************************************************************************/
16 
18 
25 
26 
27 
28 QDomElement QgsAttributeEditorElement::toDomElement( QDomDocument &doc ) const
29 {
30  QDomElement elem = doc.createElement( typeIdentifier() );
31  elem.setAttribute( QStringLiteral( "name" ), mName );
32  elem.setAttribute( QStringLiteral( "showLabel" ), mShowLabel );
33  saveConfiguration( elem, doc );
34  return elem;
35 }
36 
38 {
39  return mShowLabel;
40 }
41 
43 {
45 }
46 
47 QgsAttributeEditorElement *QgsAttributeEditorElement::create( const QDomElement &element, const QString &layerId, const QgsFields &fields, const QgsReadWriteContext &context, QgsAttributeEditorElement *parent )
48 {
49  QgsAttributeEditorElement *newElement = nullptr;
50 
51  const QString name = element.attribute( QStringLiteral( "name" ) );
52 
53  if ( element.tagName() == QLatin1String( "attributeEditorContainer" ) )
54  {
55  newElement = new QgsAttributeEditorContainer( context.projectTranslator()->translate( QStringLiteral( "project:layers:%1:formcontainers" ).arg( layerId ),
56  name ), parent );
57  }
58  else if ( element.tagName() == QLatin1String( "attributeEditorField" ) )
59  {
60  const int idx = fields.lookupField( name );
61  newElement = new QgsAttributeEditorField( name, idx, parent );
62  }
63  else if ( element.tagName() == QLatin1String( "attributeEditorRelation" ) )
64  {
65  // At this time, the relations are not loaded
66  // So we only grab the id and delegate the rest to onRelationsLoaded()
67  newElement = new QgsAttributeEditorRelation( element.attribute( QStringLiteral( "relation" ), QStringLiteral( "[None]" ) ), parent );
68  }
69  else if ( element.tagName() == QLatin1String( "attributeEditorQmlElement" ) )
70  {
71  newElement = new QgsAttributeEditorQmlElement( element.attribute( QStringLiteral( "name" ) ), parent );
72  }
73  else if ( element.tagName() == QLatin1String( "attributeEditorHtmlElement" ) )
74  {
75  newElement = new QgsAttributeEditorHtmlElement( element.attribute( QStringLiteral( "name" ) ), parent );
76  }
77  else if ( element.tagName() == QLatin1String( "attributeEditorAction" ) )
78  {
79  newElement = new QgsAttributeEditorAction( QUuid( element.attribute( QStringLiteral( "name" ) ) ), parent );
80  }
81 
82  if ( newElement )
83  {
84  if ( element.hasAttribute( QStringLiteral( "showLabel" ) ) )
85  newElement->setShowLabel( element.attribute( QStringLiteral( "showLabel" ) ).toInt() );
86  else
87  newElement->setShowLabel( true );
88 
89  newElement->loadConfiguration( element, layerId, context, fields );
90  }
91 
92  return newElement;
93 }
94 
This element will load a layer action onto the form.
This is a container for attribute editors, used to group them visually in the attribute form if it is...
This is an abstract base class for any elements of a drag and drop form.
QDomElement toDomElement(QDomDocument &doc) const
Gets the XML Dom element to save this element.
bool showLabel() const
Controls if this element should be labeled with a title (field, relation or groupname).
QString name() const
Returns the name of this element.
static QgsAttributeEditorElement * create(const QDomElement &element, const QString &layerId, const QgsFields &fields, const QgsReadWriteContext &context, QgsAttributeEditorElement *parent=nullptr)
Constructs the editor element from the given element.
void setShowLabel(bool showLabel)
Controls if this element should be labeled with a title (field, relation or groupname).
QgsAttributeEditorElement * parent() const
Gets the parent of this element.
This element will load a field's widget onto the form.
An attribute editor widget that will represent arbitrary HTML code.
An attribute editor widget that will represent arbitrary QML code.
This element will load a relation editor onto the form.
Container of fields for a vector layer.
Definition: qgsfields.h:45
int lookupField(const QString &fieldName) const
Looks up field's index from the field name.
Definition: qgsfields.cpp:349
virtual QString translate(const QString &context, const QString &sourceText, const char *disambiguation=nullptr, int n=-1) const =0
The derived translate() translates with QTranslator and qm file the sourceText.
The class is used as a container of context for various read/write operations on other objects.
const QgsProjectTranslator * projectTranslator() const
Returns the project translator.