1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the QtQml module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or (at your option) the GNU General
28** Public license version 3 or any later version approved by the KDE Free
29** Qt Foundation. The licenses are as published by the Free Software
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31** included in the packaging of this file. Please review the following
32** information to ensure the GNU General Public License requirements will
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34** https://www.gnu.org/licenses/gpl-3.0.html.
35**
36** $QT_END_LICENSE$
37**
38****************************************************************************/
39
40#include "qqmlvme_p.h"
41
42#include "qqmlboundsignal_p.h"
43#include "qqmlstringconverters_p.h"
44#include <private/qmetaobjectbuilder_p.h>
45#include "qqmldata_p.h"
46#include "qqml.h"
47#include "qqmlinfo.h"
48#include "qqmlcustomparser_p.h"
49#include "qqmlengine.h"
50#include "qqmlcontext.h"
51#include "qqmlcomponent.h"
52#include "qqmlcomponentattached_p.h"
53#include "qqmlbinding_p.h"
54#include "qqmlengine_p.h"
55#include "qqmlcomponent_p.h"
56#include "qqmlvmemetaobject_p.h"
57#include "qqmlcontext_p.h"
58#include "qqmlglobal_p.h"
59#include <private/qfinitestack_p.h>
60#include "qqmlscriptstring.h"
61#include "qqmlscriptstring_p.h"
62#include "qqmlpropertyvalueinterceptor_p.h"
63#include "qqmlvaluetypeproxybinding_p.h"
64#include "qqmlexpression_p.h"
65
66#include <QStack>
67#include <QPointF>
68#include <QSizeF>
69#include <QRectF>
70#include <QtCore/qdebug.h>
71#include <QtCore/qvarlengtharray.h>
72#include <QtCore/qcoreapplication.h>
73#include <QtCore/qdatetime.h>
74#include <QtCore/qvarlengtharray.h>
75#include <QtQml/qjsvalue.h>
76
77QT_BEGIN_NAMESPACE
78
79using namespace QQmlVMETypes;
80
81bool QQmlVME::s_enableComponentComplete = true;
82
83void QQmlVME::enableComponentComplete()
84{
85 s_enableComponentComplete = true;
86}
87
88void QQmlVME::disableComponentComplete()
89{
90 s_enableComponentComplete = false;
91}
92
93bool QQmlVME::componentCompleteEnabled()
94{
95 return s_enableComponentComplete;
96}
97
98QQmlVMEGuard::QQmlVMEGuard()
99: m_objectCount(0), m_objects(nullptr), m_contextCount(0), m_contexts(nullptr)
100{
101}
102
103QQmlVMEGuard::~QQmlVMEGuard()
104{
105 clear();
106}
107
108void QQmlVMEGuard::guard(QQmlObjectCreator *creator)
109{
110 clear();
111
112 QFiniteStack<QPointer<QObject> > &objects = creator->allCreatedObjects();
113 m_objectCount = objects.count();
114 m_objects = new QPointer<QObject>[m_objectCount];
115 for (int ii = 0; ii < m_objectCount; ++ii)
116 m_objects[ii] = objects[ii];
117
118 m_contextCount = 1;
119 m_contexts = new QQmlGuardedContextData[m_contextCount];
120 m_contexts[0] = creator->parentContextData();
121}
122
123void QQmlVMEGuard::clear()
124{
125 delete [] m_objects;
126 delete [] m_contexts;
127
128 m_objectCount = 0;
129 m_objects = nullptr;
130 m_contextCount = 0;
131 m_contexts = nullptr;
132}
133
134bool QQmlVMEGuard::isOK() const
135{
136 for (int ii = 0; ii < m_objectCount; ++ii)
137 if (m_objects[ii].isNull())
138 return false;
139
140 for (int ii = 0; ii < m_contextCount; ++ii)
141 if (m_contexts[ii].isNull() || !m_contexts[ii]->engine)
142 return false;
143
144 return true;
145}
146
147QT_END_NAMESPACE
148

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