mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-08-01 11:20:19 +02:00

- Fixed bug #371 which caused task to mis-apply certain color rules, like color.alternate, which was (a) not applied first, and (b) not blended with the other color rules (thanks to Richard Querin).
147 lines
4.7 KiB
C++
147 lines
4.7 KiB
C++
////////////////////////////////////////////////////////////////////////////////
|
|
// task - a command line task list manager.
|
|
//
|
|
// Copyright 2006 - 2010, Paul Beckingham.
|
|
// 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_TABLE
|
|
#define INCLUDED_TABLE
|
|
|
|
#include <map>
|
|
#include <vector>
|
|
#include <string>
|
|
#include "Color.h"
|
|
#include "Grid.h"
|
|
|
|
class Table
|
|
{
|
|
public:
|
|
enum just {left, center, right};
|
|
enum order {ascendingNumeric,
|
|
ascendingCharacter,
|
|
ascendingPriority,
|
|
ascendingDate,
|
|
ascendingDueDate,
|
|
ascendingPeriod,
|
|
descendingNumeric,
|
|
descendingCharacter,
|
|
descendingPriority,
|
|
descendingDate,
|
|
descendingDueDate,
|
|
descendingPeriod};
|
|
enum sizing {minimum = -1, flexible = 0};
|
|
|
|
Table ();
|
|
virtual ~Table ();
|
|
|
|
Table (const Table&);
|
|
Table& operator= (const Table&);
|
|
|
|
// TODO Obsolete - this is not used. Consider removal.
|
|
// void setTableColor (const Color&);
|
|
void setTableAlternateColor (const Color&);
|
|
void setTablePadding (int);
|
|
void setTableIntraPadding (int);
|
|
void setTableWidth (int);
|
|
void setTableDashedUnderline ();
|
|
|
|
int addColumn (const std::string&);
|
|
// TODO Obsolete - this is not used. Consider removal.
|
|
// void setColumnColor (int, const Color&);
|
|
void setColumnUnderline (int);
|
|
void setColumnPadding (int, int);
|
|
void setColumnWidth (int, int);
|
|
void setColumnWidth (int, sizing);
|
|
void setColumnJustification (int, just);
|
|
void setColumnCommify (int);
|
|
void sortOn (int, order);
|
|
|
|
int addRow ();
|
|
void setRowColor (int, const Color&);
|
|
|
|
void addCell (int, int, const std::string&);
|
|
void addCell (int, int, char);
|
|
void addCell (int, int, int);
|
|
void addCell (int, int, float);
|
|
void addCell (int, int, double);
|
|
void setCellColor (int, int, const Color&);
|
|
|
|
void suppressWS ();
|
|
void setDateFormat (const std::string&);
|
|
void setReportName (const std::string&);
|
|
|
|
int rowCount ();
|
|
int columnCount ();
|
|
const std::string render (int maximum = 0);
|
|
|
|
private:
|
|
std::string getCell (const int, const int);
|
|
Color getColor (const int, const int, const int);
|
|
Color getHeaderColor (const int);
|
|
Color getHeaderUnderline (const int);
|
|
int getPadding (const int);
|
|
int getIntraPadding ();
|
|
void calculateColumnWidths ();
|
|
just getJustification (const int, const int);
|
|
just getHeaderJustification (const int);
|
|
const std::string formatHeader (const int, const int, const int);
|
|
const std::string formatHeaderDashedUnderline (const int, const int, const int);
|
|
void formatCell (const int, const int, const int, const int, const int, std::vector <std::string>&, std::string&);
|
|
void sort (std::vector <int>&);
|
|
void clean (std::string&);
|
|
void optimize (std::string&) const;
|
|
|
|
private:
|
|
std::vector <std::string> mColumns;
|
|
int mRows;
|
|
int mIntraPadding;
|
|
std::map <std::string, Color> mColor;
|
|
std::map <std::string, Color> mUnderline;
|
|
bool mDashedUnderline;
|
|
Color alternate;
|
|
|
|
// Padding...
|
|
int mTablePadding;
|
|
std::vector <int> mColumnPadding;
|
|
|
|
// Width...
|
|
int mTableWidth;
|
|
std::vector <int> mSpecifiedWidth;
|
|
std::vector <int> mMaxDataWidth;
|
|
std::vector <int> mCalculatedWidth;
|
|
|
|
std::map <int, just> mJustification;
|
|
std::map <int, bool> mCommify;
|
|
Grid mData;
|
|
std::vector <int> mSortColumns;
|
|
std::map <int, order> mSortOrder;
|
|
|
|
// Misc...
|
|
bool mSuppressWS;
|
|
std::string mDateFormat;
|
|
std::string mReportName;
|
|
};
|
|
|
|
#endif
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|