removed old user settings system
parent
67cf260144
commit
c646533448
@ -1,128 +0,0 @@
|
||||
#include "connector.hpp"
|
||||
#include "../../view/settings/view.hpp"
|
||||
#include "../../view/settings/page.hpp"
|
||||
|
||||
CSMSettings::Connector::Connector(CSVSettings::View *master,
|
||||
QObject *parent)
|
||||
: QObject(parent), mMasterView (master)
|
||||
{}
|
||||
|
||||
void CSMSettings::Connector::addSlaveView (CSVSettings::View *view,
|
||||
QList <QStringList> &masterProxyValues)
|
||||
{
|
||||
mSlaveViews.append (view);
|
||||
|
||||
mProxyListMap[view->viewKey()].append (masterProxyValues);
|
||||
}
|
||||
|
||||
QList <QStringList> CSMSettings::Connector::getSlaveViewValues() const
|
||||
{
|
||||
QList <QStringList> list;
|
||||
|
||||
foreach (const CSVSettings::View *view, mSlaveViews)
|
||||
list.append (view->selectedValues());
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
bool CSMSettings::Connector::proxyListsMatch (
|
||||
const QList <QStringList> &list1,
|
||||
const QList <QStringList> &list2) const
|
||||
{
|
||||
bool success = true;
|
||||
|
||||
for (int i = 0; i < list1.size(); i++)
|
||||
{
|
||||
success = stringListsMatch (list1.at(i), list2.at(i));
|
||||
|
||||
if (!success)
|
||||
break;
|
||||
}
|
||||
return success;
|
||||
}
|
||||
|
||||
void CSMSettings::Connector::slotUpdateMaster() const
|
||||
{
|
||||
//list of the current values for each slave.
|
||||
QList <QStringList> slaveValueList = getSlaveViewValues();
|
||||
|
||||
int masterColumn = -1;
|
||||
|
||||
/*
|
||||
* A row in the master view is one of the values in the
|
||||
* master view's data model. This corresponds directly to the number of
|
||||
* values in a proxy list contained in the ProxyListMap member.
|
||||
* Thus, we iterate each "column" in the master proxy list
|
||||
* (one for each vlaue in the master. Each column represents
|
||||
* one master value's corresponding list of slave values. We examine
|
||||
* each master value's list, comparing it to the current slave value list,
|
||||
* stopping when we find a match using proxyListsMatch().
|
||||
*
|
||||
* If no match is found, clear the master view's value
|
||||
*/
|
||||
|
||||
for (int i = 0; i < mMasterView->rowCount(); i++)
|
||||
{
|
||||
QList <QStringList> proxyValueList;
|
||||
|
||||
foreach (const QString &settingKey, mProxyListMap.keys())
|
||||
{
|
||||
// append the proxy value list stored in the i'th column
|
||||
// for each setting key. A setting key is the id of the setting
|
||||
// in page.name format.
|
||||
proxyValueList.append (mProxyListMap.value(settingKey).at(i));
|
||||
}
|
||||
|
||||
if (proxyListsMatch (slaveValueList, proxyValueList))
|
||||
{
|
||||
masterColumn = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
QString masterValue = mMasterView->value (masterColumn);
|
||||
|
||||
mMasterView->setSelectedValue (masterValue);
|
||||
}
|
||||
|
||||
void CSMSettings::Connector::slotUpdateSlaves() const
|
||||
{
|
||||
int row = mMasterView->currentIndex();
|
||||
|
||||
if (row == -1)
|
||||
return;
|
||||
|
||||
//iterate the proxy lists for the chosen master index
|
||||
//and pass the list to each slave for updating
|
||||
for (int i = 0; i < mSlaveViews.size(); i++)
|
||||
{
|
||||
QList <QStringList> proxyList =
|
||||
mProxyListMap.value(mSlaveViews.at(i)->viewKey());
|
||||
|
||||
mSlaveViews.at(i)->setSelectedValues (proxyList.at(row));
|
||||
}
|
||||
}
|
||||
|
||||
bool CSMSettings::Connector::stringListsMatch (
|
||||
const QStringList &list1,
|
||||
const QStringList &list2) const
|
||||
{
|
||||
//returns a "sloppy" match, verifying that each list contains all the same
|
||||
//items, though not necessarily in the same order.
|
||||
|
||||
if (list1.size() != list2.size())
|
||||
return false;
|
||||
|
||||
QStringList tempList(list2);
|
||||
|
||||
//iterate each value in the list, removing one occurrence of the value in
|
||||
//the other list. If no corresponding value is found, test fails
|
||||
foreach (const QString &value, list1)
|
||||
{
|
||||
if (!tempList.contains(value))
|
||||
return false;
|
||||
|
||||
tempList.removeOne(value);
|
||||
}
|
||||
return true;
|
||||
}
|
@ -1,67 +0,0 @@
|
||||
#ifndef CSMSETTINGS_CONNECTOR_HPP
|
||||
#define CSMSETTINGS_CONNECTOR_HPP
|
||||
|
||||
#include <QObject>
|
||||
#include <QList>
|
||||
#include <QMap>
|
||||
#include <QStringList>
|
||||
|
||||
#include "support.hpp"
|
||||
|
||||
namespace CSVSettings {
|
||||
class View;
|
||||
}
|
||||
|
||||
namespace CSMSettings {
|
||||
|
||||
class Connector : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
CSVSettings::View *mMasterView;
|
||||
|
||||
///map using the view pointer as a key to it's index value
|
||||
QList <CSVSettings::View *> mSlaveViews;
|
||||
|
||||
///list of proxy values for each master value.
|
||||
///value list order is indexed to the master value index.
|
||||
QMap < QString, QList <QStringList> > mProxyListMap;
|
||||
|
||||
public:
|
||||
explicit Connector(CSVSettings::View *master,
|
||||
QObject *parent = 0);
|
||||
|
||||
///Set the view which acts as a proxy for other setting views
|
||||
void setMasterView (CSVSettings::View *view);
|
||||
|
||||
///Add a view to be updated / update to the master
|
||||
void addSlaveView (CSVSettings::View *view,
|
||||
QList <QStringList> &masterProxyValues);
|
||||
|
||||
private:
|
||||
|
||||
///loosely matches lists of proxy values across registered slaves
|
||||
///against a proxy value list for a given master value
|
||||
bool proxyListsMatch (const QList <QStringList> &list1,
|
||||
const QList <QStringList> &list2) const;
|
||||
|
||||
///loosely matches two string lists
|
||||
bool stringListsMatch (const QStringList &list1,
|
||||
const QStringList &list2) const;
|
||||
|
||||
///retrieves current values of registered slave views
|
||||
QList <QStringList> getSlaveViewValues() const;
|
||||
|
||||
public slots:
|
||||
|
||||
///updates slave views with proxy values associated with current
|
||||
///master value
|
||||
void slotUpdateSlaves() const;
|
||||
|
||||
///updates master value associated with the currently selected
|
||||
///slave values, if applicable.
|
||||
void slotUpdateMaster() const;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // CSMSETTINGS_CONNECTOR_HPP
|
@ -1,414 +0,0 @@
|
||||
#include "setting.hpp"
|
||||
#include "support.hpp"
|
||||
|
||||
CSMSettings::Setting::Setting(SettingType typ, const QString &settingName,
|
||||
const QString &pageName, const QString& label)
|
||||
: mIsEditorSetting (true)
|
||||
{
|
||||
buildDefaultSetting();
|
||||
|
||||
int settingType = static_cast <int> (typ);
|
||||
|
||||
//even-numbered setting types are multi-valued
|
||||
if ((settingType % 2) == 0)
|
||||
setProperty (Property_IsMultiValue, QVariant(true).toString());
|
||||
|
||||
//view type is related to setting type by an order of magnitude
|
||||
setProperty (Property_SettingType, QVariant (settingType).toString());
|
||||
setProperty (Property_Page, pageName);
|
||||
setProperty (Property_Name, settingName);
|
||||
setProperty (Property_Label, label.isEmpty() ? settingName : label);
|
||||
}
|
||||
|
||||
void CSMSettings::Setting::buildDefaultSetting()
|
||||
{
|
||||
int arrLen = sizeof(sPropertyDefaults) / sizeof (*sPropertyDefaults);
|
||||
|
||||
for (int i = 0; i < arrLen; i++)
|
||||
{
|
||||
QStringList propertyList;
|
||||
|
||||
if (i <Property_DefaultValues)
|
||||
propertyList.append (sPropertyDefaults[i]);
|
||||
|
||||
mProperties.append (propertyList);
|
||||
}
|
||||
}
|
||||
|
||||
void CSMSettings::Setting::addProxy (const Setting *setting,
|
||||
const QStringList &vals)
|
||||
{
|
||||
if (serializable())
|
||||
setSerializable (false);
|
||||
|
||||
QList <QStringList> list;
|
||||
|
||||
foreach (const QString &val, vals)
|
||||
list << (QStringList() << val);
|
||||
|
||||
mProxies [setting->page() + '/' + setting->name()] = list;
|
||||
}
|
||||
|
||||
void CSMSettings::Setting::addProxy (const Setting *setting,
|
||||
const QList <QStringList> &list)
|
||||
{
|
||||
if (serializable())
|
||||
setProperty (Property_Serializable, false);
|
||||
|
||||
mProxies [setting->page() + '/' + setting->name()] = list;
|
||||
}
|
||||
|
||||
void CSMSettings::Setting::setColumnSpan (int value)
|
||||
{
|
||||
setProperty (Property_ColumnSpan, value);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
QStringList CSMSettings::Setting::property (SettingProperty prop) const
|
||||
{
|
||||
if (prop >= mProperties.size())
|
||||
return QStringList();
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
void CSMSettings::Setting::setDefaultValues (const QStringList &values)
|
||||
{
|
||||
setProperty (Property_DefaultValues, values);
|
||||
}
|
||||
|
||||
QStringList CSMSettings::Setting::defaultValues() const
|
||||
{
|
||||
return property (Property_DefaultValues);
|
||||
}
|
||||
|
||||
void CSMSettings::Setting::setDelimiter (const QString &value)
|
||||
{
|
||||
setProperty (Property_Delimiter, value);
|
||||
}
|
||||
|
||||
QString CSMSettings::Setting::delimiter() const
|
||||
{
|
||||
return property (Property_Delimiter).at(0);
|
||||
}
|
||||
|
||||
void CSMSettings::Setting::setEditorSetting(bool state)
|
||||
{
|
||||
mIsEditorSetting = true;
|
||||
}
|
||||
|
||||
bool CSMSettings::Setting::isEditorSetting() const
|
||||
{
|
||||
return mIsEditorSetting;
|
||||
}
|
||||
void CSMSettings::Setting::setIsMultiLine (bool state)
|
||||
{
|
||||
setProperty (Property_IsMultiLine, state);
|
||||
}
|
||||
|
||||
bool CSMSettings::Setting::isMultiLine() const
|
||||
{
|
||||
return (property (Property_IsMultiLine).at(0) == "true");
|
||||
}
|
||||
|
||||
void CSMSettings::Setting::setIsMultiValue (bool state)
|
||||
{
|
||||
setProperty (Property_IsMultiValue, state);
|
||||
}
|
||||
|
||||
bool CSMSettings::Setting::isMultiValue() const
|
||||
{
|
||||
return (property (Property_IsMultiValue).at(0) == "true");
|
||||
}
|
||||
|
||||
const CSMSettings::ProxyValueMap &CSMSettings::Setting::proxyLists() const
|
||||
{
|
||||
return mProxies;
|
||||
}
|
||||
|
||||
void CSMSettings::Setting::setSerializable (bool state)
|
||||
{
|
||||
setProperty (Property_Serializable, state);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
QString CSMSettings::Setting::name() const
|
||||
{
|
||||
return property (Property_Name).at(0);
|
||||
}
|
||||
|
||||
void CSMSettings::Setting::setPage (const QString &value)
|
||||
{
|
||||
setProperty (Property_Page, value);
|
||||
}
|
||||
|
||||
QString CSMSettings::Setting::page() const
|
||||
{
|
||||
return property (Property_Page).at(0);
|
||||
}
|
||||
|
||||
void CSMSettings::Setting::setStyleSheet (const QString &value)
|
||||
{
|
||||
setProperty (Property_StyleSheet, value);
|
||||
}
|
||||
|
||||
QString CSMSettings::Setting::styleSheet() const
|
||||
{
|
||||
return property (Property_StyleSheet).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);
|
||||
}
|
||||
|
||||
int CSMSettings::Setting::rowSpan () const
|
||||
{
|
||||
return property (Property_RowSpan).at(0).toInt();
|
||||
}
|
||||
|
||||
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
|
||||
{
|
||||
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::setRange (int min, int max)
|
||||
{
|
||||
setProperty (Property_Minimum, min);
|
||||
setProperty (Property_Maximum, max);
|
||||
}
|
||||
|
||||
void CSMSettings::Setting::setRange (double min, double max)
|
||||
{
|
||||
setProperty (Property_Minimum, min);
|
||||
setProperty (Property_Maximum, max);
|
||||
}
|
||||
|
||||
QString CSMSettings::Setting::maximum() const
|
||||
{
|
||||
return property (Property_Maximum).at(0);
|
||||
}
|
||||
|
||||
QString CSMSettings::Setting::minimum() const
|
||||
{
|
||||
return property (Property_Minimum).at(0);
|
||||
}
|
||||
|
||||
CSVSettings::ViewType CSMSettings::Setting::viewType() const
|
||||
{
|
||||
return static_cast <CSVSettings::ViewType> ( property (
|
||||
Property_SettingType).at(0).toInt() / 10);
|
||||
}
|
||||
|
||||
void CSMSettings::Setting::setViewColumn (int value)
|
||||
{
|
||||
setProperty (Property_ViewColumn, value);
|
||||
}
|
||||
|
||||
int CSMSettings::Setting::viewColumn() const
|
||||
{
|
||||
return property (Property_ViewColumn).at(0).toInt();
|
||||
}
|
||||
|
||||
void CSMSettings::Setting::setViewLocation (int row, int column)
|
||||
{
|
||||
setViewRow (row);
|
||||
setViewColumn (column);
|
||||
}
|
||||
|
||||
void CSMSettings::Setting::setViewRow (int value)
|
||||
{
|
||||
setProperty (Property_ViewRow, value);
|
||||
}
|
||||
|
||||
int CSMSettings::Setting::viewRow() const
|
||||
{
|
||||
return property (Property_ViewRow).at(0).toInt();
|
||||
}
|
||||
|
||||
void CSMSettings::Setting::setWidgetWidth (int value)
|
||||
{
|
||||
setProperty (Property_WidgetWidth, value);
|
||||
}
|
||||
|
||||
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::setLabel (const QString& label)
|
||||
{
|
||||
setProperty (Property_Label, label);
|
||||
}
|
||||
|
||||
QString CSMSettings::Setting::getLabel() const
|
||||
{
|
||||
return property (Property_Label).at (0);
|
||||
}
|
||||
|
||||
void CSMSettings::Setting::setToolTip (const QString& toolTip)
|
||||
{
|
||||
setProperty (Property_ToolTip, toolTip);
|
||||
}
|
||||
|
||||
QString CSMSettings::Setting::getToolTip() const
|
||||
{
|
||||
return property (Property_ToolTip).at (0);
|
||||
}
|
||||
|
||||
void CSMSettings::Setting::setProperty (SettingProperty prop, bool value)
|
||||
{
|
||||
setProperty (prop, QStringList() << QVariant (value).toString());
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
setProperty (prop, QStringList() << value);
|
||||
}
|
||||
|
||||
void CSMSettings::Setting::setProperty (SettingProperty prop,
|
||||
const QStringList &value)
|
||||
{
|
||||
if (prop < mProperties.size())
|
||||
mProperties.replace (prop, value);
|
||||
}
|
@ -1,159 +0,0 @@
|
||||
#ifndef CSMSETTINGS_SETTING_HPP
|
||||
#define CSMSETTINGS_SETTING_HPP
|
||||
|
||||
#include <QStringList>
|
||||
#include <QMap>
|
||||
#include "support.hpp"
|
||||
|
||||
namespace CSMSettings
|
||||
{
|
||||
//QString is the setting id in the form of "page/name"
|
||||
//QList is a list of stringlists of proxy values.
|
||||
//Order is important! Proxy stringlists are matched against
|
||||
//master values by their position in the QList.
|
||||
typedef QMap <QString, QList <QStringList> > ProxyValueMap;
|
||||
|
||||
///Setting class is the interface for the User Settings. It contains
|
||||
///a great deal of boiler plate to provide the core API functions, as
|
||||
///well as the property() functions which use enumeration to be iterable.
|
||||
///This makes the Setting class capable of being manipulated by script.
|
||||
///See CSMSettings::support.hpp for enumerations / string values.
|
||||
class Setting
|
||||
{
|
||||
QList <QStringList> mProperties;
|
||||
QStringList mDefaults;
|
||||
|
||||
bool mIsEditorSetting;
|
||||
|
||||
ProxyValueMap mProxies;
|
||||
|
||||
public:
|
||||
|
||||
Setting(SettingType typ, const QString &settingName,
|
||||
const QString &pageName, const QString& label = "");
|
||||
|
||||
void addProxy (const Setting *setting, const QStringList &vals);
|
||||
void addProxy (const Setting *setting, const QList <QStringList> &list);
|
||||
|
||||
const QList <QStringList> &properties() const { return mProperties; }
|
||||
const ProxyValueMap &proxies() const { return mProxies; }
|
||||
|
||||
void setColumnSpan (int value);
|
||||
int columnSpan() const;
|
||||
|
||||
void setDeclaredValues (QStringList list);
|
||||
QStringList declaredValues() const;
|
||||
|
||||
void setDefaultValue (int value);
|
||||
void setDefaultValue (double value);
|
||||
void setDefaultValue (const QString &value);
|
||||
|
||||
void setDefaultValues (const QStringList &values);
|
||||
QStringList defaultValues() const;
|
||||
|
||||
void setDelimiter (const QString &value);
|
||||
QString delimiter() const;
|
||||
|
||||
void setEditorSetting (bool state);
|
||||
bool isEditorSetting() const;
|
||||
|
||||
void setIsMultiLine (bool state);
|
||||
bool isMultiLine() const;
|
||||
|
||||
void setIsMultiValue (bool state);
|
||||
bool isMultiValue() const;
|
||||
|
||||
void setMask (const QString &value);
|
||||
QString mask() const;
|
||||
|
||||
void setRange (int min, int max);
|
||||
void setRange (double min, double max);
|
||||
|
||||
QString maximum() const;
|
||||
|
||||
QString minimum() const;
|
||||
|
||||
void setName (const QString &value);
|
||||
QString name() const;
|
||||
|
||||
void setPage (const QString &value);
|
||||
QString page() const;
|
||||
|
||||
void setStyleSheet (const QString &value);
|
||||
QString styleSheet() const;
|
||||
|
||||
void setPrefix (const QString &value);
|
||||
QString prefix() const;
|
||||
|
||||
void setRowSpan (const int value);
|
||||
int rowSpan() const;
|
||||
|
||||
const ProxyValueMap &proxyLists() const;
|
||||
|
||||
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;
|
||||
|
||||
void setViewLocation (int row = -1, int column = -1);
|
||||
|
||||
void setViewRow (int value);
|
||||
int viewRow() const;
|
||||
|
||||
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;
|
||||
|
||||
/// This is the text the user gets to see.
|
||||
void setLabel (const QString& label);
|
||||
QString getLabel() const;
|
||||
|
||||
void setToolTip (const QString& toolTip);
|
||||
QString getToolTip() const;
|
||||
|
||||
///returns the specified property value
|
||||
QStringList property (SettingProperty prop) const;
|
||||
|
||||
///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);
|
||||
|
||||
void addProxy (Setting* setting,
|
||||
QMap <QString, QStringList> &proxyMap);
|
||||
|
||||
protected:
|
||||
void buildDefaultSetting();
|
||||
};
|
||||
}
|
||||
|
||||
#endif // CSMSETTINGS_SETTING_HPP
|
@ -1,149 +0,0 @@
|
||||
#ifndef SETTING_SUPPORT_HPP
|
||||
#define SETTING_SUPPORT_HPP
|
||||
|
||||
#include <Qt>
|
||||
#include <QPair>
|
||||
#include <QList>
|
||||
#include <QVariant>
|
||||
#include <QStringList>
|
||||
|
||||
//Enums
|
||||
namespace CSMSettings
|
||||
{
|
||||
///Enumerated properties for scripting
|
||||
enum SettingProperty
|
||||
{
|
||||
Property_Name = 0,
|
||||
Property_Page = 1,
|
||||
Property_SettingType = 2,
|
||||
Property_IsMultiValue = 3,
|
||||
Property_IsMultiLine = 4,
|
||||
Property_WidgetWidth = 5,
|
||||
Property_ViewRow = 6,
|
||||
Property_ViewColumn = 7,
|
||||
Property_Delimiter = 8,
|
||||
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,
|
||||
Property_StyleSheet = 22,
|
||||
Property_Label = 23,
|
||||
Property_ToolTip = 24,
|
||||
|
||||
//Stringlists should always be the last items
|
||||
Property_DefaultValues = 25,
|
||||
Property_DeclaredValues = 26,
|
||||
Property_DefinedValues = 27,
|
||||
Property_Proxies = 28
|
||||
};
|
||||
|
||||
///Basic setting widget types.
|
||||
enum SettingType
|
||||
{
|
||||
/*
|
||||
* 0 - 9 - Boolean widgets
|
||||
* 10-19 - List widgets
|
||||
* 21-29 - Range widgets
|
||||
* 31-39 - Text widgets
|
||||
*
|
||||
* Each range corresponds to a View_Type enum by a factor of 10.
|
||||
*
|
||||
* Even-numbered values are single-value widgets
|
||||
* Odd-numbered values are multi-valued widgets
|
||||
*/
|
||||
|
||||
Type_CheckBox = 0,
|
||||
Type_RadioButton = 1,
|
||||
Type_ListView = 10,
|
||||
Type_ComboBox = 11,
|
||||
Type_SpinBox = 21,
|
||||
Type_DoubleSpinBox = 23,
|
||||
Type_Slider = 25,
|
||||
Type_Dial = 27,
|
||||
Type_TextArea = 30,
|
||||
Type_LineEdit = 31,
|
||||
Type_Undefined = 40
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
namespace CSVSettings
|
||||
{
|
||||
///Categorical view types which encompass the setting widget types
|
||||
enum ViewType
|
||||
{
|
||||
ViewType_Boolean = 0,
|
||||
ViewType_List = 1,
|
||||
ViewType_Range = 2,
|
||||
ViewType_Text = 3,
|
||||
ViewType_Undefined = 4
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
namespace CSMSettings
|
||||
{
|
||||
///used to construct default settings in the Setting class
|
||||
struct PropertyDefaultValues
|
||||
{
|
||||
int id;
|
||||
QString name;
|
||||
QVariant value;
|
||||
};
|
||||
|
||||
///strings which correspond to setting values. These strings represent
|
||||
///the script language keywords which would be used to declare setting
|
||||
///views for 3rd party addons
|
||||
const QString sPropertyNames[] =
|
||||
{
|
||||
"name", "page", "setting_type", "is_multi_value",
|
||||
"is_multi_line", "widget_width", "view_row", "view_column", "delimiter",
|
||||
"is_serializable","column_span", "row_span", "minimum", "maximum",
|
||||
"special_value_text", "prefix", "suffix", "single_step", "wrapping",
|
||||
"tick_interval", "ticks_above", "ticks_below", "stylesheet",
|
||||
"defaults", "declarations", "definitions", "proxies"
|
||||
};
|
||||
|
||||
///Default values for a setting. Used in setting creation.
|
||||
const QString sPropertyDefaults[] =
|
||||
{
|
||||
"", //name
|
||||
"", //page
|
||||
"40", //setting type
|
||||
"false", //multivalue
|
||||
"false", //multiline
|
||||
"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
|
||||
"", //StyleSheet
|
||||
"", //default values
|
||||
"", //declared values
|
||||
"", //defined values
|
||||
"" //proxy values
|
||||
};
|
||||
}
|
||||
|
||||
#endif // VIEW_SUPPORT_HPP
|
@ -1,824 +0,0 @@
|
||||
#include "usersettings.hpp"
|
||||
|
||||
#include <QSettings>
|
||||
#include <QFile>
|
||||
|
||||
#include <components/files/configurationmanager.hpp>
|
||||
#include <components/settings/settings.hpp>
|
||||
#include <boost/version.hpp>
|
||||
|
||||
#include "setting.hpp"
|
||||
#include "support.hpp"
|
||||
#include <QTextCodec>
|
||||
#include <QDebug>
|
||||
|
||||
/**
|
||||
* Workaround for problems with whitespaces in paths in older versions of Boost library
|
||||
*/
|
||||
#if (BOOST_VERSION <= 104600)
|
||||
namespace boost
|
||||
{
|
||||
|
||||
template<>
|
||||
inline boost::filesystem::path lexical_cast<boost::filesystem::path, std::string>(const std::string& arg)
|
||||
{
|
||||
return boost::filesystem::path(arg);
|
||||
}
|
||||
|
||||
} /* namespace boost */
|
||||
#endif /* (BOOST_VERSION <= 104600) */
|
||||
|
||||
CSMSettings::UserSettings *CSMSettings::UserSettings::sUserSettingsInstance = 0;
|
||||
|
||||
CSMSettings::UserSettings::UserSettings (const Files::ConfigurationManager& configurationManager)
|
||||
: mCfgMgr (configurationManager)
|
||||
, mSettingDefinitions(NULL)
|
||||
{
|
||||
assert(!sUserSettingsInstance);
|
||||
sUserSettingsInstance = this;
|
||||
|
||||
buildSettingModelDefaults();
|
||||
}
|
||||
|
||||
void CSMSettings::UserSettings::buildSettingModelDefaults()
|
||||
{
|
||||
/*
|
||||
declareSection ("3d-render", "3D Rendering");
|
||||
{
|
||||
Setting *farClipDist = createSetting (Type_DoubleSpinBox, "far-clip-distance", "Far clipping distance");
|
||||
farClipDist->setDefaultValue (300000);
|
||||
farClipDist->setRange (0, 1000000);
|
||||
farClipDist->setToolTip ("The maximum distance objects are still rendered at.");
|
||||
|
||||
QString defaultValue = "None";
|
||||
Setting *antialiasing = createSetting (Type_ComboBox, "antialiasing", "Antialiasing");
|
||||
antialiasing->setDeclaredValues (QStringList()
|
||||
<< defaultValue << "MSAA 2" << "MSAA 4" << "MSAA 8" << "MSAA 16");
|
||||
antialiasing->setDefaultValue (defaultValue);
|
||||
}
|
||||
*/
|
||||
|
||||
/*
|
||||
declareSection ("scene-input", "Scene Input");
|
||||
{
|
||||
Setting *fastFactor = createSetting (Type_SpinBox, "fast-factor",
|
||||
"Fast movement factor");
|
||||
fastFactor->setDefaultValue (4);
|
||||
fastFactor->setRange (1, 100);
|
||||
fastFactor->setToolTip (
|
||||
"Factor by which movement is speed up while the shift key is held down.");
|
||||
}
|
||||
*/
|
||||
|
||||
declareSection ("window", "Window");
|
||||
{
|
||||
Setting *preDefined = createSetting (Type_ComboBox, "pre-defined",
|
||||
"Default window size");
|
||||
preDefined->setEditorSetting (false);
|
||||
preDefined->setDeclaredValues (
|
||||
QStringList() << "640 x 480" << "800 x 600" << "1024 x 768" << "1440 x 900");
|
||||
preDefined->setViewLocation (1, 1);
|
||||
preDefined->setColumnSpan (2);
|
||||
preDefined->setToolTip ("Newly opened top-level windows will open with this size "
|
||||
"(picked from a list of pre-defined values)");
|
||||
|
||||
Setting *width = createSetting (Type_LineEdit, "default-width",
|
||||
"Default window width");
|
||||
width->setDefaultValues (QStringList() << "1024");
|
||||
width->setViewLocation (2, 1);
|
||||
width->setColumnSpan (1);
|
||||
width->setToolTip ("Newly opened top-level windows will open with this width.");
|
||||
preDefined->addProxy (width, QStringList() << "640" << "800" << "1024" << "1440");
|
||||
|
||||
Setting *height = createSetting (Type_LineEdit, "default-height",
|
||||
"Default window height");
|
||||
height->setDefaultValues (QStringList() << "768");
|
||||
height->setViewLocation (2, 2);
|
||||
height->setColumnSpan (1);
|
||||
height->setToolTip ("Newly opened top-level windows will open with this height.");
|
||||
preDefined->addProxy (height, QStringList() << "480" << "600" << "768" << "900");
|
||||
|
||||
Setting *reuse = createSetting (Type_CheckBox, "reuse", "Reuse Subviews");
|
||||
reuse->setDefaultValue ("true");
|
||||
reuse->setToolTip ("When a new subview is requested and a matching subview already "
|
||||
" exist, do not open a new subview and use the existing one instead.");
|
||||
|
||||
Setting *statusBar = createSetting (Type_CheckBox, "show-statusbar", "Show Status Bar");
|
||||
statusBar->setDefaultValue ("true");
|
||||
statusBar->setToolTip ("If a newly open top level window is showing status bars or not. "
|
||||
" Note that this does not affect existing windows.");
|
||||
|
||||
Setting *maxSubView = createSetting (Type_SpinBox, "max-subviews",
|
||||
"Maximum number of subviews per top-level window");
|
||||
maxSubView->setDefaultValue (256);
|
||||
maxSubView->setRange (1, 256);
|
||||
maxSubView->setToolTip ("If the maximum number is reached and a new subview is opened "
|
||||
"it will be placed into a new top-level window.");
|
||||
|
||||
Setting *hide = createSetting (Type_CheckBox, "hide-subview", "Hide single subview");
|
||||
hide->setDefaultValue ("false");
|
||||
hide->setToolTip ("When a view contains only a single subview, hide the subview title "
|
||||
"bar and if this subview is closed also close the view (unless it is the last "
|
||||
"view for this document)");
|
||||
|
||||
Setting *minWidth = createSetting (Type_SpinBox, "minimum-width",
|
||||
"Minimum subview width");
|
||||
minWidth->setDefaultValue (325);
|
||||
minWidth->setRange (50, 10000);
|
||||
minWidth->setToolTip ("Minimum width of subviews.");
|
||||
|
||||
QString defaultScroll = "Scrollbar Only";
|
||||
QStringList scrollValues = QStringList() << defaultScroll << "Grow Only" << "Grow then Scroll";
|
||||
|
||||
Setting *mainwinScroll = createSetting (Type_RadioButton, "mainwindow-scrollbar",
|
||||
"Add a horizontal scrollbar to the main view window.");
|
||||
mainwinScroll->setDefaultValue (defaultScroll);
|
||||
mainwinScroll->setDeclaredValues (scrollValues);
|
||||
mainwinScroll->setToolTip ("Scrollbar Only: Simple addition of scrollbars, the view window does not grow"
|
||||
" automatically.\n"
|
||||
"Grow Only: Original Editor behaviour. The view window grows as subviews are added. No scrollbars.\n"
|
||||
"Grow then Scroll: The view window grows. The scrollbar appears once it cannot grow any further.");
|
||||
|
||||
Setting *grow = createSetting (Type_CheckBox, "grow-limit", "Grow Limit Screen");
|
||||
grow->setDefaultValue ("false");
|
||||
grow->setToolTip ("When \"Grow then Scroll\" option is selected, the window size grows to"
|
||||
" the width of the virtual desktop. \nIf this option is selected the the window growth"
|
||||
"is limited to the current screen.");
|
||||
}
|
||||
|
||||
declareSection ("records", "Records");
|
||||
{
|
||||
QString defaultValue = "Icon and Text";
|
||||
QStringList values = QStringList() << defaultValue << "Icon Only" << "Text Only";
|
||||
|
||||
Setting *rsd = createSetting (Type_RadioButton, "status-format",
|
||||
"Modification status display format");
|
||||
rsd->setDefaultValue (defaultValue);
|
||||
rsd->setDeclaredValues (values);
|
||||
|
||||
Setting *ritd = createSetting (Type_RadioButton, "type-format",
|
||||
"ID type display format");
|
||||
ritd->setDefaultValue (defaultValue);
|
||||
ritd->setDeclaredValues (values);
|
||||
}
|
||||
|
||||
declareSection ("table-input", "ID Tables");
|
||||
{
|
||||
QString inPlaceEdit ("Edit in Place");
|
||||
QString editRecord ("Edit Record");
|
||||
QString view ("View");
|
||||
QString editRecordAndClose ("Edit Record and Close");
|
||||
|
||||
QStringList values;
|
||||
values
|
||||
<< "None" << inPlaceEdit << editRecord << view << "Revert" << "Delete"
|
||||
<< editRecordAndClose << "View and Close";
|
||||
|
||||
QString toolTip = "<ul>"
|
||||
"<li>None</li>"
|
||||
"<li>Edit in Place: Edit the clicked cell</li>"
|
||||
"<li>Edit Record: Open a dialogue subview for the clicked record</li>"
|
||||
"<li>View: Open a scene subview for the clicked record (not available everywhere)</li>"
|
||||
"<li>Revert: Revert record</li>"
|
||||
"<li>Delete: Delete recordy</li>"
|
||||
"<li>Edit Record and Close: Open a dialogue subview for the clicked record and close the table subview</li>"
|
||||
"<li>View And Close: Open a scene subview for the clicked record and close the table subview</li>"
|
||||
"</ul>";
|
||||
|
||||
Setting *doubleClick = createSetting (Type_ComboBox, "double", "Double Click");
|
||||
doubleClick->setDeclaredValues (values);
|
||||
doubleClick->setDefaultValue (inPlaceEdit);
|
||||
doubleClick->setToolTip ("Action on double click in table:<p>" + toolTip);
|
||||
|
||||
Setting *shiftDoubleClick = createSetting (Type_ComboBox, "double-s",
|
||||
"Shift Double Click");
|
||||
shiftDoubleClick->setDeclaredValues (values);
|
||||
shiftDoubleClick->setDefaultValue (editRecord);
|
||||
shiftDoubleClick->setToolTip ("Action on shift double click in table:<p>" + toolTip);
|
||||
|
||||
Setting *ctrlDoubleClick = createSetting (Type_ComboBox, "double-c",
|
||||
"Control Double Click");
|
||||
ctrlDoubleClick->setDeclaredValues (values);
|
||||
ctrlDoubleClick->setDefaultValue (view);
|
||||
ctrlDoubleClick->setToolTip ("Action on control double click in table:<p>" + toolTip);
|
||||
|
||||
Setting *shiftCtrlDoubleClick = createSetting (Type_ComboBox, "double-sc",
|
||||
"Shift Control Double Click");
|
||||
shiftCtrlDoubleClick->setDeclaredValues (values);
|
||||
shiftCtrlDoubleClick->setDefaultValue (editRecordAndClose);
|
||||
shiftCtrlDoubleClick->setToolTip ("Action on shift control double click in table:<p>" + toolTip);
|
||||
|
||||
QString defaultValue = "Jump and Select";
|
||||
QStringList jumpValues = QStringList() << defaultValue << "Jump Only" << "No Jump";
|
||||
|
||||
Setting *jumpToAdded = createSetting (Type_RadioButton, "jump-to-added",
|
||||
"Jump to the added or cloned record.");
|
||||
jumpToAdded->setDefaultValue (defaultValue);
|
||||
jumpToAdded->setDeclaredValues (jumpValues);
|
||||
|
||||
Setting *extendedConfig = createSetting (Type_CheckBox, "extended-config",
|
||||
"Manually specify affected record types for an extended delete/revert");
|
||||
extendedConfig->setDefaultValue("false");
|
||||
extendedConfig->setToolTip("Delete and revert commands have an extended form that also affects "
|
||||
"associated records.\n\n"
|
||||
"If this option is enabled, types of affected records are selected "
|
||||
"manually before a command execution.\nOtherwise, all associated "
|
||||
"records are deleted/reverted immediately.");
|
||||
}
|
||||
|
||||
declareSection ("dialogues", "ID Dialogues");
|
||||
{
|
||||
Setting *toolbar = createSetting (Type_CheckBox, "toolbar", "Show toolbar");
|
||||
toolbar->setDefaultValue ("true");
|
||||
}
|
||||
|
||||
declareSection ("report-input", "Reports");
|
||||
{
|
||||
QString none ("None");
|
||||
QString edit ("Edit");
|
||||
QString remove ("Remove");
|
||||
QString editAndRemove ("Edit And Remove");
|
||||
|
||||
QStringList values;
|
||||
values << none << edit << remove << editAndRemove;
|
||||
|
||||
QString toolTip = "<ul>"
|
||||
"<li>None</li>"
|
||||
"<li>Edit: Open a table or dialogue suitable for addressing the listed report</li>"
|
||||
"<li>Remove: Remove the report from the report table</li>"
|
||||
"<li>Edit and Remove: Open a table or dialogue suitable for addressing the listed report, then remove the report from the report table</li>"
|
||||
"</ul>";
|
||||
|
||||
Setting *doubleClick = createSetting (Type_ComboBox, "double", "Double Click");
|
||||
doubleClick->setDeclaredValues (values);
|
||||
doubleClick->setDefaultValue (edit);
|
||||
doubleClick->setToolTip ("Action on double click in report table:<p>" + toolTip);
|
||||
|
||||
Setting *shiftDoubleClick = createSetting (Type_ComboBox, "double-s",
|
||||
"Shift Double Click");
|
||||
shiftDoubleClick->setDeclaredValues (values);
|
||||
shiftDoubleClick->setDefaultValue (remove);
|
||||
shiftDoubleClick->setToolTip ("Action on shift double click in report table:<p>" + toolTip);
|
||||
|
||||
Setting *ctrlDoubleClick = createSetting (Type_ComboBox, "double-c",
|
||||
"Control Double Click");
|
||||
ctrlDoubleClick->setDeclaredValues (values);
|
||||
ctrlDoubleClick->setDefaultValue (editAndRemove);
|
||||
ctrlDoubleClick->setToolTip ("Action on control double click in report table:<p>" + toolTip);
|
||||
|
||||
Setting *shiftCtrlDoubleClick = createSetting (Type_ComboBox, "double-sc",
|
||||
"Shift Control Double Click");
|
||||
shiftCtrlDoubleClick->setDeclaredValues (values);
|
||||
shiftCtrlDoubleClick->setDefaultValue (none);
|
||||
shiftCtrlDoubleClick->setToolTip ("Action on shift control double click in report table:<p>" + toolTip);
|
||||
}
|
||||
|
||||
declareSection ("search", "Search & Replace");
|
||||
{
|
||||
Setting *before = createSetting (Type_SpinBox, "char-before",
|
||||
"Characters before search string");
|
||||
before->setDefaultValue (10);
|
||||
before->setRange (0, 1000);
|
||||
before->setToolTip ("Maximum number of character to display in search result before the searched text");
|
||||
|
||||
Setting *after = createSetting (Type_SpinBox, "char-after",
|
||||
"Characters after search string");
|
||||
after->setDefaultValue (10);
|
||||
after->setRange (0, 1000);
|
||||
after->setToolTip ("Maximum number of character to display in search result after the searched text");
|
||||
|
||||
Setting *autoDelete = createSetting (Type_CheckBox, "auto-delete", "Delete row from result table after a successful replace");
|
||||
autoDelete->setDefaultValue ("true");
|
||||
}
|
||||
|
||||
declareSection ("script-editor", "Scripts");
|
||||
{
|
||||
Setting *lineNum = createSetting (Type_CheckBox, "show-linenum", "Show Line Numbers");
|
||||
lineNum->setDefaultValue ("true");
|
||||
lineNum->setToolTip ("Show line numbers to the left of the script editor window."
|
||||
"The current row and column numbers of the text cursor are shown at the bottom.");
|
||||
|
||||
Setting *monoFont = createSetting (Type_CheckBox, "mono-font", "Use monospace font");
|
||||
monoFont->setDefaultValue ("true");
|
||||
monoFont->setToolTip ("Whether to use monospaced fonts on script edit subview.");
|
||||
|
||||
QString tooltip =
|
||||
"\n#RGB (each of R, G, and B is a single hex digit)"
|
||||
"\n#RRGGBB"
|
||||
"\n#RRRGGGBBB"
|
||||
"\n#RRRRGGGGBBBB"
|
||||
"\nA name from the list of colors defined in the list of SVG color keyword names."
|
||||
"\nX11 color names may also work.";
|
||||
|
||||
QString modeNormal ("Normal");
|
||||
|
||||
QStringList modes;
|
||||
modes << "Ignore" << modeNormal << "Strict";
|
||||
|
||||
Setting *warnings = createSetting (Type_ComboBox, "warnings",
|
||||
"Warning Mode");
|
||||
warnings->setDeclaredValues (modes);
|
||||
warnings->setDefaultValue (modeNormal);
|
||||
warnings->setToolTip ("<ul>How to handle warning messages during compilation:<p>"
|
||||
"<li>Ignore: Do not report warning</li>"
|
||||
"<li>Normal: Report warning as a warning</li>"
|
||||
"<li>Strict: Promote warning to an error</li>"
|
||||
"</ul>");
|
||||
|
||||
Setting *toolbar = createSetting (Type_CheckBox, "toolbar", "Show toolbar");
|
||||
toolbar->setDefaultValue ("true");
|
||||
|
||||
Setting *delay = createSetting (Type_SpinBox, "compile-delay",
|
||||
"Delay between updating of source errors");
|
||||
delay->setDefaultValue (100);
|
||||
delay->setRange (0, 10000);
|
||||
delay->setToolTip ("Delay in milliseconds");
|
||||
|
||||
Setting *errorHeight = createSetting (Type_SpinBox, "error-height",
|
||||
"Initial height of the error panel");
|
||||
errorHeight->setDefaultValue (100);
|
||||
errorHeight->setRange (100, 10000);
|
||||
|
||||
Setting *formatInt = createSetting (Type_LineEdit, "colour-int", "Highlight Colour: Int");
|
||||
formatInt->setDefaultValues (QStringList() << "Dark magenta");
|
||||
formatInt->setToolTip ("(Default: Green) Use one of the following formats:" + tooltip);
|
||||
|
||||
Setting *formatFloat = createSetting (Type_LineEdit, "colour-float", "Highlight Colour: Float");
|
||||
formatFloat->setDefaultValues (QStringList() << "Magenta");
|
||||
formatFloat->setToolTip ("(Default: Magenta) Use one of the following formats:" + tooltip);
|
||||
|
||||
Setting *formatName = createSetting (Type_LineEdit, "colour-name", "Highlight Colour: Name");
|
||||
formatName->setDefaultValues (QStringList() << "Gray");
|
||||
formatName->setToolTip ("(Default: Gray) Use one of the following formats:" + tooltip);
|
||||
|
||||
Setting *formatKeyword = createSetting (Type_LineEdit, "colour-keyword", "Highlight Colour: Keyword");
|
||||
formatKeyword->setDefaultValues (QStringList() << "Red");
|
||||
formatKeyword->setToolTip ("(Default: Red) Use one of the following formats:" + tooltip);
|
||||
|
||||
Setting *formatSpecial = createSetting (Type_LineEdit, "colour-special", "Highlight Colour: Special");
|
||||
formatSpecial->setDefaultValues (QStringList() << "Dark yellow");
|
||||
formatSpecial->setToolTip ("(Default: Dark yellow) Use one of the following formats:" + tooltip);
|
||||
|
||||
Setting *formatComment = createSetting (Type_LineEdit, "colour-comment", "Highlight Colour: Comment");
|
||||
formatComment->setDefaultValues (QStringList() << "Green");
|
||||
formatComment->setToolTip ("(Default: Green) Use one of the following formats:" + tooltip);
|
||||
|
||||
Setting *formatId = createSetting (Type_LineEdit, "colour-id", "Highlight Colour: Id");
|
||||
formatId->setDefaultValues (QStringList() << "Blue");
|
||||
formatId->setToolTip ("(Default: Blue) Use one of the following formats:" + tooltip);
|
||||
}
|
||||
|
||||
declareSection ("general-input", "General Input");
|
||||
{
|
||||
Setting *cycle = createSetting (Type_CheckBox, "cycle", "Cyclic next/previous");
|
||||
cycle->setDefaultValue ("false");
|
||||
cycle->setToolTip ("When using next/previous functions at the last/first item of a "
|
||||
"list go to the first/last item");
|
||||
}
|
||||
|
||||
declareSection ("scene-input", "3D Scene Input");
|
||||
{
|
||||
QString left ("Left Mouse-Button");
|
||||
QString cLeft ("Ctrl-Left Mouse-Button");
|
||||
QString right ("Right Mouse-Button");
|
||||
QString cRight ("Ctrl-Right Mouse-Button");
|
||||
QString middle ("Middle Mouse-Button");
|
||||
QString cMiddle ("Ctrl-Middle Mouse-Button");
|
||||
|
||||
QStringList values;
|
||||
values << left << cLeft << right << cRight << middle << cMiddle;
|
||||
|
||||
Setting *primaryNavigation = createSetting (Type_ComboBox, "p-navi", "Primary Camera Navigation Button");
|
||||
primaryNavigation->setDeclaredValues (values);
|
||||
primaryNavigation->setDefaultValue (left);
|
||||
|
||||
Setting *secondaryNavigation = createSetting (Type_ComboBox, "s-navi", "Secondary Camera Navigation Button");
|
||||
secondaryNavigation->setDeclaredValues (values);
|
||||
secondaryNavigation->setDefaultValue (cLeft);
|
||||
|
||||
Setting *primaryEditing = createSetting (Type_ComboBox, "p-edit", "Primary Editing Button");
|
||||
primaryEditing->setDeclaredValues (values);
|
||||
primaryEditing->setDefaultValue (right);
|
||||
|
||||
Setting *secondaryEditing = createSetting (Type_ComboBox, "s-edit", "Secondary Editing Button");
|
||||
secondaryEditing->setDeclaredValues (values);
|
||||
secondaryEditing->setDefaultValue (cRight);
|
||||
|
||||
Setting *primarySelection = createSetting (Type_ComboBox, "p-select", "Selection Button");
|
||||
primarySelection->setDeclaredValues (values);
|
||||
primarySelection->setDefaultValue (middle);
|
||||
|
||||
Setting *secondarySelection = createSetting (Type_ComboBox, "s-select", "Selection Button");
|
||||
secondarySelection->setDeclaredValues (values);
|
||||
secondarySelection->setDefaultValue (cMiddle);
|
||||
|
||||
Setting *contextSensitive = createSetting (Type_CheckBox, "context-select", "Context Sensitive Selection");
|
||||
contextSensitive->setDefaultValue ("false");
|
||||
|
||||
Setting *dragMouseSensitivity = createSetting (Type_DoubleSpinBox, "drag-factor",
|
||||
"Mouse sensitivity during drag operations");
|
||||
dragMouseSensitivity->setDefaultValue (1.0);
|
||||
dragMouseSensitivity->setRange (0.001, 100.0);
|
||||
|
||||
Setting *dragWheelSensitivity = createSetting (Type_DoubleSpinBox, "drag-wheel-factor",
|
||||
"Mouse wheel sensitivity during drag operations");
|
||||
dragWheelSensitivity->setDefaultValue (1.0);
|
||||
dragWheelSensitivity->setRange (0.001, 100.0);
|
||||
|
||||
Setting *dragShiftFactor = createSetting (Type_DoubleSpinBox, "drag-shift-factor",
|
||||
"Acceleration factor during drag operations while holding down shift");
|
||||
dragShiftFactor->setDefaultValue (4.0);
|
||||
dragShiftFactor->setRange (0.001, 100.0);
|
||||
}
|
||||
|
||||
declareSection ("tooltips", "Tooltips");
|
||||
{
|
||||
Setting *scene = createSetting (Type_CheckBox, "scene", "Show Tooltips in 3D scenes");
|
||||
scene->setDefaultValue ("true");
|
||||
|
||||
Setting *sceneHideBasic = createSetting (Type_CheckBox, "scene-hide-basic", "Hide basic 3D scenes tooltips");
|
||||
sceneHideBasic->setDefaultValue ("false");
|
||||
|
||||
Setting *sceneDelay = createSetting (Type_SpinBox, "scene-delay",
|
||||
"Tooltip delay in milliseconds");
|
||||
sceneDelay->setDefaultValue (500);
|
||||
sceneDelay->setRange (1, 10000);
|
||||
}
|
||||
|
||||
{
|
||||
/******************************************************************
|
||||
* 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");
|
||||
|
||||
Setting *slaveBoolean = createSetting (Type_CheckBox, section,
|
||||
"Proxy Checkboxes");
|
||||
|
||||
Setting *slaveSingleText = createSetting (Type_LineEdit, section,
|
||||
"Proxy TextBox 1");
|
||||
|
||||
Setting *slaveMultiText = createSetting (Type_LineEdit, section,
|
||||
"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")
|
||||
<< (QStringList() << "One" << "Three")
|
||||
<< (QStringList() << "One" << "Three" << "Five")
|
||||
<< (QStringList() << "Two" << "Four")
|
||||
);
|
||||
|
||||
masterBoolean->addProxy (slaveSingleText, QList <QStringList>()
|
||||
<< (QStringList() << "Text A")
|
||||
<< (QStringList() << "Text B")
|
||||
<< (QStringList() << "Text A")
|
||||
<< (QStringList() << "Text C")
|
||||
);
|
||||
|
||||
masterBoolean->addProxy (slaveMultiText, QList <QStringList>()
|
||||
<< (QStringList() << "One" << "Three")
|
||||
<< (QStringList() << "One" << "Three")
|
||||
<< (QStringList() << "One" << "Three" << "Five")
|
||||
<< (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);
|
||||
slaveDial->setSerializable (false);
|
||||
|
||||
slaveBoolean->setDefaultValues (QStringList()
|
||||
<< "One" << "Three" << "Five");
|
||||
|
||||
slaveSingleText->setDefaultValue ("Text A");
|
||||
|
||||
slaveMultiText->setDefaultValues (QStringList()
|
||||
<< "One" << "Three" << "Five");
|
||||
|
||||
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()
|
||||
{
|
||||
sUserSettingsInstance = 0;
|
||||
}
|
||||
|
||||
void CSMSettings::UserSettings::loadSettings (const QString &fileName)
|
||||
{
|
||||
QString userFilePath = QString::fromUtf8
|
||||
(mCfgMgr.getUserConfigPath().string().c_str());
|
||||
|
||||
QString globalFilePath = QString::fromUtf8
|
||||
(mCfgMgr.getGlobalPath().string().c_str());
|
||||
|
||||
QString otherFilePath = globalFilePath;
|
||||
|
||||
//test for local only if global fails (uninstalled copy)
|
||||
if (!QFile (globalFilePath + fileName).exists())
|
||||
{
|
||||
//if global is invalid, use the local path
|
||||
otherFilePath = QString::fromUtf8
|
||||
(mCfgMgr.getLocalPath().string().c_str());
|
||||
}
|
||||
|
||||
QSettings::setPath
|
||||
(QSettings::IniFormat, QSettings::UserScope, userFilePath);
|
||||
|
||||
QSettings::setPath
|
||||
(QSettings::IniFormat, QSettings::SystemScope, otherFilePath);
|
||||
|
||||
mSettingDefinitions = new QSettings
|
||||
(QSettings::IniFormat, QSettings::UserScope, "opencs", QString(), this);
|
||||
}
|
||||
|
||||
// if the key is not found create one with a default value
|
||||
QString CSMSettings::UserSettings::setting(const QString &viewKey, const QString &value)
|
||||
{
|
||||
if(mSettingDefinitions->contains(viewKey))
|
||||
return settingValue(viewKey);
|
||||
else if(value != QString())
|
||||
{
|
||||
mSettingDefinitions->setValue (viewKey, QStringList() << value);
|
||||
return value;
|
||||
}
|
||||
|
||||
return QString();
|
||||
}
|
||||
|
||||
bool CSMSettings::UserSettings::hasSettingDefinitions (const QString &viewKey) const
|
||||
{
|
||||
return (mSettingDefinitions->contains (viewKey));
|
||||
}
|
||||
|
||||
void CSMSettings::UserSettings::setDefinitions
|
||||
(const QString &key, const QStringList &list)
|
||||
{
|
||||
mSettingDefinitions->setValue (key, list);
|
||||
}
|
||||
|
||||
void CSMSettings::UserSettings::saveDefinitions() const
|
||||
{
|
||||
mSettingDefinitions->sync();
|
||||
}
|
||||
|
||||
QString CSMSettings::UserSettings::settingValue (const QString &settingKey)
|
||||
{
|
||||
QStringList defs;
|
||||
|
||||
if (!mSettingDefinitions->contains (settingKey))
|
||||
return QString();
|
||||
|
||||
defs = mSettingDefinitions->value (settingKey).toStringList();
|
||||
|
||||
if (defs.isEmpty())
|
||||
return QString();
|
||||
|
||||
return defs.at(0);
|
||||
}
|
||||
|
||||
CSMSettings::UserSettings& CSMSettings::UserSettings::instance()
|
||||
{
|
||||
assert(sUserSettingsInstance);
|
||||
return *sUserSettingsInstance;
|
||||
}
|
||||
|
||||
void CSMSettings::UserSettings::updateUserSetting(const QString &settingKey,
|
||||
const QStringList &list)
|
||||
{
|
||||
mSettingDefinitions->setValue (settingKey ,list);
|
||||
|
||||
emit userSettingUpdated (settingKey, list);
|
||||
}
|
||||
|
||||
CSMSettings::Setting *CSMSettings::UserSettings::findSetting
|
||||
(const QString &pageName, const QString &settingName)
|
||||
{
|
||||
foreach (Setting *setting, mSettings)
|
||||
{
|
||||
if (setting->name() == settingName)
|
||||
{
|
||||
if (setting->page() == pageName)
|
||||
return setting;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void CSMSettings::UserSettings::removeSetting
|
||||
(const QString &pageName, const QString &settingName)
|
||||
{
|
||||
if (mSettings.isEmpty())
|
||||
return;
|
||||
|
||||
QList <Setting *>::iterator removeIterator = mSettings.begin();
|
||||
|
||||
while (removeIterator != mSettings.end())
|
||||
{
|
||||
if ((*removeIterator)->name() == settingName)
|
||||
{
|
||||
if ((*removeIterator)->page() == pageName)
|
||||
{
|
||||
mSettings.erase (removeIterator);
|
||||
break;
|
||||
}
|
||||
}
|
||||
removeIterator++;
|
||||
}
|
||||
}
|
||||
|
||||
CSMSettings::SettingPageMap CSMSettings::UserSettings::settingPageMap() const
|
||||
{
|
||||
SettingPageMap pageMap;
|
||||
|
||||
foreach (Setting *setting, mSettings)
|
||||
{
|
||||
SettingPageMap::iterator iter = pageMap.find (setting->page());
|
||||
|
||||
if (iter==pageMap.end())
|
||||
{
|
||||
QPair<QString, QList <Setting *> > value;
|
||||
|
||||
std::map<QString, QString>::const_iterator iter2 =
|
||||
mSectionLabels.find (setting->page());
|
||||
|
||||
value.first = iter2!=mSectionLabels.end() ? iter2->second : "";
|
||||
|
||||
iter = pageMap.insert (setting->page(), value);
|
||||
}
|
||||
|
||||
iter->second.append (setting);
|
||||
}
|
||||
|
||||
return pageMap;
|
||||
}
|
||||
|
||||
CSMSettings::Setting *CSMSettings::UserSettings::createSetting
|
||||
(CSMSettings::SettingType type, const QString &name, const QString& label)
|
||||
{
|
||||
Setting *setting = new Setting (type, name, mSection, label);
|
||||
|
||||
// set useful defaults
|
||||
int row = 1;
|
||||
|
||||
if (!mSettings.empty())
|
||||
row = mSettings.back()->viewRow()+1;
|
||||
|
||||
setting->setViewLocation (row, 1);
|
||||
|
||||
setting->setColumnSpan (3);
|
||||
|
||||
int width = 10;
|
||||
|
||||
if (type==Type_CheckBox)
|
||||
width = 40;
|
||||
|
||||
setting->setWidgetWidth (width);
|
||||
|
||||
if (type==Type_CheckBox)
|
||||
setting->setStyleSheet ("QGroupBox { border: 0px; }");
|
||||
|
||||
if (type==Type_CheckBox)
|
||||
setting->setDeclaredValues(QStringList() << "true" << "false");
|
||||
|
||||
if (type==Type_CheckBox)
|
||||
setting->setSpecialValueText (setting->getLabel());
|
||||
|
||||
//add declaration to the model
|
||||
mSettings.append (setting);
|
||||
|
||||
return setting;
|
||||
}
|
||||
|
||||
void CSMSettings::UserSettings::declareSection (const QString& page, const QString& label)
|
||||
{
|
||||
mSection = page;
|
||||
mSectionLabels[page] = label;
|
||||
}
|
||||
|
||||
QStringList CSMSettings::UserSettings::definitions (const QString &viewKey) const
|
||||
{
|
||||
if (mSettingDefinitions->contains (viewKey))
|
||||
return mSettingDefinitions->value (viewKey).toStringList();
|
||||
|
||||
return QStringList();
|
||||
}
|
@ -1,107 +0,0 @@
|
||||
#ifndef USERSETTINGS_HPP
|
||||
#define USERSETTINGS_HPP
|
||||
|
||||
#include <map>
|
||||
|
||||
#include <QList>
|
||||
#include <QStringList>
|
||||
#include <QString>
|
||||
#include <QMap>
|
||||
#include <QPair>
|
||||
|
||||
#include <boost/filesystem/path.hpp>
|
||||
#include "support.hpp"
|
||||
|
||||
#ifndef Q_MOC_RUN
|
||||
#include <components/files/configurationmanager.hpp>
|
||||
#endif
|
||||
|
||||
namespace Files { typedef std::vector<boost::filesystem::path> PathContainer;
|
||||
struct ConfigurationManager;}
|
||||
|
||||
class QFile;
|
||||
class QSettings;
|
||||
|
||||
namespace CSMSettings {
|
||||
|
||||
class Setting;
|
||||
typedef QMap <QString, QPair<QString, QList <Setting *> > > SettingPageMap;
|
||||
|
||||
class UserSettings: public QObject
|
||||
{
|
||||
|
||||
Q_OBJECT
|
||||
|
||||
static UserSettings *sUserSettingsInstance;
|
||||
const Files::ConfigurationManager& mCfgMgr;
|
||||
|
||||
QSettings *mSettingDefinitions;
|
||||
QList <Setting *> mSettings;
|
||||
QString mSection;
|
||||
std::map<QString, QString> mSectionLabels;
|
||||
|
||||
public:
|
||||
|
||||
/// Singleton implementation
|
||||
static UserSettings& instance();
|
||||
|
||||
UserSettings (const Files::ConfigurationManager& configurationManager);
|
||||
~UserSettings();
|
||||
|
||||
UserSettings (UserSettings const &); //not implemented
|
||||
UserSettings& operator= (UserSettings const &); //not implemented
|
||||
|
||||
/// Retrieves the settings file at all three levels (global, local and user).
|
||||
void loadSettings (const QString &fileName);
|
||||
|
||||
/// Updates QSettings and syncs with the ini file
|
||||
void setDefinitions (const QString &key, const QStringList &defs);
|
||||
|
||||
QString settingValue (const QString &settingKey);
|
||||
|
||||
///retrieve a setting object from a given page and setting name
|
||||
Setting *findSetting
|
||||
(const QString &pageName, const QString &settingName = QString());
|
||||
|
||||
///remove a setting from the list
|
||||
void removeSetting
|
||||
(const QString &pageName, const QString &settingName);
|
||||
|
||||
///Retrieve a map of the settings, keyed by page name
|
||||
SettingPageMap settingPageMap() const;
|
||||
|
||||
///Returns a string list of defined vlaues for the specified setting
|
||||
///in "page/name" format.
|
||||
QStringList definitions (const QString &viewKey) const;
|
||||
|
||||
///Test to indicate whether or not a setting has any definitions
|
||||
bool hasSettingDefinitions (const QString &viewKey) const;
|
||||
|
||||
///Save any unsaved changes in the QSettings object
|
||||
void saveDefinitions() const;
|
||||
|
||||
QString setting(const QString &viewKey, const QString &value = QString());
|
||||
|
||||
private:
|
||||
|
||||
void buildSettingModelDefaults();
|
||||
|
||||
///add a new setting to the model and return it
|
||||
Setting *createSetting (CSMSettings::SettingType type, const QString &name,
|
||||
const QString& label);
|
||||
|
||||
/// Set the section for createSetting calls.
|
||||
///
|
||||
/// Sections can be declared multiple times.
|
||||
void declareSection (const QString& page, const QString& label);
|
||||
|
||||
signals:
|
||||
|
||||
void userSettingUpdated (const QString &, const QStringList &);
|
||||
|
||||
public slots:
|
||||
|
||||
void updateUserSetting (const QString &, const QStringList &);
|
||||
};
|
||||
}
|
||||
#endif // USERSETTINGS_HPP
|
@ -1,120 +0,0 @@
|
||||
#include <QHBoxLayout>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
#include <QCheckBox>
|
||||
#include <QRadioButton>
|
||||
#include <QGroupBox>
|
||||
|
||||
#include <QAbstractButton>
|
||||
|
||||
#include "booleanview.hpp"
|
||||
#include "../../model/settings/setting.hpp"
|
||||
|
||||
CSVSettings::BooleanView::BooleanView (CSMSettings::Setting *setting,
|
||||
Page *parent)
|
||||
: View (setting, parent), mType(setting->type())
|
||||
{
|
||||
foreach (const QString &value, setting->declaredValues())
|
||||
{
|
||||
QAbstractButton *button = 0;
|
||||
|
||||
switch (mType)
|
||||
{
|
||||
case CSMSettings::Type_CheckBox: {
|
||||
if(mButtons.empty()) // show only one for checkboxes
|
||||
{
|
||||
button = new QCheckBox (value, this);
|
||||
button->setChecked (setting->defaultValues().at(0) == "true" ? true : false);
|
||||
|
||||
// special visual treatment option for checkboxes
|
||||
if(setting->specialValueText() != "") {
|
||||
Frame::setTitle("");
|
||||
button->setText(setting->specialValueText());
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case CSMSettings::Type_RadioButton:
|
||||
button = new QRadioButton (value, this);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if(button && (mType != CSMSettings::Type_CheckBox || mButtons.empty()))
|
||||
{
|
||||
connect (button, SIGNAL (clicked (bool)),
|
||||
this, SLOT (slotToggled (bool)));
|
||||
|
||||
button->setObjectName (value);
|
||||
|
||||
addWidget (button);
|
||||
|
||||
mButtons[value] = button;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CSVSettings::BooleanView::slotToggled (bool state)
|
||||
{
|
||||
//test only for true to avoid multiple selection updates with radiobuttons
|
||||
if (!isMultiValue() && !state)
|
||||
return;
|
||||
|
||||
QStringList values;
|
||||
|
||||
foreach (QString key, mButtons.keys())
|
||||
{
|
||||
// checkbox values are true/false unlike radio buttons
|
||||
if(mType == CSMSettings::Type_CheckBox)
|
||||
values.append(mButtons.value(key)->isChecked() ? "true" : "false");
|
||||
else
|
||||
{
|
||||
if (mButtons.value(key)->isChecked())
|
||||
values.append (key);
|
||||
}
|
||||
}
|
||||
setSelectedValues (values, false);
|
||||
|
||||
View::updateView();
|
||||
}
|
||||
|
||||
void CSVSettings::BooleanView::updateView (bool signalUpdate) const
|
||||
{
|
||||
|
||||
QStringList values = selectedValues();
|
||||
|
||||
foreach (const QString &buttonName, mButtons.keys())
|
||||
{
|
||||
QAbstractButton *button = mButtons[buttonName];
|
||||
|
||||
//if the value is not found in the list, the widget is checked false
|
||||
bool buttonValue = values.contains(buttonName);
|
||||
|
||||
//skip if the butotn value will not change
|
||||
if (button->isChecked() == buttonValue)
|
||||
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);
|
||||
}
|
||||
|
||||
CSVSettings::BooleanView *CSVSettings::BooleanViewFactory::createView
|
||||
(CSMSettings::Setting *setting,
|
||||
Page *parent)
|
||||
{
|
||||
return new BooleanView (setting, parent);
|
||||
}
|
@ -1,45 +0,0 @@
|
||||
#ifndef CSVSETTINGS_BOOLEANVIEW_HPP
|
||||
#define CSVSETTINGS_BOOLEANVIEW_HPP
|
||||
|
||||
#include <QWidget>
|
||||
#include <QAbstractButton>
|
||||
|
||||
#include "view.hpp"
|
||||
#include "../../model/settings/support.hpp"
|
||||
|
||||
class QStringListModel;
|
||||
|
||||
namespace CSVSettings
|
||||
{
|
||||
class BooleanView : public View
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
QMap <QString, QAbstractButton *> mButtons;
|
||||
enum CSMSettings::SettingType mType;
|
||||
|
||||
public:
|
||||
explicit BooleanView (CSMSettings::Setting *setting,
|
||||
Page *parent);
|
||||
|
||||
protected:
|
||||
void updateView (bool signalUpdate = true) const;
|
||||
|
||||
private slots:
|
||||
void slotToggled (bool state);
|
||||
};
|
||||
|
||||
class BooleanViewFactory : public QObject, public IViewFactory
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit BooleanViewFactory (QWidget *parent = 0)
|
||||
: QObject (parent)
|
||||
{}
|
||||
|
||||
BooleanView *createView (CSMSettings::Setting *setting,
|
||||
Page *parent);
|
||||
};
|
||||
}
|
||||
#endif // CSVSETTINGS_BOOLEANVIEW_HPP
|
@ -1,127 +0,0 @@
|
||||
#include "dialog.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
#include <QListWidgetItem>
|
||||
#include <QApplication>
|
||||
#include <QWidget>
|
||||
#include <QStackedWidget>
|
||||
#include <QtGui>
|
||||
#include <QSplitter>
|
||||
#include <QDesktopWidget>
|
||||
|
||||
#include "../../model/settings/usersettings.hpp"
|
||||
|
||||
#include "page.hpp"
|
||||
|
||||
|
||||
CSVSettings::Dialog::Dialog(QMainWindow *parent)
|
||||
: SettingWindow (parent), mStackedWidget (0), mDebugMode (false)
|
||||
{
|
||||
setWindowTitle(QString::fromUtf8 ("User Settings"));
|
||||
|
||||
setSizePolicy (QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
|
||||
|
||||
setMinimumSize (600, 400);
|
||||
|
||||
setupDialog();
|
||||
|
||||
connect (mPageListWidget,
|
||||
SIGNAL (currentItemChanged(QListWidgetItem*, QListWidgetItem*)),
|
||||
this,
|
||||
SLOT (slotChangePage (QListWidgetItem*, QListWidgetItem*)));
|
||||
}
|
||||
|
||||
void CSVSettings::Dialog::slotChangePage
|
||||
(QListWidgetItem *cur, QListWidgetItem *prev)
|
||||
{
|
||||
mStackedWidget->changePage
|
||||
(mPageListWidget->row (cur), mPageListWidget->row (prev));
|
||||
}
|
||||
|
||||
void CSVSettings::Dialog::setupDialog()
|
||||
{
|
||||
QSplitter *centralWidget = new QSplitter (this);
|
||||
centralWidget->setSizePolicy (QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
|
||||
|
||||
setCentralWidget (centralWidget);
|
||||
|
||||
buildPageListWidget (centralWidget);
|
||||
buildStackedWidget (centralWidget);
|
||||
}
|
||||
|
||||
void CSVSettings::Dialog::buildPages()
|
||||
{
|
||||
SettingWindow::createPages ();
|
||||
|
||||
QFontMetrics fm (QApplication::font());
|
||||
|
||||
int maxWidth = 1;
|
||||
|
||||
foreach (Page *page, SettingWindow::pages())
|
||||
{
|
||||
maxWidth = std::max (maxWidth, fm.width(page->getLabel()));
|
||||
|
||||
new QListWidgetItem (page->getLabel(), mPageListWidget);
|
||||
|
||||
mStackedWidget->addWidget (page);
|
||||
}
|
||||
|
||||
mPageListWidget->setMaximumWidth (maxWidth + 10);
|
||||
|
||||
resize (mStackedWidget->sizeHint());
|
||||
}
|
||||
|
||||
void CSVSettings::Dialog::buildPageListWidget (QSplitter *centralWidget)
|
||||
{
|
||||
mPageListWidget = new QListWidget (centralWidget);
|
||||
mPageListWidget->setMinimumWidth(50);
|
||||
mPageListWidget->setSizePolicy (QSizePolicy::Expanding, QSizePolicy::Expanding);
|
||||
|
||||
mPageListWidget->setSelectionBehavior (QAbstractItemView::SelectItems);
|
||||
|
||||
centralWidget->addWidget(mPageListWidget);
|
||||
}
|
||||
|
||||
void CSVSettings::Dialog::buildStackedWidget (QSplitter *centralWidget)
|
||||
{
|
||||
mStackedWidget = new ResizeableStackedWidget (centralWidget);
|
||||
mStackedWidget->setSizePolicy (QSizePolicy::Preferred, QSizePolicy::Expanding);
|
||||
|
||||
centralWidget->addWidget (mStackedWidget);
|
||||
}
|
||||
|
||||
void CSVSettings::Dialog::closeEvent (QCloseEvent *event)
|
||||
{
|
||||
//SettingWindow::closeEvent() must be called first to ensure
|
||||
//model is updated
|
||||
SettingWindow::closeEvent (event);
|
||||
|
||||
saveSettings();
|
||||
}
|
||||
|
||||
void CSVSettings::Dialog::show()
|
||||
{
|
||||
if (pages().isEmpty())
|
||||
{
|
||||
buildPages();
|
||||
setViewValues();
|
||||
}
|
||||
|
||||
QWidget *currView = QApplication::activeWindow();
|
||||
if(currView)
|
||||
{
|
||||
// place at the center of the window with focus
|
||||
QSize size = currView->size();
|
||||
move(currView->geometry().x()+(size.width() - frameGeometry().width())/2,
|
||||
currView->geometry().y()+(size.height() - frameGeometry().height())/2);
|
||||
}
|
||||
else
|
||||
{
|
||||
// something's gone wrong, place at the center of the screen
|
||||
QPoint screenCenter = QApplication::desktop()->screenGeometry().center();
|
||||
move(screenCenter - QPoint(frameGeometry().width()/2,
|
||||
frameGeometry().height()/2));
|
||||
}
|
||||
QWidget::show();
|
||||
}
|
@ -1,50 +0,0 @@
|
||||
#ifndef CSVSETTINGS_DIALOG_H
|
||||
#define CSVSETTINGS_DIALOG_H
|
||||
|
||||
#include "settingwindow.hpp"
|
||||
#include "resizeablestackedwidget.hpp"
|
||||
|
||||
class QStackedWidget;
|
||||
class QListWidget;
|
||||
class QListWidgetItem;
|
||||
class QSplitter;
|
||||
|
||||
namespace CSVSettings {
|
||||
|
||||
class Page;
|
||||
|
||||
class Dialog : public SettingWindow
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
QListWidget *mPageListWidget;
|
||||
ResizeableStackedWidget *mStackedWidget;
|
||||
bool mDebugMode;
|
||||
|
||||
public:
|
||||
|
||||
explicit Dialog (QMainWindow *parent = 0);
|
||||
|
||||
protected:
|
||||
|
||||
/// Settings are written on close
|
||||
void closeEvent (QCloseEvent *event);
|
||||
|
||||
void setupDialog();
|
||||
|
||||
private:
|
||||
|
||||
void buildPages();
|
||||
void buildPageListWidget (QSplitter *centralWidget);
|
||||
void buildStackedWidget (QSplitter *centralWidget);
|
||||
|
||||
public slots:
|
||||
|
||||
void show();
|
||||
|
||||
private slots:
|
||||
|
||||
void slotChangePage (QListWidgetItem *, QListWidgetItem *);
|
||||
};
|
||||
}
|
||||
#endif // CSVSETTINGS_DIALOG_H
|
@ -1,108 +0,0 @@
|
||||
#include "frame.hpp"
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
const QString CSVSettings::Frame::sInvisibleBoxStyle =
|
||||
QString::fromUtf8("Frame { border:2px; padding: 2px; margin: 2px;}");
|
||||
|
||||
CSVSettings::Frame::Frame (bool isVisible, const QString &title,
|
||||
QWidget *parent)
|
||||
: QGroupBox (title, parent), mIsHorizontal (true),
|
||||
mLayout (new SettingLayout())
|
||||
{
|
||||
setFlat (true);
|
||||
mVisibleBoxStyle = styleSheet();
|
||||
|
||||
if (!isVisible)
|
||||
{
|
||||
// must be Page, not a View
|
||||
setStyleSheet (sInvisibleBoxStyle);
|
||||
}
|
||||
|
||||
setLayout (mLayout);
|
||||
}
|
||||
|
||||
void CSVSettings::Frame::hideWidgets()
|
||||
{
|
||||
for (int i = 0; i < children().size(); i++)
|
||||
{
|
||||
QObject *obj = children().at(i);
|
||||
|
||||
Frame *widgFrame = dynamic_cast <Frame *> (obj);
|
||||
|
||||
if (widgFrame)
|
||||
{
|
||||
widgFrame->hideWidgets();
|
||||
continue;
|
||||
}
|
||||
|
||||
QWidget *widg = static_cast <QWidget *> (obj);
|
||||
if (widg->property("sizePolicy").isValid())
|
||||
widg->setSizePolicy (QSizePolicy::Expanding, QSizePolicy::Expanding);
|
||||
}
|
||||
|
||||
layout()->activate();
|
||||
setFixedSize(minimumSizeHint());
|
||||
|
||||
}
|
||||
|
||||
void CSVSettings::Frame::showWidgets()
|
||||
{
|
||||
for (int i = 0; i < children().size(); i++)
|
||||
{
|
||||
QObject *obj = children().at(i);
|
||||
|
||||
Frame *widgFrame = dynamic_cast <Frame *> (obj);
|
||||
|
||||
if (widgFrame)
|
||||
{
|
||||
widgFrame->showWidgets();
|
||||
continue;
|
||||
}
|
||||
|
||||
QWidget *widg = static_cast <QWidget *> (obj);
|
||||
|
||||
if (widg->property("sizePolicy").isValid())
|
||||
{
|
||||
widg->setSizePolicy
|
||||
(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
|
||||
}
|
||||
}
|
||||
layout()->activate();
|
||||
setFixedSize(minimumSizeHint());
|
||||
}
|
||||
|
||||
void CSVSettings::Frame::addWidget (QWidget *widget, int row, int column,
|
||||
int rowSpan, int columnSpan)
|
||||
{
|
||||
if (row == -1)
|
||||
row = getNextRow();
|
||||
|
||||
if (column == -1)
|
||||
column = getNextColumn();
|
||||
|
||||
mLayout->addWidget (widget, row, column, rowSpan, columnSpan);
|
||||
//, Qt::AlignLeft | Qt::AlignTop);
|
||||
|
||||
widget->setSizePolicy (QSizePolicy::Ignored, QSizePolicy::Ignored);
|
||||
}
|
||||
|
||||
int CSVSettings::Frame::getNextRow () const
|
||||
{
|
||||
int row = mLayout->rowCount();
|
||||
|
||||
if (mIsHorizontal && row > 0)
|
||||
row--;
|
||||
|
||||
return row;
|
||||
}
|
||||
|
||||
int CSVSettings::Frame::getNextColumn () const
|
||||
{
|
||||
int column = 0;
|
||||
|
||||
if (mIsHorizontal)
|
||||
column = mLayout->columnCount();
|
||||
|
||||
return column;
|
||||
}
|
@ -1,60 +0,0 @@
|
||||
#ifndef CSVSETTINGS_FRAME_HPP
|
||||
#define CSVSETTINGS_FRAME_HPP
|
||||
|
||||
#include <QSizePolicy>
|
||||
#include <QGroupBox>
|
||||
#include <QGridLayout>
|
||||
#include "../../model/settings/support.hpp"
|
||||
|
||||
namespace CSVSettings
|
||||
{
|
||||
class SettingLayout : public QGridLayout
|
||||
{
|
||||
public:
|
||||
explicit SettingLayout (QWidget *parent = 0)
|
||||
: QGridLayout (parent)
|
||||
{
|
||||
setContentsMargins(0,0,0,0);
|
||||
setAlignment(Qt::AlignLeft | Qt::AlignTop);
|
||||
}
|
||||
};
|
||||
|
||||
/// Custom implementation of QGroupBox to act as a base for view classes
|
||||
class Frame : public QGroupBox
|
||||
{
|
||||
static const QString sInvisibleBoxStyle;
|
||||
|
||||
QString mVisibleBoxStyle;
|
||||
|
||||
bool mIsHorizontal;
|
||||
|
||||
SettingLayout *mLayout;
|
||||
|
||||
public:
|
||||
explicit Frame (bool isVisible, const QString &title = "",
|
||||
QWidget *parent = 0);
|
||||
|
||||
///Adds a widget to the grid layout, setting the position
|
||||
///relative to the last added widgets, or absolutely for positive
|
||||
///row / column values
|
||||
void addWidget (QWidget *widget, int row = -1, int column = -1,
|
||||
int rowSpan = 1, int columnSpan = 1);
|
||||
|
||||
///Force the grid to lay out in horizontal or vertical alignments
|
||||
void setHLayout() { mIsHorizontal = true; }
|
||||
void setVLayout() { mIsHorizontal = false; }
|
||||
|
||||
///show / hide widgets (when stacked widget page changes)
|
||||
void showWidgets();
|
||||
void hideWidgets();
|
||||
|
||||
private:
|
||||
|
||||
///functions which return the index for the next layout row / column
|
||||
int getNextColumn() const;
|
||||
int getNextRow() const;
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
#endif // CSVSETTINGS_FRAME_HPP
|
@ -1,106 +0,0 @@
|
||||
#include "listview.hpp"
|
||||
#include "../../model/settings/setting.hpp"
|
||||
|
||||
#include <QListView>
|
||||
#include <QComboBox>
|
||||
#include <QStringListModel>
|
||||
|
||||
CSVSettings::ListView::ListView(CSMSettings::Setting *setting,
|
||||
Page *parent)
|
||||
: View(setting, parent), mAbstractItemView (0), mComboBox (0)
|
||||
{
|
||||
QWidget *widget =
|
||||
buildWidget(setting->isMultiLine(), setting->widgetWidth());
|
||||
|
||||
addWidget (widget, setting->viewRow(), setting->viewColumn());
|
||||
|
||||
if (mComboBox)
|
||||
buildComboBoxModel();
|
||||
|
||||
else if (mAbstractItemView)
|
||||
buildAbstractItemViewModel();
|
||||
}
|
||||
|
||||
void CSVSettings::ListView::buildComboBoxModel()
|
||||
{
|
||||
mComboBox->setModel (dataModel());
|
||||
mComboBox->setModelColumn (0);
|
||||
mComboBox->view()->setSelectionModel (selectionModel());
|
||||
|
||||
int curIdx = -1;
|
||||
|
||||
if (!selectionModel()->selection().isEmpty())
|
||||
curIdx = selectionModel()->selectedIndexes().at(0).row();
|
||||
|
||||
mComboBox->setCurrentIndex (curIdx);
|
||||
|
||||
connect (mComboBox, SIGNAL(currentIndexChanged(int)),
|
||||
this, SLOT(emitItemViewUpdate(int)));
|
||||
}
|
||||
|
||||
void CSVSettings::ListView::buildAbstractItemViewModel()
|
||||
{
|
||||
mAbstractItemView->setModel (dataModel());
|
||||
mAbstractItemView->setSelectionModel (selectionModel());
|
||||
|
||||
//connection needs to go here for list view update to signal to
|
||||
//the outside
|
||||
}
|
||||
|
||||
void CSVSettings::ListView::emitItemViewUpdate (int idx)
|
||||
{
|
||||
updateView();
|
||||
}
|
||||
|
||||
QWidget *CSVSettings::ListView::buildWidget(bool isMultiLine, int width)
|
||||
{
|
||||
QWidget *widget = 0;
|
||||
|
||||
if (isMultiLine)
|
||||
{
|
||||
mAbstractItemView = new QListView (this);
|
||||
widget = mAbstractItemView;
|
||||
|
||||
if (width > 0)
|
||||
widget->setFixedWidth (widgetWidth (width));
|
||||
}
|
||||
else
|
||||
{
|
||||
mComboBox = new QComboBox (this);
|
||||
widget = mComboBox;
|
||||
|
||||
if (width > 0)
|
||||
mComboBox->setMinimumContentsLength (width);
|
||||
}
|
||||
|
||||
return widget;
|
||||
}
|
||||
|
||||
void CSVSettings::ListView::showEvent ( QShowEvent * event )
|
||||
{
|
||||
View::showEvent (event);
|
||||
}
|
||||
|
||||
void CSVSettings::ListView::updateView (bool signalUpdate) const
|
||||
{
|
||||
QStringList values = selectedValues();
|
||||
|
||||
if (mComboBox)
|
||||
{
|
||||
int idx = -1;
|
||||
|
||||
if (values.size() > 0)
|
||||
idx = (mComboBox->findText(values.at(0)));
|
||||
|
||||
mComboBox->setCurrentIndex (idx);
|
||||
}
|
||||
|
||||
View::updateView (signalUpdate);
|
||||
}
|
||||
|
||||
CSVSettings::ListView *CSVSettings::ListViewFactory::createView
|
||||
(CSMSettings::Setting *setting,
|
||||
Page *parent)
|
||||
{
|
||||
return new ListView(setting, parent);
|
||||
}
|
@ -1,63 +0,0 @@
|
||||
#ifndef CSVSETTINGS_LISTVIEW_HPP
|
||||
#define CSVSETTINGS_LISTVIEW_HPP
|
||||
|
||||
#include "view.hpp"
|
||||
|
||||
|
||||
class QStringListModel;
|
||||
class QComboBox;
|
||||
class QAbstractItemView;
|
||||
|
||||
namespace CSVSettings
|
||||
{
|
||||
class ListView : public View
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
QAbstractItemView *mAbstractItemView;
|
||||
QComboBox *mComboBox;
|
||||
|
||||
public:
|
||||
explicit ListView (CSMSettings::Setting *setting,
|
||||
Page *parent);
|
||||
|
||||
protected:
|
||||
|
||||
void updateView (bool signalUpdate = true) const;
|
||||
void showEvent ( QShowEvent * event );
|
||||
|
||||
///Receives signal from widget and signals viwUpdated()
|
||||
void slotTextEdited (QString value);
|
||||
|
||||
private:
|
||||
|
||||
///Helper function to construct a model for an AbstractItemView
|
||||
void buildAbstractItemViewModel();
|
||||
|
||||
///Helper function to construct a model for a combobox
|
||||
void buildComboBoxModel();
|
||||
|
||||
///Helper function to build the view widget
|
||||
QWidget *buildWidget (bool isMultiLine, int width);
|
||||
|
||||
private slots:
|
||||
|
||||
///Receives updates from single-select widgets (like combobox) and
|
||||
///signals viewUpdated with the selected values.
|
||||
void emitItemViewUpdate (int idx);
|
||||
};
|
||||
|
||||
class ListViewFactory : public QObject, public IViewFactory
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit ListViewFactory (QWidget *parent = 0)
|
||||
: QObject (parent)
|
||||
{}
|
||||
|
||||
ListView *createView (CSMSettings::Setting *setting,
|
||||
Page *parent);
|
||||
};
|
||||
}
|
||||
#endif // CSVSETTINGS_LISTVIEW_HPP
|
@ -1,110 +0,0 @@
|
||||
#include "page.hpp"
|
||||
|
||||
#include <QLabel>
|
||||
|
||||
#include "view.hpp"
|
||||
#include "booleanview.hpp"
|
||||
#include "textview.hpp"
|
||||
#include "listview.hpp"
|
||||
#include "rangeview.hpp"
|
||||
|
||||
#include "../../model/settings/usersettings.hpp"
|
||||
#include "../../model/settings/connector.hpp"
|
||||
#include "../../model/settings/support.hpp"
|
||||
|
||||
#include "settingwindow.hpp"
|
||||
|
||||
QMap <CSVSettings::ViewType, CSVSettings::IViewFactory *>
|
||||
CSVSettings::Page::mViewFactories;
|
||||
|
||||
CSVSettings::Page::Page (const QString &pageName, QList <CSMSettings::Setting *> settingList,
|
||||
SettingWindow *parent, const QString& label)
|
||||
: Frame(false, "", parent), mParent(parent), mIsEditorPage (false), mLabel (label)
|
||||
{
|
||||
setObjectName (pageName);
|
||||
|
||||
if (mViewFactories.size() == 0)
|
||||
buildFactories();
|
||||
|
||||
setVLayout();
|
||||
setupViews (settingList);
|
||||
}
|
||||
|
||||
void CSVSettings::Page::setupViews
|
||||
(QList <CSMSettings::Setting *> &settingList)
|
||||
{
|
||||
foreach (CSMSettings::Setting *setting, settingList)
|
||||
addView (setting);
|
||||
}
|
||||
|
||||
void CSVSettings::Page::addView (CSMSettings::Setting *setting)
|
||||
{
|
||||
if (setting->viewType() == ViewType_Undefined)
|
||||
{
|
||||
if(setting->specialValueText() != "")
|
||||
{
|
||||
// hack to put a label
|
||||
addWidget(new QLabel(setting->specialValueText()),
|
||||
setting->viewRow(), setting->viewColumn(),
|
||||
setting->rowSpan(), setting->columnSpan());
|
||||
return;
|
||||
}
|
||||
else
|
||||
return;
|
||||
}
|
||||
|
||||
View *view = mViewFactories[setting->viewType()]->createView(setting, this);
|
||||
|
||||
if (!view)
|
||||
return;
|
||||
|
||||
mViews.append (view);
|
||||
|
||||
addWidget (view, setting->viewRow(), setting->viewColumn(),
|
||||
setting->rowSpan(), setting->columnSpan() );
|
||||
|
||||
//if this page is an editor page, connect each of it's views up to the
|
||||
//UserSettings singleton for signaling back to OpenCS
|
||||
if (setting->isEditorSetting()) {
|
||||
connect (view, SIGNAL (viewUpdated(const QString&, const QStringList&)),
|
||||
&CSMSettings::UserSettings::instance(),
|
||||
SLOT (updateUserSetting (const QString &, const QStringList &)));
|
||||
}
|
||||
}
|
||||
|
||||
CSVSettings::View *CSVSettings::Page::findView (const QString &page,
|
||||
const QString &setting) const
|
||||
{
|
||||
|
||||
//if this is not the page we're looking for,
|
||||
//appeal to the parent setting window to find the appropriate view
|
||||
if (page != objectName())
|
||||
return mParent->findView (page, setting);
|
||||
|
||||
//otherwise, return the matching view
|
||||
for (int i = 0; i < mViews.size(); i++)
|
||||
{
|
||||
View *view = mViews.at(i);
|
||||
|
||||
if (view->parentPage()->objectName() != page)
|
||||
continue;
|
||||
|
||||
if (view->objectName() == setting)
|
||||
return view;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void CSVSettings::Page::buildFactories()
|
||||
{
|
||||
mViewFactories[ViewType_Boolean] = new BooleanViewFactory (this);
|
||||
mViewFactories[ViewType_Text] = new TextViewFactory (this);
|
||||
mViewFactories[ViewType_List] = new ListViewFactory (this);
|
||||
mViewFactories[ViewType_Range] = new RangeViewFactory (this);
|
||||
}
|
||||
|
||||
QString CSVSettings::Page::getLabel() const
|
||||
{
|
||||
return mLabel;
|
||||
}
|
@ -1,56 +0,0 @@
|
||||
#ifndef CSVSETTINGS_PAGE_HPP
|
||||
#define CSVSETTINGS_PAGE_HPP
|
||||
|
||||
#include <QWidget>
|
||||
#include <QMap>
|
||||
#include <QList>
|
||||
|
||||
#include "frame.hpp"
|
||||
|
||||
#include "../../model/settings/support.hpp"
|
||||
|
||||
namespace CSMSettings { class Setting; }
|
||||
|
||||
namespace CSVSettings
|
||||
{
|
||||
class View;
|
||||
class IViewFactory;
|
||||
class SettingWindow;
|
||||
|
||||
class Page : public Frame
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
QList<View *> mViews;
|
||||
SettingWindow *mParent;
|
||||
static QMap <ViewType, IViewFactory *> mViewFactories;
|
||||
bool mIsEditorPage;
|
||||
QString mLabel;
|
||||
|
||||
public:
|
||||
Page (const QString &pageName, QList <CSMSettings::Setting *> settingList,
|
||||
SettingWindow *parent, const QString& label);
|
||||
|
||||
///Creates a new view based on the passed setting and adds it to
|
||||
///the page.
|
||||
void addView (CSMSettings::Setting *setting);
|
||||
|
||||
///Iterates the views created for this page based on the passed setting
|
||||
///and returns it.
|
||||
View *findView (const QString &page, const QString &setting) const;
|
||||
|
||||
///returns the list of views associated with the page
|
||||
const QList <View *> &views () const { return mViews; }
|
||||
|
||||
QString getLabel() const;
|
||||
|
||||
private:
|
||||
|
||||
///Creates views based on the passed setting list
|
||||
void setupViews (QList <CSMSettings::Setting *> &settingList);
|
||||
|
||||
///Creates factory objects for view construction
|
||||
void buildFactories();
|
||||
};
|
||||
}
|
||||
#endif // CSVSETTINGS_PAGE_HPP
|
@ -1,208 +0,0 @@
|
||||
#include <QSpinBox>
|
||||
#include <QDoubleSpinBox>
|
||||
#include <QAbstractSpinBox>
|
||||
#include <QAbstractSlider>
|
||||
#include <QDial>
|
||||
#include <QSlider>
|
||||
|
||||
#include "rangeview.hpp"
|
||||
#include "spinbox.hpp"
|
||||
#include "../../model/settings/setting.hpp"
|
||||
#include "../../model/settings/support.hpp"
|
||||
|
||||
CSVSettings::RangeView::RangeView (CSMSettings::Setting *setting,
|
||||
Page *parent)
|
||||
: View (setting, parent), mRangeWidget (0), mRangeType (setting->type())
|
||||
{
|
||||
|
||||
mRangeWidget = 0;
|
||||
|
||||
if (isMultiValue())
|
||||
return;
|
||||
|
||||
switch (mRangeType)
|
||||
{
|
||||
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(mRangeWidget)
|
||||
{
|
||||
mRangeWidget->setFixedWidth (widgetWidth (setting->widgetWidth()));
|
||||
mRangeWidget->setObjectName (setting->name());
|
||||
}
|
||||
|
||||
addWidget (mRangeWidget);
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
case CSMSettings::Type_Dial:
|
||||
mRangeWidget = new QDial (this);
|
||||
mRangeWidget->setProperty ("wrapping", setting->wrapping());
|
||||
mRangeWidget->setProperty ("notchesVisible",
|
||||
(setting->ticksAbove() || setting->ticksBelow()));
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if(mRangeWidget)
|
||||
{
|
||||
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::buildSpinBox (CSMSettings::Setting *setting)
|
||||
{
|
||||
SpinBox *sb = 0;
|
||||
|
||||
switch (setting->type())
|
||||
{
|
||||
case CSMSettings::Type_SpinBox:
|
||||
|
||||
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:
|
||||
return;
|
||||
}
|
||||
|
||||
//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 ("prefix", setting->prefix());
|
||||
mRangeWidget->setProperty ("suffix", setting->suffix());
|
||||
mRangeWidget->setProperty ("wrapping", setting->wrapping());
|
||||
dynamic_cast<QAbstractSpinBox *> (mRangeWidget)->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter);
|
||||
|
||||
if(setting->type() == CSMSettings::Type_SpinBox && setting->declaredValues().isEmpty())
|
||||
dynamic_cast<QSpinBox *> (mRangeWidget)->setValue (setting->defaultValues().at(0).toInt());
|
||||
}
|
||||
|
||||
void CSVSettings::RangeView::slotUpdateView (int value)
|
||||
{
|
||||
QString textValue = "";
|
||||
QStringList list;
|
||||
|
||||
switch (mRangeType)
|
||||
{
|
||||
case CSMSettings::Type_SpinBox:
|
||||
list = static_cast <SpinBox *> (mRangeWidget)->valueList();
|
||||
if (!list.isEmpty())
|
||||
textValue = list.at(value);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
void CSVSettings::RangeView::updateView (bool signalUpdate) const
|
||||
{
|
||||
QString value;
|
||||
|
||||
if (!selectedValues().isEmpty())
|
||||
value = selectedValues().at(0);
|
||||
|
||||
switch (mRangeType)
|
||||
{
|
||||
case CSMSettings::Type_SpinBox:
|
||||
static_cast <SpinBox *> (mRangeWidget)->setValue (value);
|
||||
break;
|
||||
|
||||
case CSMSettings::Type_DoubleSpinBox:
|
||||
static_cast <QDoubleSpinBox *> (mRangeWidget)->setValue (value.toDouble());
|
||||
break;
|
||||
|
||||
case CSMSettings::Type_Slider:
|
||||
case CSMSettings::Type_Dial:
|
||||
mRangeWidget->setProperty ("value", value.toInt());
|
||||
mRangeWidget->setProperty ("sliderPosition", value.toInt());
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
View::updateView (signalUpdate);
|
||||
}
|
||||
|
||||
CSVSettings::RangeView *CSVSettings::RangeViewFactory::createView
|
||||
(CSMSettings::Setting *setting,
|
||||
Page *parent)
|
||||
{
|
||||
return new RangeView (setting, parent);
|
||||
}
|
@ -1,55 +0,0 @@
|
||||
#ifndef CSVSETTINGS_RANGEVIEW_HPP
|
||||
#define CSVSETTINGS_RANGEVIEW_HPP
|
||||
|
||||
#include "view.hpp"
|
||||
#include "../../model/settings/support.hpp"
|
||||
|
||||
class QStringListModel;
|
||||
class QAbstractSpinBox;
|
||||
|
||||
namespace CSVSettings
|
||||
{
|
||||
class RangeView : public View
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
QWidget *mRangeWidget;
|
||||
CSMSettings::SettingType mRangeType;
|
||||
|
||||
public:
|
||||
explicit RangeView (CSMSettings::Setting *setting,
|
||||
Page *parent);
|
||||
|
||||
protected:
|
||||
|
||||
///virtual function called through View
|
||||
void updateView (bool signalUpdate = true) const;
|
||||
|
||||
///construct a slider-based view
|
||||
void buildSlider (CSMSettings::Setting *setting);
|
||||
|
||||
///construct a spinbox-based view
|
||||
void buildSpinBox (CSMSettings::Setting *setting);
|
||||
|
||||
private slots:
|
||||
|
||||
///responds to valueChanged signals
|
||||
void slotUpdateView (int value);
|
||||
void slotUpdateView (double value);
|
||||
|
||||
};
|
||||
|
||||
class RangeViewFactory : public QObject, public IViewFactory
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit RangeViewFactory (QWidget *parent = 0)
|
||||
: QObject (parent)
|
||||
{}
|
||||
|
||||
RangeView *createView (CSMSettings::Setting *setting,
|
||||
Page *parent);
|
||||
};
|
||||
}
|
||||
#endif // CSVSETTINGS_RANGEVIEW_HPP
|
@ -1,39 +0,0 @@
|
||||
#include "resizeablestackedwidget.hpp"
|
||||
#include "page.hpp"
|
||||
|
||||
#include <QListWidgetItem>
|
||||
|
||||
CSVSettings::ResizeableStackedWidget::ResizeableStackedWidget(QWidget *parent) :
|
||||
QStackedWidget(parent)
|
||||
{}
|
||||
|
||||
void CSVSettings::ResizeableStackedWidget::addWidget(QWidget* pWidget)
|
||||
{
|
||||
QStackedWidget::addWidget(pWidget);
|
||||
}
|
||||
|
||||
void CSVSettings::ResizeableStackedWidget::changePage
|
||||
(int current, int previous)
|
||||
{
|
||||
if (current == previous)
|
||||
return;
|
||||
|
||||
Page *prevPage = 0;
|
||||
Page *curPage = 0;
|
||||
|
||||
if (previous > -1)
|
||||
prevPage = static_cast <Page *> (widget (previous));
|
||||
|
||||
if (current > -1)
|
||||
curPage = static_cast <Page *> (widget (current));
|
||||
|
||||
if (prevPage)
|
||||
prevPage->hideWidgets();
|
||||
|
||||
if (curPage)
|
||||
curPage->showWidgets();
|
||||
|
||||
layout()->activate();
|
||||
|
||||
setCurrentIndex (current);
|
||||
}
|
@ -1,25 +0,0 @@
|
||||
#ifndef CSVSETTINGS_RESIZEABLESTACKEDWIDGET_HPP
|
||||
#define CSVSETTINGS_RESIZEABLESTACKEDWIDGET_HPP
|
||||
|
||||
#include <QStackedWidget>
|
||||
|
||||
class QListWidgetItem;
|
||||
|
||||
namespace CSVSettings
|
||||
{
|
||||
class ResizeableStackedWidget : public QStackedWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit ResizeableStackedWidget(QWidget *parent = 0);
|
||||
|
||||
///add a widget to the stacked widget
|
||||
void addWidget(QWidget* pWidget);
|
||||
|
||||
///called whenever the stacked widget page is changed
|
||||
void changePage (int, int);
|
||||
};
|
||||
}
|
||||
|
||||
#endif // CSVSETTINGS_RESIZEABLESTACKEDWIDGET_HPP
|
@ -1,131 +0,0 @@
|
||||
#include <QApplication>
|
||||
#include <QDebug>
|
||||
|
||||
#include "../../model/settings/setting.hpp"
|
||||
#include "../../model/settings/connector.hpp"
|
||||
#include "../../model/settings/usersettings.hpp"
|
||||
#include "settingwindow.hpp"
|
||||
#include "page.hpp"
|
||||
#include "view.hpp"
|
||||
|
||||
CSVSettings::SettingWindow::SettingWindow(QWidget *parent)
|
||||
: QMainWindow(parent), mModel(NULL)
|
||||
{}
|
||||
|
||||
void CSVSettings::SettingWindow::createPages()
|
||||
{
|
||||
CSMSettings::SettingPageMap pageMap = mModel->settingPageMap();
|
||||
|
||||
QList <CSMSettings::Setting *> connectedSettings;
|
||||
|
||||
foreach (const QString &pageName, pageMap.keys())
|
||||
{
|
||||
QList <CSMSettings::Setting *> pageSettings = pageMap.value (pageName).second;
|
||||
|
||||
mPages.append (new Page (pageName, pageSettings, this, pageMap.value (pageName).first));
|
||||
|
||||
for (int i = 0; i < pageSettings.size(); i++)
|
||||
{
|
||||
CSMSettings::Setting *setting = pageSettings.at(i);
|
||||
|
||||
if (!setting->proxyLists().isEmpty())
|
||||
connectedSettings.append (setting);
|
||||
}
|
||||
}
|
||||
|
||||
if (!connectedSettings.isEmpty())
|
||||
createConnections(connectedSettings);
|
||||
}
|
||||
|
||||
void CSVSettings::SettingWindow::createConnections
|
||||
(const QList <CSMSettings::Setting *> &list)
|
||||
{
|
||||
foreach (const CSMSettings::Setting *setting, list)
|
||||
{
|
||||
View *masterView = findView (setting->page(), setting->name());
|
||||
|
||||
CSMSettings::Connector *connector =
|
||||
new CSMSettings::Connector (masterView, this);
|
||||
|
||||
connect (masterView,
|
||||
SIGNAL (viewUpdated(const QString &, const QStringList &)),
|
||||
connector,
|
||||
SLOT (slotUpdateSlaves())
|
||||
);
|
||||
|
||||
const CSMSettings::ProxyValueMap &proxyMap = setting->proxyLists();
|
||||
|
||||
foreach (const QString &key, proxyMap.keys())
|
||||
{
|
||||
QStringList keyPair = key.split('/');
|
||||
|
||||
if (keyPair.size() != 2)
|
||||
continue;
|
||||
|
||||
View *slaveView = findView (keyPair.at(0), keyPair.at(1));
|
||||
|
||||
if (!slaveView)
|
||||
{
|
||||
qWarning () << "Unable to create connection for view "
|
||||
<< key;
|
||||
continue;
|
||||
}
|
||||
|
||||
QList <QStringList> proxyList = proxyMap.value (key);
|
||||
connector->addSlaveView (slaveView, proxyList);
|
||||
|
||||
connect (slaveView,
|
||||
SIGNAL (viewUpdated(const QString &, const QStringList &)),
|
||||
connector,
|
||||
SLOT (slotUpdateMaster()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CSVSettings::SettingWindow::setViewValues()
|
||||
{
|
||||
//iterate each page and view, setting their definitions
|
||||
//if they exist in the model
|
||||
foreach (const Page *page, mPages)
|
||||
{
|
||||
foreach (const View *view, page->views())
|
||||
{
|
||||
//testing beforehand prevents overwriting a proxy setting
|
||||
if (!mModel->hasSettingDefinitions (view->viewKey()))
|
||||
continue;
|
||||
|
||||
QStringList defs = mModel->definitions (view->viewKey());
|
||||
|
||||
view->setSelectedValues(defs);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
CSVSettings::View *CSVSettings::SettingWindow::findView
|
||||
(const QString &pageName, const QString &setting)
|
||||
{
|
||||
foreach (const Page *page, mPages)
|
||||
{
|
||||
if (page->objectName() == pageName)
|
||||
return page->findView (pageName, setting);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void CSVSettings::SettingWindow::saveSettings()
|
||||
{
|
||||
//setting the definition in the model automatically syncs with the file
|
||||
foreach (const Page *page, mPages)
|
||||
{
|
||||
foreach (const View *view, page->views())
|
||||
{
|
||||
if (!view->serializable())
|
||||
continue;
|
||||
|
||||
mModel->setDefinitions (view->viewKey(), view->selectedValues());
|
||||
}
|
||||
}
|
||||
|
||||
mModel->saveDefinitions();
|
||||
}
|
||||
|
@ -1,58 +0,0 @@
|
||||
#ifndef CSVSETTINGS_SETTINGWINDOW_HPP
|
||||
#define CSVSETTINGS_SETTINGWINDOW_HPP
|
||||
|
||||
#include <QMainWindow>
|
||||
#include <QList>
|
||||
|
||||
#include "../../model/settings/support.hpp"
|
||||
|
||||
namespace CSMSettings {
|
||||
class Setting;
|
||||
class UserSettings;
|
||||
}
|
||||
|
||||
namespace CSVSettings {
|
||||
|
||||
class Page;
|
||||
class View;
|
||||
|
||||
typedef QList <Page *> PageList;
|
||||
|
||||
class SettingWindow : public QMainWindow
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
PageList mPages;
|
||||
CSMSettings::UserSettings *mModel;
|
||||
|
||||
public:
|
||||
explicit SettingWindow(QWidget *parent = 0);
|
||||
|
||||
///retrieve a reference to a view based on it's page and setting name
|
||||
View *findView (const QString &pageName, const QString &setting);
|
||||
|
||||
///set the model the view uses (instance of UserSettings)
|
||||
void setModel (CSMSettings::UserSettings &model) { mModel = &model; }
|
||||
|
||||
protected:
|
||||
|
||||
///construct the pages to be displayed in the dialog
|
||||
void createPages();
|
||||
|
||||
///return the list of constructed pages
|
||||
const PageList &pages() const { return mPages; }
|
||||
|
||||
///save settings from the GUI to file
|
||||
void saveSettings();
|
||||
|
||||
///sets the defined values for the views that have been created
|
||||
void setViewValues();
|
||||
|
||||
private:
|
||||
|
||||
///create connections between settings (used for proxy settings)
|
||||
void createConnections (const QList <CSMSettings::Setting *> &list);
|
||||
};
|
||||
}
|
||||
|
||||
#endif // CSVSETTINGS_SETTINGWINDOW_HPP
|
@ -1,50 +0,0 @@
|
||||
#include "spinbox.hpp"
|
||||
|
||||
#include <QLineEdit>
|
||||
|
||||
CSVSettings::SpinBox::SpinBox(QWidget *parent)
|
||||
: QSpinBox(parent), mValueList(QStringList())
|
||||
{
|
||||
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 text.toInt(); // TODO: assumed integer, untested error handling for alpha types
|
||||
|
||||
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);
|
||||
}
|
@ -1,38 +0,0 @@
|
||||
#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);
|
||||
|
||||
///set the value displayed in the spin box
|
||||
void setValue (const QString &value);
|
||||
|
||||
///set the stringlist that's used as a list of pre-defined values
|
||||
///to be displayed as the user scrolls
|
||||
void setValueList (const QStringList &list);
|
||||
|
||||
///returns the pre-defined value list.
|
||||
const QStringList &valueList() const { return mValueList; }
|
||||
|
||||
protected:
|
||||
|
||||
///converts an index value to corresponding text to be displayed
|
||||
QString textFromValue (int val) const;
|
||||
|
||||
///converts a text value to a corresponding index
|
||||
int valueFromText (const QString &text) const;
|
||||
};
|
||||
}
|
||||
#endif // CSVSETTINGS_SPINBOX_HPP
|
@ -1,63 +0,0 @@
|
||||
#include <QTextEdit>
|
||||
#include <QLineEdit>
|
||||
|
||||
#include "textview.hpp"
|
||||
#include "../../model/settings/setting.hpp"
|
||||
|
||||
CSVSettings::TextView::TextView(CSMSettings::Setting *setting, Page *parent)
|
||||
: View (setting, parent), mDelimiter (setting->delimiter())
|
||||
|
||||
{
|
||||
if (setting->isMultiLine())
|
||||
mTextWidget = new QTextEdit ("", this);
|
||||
else
|
||||
mTextWidget = new QLineEdit ("", this);
|
||||
|
||||
if (setting->widgetWidth() > 0)
|
||||
mTextWidget->setFixedWidth (widgetWidth (setting->widgetWidth()));
|
||||
|
||||
connect (mTextWidget, SIGNAL (textEdited (QString)),
|
||||
this, SLOT (slotTextEdited (QString)));
|
||||
|
||||
addWidget (mTextWidget, setting->viewRow(), setting->viewColumn());
|
||||
}
|
||||
|
||||
bool CSVSettings::TextView::isEquivalent
|
||||
(const QString &lhs, const QString &rhs) const
|
||||
{
|
||||
return (lhs.trimmed() == rhs.trimmed());
|
||||
}
|
||||
|
||||
void CSVSettings::TextView::slotTextEdited (QString value)
|
||||
{
|
||||
QStringList values = value.split (mDelimiter, QString::SkipEmptyParts);
|
||||
|
||||
QStringList returnValues;
|
||||
|
||||
foreach (const QString &splitValue, values)
|
||||
returnValues.append (splitValue.trimmed());
|
||||
|
||||
setSelectedValues (returnValues, false);
|
||||
|
||||
View::updateView();
|
||||
}
|
||||
|
||||
void CSVSettings::TextView::updateView(bool signalUpdate) const
|
||||
{
|
||||
QString values = selectedValues().join (mDelimiter);
|
||||
|
||||
if (isEquivalent (mTextWidget->property("text").toString(), values))
|
||||
return;
|
||||
|
||||
mTextWidget->setProperty("text", values);
|
||||
|
||||
View::updateView (signalUpdate);
|
||||
}
|
||||
|
||||
CSVSettings::TextView *CSVSettings::TextViewFactory::createView
|
||||
(CSMSettings::Setting *setting,
|
||||
Page *parent)
|
||||
{
|
||||
return new TextView (setting, parent);
|
||||
}
|
||||
|
@ -1,51 +0,0 @@
|
||||
#ifndef CSVSETTINGS_TEXTVIEW_HPP
|
||||
#define CSVSETTINGS_TEXTVIEW_HPP
|
||||
|
||||
#include "view.hpp"
|
||||
#include "../../model/settings/setting.hpp"
|
||||
|
||||
namespace CSVSettings
|
||||
{
|
||||
class TextView : public View
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
QWidget *mTextWidget;
|
||||
|
||||
QString mDelimiter;
|
||||
|
||||
public:
|
||||
explicit TextView (CSMSettings::Setting *setting,
|
||||
Page *parent = 0);
|
||||
|
||||
protected:
|
||||
|
||||
/// virtual function called through View
|
||||
void updateView (bool signalUpdate = true) const;
|
||||
|
||||
protected slots:
|
||||
|
||||
///Receives updates to the widget for signalling
|
||||
void slotTextEdited (QString value);
|
||||
|
||||
private:
|
||||
|
||||
///Comparison function that returns true if the trimmed() strings
|
||||
///are equal
|
||||
bool isEquivalent (const QString &lhs, const QString &rhs) const;
|
||||
};
|
||||
|
||||
class TextViewFactory : public QObject, public IViewFactory
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit TextViewFactory (QWidget *parent = 0)
|
||||
: QObject (parent)
|
||||
{}
|
||||
|
||||
TextView *createView (CSMSettings::Setting *setting,
|
||||
Page *parent);
|
||||
};
|
||||
}
|
||||
#endif // CSVSETTINGS_TEXTVIEW_HPP
|
@ -1,222 +0,0 @@
|
||||
#include <QStandardItemModel>
|
||||
#include <QStandardItem>
|
||||
#include <QApplication>
|
||||
#include <QItemSelectionModel>
|
||||
#include <QStringListModel>
|
||||
|
||||
#include "view.hpp"
|
||||
#include "../../model/settings/support.hpp"
|
||||
#include "../../model/settings/setting.hpp"
|
||||
#include "page.hpp"
|
||||
|
||||
CSVSettings::View::View(CSMSettings::Setting *setting,
|
||||
Page *parent)
|
||||
|
||||
: Frame(true, setting->getLabel(), parent),
|
||||
mParentPage (parent), mDataModel(0),
|
||||
mHasFixedValues (!setting->declaredValues().isEmpty()),
|
||||
mIsMultiValue (setting->isMultiValue()),
|
||||
mViewKey (setting->page() + '/' + setting->name()),
|
||||
mSerializable (setting->serializable())
|
||||
{
|
||||
if (!setting->getToolTip().isEmpty())
|
||||
setToolTip (setting->getToolTip());
|
||||
|
||||
setObjectName (setting->name());
|
||||
buildView();
|
||||
buildModel (setting);
|
||||
// apply stylesheet to view's frame if exists
|
||||
if(setting->styleSheet() != "")
|
||||
Frame::setStyleSheet (setting->styleSheet());
|
||||
}
|
||||
|
||||
void CSVSettings::View::buildModel (const CSMSettings::Setting *setting)
|
||||
{
|
||||
QStringList values = setting->defaultValues();
|
||||
|
||||
if (mHasFixedValues)
|
||||
buildFixedValueModel (setting->declaredValues());
|
||||
else
|
||||
buildUpdatableValueModel (values);
|
||||
|
||||
mSelectionModel = new QItemSelectionModel (mDataModel, this);
|
||||
|
||||
setSelectedValues (values, false);
|
||||
}
|
||||
|
||||
void CSVSettings::View::buildFixedValueModel (const QStringList &values)
|
||||
{
|
||||
//fixed value models are simple string list models, since they are read-only
|
||||
mDataModel = new QStringListModel (values, this);
|
||||
}
|
||||
|
||||
void CSVSettings::View::buildUpdatableValueModel (const QStringList &values)
|
||||
{
|
||||
//updateable models are standard item models because they support
|
||||
//replacing entire columns
|
||||
QList <QStandardItem *> itemList;
|
||||
|
||||
foreach (const QString &value, values)
|
||||
itemList.append (new QStandardItem(value));
|
||||
|
||||
QStandardItemModel *model = new QStandardItemModel (this);
|
||||
model->appendColumn (itemList);
|
||||
|
||||
mDataModel = model;
|
||||
}
|
||||
|
||||
void CSVSettings::View::buildView()
|
||||
{
|
||||
setFlat (true);
|
||||
setHLayout();
|
||||
}
|
||||
|
||||
int CSVSettings::View::currentIndex () const
|
||||
{
|
||||
if (selectedValues().isEmpty())
|
||||
return -1;
|
||||
|
||||
QString currentValue = selectedValues().at(0);
|
||||
|
||||
for (int i = 0; i < mDataModel->rowCount(); i++)
|
||||
if (value(i) == currentValue)
|
||||
return i;
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
void CSVSettings::View::refresh() const
|
||||
{
|
||||
select (mSelectionModel->selection());
|
||||
updateView();
|
||||
}
|
||||
|
||||
int CSVSettings::View::rowCount() const
|
||||
{
|
||||
return mDataModel->rowCount();
|
||||
}
|
||||
|
||||
void CSVSettings::View::select (const QItemSelection &selection) const
|
||||
{
|
||||
mSelectionModel->clear();
|
||||
mSelectionModel->select(selection, QItemSelectionModel::Select);
|
||||
}
|
||||
|
||||
QStringList CSVSettings::View::selectedValues() const
|
||||
{
|
||||
QStringList selValues;
|
||||
|
||||
foreach (const QModelIndex &idx, mSelectionModel->selectedIndexes())
|
||||
selValues.append (value(idx.row()));
|
||||
|
||||
return selValues;
|
||||
}
|
||||
|
||||
void CSVSettings::View::setSelectedValue (const QString &value,
|
||||
bool doViewUpdate, bool signalUpdate)
|
||||
{
|
||||
setSelectedValues (QStringList() << value, doViewUpdate, signalUpdate);
|
||||
}
|
||||
|
||||
void CSVSettings::View::setSelectedValues (const QStringList &list,
|
||||
bool doViewUpdate, bool signalUpdate) const
|
||||
{
|
||||
QItemSelection selection;
|
||||
|
||||
if (stringListsMatch (list, selectedValues()))
|
||||
return;
|
||||
|
||||
if (!mHasFixedValues)
|
||||
{
|
||||
QStandardItemModel *model =
|
||||
static_cast <QStandardItemModel *>(mDataModel);
|
||||
|
||||
model->clear();
|
||||
model->appendColumn (toStandardItemList (list));
|
||||
|
||||
for (int i = 0; i < model->rowCount(); i++)
|
||||
{
|
||||
QModelIndex idx = model->index(i, 0);
|
||||
selection.append (QItemSelectionRange (idx, idx));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = 0; i < mDataModel->rowCount(); i++)
|
||||
{
|
||||
if (list.contains(value(i)))
|
||||
{
|
||||
QModelIndex idx = mDataModel->index(i, 0);
|
||||
selection.append(QItemSelectionRange (idx, idx));
|
||||
}
|
||||
}
|
||||
}
|
||||
select (selection);
|
||||
|
||||
//update the view if the selection was set from the model side, not by the
|
||||
//user
|
||||
if (doViewUpdate)
|
||||
updateView (signalUpdate);
|
||||
}
|
||||
|
||||
void CSVSettings::View::showEvent ( QShowEvent * event )
|
||||
{
|
||||
refresh();
|
||||
}
|
||||
|
||||
bool CSVSettings::View::stringListsMatch (
|
||||
const QStringList &list1,
|
||||
const QStringList &list2) const
|
||||
{
|
||||
//returns a "sloppy" match, verifying that each list contains all the same
|
||||
//items, though not necessarily in the same order.
|
||||
|
||||
if (list1.size() != list2.size())
|
||||
return false;
|
||||
|
||||
QStringList tempList(list2);
|
||||
|
||||
//iterate each value in the list, removing one occurrence of the value in
|
||||
//the other list. If no corresponding value is found, test fails
|
||||
foreach (const QString &value, list1)
|
||||
{
|
||||
if (!tempList.contains(value))
|
||||
return false;
|
||||
|
||||
tempList.removeOne(value);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
QList <QStandardItem *> CSVSettings::View::toStandardItemList
|
||||
(const QStringList &list) const
|
||||
{
|
||||
QList <QStandardItem *> itemList;
|
||||
|
||||
foreach (const QString &value, list)
|
||||
itemList.append (new QStandardItem (value));
|
||||
|
||||
return itemList;
|
||||
}
|
||||
|
||||
void CSVSettings::View::updateView (bool signalUpdate) const
|
||||
{
|
||||
if (signalUpdate)
|
||||
emit viewUpdated(viewKey(), selectedValues());
|
||||
}
|
||||
|
||||
QString CSVSettings::View::value (int row) const
|
||||
{
|
||||
if (row > -1 && row < mDataModel->rowCount())
|
||||
return mDataModel->data (mDataModel->index(row, 0)).toString();
|
||||
|
||||
return QString();
|
||||
}
|
||||
|
||||
int CSVSettings::View::widgetWidth(int characterCount) const
|
||||
{
|
||||
QString widthToken = QString().fill ('m', characterCount);
|
||||
QFontMetrics fm (QApplication::font());
|
||||
|
||||
return (fm.width (widthToken));
|
||||
}
|
@ -1,160 +0,0 @@
|
||||
#ifndef CSVSETTINGS_VIEW_HPP
|
||||
#define CSVSETTINGS_VIEW_HPP
|
||||
|
||||
#include <QWidget>
|
||||
#include <QList>
|
||||
|
||||
#include "frame.hpp"
|
||||
#include "../../model/settings/support.hpp"
|
||||
|
||||
class QGroupBox;
|
||||
class QStringList;
|
||||
class QStandardItem;
|
||||
class QItemSelection;
|
||||
class QAbstractItemModel;
|
||||
class QItemSelectionModel;
|
||||
|
||||
namespace CSMSettings { class Setting; }
|
||||
|
||||
namespace CSVSettings
|
||||
{
|
||||
class Page;
|
||||
|
||||
class View : public Frame
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
///Pointer to the owning Page instance
|
||||
Page *mParentPage;
|
||||
|
||||
///Pointer to the selection model for the view
|
||||
QItemSelectionModel *mSelectionModel;
|
||||
|
||||
///Pointer to the data model for the view's selection model
|
||||
QAbstractItemModel *mDataModel;
|
||||
|
||||
///State indicating whether or not the setting has a pre-defined list
|
||||
///of values, limiting possible definitions
|
||||
bool mHasFixedValues;
|
||||
|
||||
///State indicating whether the view will allow multiple values
|
||||
bool mIsMultiValue;
|
||||
|
||||
///'pagename.settingname' form of the view's id
|
||||
QString mViewKey;
|
||||
|
||||
///indicates whether or not the setting is written to file
|
||||
bool mSerializable;
|
||||
|
||||
public:
|
||||
|
||||
explicit View (CSMSettings::Setting *setting, Page *parent);
|
||||
|
||||
///Returns the index / row of the passed value, -1 if not found.
|
||||
int currentIndex () const;
|
||||
|
||||
///Returns the number of rows in the view's data model
|
||||
int rowCount() const;
|
||||
|
||||
///Returns bool indicating the data in this view should / should not
|
||||
///be serialized to a config file
|
||||
bool serializable() const { return mSerializable; }
|
||||
|
||||
///Returns a pointer to the view's owning parent page
|
||||
const Page *parentPage() const { return mParentPage; }
|
||||
|
||||
///Returns the selected items in the selection model as a QStringList
|
||||
QStringList selectedValues() const;
|
||||
|
||||
///Sets the selected items in the selection model based on passed list.
|
||||
///Bools allow opt-out of updating the view
|
||||
///or signaling the view was updatedto avoid viscious cylcing.
|
||||
void setSelectedValues (const QStringList &values,
|
||||
bool updateView = true,
|
||||
bool signalUpdate = true) const;
|
||||
|
||||
void setSelectedValue (const QString &value,
|
||||
bool updateView = true,
|
||||
bool signalUpdate = true);
|
||||
|
||||
|
||||
///Returns the value of the data model at the specified row
|
||||
QString value (int row) const;
|
||||
|
||||
QString viewKey() const { return mViewKey; }
|
||||
|
||||
protected:
|
||||
|
||||
/// Returns the model which provides data for the selection model
|
||||
QAbstractItemModel *dataModel() { return mDataModel; }
|
||||
|
||||
///Accessor function for subclasses
|
||||
bool isMultiValue() { return mIsMultiValue; }
|
||||
|
||||
///Returns the view selection model
|
||||
QItemSelectionModel *selectionModel() { return mSelectionModel;}
|
||||
|
||||
///Global callback for basic view initialization
|
||||
void showEvent ( QShowEvent * event );
|
||||
|
||||
///Virtual for updating a specific View subclass
|
||||
///bool indicates whether viewUpdated() signal is emitted
|
||||
virtual void updateView (bool signalUpdate = true) const;
|
||||
|
||||
///Returns the pixel width corresponding to the specified number of
|
||||
///characters.
|
||||
int widgetWidth(int characterCount) const;
|
||||
|
||||
private:
|
||||
|
||||
///Constructs the view layout
|
||||
void buildView();
|
||||
|
||||
///Constructs the data and selection models
|
||||
void buildModel (const CSMSettings::Setting *setting);
|
||||
|
||||
///In cases where the view has a pre-defined list of possible values,
|
||||
///a QStringListModel is created using those values.
|
||||
///View changes operate on the selection model only.
|
||||
void buildFixedValueModel (const QStringList &definitions);
|
||||
|
||||
///In cases where the view does not have a pre-defined list of possible
|
||||
///values, a QStandardItemModel is created, containing the actual
|
||||
///setting definitions. View changes first update the data in the
|
||||
///model to match the data in the view. The selection model always
|
||||
///selects all values.
|
||||
void buildUpdatableValueModel (const QStringList &definitions);
|
||||
|
||||
///Refreshes the view
|
||||
void refresh() const;
|
||||
|
||||
///Convenince function for selection model's select() method. Also
|
||||
///clears out the model beforehand to ensure complete selection.
|
||||
void select (const QItemSelection &selection) const;
|
||||
|
||||
///Compares two string lists "loosely", ensuring that all values in
|
||||
///one list are contained entirely in the other, and that neither list
|
||||
///has more values than the other. List order is not considered.
|
||||
bool stringListsMatch (const QStringList &list1,
|
||||
const QStringList &list2) const;
|
||||
|
||||
///Converts a string list to a list of QStandardItem pointers.
|
||||
QList <QStandardItem *> toStandardItemList(const QStringList &) const;
|
||||
|
||||
signals:
|
||||
|
||||
///Signals that the view has been changed.
|
||||
void viewUpdated(const QString &, const QStringList &) const;
|
||||
|
||||
};
|
||||
|
||||
class IViewFactory
|
||||
{
|
||||
public:
|
||||
|
||||
///Creation interface for view factories
|
||||
virtual View *createView (CSMSettings::Setting *setting,
|
||||
Page *parent) = 0;
|
||||
};
|
||||
}
|
||||
#endif // CSVSETTINGS_VIEW_HPP
|
Loading…
Reference in New Issue