32using namespace Qt::StringLiterals;
36 QDomElement elem = doc.createElement( typeIdentifier() );
37 elem.setAttribute( u
"name"_s,
mName );
38 elem.setAttribute( u
"showLabel"_s,
mShowLabel );
42 saveConfiguration( elem, doc );
70 std::unique_ptr<QgsAttributeEditorElement> newElement;
72 const QString
name = element.attribute( u
"name"_s );
74 if ( element.tagName() ==
"attributeEditorContainer"_L1 )
78 else if ( element.tagName() ==
"attributeEditorField"_L1 )
81 newElement = std::make_unique<QgsAttributeEditorField>(
name, idx,
parent );
83 else if ( element.tagName() ==
"attributeEditorRelation"_L1 )
87 newElement = std::make_unique<QgsAttributeEditorRelation>( element.attribute( u
"relation"_s, u
"[None]"_s ),
parent );
89 else if ( element.tagName() ==
"attributeEditorQmlElement"_L1 )
91 newElement = std::make_unique<QgsAttributeEditorQmlElement>( element.attribute( u
"name"_s ),
parent );
93 else if ( element.tagName() ==
"attributeEditorHtmlElement"_L1 )
95 newElement = std::make_unique<QgsAttributeEditorHtmlElement>( element.attribute( u
"name"_s ),
parent );
97 else if ( element.tagName() ==
"attributeEditorTextElement"_L1 )
99 newElement = std::make_unique<QgsAttributeEditorTextElement>( element.attribute( u
"name"_s ),
parent );
101 else if ( element.tagName() ==
"attributeEditorSpacerElement"_L1 )
103 newElement = std::make_unique<QgsAttributeEditorSpacerElement>( element.attribute( u
"name"_s ),
parent );
105 else if ( element.tagName() ==
"attributeEditorAction"_L1 )
107 newElement = std::make_unique<QgsAttributeEditorAction>( QUuid( element.attribute( u
"name"_s ) ),
parent );
112 if ( element.hasAttribute( u
"showLabel"_s ) )
113 newElement->setShowLabel( element.attribute( u
"showLabel"_s ).toInt() );
115 newElement->setShowLabel(
true );
117 newElement->setHorizontalStretch( element.attribute( u
"horizontalStretch"_s, u
"0"_s ).toInt() );
118 newElement->setVerticalStretch( element.attribute( u
"verticalStretch"_s, u
"0"_s ).toInt() );
123 newElement->setLabelStyle( style );
125 newElement->loadConfiguration( element, layerId, context, fields );
134 QDomElement element { node.firstChildElement( u
"labelStyle"_s ) };
136 if ( !element.isNull() )
139 if ( element.hasAttribute( u
"labelColor"_s ) )
149 if ( element.hasAttribute( u
"overrideLabelColor"_s ) )
151 overrideColor = element.attribute( u
"overrideLabelColor"_s ) == QChar(
'1' );
154 if ( element.hasAttribute( u
"overrideLabelFont"_s ) )
156 overrideFont = element.attribute( u
"overrideLabelFont"_s ) == QChar(
'1' );
163 QDomElement elem { document.createElement( u
"labelStyle"_s ) };
166 elem.setAttribute( u
"overrideLabelColor"_s,
overrideColor ? QChar(
'1' ) : QChar(
'0' ) );
167 elem.setAttribute( u
"overrideLabelFont"_s,
overrideFont ? QChar(
'1' ) : QChar(
'0' ) );
static std::unique_ptr< 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.
QDomElement toDomElement(QDomDocument &doc) const
Gets the XML Dom element to save this element.
QgsAttributeEditorElement * parent() const
Gets the parent of this element.
QgsAttributeEditorElement(Qgis::AttributeEditorType type, const QString &name, QgsAttributeEditorElement *parent=nullptr)
Constructor.
LabelStyle labelStyle() const
Returns the label style.
void setLabelStyle(const LabelStyle &labelStyle)
Sets the labelStyle.
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.
void setShowLabel(bool showLabel)
Controls if this element should be labeled with a title (field, relation or groupname).
static QColor colorFromString(const QString &string)
Decodes a string into a color value.
static QString colorToString(const QColor &color)
Encodes a color into a string value.
Container of fields for a vector layer.
Q_INVOKABLE int lookupField(const QString &fieldName) const
Looks up field's index from the field name.
static bool setFromXmlChildNode(QFont &font, const QDomElement &element, const QString &childNode)
Sets the properties of a font to match the properties stored in an XML child node.
static QDomElement toXmlElement(const QFont &font, QDomDocument &document, const QString &elementName)
Returns a DOM element containing the properties of the font.
virtual QString translate(const QString &context, const QString &sourceText, const char *disambiguation=nullptr, int n=-1) const =0
Translates a string using the Qt QTranslator mechanism.
A container for the context for various read/write operations on objects.
const QgsProjectTranslator * projectTranslator() const
Returns the project translator.
The TabStyle struct defines color and font overrides for form fields, tabs and groups labels.
void readXml(const QDomNode &node)
Reads configuration from node.
bool overrideColor
Override label color.
QDomElement writeXml(QDomDocument &document) const
Creates the XML configuration from document.
bool overrideFont
Override label font.
bool operator==(LabelStyle const &other) const
Returns true if the style is equal to other.