- Implemented column sizing algorithm.
This commit is contained in:
Paul Beckingham 2011-04-27 01:50:32 -04:00
parent 29649bdf07
commit 9f672d0b06
7 changed files with 94 additions and 16 deletions

View file

@ -25,6 +25,7 @@
//
////////////////////////////////////////////////////////////////////////////////
#include <iostream> // TODO Remove
#include <iomanip>
#include <sstream>
#include <math.h>
@ -60,16 +61,18 @@ void ColumnID::measure (Task& task, int& minimum, int& maximum)
else length = (int) log10 ((double) task.id); // Slow
minimum = maximum = length;
std::cout << "# ColID::measure id=" << task.id << " min=" << minimum << " max=" << maximum << "\n";
}
////////////////////////////////////////////////////////////////////////////////
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;
line << std::setw (width) << std::setfill (' ') << task.id;
if (task->id)
line << task->id;
if (task.id)
line << task.id;
else
line << '-';

View file

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

View file

@ -25,6 +25,7 @@
//
////////////////////////////////////////////////////////////////////////////////
#include <iostream> // TODO Remove
#include <math.h>
#include <Context.h>
#include <ColProject.h>
@ -51,12 +52,19 @@ void ColumnProject::measure (Task& task, int& minimum, int& maximum)
std::string project = task.get ("project");
minimum = maximum = project.length ();
std::string::size_type space = project.find (' ');
if (space == std::string::npos)
{
std::cout << "# ColProject::measure project=" << project << " min=" << minimum << " max=" << maximum << "\n";
return;
}
minimum = 0;
int longest = 0;
std::string::size_type last = -1;
std::string::size_type space = project.find (' ');
while (space != std::string::npos)
{
if (space - last - 1 > minimum)
if (space - last - 1 > longest)
longest = space - last - 1;
last = space;
@ -65,10 +73,12 @@ void ColumnProject::measure (Task& task, int& minimum, int& maximum)
if (longest)
minimum = longest;
std::cout << "# ColProject::measure project=" << project << " min=" << minimum << " max=" << maximum << "\n";
}
////////////////////////////////////////////////////////////////////////////////
void ColumnProject::render (std::vector <std::string>& lines, Task* task, int width)
void ColumnProject::render (std::vector <std::string>& lines, Task& task, int width)
{
}

View file

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

View file

@ -50,7 +50,7 @@ public:
virtual void measure (Task&, int&, 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;
protected:
std::string _type;