summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Faure <[email protected]>2018-03-20 18:15:28 +0100
committerDavid Faure <[email protected]>2018-03-20 23:33:50 +0100
commita3a66bb10020e6fbdd354b4ecc6c0fee6741c467 (patch)
tree487d4bed8436d3849ea7eb9e693cd0336af64f82
parent9abf9eeb117800b4bcafb8a438c31f56360e34c1 (diff)
Fix crash when comparing nodes with depth of -1Applications/17.12
Summary: Enabling a calendar with todos crashed for me. Apparently because of missing parent todos. Reviewers: smartins Reviewed By: smartins Subscribers: #kde_pim Tags: #kde_pim Differential Revision: https://phabricator.kde.org/D11517
-rw-r--r--src/todo/incidencetreemodel.cpp12
1 files changed, 8 insertions, 4 deletions
diff --git a/src/todo/incidencetreemodel.cpp b/src/todo/incidencetreemodel.cpp
index c7ad57c..89ad5bf 100644
--- a/src/todo/incidencetreemodel.cpp
+++ b/src/todo/incidencetreemodel.cpp
@@ -38,13 +38,17 @@ static void calculateDepth(const Node::Ptr &node)
}
}
-bool lessThan(const Node::Ptr &node1, const Node::Ptr &node2)
+// Desired ordering [...],3,2,1,0,-1
+static bool reverseDepthLessThan(const Node::Ptr &node1, const Node::Ptr &node2)
{
return node1->depth > node2->depth;
}
-bool greaterThan(const PreNode::Ptr &node1, const PreNode::Ptr &node2)
+// Desired ordering 0,1,2,3,[...],-1
+static bool depthLessThan(const PreNode::Ptr &node1, const PreNode::Ptr &node2)
{
+ if (node1->depth == -1)
+ return false;
return node1->depth < node2->depth || node2->depth == -1;
}
@@ -81,7 +85,7 @@ static PreNode::List sortedPrenodes(const PreNode::List &nodes)
}
PreNode::List sorted = nodes;
- std::sort(sorted.begin(), sorted.end(), greaterThan);
+ std::sort(sorted.begin(), sorted.end(), depthLessThan);
return sorted;
}
@@ -446,7 +450,7 @@ Node::List IncidenceTreeModel::Private::sorted(const Node::List &nodes) const
}
Node::List sorted = nodes;
- std::sort(sorted.begin(), sorted.end(), lessThan);
+ std::sort(sorted.begin(), sorted.end(), reverseDepthLessThan);
return sorted;
}