2023-05-08 12:57:34 +00:00
|
|
|
// Copyright (C) 2023 The Qt Company Ltd.
|
2024-02-22 14:51:16 +00:00
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
|
2023-05-08 12:57:34 +00:00
|
|
|
|
|
|
|
#ifndef SEQUENCETOITERABLE_H
|
|
|
|
#define SEQUENCETOITERABLE_H
|
|
|
|
|
|
|
|
#include <QtCore/qobject.h>
|
|
|
|
#include <QtQml/qqml.h>
|
|
|
|
|
|
|
|
class Entry : public QObject {
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
explicit Entry(const QString &name, QObject *parent = nullptr)
|
|
|
|
: QObject(parent), m_name(name)
|
|
|
|
{
|
|
|
|
setObjectName(name);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
QString m_name;
|
|
|
|
};
|
|
|
|
|
|
|
|
class EntryWrapper {
|
|
|
|
Q_GADGET
|
|
|
|
QML_FOREIGN(Entry)
|
|
|
|
QML_NAMED_ELEMENT(Entry)
|
|
|
|
QML_UNCREATABLE("These are my Entry objects")
|
|
|
|
};
|
|
|
|
|
|
|
|
class EntryListRegistration
|
|
|
|
{
|
|
|
|
Q_GADGET
|
|
|
|
QML_FOREIGN(QList<Entry*>)
|
|
|
|
QML_ANONYMOUS
|
|
|
|
QML_SEQUENTIAL_CONTAINER(Entry*)
|
|
|
|
};
|
|
|
|
|
|
|
|
class EntrySource : public QObject {
|
|
|
|
Q_OBJECT
|
|
|
|
QML_ELEMENT
|
|
|
|
QML_SINGLETON
|
|
|
|
|
|
|
|
public:
|
|
|
|
explicit EntrySource(QObject* parent = nullptr) : QObject(parent) {
|
|
|
|
for (int i = 0; i < 10; i++) {
|
2024-10-09 07:41:43 +00:00
|
|
|
m_entries.push_back(new Entry(QStringLiteral("Item %1").arg(i), this));
|
2023-05-08 12:57:34 +00:00
|
|
|
}
|
|
|
|
}
|
2025-09-03 11:47:48 +00:00
|
|
|
Q_INVOKABLE QList<Entry *> getEntries() const { return m_entries; }
|
|
|
|
Q_INVOKABLE QList<Entry *> convertEntries(const QVariantList &entries) const
|
|
|
|
{
|
|
|
|
QList<Entry *> converted;
|
|
|
|
for (const QVariant &entry : entries)
|
|
|
|
converted.push_back(entry.value<Entry *>());
|
|
|
|
return converted;
|
|
|
|
}
|
2023-05-08 12:57:34 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
QList<Entry*> m_entries;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // SEQUENCETOITERABLE_H
|