1// Copyright (C) 2016 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
4#include "qqmlvme_p.h"
5
6#include <private/qmetaobjectbuilder_p.h>
7#include "qqmlengine.h"
8#include <private/qfinitestack_p.h>
9#include <QtQml/private/qqmlcomponent_p.h>
10
11#include <QStack>
12#include <QPointF>
13#include <QSizeF>
14#include <QRectF>
15#include <QtCore/qdebug.h>
16#include <QtCore/qvarlengtharray.h>
17#include <QtCore/qcoreapplication.h>
18#include <QtCore/qdatetime.h>
19#include <QtCore/qvarlengtharray.h>
20#include <QtQml/qjsvalue.h>
21
22QT_BEGIN_NAMESPACE
23
24bool QQmlVME::s_enableComponentComplete = true;
25
26void QQmlVME::enableComponentComplete()
27{
28 s_enableComponentComplete = true;
29}
30
31void QQmlVME::disableComponentComplete()
32{
33 s_enableComponentComplete = false;
34}
35
36bool QQmlVME::componentCompleteEnabled()
37{
38 return s_enableComponentComplete;
39}
40
41QQmlVMEGuard::QQmlVMEGuard()
42: m_objectCount(0), m_objects(nullptr), m_contextCount(0), m_contexts(nullptr)
43{
44}
45
46QQmlVMEGuard::~QQmlVMEGuard()
47{
48 clear();
49}
50
51void QQmlVMEGuard::guard(QQmlObjectCreator *creator)
52{
53 clear();
54
55 QFiniteStack<QQmlGuard<QObject> > &objects = creator->allCreatedObjects();
56 m_objectCount = objects.count();
57 m_objects = new QQmlGuard<QObject>[m_objectCount];
58 for (int ii = 0; ii < m_objectCount; ++ii)
59 m_objects[ii] = objects[ii];
60
61 m_contextCount = 1;
62 m_contexts = new QQmlGuardedContextData[m_contextCount];
63 m_contexts[0] = creator->parentContextData();
64}
65
66void QQmlVMEGuard::clear()
67{
68 delete [] m_objects;
69 delete [] m_contexts;
70
71 m_objectCount = 0;
72 m_objects = nullptr;
73 m_contextCount = 0;
74 m_contexts = nullptr;
75}
76
77bool QQmlVMEGuard::isOK() const
78{
79 for (int ii = 0; ii < m_objectCount; ++ii)
80 if (m_objects[ii].isNull())
81 return false;
82
83 for (int ii = 0; ii < m_contextCount; ++ii)
84 if (m_contexts[ii].isNull() || !m_contexts[ii]->engine())
85 return false;
86
87 return true;
88}
89
90QT_END_NAMESPACE
91

source code of qtdeclarative/src/qml/qml/qqmlvme.cpp