21using namespace Qt::StringLiterals;
25 qDeleteAll( mChildren );
30 mChildren.append( widget );
53 return mVisibilityExpression;
66 return mCollapsedExpression;
79 return mBackgroundColor;
89 QList<QgsAttributeEditorElement *> results;
91 const auto constMChildren = mChildren;
94 if ( elem->type() ==
type )
96 results.append( elem );
112 qDeleteAll( mChildren );
130 const auto childElements =
children();
136 element->mType = mType;
137 element->mColumnCount = mColumnCount;
138 element->mVisibilityExpression = mVisibilityExpression;
139 element->mCollapsed = mCollapsed;
140 element->mCollapsedExpression = mCollapsedExpression;
146void QgsAttributeEditorContainer::saveConfiguration( QDomElement &elem, QDomDocument &doc )
const
149 elem.setAttribute( u
"columnCount"_s, mColumnCount );
152 elem.setAttribute( u
"collapsed"_s, mCollapsed );
153 elem.setAttribute( u
"collapsedExpressionEnabled"_s, mCollapsedExpression.
enabled() ? 1 : 0 );
154 elem.setAttribute( u
"collapsedExpression"_s, mCollapsedExpression->expression() );
155 elem.setAttribute( u
"visibilityExpressionEnabled"_s, mVisibilityExpression.
enabled() ? 1 : 0 );
156 elem.setAttribute( u
"visibilityExpression"_s, mVisibilityExpression->expression() );
157 if ( mBackgroundColor.isValid() )
158 elem.setAttribute( u
"backgroundColor"_s, mBackgroundColor.name( ) );
159 const auto constMChildren = mChildren;
162 QDomDocument doc = elem.ownerDocument();
163 elem.appendChild( child->toDomElement( doc ) );
167void QgsAttributeEditorContainer::loadConfiguration(
const QDomElement &element,
const QString &layerId,
const QgsReadWriteContext &context,
const QgsFields &fields )
169 mBackgroundColor = element.attribute( u
"backgroundColor"_s, QString() );
171 int cc = element.attribute( u
"columnCount"_s ).toInt( &ok );
176 if ( element.hasAttribute( u
"type"_s ) )
182 const bool isGroupBox = element.attribute( u
"groupBox"_s ).toInt( &ok );
189 const bool isCollapsed = element.attribute( u
"collapsed"_s ).toInt( &ok );
195 const bool collapsedExpressionEnabled = element.attribute( u
"collapsedExpressionEnabled"_s ).toInt( &ok );
200 collapsedExpression.setData( QgsExpression( element.attribute( u
"collapsedExpression"_s ) ) );
205 const bool visibilityExpressionEnabled = element.attribute( u
"visibilityExpressionEnabled"_s ).toInt( &ok );
210 visibilityExpression.setData( QgsExpression( element.attribute( u
"visibilityExpression"_s ) ) );
214 const QDomNodeList childNodeList = element.childNodes();
216 for (
int i = 0; i < childNodeList.size(); i++ )
218 const QDomElement childElem = childNodeList.at( i ).toElement();
226QString QgsAttributeEditorContainer::typeIdentifier()
const
228 return u
"attributeEditorContainer"_s;
AttributeEditorType
Attribute editor types.
QgsAttributeEditorContainer(const QString &name, QgsAttributeEditorElement *parent, const QColor &backgroundColor=QColor())
Creates a new attribute editor container.
virtual void addChildElement(QgsAttributeEditorElement *element)
Add a child element to this container.
QgsOptionalExpression visibilityExpression() const
The visibility expression is used in the attribute form to show or hide this container based on an ex...
void setColumnCount(int columnCount)
Set the number of columns in this group.
~QgsAttributeEditorContainer() override
void setVisibilityExpression(const QgsOptionalExpression &visibilityExpression)
The visibility expression is used in the attribute form to show or hide this container based on an ex...
QgsOptionalExpression collapsedExpression() const
The collapsed expression is used in the attribute form to set the collapsed status of the group box c...
Qgis::AttributeEditorContainerType type() const
Returns the container type.
void setType(Qgis::AttributeEditorContainerType type)
Sets the container type.
void setCollapsedExpression(const QgsOptionalExpression &collapsedExpression)
The collapsed expression is used in the attribute form to set the collapsed status of the group box o...
QList< QgsAttributeEditorElement * > children() const
Gets a list of the children elements of this container.
virtual Q_DECL_DEPRECATED void setIsGroupBox(bool isGroupBox)
Determines if this container is rendered as collapsible group box or tab in a tabwidget.
void clear()
Clear all children from this container.
QgsAttributeEditorElement * clone(QgsAttributeEditorElement *parent) const override
Creates a deep copy of this element.
void setName(const QString &name)
Change the name of this container.
QColor backgroundColor() const
Returns the background color of the container.
void setCollapsed(bool collapsed)
For group box containers sets if this group box is collapsed.
virtual Q_DECL_DEPRECATED bool isGroupBox() const
Returns if this container is going to be a group box.
virtual QList< QgsAttributeEditorElement * > findElements(Qgis::AttributeEditorType type) const
Traverses the element tree to find any element of the specified type.
int columnCount() const
Gets the number of columns in this group.
void setBackgroundColor(const QColor &backgroundColor)
Sets the background color to backgroundColor.
An abstract base class for any elements of a drag and drop form.
QgsAttributeEditorElement * parent() const
Gets the parent of this element.
QgsAttributeEditorElement(Qgis::AttributeEditorType type, const QString &name, QgsAttributeEditorElement *parent=nullptr)
Constructor.
QgsAttributeEditorElement * mParent
Qgis::AttributeEditorType mType
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.
Container of fields for a vector layer.
An expression with an additional enabled flag.
bool enabled() const
Check if this optional is enabled.
A container for the context for various read/write operations on objects.
T qgsEnumKeyToValue(const QString &key, const T &defaultValue, bool tryValueAsKey=true, bool *returnOk=nullptr)
Returns the value corresponding to the given key of an enum.
QString qgsEnumValueToKey(const T &value, bool *returnOk=nullptr)
Returns the value for the given key of an enum.