Commit a20a7eaf authored by Hugo Beauzee-Luyssen's avatar Hugo Beauzee-Luyssen

SettingsManager: Saving is functionnal again.

parent c9796ab4
......@@ -231,7 +231,7 @@ void ProjectManager::__saveProject( const QString &fileName )
Library::getInstance()->saveProject( project );
MainWorkflow::getInstance()->saveProject( project );
// SettingsManager::getInstance()->save( doc, rootNode );
SettingsManager::getInstance()->save( project );
project.writeEndElement();
project.writeEndDocument();
......
......@@ -25,13 +25,13 @@
#include "SettingValue.h"
#include <QSettings>
#include <QDomDocument>
#include <QWriteLocker>
#include <QReadLocker>
#include <QXmlStreamWriter>
#include <QStringList>
#include <QtDebug>
#include <QDomElement>
void
SettingsManager::setValue( const QString &key,
......@@ -175,40 +175,21 @@ SettingsManager::save() const
}
void
SettingsManager::save( QDomDocument &xmlfile, QDomElement &root ) const
SettingsManager::save( QXmlStreamWriter& project ) const
{
typedef QPair<QString, SettingValue*> settingPair;
QMultiHash<QString, settingPair> parts;
QReadLocker rl( &m_rwLock );
SettingHash::const_iterator it;
SettingHash::const_iterator ed = m_xmlSettings.end();
for ( it = m_xmlSettings.begin(); it != ed; ++it )
{
QString key = it.key();
if ( key.count( "/" ) == 1 )
{
int idx = key.indexOf( "/" );
QString part = key.left( idx );
QString name = key.right( key.size() - idx - 1 );
SettingHash::const_iterator it = m_xmlSettings.begin();
SettingHash::const_iterator end = m_xmlSettings.end();
parts.insert( part, settingPair( name, it.value() ) );
}
}
QList<QString> keys = parts.uniqueKeys();
foreach( QString xmlKey, keys )
project.writeStartElement( "project" );
while ( it != end )
{
QDomElement node = xmlfile.createElement( xmlKey );
QList<settingPair> pairs = parts.values( xmlKey );
foreach( settingPair pair, pairs )
{
QDomElement item = xmlfile.createElement( pair.first );
item.setAttribute( "value", pair.second->get().toString() );
node.appendChild( item );
}
root.appendChild( node );
project.writeStartElement( "property" );
project.writeAttribute( "key", it.key() );
project.writeAttribute( "value", it.value()->get().toString() );
++it;
project.writeEndElement();
}
project.writeEndElement();
}
bool
......
......@@ -35,7 +35,6 @@
class SettingValue;
class QXmlStreamWriter;
class QDomElement;
class QDomDocument;
//Var helpers :
......@@ -115,7 +114,7 @@ class SettingsManager : public QObject, public Singleton<SettingsManager>
SettingsManager::Type type,
Qt::ConnectionType cType = Qt::AutoConnection );
void save() const;
void save( QDomDocument &xmlfile, QDomElement& root ) const;
void save( QXmlStreamWriter& project ) const;
bool load( const QDomElement &element );
bool commit( SettingsManager::Type type );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment