Commit d42dd5ec authored by Clement CHAVANCE's avatar Clement CHAVANCE Committed by Clement CHAVANCE

Settings are now saved in the project file

parent c48e9f18
......@@ -22,6 +22,10 @@
#include <QHash>
#include <QDomElement>
#include <QDomNamedNodeMap>
#include <QDomNodeList>
#include <QtDebug>
#include <QTextStream>
#include "SettingsManager.h"
......@@ -39,20 +43,27 @@ void SettingsManager::setValues( QHash<QString, QVariant> values )
QHash<QString, QVariant>::iterator it = values.begin();
QHash<QString, QVariant>::iterator end = values.end();
m_lock.lockForWrite();
for ( ; it != end; ++it )
m_data.insert( it.key(), it.value() );
m_lock.unlock();
return ;
}
void SettingsManager::setValue( const QString& key, QVariant& value )
{
m_lock.lockForWrite();
m_data.insert( key, value );
m_lock.unlock();
return ;
}
const QVariant SettingsManager::getValue( const QString& key ) const
{
return m_data[key];
m_lock.lockForRead();
QVariant value = m_data[key];
m_lock.unlock();
return value;
}
void SettingsManager::saveSettings( QDomDocument& xmlfile, QDomElement& root )
......@@ -64,8 +75,48 @@ void SettingsManager::saveSettings( QDomDocument& xmlfile, QDomElement& root )
QHash<QString, QVariant>::iterator end = m_data.end();
QDomElement settingsNode = xmlfile.createElement( "settings" );
for ( ; it != end; ++it )
{
//DEBUG
{
qDebug() << it.key() << "val" << it.value().toString();
}
settingsNode.setAttribute( it.key(), it.value().toString() );
}
m_lock.unlock();
//DEBUG
{
QTextStream stream( stdout );
stream << settingsNode;
}
root.appendChild( settingsNode );
}
void SettingsManager::loadSettings( const QDomElement& settings )
{
if ( settings.isNull() == true || settings.tagName() != "settings" )
{
qWarning() << "Invalid settings node";
return ;
}
//Loading all the settings
m_lock.lockForWrite();
QDomNodeList list = settings.childNodes();
int nbChild = list.size();
for ( int idx = 0; idx < nbChild; ++idx )
{
QDomNamedNodeMap attrMap = list.at( idx ).attributes();
if ( attrMap.count() > 1 )
{
qWarning() << "Invalid number of attributes for" << list.at( idx ).nodeName();
return ;
}
m_data.insert( attrMap.item( 0 ).nodeName(),
QVariant( attrMap.item( 0 ).nodeValue() ));
}
m_lock.unlock();
//TODO : notify the widget that values have been loaded
}
......@@ -44,15 +44,14 @@ class SettingsManager : public QObject, public QSingleton<SettingsManager>
void setValues( QHash<QString, QVariant> );
void setValue( const QString& key, QVariant& value );
const QVariant getValue( const QString& key ) const;
void saveSettings( QDomDocument& xmlfile, QDomElement& root );
void loadSettings( const QDomElement& settings );
private:
SettingsManager( QObject* parent = 0 );
~SettingsManager();
QHash<QString, QVariant> m_data;
QReadWriteLock m_lock;
public slots:
void saveSettings( QDomDocument& xmlfile, QDomElement& root );
mutable QReadWriteLock m_lock;
};
......
......@@ -152,6 +152,7 @@ void Settings::buttonClicked( QAbstractButton* button )
foreach( widg, m_pWidgets )
widg->save( sett );
qDebug() << sett;
SettingsManager::getInstance()->setValues( sett );
}
if ( hide == true )
{
......
......@@ -23,6 +23,7 @@
#include "ProjectManager.h"
#include "Library.h"
#include "MainWorkflow.h"
#include "SettingsManager.h"
ProjectManager::ProjectManager( const QString& filePath )
{
......@@ -51,6 +52,7 @@ void ProjectManager::loadProject()
connect( Library::getInstance(), SIGNAL( projectLoaded() ), this, SLOT( loadTimeline() ) );
Library::getInstance()->loadProject( root.firstChildElement( "medias" ) );
SettingsManager::getInstance()->loadSettings( root.firstChildElement( "settings" ) );
}
void ProjectManager::saveProject()
......@@ -66,6 +68,7 @@ void ProjectManager::saveProject()
Library::getInstance()->saveProject( doc, rootNode );
MainWorkflow::getInstance()->saveProject( doc, rootNode );
SettingsManager::getInstance()->saveSettings( doc, rootNode );
doc.appendChild( rootNode );
......
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