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