Skip to content
Permalink
Browse files

fix legacy config before creating elements to avoid passing widget co…

…nfig
  • Loading branch information
3nids committed Jan 12, 2021
1 parent a6aecf5 commit 9e5b6141896fdcf9515652fd0a536d45eff540f9
@@ -64,7 +64,7 @@ Constructor

virtual ~QgsAttributeEditorElement();

static QgsAttributeEditorElement *create( const QDomElement &element, const QString &layerId, const QgsFields &fields, const QMap<QString, QVariantMap > widgetConfigs, const QgsReadWriteContext &context, QgsAttributeEditorElement *parent = 0 ) /Factory/;
static QgsAttributeEditorElement *create( const QDomElement &element, const QString &layerId, const QgsFields &fields, const QgsReadWriteContext &context, QgsAttributeEditorElement *parent = 0 ) /Factory/;
%Docstring
Constructs the editor element from the given element

@@ -124,7 +124,7 @@ void QgsAttributeEditorContainer::saveConfiguration( QDomElement &elem, QDomDocu
}
}

void QgsAttributeEditorContainer::loadConfiguration( const QDomElement &element, const QString &layerId, const QgsReadWriteContext &context, const QgsFields &fields, const QMap<QString, QVariantMap> widgetConfigs )
void QgsAttributeEditorContainer::loadConfiguration( const QDomElement &element, const QString &layerId, const QgsReadWriteContext &context, const QgsFields &fields )
{
mBackgroundColor = element.attribute( QStringLiteral( "backgroundColor" ), QString() );
bool ok;
@@ -154,7 +154,7 @@ void QgsAttributeEditorContainer::loadConfiguration( const QDomElement &element,
{
QDomElement childElem = childNodeList.at( i ).toElement();

QgsAttributeEditorElement *myElem = create( childElem, layerId, fields, widgetConfigs, context, this );
QgsAttributeEditorElement *myElem = create( childElem, layerId, fields, context, this );
if ( myElem )
addChildElement( myElem );
}
@@ -197,21 +197,20 @@ void QgsAttributeEditorField::saveConfiguration( QDomElement &elem, QDomDocument
elem.setAttribute( QStringLiteral( "index" ), mIdx );
}

void QgsAttributeEditorField::loadConfiguration( const QDomElement &element, const QString &layerId, const QgsReadWriteContext &context, const QgsFields &fields, const QMap<QString, QVariantMap> widgetConfigs )
void QgsAttributeEditorField::loadConfiguration( const QDomElement &element, const QString &layerId, const QgsReadWriteContext &context, const QgsFields &fields )
{
Q_UNUSED( element )
Q_UNUSED( layerId )
Q_UNUSED( context )
Q_UNUSED( fields )
Q_UNUSED( widgetConfigs )
}

QString QgsAttributeEditorField::typeIdentifier() const
{
return QStringLiteral( "attributeEditorField" );
}

QgsAttributeEditorElement *QgsAttributeEditorElement::create( const QDomElement &element, const QString &layerId, const QgsFields &fields, const QMap<QString, QVariantMap> widgetConfigs, const QgsReadWriteContext &context, QgsAttributeEditorElement *parent )
QgsAttributeEditorElement *QgsAttributeEditorElement::create( const QDomElement &element, const QString &layerId, const QgsFields &fields, const QgsReadWriteContext &context, QgsAttributeEditorElement *parent )
{
QgsAttributeEditorElement *newElement = nullptr;

@@ -249,7 +248,7 @@ QgsAttributeEditorElement *QgsAttributeEditorElement::create( const QDomElement
else
newElement->setShowLabel( true );

newElement->loadConfiguration( element, layerId, context, fields, widgetConfigs );
newElement->loadConfiguration( element, layerId, context, fields );
}

return newElement;
@@ -287,7 +286,7 @@ void QgsAttributeEditorRelation::saveConfiguration( QDomElement &elem, QDomDocum
elem.appendChild( elemConfig );
}

void QgsAttributeEditorRelation::loadConfiguration( const QDomElement &element, const QString &layerId, const QgsReadWriteContext &context, const QgsFields &fields, const QMap<QString, QVariantMap> widgetConfigs )
void QgsAttributeEditorRelation::loadConfiguration( const QDomElement &element, const QString &layerId, const QgsReadWriteContext &context, const QgsFields &fields )
{
Q_UNUSED( layerId )
Q_UNUSED( context )
@@ -320,25 +319,13 @@ void QgsAttributeEditorRelation::loadConfiguration( const QDomElement &element,

setRelationEditorConfiguration( config );

if ( element.hasAttribute( QStringLiteral( "forceSuppressFormPopup" ) ) )
{
setForceSuppressFormPopup( element.attribute( QStringLiteral( "forceSuppressFormPopup" ) ).toInt() );
}
else
{
// pre QGIS 3.16 compatibility - the widgets section is read before
setForceSuppressFormPopup( widgetConfigs.value( element.attribute( QStringLiteral( "relation" ) ) ).value( QStringLiteral( "force-suppress-popup" ), false ).toBool() );
}
setForceSuppressFormPopup( element.attribute( QStringLiteral( "forceSuppressFormPopup" ), 0 ).toInt() );

if ( element.hasAttribute( QStringLiteral( "nmRelationId" ) ) )
{
setNmRelationId( element.attribute( QStringLiteral( "nmRelationId" ) ) );
}
else
{
// pre QGIS 3.16 compatibility - the widgets section is read before
setNmRelationId( widgetConfigs.value( element.attribute( QStringLiteral( "relation" ) ) ).value( QStringLiteral( "nm-rel" ) ) );
}

if ( element.hasAttribute( "label" ) )
{
QString label = element.attribute( QStringLiteral( "label" ) );
@@ -430,12 +417,11 @@ void QgsAttributeEditorQmlElement::saveConfiguration( QDomElement &elem, QDomDoc
elem.appendChild( codeElem );
}

void QgsAttributeEditorQmlElement::loadConfiguration( const QDomElement &element, const QString &layerId, const QgsReadWriteContext &context, const QgsFields &fields, const QMap<QString, QVariantMap> widgetConfigs )
void QgsAttributeEditorQmlElement::loadConfiguration( const QDomElement &element, const QString &layerId, const QgsReadWriteContext &context, const QgsFields &fields )
{
Q_UNUSED( layerId )
Q_UNUSED( context )
Q_UNUSED( fields )
Q_UNUSED( widgetConfigs )
setQmlCode( element.text() );
}

@@ -468,12 +454,11 @@ void QgsAttributeEditorHtmlElement::saveConfiguration( QDomElement &elem, QDomDo
elem.appendChild( codeElem );
}

void QgsAttributeEditorHtmlElement::loadConfiguration( const QDomElement &element, const QString &layerId, const QgsReadWriteContext &context, const QgsFields &fields, const QMap<QString, QVariantMap> widgetConfigs )
void QgsAttributeEditorHtmlElement::loadConfiguration( const QDomElement &element, const QString &layerId, const QgsReadWriteContext &context, const QgsFields &fields )
{
Q_UNUSED( layerId )
Q_UNUSED( context )
Q_UNUSED( fields )
Q_UNUSED( widgetConfigs )
setHtmlCode( element.text() );
}

@@ -90,7 +90,7 @@ class CORE_EXPORT QgsAttributeEditorElement SIP_ABSTRACT
*
* \since QGIS 3.18
*/
static QgsAttributeEditorElement *create( const QDomElement &element, const QString &layerId, const QgsFields &fields, const QMap<QString, QVariantMap > widgetConfigs, const QgsReadWriteContext &context, QgsAttributeEditorElement *parent = nullptr ) SIP_FACTORY;
static QgsAttributeEditorElement *create( const QDomElement &element, const QString &layerId, const QgsFields &fields, const QgsReadWriteContext &context, QgsAttributeEditorElement *parent = nullptr ) SIP_FACTORY;

/**
* Returns the name of this element
@@ -163,7 +163,7 @@ class CORE_EXPORT QgsAttributeEditorElement SIP_ABSTRACT
* Should be implemented by subclasses to read specific configuration
* \since QGIS 3.18
*/
virtual void loadConfiguration( const QDomElement &element, const QString &layerId, const QgsReadWriteContext &context, const QgsFields &fields, const QMap<QString, QVariantMap> widgetConfigs ) = 0;
virtual void loadConfiguration( const QDomElement &element, const QString &layerId, const QgsReadWriteContext &context, const QgsFields &fields ) = 0;

/**
* All subclasses need to overwrite this method and return a type specific identifier.
@@ -298,7 +298,7 @@ class CORE_EXPORT QgsAttributeEditorContainer : public QgsAttributeEditorElement

private:
void saveConfiguration( QDomElement &elem, QDomDocument &doc ) const override;
void loadConfiguration( const QDomElement &element, const QString &layerId, const QgsReadWriteContext &context, const QgsFields &fields, const QMap<QString, QVariantMap> widgetConfigs ) override;
void loadConfiguration( const QDomElement &element, const QString &layerId, const QgsReadWriteContext &context, const QgsFields &fields ) override;
QString typeIdentifier() const override;

bool mIsGroupBox;
@@ -337,7 +337,7 @@ class CORE_EXPORT QgsAttributeEditorField : public QgsAttributeEditorElement

private:
void saveConfiguration( QDomElement &elem, QDomDocument &doc ) const override;
void loadConfiguration( const QDomElement &element, const QString &layerId, const QgsReadWriteContext &context, const QgsFields &fields, const QMap<QString, QVariantMap> widgetConfigs ) override;
void loadConfiguration( const QDomElement &element, const QString &layerId, const QgsReadWriteContext &context, const QgsFields &fields ) override;
QString typeIdentifier() const override;
int mIdx;
};
@@ -496,7 +496,7 @@ class CORE_EXPORT QgsAttributeEditorRelation : public QgsAttributeEditorElement

private:
void saveConfiguration( QDomElement &elem, QDomDocument &doc ) const override;
void loadConfiguration( const QDomElement &element, const QString &layerId, const QgsReadWriteContext &context, const QgsFields &fields, const QMap<QString, QVariantMap> widgetConfigs ) override;
void loadConfiguration( const QDomElement &element, const QString &layerId, const QgsReadWriteContext &context, const QgsFields &fields ) override;
QString typeIdentifier() const override;
QString mRelationId;
QgsRelation mRelation;
@@ -547,7 +547,7 @@ class CORE_EXPORT QgsAttributeEditorQmlElement : public QgsAttributeEditorElemen

private:
void saveConfiguration( QDomElement &elem, QDomDocument &doc ) const override;
void loadConfiguration( const QDomElement &element, const QString &layerId, const QgsReadWriteContext &context, const QgsFields &fields, const QMap<QString, QVariantMap> widgetConfigs ) override;
void loadConfiguration( const QDomElement &element, const QString &layerId, const QgsReadWriteContext &context, const QgsFields &fields ) override;
QString typeIdentifier() const override;
QString mQmlCode;
};
@@ -589,7 +589,7 @@ class CORE_EXPORT QgsAttributeEditorHtmlElement : public QgsAttributeEditorEleme

private:
void saveConfiguration( QDomElement &elem, QDomDocument &doc ) const override;
void loadConfiguration( const QDomElement &element, const QString &layerId, const QgsReadWriteContext &context, const QgsFields &fields, const QMap<QString, QVariantMap> widgetConfigs ) override;
void loadConfiguration( const QDomElement &element, const QString &layerId, const QgsReadWriteContext &context, const QgsFields &fields ) override;
QString typeIdentifier() const override;
QString mHtmlCode;
};
@@ -477,8 +477,10 @@ void QgsEditFormConfig::readXml( const QDomNode &node, QgsReadWriteContext &cont
{
QDomElement elem = attributeEditorFormNodeList.at( i ).toElement();

fixLegacyConfig( elem );

const QString layerId = node.namedItem( QStringLiteral( "id" ) ).toElement().text();
QgsAttributeEditorElement *attributeEditorWidget = QgsAttributeEditorElement::create( elem, layerId, d->mFields, d->mWidgetConfigs, context, nullptr );
QgsAttributeEditorElement *attributeEditorWidget = QgsAttributeEditorElement::create( elem, layerId, d->mFields, context, nullptr );
if ( attributeEditorWidget )
addTab( attributeEditorWidget );
}
@@ -488,6 +490,34 @@ void QgsEditFormConfig::readXml( const QDomNode &node, QgsReadWriteContext &cont
}
}

void QgsEditFormConfig::fixLegacyConfig( QDomElement &el )
{
// recursive method to move widget config into attribute element config

if ( el.tagName() == QLatin1String( "attributeEditorRelation" ) )
{
if ( !el.hasAttribute( QStringLiteral( "forceSuppressFormPopup" ) ) )
{
// pre QGIS 3.16 compatibility - the widgets section is read before
bool forceSuppress = widgetConfig( el.attribute( QStringLiteral( "relation" ) ) ).value( QStringLiteral( "force-suppress-popup" ), false ).toBool();
el.setAttribute( QStringLiteral( "forceSuppressFormPopup" ), forceSuppress ? 1 : 0 );
}
if ( !el.hasAttribute( QStringLiteral( "nmRelationId" ) ) )
{
// pre QGIS 3.16 compatibility - the widgets section is read before
el.setAttribute( QStringLiteral( "nmRelationId" ), widgetConfig( el.attribute( QStringLiteral( "relation" ) ) ).value( QStringLiteral( "nm-rel" ) ).toString() );
}
}

const QDomNodeList children = el.childNodes();
for ( int i = 0; i < children.size(); i++ )
{
QDomElement child = children.at( i ).toElement();
fixLegacyConfig( child );
el.replaceChild( child, children.at( i ) );
}
}

void QgsEditFormConfig::writeXml( QDomNode &node, const QgsReadWriteContext &context ) const
{
QDomDocument doc( node.ownerDocument() );
@@ -606,5 +636,5 @@ void QgsEditFormConfig::writeXml( QDomNode &node, const QgsReadWriteContext &con

QgsAttributeEditorElement *QgsEditFormConfig::attributeEditorElementFromDomElement( QDomElement &elem, QgsAttributeEditorElement *parent, const QString &layerId, const QgsReadWriteContext &context )
{
return QgsAttributeEditorElement::create( elem, layerId, d->mFields, d->mWidgetConfigs, context, parent );
return QgsAttributeEditorElement::create( elem, layerId, d->mFields, context, parent );
}
@@ -356,6 +356,8 @@ class CORE_EXPORT QgsEditFormConfig
bool legacyUpdateRelationWidgetInTabs( QgsAttributeEditorContainer *container, const QString &widgetName, const QVariantMap &config );

private:
void fixLegacyConfig( QDomElement &el );

QExplicitlySharedDataPointer<QgsEditFormConfigPrivate> d;

friend class QgsVectorLayer;

0 comments on commit 9e5b614

Please sign in to comment.
You can’t perform that action at this time.