mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-07-07 20:06:36 +02:00
Variant: Implemented custom UDA sorting
This commit is contained in:
parent
743cb92958
commit
29a09707f3
3 changed files with 70 additions and 43 deletions
|
@ -650,7 +650,9 @@ void Context::staticInitialization ()
|
|||
std::string name = rc->first.substr (4, rc->first.length () - 7 - 4);
|
||||
std::vector <std::string> values;
|
||||
split (values, rc->second, ',');
|
||||
Task::customOrder[name] = values;
|
||||
|
||||
for (auto r = values.rbegin(); r != values.rend (); ++r)
|
||||
Task::customOrder[name].push_back (*r);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
|
||||
#include <cmake.h>
|
||||
#include <sstream>
|
||||
#include <algorithm>
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
#include <stdlib.h>
|
||||
|
@ -314,12 +315,17 @@ bool Variant::operator< (const Variant& other) const
|
|||
return left._string < right._string;
|
||||
|
||||
case type_string:
|
||||
if (left.source () == "priority" || right.source () == "priority")
|
||||
{
|
||||
if (left._string != "H" && right._string == "H") return true;
|
||||
else if (left._string == "L" && right._string == "M") return true;
|
||||
else if (left._string == "" && right._string != "") return true;
|
||||
else return false;
|
||||
if (left._string == right._string)
|
||||
return false;
|
||||
|
||||
auto order = Task::customOrder.find (left.source ());
|
||||
if (order != Task::customOrder.end ())
|
||||
{
|
||||
// Guaranteed to be found, because of ColUDA::validate ().
|
||||
auto posLeft = std::find (order->second.begin (), order->second.end (), left._string);
|
||||
auto posRight = std::find (order->second.begin (), order->second.end (), right._string);
|
||||
return posLeft < posRight;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -328,6 +334,7 @@ bool Variant::operator< (const Variant& other) const
|
|||
|
||||
return left._string < right._string;
|
||||
}
|
||||
}
|
||||
|
||||
case type_date:
|
||||
if (left.trivial () || right.trivial ())
|
||||
|
@ -459,13 +466,17 @@ bool Variant::operator<= (const Variant& other) const
|
|||
return left._string <= right._string;
|
||||
|
||||
case type_string:
|
||||
if (left.source () == "priority" || right.source () == "priority")
|
||||
{
|
||||
if (left._string == right._string ) return true;
|
||||
else if ( right._string == "H") return true;
|
||||
else if (left._string == "L" && right._string == "M") return true;
|
||||
else if (left._string == "" ) return true;
|
||||
else return false;
|
||||
if (left._string == right._string)
|
||||
return false;
|
||||
|
||||
auto order = Task::customOrder.find (left.source ());
|
||||
if (order != Task::customOrder.end ())
|
||||
{
|
||||
// Guaranteed to be found, because of ColUDA::validate ().
|
||||
auto posLeft = std::find (order->second.begin (), order->second.end (), left._string);
|
||||
auto posRight = std::find (order->second.begin (), order->second.end (), right._string);
|
||||
return posLeft <= posRight;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -474,6 +485,7 @@ bool Variant::operator<= (const Variant& other) const
|
|||
|
||||
return left._string <= right._string;
|
||||
}
|
||||
}
|
||||
|
||||
case type_date:
|
||||
if (left.trivial () || right.trivial ())
|
||||
|
@ -605,20 +617,27 @@ bool Variant::operator> (const Variant& other) const
|
|||
return left._string > right._string;
|
||||
|
||||
case type_string:
|
||||
if (left.source () == "priority" || right.source () == "priority")
|
||||
{
|
||||
if (left._string == "H" && right._string != "H") return true;
|
||||
else if (left._string == "M" && right._string == "L") return true;
|
||||
else if (left._string != "" && right._string == "") return true;
|
||||
else return false;
|
||||
if (left._string == right._string)
|
||||
return false;
|
||||
|
||||
auto order = Task::customOrder.find (left.source ());
|
||||
if (order != Task::customOrder.end ())
|
||||
{
|
||||
// Guaranteed to be found, because of ColUDA::validate ().
|
||||
auto posLeft = std::find (order->second.begin (), order->second.end (), left._string);
|
||||
auto posRight = std::find (order->second.begin (), order->second.end (), right._string);
|
||||
return posLeft > posRight;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (left.trivial () || right.trivial ())
|
||||
return false;
|
||||
|
||||
return left._string> right._string;
|
||||
return left._string > right._string;
|
||||
}
|
||||
}
|
||||
|
||||
case type_date:
|
||||
if (left.trivial () || right.trivial ())
|
||||
return false;
|
||||
|
@ -749,13 +768,17 @@ bool Variant::operator>= (const Variant& other) const
|
|||
return left._string >= right._string;
|
||||
|
||||
case type_string:
|
||||
if (left.source () == "priority" || right.source () == "priority")
|
||||
{
|
||||
if (left._string == right._string ) return true;
|
||||
else if (left._string == "H" ) return true;
|
||||
else if (left._string == "M" && right._string == "L") return true;
|
||||
else if ( right._string == "" ) return true;
|
||||
else return false;
|
||||
if (left._string == right._string)
|
||||
return false;
|
||||
|
||||
auto order = Task::customOrder.find (left.source ());
|
||||
if (order != Task::customOrder.end ())
|
||||
{
|
||||
// Guaranteed to be found, because of ColUDA::validate ().
|
||||
auto posLeft = std::find (order->second.begin (), order->second.end (), left._string);
|
||||
auto posRight = std::find (order->second.begin (), order->second.end (), right._string);
|
||||
return posLeft >= posRight;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -764,6 +787,7 @@ bool Variant::operator>= (const Variant& other) const
|
|||
|
||||
return left._string >= right._string;
|
||||
}
|
||||
}
|
||||
|
||||
case type_date:
|
||||
if (left.trivial () || right.trivial ())
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
#ifndef INCLUDED_VARIANT
|
||||
#define INCLUDED_VARIANT
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <time.h>
|
||||
#include <Task.h>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue