- 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 |
@ -148,7 +70,7 @@ std::string View::render (std::vector <Task>& data, std::vector <int>& sequence)
std::vector <Column*>::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 <Task>::iterator d;

View file

@ -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 <Task>&, std::vector <int>&);
private:
std::vector <Column*> _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

View file

@ -25,16 +25,21 @@
//
////////////////////////////////////////////////////////////////////////////////
#include <iomanip>
#include <sstream>
#include <math.h>
#include <Context.h>
#include <ColID.h>
#include <text.h>
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 <std::string>& lines, int width)
{
lines.push_back ("ID");
}
////////////////////////////////////////////////////////////////////////////////
void ColumnID::render (std::vector <std::string>& 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 ());
}
////////////////////////////////////////////////////////////////////////////////

View file

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

View file

@ -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 <std::string>& lines, int width)
{
lines.push_back ("ID");
}
////////////////////////////////////////////////////////////////////////////////
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 ();
void measure (Task&, int&, int&);
void renderHeader (std::vector <std::string>&, int);
void render (std::vector <std::string>&, Task*, int);
std::string type () const;
private:
};

View file

@ -30,6 +30,7 @@
#include <Column.h>
#include <ColID.h>
#include <ColProject.h>
#include <text.h>
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 <std::string>& 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));
}
}
////////////////////////////////////////////////////////////////////////////////

View file

@ -27,6 +27,7 @@
#ifndef INCLUDED_COLUMN
#define INCLUDED_COLUMN
#include <vector>
#include <string>
#include <Task.h>
@ -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 <std::string>&, int) = 0;
virtual void renderHeader (std::vector <std::string>&, int);
virtual void render (std::vector <std::string>&, Task*, int) = 0;
virtual std::string type () const = 0;
protected:
std::string _type;
std::string _style;
std::string _label;
int _minimum;
int _maximum;
};
#endif