mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-01-18 13:12:50 +00:00
Add option to reset settings to default
This commit is contained in:
parent
8d84869432
commit
64879c03e4
@ -5,6 +5,8 @@
|
||||
#include <algorithm>
|
||||
#include <sstream>
|
||||
|
||||
#include <QMutexLocker>
|
||||
|
||||
#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()
|
||||
{
|
||||
|
@ -106,6 +106,8 @@ namespace CSMPrefs
|
||||
|
||||
static State& get();
|
||||
|
||||
void resetCategory(const std::string& category);
|
||||
|
||||
signals:
|
||||
|
||||
void settingChanged (const CSMPrefs::Setting *setting);
|
||||
|
@ -6,9 +6,11 @@
|
||||
#include <QGridLayout>
|
||||
#include <QStackedLayout>
|
||||
#include <QVBoxLayout>
|
||||
#include <QPushButton>
|
||||
|
||||
#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);
|
||||
|
@ -2,9 +2,11 @@
|
||||
#include "page.hpp"
|
||||
|
||||
#include <QGridLayout>
|
||||
#include <QPushButton>
|
||||
|
||||
#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);
|
||||
|
||||
|
@ -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());
|
||||
}
|
||||
|
@ -21,6 +21,10 @@ namespace CSVPrefs
|
||||
PageBase (CSMPrefs::Category& category, QWidget *parent);
|
||||
|
||||
CSMPrefs::Category& getCategory();
|
||||
|
||||
public slots:
|
||||
|
||||
void resetCategory();
|
||||
};
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user