mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-06-26 10:54:26 +02:00
View
- Code reorganization. Much can be moved to default behavior in the base class.
This commit is contained in:
parent
63c84129f2
commit
29649bdf07
8 changed files with 85 additions and 159 deletions
80
src/View.cpp
80
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 <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;
|
||||
|
|
26
src/View.h
26
src/View.h
|
@ -40,19 +40,19 @@ 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>&);
|
||||
|
|
|
@ -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 ());
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -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:
|
||||
};
|
||||
|
|
|
@ -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";
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -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:
|
||||
};
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
_type = other._type;
|
||||
_style = other._style;
|
||||
_label = other._label;
|
||||
_minimum = other._minimum;
|
||||
_maximum = other._maximum;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue