From 2b2795077bd7bd576ad219093e6dd5680e20cfde Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Sat, 6 Feb 2010 12:22:20 -0500 Subject: [PATCH] Bug Fix - #371 color.due clobbered by color.alternate - 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). --- ChangeLog | 3 ++ src/Table.cpp | 87 +++++++++++++++++++++++++++++++++------------------ src/Table.h | 11 ++++--- 3 files changed, 67 insertions(+), 34 deletions(-) diff --git a/ChangeLog b/ChangeLog index 63998df6e..a2e980ce6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -80,6 +80,9 @@ + Fixed bug #370 which prevented the removal of a due date from a task, mis-identifying the task as recurring just because it had a due date (thanks to John Florian). + + 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). ------ old releases ------------------------------ diff --git a/src/Table.cpp b/src/Table.cpp index 4603b3d0e..c45194e62 100644 --- a/src/Table.cpp +++ b/src/Table.cpp @@ -73,15 +73,17 @@ Table::~Table () } //////////////////////////////////////////////////////////////////////////////// +/* void Table::setTableColor (const Color& c) { mColor["table"] = c; } +*/ //////////////////////////////////////////////////////////////////////////////// void Table::setTableAlternateColor (const Color& c) { - mColor["alternate"] = c; + alternate = c; } //////////////////////////////////////////////////////////////////////////////// @@ -122,12 +124,15 @@ int Table::addColumn (const std::string& col) } //////////////////////////////////////////////////////////////////////////////// +// TODO Obsolete - this call is not used. Consider removal. +/* void Table::setColumnColor (int column, const Color& c) { char id[12]; sprintf (id, "col:%d", column); mColor[id] = c; } +*/ //////////////////////////////////////////////////////////////////////////////// void Table::setColumnUnderline (int column) @@ -316,38 +321,65 @@ std::string Table::getCell (const int row, const int col) } //////////////////////////////////////////////////////////////////////////////// -Color Table::getColor (const int row, const int col) +Color Table::getColor (const int index, const int row, const int col) { - char idCell[24]; - sprintf (idCell, "cell:%d,%d", row, col); - if (mColor.find (idCell) != mColor.end ()) - return mColor[idCell]; + // Color defaults to trivial. + Color c; - char idRow[12]; - sprintf (idRow, "row:%d", row); - if (mColor.find (idRow) != mColor.end ()) - return mColor[idRow]; + // For alternating rows, use Table::alternate. + std::map ::iterator i; + char id[24]; - char idCol[12]; - sprintf (idCol, "col:%d", col); - if (mColor.find (idCol) != mColor.end ()) - return mColor[idCol]; + if (index % 2) + c = alternate; - if (mColor.find ("table") != mColor.end ()) - return mColor["table"]; +/* + // TODO Obsolete - this is not used. Consider removal. + // Blend with a table color, if specified. + if ((i = mColor.find ("table")) != mColor.end ()) + c.blend (i->second); - return Color (); + // Blend with a column color, if specified. + sprintf (id, "col:%d", col); + if ((i = mColor.find (id)) != mColor.end ()) + c.blend (i->second); +*/ + + // Blend with a row color, if specified. + sprintf (id, "row:%d", row); + if ((i = mColor.find (id)) != mColor.end ()) + c.blend (i->second); + + // Blend with a cell color, if specified. + sprintf (id, "cell:%d,%d", row, col); + if ((i = mColor.find (id)) != mColor.end ()) + c.blend (i->second); + + return c; } //////////////////////////////////////////////////////////////////////////////// +// TODO Obsolete - this is not used. Consider removal. Color Table::getHeaderColor (int col) { - char idCol[12]; - sprintf (idCol, "col:%d", col); + // Color defaults to trivial. + Color c; - return mColor.find (idCol) != mColor.end () ? mColor[idCol] - : mColor.find ("table") != mColor.end () ? mColor["table"] - : Color (); +/* + std::map ::iterator i; + char id[24]; + + // Blend with a table color, if specified. + if ((i = mColor.find ("table")) != mColor.end ()) + c.blend (i->second); + + // Blend with a column color, if specified. + sprintf (id, "col:%d", col); + if ((i = mColor.find (id)) != mColor.end ()) + c.blend (i->second); +*/ + + return c; } //////////////////////////////////////////////////////////////////////////////// @@ -568,6 +600,7 @@ const std::string Table::formatHeaderDashedUnderline ( //////////////////////////////////////////////////////////////////////////////// void Table::formatCell ( + const int index, const int row, const int col, const int width, @@ -577,7 +610,7 @@ void Table::formatCell ( { assert (width > 0); - Color c = getColor (row, col); + Color c = getColor (index, row, col); just justification = getJustification (row, col); std::string data = getCell (row, col); @@ -1027,13 +1060,6 @@ const std::string Table::render (int maximum /* = 0 */) if (mSortColumns.size ()) sort (order); - // Now blend in the alternate row color. - Color alternate = mColor["alternate"]; - if (alternate.nontrivial ()) - for (unsigned int row = 0; row < order.size (); ++row) - if (row % 2) - setRowColor (order[row], alternate); - // If a non-zero maximum is specified, then it limits the number of rows of // the table that are rendered. int limit = mRows; @@ -1052,6 +1078,7 @@ const std::string Table::render (int maximum /* = 0 */) std::vector lines; std::string blank; formatCell ( + row, order[row], col, mCalculatedWidth[col], diff --git a/src/Table.h b/src/Table.h index 6ca5f2994..6fbd651b4 100644 --- a/src/Table.h +++ b/src/Table.h @@ -57,7 +57,8 @@ public: Table (const Table&); Table& operator= (const Table&); - void setTableColor (const Color&); +// TODO Obsolete - this is not used. Consider removal. +// void setTableColor (const Color&); void setTableAlternateColor (const Color&); void setTablePadding (int); void setTableIntraPadding (int); @@ -65,7 +66,8 @@ public: void setTableDashedUnderline (); int addColumn (const std::string&); - void setColumnColor (int, const Color&); +// TODO Obsolete - this is not used. Consider removal. +// void setColumnColor (int, const Color&); void setColumnUnderline (int); void setColumnPadding (int, int); void setColumnWidth (int, int); @@ -94,7 +96,7 @@ public: private: std::string getCell (const int, const int); - Color getColor (const int, const int); + Color getColor (const int, const int, const int); Color getHeaderColor (const int); Color getHeaderUnderline (const int); int getPadding (const int); @@ -104,7 +106,7 @@ private: 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, std::vector &, std::string&); + void formatCell (const int, const int, const int, const int, const int, std::vector &, std::string&); void sort (std::vector &); void clean (std::string&); void optimize (std::string&) const; @@ -116,6 +118,7 @@ private: std::map mColor; std::map mUnderline; bool mDashedUnderline; + Color alternate; // Padding... int mTablePadding;