Commit d40941d6 authored by Hugo Beauzée-Luyssen's avatar Hugo Beauzée-Luyssen

Settings: Allow a setting widget to refuse to save its value.

parent faa70346
......@@ -33,10 +33,11 @@ BoolWidget::BoolWidget( SettingValue *s, QWidget *parent /*= NULL*/ ) :
changed( s->get() );
}
void
bool
BoolWidget::save()
{
m_setting->set( m_checkbox->isChecked() );
return true;
}
void
......
......@@ -36,7 +36,7 @@ class BoolWidget : public ISettingsCategoryWidget
public:
BoolWidget( SettingValue *s, QWidget *parent = NULL );
void save();
bool save();
private slots:
virtual void changed( const QVariant& );
......
......@@ -38,10 +38,11 @@ ColorWidget::ColorWidget( SettingValue *s, QWidget *parent ) :
changed( m_color );
}
void
bool
ColorWidget::save()
{
m_setting->set( m_color );
return true;
}
void
......
......@@ -36,7 +36,7 @@ class ColorWidget : public ISettingsCategoryWidget
public:
ColorWidget( SettingValue *s, QWidget *parent = NULL );
void save();
bool save();
private slots:
virtual void changed( const QVariant& );
......
......@@ -49,10 +49,11 @@ DoubleSliderWidget::DoubleSliderWidget( SettingValue *s, QWidget *parent /*= NUL
connect( m_slider, SIGNAL( valueChanged( int ) ), this, SLOT( sliderMoved( int ) ) );
}
void
bool
DoubleSliderWidget::save()
{
m_setting->set( m_slider->value() / 100.0 );
return true;
}
void
......
......@@ -36,7 +36,7 @@ class DoubleSliderWidget : public ISettingsCategoryWidget
public:
DoubleSliderWidget( SettingValue *s, QWidget *parent = NULL );
void save();
bool save();
private:
QSlider *m_slider;
......
......@@ -41,10 +41,11 @@ DoubleWidget::DoubleWidget( SettingValue *s, QWidget *parent /*= NULL*/ ) :
}
}
void
bool
DoubleWidget::save()
{
m_setting->set( m_spinbox->value() );
return true;
}
void
......
......@@ -36,7 +36,7 @@ class DoubleWidget : public ISettingsCategoryWidget
public:
DoubleWidget( SettingValue *s, QWidget *parent = NULL );
void save();
bool save();
private slots:
virtual void changed( const QVariant& );
......
......@@ -38,7 +38,7 @@ class ISettingsCategoryWidget : public QWidget
public:
virtual ~ISettingsCategoryWidget(){}
virtual SettingValue *setting() { return m_setting; }
virtual void save() = 0;
virtual bool save() = 0;
protected:
ISettingsCategoryWidget( QWidget *parent, SettingValue* s ) :
......
......@@ -44,10 +44,11 @@ IntWidget::IntWidget( SettingValue *s, QWidget *parent /*= NULL*/ ) :
changed( s->get() );
}
void
bool
IntWidget::save()
{
m_setting->set( m_spinbox->value() );
return true;
}
void
......
......@@ -36,7 +36,7 @@ class IntWidget : public ISettingsCategoryWidget
public:
IntWidget( SettingValue *s, QWidget *parent = NULL );
void save();
bool save();
private slots:
virtual void changed( const QVariant& );
......
......@@ -31,8 +31,9 @@ KeyboardShortcut::KeyboardShortcut( SettingValue *s, QWidget *parent /*= NULL*/
layout()->addWidget( m_input );
}
void
bool
KeyboardShortcut::save()
{
m_setting->set( m_input->shortcut() );
return true;
}
......@@ -35,7 +35,7 @@ class KeyboardShortcut : public ISettingsCategoryWidget
public:
KeyboardShortcut( SettingValue *s, QWidget *parent = NULL );
void save();
bool save();
private slots:
///The KeyboardShortcutInput does this itself.
......
......@@ -78,11 +78,12 @@ LanguageWidget::LanguageWidget( SettingValue *s, QWidget *parent /*= NULL*/ ) :
changed( s->get() );
}
void
bool
LanguageWidget::save()
{
QString lang = m_list->itemData( m_list->currentIndex() ).toString();
m_setting->set( lang );
return true;
}
void
......
......@@ -36,7 +36,7 @@ class LanguageWidget : public ISettingsCategoryWidget
public:
LanguageWidget( SettingValue *s, QWidget *parent = NULL );
void save();
bool save();
private slots:
virtual void changed( const QVariant& );
......
......@@ -54,10 +54,11 @@ PathWidget::changeEvent( QEvent *event )
retranslate();
}
void
bool
PathWidget::save()
{
m_setting->set( m_lineEdit->text() );
return true;
}
void
......
......@@ -37,7 +37,7 @@ class PathWidget : public ISettingsCategoryWidget
public:
PathWidget( SettingValue *s, QWidget *parent = NULL );
void save();
bool save();
protected:
void changeEvent( QEvent *event );
......
......@@ -97,11 +97,15 @@ PreferenceWidget::widgetFactory( SettingValue *s )
}
}
void
bool
PreferenceWidget::save()
{
foreach ( ISettingsCategoryWidget* w, m_settings )
w->save();
{
if ( w->save() == false )
return false;
}
return true;
}
void
......
......@@ -44,7 +44,7 @@ class PreferenceWidget : public QScrollArea
QWidget* parent = 0 );
virtual ~PreferenceWidget() {}
virtual void save();
virtual bool save();
virtual void reset();
const char *category() const;
protected:
......
......@@ -121,7 +121,14 @@ Settings::buttonClicked( QAbstractButton *button )
case QDialogButtonBox::Apply:
{
for ( int i = 0; i < m_stackedLayout->count(); ++i )
qobject_cast<PreferenceWidget*>( m_stackedLayout->widget( i ) )->save();
{
if ( qobject_cast<PreferenceWidget*>( m_stackedLayout->widget( i ) )->save() == false )
{
QMessageBox::warning( NULL, tr( "Invalid value" ),
tr( "Can't save settings due to an invalid value" ) );
return ;
}
}
//If we're handling vlmc preferences, save the value in the QSettings
if ( m_type == SettingsManager::Vlmc )
SettingsManager::getInstance()->save();
......
......@@ -35,10 +35,11 @@ StringWidget::StringWidget( SettingValue *s, QWidget *parent /*= NULL*/ ) :
changed( s->get() );
}
void
bool
StringWidget::save()
{
m_setting->set( m_lineEdit->text() );
return true;
}
void
StringWidget::changed( const QVariant &val )
......
......@@ -36,7 +36,7 @@ class StringWidget : public ISettingsCategoryWidget
public:
StringWidget( SettingValue *s, QWidget *parent = NULL );
void save();
bool save();
private slots:
virtual void changed( const QVariant& );
......
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