- Code reorganization.  Much can be moved to default behavior in the
  base class.
This commit is contained in:
Paul Beckingham 2011-04-27 00:22:56 -04:00
parent 63c84129f2
commit 29649bdf07
8 changed files with 85 additions and 159 deletions

View file

@ -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 | // |header | |header | |header |
@ -148,7 +70,7 @@ std::string View::render (std::vector <Task>& data, std::vector <int>& sequence)
std::vector <Column*>::iterator i; std::vector <Column*>::iterator i;
for (i = _columns.begin (); i != _columns.end (); ++i) for (i = _columns.begin (); i != _columns.end (); ++i)
{ {
int global_min = 0; int global_min = characters ((*i)->getLabel ());
int global_ideal = 0; int global_ideal = 0;
std::vector <Task>::iterator d; std::vector <Task>::iterator d;

View file

@ -40,19 +40,19 @@ public:
~View (); ~View ();
// View specifications. // View specifications.
void add (Column*); void add (Column* column) { _columns.push_back (column); }
void width (int); void width (int width) { _width = width; }
void leftMargin (int); void leftMargin (int margin) { _left_margin = margin; }
void colorOdd (Color&); void colorOdd (Color& c) { _odd = c; }
void colorEven (Color&); void colorEven (Color& c) { _even = c; }
void intraPadding (int); void intraPadding (int padding) { _intra_padding = padding; }
void extraPadding (int); void intraColorOdd (Color& c) { _intra_odd = c; }
void intraColorOdd (Color&); void intraColorEven (Color& c) { _intra_even = c; }
void intraColorEven (Color&); void extraPadding (int padding) { _extra_padding = padding; }
void extraColorOdd (Color&); void extraColorOdd (Color& c) { _extra_odd = c; }
void extraColorEven (Color&); void extraColorEven (Color& c) { _extra_even = c; }
void truncate (int); void truncate (int n) { _truncate = n; }
int lines (); int lines () { return _lines; }
// View rendering. // View rendering.
std::string render (std::vector <Task>&, std::vector <int>&); std::string render (std::vector <Task>&, std::vector <int>&);

View file

@ -25,16 +25,21 @@
// //
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
#include <iomanip>
#include <sstream>
#include <math.h> #include <math.h>
#include <Context.h> #include <Context.h>
#include <ColID.h> #include <ColID.h>
#include <text.h>
extern Context context; extern Context context;
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
ColumnID::ColumnID () 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; minimum = maximum = length;
} }
////////////////////////////////////////////////////////////////////////////////
void ColumnID::renderHeader (std::vector <std::string>& lines, int width)
{
lines.push_back ("ID");
}
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
void ColumnID::render (std::vector <std::string>& lines, Task* task, int width) void ColumnID::render (std::vector <std::string>& lines, Task* task, int width)
{ {
} std::stringstream line;
line << std::setw (width) << std::setfill (' ') << task->id;
////////////////////////////////////////////////////////////////////////////////
std::string ColumnID::type () const if (task->id)
{ line << task->id;
return "number"; else
line << '-';
lines.push_back (line.str ());
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////

View file

@ -39,9 +39,7 @@ public:
~ColumnID (); ~ColumnID ();
void measure (Task&, int&, int&); void measure (Task&, int&, int&);
void renderHeader (std::vector <std::string>&, int);
void render (std::vector <std::string>&, Task*, int); void render (std::vector <std::string>&, Task*, int);
std::string type () const;
private: private:
}; };

View file

@ -34,7 +34,9 @@ extern Context context;
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
ColumnProject::ColumnProject () 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; minimum = longest;
} }
////////////////////////////////////////////////////////////////////////////////
void ColumnProject::renderHeader (std::vector <std::string>& lines, int width)
{
lines.push_back ("ID");
}
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
void ColumnProject::render (std::vector <std::string>& lines, Task* task, int width) void ColumnProject::render (std::vector <std::string>& lines, Task* task, int width)
{ {
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
std::string ColumnProject::type () const
{
return "number";
}
////////////////////////////////////////////////////////////////////////////////

View file

@ -39,9 +39,7 @@ public:
~ColumnProject (); ~ColumnProject ();
void measure (Task&, int&, int&); void measure (Task&, int&, int&);
void renderHeader (std::vector <std::string>&, int);
void render (std::vector <std::string>&, Task*, int); void render (std::vector <std::string>&, Task*, int);
std::string type () const;
private: private:
}; };

View file

@ -30,6 +30,7 @@
#include <Column.h> #include <Column.h>
#include <ColID.h> #include <ColID.h>
#include <ColProject.h> #include <ColProject.h>
#include <text.h>
extern Context context; extern Context context;
@ -45,19 +46,18 @@ Column* Column::factory (const std::string& name)
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
Column::Column () Column::Column ()
: _style ("default") : _type ("string")
, _style ("default")
, _label ("") , _label ("")
, _minimum (0)
, _maximum (0)
{ {
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
Column::Column (const Column& other) Column::Column (const Column& other)
{ {
_type = other._type;
_style = other._style;
_label = other._label; _label = other._label;
_minimum = other._minimum;
_maximum = other._maximum;
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -65,9 +65,9 @@ Column& Column::operator= (const Column& other)
{ {
if (this != &other) if (this != &other)
{ {
_type = other._type;
_style = other._style;
_label = other._label; _label = other._label;
_minimum = other._minimum;
_maximum = other._maximum;
} }
return *this; return *this;
@ -76,9 +76,9 @@ Column& Column::operator= (const Column& other)
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
bool Column::operator== (const Column& other) const bool Column::operator== (const Column& other) const
{ {
return _label == other._label && return _type == other._type &&
_minimum == other._minimum && _style == other._style &&
_maximum == other._maximum; _label == other._label;
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -87,15 +87,28 @@ Column::~Column ()
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
void Column::setStyle (const std::string& style) void Column::renderHeader (std::vector <std::string>& lines, int width)
{ {
_style = style; // Create a basic label.
} std::string header;
header.reserve (width);
//////////////////////////////////////////////////////////////////////////////// header = _label;
void Column::setLabel (const std::string& label)
{ // Right pad with spaces, if necessary.
_label = label; 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));
}
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////

View file

@ -27,6 +27,7 @@
#ifndef INCLUDED_COLUMN #ifndef INCLUDED_COLUMN
#define INCLUDED_COLUMN #define INCLUDED_COLUMN
#include <vector>
#include <string> #include <string>
#include <Task.h> #include <Task.h>
@ -41,18 +42,20 @@ public:
bool operator== (const Column&) const; // TODO Is this necessary? bool operator== (const Column&) const; // TODO Is this necessary?
~Column (); ~Column ();
virtual void setStyle (const std::string&); std::string getStyle () { return _style; }
virtual void setLabel (const std::string&); 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 measure (Task&, int&, int&) = 0;
virtual void renderHeader (std::vector <std::string>&, int) = 0; virtual void renderHeader (std::vector <std::string>&, int);
virtual void render (std::vector <std::string>&, Task*, int) = 0; virtual void render (std::vector <std::string>&, Task*, int) = 0;
virtual std::string type () const = 0;
protected: protected:
std::string _type;
std::string _style; std::string _style;
std::string _label; std::string _label;
int _minimum;
int _maximum;
}; };
#endif #endif