Commit c53d3b17 authored by Clement CHAVANCE's avatar Clement CHAVANCE Committed by Vincent Carrubba
Browse files

removed the method that assigned an int to a settings object.

For now, there will be only one map for the settings
parent 89d7c059
...@@ -21,17 +21,18 @@ ...@@ -21,17 +21,18 @@
*****************************************************************************/ *****************************************************************************/
#include <QHash> #include <QHash>
#include <QDomElement>
#include "SettingsManager.h" #include "SettingsManager.h"
int SettingsManager::createNewSettings() int SettingsManager::createNewSettings()
{ {
this->m_settings.append(new SettingsContainer()); this->m_settings.append(new SettingsContainer());
return this->m_settings.size() - 1; return this->m_settings.size() - 1;
} }
SettingsManager::SettingsManager( QObject* parent ) SettingsManager::SettingsManager( QObject* parent )
: QObject( parent ) : QObject( parent )
{ {
} }
...@@ -39,12 +40,6 @@ SettingsManager::~SettingsManager() ...@@ -39,12 +40,6 @@ SettingsManager::~SettingsManager()
{ {
} }
void SettingsManager::saveSettings( QDomDocument& xmlfile, int index ) void SettingsManager::saveSettings( QDomDocument& xmlfile, QDomElement& root )
{ {
Q_UNUSED( xmlfile )
SettingsContainer* settings = m_settings[index];
settings->lock.lockForRead();
//SAVE SETTINGS TO DomDocument
settings->lock.unlock();
} }
...@@ -33,31 +33,26 @@ ...@@ -33,31 +33,26 @@
#include "QSingleton.hpp" #include "QSingleton.hpp"
struct SettingsContainer
{
QReadWriteLock lock;
QHash<QString, QVariant> settings;
};
class SettingsManager : public QObject, public QSingleton<SettingsManager> class SettingsManager : public QObject, public QSingleton<SettingsManager>
{ {
//Q_OBJECT Q_OBJECT
//
friend class QSingleton<SettingsManager>; friend class QSingleton<SettingsManager>;
public: public:
int createNewSettings();
void setValues( QHash<QString, QVariant>, int index ); void setValues( QHash<QString, QVariant> );
void setValue( const QString& key, QVariant& value, int index ); void setValue( const QString& key, QVariant& value );
QVariant& getValue( const QString& key ); QVariant& getValue( const QString& key );
private: private:
SettingsManager( QObject* parent = 0 ); SettingsManager( QObject* parent = 0 );
~SettingsManager(); ~SettingsManager();
QVector<SettingsContainer*> m_settings; QHash<QString, QVariant> m_data;
QReadWriteLock m_lock;
public slots: public slots:
void saveSettings( QDomDocument& xmlfile, int index ); void saveSettings( QDomDocument& xmlfile, QDomElement& root );
}; };
......
...@@ -38,19 +38,18 @@ ...@@ -38,19 +38,18 @@
Settings::Settings( QWidget* parent, Qt::WindowFlags f ) Settings::Settings( QWidget* parent, Qt::WindowFlags f )
: QDialog( parent, f ), : QDialog( parent, f ),
m_currentWidget( NULL ) m_currentWidget( NULL )
{ {
m_panel = new Panel( this ); m_panel = new Panel( this );
m_stackedWidgets = new QStackedWidget( this ); m_stackedWidgets = new QStackedWidget( this );
connect( m_panel, connect( m_panel,
SIGNAL( changePanel( int ) ), SIGNAL( changePanel( int ) ),
SLOT( switchWidget( int ) ) ); SLOT( switchWidget( int ) ) );
QObject::connect( this, QObject::connect( this,
SIGNAL( widgetSwitched( int ) ), SIGNAL( widgetSwitched( int ) ),
m_stackedWidgets, m_stackedWidgets,
SLOT( setCurrentIndex( int ) )); SLOT( setCurrentIndex( int ) ));
m_settingsNumber = SettingsManager::getInstance()->createNewSettings();
} }
Settings::~Settings() Settings::~Settings()
...@@ -61,9 +60,9 @@ Settings::~Settings() ...@@ -61,9 +60,9 @@ Settings::~Settings()
//TODO : see if the widget MUST have a fixed size, or if the window can dynamicaly //TODO : see if the widget MUST have a fixed size, or if the window can dynamicaly
//adjust to the size of the biggest Widget. //adjust to the size of the biggest Widget.
void Settings::addWidget( const QString& name, void Settings::addWidget( const QString& name,
PreferenceWidget* pWidget, PreferenceWidget* pWidget,
const QString& icon, const QString& icon,
const QString& label ) const QString& label )
{ {
m_stackedWidgets->addWidget( pWidget ); m_stackedWidgets->addWidget( pWidget );
...@@ -95,7 +94,7 @@ QVBoxLayout* Settings::buildRightHLayout() ...@@ -95,7 +94,7 @@ QVBoxLayout* Settings::buildRightHLayout()
m_buttons = new QDialogButtonBox( this ); m_buttons = new QDialogButtonBox( this );
QObject::connect( m_buttons, SIGNAL( clicked( QAbstractButton* ) ), QObject::connect( m_buttons, SIGNAL( clicked( QAbstractButton* ) ),
this, SLOT( buttonClicked( QAbstractButton* ) ) ); this, SLOT( buttonClicked( QAbstractButton* ) ) );
m_title = new QLabel( this ); m_title = new QLabel( this );
titleLine->setFrameShape( QFrame::HLine ); titleLine->setFrameShape( QFrame::HLine );
...@@ -108,8 +107,8 @@ QVBoxLayout* Settings::buildRightHLayout() ...@@ -108,8 +107,8 @@ QVBoxLayout* Settings::buildRightHLayout()
m_title->setFont( labelFont ); m_title->setFont( labelFont );
m_buttons->setStandardButtons( QDialogButtonBox::Ok | m_buttons->setStandardButtons( QDialogButtonBox::Ok |
QDialogButtonBox::Cancel | QDialogButtonBox::Cancel |
QDialogButtonBox::Apply ); QDialogButtonBox::Apply );
QString title( m_widgets.value( m_stackedWidgets->indexOf( m_currentWidget ) ) ); QString title( m_widgets.value( m_stackedWidgets->indexOf( m_currentWidget ) ) );
m_title->setText( title ); m_title->setText( title );
...@@ -130,33 +129,33 @@ void Settings::buttonClicked( QAbstractButton* button ) ...@@ -130,33 +129,33 @@ void Settings::buttonClicked( QAbstractButton* button )
bool hide = false ; bool hide = false ;
switch ( m_buttons->standardButton( button ) ) switch ( m_buttons->standardButton( button ) )
{ {
case QDialogButtonBox::Ok : case QDialogButtonBox::Ok :
save = true; save = true;
hide = true; hide = true;
break; break;
case QDialogButtonBox::Cancel : case QDialogButtonBox::Cancel :
hide = true; hide = true;
break; break;
case QDialogButtonBox::Apply : case QDialogButtonBox::Apply :
save = true; save = true;
break; break;
default : default :
break; break;
} }
if ( save == true ) if ( save == true )
{ {
qDebug() << "Saving Preferences"; qDebug() << "Saving Preferences";
//Save Settings //Save Settings
QHash<QString, QVariant> sett; QHash<QString, QVariant> sett;
PreferenceWidget* widg; PreferenceWidget* widg;
foreach( widg, m_pWidgets ) foreach( widg, m_pWidgets )
widg->save( sett ); widg->save( sett );
qDebug() << sett; qDebug() << sett;
} }
if ( hide == true ) if ( hide == true )
{ {
setVisible( false ); setVisible( false );
} }
} }
......
...@@ -46,9 +46,9 @@ class Settings : public QDialog ...@@ -46,9 +46,9 @@ class Settings : public QDialog
Settings( QWidget* parent = 0, Qt::WindowFlags f = 0 ); Settings( QWidget* parent = 0, Qt::WindowFlags f = 0 );
virtual ~Settings(); virtual ~Settings();
void addWidget( const QString& name, void addWidget( const QString& name,
PreferenceWidget* pWidget, PreferenceWidget* pWidget,
const QString& icon, const QString& icon,
const QString& label ); const QString& label );
void build(); void build();
private: private:
...@@ -65,8 +65,6 @@ class Settings : public QDialog ...@@ -65,8 +65,6 @@ class Settings : public QDialog
QDialogButtonBox* m_buttons; QDialogButtonBox* m_buttons;
bool m_saved; bool m_saved;
int m_settingsNumber;
public slots: public slots:
void switchWidget( int widget ); void switchWidget( int widget );
......
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