Merge remote-tracking branch 'graffy76/master'

openmw-30
Marc Zinnschlag 11 years ago
commit e43913e7c2

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

@ -1,13 +1,8 @@
#include "setting.hpp"
#include "support.hpp"
CSMSettings::Setting::Setting()
{
buildDefaultSetting();
}
CSMSettings::Setting::Setting(SettingType typ, const QString &settingName,
const QString &pageName, const QStringList &values)
const QString &pageName)
: mIsEditorSetting (false)
{
buildDefaultSetting();
@ -19,10 +14,9 @@ CSMSettings::Setting::Setting(SettingType typ, const QString &settingName,
setProperty (Property_IsMultiValue, QVariant(true).toString());
//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_Name, settingName);
setProperty (Property_DeclaredValues, values);
}
void CSMSettings::Setting::buildDefaultSetting()
@ -73,6 +67,11 @@ int CSMSettings::Setting::columnSpan() const
return property (Property_ColumnSpan).at(0).toInt();
}
void CSMSettings::Setting::setDeclaredValues (QStringList list)
{
setProperty (Property_DeclaredValues, list);
}
QStringList CSMSettings::Setting::declaredValues() const
{
return property (Property_DeclaredValues);
@ -96,6 +95,16 @@ QStringList CSMSettings::Setting::property (SettingProperty prop) const
return mProperties.at(prop);
}
void CSMSettings::Setting::setDefaultValue (int value)
{
setDefaultValues (QStringList() << QVariant (value).toString());
}
void CSMSettings::Setting::setDefaultValue (double value)
{
setDefaultValues (QStringList() << QVariant (value).toString());
}
void CSMSettings::Setting::setDefaultValue (const QString &value)
{
setDefaultValues (QStringList() << value);
@ -165,6 +174,16 @@ bool CSMSettings::Setting::serializable() const
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)
{
setProperty (Property_Name, value);
@ -185,6 +204,16 @@ QString CSMSettings::Setting::page() const
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)
{
setProperty (Property_RowSpan, value);
@ -195,15 +224,106 @@ int CSMSettings::Setting::rowSpan () const
return property (Property_RowSpan).at(0).toInt();
}
void CSMSettings::Setting::setViewType (int vType)
void CSMSettings::Setting::setSingleStep (int value)
{
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::setTickInterval (int value)
{
setProperty (Property_TickInterval, value);
}
int CSMSettings::Setting::tickInterval () const
{
return property (Property_TickInterval).at(0).toInt();
}
void CSMSettings::Setting::setTicksAbove (bool state)
{
setProperty (Property_TicksAbove, state);
}
bool CSMSettings::Setting::ticksAbove() const
{
setProperty (Property_ViewType, vType);
return (property (Property_TicksAbove).at(0) == "true");
}
void CSMSettings::Setting::setTicksBelow (bool state)
{
setProperty (Property_TicksBelow, state);
}
bool CSMSettings::Setting::ticksBelow() const
{
return (property (Property_TicksBelow).at(0) == "true");
}
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
{
return static_cast <CSVSettings::ViewType>
(property(Property_ViewType).at(0).toInt());
return static_cast <CSVSettings::ViewType> ( property (
Property_SettingType).at(0).toInt() / 10);
}
void CSMSettings::Setting::setViewColumn (int value)
@ -241,6 +361,17 @@ int CSMSettings::Setting::widgetWidth() const
{
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)
{
setProperty (prop, QStringList() << QVariant (value).toString());
@ -251,6 +382,11 @@ void CSMSettings::Setting::setProperty (SettingProperty prop, int value)
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,
const QString &value)
{
@ -263,18 +399,3 @@ void CSMSettings::Setting::setProperty (SettingProperty prop,
if (prop < mProperties.size())
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;
}

@ -27,12 +27,8 @@ namespace CSMSettings
public:
explicit Setting();
explicit Setting(SettingType typ, const QString &settingName,
const QString &pageName,
const QStringList &values = QStringList());
const QString &pageName);
void addProxy (const Setting *setting, const QStringList &vals);
void addProxy (const Setting *setting, const QList <QStringList> &list);
@ -49,6 +45,8 @@ namespace CSMSettings
void setDefinedValues (QStringList list);
QStringList definedValues() const;
void setDefaultValue (int value);
void setDefaultValue (double value);
void setDefaultValue (const QString &value);
void setDefaultValues (const QStringList &values);
@ -66,12 +64,26 @@ namespace CSMSettings
void setIsMultiValue (bool state);
bool isMultiValue() const;
void setMask (const QString &value);
QString mask() const;
void setMaximum (int value);
void setMaximum (double value);
QString maximum() const;
void setMinimum (int value);
void setMinimum (double value);
QString minimum() const;
void setName (const QString &value);
QString name() const;
void setPage (const QString &value);
QString page() const;
void setPrefix (const QString &value);
QString prefix() const;
void setRowSpan (const int value);
int rowSpan() const;
@ -80,6 +92,25 @@ namespace CSMSettings
void setSerializable (bool state);
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 setTickInterval (int value);
int tickInterval() const;
void setTicksAbove (bool state);
bool ticksAbove() const;
void setTicksBelow (bool state);
bool ticksBelow() const;
void setViewColumn (int value);
int viewColumn() const;
@ -88,9 +119,14 @@ namespace CSMSettings
void setViewRow (int value);
int viewRow() const;
void setViewType (int vType);
void setType (int settingType);
CSMSettings::SettingType type() const;
CSVSettings::ViewType viewType() const;
void setWrapping (bool state);
bool wrapping() const;
void setWidgetWidth (int value);
int widgetWidth() const;
@ -100,6 +136,7 @@ namespace CSMSettings
///boilerplate code to convert setting values of common types
void setProperty (SettingProperty prop, bool 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 QStringList &value);
@ -111,9 +148,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

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

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

@ -27,7 +27,7 @@ namespace CSMSettings
{
Property_Name = 0,
Property_Page = 1,
Property_ViewType = 2,
Property_SettingType = 2,
Property_IsMultiValue = 3,
Property_IsMultiLine = 4,
Property_WidgetWidth = 5,
@ -37,12 +37,22 @@ namespace CSMSettings
Property_Serializable = 9,
Property_ColumnSpan = 10,
Property_RowSpan = 11,
Property_Minimum = 12,
Property_Maximum = 13,
Property_SpecialValueText = 14,
Property_Prefix = 15,
Property_Suffix = 16,
Property_SingleStep = 17,
Property_Wrapping = 18,
Property_TickInterval = 19,
Property_TicksAbove = 20,
Property_TicksBelow = 21,
//Stringlists should always be the last items
Property_DefaultValues = 12,
Property_DeclaredValues = 13,
Property_DefinedValues = 14,
Property_Proxies = 15
Property_DefaultValues = 22,
Property_DeclaredValues = 23,
Property_DefinedValues = 24,
Property_Proxies = 25
};
enum SettingType
@ -64,10 +74,12 @@ namespace CSMSettings
Type_ListView = 10,
Type_ComboBox = 11,
Type_SpinBox = 21,
Type_Slider = 23,
Type_Dial = 24,
Type_DoubleSpinBox = 23,
Type_Slider = 25,
Type_Dial = 27,
Type_TextArea = 30,
Type_LineEdit = 31
Type_LineEdit = 31,
Type_Undefined = 40
};
enum MergeMethod
@ -97,7 +109,7 @@ namespace CSVSettings
};
}
//
namespace CSMSettings
{
struct PropertyDefaultValues
@ -109,9 +121,11 @@ namespace CSMSettings
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_serializable","column_span", "row_span",
"is_serializable","column_span", "row_span", "minimum", "maximum",
"special_value_text", "prefix", "suffix", "single_step", "wrapping",
"tick_interval", "ticks_above", "ticks_below",
"defaults", "declarations", "definitions", "proxies"
};
@ -119,16 +133,26 @@ namespace CSMSettings
{
"", //name
"", //page
"0", //view type
"40", //setting type
"false", //multivalue
"false", //multiline
"0", //widget width
"7", //widget width
"-1", //view row
"-1", //view column
",", //delimiter
"true", //serialized
"1", //column span
"1", //row span
"0", //value range
"0", //value minimum
"0", //value maximum
"", //special text
"", //prefix
"", //suffix
"false", //wrapping
"1", //tick interval
"false", //ticks above
"true", //ticks below
"", //default values
"", //declared values
"", //defined values

@ -51,7 +51,7 @@ void CSMSettings::UserSettings::buildSettingModelDefaults()
Setting *height = createSetting (Type_LineEdit, section, "Height");
width->setWidgetWidth (5);
height->setWidgetWidth (5);
height->setWidgetWidth (8);
width->setDefaultValues (QStringList() << "1024");
height->setDefaultValues (QStringList() << "768");
@ -66,13 +66,10 @@ void CSMSettings::UserSettings::buildSettingModelDefaults()
*Create the proxy setting for predefined values
*/
Setting *preDefined = createSetting (Type_ComboBox, section,
"Pre-Defined",
QStringList()
<< "640 x 480"
<< "800 x 600"
<< "1024 x 768"
<< "1440 x 900"
);
"Pre-Defined");
preDefined->setDeclaredValues (QStringList() << "640 x 480"
<< "800 x 600" << "1024 x 768" << "1440 x 900");
preDefined->setViewLocation (1, 1);
preDefined->setWidgetWidth (10);
@ -95,12 +92,13 @@ void CSMSettings::UserSettings::buildSettingModelDefaults()
<< defaultValue << "Icon Only" << "Text Only";
Setting *rsd = createSetting (Type_RadioButton,
section, "Record Status Display",
values);
section, "Record Status Display");
Setting *ritd = createSetting (Type_RadioButton,
section, "Referenceable ID Type Display",
values);
section, "Referenceable ID Type Display");
rsd->setDeclaredValues (values);
ritd->setDeclaredValues (values);
rsd->setEditorSetting (true);
ritd->setEditorSetting (true);
@ -108,44 +106,67 @@ void CSMSettings::UserSettings::buildSettingModelDefaults()
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,
"Master Proxy",
QStringList()
<< "Profile One" << "Profile Two"
<< "Profile Three" << "Profile Four"
);
"Master Proxy");
Setting *slaveBoolean = createSetting (Type_CheckBox, section,
"Proxy Checkboxes",
QStringList() << "One" << "Two"
<< "Three" << "Four" << "Five"
);
"Proxy Checkboxes");
Setting *slaveSingleText = createSetting (Type_LineEdit, section,
"Proxy TextBox 1"
);
"Proxy TextBox 1");
Setting *slaveMultiText = createSetting (Type_LineEdit, section,
"ProxyTextBox 2"
);
// 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.
"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");
Setting *slaveSlider = createSetting (Type_Slider, section, "Slider");
Setting *slaveDial = createSetting (Type_Dial, section, "Dial");
//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");
masterBoolean->addProxy (slaveBoolean, QList <QStringList>()
<< (QStringList() << "One" << "Three")
@ -168,11 +189,47 @@ void CSMSettings::UserSettings::buildSettingModelDefaults()
<< (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"));
masterBoolean->addProxy (slaveSlider, QList <QStringList> ()
<< (QStringList() << "25")
<< (QStringList() << "50")
<< (QStringList() << "75")
<< (QStringList() << "100")
);
masterBoolean->addProxy (slaveDial, QList <QStringList> ()
<< (QStringList() << "25")
<< (QStringList() << "50")
<< (QStringList() << "75")
<< (QStringList() << "100")
);
//settings with proxies are not serialized by default
//other settings non-serialized for demo purposes
slaveBoolean->setSerializable (false);
slaveSingleText->setSerializable (false);
slaveMultiText->setSerializable (false);
slaveAlphaSpinbox->setSerializable (false);
slaveIntegerSpinbox->setSerializable (false);
slaveDoubleSpinbox->setSerializable (false);
slaveSlider->setSerializable (false);
slaveBoolean->setDefaultValues (QStringList()
<< "One" << "Three" << "Five");
@ -184,7 +241,39 @@ void CSMSettings::UserSettings::buildSettingModelDefaults()
slaveSingleText->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);
slaveSlider->setMinimum (0);
slaveSlider->setMaximum (100);
slaveSlider->setDefaultValue (75);
slaveSlider->setWidgetWidth (100);
slaveSlider->setTicksAbove (true);
slaveSlider->setTickInterval (25);
slaveDial->setMinimum (0);
slaveDial->setMaximum (100);
slaveDial->setSingleStep (5);
slaveDial->setDefaultValue (75);
slaveDial->setTickInterval (25);
*/
}
}
CSMSettings::UserSettings::~UserSettings()

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

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

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

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

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

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

@ -0,0 +1,51 @@
#include "spinbox.hpp"
#include <QSpinBox>
#include <QLineEdit>
CSVSettings::SpinBox::SpinBox(QWidget *parent)
: mValueList(QStringList()), QSpinBox(parent)
{
setRange (0, 0);
}
QString CSVSettings::SpinBox::textFromValue(int val) const
{
if (mValueList.isEmpty())
return QVariant (val).toString();
QString value = "";
if (val < mValueList.size())
value = mValueList.at (val);
return value;
}
int CSVSettings::SpinBox::valueFromText(const QString &text) const
{
if (mValueList.isEmpty())
return -1;
if (mValueList.contains (text))
return mValueList.indexOf(text);
return -1;
}
void CSVSettings::SpinBox::setValue (const QString &value)
{
if (!mValueList.isEmpty())
{
lineEdit()->setText (value);
QSpinBox::setValue(valueFromText(value));
}
else
QSpinBox::setValue (value.toInt());
}
void CSVSettings::SpinBox::setValueList (const QStringList &list)
{
mValueList = list;
setMaximum (list.size() - 1);
}

@ -0,0 +1,31 @@
#ifndef CSVSETTINGS_SPINBOX_HPP
#define CSVSETTINGS_SPINBOX_HPP
#include <QObject>
#include <QStringList>
#include <QSpinBox>
namespace CSVSettings
{
class SpinBox : public QSpinBox
{
Q_OBJECT
QStringList mValueList;
public:
explicit SpinBox(QWidget *parent = 0);
void setObjectName (const QString &name);
void setValue (const QString &value);
void setValueList (const QStringList &list);
const QStringList &valueList() const { return mValueList; }
protected:
QString textFromValue (int val) const;
int valueFromText (const QString &text) const;
};
}
#endif // CSVSETTINGS_SPINBOX_HPP

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

@ -32,12 +32,6 @@ namespace CSVSettings
///Comparison function that returns true if the trimmed() strings
///are equal
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

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

@ -101,7 +101,7 @@ namespace CSVSettings
void showEvent ( QShowEvent * event );
///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;
///Returns the pixel width corresponding to the specified number of

Loading…
Cancel
Save