- Added unit tests - blank for now.
- Added stubbed ColProject, just so that ColID is not the only column.
- Renamed files for clarity and namespace reasons.
This commit is contained in:
Paul Beckingham 2011-04-26 22:46:04 -04:00
parent 74d799acea
commit c5f71051ad
10 changed files with 225 additions and 5 deletions

View file

@ -25,8 +25,10 @@
//
////////////////////////////////////////////////////////////////////////////////
#include <iostream> // TODO Remove
#include <sstream>
#include <View.h>
#include <text.h>
////////////////////////////////////////////////////////////////////////////////
View::View ()
@ -164,6 +166,12 @@ std::string View::render (std::vector <Task>& data, std::vector <int>& sequence)
ideal.push_back (global_ideal);
}
std::string combined;
join (combined, ",", minimal);
std::cout << "# minimal " << combined << "\n";
join (combined, ",", ideal);
std::cout << "# ideal " << combined << "\n";
// TODO Calculate final column widths.
// TODO Compose column headers.

View file

@ -5,7 +5,8 @@ include_directories (${CMAKE_SOURCE_DIR}/src
${TASK_INCLUDE_DIRS})
set (columns_SRCS Column.cpp Column.h
ID.cpp ID.h)
ColID.cpp ColID.h
ColProject.cpp ColProject.h)
add_library (columns STATIC ${columns_SRCS})

View file

@ -27,7 +27,7 @@
#include <math.h>
#include <Context.h>
#include <ID.h>
#include <ColID.h>
extern Context context;

View file

@ -0,0 +1,85 @@
////////////////////////////////////////////////////////////////////////////////
// taskwarrior - a command line task list manager.
//
// Copyright 2006 - 2011, Paul Beckingham, Federico Hernandez.
// All rights reserved.
//
// This program is free software; you can redistribute it and/or modify it under
// the terms of the GNU General Public License as published by the Free Software
// Foundation; either version 2 of the License, or (at your option) any later
// version.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
// details.
//
// You should have received a copy of the GNU General Public License along with
// this program; if not, write to the
//
// Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor,
// Boston, MA
// 02110-1301
// USA
//
////////////////////////////////////////////////////////////////////////////////
#include <math.h>
#include <Context.h>
#include <ColProject.h>
extern Context context;
////////////////////////////////////////////////////////////////////////////////
ColumnProject::ColumnProject ()
{
setLabel ("id");
}
////////////////////////////////////////////////////////////////////////////////
ColumnProject::~ColumnProject ()
{
}
////////////////////////////////////////////////////////////////////////////////
// Set the minimum and maximum widths for the value.
void ColumnProject::measure (Task& task, int& minimum, int& maximum)
{
std::string project = task.get ("project");
minimum = maximum = project.length ();
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)
longest = space - last - 1;
last = space;
space = project.find (' ', last + 1);
}
if (longest)
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";
}
////////////////////////////////////////////////////////////////////////////////

50
src/columns/ColProject.h Normal file
View file

@ -0,0 +1,50 @@
////////////////////////////////////////////////////////////////////////////////
// taskwarrior - a command line task list manager.
//
// Copyright 2006 - 2011, Paul Beckingham, Federico Hernandez.
// All rights reserved.
//
// This program is free software; you can redistribute it and/or modify it under
// the terms of the GNU General Public License as published by the Free Software
// Foundation; either version 2 of the License, or (at your option) any later
// version.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
// details.
//
// You should have received a copy of the GNU General Public License along with
// this program; if not, write to the
//
// Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor,
// Boston, MA
// 02110-1301
// USA
//
////////////////////////////////////////////////////////////////////////////////
#ifndef INCLUDED_PROJECT
#define INCLUDED_PROJECT
#include <vector>
#include <string>
#include <Column.h>
#include <Task.h>
class ColumnProject : public Column
{
public:
ColumnProject ();
~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:
};
#endif
////////////////////////////////////////////////////////////////////////////////

View file

@ -28,14 +28,16 @@
#include <iostream>
#include <Context.h>
#include <Column.h>
#include <ID.h>
#include <ColID.h>
#include <ColProject.h>
extern Context context;
////////////////////////////////////////////////////////////////////////////////
Column* Column::factory (const std::string& name)
{
if (name == "id") return new ColumnID ();
if (name == "id") return new ColumnID ();
if (name == "project") return new ColumnProject ();
throw std::string ("Unrecognized column type '") + name + "'";
return NULL;