From a3f86438ddfac9c5a8973e26a6acba26c85b1847 Mon Sep 17 00:00:00 2001
From: Stepan Salenikovich <stepan.salenikovich@savoirfairelinux.com>
Date: Fri, 16 Sep 2016 09:16:36 -0400
Subject: [PATCH] history: add method to clear the model and the backends

clearAllBackends() only deletes the file, but does not reset the
model; the new clear() method does both.

Change-Id: I39f37276b650b9511d08d8bd4f7c7b52a33a142a
Tuleap: #925
---
 src/categorizedhistorymodel.cpp | 18 ++++++++++++------
 src/categorizedhistorymodel.h   |  1 +
 2 files changed, 13 insertions(+), 6 deletions(-)

diff --git a/src/categorizedhistorymodel.cpp b/src/categorizedhistorymodel.cpp
index d3c784d3..88f9854e 100644
--- a/src/categorizedhistorymodel.cpp
+++ b/src/categorizedhistorymodel.cpp
@@ -564,12 +564,18 @@ void CategorizedHistoryModel::collectionAddedCallback(CollectionInterface* backe
 ///Call all collections that support clearing
 bool CategorizedHistoryModel::clearAllCollections() const
 {
-   foreach (CollectionInterface* backend, collections()) { //TODO use the filter API
-      if (backend->supportedFeatures() & CollectionInterface::SupportedFeatures::CLEAR) {
-         backend->clear();
-      }
-   }
-   return true;
+    foreach (CollectionInterface* backend, collections(CollectionInterface::SupportedFeatures::CLEAR)) {
+        backend->clear();
+    }
+    return true;
+}
+
+///Delete all history and clear model
+void CategorizedHistoryModel::clear()
+{
+    beginResetModel();
+    clearAllCollections();
+    endResetModel();
 }
 
 bool CategorizedHistoryModel::addItemCallback(const Call* item)
diff --git a/src/categorizedhistorymodel.h b/src/categorizedhistorymodel.h
index 238b3d3b..69fb32be 100644
--- a/src/categorizedhistorymodel.h
+++ b/src/categorizedhistorymodel.h
@@ -74,6 +74,7 @@ public:
    void setHistoryLimited(bool isLimited);
    void setHistoryLimit(int numberOfDays);
    void setHistoryEnabled(bool isEnabled);
+   void clear();
 
    //Model implementation
    virtual bool          setData     ( const QModelIndex& index, const QVariant &value, int role   ) override;
-- 
GitLab