1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-04-01 21:06:43 +00:00

Implemented rangeview with spinbox as only control. Simplified setting

class constructor.
This commit is contained in:
graffy76 2014-05-03 18:58:43 -05:00
parent bc6197c552
commit 1c26741c56
17 changed files with 398 additions and 182 deletions

View file

@ -97,6 +97,7 @@ opencs_units (view/settings
listview listview
rangeview rangeview
resizeablestackedwidget resizeablestackedwidget
spinbox
) )
opencs_units_noqt (view/settings opencs_units_noqt (view/settings

View file

@ -1,13 +1,8 @@
#include "setting.hpp" #include "setting.hpp"
#include "support.hpp" #include "support.hpp"
CSMSettings::Setting::Setting()
{
buildDefaultSetting();
}
CSMSettings::Setting::Setting(SettingType typ, const QString &settingName, CSMSettings::Setting::Setting(SettingType typ, const QString &settingName,
const QString &pageName, const QStringList &values) const QString &pageName)
: mIsEditorSetting (false) : mIsEditorSetting (false)
{ {
buildDefaultSetting(); buildDefaultSetting();
@ -19,10 +14,9 @@ CSMSettings::Setting::Setting(SettingType typ, const QString &settingName,
setProperty (Property_IsMultiValue, QVariant(true).toString()); setProperty (Property_IsMultiValue, QVariant(true).toString());
//view type is related to setting type by an order of magnitude //view type is related to setting type by an order of magnitude
setProperty (Property_ViewType, QVariant (settingType / 10).toString()); setProperty (Property_SettingType, QVariant (settingType).toString());
setProperty (Property_Page, pageName); setProperty (Property_Page, pageName);
setProperty (Property_Name, settingName); setProperty (Property_Name, settingName);
setProperty (Property_DeclaredValues, values);
} }
void CSMSettings::Setting::buildDefaultSetting() void CSMSettings::Setting::buildDefaultSetting()
@ -73,6 +67,11 @@ int CSMSettings::Setting::columnSpan() const
return property (Property_ColumnSpan).at(0).toInt(); return property (Property_ColumnSpan).at(0).toInt();
} }
void CSMSettings::Setting::setDeclaredValues (QStringList list)
{
setProperty (Property_DeclaredValues, list);
}
QStringList CSMSettings::Setting::declaredValues() const QStringList CSMSettings::Setting::declaredValues() const
{ {
return property (Property_DeclaredValues); return property (Property_DeclaredValues);
@ -165,6 +164,16 @@ bool CSMSettings::Setting::serializable() const
return (property (Property_Serializable).at(0) == "true"); return (property (Property_Serializable).at(0) == "true");
} }
void CSMSettings::Setting::setSpecialValueText(const QString &text)
{
setProperty (Property_SpecialValueText, text);
}
QString CSMSettings::Setting::specialValueText() const
{
return property (Property_SpecialValueText).at(0);
}
void CSMSettings::Setting::setName (const QString &value) void CSMSettings::Setting::setName (const QString &value)
{ {
setProperty (Property_Name, value); setProperty (Property_Name, value);
@ -185,6 +194,16 @@ QString CSMSettings::Setting::page() const
return property (Property_Page).at(0); return property (Property_Page).at(0);
} }
void CSMSettings::Setting::setPrefix (const QString &value)
{
setProperty (Property_Prefix, value);
}
QString CSMSettings::Setting::prefix() const
{
return property (Property_Prefix).at(0);
}
void CSMSettings::Setting::setRowSpan (const int value) void CSMSettings::Setting::setRowSpan (const int value)
{ {
setProperty (Property_RowSpan, value); setProperty (Property_RowSpan, value);
@ -195,15 +214,76 @@ int CSMSettings::Setting::rowSpan () const
return property (Property_RowSpan).at(0).toInt(); return property (Property_RowSpan).at(0).toInt();
} }
void CSMSettings::Setting::setViewType (int vType) void CSMSettings::Setting::setSingleStep (int value)
{ {
setProperty (Property_ViewType, vType); setProperty (Property_SingleStep, value);
}
void CSMSettings::Setting::setSingleStep (double value)
{
setProperty (Property_SingleStep, value);
}
QString CSMSettings::Setting::singleStep() const
{
return property (Property_SingleStep).at(0);
}
void CSMSettings::Setting::setSuffix (const QString &value)
{
setProperty (Property_Suffix, value);
}
QString CSMSettings::Setting::suffix() const
{
return property (Property_Suffix).at(0);
}
void CSMSettings::Setting::setType (int settingType)
{
setProperty (Property_SettingType, settingType);
}
CSMSettings::SettingType CSMSettings::Setting::type() const
{
return static_cast <CSMSettings::SettingType> ( property (
Property_SettingType).at(0).toInt());
}
void CSMSettings::Setting::setMaximum (int value)
{
setProperty (Property_Maximum, value);
}
void CSMSettings::Setting::setMaximum (double value)
{
setProperty (Property_Maximum, value);
}
QString CSMSettings::Setting::maximum() const
{
return property (Property_Maximum).at(0);
}
void CSMSettings::Setting::setMinimum (int value)
{
setProperty (Property_Minimum, value);
}
void CSMSettings::Setting::setMinimum (double value)
{
setProperty (Property_Minimum, value);
}
QString CSMSettings::Setting::minimum() const
{
return property (Property_Minimum).at(0);
} }
CSVSettings::ViewType CSMSettings::Setting::viewType() const CSVSettings::ViewType CSMSettings::Setting::viewType() const
{ {
return static_cast <CSVSettings::ViewType> return static_cast <CSVSettings::ViewType> ( property (
(property(Property_ViewType).at(0).toInt()); Property_SettingType).at(0).toInt() / 10);
} }
void CSMSettings::Setting::setViewColumn (int value) void CSMSettings::Setting::setViewColumn (int value)
@ -241,6 +321,17 @@ int CSMSettings::Setting::widgetWidth() const
{ {
return property (Property_WidgetWidth).at(0).toInt(); return property (Property_WidgetWidth).at(0).toInt();
} }
void CSMSettings::Setting::setWrapping (bool state)
{
setProperty (Property_Wrapping, state);
}
bool CSMSettings::Setting::wrapping() const
{
return (property (Property_Wrapping).at(0) == "true");
}
void CSMSettings::Setting::setProperty (SettingProperty prop, bool value) void CSMSettings::Setting::setProperty (SettingProperty prop, bool value)
{ {
setProperty (prop, QStringList() << QVariant (value).toString()); setProperty (prop, QStringList() << QVariant (value).toString());
@ -251,6 +342,11 @@ void CSMSettings::Setting::setProperty (SettingProperty prop, int value)
setProperty (prop, QStringList() << QVariant (value).toString()); setProperty (prop, QStringList() << QVariant (value).toString());
} }
void CSMSettings::Setting::setProperty (SettingProperty prop, double value)
{
setProperty (prop, QStringList() << QVariant (value).toString());
}
void CSMSettings::Setting::setProperty (SettingProperty prop, void CSMSettings::Setting::setProperty (SettingProperty prop,
const QString &value) const QString &value)
{ {
@ -263,18 +359,3 @@ void CSMSettings::Setting::setProperty (SettingProperty prop,
if (prop < mProperties.size()) if (prop < mProperties.size())
mProperties.replace (prop, value); mProperties.replace (prop, value);
} }
QDataStream &operator <<(QDataStream &stream, const CSMSettings::Setting& setting)
{
// stream << setting.properties();
// stream << setting.proxies();
return stream;
}
QDataStream &operator >>(QDataStream& stream, CSMSettings::Setting& setting)
{
// stream >> setting.properties();
// stream >> setting.proxies();
return stream;
}

View file

@ -27,12 +27,8 @@ namespace CSMSettings
public: public:
explicit Setting();
explicit Setting(SettingType typ, const QString &settingName, explicit Setting(SettingType typ, const QString &settingName,
const QString &pageName, const QString &pageName);
const QStringList &values = QStringList());
void addProxy (const Setting *setting, const QStringList &vals); void addProxy (const Setting *setting, const QStringList &vals);
void addProxy (const Setting *setting, const QList <QStringList> &list); void addProxy (const Setting *setting, const QList <QStringList> &list);
@ -66,12 +62,18 @@ namespace CSMSettings
void setIsMultiValue (bool state); void setIsMultiValue (bool state);
bool isMultiValue() const; bool isMultiValue() const;
void setMask (const QString &value);
QString mask() const;
void setName (const QString &value); void setName (const QString &value);
QString name() const; QString name() const;
void setPage (const QString &value); void setPage (const QString &value);
QString page() const; QString page() const;
void setPrefix (const QString &value);
QString prefix() const;
void setRowSpan (const int value); void setRowSpan (const int value);
int rowSpan() const; int rowSpan() const;
@ -80,6 +82,24 @@ namespace CSMSettings
void setSerializable (bool state); void setSerializable (bool state);
bool serializable() const; bool serializable() const;
void setSpecialValueText (const QString &text);
QString specialValueText() const;
void setSingleStep (int value);
void setSingleStep (double value);
QString singleStep() const;
void setSuffix (const QString &value);
QString suffix() const;
void setMaximum (int value);
void setMaximum (double value);
QString maximum() const;
void setMinimum (int value);
void setMinimum (double value);
QString minimum() const;
void setViewColumn (int value); void setViewColumn (int value);
int viewColumn() const; int viewColumn() const;
@ -88,9 +108,14 @@ namespace CSMSettings
void setViewRow (int value); void setViewRow (int value);
int viewRow() const; int viewRow() const;
void setViewType (int vType); void setType (int settingType);
CSMSettings::SettingType type() const;
CSVSettings::ViewType viewType() const; CSVSettings::ViewType viewType() const;
void setWrapping (bool state);
bool wrapping() const;
void setWidgetWidth (int value); void setWidgetWidth (int value);
int widgetWidth() const; int widgetWidth() const;
@ -100,6 +125,7 @@ namespace CSMSettings
///boilerplate code to convert setting values of common types ///boilerplate code to convert setting values of common types
void setProperty (SettingProperty prop, bool value); void setProperty (SettingProperty prop, bool value);
void setProperty (SettingProperty prop, int value); void setProperty (SettingProperty prop, int value);
void setProperty (SettingProperty prop, double value);
void setProperty (SettingProperty prop, const QString &value); void setProperty (SettingProperty prop, const QString &value);
void setProperty (SettingProperty prop, const QStringList &value); void setProperty (SettingProperty prop, const QStringList &value);
@ -111,9 +137,4 @@ namespace CSMSettings
}; };
} }
Q_DECLARE_METATYPE(CSMSettings::Setting)
QDataStream &operator <<(QDataStream &stream, const CSMSettings::Setting& setting);
QDataStream &operator >>(QDataStream &stream, CSMSettings::Setting& setting);
#endif // CSMSETTINGS_SETTING_HPP #endif // CSMSETTINGS_SETTING_HPP

View file

@ -30,8 +30,7 @@ void CSMSettings::SettingManager::dumpModel()
} }
CSMSettings::Setting *CSMSettings::SettingManager::createSetting CSMSettings::Setting *CSMSettings::SettingManager::createSetting
(CSMSettings::SettingType typ, const QString &page, const QString &name, (CSMSettings::SettingType typ, const QString &page, const QString &name)
const QStringList &values)
{ {
//get list of all settings for the current setting name //get list of all settings for the current setting name
if (findSetting (page, name)) if (findSetting (page, name))
@ -41,7 +40,8 @@ CSMSettings::Setting *CSMSettings::SettingManager::createSetting
return 0; return 0;
} }
Setting *setting = new Setting (typ, name, page, values); Setting *setting = new Setting (typ, name, page);
//add declaration to the model //add declaration to the model
mSettings.append (setting); mSettings.append (setting);

View file

@ -46,8 +46,7 @@ namespace CSMSettings
///add a new setting to the model and return it ///add a new setting to the model and return it
Setting *createSetting (CSMSettings::SettingType typ, Setting *createSetting (CSMSettings::SettingType typ,
const QString &page, const QString &name, const QString &page, const QString &name);
const QStringList &values = QStringList());
///add definitions to the settings specified in the page map ///add definitions to the settings specified in the page map
void addDefinitions (DefinitionPageMap &pageMap); void addDefinitions (DefinitionPageMap &pageMap);

View file

@ -27,7 +27,7 @@ namespace CSMSettings
{ {
Property_Name = 0, Property_Name = 0,
Property_Page = 1, Property_Page = 1,
Property_ViewType = 2, Property_SettingType = 2,
Property_IsMultiValue = 3, Property_IsMultiValue = 3,
Property_IsMultiLine = 4, Property_IsMultiLine = 4,
Property_WidgetWidth = 5, Property_WidgetWidth = 5,
@ -37,12 +37,19 @@ namespace CSMSettings
Property_Serializable = 9, Property_Serializable = 9,
Property_ColumnSpan = 10, Property_ColumnSpan = 10,
Property_RowSpan = 11, Property_RowSpan = 11,
Property_Minimum = 12,
Property_Maximum = 13,
Property_SpecialValueText = 14,
Property_Prefix = 15,
Property_Suffix = 16,
Property_SingleStep = 17,
Property_Wrapping = 18,
//Stringlists should always be the last items //Stringlists should always be the last items
Property_DefaultValues = 12, Property_DefaultValues = 19,
Property_DeclaredValues = 13, Property_DeclaredValues = 20,
Property_DefinedValues = 14, Property_DefinedValues = 21,
Property_Proxies = 15 Property_Proxies = 22
}; };
enum SettingType enum SettingType
@ -64,10 +71,12 @@ namespace CSMSettings
Type_ListView = 10, Type_ListView = 10,
Type_ComboBox = 11, Type_ComboBox = 11,
Type_SpinBox = 21, Type_SpinBox = 21,
Type_Slider = 23, Type_DoubleSpinBox = 23,
Type_Dial = 24, Type_Slider = 25,
Type_Dial = 27,
Type_TextArea = 30, Type_TextArea = 30,
Type_LineEdit = 31 Type_LineEdit = 31,
Type_Undefined = 40
}; };
enum MergeMethod enum MergeMethod
@ -97,7 +106,7 @@ namespace CSVSettings
}; };
} }
//
namespace CSMSettings namespace CSMSettings
{ {
struct PropertyDefaultValues struct PropertyDefaultValues
@ -109,9 +118,10 @@ namespace CSMSettings
const QString sPropertyNames[] = const QString sPropertyNames[] =
{ {
"name", "page", "view_type", "is_multi_value", "name", "page", "setting_type", "is_multi_value",
"is_multi_line", "widget_width", "view_row", "view_column", "delimiter", "is_multi_line", "widget_width", "view_row", "view_column", "delimiter",
"is_serializable","column_span", "row_span", "is_serializable","column_span", "row_span", "minimum", "maximum",
"special_value_text", "prefix", "suffix", "single_step", "wrapping",
"defaults", "declarations", "definitions", "proxies" "defaults", "declarations", "definitions", "proxies"
}; };
@ -119,16 +129,23 @@ namespace CSMSettings
{ {
"", //name "", //name
"", //page "", //page
"0", //view type "40", //setting type
"false", //multivalue "false", //multivalue
"false", //multiline "false", //multiline
"0", //widget width "7", //widget width
"-1", //view row "-1", //view row
"-1", //view column "-1", //view column
",", //delimiter ",", //delimiter
"true", //serialized "true", //serialized
"1", //column span "1", //column span
"1", //row span "1", //row span
"0", //value range
"0", //value minimum
"0", //value maximum
"", //special text
"", //prefix
"", //suffix
"false", //wrapping
"", //default values "", //default values
"", //declared values "", //declared values
"", //defined values "", //defined values

View file

@ -51,7 +51,7 @@ void CSMSettings::UserSettings::buildSettingModelDefaults()
Setting *height = createSetting (Type_LineEdit, section, "Height"); Setting *height = createSetting (Type_LineEdit, section, "Height");
width->setWidgetWidth (5); width->setWidgetWidth (5);
height->setWidgetWidth (5); height->setWidgetWidth (8);
width->setDefaultValues (QStringList() << "1024"); width->setDefaultValues (QStringList() << "1024");
height->setDefaultValues (QStringList() << "768"); height->setDefaultValues (QStringList() << "768");
@ -66,13 +66,10 @@ void CSMSettings::UserSettings::buildSettingModelDefaults()
*Create the proxy setting for predefined values *Create the proxy setting for predefined values
*/ */
Setting *preDefined = createSetting (Type_ComboBox, section, Setting *preDefined = createSetting (Type_ComboBox, section,
"Pre-Defined", "Pre-Defined");
QStringList()
<< "640 x 480" preDefined->setDeclaredValues (QStringList() << "640 x 480"
<< "800 x 600" << "800 x 600" << "1024 x 768" << "1440 x 900");
<< "1024 x 768"
<< "1440 x 900"
);
preDefined->setViewLocation (1, 1); preDefined->setViewLocation (1, 1);
preDefined->setWidgetWidth (10); preDefined->setWidgetWidth (10);
@ -95,12 +92,13 @@ void CSMSettings::UserSettings::buildSettingModelDefaults()
<< defaultValue << "Icon Only" << "Text Only"; << defaultValue << "Icon Only" << "Text Only";
Setting *rsd = createSetting (Type_RadioButton, Setting *rsd = createSetting (Type_RadioButton,
section, "Record Status Display", section, "Record Status Display");
values);
Setting *ritd = createSetting (Type_RadioButton, Setting *ritd = createSetting (Type_RadioButton,
section, "Referenceable ID Type Display", section, "Referenceable ID Type Display");
values);
rsd->setDeclaredValues (values);
ritd->setDeclaredValues (values);
rsd->setEditorSetting (true); rsd->setEditorSetting (true);
ritd->setEditorSetting (true); ritd->setEditorSetting (true);
@ -108,44 +106,63 @@ void CSMSettings::UserSettings::buildSettingModelDefaults()
section = "Proxy Selection Test"; section = "Proxy Selection Test";
{ {
//create three setting objects, specifying the basic widget type, /******************************************************************
//the setting view name, the page name, and the default value * There are three types of values:
*
* Declared values
*
* Pre-determined values, typically for
* combobox drop downs and boolean (radiobutton / checkbox) labels.
* These values represent the total possible list of values that
* may define a setting. No other values are allowed.
*
* Defined values
*
* Values which represent the actual, current value of
* a setting. For settings with declared values, this must be one or
* several declared values, as appropriate.
*
* Proxy values - values the proxy master updates the proxy slave when
* it's own definition is set / changed. These are definitions for
* proxy slave settings, but must match any declared values the proxy
* slave has, if any.
*******************************************************************/
//create setting objects, specifying the basic widget type,
//the page name, and the view name
Setting *masterBoolean = createSetting (Type_RadioButton, section, Setting *masterBoolean = createSetting (Type_RadioButton, section,
"Master Proxy", "Master Proxy");
QStringList()
<< "Profile One" << "Profile Two"
<< "Profile Three" << "Profile Four"
);
Setting *slaveBoolean = createSetting (Type_CheckBox, section, Setting *slaveBoolean = createSetting (Type_CheckBox, section,
"Proxy Checkboxes", "Proxy Checkboxes");
QStringList() << "One" << "Two"
<< "Three" << "Four" << "Five"
);
Setting *slaveSingleText = createSetting (Type_LineEdit, section, Setting *slaveSingleText = createSetting (Type_LineEdit, section,
"Proxy TextBox 1" "Proxy TextBox 1");
);
Setting *slaveMultiText = createSetting (Type_LineEdit, section, Setting *slaveMultiText = createSetting (Type_LineEdit, section,
"ProxyTextBox 2" "ProxyTextBox 2");
);
Setting *slaveAlphaSpinbox = createSetting (Type_SpinBox, section,
"Alpha Spinbox");
Setting *slaveIntegerSpinbox = createSetting (Type_SpinBox, section,
"Int Spinbox");
Setting *slaveDoubleSpinbox = createSetting (Type_DoubleSpinBox,
section, "Double Spinbox");
//set declared values for selected views
masterBoolean->setDeclaredValues (QStringList()
<< "Profile One" << "Profile Two"
<< "Profile Three" << "Profile Four");
slaveBoolean->setDeclaredValues (QStringList()
<< "One" << "Two" << "Three" << "Four" << "Five");
slaveAlphaSpinbox->setDeclaredValues (QStringList()
<< "One" << "Two" << "Three" << "Four");
// There are three types of values:
//
// Declared values - Pre-determined values, typically for
// combobox drop downs and boolean (radiobutton / checkbox) labels.
// These values represent the total possible list of values that may
// define a setting. No other values are allowed.
//
// Defined values - Values which represent the atual, current value of
// a setting. For settings with declared values, this must be one or
// several declared values, as appropriate.
//
// Proxy values - values the proxy master updates the proxy slave when
// it's own definition is set / changed. These are definitions for
// proxy slave settings, but must match any declared values the proxy
// slave has, if any.
masterBoolean->addProxy (slaveBoolean, QList <QStringList>() masterBoolean->addProxy (slaveBoolean, QList <QStringList>()
<< (QStringList() << "One" << "Three") << (QStringList() << "One" << "Three")
@ -168,11 +185,32 @@ void CSMSettings::UserSettings::buildSettingModelDefaults()
<< (QStringList() << "Two" << "Four") << (QStringList() << "Two" << "Four")
); );
masterBoolean->addProxy (slaveAlphaSpinbox, QList <QStringList>()
<< (QStringList() << "Four")
<< (QStringList() << "Three")
<< (QStringList() << "Two")
<< (QStringList() << "One"));
masterBoolean->addProxy (slaveIntegerSpinbox, QList <QStringList> ()
<< (QStringList() << "0")
<< (QStringList() << "7")
<< (QStringList() << "14")
<< (QStringList() << "21"));
masterBoolean->addProxy (slaveDoubleSpinbox, QList <QStringList> ()
<< (QStringList() << "0.17")
<< (QStringList() << "0.34")
<< (QStringList() << "0.51")
<< (QStringList() << "0.68"));
//settings with proxies are not serialized by default //settings with proxies are not serialized by default
//other settings non-serialized for demo purposes //other settings non-serialized for demo purposes
slaveBoolean->setSerializable (false); slaveBoolean->setSerializable (false);
slaveSingleText->setSerializable (false); slaveSingleText->setSerializable (false);
slaveMultiText->setSerializable (false); slaveMultiText->setSerializable (false);
slaveAlphaSpinbox->setSerializable (false);
slaveIntegerSpinbox->setSerializable (false);
slaveDoubleSpinbox->setSerializable (false);
slaveBoolean->setDefaultValues (QStringList() slaveBoolean->setDefaultValues (QStringList()
<< "One" << "Three" << "Five"); << "One" << "Three" << "Five");
@ -184,7 +222,25 @@ void CSMSettings::UserSettings::buildSettingModelDefaults()
slaveSingleText->setWidgetWidth (24); slaveSingleText->setWidgetWidth (24);
slaveMultiText->setWidgetWidth (24); slaveMultiText->setWidgetWidth (24);
}
slaveAlphaSpinbox->setDefaultValue ("Two");
slaveAlphaSpinbox->setWidgetWidth (20);
//slaveAlphaSpinbox->setPrefix ("No. ");
//slaveAlphaSpinbox->setSuffix ("!");
slaveAlphaSpinbox->setWrapping (true);
slaveIntegerSpinbox->setDefaultValue ("14");
slaveIntegerSpinbox->setMinimum (0);
slaveIntegerSpinbox->setMaximum (58);
slaveIntegerSpinbox->setPrefix ("$");
slaveIntegerSpinbox->setSuffix (".00");
slaveIntegerSpinbox->setWidgetWidth (10);
slaveIntegerSpinbox->setSpecialValueText ("Nothing!");
slaveDoubleSpinbox->setDefaultValue ("0.51");
slaveDoubleSpinbox->setSingleStep(0.17);
slaveDoubleSpinbox->setMaximum(4.0);
}
} }
CSMSettings::UserSettings::~UserSettings() CSMSettings::UserSettings::~UserSettings()

View file

@ -18,10 +18,19 @@ CSVSettings::BooleanView::BooleanView (CSMSettings::Setting *setting,
{ {
QAbstractButton *button = 0; QAbstractButton *button = 0;
if (isMultiValue()) switch (setting->type())
{
case CSMSettings::Type_CheckBox:
button = new QCheckBox (value, this); button = new QCheckBox (value, this);
else break;
case CSMSettings::Type_RadioButton:
button = new QRadioButton (value, this); button = new QRadioButton (value, this);
break;
default:
break;
}
connect (button, SIGNAL (clicked (bool)), connect (button, SIGNAL (clicked (bool)),
this, SLOT (slotToggled (bool))); this, SLOT (slotToggled (bool)));

View file

@ -123,10 +123,8 @@ void CSVSettings::Dialog::show()
{ {
if (pages().isEmpty()) if (pages().isEmpty())
buildPages(); buildPages();
QPoint screenCenter = QApplication::desktop()->screenGeometry().center(); QPoint screenCenter = QApplication::desktop()->screenGeometry().center();
move (screenCenter - geometry().center()); move (screenCenter - geometry().center());
QWidget::show(); QWidget::show();
} }

View file

@ -60,8 +60,10 @@ void CSVSettings::Frame::showWidgets()
QWidget *widg = static_cast <QWidget *> (obj); QWidget *widg = static_cast <QWidget *> (obj);
if (widg->property("sizePolicy").isValid()) if (widg->property("sizePolicy").isValid())
{
widg->setSizePolicy widg->setSizePolicy
(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding); (QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
}
} }
layout()->activate(); layout()->activate();
setFixedSize(minimumSizeHint()); setFixedSize(minimumSizeHint());

View file

@ -7,6 +7,8 @@
#include "../../model/settings/usersettings.hpp" #include "../../model/settings/usersettings.hpp"
#include "../../model/settings/connector.hpp" #include "../../model/settings/connector.hpp"
#include "../../model/settings/support.hpp"
#include "settingwindow.hpp" #include "settingwindow.hpp"
QMap <CSVSettings::ViewType, CSVSettings::IViewFactory *> QMap <CSVSettings::ViewType, CSVSettings::IViewFactory *>

View file

@ -1,88 +1,129 @@
#include <QHBoxLayout> #include <QHBoxLayout>
#include <QVBoxLayout> #include <QVBoxLayout>
#include <QCheckBox>
#include <QRadioButton>
#include <QGroupBox> #include <QGroupBox>
#include <QSpinBox>
#include <QAbstractButton> #include <QDoubleSpinBox>
#include <QAbstractSpinBox>
#include "rangeview.hpp" #include "rangeview.hpp"
#include "spinbox.hpp"
#include "../../model/settings/setting.hpp" #include "../../model/settings/setting.hpp"
#include "../../model/settings/support.hpp"
#include <QDebug>
CSVSettings::RangeView::RangeView (CSMSettings::Setting *setting, CSVSettings::RangeView::RangeView (CSMSettings::Setting *setting,
Page *parent) Page *parent)
: View (setting, parent) : mRangeWidget (0), mRangeType (setting->type()), View (setting, parent)
{ {
foreach (const QString &value, setting->declaredValues())
{
QAbstractButton *button = 0;
if (isMultiValue()) mRangeWidget = 0;
button = new QCheckBox (value, this);
else
button = new QRadioButton (value, this);
connect (button, SIGNAL (clicked (bool)), if (isMultiValue())
this, SLOT (slotToggled (bool)));
button->setObjectName (value);
addWidget (button);
mButtons[value] = button;
}
}
void CSVSettings::RangeView::slotToggled (bool state)
{
//test only for true to avoid multiple selection updates with radiobuttons
if (!isMultiValue() && !state)
return; return;
QStringList values; buildSpinBox (setting);
foreach (QString key, mButtons.keys()) mRangeWidget->setFixedWidth (widgetWidth (setting->widgetWidth()));
mRangeWidget->setObjectName (setting->name());
addWidget (mRangeWidget);
}
void CSVSettings::RangeView::buildSpinBox (CSMSettings::Setting *setting)
{
SpinBox *sb = 0;
switch (setting->type())
{ {
if (mButtons.value(key)->isChecked()) case CSMSettings::Type_SpinBox:
values.append (key);
sb = new SpinBox (this);
if (!setting->declaredValues().isEmpty())
sb->setValueList (setting->declaredValues());
mRangeWidget = sb;
connect (mRangeWidget, SIGNAL (valueChanged (int)),
this, SLOT (slotUpdateView (int)));
break;
case CSMSettings::Type_DoubleSpinBox:
mRangeWidget = new QDoubleSpinBox (this);
connect (mRangeWidget, SIGNAL (valueChanged (double)),
this, SLOT (slotUpdateView (double)));
break;
default:
break;
} }
setSelectedValues (values, false);
//min / max values are set automatically in AlphaSpinBox
if (setting->declaredValues().isEmpty())
{
mRangeWidget->setProperty ("minimum", setting->minimum());
mRangeWidget->setProperty ("maximum", setting->maximum());
mRangeWidget->setProperty ("singleStep", setting->singleStep());
mRangeWidget->setProperty ("specialValueText",
setting->specialValueText());
}
mRangeWidget->setProperty ("prefix", setting->prefix());
mRangeWidget->setProperty ("suffix", setting->suffix());
mRangeWidget->setProperty ("wrapping", setting->wrapping());
}
void CSVSettings::RangeView::slotUpdateView (int value)
{
QString textValue = "";
if (mRangeType == CSMSettings::Type_SpinBox)
{
QStringList list =
static_cast <SpinBox *> (mRangeWidget)->valueList();
if (!list.isEmpty())
textValue = list.at(value);
}
if (textValue.isEmpty())
textValue = QVariant (value).toString();
setSelectedValue (textValue, false);
View::updateView();
}
void CSVSettings::RangeView::slotUpdateView (double value)
{
setSelectedValue (QVariant(value).toString(), false);
View::updateView(); View::updateView();
} }
void CSVSettings::RangeView::updateView (bool signalUpdate) const void CSVSettings::RangeView::updateView (bool signalUpdate) const
{ {
QString value;
QStringList values = selectedValues(); if (!selectedValues().isEmpty())
value = selectedValues().at(0);
foreach (const QString &buttonName, mButtons.keys()) switch (mRangeType)
{ {
QAbstractButton *button = mButtons[buttonName]; case CSMSettings::Type_SpinBox:
static_cast <SpinBox *> (mRangeWidget)->setValue (value);
break;
//if the value is not found in the list, the widget is checked false case CSMSettings::Type_DoubleSpinBox:
bool buttonValue = values.contains(buttonName); static_cast <QDoubleSpinBox *> (mRangeWidget)->setValue (value.toDouble());
break;
//skip if the butotn value will not change default:
if (button->isChecked() == buttonValue) break;
continue;
//disable autoexclusive if it's enabled and we're setting
//the button value to false
bool switchExclusive = (!buttonValue && button->autoExclusive());
if (switchExclusive)
button->setAutoExclusive (false);
button->setChecked (buttonValue);
if (switchExclusive)
button->setAutoExclusive(true);
} }
View::updateView (signalUpdate); View::updateView (signalUpdate);
} }

View file

@ -1,13 +1,11 @@
#ifndef CSVSETTINGS_RANGEVIEW_HPP #ifndef CSVSETTINGS_RANGEVIEW_HPP
#define CSVSETTINGS_RANGEVIEW_HPP #define CSVSETTINGS_RANGEVIEW_HPP
#include <QWidget>
#include <QAbstractButton>
#include "view.hpp" #include "view.hpp"
#include "../../model/settings/support.hpp" #include "../../model/settings/support.hpp"
class QStringListModel; class QStringListModel;
class QAbstractSpinBox;
namespace CSVSettings namespace CSVSettings
{ {
@ -15,7 +13,8 @@ namespace CSVSettings
{ {
Q_OBJECT Q_OBJECT
QMap <QString, QAbstractButton *> mButtons; QAbstractSpinBox *mRangeWidget;
CSMSettings::SettingType mRangeType;
public: public:
explicit RangeView (CSMSettings::Setting *setting, explicit RangeView (CSMSettings::Setting *setting,
@ -24,8 +23,13 @@ namespace CSVSettings
protected: protected:
void updateView (bool signalUpdate = true) const; void updateView (bool signalUpdate = true) const;
void buildSpinBox (CSMSettings::Setting *setting);
private slots: private slots:
void slotToggled (bool state);
void slotUpdateView (int value);
void slotUpdateView (double value);
}; };
class RangeViewFactory : public QObject, public IViewFactory class RangeViewFactory : public QObject, public IViewFactory

View file

@ -28,11 +28,6 @@ bool CSVSettings::TextView::isEquivalent
return (lhs.trimmed() == rhs.trimmed()); return (lhs.trimmed() == rhs.trimmed());
} }
void CSVSettings::TextView::setWidgetText (const QString &value) const
{
mTextWidget->setProperty ("text", value);
}
void CSVSettings::TextView::slotTextEdited (QString value) void CSVSettings::TextView::slotTextEdited (QString value)
{ {
QStringList values = value.split (mDelimiter, QString::SkipEmptyParts); QStringList values = value.split (mDelimiter, QString::SkipEmptyParts);
@ -51,19 +46,14 @@ void CSVSettings::TextView::updateView(bool signalUpdate) const
{ {
QString values = selectedValues().join (mDelimiter); QString values = selectedValues().join (mDelimiter);
if (isEquivalent (widgetText(), values)) if (isEquivalent (mTextWidget->property("text").toString(), values))
return; return;
setWidgetText (values); mTextWidget->setProperty("text", values);
View::updateView (signalUpdate); View::updateView (signalUpdate);
} }
QString CSVSettings::TextView::widgetText() const
{
return mTextWidget->property("text").toString();
}
CSVSettings::TextView *CSVSettings::TextViewFactory::createView CSVSettings::TextView *CSVSettings::TextViewFactory::createView
(CSMSettings::Setting *setting, (CSMSettings::Setting *setting,
Page *parent) Page *parent)

View file

@ -32,12 +32,6 @@ namespace CSVSettings
///Comparison function that returns true if the trimmed() strings ///Comparison function that returns true if the trimmed() strings
///are equal ///are equal
bool isEquivalent (const QString &lhs, const QString &rhs) const; bool isEquivalent (const QString &lhs, const QString &rhs) const;
///Convenience function to return the text of the widget
QString widgetText() const;
///Convenience function to set the text of the widget
void setWidgetText (const QString &value) const;
}; };
class TextViewFactory : public QObject, public IViewFactory class TextViewFactory : public QObject, public IViewFactory

View file

@ -192,6 +192,7 @@ bool CSVSettings::View::stringListsMatch (
QList <QStandardItem *> CSVSettings::View::toStandardItemList QList <QStandardItem *> CSVSettings::View::toStandardItemList
(const QStringList &list) const (const QStringList &list) const
{ {
QList <QStandardItem *> itemList; QList <QStandardItem *> itemList;
foreach (const QString &value, list) foreach (const QString &value, list)

View file

@ -101,7 +101,7 @@ namespace CSVSettings
void showEvent ( QShowEvent * event ); void showEvent ( QShowEvent * event );
///Virtual for updating a specific View subclass ///Virtual for updating a specific View subclass
///bool indicates whether a signal is emitted that the view was updated ///bool indicates whether viewUpdated() signal is emitted
virtual void updateView (bool signalUpdate = true) const; virtual void updateView (bool signalUpdate = true) const;
///Returns the pixel width corresponding to the specified number of ///Returns the pixel width corresponding to the specified number of