diff --git a/src/maps.h b/src/maps.h --- a/src/maps.h +++ b/src/maps.h @@ -57,6 +57,7 @@ signals: void added(int index); + void aboutToBeRemoved(int index); void removed(int index); }; @@ -151,6 +152,7 @@ m_pendingRemovals.insert(index); } else { const int modelIndex = m_data.keys().indexOf(index); + emit aboutToBeRemoved(modelIndex); delete m_data.take(index); emit removed(modelIndex); } diff --git a/src/pulseaudio.cpp b/src/pulseaudio.cpp --- a/src/pulseaudio.cpp +++ b/src/pulseaudio.cpp @@ -48,7 +48,14 @@ }); connect(m_map, &MapBaseQObject::added, this, &AbstractModel::onDataAdded); - connect(m_map, &MapBaseQObject::removed, this, &AbstractModel::onDataRemoved); + connect(m_map, &MapBaseQObject::aboutToBeRemoved, this, [this](int index) { + beginRemoveRows(QModelIndex(), index, index); + }); + connect(m_map, &MapBaseQObject::removed, this, [this](int index) { + Q_UNUSED(index); + endRemoveRows(); + }); + } QHash AbstractModel::roleNames() const @@ -184,12 +191,6 @@ endInsertRows(); } -void AbstractModel::onDataRemoved(int index) -{ - beginRemoveRows(QModelIndex(), index, index); - endRemoveRows(); -} - QMetaMethod AbstractModel::propertyChangedMetaMethod() const { auto mo = metaObject();