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 ) ...@@ -231,7 +231,7 @@ void ProjectManager::__saveProject( const QString &fileName )
Library::getInstance()->saveProject( project ); Library::getInstance()->saveProject( project );
MainWorkflow::getInstance()->saveProject( project ); MainWorkflow::getInstance()->saveProject( project );
// SettingsManager::getInstance()->save( doc, rootNode ); SettingsManager::getInstance()->save( project );
project.writeEndElement(); project.writeEndElement();
project.writeEndDocument(); project.writeEndDocument();
......
...@@ -25,13 +25,13 @@ ...@@ -25,13 +25,13 @@
#include "SettingValue.h" #include "SettingValue.h"
#include <QSettings> #include <QSettings>
#include <QDomDocument>
#include <QWriteLocker> #include <QWriteLocker>
#include <QReadLocker> #include <QReadLocker>
#include <QXmlStreamWriter> #include <QXmlStreamWriter>
#include <QStringList> #include <QStringList>
#include <QtDebug> #include <QtDebug>
#include <QDomElement>
void void
SettingsManager::setValue( const QString &key, SettingsManager::setValue( const QString &key,
...@@ -175,40 +175,21 @@ SettingsManager::save() const ...@@ -175,40 +175,21 @@ SettingsManager::save() const
} }
void void
SettingsManager::save( QDomDocument &xmlfile, QDomElement &root ) const SettingsManager::save( QXmlStreamWriter& project ) const
{ {
typedef QPair<QString, SettingValue*> settingPair; SettingHash::const_iterator it = m_xmlSettings.begin();
QMultiHash<QString, settingPair> parts; SettingHash::const_iterator end = m_xmlSettings.end();
QReadLocker rl( &m_rwLock ); project.writeStartElement( "project" );
SettingHash::const_iterator it; while ( it != end )
SettingHash::const_iterator ed = m_xmlSettings.end();
for ( it = m_xmlSettings.begin(); it != ed; ++it )
{ {
QString key = it.key(); project.writeStartElement( "property" );
if ( key.count( "/" ) == 1 ) project.writeAttribute( "key", it.key() );
{ project.writeAttribute( "value", it.value()->get().toString() );
int idx = key.indexOf( "/" ); ++it;
QString part = key.left( idx ); project.writeEndElement();
QString name = key.right( key.size() - idx - 1 );
parts.insert( part, settingPair( name, it.value() ) );
}
}
QList<QString> keys = parts.uniqueKeys();
foreach( QString xmlKey, keys )
{
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.writeEndElement();
} }
bool bool
......
...@@ -35,7 +35,6 @@ ...@@ -35,7 +35,6 @@
class SettingValue; class SettingValue;
class QXmlStreamWriter; class QXmlStreamWriter;
class QDomElement; class QDomElement;
class QDomDocument;
//Var helpers : //Var helpers :
...@@ -115,7 +114,7 @@ class SettingsManager : public QObject, public Singleton<SettingsManager> ...@@ -115,7 +114,7 @@ class SettingsManager : public QObject, public Singleton<SettingsManager>
SettingsManager::Type type, SettingsManager::Type type,
Qt::ConnectionType cType = Qt::AutoConnection ); Qt::ConnectionType cType = Qt::AutoConnection );
void save() const; void save() const;
void save( QDomDocument &xmlfile, QDomElement& root ) const; void save( QXmlStreamWriter& project ) const;
bool load( const QDomElement &element ); bool load( const QDomElement &element );
bool commit( SettingsManager::Type type ); 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