File 0001-Fix-crash-when-comparing-nodes-with-depth-of-1.patch of Package eventviews

From a3a66bb10020e6fbdd354b4ecc6c0fee6741c467 Mon Sep 17 00:00:00 2001
From: David Faure <faure@kde.org>
Date: Tue, 20 Mar 2018 18:15:28 +0100
Subject: [PATCH] Fix crash when comparing nodes with depth of -1

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
---
 src/todo/incidencetreemodel.cpp | 12 ++++++++----
 1 file 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;
 }
-- 
2.13.6

openSUSE Build Service is sponsored by