Skip to content
Snippets Groups Projects
Commit 1c53d41a authored by Matthias Puchner's avatar Matthias Puchner
Browse files

rm obsolete code

parent 05416287
No related branches found
No related tags found
1 merge request!649Cleanup and a few corrections
...@@ -56,16 +56,6 @@ void ModelMapper::setOnChildPropertyChange(std::function<void(SessionItem*, QStr ...@@ -56,16 +56,6 @@ void ModelMapper::setOnChildPropertyChange(std::function<void(SessionItem*, QStr
m_onChildPropertyChange.emplace_back(f, caller); 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. //! Calls back when number of children has changed, reports newChild.
//! newChild == nullptr denotes the case when number of children has decreased. //! newChild == nullptr denotes the case when number of children has decreased.
...@@ -74,15 +64,6 @@ void ModelMapper::setOnChildrenChange(std::function<void(SessionItem*)> f, const ...@@ -74,15 +64,6 @@ void ModelMapper::setOnChildrenChange(std::function<void(SessionItem*)> f, const
m_onChildrenChange.emplace_back(f, caller); 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) void ModelMapper::setOnItemDestroy(std::function<void(SessionItem*)> f, const void* caller)
{ {
m_onItemDestroy.emplace_back(f, caller); m_onItemDestroy.emplace_back(f, caller);
...@@ -93,15 +74,13 @@ void ModelMapper::setOnAboutToRemoveChild(std::function<void(SessionItem*)> f, c ...@@ -93,15 +74,13 @@ void ModelMapper::setOnAboutToRemoveChild(std::function<void(SessionItem*)> f, c
m_onAboutToRemoveChild.emplace_back(f, caller); m_onAboutToRemoveChild.emplace_back(f, caller);
} }
//! Cancells all subscribtion of given caller //! Cancels all subscriptions of given caller
void ModelMapper::unsubscribe(const void* caller) void ModelMapper::unsubscribe(const void* caller)
{ {
clean_container(m_onValueChange, caller); clean_container(m_onValueChange, caller);
clean_container(m_onPropertyChange, caller); clean_container(m_onPropertyChange, caller);
clean_container(m_onChildPropertyChange, caller); clean_container(m_onChildPropertyChange, caller);
clean_container(m_onParentChange, caller);
clean_container(m_onChildrenChange, caller); clean_container(m_onChildrenChange, caller);
clean_container(m_onAnyChildChange, caller);
clean_container(m_onItemDestroy, caller); clean_container(m_onItemDestroy, caller);
clean_container(m_onAboutToRemoveChild, caller); clean_container(m_onAboutToRemoveChild, caller);
} }
...@@ -156,13 +135,6 @@ void ModelMapper::callOnChildPropertyChange(SessionItem* item, const QString& na ...@@ -156,13 +135,6 @@ void ModelMapper::callOnChildPropertyChange(SessionItem* item, const QString& na
f.first(item, name); 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) void ModelMapper::callOnChildrenChange(SessionItem* item)
{ {
if (m_active) if (m_active)
...@@ -170,13 +142,6 @@ void ModelMapper::callOnChildrenChange(SessionItem* item) ...@@ -170,13 +142,6 @@ void ModelMapper::callOnChildrenChange(SessionItem* item)
f.first(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) void ModelMapper::callOnAboutToRemoveChild(SessionItem* item)
{ {
if (m_active) if (m_active)
...@@ -199,9 +164,7 @@ void ModelMapper::clearMapper() ...@@ -199,9 +164,7 @@ void ModelMapper::clearMapper()
m_onValueChange.clear(); m_onValueChange.clear();
m_onPropertyChange.clear(); m_onPropertyChange.clear();
m_onChildPropertyChange.clear(); m_onChildPropertyChange.clear();
m_onParentChange.clear();
m_onChildrenChange.clear(); m_onChildrenChange.clear();
m_onAnyChildChange.clear();
m_onItemDestroy.clear(); m_onItemDestroy.clear();
m_onAboutToRemoveChild.clear(); m_onAboutToRemoveChild.clear();
} }
...@@ -234,23 +197,14 @@ void ModelMapper::onDataChanged(const QModelIndex& topLeft, const QModelIndex& b ...@@ -234,23 +197,14 @@ void ModelMapper::onDataChanged(const QModelIndex& topLeft, const QModelIndex& b
callOnChildPropertyChange(parent, tag); callOnChildPropertyChange(parent, tag);
} }
} }
if (nestling > 0)
callOnAnyChildChange(item);
} }
void ModelMapper::onRowsInserted(const QModelIndex& parent, int first, int /*last*/) void ModelMapper::onRowsInserted(const QModelIndex& parent, int first, int /*last*/)
{ {
SessionItem* newChild = m_model->itemForIndex(m_model->index(first, 0, parent)); SessionItem* newChild = m_model->itemForIndex(m_model->index(first, 0, parent));
int nestling = nestlingDepth(newChild); if (nestlingDepth(newChild) == 1)
if (newChild)
if (m_item == newChild)
callOnParentChange(m_model->itemForIndex(parent));
if (nestling == 1)
callOnChildrenChange(newChild); callOnChildrenChange(newChild);
if (nestling > 0)
callOnAnyChildChange(newChild);
} }
void ModelMapper::onBeginRemoveRows(const QModelIndex& parent, int first, int /*last*/) void ModelMapper::onBeginRemoveRows(const QModelIndex& parent, int first, int /*last*/)
...@@ -259,12 +213,8 @@ void ModelMapper::onBeginRemoveRows(const QModelIndex& parent, int first, int /* ...@@ -259,12 +213,8 @@ void ModelMapper::onBeginRemoveRows(const QModelIndex& parent, int first, int /*
int nestling = nestlingDepth(m_model->itemForIndex(parent)); int nestling = nestlingDepth(m_model->itemForIndex(parent));
if (oldChild) { if (oldChild && nestling == 0)
if (m_item == oldChild) callOnAboutToRemoveChild(oldChild);
callOnParentChange(nullptr);
if (nestling == 0)
callOnAboutToRemoveChild(oldChild);
}
if (m_item == oldChild) if (m_item == oldChild)
m_aboutToDelete = m_model->index(first, 0, parent); m_aboutToDelete = m_model->index(first, 0, parent);
...@@ -272,12 +222,7 @@ void ModelMapper::onBeginRemoveRows(const QModelIndex& parent, int first, int /* ...@@ -272,12 +222,7 @@ void ModelMapper::onBeginRemoveRows(const QModelIndex& parent, int first, int /*
void ModelMapper::onRowRemoved(const QModelIndex& parent, int first, int /*last*/) void ModelMapper::onRowRemoved(const QModelIndex& parent, int first, int /*last*/)
{ {
int nestling = nestlingDepth(m_model->itemForIndex(parent)); if (nestlingDepth(m_model->itemForIndex(parent)) == 0)
if (nestling >= 0 || m_model->itemForIndex(parent) == m_item->parent())
callOnAnyChildChange(nullptr);
if (nestling == 0)
callOnChildrenChange(nullptr); callOnChildrenChange(nullptr);
if (m_aboutToDelete.isValid() && m_aboutToDelete == m_model->index(first, 0, parent)) if (m_aboutToDelete.isValid() && m_aboutToDelete == m_model->index(first, 0, parent))
......
...@@ -38,12 +38,8 @@ public: ...@@ -38,12 +38,8 @@ public:
void setOnChildPropertyChange(std::function<void(SessionItem*, QString)> f, void setOnChildPropertyChange(std::function<void(SessionItem*, QString)> f,
const void* caller = nullptr); 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 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 setActive(bool state) { m_active = state; }
void setOnItemDestroy(std::function<void(SessionItem*)> f, const void* caller = nullptr); void setOnItemDestroy(std::function<void(SessionItem*)> f, const void* caller = nullptr);
...@@ -74,9 +70,7 @@ private: ...@@ -74,9 +70,7 @@ private:
void callOnValueChange(); void callOnValueChange();
void callOnPropertyChange(const QString& name); void callOnPropertyChange(const QString& name);
void callOnChildPropertyChange(SessionItem* item, const QString& name); void callOnChildPropertyChange(SessionItem* item, const QString& name);
void callOnParentChange(SessionItem* new_parent);
void callOnChildrenChange(SessionItem* item); void callOnChildrenChange(SessionItem* item);
void callOnAnyChildChange(SessionItem* item);
void callOnAboutToRemoveChild(SessionItem* item); void callOnAboutToRemoveChild(SessionItem* item);
void clearMapper(); void clearMapper();
...@@ -93,9 +87,7 @@ private: ...@@ -93,9 +87,7 @@ private:
std::vector<call_t> m_onValueChange; std::vector<call_t> m_onValueChange;
std::vector<call_item_str_t> m_onPropertyChange; std::vector<call_item_str_t> m_onPropertyChange;
std::vector<call_item_str_t> m_onChildPropertyChange; 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_onChildrenChange;
std::vector<call_item_t> m_onAnyChildChange;
std::vector<call_item_t> m_onItemDestroy; std::vector<call_item_t> m_onItemDestroy;
std::vector<call_item_t> m_onAboutToRemoveChild; std::vector<call_item_t> m_onAboutToRemoveChild;
QModelIndex m_aboutToDelete; QModelIndex m_aboutToDelete;
......
...@@ -11,7 +11,6 @@ public: ...@@ -11,7 +11,6 @@ public:
Widget() Widget()
: m_onPropertyChangeCount(0) : m_onPropertyChangeCount(0)
, m_onChildPropertyChangeCount(0) , m_onChildPropertyChangeCount(0)
, m_onParentChangeCount(0)
, m_onChildrenChangeCount(0) , m_onChildrenChangeCount(0)
, m_onAboutToRemoveChild(0) , m_onAboutToRemoveChild(0)
{ {
...@@ -21,7 +20,6 @@ public: ...@@ -21,7 +20,6 @@ public:
{ {
m_onPropertyChangeCount = 0; m_onPropertyChangeCount = 0;
m_onChildPropertyChangeCount = 0; m_onChildPropertyChangeCount = 0;
m_onParentChangeCount = 0;
m_onChildrenChangeCount = 0; m_onChildrenChangeCount = 0;
m_onAboutToRemoveChild = 0; m_onAboutToRemoveChild = 0;
m_reported_items.clear(); m_reported_items.clear();
...@@ -39,8 +37,6 @@ public: ...@@ -39,8 +37,6 @@ public:
mapper->setOnChildPropertyChange( mapper->setOnChildPropertyChange(
[this](SessionItem* item, QString name) { onChildPropertyChange(item, name); }, caller); [this](SessionItem* item, QString name) { onChildPropertyChange(item, name); }, caller);
mapper->setOnParentChange([this](SessionItem* parent) { onParentChange(parent); }, caller);
mapper->setOnChildrenChange([this](SessionItem*) { onChildrenChange(); }, caller); mapper->setOnChildrenChange([this](SessionItem*) { onChildrenChange(); }, caller);
mapper->setOnAboutToRemoveChild([this](SessionItem* item) { onAboutToRemoveChild(item); }, mapper->setOnAboutToRemoveChild([this](SessionItem* item) { onAboutToRemoveChild(item); },
...@@ -60,12 +56,6 @@ public: ...@@ -60,12 +56,6 @@ public:
m_onChildPropertyChangeCount++; m_onChildPropertyChangeCount++;
} }
void onParentChange(SessionItem* item)
{
m_reported_items.append(item);
m_onParentChangeCount++;
}
void onChildrenChange() { m_onChildrenChangeCount++; } void onChildrenChange() { m_onChildrenChangeCount++; }
void unsubscribe(ModelMapper* mapper) { mapper->unsubscribe(this); } void unsubscribe(ModelMapper* mapper) { mapper->unsubscribe(this); }
...@@ -78,7 +68,6 @@ public: ...@@ -78,7 +68,6 @@ public:
int m_onPropertyChangeCount; int m_onPropertyChangeCount;
int m_onChildPropertyChangeCount; int m_onChildPropertyChangeCount;
int m_onParentChangeCount;
int m_onChildrenChangeCount; int m_onChildrenChangeCount;
int m_onAboutToRemoveChild; int m_onAboutToRemoveChild;
QList<SessionItem*> m_reported_items; QList<SessionItem*> m_reported_items;
...@@ -110,7 +99,6 @@ TEST_F(TestMapperForItem, initialCondition) ...@@ -110,7 +99,6 @@ TEST_F(TestMapperForItem, initialCondition)
Widget w; Widget w;
EXPECT_EQ(w.m_onPropertyChangeCount, 0); EXPECT_EQ(w.m_onPropertyChangeCount, 0);
EXPECT_EQ(w.m_onChildPropertyChangeCount, 0); EXPECT_EQ(w.m_onChildPropertyChangeCount, 0);
EXPECT_EQ(w.m_onParentChangeCount, 0);
EXPECT_EQ(w.m_onChildrenChangeCount, 0); EXPECT_EQ(w.m_onChildrenChangeCount, 0);
EXPECT_TRUE(w.m_reported_items.isEmpty()); EXPECT_TRUE(w.m_reported_items.isEmpty());
EXPECT_TRUE(w.m_reported_names.isEmpty()); EXPECT_TRUE(w.m_reported_names.isEmpty());
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment