Skip to content

Commit c2162b0

Browse files
committedSep 15, 2017
Fix save/reload of N:M relations
1 parent f63c302 commit c2162b0

File tree

1 file changed

+19
-25
lines changed

1 file changed

+19
-25
lines changed
 

‎src/core/qgseditformconfig.cpp

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "qgsreadwritecontext.h"
2020
#include "qgsrelationmanager.h"
2121
#include "qgslogger.h"
22+
#include "qgsxmlutils.h"
2223

2324
//#include "qgseditorwidgetregistry.h"
2425

@@ -337,6 +338,16 @@ void QgsEditFormConfig::readXml( const QDomNode &node, const QgsReadWriteContext
337338
}
338339
}
339340

341+
QDomNodeList widgetsNodeList = node.namedItem( QStringLiteral( "widgets" ) ).toElement().childNodes();
342+
343+
for ( int i = 0; i < widgetsNodeList.size(); ++i )
344+
{
345+
QDomElement widgetElement = widgetsNodeList.at( i ).toElement();
346+
QVariant config = QgsXmlUtils::readVariant( widgetElement.firstChildElement( "config" ) );
347+
348+
d->mWidgetConfigs[widgetElement.attribute( QStringLiteral( "name" ) )] = config.toMap();
349+
}
350+
340351
// tabs and groups display info
341352
QDomNode attributeEditorFormNode = node.namedItem( QStringLiteral( "attributeEditorForm" ) );
342353
if ( !attributeEditorFormNode.isNull() )
@@ -428,37 +439,20 @@ void QgsEditFormConfig::writeXml( QDomNode &node, const QgsReadWriteContext &con
428439
node.appendChild( tabsElem );
429440
}
430441

431-
//// TODO: MAKE THIS MORE GENERIC, SO INDIVIDUALL WIDGETS CAN NOT ONLY SAVE STRINGS
432-
/// SEE QgsEditorWidgetFactory::writeConfig
433-
434442
QDomElement widgetsElem = doc.createElement( QStringLiteral( "widgets" ) );
435443

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

438446
while ( configIt != d->mWidgetConfigs.constEnd() )
439447
{
440-
if ( d->mFields.indexFromName( configIt.key() ) == -1 )
441-
{
442-
QDomElement widgetElem = doc.createElement( QStringLiteral( "widget" ) );
443-
widgetElem.setAttribute( QStringLiteral( "name" ), configIt.key() );
444-
// widgetElem.setAttribute( "notNull", );
445-
446-
QDomElement configElem = doc.createElement( QStringLiteral( "config" ) );
447-
widgetElem.appendChild( configElem );
448-
449-
QVariantMap::ConstIterator cfgIt( configIt.value().constBegin() );
450-
451-
while ( cfgIt != configIt.value().constEnd() )
452-
{
453-
QDomElement optionElem = doc.createElement( QStringLiteral( "option" ) );
454-
optionElem.setAttribute( QStringLiteral( "key" ), cfgIt.key() );
455-
optionElem.setAttribute( QStringLiteral( "value" ), cfgIt.value().toString() );
456-
configElem.appendChild( optionElem );
457-
++cfgIt;
458-
}
459-
460-
widgetsElem.appendChild( widgetElem );
461-
}
448+
QDomElement widgetElem = doc.createElement( QStringLiteral( "widget" ) );
449+
widgetElem.setAttribute( QStringLiteral( "name" ), configIt.key() );
450+
// widgetElem.setAttribute( "notNull", );
451+
452+
QDomElement configElem = QgsXmlUtils::writeVariant( configIt.value(), doc );
453+
configElem.setTagName( QStringLiteral( "config" ) );
454+
widgetElem.appendChild( configElem );
455+
widgetsElem.appendChild( widgetElem );
462456
++configIt;
463457
}
464458

0 commit comments

Comments
 (0)
Please sign in to comment.