From 5a84e734426fc73e6a4bef993244ea422782e68b Mon Sep 17 00:00:00 2001 From: outfoxxed Date: Thu, 23 May 2024 19:12:21 -0700 Subject: [PATCH] core/objectmodel: add signals for changes to the list --- src/core/model.cpp | 11 +++++++++-- src/core/model.hpp | 8 ++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/core/model.cpp b/src/core/model.cpp index 74c7c284..64f7d765 100644 --- a/src/core/model.cpp +++ b/src/core/model.cpp @@ -39,21 +39,28 @@ QObject* UntypedObjectModel::valueAt(QQmlListProperty* property, qsizet void UntypedObjectModel::insertObject(QObject* object, qsizetype index) { auto iindex = index == -1 ? this->valuesList.length() : index; - auto intIndex = static_cast(iindex); + emit this->objectInsertedPre(object, index); + auto intIndex = static_cast(iindex); this->beginInsertRows(QModelIndex(), intIndex, intIndex); this->valuesList.insert(iindex, object); this->endInsertRows(); + emit this->valuesChanged(); + emit this->objectInsertedPost(object, index); } void UntypedObjectModel::removeAt(qsizetype index) { - auto intIndex = static_cast(index); + auto* object = this->valuesList.at(index); + emit this->objectRemovedPre(object, index); + auto intIndex = static_cast(index); this->beginRemoveRows(QModelIndex(), intIndex, intIndex); this->valuesList.removeAt(index); this->endRemoveRows(); + emit this->valuesChanged(); + emit this->objectRemovedPost(object, index); } bool UntypedObjectModel::removeObject(const QObject* object) { diff --git a/src/core/model.hpp b/src/core/model.hpp index bcf5ab62..10465bba 100644 --- a/src/core/model.hpp +++ b/src/core/model.hpp @@ -57,6 +57,14 @@ public: signals: void valuesChanged(); + /// Sent immediately before an object is inserted into the list. + void objectInsertedPre(QObject* object, qsizetype index); + /// Sent immediately after an object is inserted into the list. + void objectInsertedPost(QObject* object, qsizetype index); + /// Sent immediately before an object is removed from the list. + void objectRemovedPre(QObject* object, qsizetype index); + /// Sent immediately after an object is removed from the list. + void objectRemovedPost(QObject* object, qsizetype index); protected: void insertObject(QObject* object, qsizetype index = -1);