diff --git a/src/View.cpp b/src/View.cpp index 14c152bcb..b3e9f4542 100644 --- a/src/View.cpp +++ b/src/View.cpp @@ -52,84 +52,6 @@ View::~View () { } -//////////////////////////////////////////////////////////////////////////////// -void View::add (Column* column) -{ - _columns.push_back (column); -} - -//////////////////////////////////////////////////////////////////////////////// -void View::width (int width) -{ - _width = width; -} - -//////////////////////////////////////////////////////////////////////////////// -void View::leftMargin (int margin) -{ - _left_margin = margin; -} - -//////////////////////////////////////////////////////////////////////////////// -void View::colorOdd (Color& c) -{ - _odd = c; -} - -//////////////////////////////////////////////////////////////////////////////// -void View::colorEven (Color& c) -{ - _even = c; -} - -//////////////////////////////////////////////////////////////////////////////// -void View::intraPadding (int padding) -{ - _intra_padding = padding; -} - -//////////////////////////////////////////////////////////////////////////////// -void View::intraColorOdd (Color& c) -{ - _intra_odd = c; -} - -//////////////////////////////////////////////////////////////////////////////// -void View::intraColorEven (Color& c) -{ - _intra_even = c; -} - -//////////////////////////////////////////////////////////////////////////////// -void View::extraPadding (int padding) -{ - _extra_padding = padding; -} - -//////////////////////////////////////////////////////////////////////////////// -void View::extraColorOdd (Color& c) -{ - _extra_odd = c; -} - -//////////////////////////////////////////////////////////////////////////////// -void View::extraColorEven (Color& c) -{ - _extra_even = c; -} - -//////////////////////////////////////////////////////////////////////////////// -void View::truncate (int n) -{ - _truncate = n; -} - -//////////////////////////////////////////////////////////////////////////////// -int View::lines () -{ - return _lines; -} - //////////////////////////////////////////////////////////////////////////////// // +-------+ +-------+ +-------+ // |header | |header | |header | @@ -148,7 +70,7 @@ std::string View::render (std::vector & data, std::vector & sequence) std::vector ::iterator i; for (i = _columns.begin (); i != _columns.end (); ++i) { - int global_min = 0; + int global_min = characters ((*i)->getLabel ()); int global_ideal = 0; std::vector ::iterator d; diff --git a/src/View.h b/src/View.h index 4f8aa6b37..9e649dfe7 100644 --- a/src/View.h +++ b/src/View.h @@ -40,37 +40,37 @@ public: ~View (); // View specifications. - void add (Column*); - void width (int); - void leftMargin (int); - void colorOdd (Color&); - void colorEven (Color&); - void intraPadding (int); - void extraPadding (int); - void intraColorOdd (Color&); - void intraColorEven (Color&); - void extraColorOdd (Color&); - void extraColorEven (Color&); - void truncate (int); - int lines (); + void add (Column* column) { _columns.push_back (column); } + void width (int width) { _width = width; } + void leftMargin (int margin) { _left_margin = margin; } + void colorOdd (Color& c) { _odd = c; } + void colorEven (Color& c) { _even = c; } + void intraPadding (int padding) { _intra_padding = padding; } + void intraColorOdd (Color& c) { _intra_odd = c; } + void intraColorEven (Color& c) { _intra_even = c; } + void extraPadding (int padding) { _extra_padding = padding; } + void extraColorOdd (Color& c) { _extra_odd = c; } + void extraColorEven (Color& c) { _extra_even = c; } + void truncate (int n) { _truncate = n; } + int lines () { return _lines; } // View rendering. std::string render (std::vector &, std::vector &); private: std::vector _columns; - int _width; - int _left_margin; - Color _odd; - Color _even; - int _intra_padding; - Color _intra_odd; - Color _intra_even; - int _extra_padding; - Color _extra_odd; - Color _extra_even; - int _truncate; - int _lines; + int _width; + int _left_margin; + Color _odd; + Color _even; + int _intra_padding; + Color _intra_odd; + Color _intra_even; + int _extra_padding; + Color _extra_odd; + Color _extra_even; + int _truncate; + int _lines; }; #endif diff --git a/src/columns/ColID.cpp b/src/columns/ColID.cpp index 639590326..c292e3799 100644 --- a/src/columns/ColID.cpp +++ b/src/columns/ColID.cpp @@ -25,16 +25,21 @@ // //////////////////////////////////////////////////////////////////////////////// +#include +#include #include #include #include +#include extern Context context; //////////////////////////////////////////////////////////////////////////////// ColumnID::ColumnID () { - setLabel ("id"); + _type = "number"; + _style = "default"; + _label = "ID"; } //////////////////////////////////////////////////////////////////////////////// @@ -57,21 +62,18 @@ void ColumnID::measure (Task& task, int& minimum, int& maximum) minimum = maximum = length; } -//////////////////////////////////////////////////////////////////////////////// -void ColumnID::renderHeader (std::vector & lines, int width) -{ - lines.push_back ("ID"); -} - //////////////////////////////////////////////////////////////////////////////// void ColumnID::render (std::vector & lines, Task* task, int width) { -} - -//////////////////////////////////////////////////////////////////////////////// -std::string ColumnID::type () const -{ - return "number"; + std::stringstream line; + line << std::setw (width) << std::setfill (' ') << task->id; + + if (task->id) + line << task->id; + else + line << '-'; + + lines.push_back (line.str ()); } //////////////////////////////////////////////////////////////////////////////// diff --git a/src/columns/ColID.h b/src/columns/ColID.h index 6c112d259..16080f2ce 100644 --- a/src/columns/ColID.h +++ b/src/columns/ColID.h @@ -39,9 +39,7 @@ public: ~ColumnID (); void measure (Task&, int&, int&); - void renderHeader (std::vector &, int); void render (std::vector &, Task*, int); - std::string type () const; private: }; diff --git a/src/columns/ColProject.cpp b/src/columns/ColProject.cpp index 5c9a22286..8930666cf 100644 --- a/src/columns/ColProject.cpp +++ b/src/columns/ColProject.cpp @@ -34,7 +34,9 @@ extern Context context; //////////////////////////////////////////////////////////////////////////////// ColumnProject::ColumnProject () { - setLabel ("id"); + _type = "string"; + _style = "default"; + _label = "Project"; } //////////////////////////////////////////////////////////////////////////////// @@ -65,21 +67,9 @@ void ColumnProject::measure (Task& task, int& minimum, int& maximum) minimum = longest; } -//////////////////////////////////////////////////////////////////////////////// -void ColumnProject::renderHeader (std::vector & lines, int width) -{ - lines.push_back ("ID"); -} - //////////////////////////////////////////////////////////////////////////////// void ColumnProject::render (std::vector & lines, Task* task, int width) { } //////////////////////////////////////////////////////////////////////////////// -std::string ColumnProject::type () const -{ - return "number"; -} - -//////////////////////////////////////////////////////////////////////////////// diff --git a/src/columns/ColProject.h b/src/columns/ColProject.h index e1b891b60..02209af60 100644 --- a/src/columns/ColProject.h +++ b/src/columns/ColProject.h @@ -39,9 +39,7 @@ public: ~ColumnProject (); void measure (Task&, int&, int&); - void renderHeader (std::vector &, int); void render (std::vector &, Task*, int); - std::string type () const; private: }; diff --git a/src/columns/Column.cpp b/src/columns/Column.cpp index b3e6af510..18a4f5f2f 100644 --- a/src/columns/Column.cpp +++ b/src/columns/Column.cpp @@ -30,6 +30,7 @@ #include #include #include +#include extern Context context; @@ -45,19 +46,18 @@ Column* Column::factory (const std::string& name) //////////////////////////////////////////////////////////////////////////////// Column::Column () -: _style ("default") +: _type ("string") +, _style ("default") , _label ("") -, _minimum (0) -, _maximum (0) { } //////////////////////////////////////////////////////////////////////////////// Column::Column (const Column& other) { - _label = other._label; - _minimum = other._minimum; - _maximum = other._maximum; + _type = other._type; + _style = other._style; + _label = other._label; } //////////////////////////////////////////////////////////////////////////////// @@ -65,9 +65,9 @@ Column& Column::operator= (const Column& other) { if (this != &other) { + _type = other._type; + _style = other._style; _label = other._label; - _minimum = other._minimum; - _maximum = other._maximum; } return *this; @@ -76,9 +76,9 @@ Column& Column::operator= (const Column& other) //////////////////////////////////////////////////////////////////////////////// bool Column::operator== (const Column& other) const { - return _label == other._label && - _minimum == other._minimum && - _maximum == other._maximum; + return _type == other._type && + _style == other._style && + _label == other._label; } //////////////////////////////////////////////////////////////////////////////// @@ -87,15 +87,28 @@ Column::~Column () } //////////////////////////////////////////////////////////////////////////////// -void Column::setStyle (const std::string& style) +void Column::renderHeader (std::vector & lines, int width) { - _style = style; -} - -//////////////////////////////////////////////////////////////////////////////// -void Column::setLabel (const std::string& label) -{ - _label = label; + // Create a basic label. + std::string header; + header.reserve (width); + header = _label; + + // Right pad with spaces, if necessary. + int length = characters (_label); + if (length < width) + _label += std::string (' ', width - length); + + // Now underline the header, or add a dashed line. + if (context.config.getBoolean ("fontunderline")) + { + lines.push_back (header); + } + else + { + lines.push_back (header); + lines.push_back (std::string ('-', width)); + } } //////////////////////////////////////////////////////////////////////////////// diff --git a/src/columns/Column.h b/src/columns/Column.h index a9a65d985..4cde052a8 100644 --- a/src/columns/Column.h +++ b/src/columns/Column.h @@ -27,6 +27,7 @@ #ifndef INCLUDED_COLUMN #define INCLUDED_COLUMN +#include #include #include @@ -41,18 +42,20 @@ public: bool operator== (const Column&) const; // TODO Is this necessary? ~Column (); - virtual void setStyle (const std::string&); - virtual void setLabel (const std::string&); + std::string getStyle () { return _style; } + std::string getLabel () { return _label; } + void setStyle (const std::string& value) { _style = value; } + void setLabel (const std::string& value) { _label = value; } + std::string type () const { return _type; } + virtual void measure (Task&, int&, int&) = 0; - virtual void renderHeader (std::vector &, int) = 0; + virtual void renderHeader (std::vector &, int); virtual void render (std::vector &, Task*, int) = 0; - virtual std::string type () const = 0; protected: + std::string _type; std::string _style; std::string _label; - int _minimum; - int _maximum; }; #endif