diff --git a/GUI/coregui/Models/ModelMapper.cpp b/GUI/coregui/Models/ModelMapper.cpp index d648e95120ddf79ac35625f3ad3ff32ce72d6158..c2d7a253a6b12f2c416f0cd6af5484a1bc7253bf 100644 --- a/GUI/coregui/Models/ModelMapper.cpp +++ b/GUI/coregui/Models/ModelMapper.cpp @@ -16,7 +16,11 @@ #include "SessionModel.h" -ModelMapper::ModelMapper(QObject* parent) : QObject(parent), m_active{true}, m_model(0), m_item(0) +ModelMapper::ModelMapper(QObject* parent) + : QObject(parent) + , m_active(true) + , m_model(nullptr) + , m_item(nullptr) { } @@ -38,6 +42,8 @@ void ModelMapper::setOnPropertyChange(std::function<void(QString)> f, const void m_onPropertyChange.push_back(call_str_t(f, caller)); } +//! Calls back on child property change, report childItem and property name. + void ModelMapper::setOnChildPropertyChange(std::function<void(SessionItem*, QString)> f, const void* caller) { @@ -54,6 +60,9 @@ void ModelMapper::setOnParentChange(std::function<void(SessionItem*)> f, const v m_onParentChange.push_back(call_item_t(f, caller)); } +//! Calls back when number of children has changed, reports newChild. +//! newChild == nullptr denotes the case when number of children has decreased. + void ModelMapper::setOnChildrenChange(std::function<void(SessionItem*)> f, const void* caller) { m_onChildrenChange.push_back(call_item_t(f, caller)); @@ -64,6 +73,10 @@ void ModelMapper::setOnSiblingsChange(std::function<void()> f, const void* calle m_onSiblingsChange.push_back(call_t(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.push_back(call_item_t(f, caller)); @@ -96,27 +109,21 @@ void ModelMapper::unsubscribe(const void* caller) void ModelMapper::setModel(SessionModel* model) { if (m_model) { - disconnect(m_model, SIGNAL(dataChanged(QModelIndex, QModelIndex, QVector<int>)), this, - SLOT(onDataChanged(QModelIndex, QModelIndex, QVector<int>))); - disconnect(m_model, SIGNAL(rowsInserted(QModelIndex, int, int)), this, - SLOT(onRowsInserted(QModelIndex, int, int))); - disconnect(m_model, SIGNAL(rowsAboutToBeRemoved(QModelIndex, int, int)), this, - SLOT(onBeginRemoveRows(QModelIndex, int, int))); - disconnect(m_model, SIGNAL(rowsRemoved(QModelIndex, int, int)), this, - SLOT(onRowRemoved(QModelIndex, int, int))); + disconnect(m_model, &SessionModel::dataChanged, this, &ModelMapper::onDataChanged); + disconnect(m_model, &SessionModel::rowsInserted, this, &ModelMapper::onRowsInserted); + disconnect(m_model, &SessionModel::rowsAboutToBeRemoved, + this, &ModelMapper::onBeginRemoveRows); + disconnect(m_model, &SessionModel::rowsRemoved, this, &ModelMapper::onRowRemoved); } m_model = model; if (m_model) { - connect(m_model, SIGNAL(dataChanged(QModelIndex, QModelIndex, QVector<int>)), this, - SLOT(onDataChanged(QModelIndex, QModelIndex, QVector<int>))); - connect(m_model, SIGNAL(rowsInserted(QModelIndex, int, int)), this, - SLOT(onRowsInserted(QModelIndex, int, int))); - connect(m_model, SIGNAL(rowsAboutToBeRemoved(QModelIndex, int, int)), this, - SLOT(onBeginRemoveRows(QModelIndex, int, int))); - connect(m_model, SIGNAL(rowsRemoved(QModelIndex, int, int)), this, - SLOT(onRowRemoved(QModelIndex, int, int))); + connect(m_model, &SessionModel::dataChanged, this, &ModelMapper::onDataChanged); + connect(m_model, &SessionModel::rowsInserted, this, &ModelMapper::onRowsInserted); + connect(m_model, &SessionModel::rowsAboutToBeRemoved, + this, &ModelMapper::onBeginRemoveRows); + connect(m_model, &SessionModel::rowsRemoved, this, &ModelMapper::onRowRemoved); } } @@ -197,8 +204,8 @@ void ModelMapper::callOnItemDestroy() void ModelMapper::clearMapper() { - m_item = 0; - setModel(0); + m_item = nullptr; + setModel(nullptr); m_onValueChange.clear(); m_onPropertyChange.clear(); m_onChildPropertyChange.clear();