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;
|
||||
|
||||
// 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));
|
||||
return true;
|
||||
}
|
||||
|
||||
if (task.data.size () && name == "urgency")
|
||||
if (task.data_removeme ().size () && name == "urgency")
|
||||
{
|
||||
value = Variant (task.urgency_c ());
|
||||
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
|
||||
// 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));
|
||||
return true;
|
||||
}
|
||||
|
||||
if (ref.data.size () && size == 1 && canonical == "urgency")
|
||||
if (ref.data_removeme ().size () && size == 1 && canonical == "urgency")
|
||||
{
|
||||
value = Variant (ref.urgency_c ());
|
||||
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
|
||||
// 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 ()));
|
||||
return true;
|
||||
|
@ -340,7 +340,7 @@ bool getDOM (const std::string& name, const Task& task, Variant& value)
|
|||
|
||||
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))
|
||||
{
|
||||
|
@ -375,13 +375,13 @@ bool getDOM (const std::string& name, const Task& task, Variant& value)
|
|||
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] : "");
|
||||
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));
|
||||
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 ()));
|
||||
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 ();
|
||||
|
||||
|
@ -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 ();
|
||||
|
||||
|
|
12
src/TDB2.cpp
12
src/TDB2.cpp
|
@ -1048,11 +1048,11 @@ void TDB2::show_diff (
|
|||
Task before (prior);
|
||||
|
||||
std::vector <std::string> beforeAtts;
|
||||
for (auto& att : before.data)
|
||||
for (auto& att : before.data_removeme ())
|
||||
beforeAtts.push_back (att.first);
|
||||
|
||||
std::vector <std::string> afterAtts;
|
||||
for (auto& att : after.data)
|
||||
for (auto& att : after.data_removeme ())
|
||||
afterAtts.push_back (att.first);
|
||||
|
||||
std::vector <std::string> beforeOnly;
|
||||
|
@ -1067,7 +1067,7 @@ void TDB2::show_diff (
|
|||
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 currentValue = after.get (att.first);
|
||||
|
@ -1093,7 +1093,7 @@ void TDB2::show_diff (
|
|||
else
|
||||
{
|
||||
int row;
|
||||
for (auto& att : after.data)
|
||||
for (auto& att : after.data_removeme ())
|
||||
{
|
||||
row = view.addRow ();
|
||||
view.set (row, 0, att.first);
|
||||
|
@ -1151,11 +1151,11 @@ void TDB2::show_diff (
|
|||
std::vector <std::string> all = Context::getContext ().getColumns ();
|
||||
|
||||
// Now factor in the annotation attributes.
|
||||
for (auto& it : before.data)
|
||||
for (auto& it : before.data_removeme ())
|
||||
if (it.first.substr (0, 11) == "annotation_")
|
||||
all.push_back (it.first);
|
||||
|
||||
for (auto& it : after.data)
|
||||
for (auto& it : after.data_removeme ())
|
||||
if (it.first.substr (0, 11) == "annotation_")
|
||||
all.push_back (it.first);
|
||||
|
||||
|
|
|
@ -74,7 +74,7 @@ public:
|
|||
enum dateState {dateNotDue, dateAfterToday, dateLaterToday, dateEarlierToday, dateBeforeToday};
|
||||
|
||||
// Public data.
|
||||
std::map <std::string, std::string> data {};
|
||||
const std::map <std::string, std::string> &data_removeme () const { return data; };
|
||||
int id {0};
|
||||
float urgency_value {0.0};
|
||||
bool recalc_urgency {true};
|
||||
|
@ -187,6 +187,9 @@ private:
|
|||
void fixDependsAttribute ();
|
||||
void fixTagsAttribute ();
|
||||
|
||||
protected:
|
||||
std::map <std::string, std::string> data {};
|
||||
|
||||
public:
|
||||
float urgency_project () 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}'?",
|
||||
task.identifier (true),
|
||||
|
|
|
@ -198,7 +198,7 @@ void CmdImport::importSingleTask (json::object* obj)
|
|||
if (hasGeneratedEnd)
|
||||
task.set ("end", before.get ("end"));
|
||||
|
||||
if (before.data != task.data)
|
||||
if (before.data_removeme() != task.data_removeme())
|
||||
{
|
||||
CmdModify modHelper;
|
||||
modHelper.checkConsistency (before, task);
|
||||
|
|
|
@ -79,7 +79,7 @@ int CmdModify::execute (std::string&)
|
|||
Task before (task);
|
||||
task.modify (Task::modReplace);
|
||||
|
||||
if (before.data != task.data)
|
||||
if (before.data_removeme () != task.data_removeme ())
|
||||
{
|
||||
// Abort if change introduces inconsistencies.
|
||||
checkConsistency(before, task);
|
||||
|
|
|
@ -134,7 +134,7 @@ int CmdUDAs::execute (std::string& output)
|
|||
std::map <std::string, int> orphans;
|
||||
for (auto& i : filtered)
|
||||
{
|
||||
for (auto& att : i.data)
|
||||
for (auto& att : i.data_removeme ())
|
||||
if (! Task::isAnnotationAttr (att.first) &&
|
||||
! Task::isTagAttr (att.first) &&
|
||||
! Task::isDepAttr (att.first) &&
|
||||
|
|
|
@ -189,7 +189,7 @@ static void colorizeKeyword (Task& task, const std::string& rule, const Color& b
|
|||
// first match.
|
||||
else
|
||||
{
|
||||
for (const auto& att : task.data)
|
||||
for (const auto& att : task.data_removeme ())
|
||||
{
|
||||
if (! att.first.compare (0, 11, "annotation_", 11) &&
|
||||
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");
|
||||
|
||||
// Task::set
|
||||
task.data.clear ();
|
||||
task = Task();
|
||||
task.set ("name", "value");
|
||||
test.is (task.composeF4 (), "[name:\"value\"]", "Task::set");
|
||||
|
||||
|
@ -211,7 +211,7 @@ TODO Task::decode
|
|||
test.is (task.composeF4 (), "[name:\"value\"]", "Task::remove");
|
||||
|
||||
// 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);
|
||||
|
||||
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 ("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");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue