Skip to content

Commit 34c0b4c

Browse files
committed
core/model: return ObjectModel values list directly
1 parent 32c5f46 commit 34c0b4c

File tree

2 files changed

+2
-19
lines changed

2 files changed

+2
-19
lines changed

src/core/model.cpp

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -23,23 +23,6 @@ QHash<int, QByteArray> UntypedObjectModel::roleNames() const {
2323
return {{Qt::UserRole, "modelData"}};
2424
}
2525

26-
QQmlListProperty<QObject> UntypedObjectModel::values() {
27-
return QQmlListProperty<QObject>(
28-
this,
29-
nullptr,
30-
&UntypedObjectModel::valuesCount,
31-
&UntypedObjectModel::valueAt
32-
);
33-
}
34-
35-
qsizetype UntypedObjectModel::valuesCount(QQmlListProperty<QObject>* property) {
36-
return static_cast<UntypedObjectModel*>(property->object)->valuesList.count(); // NOLINT
37-
}
38-
39-
QObject* UntypedObjectModel::valueAt(QQmlListProperty<QObject>* property, qsizetype index) {
40-
return static_cast<UntypedObjectModel*>(property->object)->valuesList.at(index); // NOLINT
41-
}
42-
4326
void UntypedObjectModel::insertObject(QObject* object, qsizetype index) {
4427
auto iindex = index == -1 ? this->valuesList.length() : index;
4528
emit this->objectInsertedPre(object, iindex);

src/core/model.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class UntypedObjectModel: public QAbstractListModel {
4242
Q_OBJECT;
4343
/// The content of the object model, as a QML list.
4444
/// The values of this property will always be of the type of the model.
45-
Q_PROPERTY(QQmlListProperty<QObject> values READ values NOTIFY valuesChanged);
45+
Q_PROPERTY(QList<QObject*> values READ values NOTIFY valuesChanged);
4646
QML_NAMED_ELEMENT(ObjectModel);
4747
QML_UNCREATABLE("ObjectModels cannot be created directly.");
4848

@@ -53,7 +53,7 @@ class UntypedObjectModel: public QAbstractListModel {
5353
[[nodiscard]] QVariant data(const QModelIndex& index, qint32 role) const override;
5454
[[nodiscard]] QHash<int, QByteArray> roleNames() const override;
5555

56-
[[nodiscard]] QQmlListProperty<QObject> values();
56+
[[nodiscard]] QList<QObject*> values() const { return this->valuesList; };
5757
void removeAt(qsizetype index);
5858

5959
Q_INVOKABLE qsizetype indexOf(QObject* object);

0 commit comments

Comments
 (0)