mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-06-26 10:54:26 +02:00
UDA
- Implemented UDA sorting.
This commit is contained in:
parent
f42fa76e45
commit
2815fcb90d
1 changed files with 70 additions and 10 deletions
80
src/sort.cpp
80
src/sort.cpp
|
@ -84,8 +84,23 @@ static bool sort_compare (int left, int right)
|
|||
{
|
||||
context.decomposeSortField (*k, field, ascending);
|
||||
|
||||
// Urgency.
|
||||
if (field == "urgency")
|
||||
{
|
||||
left_real = (*global_data)[left].urgency ();
|
||||
right_real = (*global_data)[right].urgency ();
|
||||
|
||||
if (left_real == right_real)
|
||||
continue;
|
||||
|
||||
if (ascending)
|
||||
return left_real < right_real;
|
||||
|
||||
return left_real > right_real;
|
||||
}
|
||||
|
||||
// Number.
|
||||
if (field == "id")
|
||||
else if (field == "id")
|
||||
{
|
||||
left_number = (*global_data)[left].id;
|
||||
right_number = (*global_data)[right].id;
|
||||
|
@ -223,19 +238,64 @@ static bool sort_compare (int left, int right)
|
|||
return left_duration > right_duration;
|
||||
}
|
||||
|
||||
// Urgency.
|
||||
else if (field == "urgency")
|
||||
// UDAs.
|
||||
else
|
||||
{
|
||||
left_real = (*global_data)[left].urgency ();
|
||||
right_real = (*global_data)[right].urgency ();
|
||||
std::string type = context.columns[field]->type ();
|
||||
if (type == "numeric")
|
||||
{
|
||||
left_real = (*global_data)[left].urgency ();
|
||||
right_real = (*global_data)[right].urgency ();
|
||||
|
||||
if (left_real == right_real)
|
||||
continue;
|
||||
if (left_real == right_real)
|
||||
continue;
|
||||
|
||||
if (ascending)
|
||||
return left_real < right_real;
|
||||
if (ascending)
|
||||
return left_real < right_real;
|
||||
|
||||
return left_real > right_real;
|
||||
return left_real > right_real;
|
||||
}
|
||||
else if (type == "string")
|
||||
{
|
||||
const std::string& left_string = (*global_data)[left].get_ref (field);
|
||||
const std::string& right_string = (*global_data)[right].get_ref (field);
|
||||
|
||||
if (left_string == right_string)
|
||||
continue;
|
||||
|
||||
if (ascending)
|
||||
return left_string < right_string;
|
||||
|
||||
return left_string > right_string;
|
||||
}
|
||||
else if (type == "date")
|
||||
{
|
||||
const std::string& left_string = (*global_data)[left].get_ref (field);
|
||||
const std::string& right_string = (*global_data)[right].get_ref (field);
|
||||
|
||||
if (left_string == right_string)
|
||||
continue;
|
||||
|
||||
if (ascending)
|
||||
return left_string < right_string;
|
||||
|
||||
return left_string > right_string;
|
||||
}
|
||||
else if (type == "duration")
|
||||
{
|
||||
const std::string& left_string = (*global_data)[left].get_ref (field);
|
||||
const std::string& right_string = (*global_data)[right].get_ref (field);
|
||||
|
||||
if (left_string == right_string)
|
||||
continue;
|
||||
|
||||
Duration left_duration (left_string);
|
||||
Duration right_duration (right_string);
|
||||
if (ascending)
|
||||
return left_duration < right_duration;
|
||||
|
||||
return left_duration > right_duration;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue