- Fixed bug #1218 so that description columns minimum width is calculated
  correctly.
This commit is contained in:
Paul Beckingham 2013-04-01 18:07:25 -04:00
parent d14a9cacec
commit d895c4a249
6 changed files with 81 additions and 63 deletions

View file

@ -52,7 +52,11 @@ ColumnDescription::ColumnDescription ()
_styles.push_back ("truncated");
_styles.push_back ("count");
std::string t = Date ().toString (context.config.get ("dateformat"));
_dateformat = context.config.get ("dateformat.annotation");
if (_dateformat == "")
_dateformat = context.config.get ("dateformat");
std::string t = Date ().toString (_dateformat);
std::string d = STRING_COLUMN_EXAMPLES_DESC;
std::string a1 = STRING_COLUMN_EXAMPLES_ANNO1;
std::string a2 = STRING_COLUMN_EXAMPLES_ANNO2;
@ -74,6 +78,8 @@ ColumnDescription::ColumnDescription ()
_examples.push_back (d + " [4]");
_hyphenate = context.config.getBoolean ("hyphenate");
_indent = context.config.getInteger ("indent.annotation");
}
////////////////////////////////////////////////////////////////////////////////
@ -99,24 +105,24 @@ void ColumnDescription::measure (Task& task, unsigned int& minimum, unsigned int
if (_style == "default" ||
_style == "combined")
{
int indent = context.config.getInteger ("indent.annotation");
std::string format = context.config.get ("dateformat.annotation");
if (format == "")
format = context.config.get ("dateformat");
int min_desc = longestWord (description);
int min_anno = indent + Date::length (format);
minimum = std::max (min_desc, min_anno);
minimum = longestWord (description);
maximum = utf8_width (description);
std::map <std::string, std::string> annos;
task.getAnnotations (annos);
std::map <std::string, std::string>::iterator i;
for (i = annos.begin (); i != annos.end (); i++)
if (task.annotation_count)
{
unsigned int len = min_anno + 1 + utf8_width (i->second);
if (len > maximum)
maximum = len;
int min_anno = _indent + Date::length (_dateformat);
if (min_anno > minimum)
minimum = min_anno;
std::map <std::string, std::string> annos;
task.getAnnotations (annos);
std::map <std::string, std::string>::iterator i;
for (i = annos.begin (); i != annos.end (); i++)
{
unsigned int len = min_anno + 1 + utf8_width (i->second);
if (len > maximum)
maximum = len;
}
}
}
@ -130,20 +136,18 @@ void ColumnDescription::measure (Task& task, unsigned int& minimum, unsigned int
// The text <date> <anno> ...
else if (_style == "oneline")
{
std::string format = context.config.get ("dateformat.annotation");
if (format == "")
format = context.config.get ("dateformat");
int min_desc = longestWord (description);
int min_anno = Date::length (format);
minimum = std::max (min_desc, min_anno);
minimum = longestWord (description);
maximum = utf8_width (description);
std::map <std::string, std::string> annos;
task.getAnnotations (annos);
std::map <std::string, std::string>::iterator i;
for (i = annos.begin (); i != annos.end (); i++)
maximum += utf8_width (i->second) + minimum + 1;
if (task.annotation_count)
{
int min_anno = Date::length (_dateformat);
std::map <std::string, std::string> annos;
task.getAnnotations (annos);
std::map <std::string, std::string>::iterator i;
for (i = annos.begin (); i != annos.end (); i++)
maximum += min_anno + 1 + utf8_width (i->second);
}
}
// The te...
@ -156,11 +160,8 @@ void ColumnDescription::measure (Task& task, unsigned int& minimum, unsigned int
// The text [2]
else if (_style == "count")
{
std::map <std::string, std::string> annos;
task.getAnnotations (annos);
// <description> + ' ' + '[' + <count> + ']'
maximum = utf8_width (description) + 3 + utf8_width (format ((int)annos.size ()));
maximum = utf8_width (description) + 1 + 1 + format (task.annotation_count).length () + 1;
minimum = longestWord (description);
}
@ -183,21 +184,15 @@ void ColumnDescription::render (
if (_style == "default" ||
_style == "combined")
{
int indent = context.config.getInteger ("indent.annotation");
std::map <std::string, std::string> annos;
task.getAnnotations (annos);
if (annos.size ())
{
std::string format = context.config.get ("dateformat.annotation");
if (format == "")
format = context.config.get ("dateformat");
std::map <std::string, std::string>::iterator i;
for (i = annos.begin (); i != annos.end (); i++)
{
Date dt (strtol (i->first.substr (11).c_str (), NULL, 10));
description += "\n" + std::string (indent, ' ') + dt.toString (format) + " " + i->second;
description += "\n" + std::string (_indent, ' ') + dt.toString (_dateformat) + " " + i->second;
}
}
@ -227,15 +222,11 @@ void ColumnDescription::render (
task.getAnnotations (annos);
if (annos.size ())
{
std::string format = context.config.get ("dateformat.annotation");
if (format == "")
format = context.config.get ("dateformat");
std::map <std::string, std::string>::iterator i;
for (i = annos.begin (); i != annos.end (); i++)
{
Date dt (atoi (i->first.substr (11).c_str ()));
description += " " + dt.toString (format) + " " + i->second;
description += " " + dt.toString (_dateformat) + " " + i->second;
}
}

View file

@ -47,6 +47,8 @@ public:
private:
bool _hyphenate;
std::string _dateformat;
int _indent;
};
#endif