ColTypeNumeric: Migrated part of Task::modify to ::modify
This commit is contained in:
@@ -26,6 +26,16 @@
|
||||
|
||||
#include <cmake.h>
|
||||
#include <ColTypeNumeric.h>
|
||||
#include <Context.h>
|
||||
#include <Eval.h>
|
||||
#include <Variant.h>
|
||||
#include <Filter.h>
|
||||
#include <Dates.h>
|
||||
#include <text.h>
|
||||
#include <i18n.h>
|
||||
|
||||
extern Context context;
|
||||
extern Task& contextTask;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
ColumnTypeNumeric::ColumnTypeNumeric ()
|
||||
@@ -51,7 +61,31 @@ void ColumnTypeNumeric::render (
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
void ColumnTypeNumeric::modify (Task& task, const std::string& value)
|
||||
{
|
||||
task.set (_name, value);
|
||||
// Try to evaluate 'value'. It might work.
|
||||
Variant evaluatedValue;
|
||||
try
|
||||
{
|
||||
Eval e;
|
||||
e.addSource (domSource);
|
||||
e.addSource (namedDates);
|
||||
contextTask = task;
|
||||
e.evaluateInfixExpression (value, evaluatedValue);
|
||||
}
|
||||
|
||||
catch (...)
|
||||
{
|
||||
evaluatedValue = Variant (value);
|
||||
}
|
||||
|
||||
std::string label = " [1;37;43mMODIFICATION[0m ";
|
||||
context.debug (label + _name + " <-- '" + evaluatedValue.get_string () + "' <-- '" + value + "'");
|
||||
|
||||
// If the result is not readily convertible to a numeric value,
|
||||
// then this is an error.
|
||||
if (evaluatedValue.type () == Variant::type_string)
|
||||
throw format (STRING_UDA_NUMERIC, evaluatedValue.get_string ());
|
||||
|
||||
task.set (_name, evaluatedValue);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Reference in New Issue
Block a user