- 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

@ -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