From 61f00a0442a9f4be3326238025f0ff19d18a8db6 Mon Sep 17 00:00:00 2001 From: outfoxxed Date: Sat, 17 May 2025 17:03:03 -0700 Subject: [PATCH] core/model: return ObjectModel values list directly --- src/core/model.cpp | 17 ----------------- src/core/model.hpp | 4 ++-- 2 files changed, 2 insertions(+), 19 deletions(-) diff --git a/src/core/model.cpp b/src/core/model.cpp index 2aba1846..165c6066 100644 --- a/src/core/model.cpp +++ b/src/core/model.cpp @@ -23,23 +23,6 @@ QHash UntypedObjectModel::roleNames() const { return {{Qt::UserRole, "modelData"}}; } -QQmlListProperty UntypedObjectModel::values() { - return QQmlListProperty( - this, - nullptr, - &UntypedObjectModel::valuesCount, - &UntypedObjectModel::valueAt - ); -} - -qsizetype UntypedObjectModel::valuesCount(QQmlListProperty* property) { - return static_cast(property->object)->valuesList.count(); // NOLINT -} - -QObject* UntypedObjectModel::valueAt(QQmlListProperty* property, qsizetype index) { - return static_cast(property->object)->valuesList.at(index); // NOLINT -} - void UntypedObjectModel::insertObject(QObject* object, qsizetype index) { auto iindex = index == -1 ? this->valuesList.length() : index; emit this->objectInsertedPre(object, iindex); diff --git a/src/core/model.hpp b/src/core/model.hpp index f9c258cf..6346c96b 100644 --- a/src/core/model.hpp +++ b/src/core/model.hpp @@ -42,7 +42,7 @@ class UntypedObjectModel: public QAbstractListModel { Q_OBJECT; /// The content of the object model, as a QML list. /// The values of this property will always be of the type of the model. - Q_PROPERTY(QQmlListProperty values READ values NOTIFY valuesChanged); + Q_PROPERTY(QList values READ values NOTIFY valuesChanged); QML_NAMED_ELEMENT(ObjectModel); QML_UNCREATABLE("ObjectModels cannot be created directly."); @@ -53,7 +53,7 @@ public: [[nodiscard]] QVariant data(const QModelIndex& index, qint32 role) const override; [[nodiscard]] QHash roleNames() const override; - [[nodiscard]] QQmlListProperty values(); + [[nodiscard]] QList values() const { return this->valuesList; }; void removeAt(qsizetype index); Q_INVOKABLE qsizetype indexOf(QObject* object);