-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow to set inital persistant value of COs #559
Changes from all commits
ecbcf3f
4f4a2d6
4c43963
24dab04
5dc98ee
6c69502
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,7 +27,7 @@ ControlDoublePrivate::ControlDoublePrivate() | |
ControlDoublePrivate::ControlDoublePrivate(ConfigKey key, | ||
ControlObject* pCreatorCO, | ||
bool bIgnoreNops, bool bTrack, | ||
bool bPersist) | ||
double defaultValue, bool bPersist) | ||
: m_key(key), | ||
m_bPersistInConfiguration(bPersist), | ||
m_bIgnoreNops(bIgnoreNops), | ||
|
@@ -38,20 +38,20 @@ ControlDoublePrivate::ControlDoublePrivate(ConfigKey key, | |
Stat::SAMPLE_VARIANCE | Stat::MIN | Stat::MAX), | ||
m_confirmRequired(false), | ||
m_pCreatorCO(pCreatorCO) { | ||
initialize(); | ||
initialize(defaultValue); | ||
} | ||
|
||
void ControlDoublePrivate::initialize() { | ||
double value = 0; | ||
void ControlDoublePrivate::initialize(double defaultValue) { | ||
m_defaultValue.setValue(defaultValue); | ||
double initalValue = defaultValue; | ||
if (m_bPersistInConfiguration) { | ||
ConfigObject<ConfigValue>* pConfig = ControlDoublePrivate::s_pUserConfig; | ||
if (pConfig != NULL) { | ||
// Assume toDouble() returns 0 if conversion fails. | ||
value = pConfig->getValueString(m_key).toDouble(); | ||
initalValue = pConfig->getValueString(m_key).toDouble(); | ||
} | ||
} | ||
m_defaultValue.setValue(0); | ||
m_value.setValue(value); | ||
m_value.setValue(initalValue); | ||
|
||
//qDebug() << "Creating:" << m_trackKey << "at" << &m_value << sizeof(m_value); | ||
|
||
|
@@ -101,7 +101,7 @@ void ControlDoublePrivate::insertAlias(const ConfigKey& alias, const ConfigKey& | |
// static | ||
QSharedPointer<ControlDoublePrivate> ControlDoublePrivate::getControl( | ||
const ConfigKey& key, bool warn, ControlObject* pCreatorCO, | ||
bool bIgnoreNops, bool bTrack, bool bPersist) { | ||
bool bIgnoreNops, bool bTrack, double defaulValue, bool bPersist) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. defaultValue |
||
if (key.isNull()) { | ||
if (warn) { | ||
qWarning() << "ControlDoublePrivate::getControl returning NULL" | ||
|
@@ -130,7 +130,7 @@ QSharedPointer<ControlDoublePrivate> ControlDoublePrivate::getControl( | |
if (pCreatorCO) { | ||
pControl = QSharedPointer<ControlDoublePrivate>( | ||
new ControlDoublePrivate(key, pCreatorCO, bIgnoreNops, | ||
bTrack, bPersist)); | ||
bTrack, defaulValue, bPersist)); | ||
locker.relock(); | ||
//qDebug() << "ControlDoublePrivate::s_qCOHash.insert(" << key.group << "," << key.item << ")"; | ||
s_qCOHash.insert(key, pControl); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,7 +36,7 @@ class ControlDoublePrivate : public QObject { | |
static QSharedPointer<ControlDoublePrivate> getControl( | ||
const ConfigKey& key, bool warn = true, | ||
ControlObject* pCreatorCO = NULL, bool bIgnoreNops = true, bool bTrack = false, | ||
bool bPersist = false); | ||
double defaultValue = 0.0, bool bPersist = false); | ||
|
||
// Adds all ControlDoublePrivate that currently exist to pControlList | ||
static void getControls(QList<QSharedPointer<ControlDoublePrivate> >* pControlsList); | ||
|
@@ -125,9 +125,12 @@ class ControlDoublePrivate : public QObject { | |
void valueChangeRequest(double value); | ||
|
||
private: | ||
// The defaultValue is adopted as initial value as well | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. // If bPersist is true and the configuration object is not null, |
||
// except it is a persistent CO with a saved value in place | ||
ControlDoublePrivate(ConfigKey key, ControlObject* pCreatorCO, | ||
bool bIgnoreNops, bool bTrack, bool bPersist); | ||
void initialize(); | ||
bool bIgnoreNops, bool bTrack, double defaultValue, | ||
bool bPersist); | ||
void initialize(double defaultValue); | ||
void setInner(double value, QObject* pSender); | ||
|
||
ConfigKey m_key; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,10 +33,12 @@ class ControlObject : public QObject { | |
|
||
// bIgnoreNops: Don't emit a signal if the CO is set to its current value. | ||
// bTrack: Record statistics about this control. | ||
// defaultValue: is adopted as initial value as well | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same as above |
||
// except it is a persistent CO with a saved value in place | ||
// bPersist: Store value on exit, load on startup. | ||
ControlObject(ConfigKey key, | ||
bool bIgnoreNops=true, bool bTrack=false, | ||
bool bPersist=false); | ||
double defaultValue = 0.0, bool bPersist=false); | ||
virtual ~ControlObject(); | ||
|
||
// Returns a pointer to the ControlObject matching the given ConfigKey | ||
|
@@ -164,7 +166,7 @@ class ControlObject : public QObject { | |
|
||
private: | ||
void initialize(ConfigKey key, bool bIgnoreNops, bool bTrack, | ||
bool bPersist); | ||
double defaultValue, bool bPersist); | ||
inline bool ignoreNops() const { | ||
return m_pControl ? m_pControl->ignoreNops() : true; | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -53,7 +53,8 @@ class ControlPushButton : public ControlObject { | |
} | ||
} | ||
|
||
ControlPushButton(ConfigKey key, bool bPersist=false); | ||
ControlPushButton(ConfigKey key, double defaulValue = 0.0, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. defaultValue |
||
bool bPersist = false); | ||
virtual ~ControlPushButton(); | ||
|
||
inline ButtonMode getButtonMode() const { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -83,7 +83,7 @@ QMutex LegacySkinParser::s_safeStringMutex; | |
|
||
static bool sDebug = false; | ||
|
||
ControlObject* controlFromConfigKey(ConfigKey key, bool bPersist, | ||
ControlObject* controlFromConfigKey(ConfigKey key, double defaulValue, bool bPersist, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. defaultValue |
||
bool* created) { | ||
ControlObject* pControl = ControlObject::getControl(key); | ||
|
||
|
@@ -100,7 +100,7 @@ ControlObject* controlFromConfigKey(ConfigKey key, bool bPersist, | |
<< "Creating it."; | ||
// Since the usual behavior here is to create a skin-defined push | ||
// button, actually make it a push button and set it to toggle. | ||
ControlPushButton* controlButton = new ControlPushButton(key, bPersist); | ||
ControlPushButton* controlButton = new ControlPushButton(key, defaulValue, bPersist); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. again |
||
controlButton->setButtonMode(ControlPushButton::TOGGLE); | ||
if (created) { | ||
*created = true; | ||
|
@@ -121,7 +121,7 @@ ControlObject* LegacySkinParser::controlFromConfigNode(QDomElement element, | |
|
||
bool bPersist = m_pContext->selectAttributeBool(keyElement, "persist", false); | ||
|
||
return controlFromConfigKey(key, bPersist, created); | ||
return controlFromConfigKey(key, 0.0, bPersist, created); | ||
} | ||
|
||
LegacySkinParser::LegacySkinParser(ConfigObject<ConfigValue>* pConfig, | ||
|
@@ -326,14 +326,8 @@ QWidget* LegacySkinParser::parseSkin(QString skinPath, QWidget* pParent) { | |
// If there is no existing value for this CO in the skin, | ||
// update the config with the specified value. If the attribute | ||
// is set to persist, the value will be read when the control is created. | ||
// TODO: This is a hack, but right now it's the cleanest way to | ||
// get a CO with a specified initial value. We should have a better | ||
// mechanism to provide initial default values for COs. | ||
if (attribute.persist() && | ||
m_pConfig->getValueString(configKey).isEmpty()) { | ||
m_pConfig->set(configKey, ConfigValue(QString::number(value))); | ||
} | ||
ControlObject* pControl = controlFromConfigKey(configKey, | ||
value, | ||
attribute.persist(), | ||
&created); | ||
if (created) { | ||
|
@@ -622,7 +616,7 @@ QWidget* LegacySkinParser::parseWidgetStack(QDomElement node) { | |
ConfigKey configKey = ConfigKey::parseCommaSeparated(currentpage_co); | ||
QString persist_co = node.attribute("persist"); | ||
bool persist = m_pContext->selectAttributeBool(node, "persist", false); | ||
pCurrentPageControl = controlFromConfigKey(configKey, persist, | ||
pCurrentPageControl = controlFromConfigKey(configKey, 0.0, persist, | ||
&createdCurrentPage); | ||
} | ||
|
||
|
@@ -684,7 +678,7 @@ QWidget* LegacySkinParser::parseWidgetStack(QDomElement node) { | |
if (trigger_configkey.length() > 0) { | ||
ConfigKey configKey = ConfigKey::parseCommaSeparated(trigger_configkey); | ||
bool created; | ||
pControl = controlFromConfigKey(configKey, false, &created); | ||
pControl = controlFromConfigKey(configKey, 0.0, false, &created); | ||
if (created) { | ||
// If we created the control, parent it to the child widget so | ||
// it doesn't leak. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
inital -> initial