Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qqmladaptormodel.cpp
Go to the documentation of this file.
1// Copyright (C) 2018 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
5
6#include <private/qqmldmabstractitemmodeldata_p.h>
7#include <private/qqmldmlistaccessordata_p.h>
8#include <private/qqmldmobjectdata_p.h>
9
11
15
17 : QQmlGuard<QObject>(QQmlAdaptorModel::objectDestroyedImpl, nullptr)
18 , accessors(&m_nullAccessors)
19{
20}
21
26
28{
29 accessors->cleanup(*this);
30
31 // Don't use variant anymore after this. list may transform it.
33
35
36 if (QObject *object = qvariant_cast<QObject *>(list.list())) {
37 if (QQmlData *ddata = QQmlData::get(object))
38 modelStrongReference = ddata->jsWrapper;
39 setObject(object);
40 if (qobject_cast<QAbstractItemModel *>(object))
42 else
45 auto object = static_cast<const QQmlListReference *>(list.list().constData())->object();
46 if (QQmlData *ddata = QQmlData::get(object))
47 modelStrongReference = ddata->jsWrapper;
48 setObject(object);
50 } else if (list.type() == QQmlListAccessor::ObjectList) {
51 setObject(nullptr);
53 } else if (list.type() != QQmlListAccessor::Invalid
54 && list.type() != QQmlListAccessor::Instance) { // Null QObject
55 setObject(nullptr);
57 } else {
58 setObject(nullptr);
59 accessors = &m_nullAccessors;
60 }
61}
62
64{
65 accessors->cleanup(*this);
66 accessors = &m_nullAccessors;
67 // Don't clear the model object as we still need the guard to clear the list variant if the
68 // object is destroyed.
69}
70
72{
73 return accessors != &m_nullAccessors;
74}
75
77{
78 return rowCount() * columnCount();
79}
80
82{
83 return qMax(0, accessors->rowCount(*this));
84}
85
87{
88 return qMax(0, accessors->columnCount(*this));
89}
90
92{
93 int count = rowCount();
94 return count <= 0 ? -1 : index % count;
95}
96
98{
99 int count = rowCount();
100 return count <= 0 ? -1 : index / count;
101}
102
104{
105 return column * rowCount() + row;
106}
107
112
113void QQmlAdaptorModel::objectDestroyedImpl(QQmlGuardImpl *guard)
114{
115 auto This = static_cast<QQmlAdaptorModel *>(guard);
116 This->setModel(QVariant());
117}
118
\inmodule QtCore
Definition qobject.h:103
virtual int rowCount(const QQmlAdaptorModel &) const
virtual int columnCount(const QQmlAdaptorModel &) const
virtual void cleanup(QQmlAdaptorModel &) const
int rowAt(int index) const
QV4::PersistentValue modelStrongReference
QTypeRevision modelItemRevision
int columnAt(int index) const
void useImportVersion(QTypeRevision revision)
int indexAt(int row, int column) const
void setModel(const QVariant &variant)
QQmlListAccessor list
static QQmlData * get(QObjectPrivate *priv, bool create)
Definition qqmldata_p.h:199
void setObject(QObject *g)
Definition qqmlguard_p.h:62
void setList(const QVariant &)
QVariant list() const
The QQmlListReference class allows the manipulation of QQmlListProperty properties.
Definition qqmllist.h:183
\inmodule QtCore
\inmodule QtCore
Definition qvariant.h:65
const void * constData() const
Definition qvariant.h:451
Combined button and popup list for selecting options.
constexpr const T & qMax(const T &a, const T &b)
Definition qminmax.h:42
GLuint index
[2]
GLenum GLenum GLsizei count
GLenum GLenum GLsizei void GLsizei void * column
GLenum GLenum GLsizei void * row
QObject::connect nullptr
QVariant variant
[1]