diff --git a/apps/opencs/model/prefs/state.cpp b/apps/opencs/model/prefs/state.cpp index 3921e32f2..7a1889407 100644 --- a/apps/opencs/model/prefs/state.cpp +++ b/apps/opencs/model/prefs/state.cpp @@ -5,6 +5,8 @@ #include #include +#include + #include "intsetting.hpp" #include "doublesetting.hpp" #include "boolsetting.hpp" @@ -587,6 +589,30 @@ CSMPrefs::State& CSMPrefs::State::get() return *sThis; } +void CSMPrefs::State::resetCategory(const std::string& category) +{ + { + QMutexLocker lock (&mMutex); + for (Settings::CategorySettingValueMap::iterator i = mSettings.mUserSettings.begin(); i != mSettings.mUserSettings.end(); ++i) + { + // if the category matches + if (i->first.first == category) + { + // mark the setting as changed + mSettings.mChangedSettings.insert(std::make_pair(i->first.first, i->first.second)); + // reset the value to the default + i->second = mSettings.mDefaultSettings[i->first]; + } + } + } + + Collection::iterator iter = mCategories.find(category); + if (iter != mCategories.end()) + { + (*iter).second.update(); + } +} + CSMPrefs::State& CSMPrefs::get() { diff --git a/apps/opencs/model/prefs/state.hpp b/apps/opencs/model/prefs/state.hpp index 1e46c68ee..1e0ac8c11 100644 --- a/apps/opencs/model/prefs/state.hpp +++ b/apps/opencs/model/prefs/state.hpp @@ -106,6 +106,8 @@ namespace CSMPrefs static State& get(); + void resetCategory(const std::string& category); + signals: void settingChanged (const CSMPrefs::Setting *setting); diff --git a/apps/opencs/view/prefs/keybindingpage.cpp b/apps/opencs/view/prefs/keybindingpage.cpp index 143665f4a..c70461874 100644 --- a/apps/opencs/view/prefs/keybindingpage.cpp +++ b/apps/opencs/view/prefs/keybindingpage.cpp @@ -6,9 +6,11 @@ #include #include #include +#include #include "../../model/prefs/setting.hpp" #include "../../model/prefs/category.hpp" +#include "../../model/prefs/state.hpp" namespace CSVPrefs { @@ -22,6 +24,10 @@ namespace CSVPrefs QWidget* topWidget = new QWidget(); QVBoxLayout* topLayout = new QVBoxLayout(topWidget); + QWidget* resetAll = new QPushButton("Reset all to default", this); + connect(resetAll, SIGNAL(clicked()), this, SLOT(resetCategory())); + topLayout->addWidget(resetAll); + // Allows switching between "pages" QWidget* stackedWidget = new QWidget(); mStackedLayout = new QStackedLayout(stackedWidget); diff --git a/apps/opencs/view/prefs/page.cpp b/apps/opencs/view/prefs/page.cpp index c23e9f64f..7d8644621 100644 --- a/apps/opencs/view/prefs/page.cpp +++ b/apps/opencs/view/prefs/page.cpp @@ -2,9 +2,11 @@ #include "page.hpp" #include +#include #include "../../model/prefs/setting.hpp" #include "../../model/prefs/category.hpp" +#include "../../model/prefs/state.hpp" CSVPrefs::Page::Page (CSMPrefs::Category& category, QWidget *parent) : PageBase (category, parent) @@ -12,6 +14,10 @@ CSVPrefs::Page::Page (CSMPrefs::Category& category, QWidget *parent) QWidget *widget = new QWidget (parent); mGrid = new QGridLayout (widget); + QWidget* resetAll = new QPushButton("Reset all to default", this); + connect (resetAll, SIGNAL (clicked()), this, SLOT (resetCategory())); + mGrid->addWidget(resetAll, 0, 0, 1, 2); + for (CSMPrefs::Category::Iterator iter = category.begin(); iter!=category.end(); ++iter) addSetting (*iter); diff --git a/apps/opencs/view/prefs/pagebase.cpp b/apps/opencs/view/prefs/pagebase.cpp index 16684a69d..344360607 100644 --- a/apps/opencs/view/prefs/pagebase.cpp +++ b/apps/opencs/view/prefs/pagebase.cpp @@ -2,6 +2,7 @@ #include "pagebase.hpp" #include "../../model/prefs/category.hpp" +#include "../../model/prefs/state.hpp" CSVPrefs::PageBase::PageBase (CSMPrefs::Category& category, QWidget *parent) : QScrollArea (parent), mCategory (category) @@ -11,3 +12,8 @@ CSMPrefs::Category& CSVPrefs::PageBase::getCategory() { return mCategory; } + +void CSVPrefs::PageBase::resetCategory() +{ + CSMPrefs::get().resetCategory(getCategory().getKey()); +} diff --git a/apps/opencs/view/prefs/pagebase.hpp b/apps/opencs/view/prefs/pagebase.hpp index affe49f4a..1d83d64d2 100644 --- a/apps/opencs/view/prefs/pagebase.hpp +++ b/apps/opencs/view/prefs/pagebase.hpp @@ -21,6 +21,10 @@ namespace CSVPrefs PageBase (CSMPrefs::Category& category, QWidget *parent); CSMPrefs::Category& getCategory(); + + public slots: + + void resetCategory(); }; }