mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-06-26 10:54:26 +02:00
Replace direct Task.data access with a temp getter (syntactic refactor)
Now this getter, `data_removeme`, can easily be grepped out and replaced, one usage at a time in small PRs.
This commit is contained in:
parent
3a00956144
commit
dede40bc4e
10 changed files with 29 additions and 26 deletions
22
src/DOM.cpp
22
src/DOM.cpp
|
@ -246,13 +246,13 @@ bool getDOM (const std::string& name, const Task& task, Variant& value)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Quickly deal with the most common cases.
|
// Quickly deal with the most common cases.
|
||||||
if (task.data.size () && name == "id")
|
if (task.data_removeme ().size () && name == "id")
|
||||||
{
|
{
|
||||||
value = Variant (static_cast<int> (task.id));
|
value = Variant (static_cast<int> (task.id));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (task.data.size () && name == "urgency")
|
if (task.data_removeme ().size () && name == "urgency")
|
||||||
{
|
{
|
||||||
value = Variant (task.urgency_c ());
|
value = Variant (task.urgency_c ());
|
||||||
return true;
|
return true;
|
||||||
|
@ -318,13 +318,13 @@ bool getDOM (const std::string& name, const Task& task, Variant& value)
|
||||||
{
|
{
|
||||||
// Now that 'ref' is the contextual task, and any ID/UUID is chopped off the
|
// Now that 'ref' is the contextual task, and any ID/UUID is chopped off the
|
||||||
// elements vector, DOM resolution is now simple.
|
// elements vector, DOM resolution is now simple.
|
||||||
if (ref.data.size () && size == 1 && canonical == "id")
|
if (ref.data_removeme ().size () && size == 1 && canonical == "id")
|
||||||
{
|
{
|
||||||
value = Variant (static_cast<int> (ref.id));
|
value = Variant (static_cast<int> (ref.id));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ref.data.size () && size == 1 && canonical == "urgency")
|
if (ref.data_removeme ().size () && size == 1 && canonical == "urgency")
|
||||||
{
|
{
|
||||||
value = Variant (ref.urgency_c ());
|
value = Variant (ref.urgency_c ());
|
||||||
return true;
|
return true;
|
||||||
|
@ -332,7 +332,7 @@ bool getDOM (const std::string& name, const Task& task, Variant& value)
|
||||||
|
|
||||||
// Special handling of status required for virtual waiting status
|
// Special handling of status required for virtual waiting status
|
||||||
// implementation. Remove in 3.0.0.
|
// implementation. Remove in 3.0.0.
|
||||||
if (ref.data.size () && size == 1 && canonical == "status")
|
if (ref.data_removeme ().size () && size == 1 && canonical == "status")
|
||||||
{
|
{
|
||||||
value = Variant (ref.statusToText (ref.getStatus ()));
|
value = Variant (ref.statusToText (ref.getStatus ()));
|
||||||
return true;
|
return true;
|
||||||
|
@ -340,7 +340,7 @@ bool getDOM (const std::string& name, const Task& task, Variant& value)
|
||||||
|
|
||||||
Column* column = Context::getContext ().columns[canonical];
|
Column* column = Context::getContext ().columns[canonical];
|
||||||
|
|
||||||
if (ref.data.size () && size == 1 && column)
|
if (ref.data_removeme ().size () && size == 1 && column)
|
||||||
{
|
{
|
||||||
if (column->is_uda () && ! ref.has (canonical))
|
if (column->is_uda () && ! ref.has (canonical))
|
||||||
{
|
{
|
||||||
|
@ -375,13 +375,13 @@ bool getDOM (const std::string& name, const Task& task, Variant& value)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ref.data.size () && size == 2 && canonical == "tags")
|
if (ref.data_removeme ().size () && size == 2 && canonical == "tags")
|
||||||
{
|
{
|
||||||
value = Variant (ref.hasTag (elements[1]) ? elements[1] : "");
|
value = Variant (ref.hasTag (elements[1]) ? elements[1] : "");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ref.data.size () && size == 2 && column && column->type () == "date")
|
if (ref.data_removeme ().size () && size == 2 && column && column->type () == "date")
|
||||||
{
|
{
|
||||||
Datetime date (ref.get_date (canonical));
|
Datetime date (ref.get_date (canonical));
|
||||||
if (elements[1] == "year") { value = Variant (static_cast<int> (date.year ())); return true; }
|
if (elements[1] == "year") { value = Variant (static_cast<int> (date.year ())); return true; }
|
||||||
|
@ -396,13 +396,13 @@ bool getDOM (const std::string& name, const Task& task, Variant& value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ref.data.size () && size == 2 && elements[0] == "annotations" && elements[1] == "count")
|
if (ref.data_removeme ().size () && size == 2 && elements[0] == "annotations" && elements[1] == "count")
|
||||||
{
|
{
|
||||||
value = Variant (static_cast<int> (ref.getAnnotationCount ()));
|
value = Variant (static_cast<int> (ref.getAnnotationCount ()));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ref.data.size () && size == 3 && elements[0] == "annotations")
|
if (ref.data_removeme ().size () && size == 3 && elements[0] == "annotations")
|
||||||
{
|
{
|
||||||
auto annos = ref.getAnnotations ();
|
auto annos = ref.getAnnotations ();
|
||||||
|
|
||||||
|
@ -430,7 +430,7 @@ bool getDOM (const std::string& name, const Task& task, Variant& value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ref.data.size () && size == 4 && elements[0] == "annotations" && elements[2] == "entry")
|
if (ref.data_removeme ().size () && size == 4 && elements[0] == "annotations" && elements[2] == "entry")
|
||||||
{
|
{
|
||||||
auto annos = ref.getAnnotations ();
|
auto annos = ref.getAnnotations ();
|
||||||
|
|
||||||
|
|
12
src/TDB2.cpp
12
src/TDB2.cpp
|
@ -1048,11 +1048,11 @@ void TDB2::show_diff (
|
||||||
Task before (prior);
|
Task before (prior);
|
||||||
|
|
||||||
std::vector <std::string> beforeAtts;
|
std::vector <std::string> beforeAtts;
|
||||||
for (auto& att : before.data)
|
for (auto& att : before.data_removeme ())
|
||||||
beforeAtts.push_back (att.first);
|
beforeAtts.push_back (att.first);
|
||||||
|
|
||||||
std::vector <std::string> afterAtts;
|
std::vector <std::string> afterAtts;
|
||||||
for (auto& att : after.data)
|
for (auto& att : after.data_removeme ())
|
||||||
afterAtts.push_back (att.first);
|
afterAtts.push_back (att.first);
|
||||||
|
|
||||||
std::vector <std::string> beforeOnly;
|
std::vector <std::string> beforeOnly;
|
||||||
|
@ -1067,7 +1067,7 @@ void TDB2::show_diff (
|
||||||
view.set (row, 1, renderAttribute (name, before.get (name)), color_red);
|
view.set (row, 1, renderAttribute (name, before.get (name)), color_red);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto& att : before.data)
|
for (auto& att : before.data_removeme ())
|
||||||
{
|
{
|
||||||
std::string priorValue = before.get (att.first);
|
std::string priorValue = before.get (att.first);
|
||||||
std::string currentValue = after.get (att.first);
|
std::string currentValue = after.get (att.first);
|
||||||
|
@ -1093,7 +1093,7 @@ void TDB2::show_diff (
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
int row;
|
int row;
|
||||||
for (auto& att : after.data)
|
for (auto& att : after.data_removeme ())
|
||||||
{
|
{
|
||||||
row = view.addRow ();
|
row = view.addRow ();
|
||||||
view.set (row, 0, att.first);
|
view.set (row, 0, att.first);
|
||||||
|
@ -1151,11 +1151,11 @@ void TDB2::show_diff (
|
||||||
std::vector <std::string> all = Context::getContext ().getColumns ();
|
std::vector <std::string> all = Context::getContext ().getColumns ();
|
||||||
|
|
||||||
// Now factor in the annotation attributes.
|
// Now factor in the annotation attributes.
|
||||||
for (auto& it : before.data)
|
for (auto& it : before.data_removeme ())
|
||||||
if (it.first.substr (0, 11) == "annotation_")
|
if (it.first.substr (0, 11) == "annotation_")
|
||||||
all.push_back (it.first);
|
all.push_back (it.first);
|
||||||
|
|
||||||
for (auto& it : after.data)
|
for (auto& it : after.data_removeme ())
|
||||||
if (it.first.substr (0, 11) == "annotation_")
|
if (it.first.substr (0, 11) == "annotation_")
|
||||||
all.push_back (it.first);
|
all.push_back (it.first);
|
||||||
|
|
||||||
|
|
|
@ -74,7 +74,7 @@ public:
|
||||||
enum dateState {dateNotDue, dateAfterToday, dateLaterToday, dateEarlierToday, dateBeforeToday};
|
enum dateState {dateNotDue, dateAfterToday, dateLaterToday, dateEarlierToday, dateBeforeToday};
|
||||||
|
|
||||||
// Public data.
|
// Public data.
|
||||||
std::map <std::string, std::string> data {};
|
const std::map <std::string, std::string> &data_removeme () const { return data; };
|
||||||
int id {0};
|
int id {0};
|
||||||
float urgency_value {0.0};
|
float urgency_value {0.0};
|
||||||
bool recalc_urgency {true};
|
bool recalc_urgency {true};
|
||||||
|
@ -187,6 +187,9 @@ private:
|
||||||
void fixDependsAttribute ();
|
void fixDependsAttribute ();
|
||||||
void fixTagsAttribute ();
|
void fixTagsAttribute ();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
std::map <std::string, std::string> data {};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
float urgency_project () const;
|
float urgency_project () const;
|
||||||
float urgency_active () const;
|
float urgency_active () const;
|
||||||
|
|
|
@ -128,7 +128,7 @@ int CmdDenotate::execute (std::string&)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (before.data != task.data)
|
if (before.data_removeme () != task.data_removeme ())
|
||||||
{
|
{
|
||||||
auto question = format ("Denotate task {1} '{2}'?",
|
auto question = format ("Denotate task {1} '{2}'?",
|
||||||
task.identifier (true),
|
task.identifier (true),
|
||||||
|
|
|
@ -198,7 +198,7 @@ void CmdImport::importSingleTask (json::object* obj)
|
||||||
if (hasGeneratedEnd)
|
if (hasGeneratedEnd)
|
||||||
task.set ("end", before.get ("end"));
|
task.set ("end", before.get ("end"));
|
||||||
|
|
||||||
if (before.data != task.data)
|
if (before.data_removeme() != task.data_removeme())
|
||||||
{
|
{
|
||||||
CmdModify modHelper;
|
CmdModify modHelper;
|
||||||
modHelper.checkConsistency (before, task);
|
modHelper.checkConsistency (before, task);
|
||||||
|
|
|
@ -79,7 +79,7 @@ int CmdModify::execute (std::string&)
|
||||||
Task before (task);
|
Task before (task);
|
||||||
task.modify (Task::modReplace);
|
task.modify (Task::modReplace);
|
||||||
|
|
||||||
if (before.data != task.data)
|
if (before.data_removeme () != task.data_removeme ())
|
||||||
{
|
{
|
||||||
// Abort if change introduces inconsistencies.
|
// Abort if change introduces inconsistencies.
|
||||||
checkConsistency(before, task);
|
checkConsistency(before, task);
|
||||||
|
|
|
@ -134,7 +134,7 @@ int CmdUDAs::execute (std::string& output)
|
||||||
std::map <std::string, int> orphans;
|
std::map <std::string, int> orphans;
|
||||||
for (auto& i : filtered)
|
for (auto& i : filtered)
|
||||||
{
|
{
|
||||||
for (auto& att : i.data)
|
for (auto& att : i.data_removeme ())
|
||||||
if (! Task::isAnnotationAttr (att.first) &&
|
if (! Task::isAnnotationAttr (att.first) &&
|
||||||
! Task::isTagAttr (att.first) &&
|
! Task::isTagAttr (att.first) &&
|
||||||
! Task::isDepAttr (att.first) &&
|
! Task::isDepAttr (att.first) &&
|
||||||
|
|
|
@ -189,7 +189,7 @@ static void colorizeKeyword (Task& task, const std::string& rule, const Color& b
|
||||||
// first match.
|
// first match.
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
for (const auto& att : task.data)
|
for (const auto& att : task.data_removeme ())
|
||||||
{
|
{
|
||||||
if (! att.first.compare (0, 11, "annotation_", 11) &&
|
if (! att.first.compare (0, 11, "annotation_", 11) &&
|
||||||
find (att.second, rule.substr (14), sensitive) != std::string::npos)
|
find (att.second, rule.substr (14), sensitive) != std::string::npos)
|
||||||
|
|
|
@ -187,7 +187,7 @@ TODO Task::decode
|
||||||
test.is (task.get ("three"), "four", "three=four");
|
test.is (task.get ("three"), "four", "three=four");
|
||||||
|
|
||||||
// Task::set
|
// Task::set
|
||||||
task.data.clear ();
|
task = Task();
|
||||||
task.set ("name", "value");
|
task.set ("name", "value");
|
||||||
test.is (task.composeF4 (), "[name:\"value\"]", "Task::set");
|
test.is (task.composeF4 (), "[name:\"value\"]", "Task::set");
|
||||||
|
|
||||||
|
@ -211,7 +211,7 @@ TODO Task::decode
|
||||||
test.is (task.composeF4 (), "[name:\"value\"]", "Task::remove");
|
test.is (task.composeF4 (), "[name:\"value\"]", "Task::remove");
|
||||||
|
|
||||||
// Task::all
|
// Task::all
|
||||||
test.is (task.data.size (), (size_t)1, "Task::all size");
|
test.is (task.data_removeme ().size (), (size_t)1, "Task::all size");
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
|
@ -58,7 +58,7 @@ int main (int, char**)
|
||||||
Task rightAgain (right);
|
Task rightAgain (right);
|
||||||
|
|
||||||
std::string output = left.diff (right);
|
std::string output = left.diff (right);
|
||||||
t.ok (left.data != right.data, "Detected changes");
|
t.ok (!(left == right), "Detected changes");
|
||||||
t.ok (output.find ("Zero will be changed from '0' to '00'") != std::string::npos, "Detected change zero:0 -> zero:00");
|
t.ok (output.find ("Zero will be changed from '0' to '00'") != std::string::npos, "Detected change zero:0 -> zero:00");
|
||||||
t.ok (output.find ("One will be deleted") != std::string::npos, "Detected deletion one:1 ->");
|
t.ok (output.find ("One will be deleted") != std::string::npos, "Detected deletion one:1 ->");
|
||||||
t.ok (output.find ("Two") == std::string::npos, "Detected no change two:2 -> two:2");
|
t.ok (output.find ("Two") == std::string::npos, "Detected no change two:2 -> two:2");
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue