View
- First pass at the interface, structure and algorithm used by the new View object that will ultimately obsolete Table, Grid and Cell.
This commit is contained in:
@@ -28,44 +28,34 @@
|
||||
#include <iostream>
|
||||
#include <Context.h>
|
||||
#include <Column.h>
|
||||
#include <ID.h>
|
||||
|
||||
extern Context context;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
Column* Column::factory (const std::string& name)
|
||||
{
|
||||
/*
|
||||
if (name == "description") return new ColumnDescription ();
|
||||
if (name == "id") return new ColumnID ();
|
||||
|
||||
throw std::string ("Unrecognized column type '") + name + "'";
|
||||
*/
|
||||
return NULL;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
Column::Column ()
|
||||
: _name ("")
|
||||
/*
|
||||
: _style ("default")
|
||||
, _label ("")
|
||||
, _minimum (0)
|
||||
, _maximum (0)
|
||||
, _wrap (false)
|
||||
, _just (left)
|
||||
, _sizing (minimal)
|
||||
*/
|
||||
{
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
Column::Column (const Column& other)
|
||||
{
|
||||
_name = other._name;
|
||||
/*
|
||||
_label = other._label;
|
||||
_minimum = other._minimum;
|
||||
_maximum = other._maximum;
|
||||
_wrap = other._wrap;
|
||||
_just = other._just;
|
||||
_sizing = other._sizing;
|
||||
*/
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
@@ -73,14 +63,9 @@ Column& Column::operator= (const Column& other)
|
||||
{
|
||||
if (this != &other)
|
||||
{
|
||||
_name = other._name;
|
||||
/*
|
||||
_label = other._label;
|
||||
_minimum = other._minimum;
|
||||
_maximum = other._maximum;
|
||||
_wrap = other._wrap;
|
||||
_just = other._just;
|
||||
_sizing = other._sizing;
|
||||
*/
|
||||
}
|
||||
|
||||
return *this;
|
||||
@@ -89,12 +74,9 @@ Column& Column::operator= (const Column& other)
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
bool Column::operator== (const Column& other) const
|
||||
{
|
||||
return _name == other._name /*&&
|
||||
return _label == other._label &&
|
||||
_minimum == other._minimum &&
|
||||
_maximum == other._maximum &&
|
||||
_wrap == other._wrap &&
|
||||
_just == other._just &&
|
||||
_sizing == other._sizing*/;
|
||||
_maximum == other._maximum;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
@@ -103,9 +85,15 @@ Column::~Column ()
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
void Column::setName (const std::string& name)
|
||||
void Column::setStyle (const std::string& style)
|
||||
{
|
||||
_name = name;
|
||||
_style = style;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
void Column::setLabel (const std::string& label)
|
||||
{
|
||||
_label = label;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@@ -33,11 +33,6 @@
|
||||
class Column
|
||||
{
|
||||
public:
|
||||
/*
|
||||
enum just {right = 0, left, center};
|
||||
enum sizing {minimal = 0, fixed, proportional, maximal};
|
||||
*/
|
||||
|
||||
static Column* factory (const std::string&);
|
||||
|
||||
Column ();
|
||||
@@ -46,19 +41,18 @@ public:
|
||||
bool operator== (const Column&) const; // TODO Is this necessary?
|
||||
~Column ();
|
||||
|
||||
virtual void setName (const std::string&);
|
||||
virtual std::string render (Task*, int, int, const std::string style = "default") = 0;
|
||||
virtual void setStyle (const std::string&);
|
||||
virtual void setLabel (const std::string&);
|
||||
virtual void measure (Task&, int&, int&) = 0;
|
||||
virtual void renderHeader (std::vector <std::string>&, int) = 0;
|
||||
virtual void render (std::vector <std::string>&, Task*, int) = 0;
|
||||
virtual std::string type () const = 0;
|
||||
|
||||
protected:
|
||||
std::string _name;
|
||||
/*
|
||||
std::string _style;
|
||||
std::string _label;
|
||||
int _minimum;
|
||||
int _maximum;
|
||||
bool _wrap;
|
||||
just _just;
|
||||
sizing _sizing;
|
||||
*/
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include <math.h>
|
||||
#include <Context.h>
|
||||
#include <ID.h>
|
||||
|
||||
@@ -33,7 +34,7 @@ extern Context context;
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
ColumnID::ColumnID ()
|
||||
{
|
||||
setName ("id");
|
||||
setLabel ("id");
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
@@ -42,11 +43,28 @@ ColumnID::~ColumnID ()
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
std::string ColumnID::render (
|
||||
Task* task,
|
||||
int width,
|
||||
int height,
|
||||
const std::string style)
|
||||
// Set the minimum and maximum widths for the value.
|
||||
void ColumnID::measure (Task& task, int& minimum, int& maximum)
|
||||
{
|
||||
int length;
|
||||
|
||||
if (task.id < 10) length = 1; // Fast
|
||||
else if (task.id < 100) length = 2; // Fast
|
||||
else if (task.id < 1000) length = 3; // Fast
|
||||
else if (task.id < 10000) length = 4; // Fast
|
||||
else length = (int) log10 ((double) task.id); // Slow
|
||||
|
||||
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)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
#ifndef INCLUDED_ID
|
||||
#define INCLUDED_ID
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <Column.h>
|
||||
#include <Task.h>
|
||||
@@ -37,7 +38,9 @@ public:
|
||||
ColumnID ();
|
||||
~ColumnID ();
|
||||
|
||||
std::string render (Task*, int, int, const std::string style = "default");
|
||||
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:
|
||||
|
||||
Reference in New Issue
Block a user