Integrated Priority column modification to the ColPriority object, from Task core.

This commit is contained in:
Thomas 2013-06-14 14:42:08 -04:00 committed by Paul Beckingham
parent 55a8b157b1
commit f39120dd73
6 changed files with 46 additions and 7 deletions

View file

@ -1804,12 +1804,6 @@ void Task::modify (
}
}
// Priorities are converted to upper case.
else if (name == "priority")
{
(*this).set (name, upperCase (value));
}
// Dates are special, maybe.
else if (column->type () == "date")
{
@ -1879,9 +1873,19 @@ void Task::modify (
throw format (STRING_UDA_NUMERIC, result);
}
// By default, just add/remove it.
// Try to use modify method, otherwise just continue to the final option.
else if (column->can_modify ())
{
// column->modify () contains the logic for the specific column
// and returns the appropriate value for (*this).set ()
if (column->validate (value))
(*this).set (name, column->modify (value));
else
throw format (STRING_INVALID_MOD, name, value);
}
else
{
// Final default action
if (column->validate (value))
(*this).set (name, value);
else

View file

@ -119,3 +119,15 @@ void ColumnPriority::render (
}
////////////////////////////////////////////////////////////////////////////////
std::string ColumnPriority::modify (std::string& value)
{
return upperCase (value);
}
////////////////////////////////////////////////////////////////////////////////
bool ColumnPriority::can_modify ()
{
return true;
}
////////////////////////////////////////////////////////////////////////////////

View file

@ -44,6 +44,8 @@ public:
void setStyle (const std::string&);
void measure (Task&, unsigned int&, unsigned int&);
void render (std::vector <std::string>&, Task&, int, Color&);
std::string modify (std::string&);
bool can_modify ();
private:
};

View file

@ -323,3 +323,17 @@ void Column::render (std::vector <std::string>&, Task&, int, Color&)
}
////////////////////////////////////////////////////////////////////////////////
// No L10N.
bool Column::can_modify ()
{
return false;
}
////////////////////////////////////////////////////////////////////////////////
// No L10N.
std::string Column::modify (std::string& value)
{
throw std::string ("Virtual method Column::modify not overridden.");
}
////////////////////////////////////////////////////////////////////////////////

View file

@ -64,6 +64,8 @@ public:
virtual void renderHeader (std::vector <std::string>&, int, Color&);
virtual void render (std::vector <std::string>&, const std::string&, int, Color&);
virtual void render (std::vector <std::string>&, Task&, int, Color&);
virtual bool can_modify ();
virtual std::string modify (std::string&);
protected:
std::string _name;