mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-07-07 20:06:36 +02:00
Task: Improved method signature
This commit is contained in:
parent
cfc3e098c1
commit
5193f7d03e
10 changed files with 21 additions and 49 deletions
|
@ -300,8 +300,7 @@ bool getDOM (const std::string& name, const Task& task, Variant& value)
|
|||
|
||||
if (ref.data.size () && size == 3 && elements[0] == "annotations")
|
||||
{
|
||||
std::map <std::string, std::string> annos;
|
||||
ref.getAnnotations (annos);
|
||||
auto annos = ref.getAnnotations ();
|
||||
|
||||
int a = strtol (elements[1].c_str (), NULL, 10);
|
||||
int count = 0;
|
||||
|
@ -329,8 +328,7 @@ bool getDOM (const std::string& name, const Task& task, Variant& value)
|
|||
|
||||
if (ref.data.size () && size == 4 && elements[0] == "annotations" && elements[2] == "entry")
|
||||
{
|
||||
std::map <std::string, std::string> annos;
|
||||
ref.getAnnotations (annos);
|
||||
auto annos = ref.getAnnotations ();
|
||||
|
||||
int a = strtol (elements[1].c_str (), NULL, 10);
|
||||
int count = 0;
|
||||
|
|
12
src/Task.cpp
12
src/Task.cpp
|
@ -1081,13 +1081,14 @@ void Task::removeAnnotations ()
|
|||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
void Task::getAnnotations (std::map <std::string, std::string>& annotations) const
|
||||
std::map <std::string, std::string> Task::getAnnotations () const
|
||||
{
|
||||
annotations.clear ();
|
||||
|
||||
std::map <std::string, std::string> a;
|
||||
for (auto& ann : data)
|
||||
if (! ann.first.compare (0, 11, "annotation_", 11))
|
||||
annotations.insert (ann);
|
||||
a.insert (ann);
|
||||
|
||||
return a;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -1357,8 +1358,7 @@ void Task::substitute (
|
|||
|
||||
// Get the data to modify.
|
||||
std::string description = get ("description");
|
||||
std::map <std::string, std::string> annotations;
|
||||
getAnnotations (annotations);
|
||||
auto annotations = getAnnotations ();
|
||||
|
||||
// Count the changes, so we know whether to proceed to annotations, after
|
||||
// modifying description.
|
||||
|
|
|
@ -129,7 +129,7 @@ public:
|
|||
void removeTag (const std::string&);
|
||||
|
||||
bool hasAnnotations () const;
|
||||
void getAnnotations (std::map <std::string, std::string>&) const;
|
||||
std::map <std::string, std::string> getAnnotations () const;
|
||||
void setAnnotations (const std::map <std::string, std::string>&);
|
||||
void addAnnotation (const std::string&);
|
||||
void removeAnnotations ();
|
||||
|
|
|
@ -874,10 +874,7 @@ bool Variant::operator_match (const Variant& other, const Task& task) const
|
|||
// in the annotations.
|
||||
if (left.source () == "description")
|
||||
{
|
||||
std::map <std::string, std::string> annotations;
|
||||
task.getAnnotations (annotations);
|
||||
|
||||
for (auto& a : annotations)
|
||||
for (auto& a : task.getAnnotations ())
|
||||
if (r.match (a.second))
|
||||
return true;
|
||||
}
|
||||
|
@ -909,10 +906,7 @@ bool Variant::operator_match (const Variant& other, const Task& task) const
|
|||
// in the annotations.
|
||||
if (left.source () == "description")
|
||||
{
|
||||
std::map <std::string, std::string> annotations;
|
||||
task.getAnnotations (annotations);
|
||||
|
||||
for (auto& a : annotations)
|
||||
for (auto& a : task.getAnnotations ())
|
||||
if (find (a.second, pattern, searchCaseSensitive) != std::string::npos)
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -102,9 +102,7 @@ void ColumnDescription::measure (Task& task, unsigned int& minimum, unsigned int
|
|||
if (min_anno > minimum)
|
||||
minimum = min_anno;
|
||||
|
||||
std::map <std::string, std::string> annos;
|
||||
task.getAnnotations (annos);
|
||||
for (auto& i : annos)
|
||||
for (auto& i : task.getAnnotations ())
|
||||
{
|
||||
unsigned int len = min_anno + 1 + utf8_width (i.second);
|
||||
if (len > maximum)
|
||||
|
@ -129,9 +127,7 @@ void ColumnDescription::measure (Task& task, unsigned int& minimum, unsigned int
|
|||
if (task.annotation_count)
|
||||
{
|
||||
auto min_anno = Datetime::length (_dateformat);
|
||||
std::map <std::string, std::string> annos;
|
||||
task.getAnnotations (annos);
|
||||
for (auto& i : annos)
|
||||
for (auto& i : task.getAnnotations ())
|
||||
maximum += min_anno + 1 + utf8_width (i.second);
|
||||
}
|
||||
}
|
||||
|
@ -179,9 +175,7 @@ void ColumnDescription::render (
|
|||
{
|
||||
if (task.annotation_count)
|
||||
{
|
||||
std::map <std::string, std::string> annos;
|
||||
task.getAnnotations (annos);
|
||||
for (const auto& i : annos)
|
||||
for (const auto& i : task.getAnnotations ())
|
||||
{
|
||||
Datetime dt (strtol (i.first.substr (11).c_str (), NULL, 10));
|
||||
description += '\n' + std::string (_indent, ' ') + dt.toString (_dateformat) + ' ' + i.second;
|
||||
|
@ -210,9 +204,7 @@ void ColumnDescription::render (
|
|||
{
|
||||
if (task.annotation_count)
|
||||
{
|
||||
std::map <std::string, std::string> annos;
|
||||
task.getAnnotations (annos);
|
||||
for (const auto& i : annos)
|
||||
for (const auto& i : task.getAnnotations ())
|
||||
{
|
||||
Datetime dt (strtol (i.first.substr (11).c_str (), NULL, 10));
|
||||
description += ' ' + dt.toString (_dateformat) + ' ' + i.second;
|
||||
|
|
|
@ -90,8 +90,7 @@ int CmdDenotate::execute (std::string&)
|
|||
{
|
||||
Task before (task);
|
||||
|
||||
std::map <std::string, std::string> annotations;
|
||||
task.getAnnotations (annotations);
|
||||
auto annotations = task.getAnnotations ();
|
||||
|
||||
if (annotations.size () == 0)
|
||||
throw std::string (STRING_CMD_DENO_NONE);
|
||||
|
|
|
@ -245,9 +245,7 @@ std::string CmdEdit::formatTask (Task task, const std::string& dateformat)
|
|||
<< "# " << STRING_EDIT_HEADER_14 << '\n'
|
||||
<< "# " << STRING_EDIT_HEADER_15 << '\n';
|
||||
|
||||
std::map <std::string, std::string> annotations;
|
||||
task.getAnnotations (annotations);
|
||||
for (auto& anno : annotations)
|
||||
for (auto& anno : task.getAnnotations ())
|
||||
{
|
||||
Datetime dt (strtol (anno.first.substr (11).c_str (), NULL, 10));
|
||||
before << " Annotation: " << dt.toString (dateformat)
|
||||
|
|
|
@ -134,9 +134,7 @@ int CmdInfo::execute (std::string& output)
|
|||
std::string description = task.get ("description");
|
||||
int indent = context.config.getInteger ("indent.annotation");
|
||||
|
||||
std::map <std::string, std::string> annotations;
|
||||
task.getAnnotations (annotations);
|
||||
for (auto& anno : annotations)
|
||||
for (auto& anno : task.getAnnotations ())
|
||||
description += '\n'
|
||||
+ std::string (indent, ' ')
|
||||
+ Datetime (anno.first.substr (11)).toString (dateformatanno)
|
||||
|
|
|
@ -140,10 +140,7 @@ int CmdStats::execute (std::string& output)
|
|||
daysPending += (now.toEpoch () - entry) / 86400.0;
|
||||
|
||||
descLength += task.get ("description").length ();
|
||||
|
||||
std::map <std::string, std::string> annotations;
|
||||
task.getAnnotations (annotations);
|
||||
annotationsT += annotations.size ();
|
||||
annotationsT += task.getAnnotations ().size ();
|
||||
|
||||
auto tags = task.getTags ();
|
||||
if (tags.size ())
|
||||
|
|
|
@ -142,9 +142,7 @@ int CmdTimesheet::execute (std::string& output)
|
|||
std::string description = task.get ("description");
|
||||
int indent = context.config.getInteger ("indent.annotation");
|
||||
|
||||
std::map <std::string, std::string> annotations;
|
||||
task.getAnnotations (annotations);
|
||||
for (auto& ann : annotations)
|
||||
for (auto& ann : task.getAnnotations ())
|
||||
description += '\n'
|
||||
+ std::string (indent, ' ')
|
||||
+ Datetime (ann.first.substr (11)).toString (context.config.get ("dateformat"))
|
||||
|
@ -198,9 +196,7 @@ int CmdTimesheet::execute (std::string& output)
|
|||
std::string description = task.get ("description");
|
||||
int indent = context.config.getInteger ("indent.annotation");
|
||||
|
||||
std::map <std::string, std::string> annotations;
|
||||
task.getAnnotations (annotations);
|
||||
for (auto& ann : annotations)
|
||||
for (auto& ann : task.getAnnotations ())
|
||||
description += '\n'
|
||||
+ std::string (indent, ' ')
|
||||
+ Datetime (ann.first.substr (11)).toString (context.config.get ("dateformat"))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue