3#include <QtCore/QMetaMethod>
4#include <QtQml/QQmlEngine>
12constexpr const char* kDirtyChangedSignature =
"dirtyChanged(bool)";
13constexpr const char* kChildDirtyChangedSlotSignature =
"_childDirtyChanged(bool)";
15QMetaMethod childDirtyChangedSlot()
18 const int slotIndex = metaObject->indexOfSlot(kChildDirtyChangedSlotSignature);
19 Q_ASSERT_X(slotIndex >= 0,
"childDirtyChangedSlot",
"slot signature mismatch — update kChildDirtyChangedSlotSignature");
20 return (slotIndex >= 0) ? metaObject->method(slotIndex) : QMetaMethod();
23QMetaMethod dirtyChangedSignal(
const QObject*
object)
29 const int signalIndex =
object->metaObject()->indexOfSignal(kDirtyChangedSignature);
30 return (signalIndex >= 0) ?
object->metaObject()->method(signalIndex) : QMetaMethod();
35 const QMetaMethod signal = dirtyChangedSignal(
object);
36 const QMetaMethod slot = childDirtyChangedSlot();
37 if (signal.isValid() && slot.isValid()) {
38 QObject::connect(
object, signal, receiver, slot);
44 const QMetaMethod signal = dirtyChangedSignal(
object);
45 const QMetaMethod slot = childDirtyChangedSlot();
46 if (signal.isValid() && slot.isValid()) {
47 QObject::disconnect(
object, signal, receiver, slot);
65 return _objectList[
index];
72 return _objectList.count();
77 if (!
index.isValid()) {
81 if (
index.row() < 0 ||
index.row() >= _objectList.count()) {
86 return QVariant::fromValue(_objectList[
index.row()]);
88 return QVariant::fromValue(_objectList[
index.row()]->objectName());
97 _objectList.replace(
index.row(),
value.value<QObject*>());
127 }
else if (position +
rows > _objectList.count()) {
132 for (
int row=0; row<
rows; row++) {
133 _objectList.removeAt(position);
153 _objectList.move(
from,
to);
163 return _objectList[
index];
171 return _objectList[
index];
200 QQmlEngine::setObjectOwnership(
object, QQmlEngine::CppOwnership);
205 _objectList.insert(
i,
object);
217 for (QObject*
object:
objects) {
218 QQmlEngine::setObjectOwnership(
object, QQmlEngine::CppOwnership);
224 _objectList.insert(
j,
object);
235 insert(_objectList.count(),
object);
263 for(QObject*
object: _objectList) {
264 if (object->property(
"dirty").isValid()) {
265 object->setProperty(
"dirty",
false);
275 for (
int i=0;
i<_objectList.count();
i++) {
276 _objectList[
i]->deleteLater();
#define QGC_LOGGING_CATEGORY(name, categoryStr)
void endResetModel()
Depth-counted endResetModel — only the outermost call has effect.
void beginResetModel()
Depth-counted beginResetModel — only the outermost call has effect.
void _signalCountChangedIfNotNested()
static constexpr int ObjectRole
static constexpr int TextRole
void dirtyChanged(bool dirty)
QModelIndex index(int row, int column=0, const QModelIndex &parent=QModelIndex()) const override
QModelIndex parent(const QModelIndex &child) const override
void append(QObject *object)
Caller maintains responsibility for object ownership and deletion.
bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole) override
void move(int from, int to)
void setDirty(bool dirty) override final
bool removeRows(int position, int rows, const QModelIndex &index=QModelIndex()) override
QObject * removeAt(int index)
int rowCount(const QModelIndex &parent=QModelIndex()) const override
QObject * operator[](int index)
int count() const override final
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
void clear() override final
bool insertRows(int position, int rows, const QModelIndex &index=QModelIndex()) override
void clearAndDeleteContents() override final
Clears the list and calls deleteLater on each entry.
QObjectList swapObjectList(const QObjectList &newlist)
void insert(int index, QObject *object)
QmlObjectListModel(QObject *parent=nullptr)