2022-08-19 15:59:36 +02:00
|
|
|
// Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0 WITH Qt-GPL-exception-1.0
|
2016-01-15 14:59:14 +01:00
|
|
|
|
2012-09-19 15:57:22 +02:00
|
|
|
#include "componentnodeinstance.h"
|
|
|
|
|
|
|
|
|
|
#include <QQmlComponent>
|
|
|
|
|
#include <QQmlContext>
|
|
|
|
|
|
|
|
|
|
#include <QDebug>
|
|
|
|
|
|
|
|
|
|
namespace QmlDesigner {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
|
|
|
|
ComponentNodeInstance::ComponentNodeInstance(QQmlComponent *component)
|
|
|
|
|
: ObjectNodeInstance(component)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QQmlComponent *ComponentNodeInstance::component() const
|
|
|
|
|
{
|
|
|
|
|
Q_ASSERT(qobject_cast<QQmlComponent*>(object()));
|
|
|
|
|
return static_cast<QQmlComponent*>(object());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ComponentNodeInstance::Pointer ComponentNodeInstance::create(QObject *object)
|
|
|
|
|
{
|
|
|
|
|
QQmlComponent *component = qobject_cast<QQmlComponent *>(object);
|
|
|
|
|
|
|
|
|
|
Q_ASSERT(component);
|
|
|
|
|
|
|
|
|
|
Pointer instance(new ComponentNodeInstance(component));
|
|
|
|
|
|
|
|
|
|
instance->populateResetHashes();
|
|
|
|
|
|
|
|
|
|
return instance;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool ComponentNodeInstance::hasContent() const
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ComponentNodeInstance::setNodeSource(const QString &source)
|
|
|
|
|
{
|
2014-09-25 12:57:57 +02:00
|
|
|
QByteArray data(source.toUtf8() + "\n");
|
|
|
|
|
data.prepend(nodeInstanceServer()->importCode());
|
2012-09-19 15:57:22 +02:00
|
|
|
|
|
|
|
|
component()->setData(data, QUrl(nodeInstanceServer()->fileUrl().toString() +
|
|
|
|
|
QLatin1Char('_')+ id()));
|
|
|
|
|
setId(id());
|
|
|
|
|
|
|
|
|
|
if (component()->isError()) {
|
2019-07-25 16:58:50 +02:00
|
|
|
const QList<QQmlError> errors = component()->errors();
|
|
|
|
|
for (const QQmlError &error : errors)
|
2014-10-09 13:35:12 +02:00
|
|
|
qWarning() << error;
|
2012-09-19 15:57:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // Internal
|
|
|
|
|
} // QmlDesigner
|