|
@@ -35,15 +35,14 @@
|
|
|
|
|
|
|
|
namespace Rml {
|
|
namespace Rml {
|
|
|
|
|
|
|
|
-DataControllerValue::DataControllerValue(Element* element) : DataController(element)
|
|
|
|
|
|
|
+DataControllerValue::DataControllerValue(Element* element)
|
|
|
|
|
+ : DataController(element)
|
|
|
{}
|
|
{}
|
|
|
|
|
|
|
|
DataControllerValue::~DataControllerValue()
|
|
DataControllerValue::~DataControllerValue()
|
|
|
{
|
|
{
|
|
|
if (Element* element = GetElement())
|
|
if (Element* element = GetElement())
|
|
|
- {
|
|
|
|
|
element->RemoveEventListener(EventId::Change, this);
|
|
element->RemoveEventListener(EventId::Change, this);
|
|
|
- }
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
bool DataControllerValue::Initialize(DataModel& model, Element* element, const String& variable_name, const String& /*modifier*/)
|
|
bool DataControllerValue::Initialize(DataModel& model, Element* element, const String& variable_name, const String& /*modifier*/)
|
|
@@ -64,26 +63,27 @@ bool DataControllerValue::Initialize(DataModel& model, Element* element, const S
|
|
|
|
|
|
|
|
void DataControllerValue::ProcessEvent(Event& event)
|
|
void DataControllerValue::ProcessEvent(Event& event)
|
|
|
{
|
|
{
|
|
|
- if (Element* element = GetElement())
|
|
|
|
|
|
|
+ if (const Element* element = GetElement())
|
|
|
{
|
|
{
|
|
|
|
|
+ Variant value_to_set;
|
|
|
const auto& parameters = event.GetParameters();
|
|
const auto& parameters = event.GetParameters();
|
|
|
-
|
|
|
|
|
- auto it = parameters.find("value");
|
|
|
|
|
- if (it == parameters.end())
|
|
|
|
|
- {
|
|
|
|
|
- Log::Message(Log::LT_WARNING, "A 'change' event was received, but it did not contain a value. During processing of 'data-value' in %s", element->GetAddress().c_str());
|
|
|
|
|
- return;
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ const auto override_value_it = parameters.find("data-binding-override-value");
|
|
|
|
|
+ const auto value_it = parameters.find("value");
|
|
|
|
|
+ if (override_value_it != parameters.cend())
|
|
|
|
|
+ value_to_set = override_value_it->second;
|
|
|
|
|
+ else if (value_it != parameters.cend())
|
|
|
|
|
+ value_to_set = value_it->second;
|
|
|
|
|
+ else
|
|
|
|
|
+ Log::Message(Log::LT_WARNING, "A 'change' event was received, but it did not contain the attribute 'value' when processing a data binding in %s",
|
|
|
|
|
+ element->GetAddress().c_str());
|
|
|
|
|
|
|
|
DataModel* model = element->GetDataModel();
|
|
DataModel* model = element->GetDataModel();
|
|
|
- if (!model)
|
|
|
|
|
|
|
+ if (value_to_set.GetType() == Variant::NONE || !model)
|
|
|
return;
|
|
return;
|
|
|
|
|
|
|
|
if (DataVariable variable = model->GetVariable(address))
|
|
if (DataVariable variable = model->GetVariable(address))
|
|
|
- {
|
|
|
|
|
- if (SetValue(it->second, variable))
|
|
|
|
|
|
|
+ if (variable.Set(value_to_set))
|
|
|
model->DirtyVariable(address.front().name);
|
|
model->DirtyVariable(address.front().name);
|
|
|
- }
|
|
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -92,44 +92,6 @@ void DataControllerValue::Release()
|
|
|
delete this;
|
|
delete this;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-bool DataControllerValue::SetValue(const Variant& value, DataVariable variable)
|
|
|
|
|
-{
|
|
|
|
|
- return variable.Set(value);
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
-DataControllerChecked::DataControllerChecked(Element* element) : DataControllerValue(element)
|
|
|
|
|
-{}
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
-bool DataControllerChecked::SetValue(const Variant& value, DataVariable variable)
|
|
|
|
|
-{
|
|
|
|
|
- bool result = false;
|
|
|
|
|
- Variant old_value;
|
|
|
|
|
-
|
|
|
|
|
- if (variable.Get(old_value))
|
|
|
|
|
- {
|
|
|
|
|
- // Value will be empty if the button was just unchecked, otherwise it will take the 'value' attribute.
|
|
|
|
|
- const String new_value = value.Get<String>();
|
|
|
|
|
-
|
|
|
|
|
- if (old_value.GetType() == Variant::BOOL)
|
|
|
|
|
- {
|
|
|
|
|
- // If the client variable is a boolean type, we assume the button acts like a checkbox, and set the new checked state.
|
|
|
|
|
- result = variable.Set(Variant(!new_value.empty()));
|
|
|
|
|
- }
|
|
|
|
|
- else
|
|
|
|
|
- {
|
|
|
|
|
- // Otherwise, we assume the button acts like a radio box. Then, we do nothing if the box was unchecked,
|
|
|
|
|
- // and instead let only the newly checked box set the new value.
|
|
|
|
|
- if (!new_value.empty())
|
|
|
|
|
- result = variable.Set(value);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- return result;
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
|
|
|
|
|
DataControllerEvent::DataControllerEvent(Element* element) : DataController(element)
|
|
DataControllerEvent::DataControllerEvent(Element* element) : DataController(element)
|
|
|
{}
|
|
{}
|