From 1c53d41ae951e2d035353adc71f1f2c8232ab770 Mon Sep 17 00:00:00 2001
From: Matthias Puchner <github@mpuchner.de>
Date: Mon, 7 Feb 2022 15:33:37 +0100
Subject: [PATCH] rm obsolete code

---
 GUI/Model/BaseItem/ModelMapper.cpp   | 65 +++-------------------------
 GUI/Model/BaseItem/ModelMapper.h     |  8 ----
 Tests/Unit/GUI/TestMapperForItem.cpp | 12 -----
 3 files changed, 5 insertions(+), 80 deletions(-)

diff --git a/GUI/Model/BaseItem/ModelMapper.cpp b/GUI/Model/BaseItem/ModelMapper.cpp
index 2057ef9430f..19351c85578 100644
--- a/GUI/Model/BaseItem/ModelMapper.cpp
+++ b/GUI/Model/BaseItem/ModelMapper.cpp
@@ -56,16 +56,6 @@ void ModelMapper::setOnChildPropertyChange(std::function<void(SessionItem*, QStr
     m_onChildPropertyChange.emplace_back(f, caller);
 }
 
-//! Calls back when parent has changed, reports newParent.
-//! If newParent=0, the item is about being to be removed from children. Method parent()
-//! will still report old parent.
-//! If newParent!=0, it is just the same as parent().
-
-void ModelMapper::setOnParentChange(std::function<void(SessionItem*)> f, const void* caller)
-{
-    m_onParentChange.emplace_back(f, caller);
-}
-
 //! Calls back when number of children has changed, reports newChild.
 //! newChild == nullptr denotes the case when number of children has decreased.
 
@@ -74,15 +64,6 @@ void ModelMapper::setOnChildrenChange(std::function<void(SessionItem*)> f, const
     m_onChildrenChange.emplace_back(f, caller);
 }
 
-//! Calls back on any change in children (number of children or their properties),
-//! reports childItem.
-//! childItem == nullptr denotes the case when child was removed.
-
-void ModelMapper::setOnAnyChildChange(std::function<void(SessionItem*)> f, const void* caller)
-{
-    m_onAnyChildChange.emplace_back(f, caller);
-}
-
 void ModelMapper::setOnItemDestroy(std::function<void(SessionItem*)> f, const void* caller)
 {
     m_onItemDestroy.emplace_back(f, caller);
@@ -93,15 +74,13 @@ void ModelMapper::setOnAboutToRemoveChild(std::function<void(SessionItem*)> f, c
     m_onAboutToRemoveChild.emplace_back(f, caller);
 }
 
-//! Cancells all subscribtion of given caller
+//! Cancels all subscriptions of given caller
 void ModelMapper::unsubscribe(const void* caller)
 {
     clean_container(m_onValueChange, caller);
     clean_container(m_onPropertyChange, caller);
     clean_container(m_onChildPropertyChange, caller);
-    clean_container(m_onParentChange, caller);
     clean_container(m_onChildrenChange, caller);
-    clean_container(m_onAnyChildChange, caller);
     clean_container(m_onItemDestroy, caller);
     clean_container(m_onAboutToRemoveChild, caller);
 }
@@ -156,13 +135,6 @@ void ModelMapper::callOnChildPropertyChange(SessionItem* item, const QString& na
             f.first(item, name);
 }
 
-void ModelMapper::callOnParentChange(SessionItem* new_parent)
-{
-    if (m_active)
-        for (const auto& f : m_onParentChange)
-            f.first(new_parent);
-}
-
 void ModelMapper::callOnChildrenChange(SessionItem* item)
 {
     if (m_active)
@@ -170,13 +142,6 @@ void ModelMapper::callOnChildrenChange(SessionItem* item)
             f.first(item);
 }
 
-void ModelMapper::callOnAnyChildChange(SessionItem* item)
-{
-    if (m_active)
-        for (const auto& f : m_onAnyChildChange)
-            f.first(item);
-}
-
 void ModelMapper::callOnAboutToRemoveChild(SessionItem* item)
 {
     if (m_active)
@@ -199,9 +164,7 @@ void ModelMapper::clearMapper()
     m_onValueChange.clear();
     m_onPropertyChange.clear();
     m_onChildPropertyChange.clear();
-    m_onParentChange.clear();
     m_onChildrenChange.clear();
-    m_onAnyChildChange.clear();
     m_onItemDestroy.clear();
     m_onAboutToRemoveChild.clear();
 }
@@ -234,23 +197,14 @@ void ModelMapper::onDataChanged(const QModelIndex& topLeft, const QModelIndex& b
                 callOnChildPropertyChange(parent, tag);
         }
     }
-    if (nestling > 0)
-        callOnAnyChildChange(item);
 }
 
 void ModelMapper::onRowsInserted(const QModelIndex& parent, int first, int /*last*/)
 {
     SessionItem* newChild = m_model->itemForIndex(m_model->index(first, 0, parent));
 
-    int nestling = nestlingDepth(newChild);
-
-    if (newChild)
-        if (m_item == newChild)
-            callOnParentChange(m_model->itemForIndex(parent));
-    if (nestling == 1)
+    if (nestlingDepth(newChild) == 1)
         callOnChildrenChange(newChild);
-    if (nestling > 0)
-        callOnAnyChildChange(newChild);
 }
 
 void ModelMapper::onBeginRemoveRows(const QModelIndex& parent, int first, int /*last*/)
@@ -259,12 +213,8 @@ void ModelMapper::onBeginRemoveRows(const QModelIndex& parent, int first, int /*
 
     int nestling = nestlingDepth(m_model->itemForIndex(parent));
 
-    if (oldChild) {
-        if (m_item == oldChild)
-            callOnParentChange(nullptr);
-        if (nestling == 0)
-            callOnAboutToRemoveChild(oldChild);
-    }
+    if (oldChild && nestling == 0)
+        callOnAboutToRemoveChild(oldChild);
 
     if (m_item == oldChild)
         m_aboutToDelete = m_model->index(first, 0, parent);
@@ -272,12 +222,7 @@ void ModelMapper::onBeginRemoveRows(const QModelIndex& parent, int first, int /*
 
 void ModelMapper::onRowRemoved(const QModelIndex& parent, int first, int /*last*/)
 {
-    int nestling = nestlingDepth(m_model->itemForIndex(parent));
-
-    if (nestling >= 0 || m_model->itemForIndex(parent) == m_item->parent())
-        callOnAnyChildChange(nullptr);
-
-    if (nestling == 0)
+    if (nestlingDepth(m_model->itemForIndex(parent)) == 0)
         callOnChildrenChange(nullptr);
 
     if (m_aboutToDelete.isValid() && m_aboutToDelete == m_model->index(first, 0, parent))
diff --git a/GUI/Model/BaseItem/ModelMapper.h b/GUI/Model/BaseItem/ModelMapper.h
index 414931a5707..297996be75b 100644
--- a/GUI/Model/BaseItem/ModelMapper.h
+++ b/GUI/Model/BaseItem/ModelMapper.h
@@ -38,12 +38,8 @@ public:
     void setOnChildPropertyChange(std::function<void(SessionItem*, QString)> f,
                                   const void* caller = nullptr);
 
-    void setOnParentChange(std::function<void(SessionItem*)> f, const void* caller = nullptr);
-
     void setOnChildrenChange(std::function<void(SessionItem*)> f, const void* caller = nullptr);
 
-    void setOnAnyChildChange(std::function<void(SessionItem*)> f, const void* caller = nullptr);
-
     void setActive(bool state) { m_active = state; }
 
     void setOnItemDestroy(std::function<void(SessionItem*)> f, const void* caller = nullptr);
@@ -74,9 +70,7 @@ private:
     void callOnValueChange();
     void callOnPropertyChange(const QString& name);
     void callOnChildPropertyChange(SessionItem* item, const QString& name);
-    void callOnParentChange(SessionItem* new_parent);
     void callOnChildrenChange(SessionItem* item);
-    void callOnAnyChildChange(SessionItem* item);
     void callOnAboutToRemoveChild(SessionItem* item);
 
     void clearMapper();
@@ -93,9 +87,7 @@ private:
     std::vector<call_t> m_onValueChange;
     std::vector<call_item_str_t> m_onPropertyChange;
     std::vector<call_item_str_t> m_onChildPropertyChange;
-    std::vector<call_item_t> m_onParentChange;
     std::vector<call_item_t> m_onChildrenChange;
-    std::vector<call_item_t> m_onAnyChildChange;
     std::vector<call_item_t> m_onItemDestroy;
     std::vector<call_item_t> m_onAboutToRemoveChild;
     QModelIndex m_aboutToDelete;
diff --git a/Tests/Unit/GUI/TestMapperForItem.cpp b/Tests/Unit/GUI/TestMapperForItem.cpp
index 472fa8bc1f1..c6f76324345 100644
--- a/Tests/Unit/GUI/TestMapperForItem.cpp
+++ b/Tests/Unit/GUI/TestMapperForItem.cpp
@@ -11,7 +11,6 @@ public:
     Widget()
         : m_onPropertyChangeCount(0)
         , m_onChildPropertyChangeCount(0)
-        , m_onParentChangeCount(0)
         , m_onChildrenChangeCount(0)
         , m_onAboutToRemoveChild(0)
     {
@@ -21,7 +20,6 @@ public:
     {
         m_onPropertyChangeCount = 0;
         m_onChildPropertyChangeCount = 0;
-        m_onParentChangeCount = 0;
         m_onChildrenChangeCount = 0;
         m_onAboutToRemoveChild = 0;
         m_reported_items.clear();
@@ -39,8 +37,6 @@ public:
         mapper->setOnChildPropertyChange(
             [this](SessionItem* item, QString name) { onChildPropertyChange(item, name); }, caller);
 
-        mapper->setOnParentChange([this](SessionItem* parent) { onParentChange(parent); }, caller);
-
         mapper->setOnChildrenChange([this](SessionItem*) { onChildrenChange(); }, caller);
 
         mapper->setOnAboutToRemoveChild([this](SessionItem* item) { onAboutToRemoveChild(item); },
@@ -60,12 +56,6 @@ public:
         m_onChildPropertyChangeCount++;
     }
 
-    void onParentChange(SessionItem* item)
-    {
-        m_reported_items.append(item);
-        m_onParentChangeCount++;
-    }
-
     void onChildrenChange() { m_onChildrenChangeCount++; }
 
     void unsubscribe(ModelMapper* mapper) { mapper->unsubscribe(this); }
@@ -78,7 +68,6 @@ public:
 
     int m_onPropertyChangeCount;
     int m_onChildPropertyChangeCount;
-    int m_onParentChangeCount;
     int m_onChildrenChangeCount;
     int m_onAboutToRemoveChild;
     QList<SessionItem*> m_reported_items;
@@ -110,7 +99,6 @@ TEST_F(TestMapperForItem, initialCondition)
     Widget w;
     EXPECT_EQ(w.m_onPropertyChangeCount, 0);
     EXPECT_EQ(w.m_onChildPropertyChangeCount, 0);
-    EXPECT_EQ(w.m_onParentChangeCount, 0);
     EXPECT_EQ(w.m_onChildrenChangeCount, 0);
     EXPECT_TRUE(w.m_reported_items.isEmpty());
     EXPECT_TRUE(w.m_reported_names.isEmpty());
-- 
GitLab