mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-08-28 13:37:20 +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::string name = rc->first.substr (4, rc->first.length () - 7 - 4);
|
||||||
std::vector <std::string> values;
|
std::vector <std::string> values;
|
||||||
split (values, rc->second, ',');
|
split (values, rc->second, ',');
|
||||||
Task::customOrder[name] = values;
|
|
||||||
|
for (auto r = values.rbegin(); r != values.rend (); ++r)
|
||||||
|
Task::customOrder[name].push_back (*r);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
108
src/Variant.cpp
108
src/Variant.cpp
|
@ -26,6 +26,7 @@
|
||||||
|
|
||||||
#include <cmake.h>
|
#include <cmake.h>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
#include <algorithm>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
@ -314,19 +315,25 @@ bool Variant::operator< (const Variant& other) const
|
||||||
return left._string < right._string;
|
return left._string < right._string;
|
||||||
|
|
||||||
case type_string:
|
case type_string:
|
||||||
if (left.source () == "priority" || right.source () == "priority")
|
|
||||||
{
|
{
|
||||||
if (left._string != "H" && right._string == "H") return true;
|
if (left._string == right._string)
|
||||||
else if (left._string == "L" && right._string == "M") return true;
|
|
||||||
else if (left._string == "" && right._string != "") return true;
|
|
||||||
else return false;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (left.trivial () || right.trivial ())
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return left._string < right._string;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
case type_date:
|
case type_date:
|
||||||
|
@ -459,20 +466,25 @@ bool Variant::operator<= (const Variant& other) const
|
||||||
return left._string <= right._string;
|
return left._string <= right._string;
|
||||||
|
|
||||||
case type_string:
|
case type_string:
|
||||||
if (left.source () == "priority" || right.source () == "priority")
|
|
||||||
{
|
{
|
||||||
if (left._string == right._string ) return true;
|
if (left._string == right._string)
|
||||||
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;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (left.trivial () || right.trivial ())
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return left._string <= right._string;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
case type_date:
|
case type_date:
|
||||||
|
@ -605,20 +617,27 @@ bool Variant::operator> (const Variant& other) const
|
||||||
return left._string > right._string;
|
return left._string > right._string;
|
||||||
|
|
||||||
case type_string:
|
case type_string:
|
||||||
if (left.source () == "priority" || right.source () == "priority")
|
|
||||||
{
|
{
|
||||||
if (left._string == "H" && right._string != "H") return true;
|
if (left._string == right._string)
|
||||||
else if (left._string == "M" && right._string == "L") return true;
|
|
||||||
else if (left._string != "" && right._string == "") return true;
|
|
||||||
else return false;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (left.trivial () || right.trivial ())
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return left._string> right._string;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
case type_date:
|
case type_date:
|
||||||
if (left.trivial () || right.trivial ())
|
if (left.trivial () || right.trivial ())
|
||||||
return false;
|
return false;
|
||||||
|
@ -749,20 +768,25 @@ bool Variant::operator>= (const Variant& other) const
|
||||||
return left._string >= right._string;
|
return left._string >= right._string;
|
||||||
|
|
||||||
case type_string:
|
case type_string:
|
||||||
if (left.source () == "priority" || right.source () == "priority")
|
|
||||||
{
|
{
|
||||||
if (left._string == right._string ) return true;
|
if (left._string == right._string)
|
||||||
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;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (left.trivial () || right.trivial ())
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return left._string >= right._string;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
case type_date:
|
case type_date:
|
||||||
|
|
|
@ -27,6 +27,7 @@
|
||||||
#ifndef INCLUDED_VARIANT
|
#ifndef INCLUDED_VARIANT
|
||||||
#define INCLUDED_VARIANT
|
#define INCLUDED_VARIANT
|
||||||
|
|
||||||
|
#include <map>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <Task.h>
|
#include <Task.h>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue