Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix save/reload of N:M relations
  • Loading branch information
m-kuhn committed Sep 15, 2017
1 parent f63c302 commit c2162b0
Showing 1 changed file with 19 additions and 25 deletions.
44 changes: 19 additions & 25 deletions src/core/qgseditformconfig.cpp
Expand Up @@ -19,6 +19,7 @@
#include "qgsreadwritecontext.h"
#include "qgsrelationmanager.h"
#include "qgslogger.h"
#include "qgsxmlutils.h"

//#include "qgseditorwidgetregistry.h"

Expand Down Expand Up @@ -337,6 +338,16 @@ void QgsEditFormConfig::readXml( const QDomNode &node, const QgsReadWriteContext
}
}

QDomNodeList widgetsNodeList = node.namedItem( QStringLiteral( "widgets" ) ).toElement().childNodes();

for ( int i = 0; i < widgetsNodeList.size(); ++i )
{
QDomElement widgetElement = widgetsNodeList.at( i ).toElement();
QVariant config = QgsXmlUtils::readVariant( widgetElement.firstChildElement( "config" ) );

d->mWidgetConfigs[widgetElement.attribute( QStringLiteral( "name" ) )] = config.toMap();
}

// tabs and groups display info
QDomNode attributeEditorFormNode = node.namedItem( QStringLiteral( "attributeEditorForm" ) );
if ( !attributeEditorFormNode.isNull() )
Expand Down Expand Up @@ -428,37 +439,20 @@ void QgsEditFormConfig::writeXml( QDomNode &node, const QgsReadWriteContext &con
node.appendChild( tabsElem );
}

//// TODO: MAKE THIS MORE GENERIC, SO INDIVIDUALL WIDGETS CAN NOT ONLY SAVE STRINGS
/// SEE QgsEditorWidgetFactory::writeConfig

QDomElement widgetsElem = doc.createElement( QStringLiteral( "widgets" ) );

QMap<QString, QVariantMap >::ConstIterator configIt( d->mWidgetConfigs.constBegin() );

while ( configIt != d->mWidgetConfigs.constEnd() )
{
if ( d->mFields.indexFromName( configIt.key() ) == -1 )
{
QDomElement widgetElem = doc.createElement( QStringLiteral( "widget" ) );
widgetElem.setAttribute( QStringLiteral( "name" ), configIt.key() );
// widgetElem.setAttribute( "notNull", );

QDomElement configElem = doc.createElement( QStringLiteral( "config" ) );
widgetElem.appendChild( configElem );

QVariantMap::ConstIterator cfgIt( configIt.value().constBegin() );

while ( cfgIt != configIt.value().constEnd() )
{
QDomElement optionElem = doc.createElement( QStringLiteral( "option" ) );
optionElem.setAttribute( QStringLiteral( "key" ), cfgIt.key() );
optionElem.setAttribute( QStringLiteral( "value" ), cfgIt.value().toString() );
configElem.appendChild( optionElem );
++cfgIt;
}

widgetsElem.appendChild( widgetElem );
}
QDomElement widgetElem = doc.createElement( QStringLiteral( "widget" ) );
widgetElem.setAttribute( QStringLiteral( "name" ), configIt.key() );
// widgetElem.setAttribute( "notNull", );

QDomElement configElem = QgsXmlUtils::writeVariant( configIt.value(), doc );
configElem.setTagName( QStringLiteral( "config" ) );
widgetElem.appendChild( configElem );
widgetsElem.appendChild( widgetElem );
++configIt;
}

Expand Down

0 comments on commit c2162b0

Please sign in to comment.