From a25cffc2420382254295dcfd17b1abee840baf48 Mon Sep 17 00:00:00 2001 From: cc9cii Date: Sun, 28 Sep 2014 10:17:54 +1000 Subject: [PATCH] Fixed default value not being set for spinbox. Changed the default value of max subviews to 256. Simplified the call signature to get settings & set an initial value. Fixed missing settings for num_lights. --- apps/opencs/editor.cpp | 16 ++++---- apps/opencs/model/settings/usersettings.cpp | 43 +++++++++------------ apps/opencs/model/settings/usersettings.hpp | 2 +- apps/opencs/view/doc/view.cpp | 8 ++-- apps/opencs/view/render/scenewidget.cpp | 6 +-- apps/opencs/view/settings/rangeview.cpp | 2 + 6 files changed, 36 insertions(+), 41 deletions(-) diff --git a/apps/opencs/editor.cpp b/apps/opencs/editor.cpp index a753b0988b..de3e239659 100644 --- a/apps/opencs/editor.cpp +++ b/apps/opencs/editor.cpp @@ -265,7 +265,7 @@ std::auto_ptr CS::Editor::setupGraphics() #else "OpenGL Rendering Subsystem"; #endif - std::string renderSystem = mUserSettings.setting("Video/render system", QStringList() << renderer.c_str()).toStdString(); + std::string renderSystem = mUserSettings.setting("Video/render system", renderer.c_str()).toStdString(); Ogre::Root::getSingleton().setRenderSystem(Ogre::Root::getSingleton().getRenderSystemByName(renderSystem)); @@ -331,27 +331,27 @@ std::auto_ptr CS::Editor::setupGraphics() factory->loadAllFiles(); - bool shaders = mUserSettings.setting("Objects/shaders", (QStringList() << QString("true"))) == "true" ? true : false; + bool shaders = mUserSettings.setting("Objects/shaders", QString("true")) == "true" ? true : false; sh::Factory::getInstance ().setShadersEnabled (shaders); - std::string fog = mUserSettings.setting("Shader/fog", (QStringList() << QString("true"))).toStdString(); + std::string fog = mUserSettings.setting("Shader/fog", QString("true")).toStdString(); sh::Factory::getInstance().setGlobalSetting ("fog", fog); - std::string shadows = mUserSettings.setting("Shader/shadows", (QStringList() << QString("false"))).toStdString(); + std::string shadows = mUserSettings.setting("Shader/shadows", QString("false")).toStdString(); sh::Factory::getInstance().setGlobalSetting ("shadows", shadows); - std::string shadows_pssm = mUserSettings.setting("Shader/shadows_pssm", (QStringList() << QString("false"))).toStdString(); + std::string shadows_pssm = mUserSettings.setting("Shader/shadows_pssm", QString("false")).toStdString(); sh::Factory::getInstance().setGlobalSetting ("shadows_pssm", shadows_pssm); - std::string render_refraction = mUserSettings.setting("Shader/render_refraction", (QStringList() << QString("false"))).toStdString(); + std::string render_refraction = mUserSettings.setting("Shader/render_refraction", QString("false")).toStdString(); sh::Factory::getInstance ().setGlobalSetting ("render_refraction", render_refraction); // internal setting - may be switched on or off by the use of shader configurations sh::Factory::getInstance ().setGlobalSetting ("viewproj_fix", "false"); - sh::Factory::getInstance ().setGlobalSetting ("num_lights", - mUserSettings.settingValue("Objects/num_lights").toStdString()); + std::string num_lights = mUserSettings.setting("Objects/num_lights", QString("8")).toStdString(); + sh::Factory::getInstance ().setGlobalSetting ("num_lights", num_lights); /// \todo add more configurable shiny settings diff --git a/apps/opencs/model/settings/usersettings.cpp b/apps/opencs/model/settings/usersettings.cpp index d28512e120..97c9431e1d 100644 --- a/apps/opencs/model/settings/usersettings.cpp +++ b/apps/opencs/model/settings/usersettings.cpp @@ -50,11 +50,11 @@ void CSMSettings::UserSettings::buildSettingModelDefaults() section = "Objects"; { - Setting *numLights = createSetting (Type_SpinBox, section, "num lights"); + Setting *numLights = createSetting (Type_SpinBox, section, "num_lights"); numLights->setDefaultValue(8); numLights->setEditorSetting(true); numLights->setColumnSpan (1); - numLights->setMinimum (0); + numLights->setMinimum (2); numLights->setMaximum (100); // FIXME: not sure what the max value should be numLights->setWidgetWidth (10); numLights->setViewLocation(1, 2); @@ -74,19 +74,16 @@ void CSMSettings::UserSettings::buildSettingModelDefaults() { Setting *fastFactor = createSetting (Type_SpinBox, section, "fast factor"); fastFactor->setDefaultValue(4); - fastFactor->setEditorSetting(false); + fastFactor->setEditorSetting(true); fastFactor->setColumnSpan (1); - // FIXME: setMinimum or setSpecialValueText appears to be broken, possibly due - // to there being an empty string default for special value text. - //fastFactor->setMinimum (1); - fastFactor->setSpecialValueText("1"); // workaround for above + fastFactor->setMinimum (1); fastFactor->setMaximum (100); // FIXME: not sure what the max value should be fastFactor->setWidgetWidth (10); fastFactor->setViewLocation(1, 2); Setting *farClipDist = createSetting (Type_SpinBox, section, "far clip distance"); farClipDist->setDefaultValue(300000); - farClipDist->setEditorSetting(false); + farClipDist->setEditorSetting(true); farClipDist->setColumnSpan (1); farClipDist->setMinimum (0); farClipDist->setMaximum (1000000); // FIXME: not sure what the max value should be @@ -95,7 +92,7 @@ void CSMSettings::UserSettings::buildSettingModelDefaults() Setting *timerStart = createSetting (Type_SpinBox, section, "timer start"); timerStart->setDefaultValue(20); - timerStart->setEditorSetting(false); + timerStart->setEditorSetting(true); timerStart->setColumnSpan (1); timerStart->setMinimum (0); timerStart->setMaximum (100); // FIXME: not sure what the max value should be @@ -106,12 +103,11 @@ void CSMSettings::UserSettings::buildSettingModelDefaults() section = "SubView"; { Setting *maxSubView = createSetting (Type_SpinBox, section, "max subviews"); - maxSubView->setDefaultValue(3); + maxSubView->setDefaultValue(256); maxSubView->setEditorSetting(false); maxSubView->setColumnSpan (1); - //maxSubView->setMinimum (1); - maxSubView->setSpecialValueText("1"); // workaround for setMinimum - maxSubView->setMaximum (100); // FIXME: not sure what the max value should be + maxSubView->setMinimum (1); + maxSubView->setMaximum (256); // FIXME: not sure what the max value should be maxSubView->setWidgetWidth (10); maxSubView->setViewLocation(1, 2); @@ -119,8 +115,7 @@ void CSMSettings::UserSettings::buildSettingModelDefaults() minWidth->setDefaultValue(325); minWidth->setEditorSetting(false); minWidth->setColumnSpan (1); - //minWidth->setMinimum (50); - minWidth->setSpecialValueText("50"); // workaround for setMinimum + minWidth->setMinimum (50); minWidth->setMaximum (10000); // FIXME: not sure what the max value should be minWidth->setWidgetWidth (10); minWidth->setViewLocation(2, 2); @@ -128,7 +123,7 @@ void CSMSettings::UserSettings::buildSettingModelDefaults() Setting *reuse = createSetting (Type_CheckBox, section, "reuse"); reuse->setDeclaredValues(QStringList() << "true" << "false"); reuse->setDefaultValue("true"); - reuse->setEditorSetting(true); + reuse->setEditorSetting(false); reuse->setSpecialValueText("Reuse SubView"); reuse->setWidgetWidth(25); reuse->setColumnSpan (3); @@ -147,8 +142,8 @@ void CSMSettings::UserSettings::buildSettingModelDefaults() width->setDefaultValues (QStringList() << "1024"); height->setDefaultValues (QStringList() << "768"); - width->setEditorSetting (true); - height->setEditorSetting (true); + width->setEditorSetting (false); + height->setEditorSetting (false); height->setViewLocation (2,2); width->setViewLocation (2,1); @@ -191,8 +186,8 @@ void CSMSettings::UserSettings::buildSettingModelDefaults() rsd->setDeclaredValues (values); ritd->setDeclaredValues (values); - rsd->setEditorSetting (true); - ritd->setEditorSetting (true); + rsd->setEditorSetting (false); + ritd->setEditorSetting (false); } section = "Proxy Selection Test"; @@ -407,14 +402,14 @@ void CSMSettings::UserSettings::loadSettings (const QString &fileName) } // if the key is not found create one with a defaut value -QString CSMSettings::UserSettings::setting(const QString &viewKey, const QStringList &list) +QString CSMSettings::UserSettings::setting(const QString &viewKey, const QString &value) { if(mSettingDefinitions->contains(viewKey)) return settingValue(viewKey); - else if(!list.empty()) + else if(value != QString()) { - mSettingDefinitions->setValue (viewKey, list); - return list.at(0); + mSettingDefinitions->setValue (viewKey, QStringList() << value); + return value; } return QString(); diff --git a/apps/opencs/model/settings/usersettings.hpp b/apps/opencs/model/settings/usersettings.hpp index e2851c9ac6..0aabd66e57 100644 --- a/apps/opencs/model/settings/usersettings.hpp +++ b/apps/opencs/model/settings/usersettings.hpp @@ -77,7 +77,7 @@ namespace CSMSettings { ///Save any unsaved changes in the QSettings object void saveDefinitions() const; - QString setting(const QString &viewKey, const QStringList &list = QStringList()); + QString setting(const QString &viewKey, const QString &value = QString()); private: diff --git a/apps/opencs/view/doc/view.cpp b/apps/opencs/view/doc/view.cpp index 2ff00a5351..744865f1cb 100644 --- a/apps/opencs/view/doc/view.cpp +++ b/apps/opencs/view/doc/view.cpp @@ -456,7 +456,7 @@ void CSVDoc::View::addSubView (const CSMWorld::UniversalId& id, const std::strin // User setting to reuse sub views (on a per top level view basis) bool reuse = - userSettings.setting("SubView/reuse", (QStringList() << QString("true"))) == "true" ? true : false; + userSettings.setting("SubView/reuse", QString("true")) == "true" ? true : false; if(reuse) { foreach(SubView *sb, mSubViews) @@ -475,8 +475,7 @@ void CSVDoc::View::addSubView (const CSMWorld::UniversalId& id, const std::strin // // If the sub view limit setting is one, the sub view title bar is hidden and the // text in the main title bar is adjusted accordingly - int maxSubView = - userSettings.setting("SubView/max subviews", (QStringList() << QString("3"))).toInt(); + int maxSubView = userSettings.setting("SubView/max subviews", QString("256")).toInt(); if(mSubViews.size() >= maxSubView) // create a new top level view { mViewManager.addView(mDocument, id, hint); @@ -499,8 +498,7 @@ void CSVDoc::View::addSubView (const CSMWorld::UniversalId& id, const std::strin if (!hint.empty()) view->useHint (hint); - int minWidth = - userSettings.setting("SubView/minimum width", (QStringList() << QString("325"))).toInt(); + int minWidth = userSettings.setting("SubView/minimum width", QString("325")).toInt(); view->setMinimumWidth(minWidth); view->setStatusBar (mShowStatusBar->isChecked()); diff --git a/apps/opencs/view/render/scenewidget.cpp b/apps/opencs/view/render/scenewidget.cpp index ff1765f354..cdf55a9eb8 100644 --- a/apps/opencs/view/render/scenewidget.cpp +++ b/apps/opencs/view/render/scenewidget.cpp @@ -48,10 +48,10 @@ namespace CSVRender CSMSettings::UserSettings &userSettings = CSMSettings::UserSettings::instance(); - int farClipDist = userSettings.setting("Scene/far clip distance", (QStringList() << QString("300000"))).toInt(); + int farClipDist = userSettings.setting("Scene/far clip distance", QString("300000")).toInt(); mCamera->setFarClipDistance (farClipDist); - mFastFactor = userSettings.setting("Scene/fast factor", (QStringList() << QString("4"))).toInt(); + mFastFactor = userSettings.setting("Scene/fast factor", QString("4")).toInt(); mCamera->roll (Ogre::Degree (90)); @@ -61,7 +61,7 @@ namespace CSVRender connect (timer, SIGNAL (timeout()), this, SLOT (update())); - int timerStart = userSettings.setting("Scene/timer start", (QStringList() << QString("20"))).toInt(); + int timerStart = userSettings.setting("Scene/timer start", QString("20")).toInt(); timer->start (timerStart); /// \todo make shortcut configurable diff --git a/apps/opencs/view/settings/rangeview.cpp b/apps/opencs/view/settings/rangeview.cpp index 606ad4939c..49cc170e1d 100644 --- a/apps/opencs/view/settings/rangeview.cpp +++ b/apps/opencs/view/settings/rangeview.cpp @@ -129,6 +129,8 @@ void CSVSettings::RangeView::buildSpinBox (CSMSettings::Setting *setting) mRangeWidget->setProperty ("wrapping", setting->wrapping()); dynamic_cast (mRangeWidget)->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter); + if(setting->type() == CSMSettings::Type_SpinBox) + dynamic_cast (mRangeWidget)->setValue (setting->defaultValues().at(0).toInt()); // FIXME: can there be more than one? } void CSVSettings::RangeView::slotUpdateView (int value)