From 00a4cbf906901a13a10e1e5459db42813e3595ca Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Fri, 27 Jan 2017 17:32:19 -0500 Subject: [PATCH] CmdHistory: Code Cleanup - Fixed formatting inconsistencies. - Added Lukas to AUTHORS. --- AUTHORS | 1 + src/commands/CmdHistory.cpp | 19 ++++--- src/commands/CmdHistory.h | 110 +++++++++++++++++++++++------------- 3 files changed, 83 insertions(+), 47 deletions(-) diff --git a/AUTHORS b/AUTHORS index cc6fb0a1d..af660ee4e 100644 --- a/AUTHORS +++ b/AUTHORS @@ -137,6 +137,7 @@ The following submitted code, packages or analysis, and deserve special thanks: Jelle van der Waa Flavio Poletti Antonio Huete Jimenez + Lukas Barth Thanks to the following, who submitted detailed bug reports and excellent suggestions: diff --git a/src/commands/CmdHistory.cpp b/src/commands/CmdHistory.cpp index 41aa3efe5..6e5201343 100644 --- a/src/commands/CmdHistory.cpp +++ b/src/commands/CmdHistory.cpp @@ -56,6 +56,7 @@ CmdHistoryBase::CmdHistoryBase () _category = Command::Category::graphs; } +//////////////////////////////////////////////////////////////////////////////// template void CmdHistoryBase::outputGraphical (std::string &output) { @@ -116,10 +117,10 @@ void CmdHistoryBase::outputGraphical (std::string &output) unsigned int completedBar = (widthOfBar * completedGroup[i.first]) / maxLine; unsigned int deletedBar = (widthOfBar * deletedGroup[i.first]) / maxLine; - std::string bar = ""; + std::string bar; if (context.color ()) { - std::string aBar = ""; + std::string aBar; if (addedGroup[i.first]) { aBar = format (addedGroup[i.first]); @@ -127,7 +128,7 @@ void CmdHistoryBase::outputGraphical (std::string &output) aBar = ' ' + aBar; } - std::string cBar = ""; + std::string cBar; if (completedGroup[i.first]) { cBar = format (completedGroup[i.first]); @@ -135,7 +136,7 @@ void CmdHistoryBase::outputGraphical (std::string &output) cBar = ' ' + cBar; } - std::string dBar = ""; + std::string dBar; if (deletedGroup[i.first]) { dBar = format (deletedGroup[i.first]); @@ -151,9 +152,9 @@ void CmdHistoryBase::outputGraphical (std::string &output) } else { - std::string aBar = ""; while (aBar.length () < addedBar) aBar += '+'; - std::string cBar = ""; while (cBar.length () < completedBar) cBar += 'X'; - std::string dBar = ""; while (dBar.length () < deletedBar) dBar += '-'; + std::string aBar; while (aBar.length () < addedBar) aBar += '+'; + std::string cBar; while (cBar.length () < completedBar) cBar += 'X'; + std::string dBar; while (dBar.length () < deletedBar) dBar += '-'; bar += std::string (leftOffset - aBar.length (), ' '); bar += aBar + cBar + dBar; @@ -190,6 +191,7 @@ void CmdHistoryBase::outputGraphical (std::string &output) output = out.str (); } +//////////////////////////////////////////////////////////////////////////////// template void CmdHistoryBase::outputTabular (std::string &output) { @@ -288,6 +290,7 @@ void CmdHistoryBase::outputTabular (std::string &output) output = out.str (); } +//////////////////////////////////////////////////////////////////////////////// template int CmdHistoryBase::execute (std::string& output) { @@ -353,3 +356,5 @@ template class CmdHistoryBase; template class CmdHistoryBase; template class CmdHistoryBase; template class CmdHistoryBase; + +//////////////////////////////////////////////////////////////////////////////// diff --git a/src/commands/CmdHistory.h b/src/commands/CmdHistory.h index 234a53c95..5fd4e25b3 100644 --- a/src/commands/CmdHistory.h +++ b/src/commands/CmdHistory.h @@ -47,23 +47,31 @@ private: std::map deletedGroup; // Deletions by timeinterval int rc; - void outputTabular(std::string&); - void outputGraphical(std::string&); + void outputTabular (std::string&); + void outputGraphical (std::string&); }; ////////////////////////////////////////////////////////////////////////////i -class MonthlyHistoryStrategy { +class MonthlyHistoryStrategy +{ public: - static Datetime getRelevantDate (const Datetime & dt) { + static Datetime getRelevantDate (const Datetime & dt) + { return dt.startOfMonth (); } - static void setupTableDates (Table & view) { + static void setupTableDates (Table & view) + { view.add (STRING_CMD_HISTORY_YEAR); view.add (STRING_CMD_HISTORY_MONTH); } - static void insertRowDate (Table & view, int row, time_t rowTime, time_t lastTime) { + static void insertRowDate ( + Table& view, + int row, + time_t rowTime, + time_t lastTime) + { Datetime dt (rowTime); int m, d, y; dt.toYMD (y, m, d); @@ -76,33 +84,41 @@ public: { view.set (row, 0, y); } - view.set (row, 1, Datetime::monthName(m)); + + view.set (row, 1, Datetime::monthName (m)); } - static constexpr const char * keyword = "history.monthly"; - static constexpr const char * usage = "task history.monthly"; - static constexpr const char * description = STRING_CMD_HISTORY_USAGE_M; + static constexpr const char* keyword = "history.monthly"; + static constexpr const char* usage = "task history.monthly"; + static constexpr const char* description = STRING_CMD_HISTORY_USAGE_M; static constexpr unsigned int dateFieldCount = 2; - static constexpr bool graphical = false; + static constexpr bool graphical = false; }; typedef CmdHistoryBase CmdHistoryMonthly; -//////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////i -class MonthlyGHistoryStrategy { +class MonthlyGHistoryStrategy +{ public: - static Datetime getRelevantDate (const Datetime & dt) { + static Datetime getRelevantDate (const Datetime & dt) + { return dt.startOfMonth (); } - static void setupTableDates (Table & view) { + static void setupTableDates (Table & view) + { view.add (STRING_CMD_HISTORY_YEAR); view.add (STRING_CMD_HISTORY_MONTH); } - static void insertRowDate (Table & view, int row, time_t rowTime, time_t lastTime) { + static void insertRowDate ( + Table& view, + int row, + time_t rowTime, + time_t lastTime) + { Datetime dt (rowTime); int m, d, y; dt.toYMD (y, m, d); @@ -115,32 +131,40 @@ public: { view.set (row, 0, y); } - view.set (row, 1, Datetime::monthName(m)); + + view.set (row, 1, Datetime::monthName (m)); } - static constexpr const char * keyword = "ghistory.monthly"; - static constexpr const char * usage = "task ghistory.monthly"; - static constexpr const char * description = STRING_CMD_GHISTORY_USAGE_M; + static constexpr const char* keyword = "ghistory.monthly"; + static constexpr const char* usage = "task ghistory.monthly"; + static constexpr const char* description = STRING_CMD_GHISTORY_USAGE_M; static constexpr unsigned int dateFieldCount = 2; - static constexpr bool graphical = true; + static constexpr bool graphical = true; }; typedef CmdHistoryBase CmdGHistoryMonthly; -//////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////i -class AnnualHistoryStrategy { +class AnnualHistoryStrategy +{ public: - static Datetime getRelevantDate (const Datetime & dt) { + static Datetime getRelevantDate (const Datetime & dt) + { return dt.startOfYear (); } - static void setupTableDates (Table & view) { + static void setupTableDates (Table & view) + { view.add (STRING_CMD_HISTORY_YEAR); } - static void insertRowDate (Table & view, int row, time_t rowTime, time_t lastTime) { + static void insertRowDate ( + Table& view, + int row, + time_t rowTime, + time_t lastTime) + { Datetime dt (rowTime); int m, d, y; dt.toYMD (y, m, d); @@ -155,29 +179,36 @@ public: } } - static constexpr const char * keyword = "history.annual"; - static constexpr const char * usage = "task history.annual"; - static constexpr const char * description = STRING_CMD_HISTORY_USAGE_A; + static constexpr const char* keyword = "history.annual"; + static constexpr const char* usage = "task history.annual"; + static constexpr const char* description = STRING_CMD_HISTORY_USAGE_A; static constexpr unsigned int dateFieldCount = 1; - static constexpr bool graphical = false; + static constexpr bool graphical = false; }; typedef CmdHistoryBase CmdHistoryAnnual; -//////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////i -class AnnualGHistoryStrategy { +class AnnualGHistoryStrategy +{ public: - static Datetime getRelevantDate (const Datetime & dt) { + static Datetime getRelevantDate (const Datetime & dt) + { return dt.startOfYear (); } - static void setupTableDates (Table & view) { + static void setupTableDates (Table & view) + { view.add (STRING_CMD_HISTORY_YEAR); } - static void insertRowDate (Table & view, int row, time_t rowTime, time_t lastTime) { + static void insertRowDate ( + Table& view, + int row, + time_t rowTime, + time_t lastTime) + { Datetime dt (rowTime); int m, d, y; dt.toYMD (y, m, d); @@ -192,14 +223,13 @@ public: } } - static constexpr const char * keyword = "ghistory.annual"; - static constexpr const char * usage = "task ghistory.annual"; - static constexpr const char * description = STRING_CMD_GHISTORY_USAGE_A; + static constexpr const char* keyword = "ghistory.annual"; + static constexpr const char* usage = "task ghistory.annual"; + static constexpr const char* description = STRING_CMD_GHISTORY_USAGE_A; static constexpr unsigned int dateFieldCount = 1; - static constexpr bool graphical = true; + static constexpr bool graphical = true; }; typedef CmdHistoryBase CmdGHistoryAnnual; -//////////////////////////////////////////////////////////////////////////// #endif