Task: Improved method signature

This commit is contained in:
Paul Beckingham 2016-12-31 15:44:13 -05:00
parent 6c9660aee8
commit fab2979b87
6 changed files with 9 additions and 24 deletions

View file

@ -1313,9 +1313,9 @@ void Task::addTags (const std::vector <std::string>& tags)
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
void Task::getTags (std::vector<std::string>& tags) const std::vector <std::string> Task::getTags () const
{ {
tags = split (get ("tags"), ','); return split (get ("tags"), ',');
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////

View file

@ -125,7 +125,7 @@ public:
bool hasTag (const std::string&) const; bool hasTag (const std::string&) const;
void addTag (const std::string&); void addTag (const std::string&);
void addTags (const std::vector <std::string>&); void addTags (const std::vector <std::string>&);
void getTags (std::vector<std::string>&) const; std::vector <std::string> getTags () const;
void removeTag (const std::string&); void removeTag (const std::string&);
bool hasAnnotations () const; bool hasAnnotations () const;

View file

@ -224,14 +224,10 @@ std::string CmdEdit::formatTask (Task task, const std::string& dateformat)
<< "# iMask: " << task.get ("imask") << '\n' << "# iMask: " << task.get ("imask") << '\n'
<< " Project: " << task.get ("project") << '\n'; << " Project: " << task.get ("project") << '\n';
std::vector <std::string> tags;
task.getTags (tags);
auto allTags = join (" ", tags);
if (verbose) if (verbose)
before << "# " << STRING_EDIT_TAG_SEP << '\n'; before << "# " << STRING_EDIT_TAG_SEP << '\n';
before << " Tags: " << allTags << '\n' before << " Tags: " << join (" ", task.getTags ()) << '\n'
<< " Description: " << task.get ("description") << '\n' << " Description: " << task.get ("description") << '\n'
<< " Created: " << formatDate (task, "entry", dateformat) << '\n' << " Created: " << formatDate (task, "entry", dateformat) << '\n'
<< " Started: " << formatDate (task, "start", dateformat) << '\n' << " Started: " << formatDate (task, "start", dateformat) << '\n'
@ -353,9 +349,8 @@ void CmdEdit::parseTask (Task& task, const std::string& after, const std::string
// tags // tags
value = findValue (after, "\n Tags:"); value = findValue (after, "\n Tags:");
auto tags = split (value, ' ');
task.remove ("tags"); task.remove ("tags");
task.addTags (tags); task.addTags (split (value, ' '));
// description. // description.
value = findMultilineValue (after, "\n Description:", "\n Created:"); value = findMultilineValue (after, "\n Description:", "\n Created:");

View file

@ -300,8 +300,7 @@ int CmdInfo::execute (std::string& output)
} }
// tags ... // tags ...
std::vector <std::string> tags; auto tags = task.getTags ();
task.getTags (tags);
if (tags.size ()) if (tags.size ())
{ {
auto allTags = join (" ", tags); auto allTags = join (" ", tags);

View file

@ -145,8 +145,7 @@ int CmdStats::execute (std::string& output)
task.getAnnotations (annotations); task.getAnnotations (annotations);
annotationsT += annotations.size (); annotationsT += annotations.size ();
std::vector <std::string> tags; auto tags = task.getTags ();
task.getTags (tags);
if (tags.size ()) if (tags.size ())
++taggedT; ++taggedT;

View file

@ -79,10 +79,7 @@ int CmdTags::execute (std::string& output)
std::map <std::string, int> unique; std::map <std::string, int> unique;
for (auto& task : filtered) for (auto& task : filtered)
{ {
std::vector <std::string> tags; for (auto& tag : task.getTags ())
task.getTags (tags);
for (auto& tag : tags)
if (unique.find (tag) != unique.end ()) if (unique.find (tag) != unique.end ())
unique[tag]++; unique[tag]++;
else else
@ -182,13 +179,8 @@ int CmdCompletionTags::execute (std::string& output)
// names as keys. // names as keys.
std::map <std::string, int> unique; std::map <std::string, int> unique;
for (auto& task : filtered) for (auto& task : filtered)
{ for (auto& tag : task.getTags ())
std::vector <std::string> tags;
task.getTags (tags);
for (auto& tag : tags)
unique[tag] = 0; unique[tag] = 0;
}
// Add built-in tags to map. // Add built-in tags to map.
unique["nocolor"] = 0; unique["nocolor"] = 0;