ColRType: Added ::setStyle and ::validate
This commit is contained in:
@@ -26,8 +26,13 @@
|
|||||||
|
|
||||||
#include <cmake.h>
|
#include <cmake.h>
|
||||||
#include <ColRType.h>
|
#include <ColRType.h>
|
||||||
|
#include <Context.h>
|
||||||
|
#include <shared.h>
|
||||||
#include <format.h>
|
#include <format.h>
|
||||||
#include <i18n.h>
|
#include <i18n.h>
|
||||||
|
#include <cctype>
|
||||||
|
|
||||||
|
extern Context context;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
ColumnRType::ColumnRType ()
|
ColumnRType::ColumnRType ()
|
||||||
@@ -36,10 +41,21 @@ ColumnRType::ColumnRType ()
|
|||||||
_style = "default";
|
_style = "default";
|
||||||
_label = STRING_COLUMN_LABEL_RTYPE;
|
_label = STRING_COLUMN_LABEL_RTYPE;
|
||||||
_modifiable = false;
|
_modifiable = false;
|
||||||
_styles = {"default"};
|
_styles = {"default", "indicator"};
|
||||||
_examples = {"periodic", "chained"};
|
_examples = {"periodic", "chained"};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// Overriden so that style <----> label are linked.
|
||||||
|
// Note that you can not determine which gets called first.
|
||||||
|
void ColumnRType::setStyle (const std::string& value)
|
||||||
|
{
|
||||||
|
_style = value;
|
||||||
|
|
||||||
|
if (_style == "indicator" && _label == STRING_COLUMN_LABEL_RTYPE)
|
||||||
|
_label = _label.substr (0, context.config.get ("rtype.indicator").length ());
|
||||||
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
// Set the minimum and maximum widths for the value.
|
// Set the minimum and maximum widths for the value.
|
||||||
void ColumnRType::measure (Task& task, unsigned int& minimum, unsigned int& maximum)
|
void ColumnRType::measure (Task& task, unsigned int& minimum, unsigned int& maximum)
|
||||||
@@ -47,9 +63,11 @@ void ColumnRType::measure (Task& task, unsigned int& minimum, unsigned int& maxi
|
|||||||
minimum = maximum = 0;
|
minimum = maximum = 0;
|
||||||
if (task.has (_name))
|
if (task.has (_name))
|
||||||
{
|
{
|
||||||
minimum = maximum = task.get (_name).length ();
|
if (_style == "default")
|
||||||
|
minimum = maximum = task.get (_name).length ();
|
||||||
if (_style != "default")
|
else if (_style == "indicator")
|
||||||
|
minimum = maximum = 1;
|
||||||
|
else
|
||||||
throw format (STRING_COLUMN_BAD_FORMAT, _name, _style);
|
throw format (STRING_COLUMN_BAD_FORMAT, _name, _style);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -62,7 +80,24 @@ void ColumnRType::render (
|
|||||||
Color& color)
|
Color& color)
|
||||||
{
|
{
|
||||||
if (task.has (_name))
|
if (task.has (_name))
|
||||||
renderStringLeft (lines, width, color, task.get (_name));
|
{
|
||||||
|
if (_style == "default")
|
||||||
|
renderStringRight (lines, width, color, task.get (_name));
|
||||||
|
|
||||||
|
else if (_style == "indicator")
|
||||||
|
{
|
||||||
|
std::string value {" "};
|
||||||
|
value[0] = toupper (task.get (_name)[0]);
|
||||||
|
renderStringRight (lines, width, color, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
bool ColumnRType::validate (const std::string& input) const
|
||||||
|
{
|
||||||
|
return input == "periodic" ||
|
||||||
|
input == "chained";
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|||||||
@@ -33,8 +33,10 @@ class ColumnRType : public ColumnTypeString
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ColumnRType ();
|
ColumnRType ();
|
||||||
|
void setStyle (const std::string&);
|
||||||
void measure (Task&, unsigned int&, unsigned int&);
|
void measure (Task&, unsigned int&, unsigned int&);
|
||||||
void render (std::vector <std::string>&, Task&, int, Color&);
|
void render (std::vector <std::string>&, Task&, int, Color&);
|
||||||
|
bool validate (const std::string&) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user