Commit 08e4b339 authored by Thomas Hartmann's avatar Thomas Hartmann Committed by Marco Bubke

QmlDesigner.instances: allow fallback to item

If we know from the (text editor) meta system that an object is an
(visible) item, we always create an item as fallback.

We might not be able to instaciate the original item.

Change-Id: I6851cd7a8de68d9d09b789927c204f0617017de7
Reviewed-on: http://codereview.qt.nokia.com/829Reviewed-by: default avatarQt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: default avatarMarco Bubke <marco.bubke@nokia.com>
parent 5d87d4c4
......@@ -39,9 +39,9 @@ InstanceContainer::InstanceContainer()
{
}
InstanceContainer::InstanceContainer(qint32 instanceId, const QString &type, int majorNumber, int minorNumber, const QString &componentPath, const QString &nodeSource, NodeSourceType nodeSourceType)
InstanceContainer::InstanceContainer(qint32 instanceId, const QString &type, int majorNumber, int minorNumber, const QString &componentPath, const QString &nodeSource, NodeSourceType nodeSourceType,NodeMetaType metaType)
: m_instanceId(instanceId), m_type(type), m_majorNumber(majorNumber), m_minorNumber(minorNumber), m_componentPath(componentPath),
m_nodeSource(nodeSource), m_nodeSourceType(nodeSourceType)
m_nodeSource(nodeSource), m_nodeSourceType(nodeSourceType), m_metaType(metaType)
{
m_type.replace(QLatin1Char('.'), QLatin1Char('/'));
}
......@@ -81,6 +81,11 @@ InstanceContainer::NodeSourceType InstanceContainer::nodeSourceType() const
return static_cast<NodeSourceType>(m_nodeSourceType);
}
InstanceContainer::NodeMetaType InstanceContainer::metaType() const
{
return static_cast<NodeMetaType>(m_metaType);
}
QDataStream &operator<<(QDataStream &out, const InstanceContainer &container)
{
out << container.instanceId();
......@@ -90,6 +95,7 @@ QDataStream &operator<<(QDataStream &out, const InstanceContainer &container)
out << container.componentPath();
out << container.nodeSource();
out << container.nodeSourceType();
out << container.metaType();
return out;
}
......@@ -104,6 +110,7 @@ QDataStream &operator>>(QDataStream &in, InstanceContainer &container)
in >> container.m_componentPath;
in >> container.m_nodeSource;
in >> container.m_nodeSourceType;
in >> container.m_metaType;
return in;
}
......
......@@ -54,8 +54,13 @@ public:
ComponentSource = 2
};
enum NodeMetaType {
ObjectMetaType,
ItemMetaType
};
InstanceContainer();
InstanceContainer(qint32 instanceId, const QString &type, int majorNumber, int minorNumber, const QString &componentPath, const QString &nodeSource, NodeSourceType nodeSourceType);
InstanceContainer(qint32 instanceId, const QString &type, int majorNumber, int minorNumber, const QString &componentPath, const QString &nodeSource, NodeSourceType nodeSourceType, NodeMetaType metaType);
qint32 instanceId() const;
QString type() const;
......@@ -64,6 +69,7 @@ public:
QString componentPath() const;
QString nodeSource() const;
NodeSourceType nodeSourceType() const;
NodeMetaType metaType() const;
private:
qint32 m_instanceId;
......@@ -73,6 +79,7 @@ private:
QString m_componentPath;
QString m_nodeSource;
qint32 m_nodeSourceType;
qint32 m_metaType;
};
} // namespace QmlDesigner
......
......@@ -218,6 +218,13 @@ ServerNodeInstance ServerNodeInstance::create(NodeInstanceServer *nodeInstanceSe
object = Internal::ObjectNodeInstance::createPrimitive(instanceContainer.type(), instanceContainer.majorNumber(), instanceContainer.minorNumber(), nodeInstanceServer->context());
}
if ((object == 0) && (instanceContainer.metaType() == InstanceContainer::ItemMetaType)) //If we cannot instanciate the object but we know it has to be an Ttem, we create an Item instead.
#if QT_VERSION >= 0x050000
object = Internal::ObjectNodeInstance::createPrimitive("QSGItem", 2, 0, nodeInstanceServer->context())
#else
object = Internal::ObjectNodeInstance::createPrimitive("QDeclarativeItem", 2, 0, nodeInstanceServer->context());
#endif
ServerNodeInstance instance(createInstance(object));
instance.internalInstance()->setNodeInstanceServer(nodeInstanceServer);
......
......@@ -766,13 +766,19 @@ CreateSceneCommand NodeInstanceView::createCreateSceneCommand()
QVector<InstanceContainer> instanceContainerList;
foreach(const NodeInstance &instance, instanceList) {
InstanceContainer::NodeSourceType nodeSourceType = static_cast<InstanceContainer::NodeSourceType>(instance.modelNode().nodeSourceType());
InstanceContainer::NodeMetaType nodeMetaType = nodeMetaType = InstanceContainer::ObjectMetaType;
if (instance.modelNode().metaInfo().isSubclassOf("QtQuick.Item", -1, -1))
nodeMetaType = InstanceContainer::ItemMetaType;
InstanceContainer container(instance.instanceId(),
instance.modelNode().type(),
instance.modelNode().majorVersion(),
instance.modelNode().minorVersion(),
instance.modelNode().metaInfo().componentFileName(),
instance.modelNode().nodeSource(),
nodeSourceType
nodeSourceType,
nodeMetaType
);
instanceContainerList.append(container);
......@@ -862,8 +868,13 @@ CreateInstancesCommand NodeInstanceView::createCreateInstancesCommand(const QLis
QVector<InstanceContainer> containerList;
foreach(const NodeInstance &instance, instanceList) {
InstanceContainer::NodeSourceType nodeSourceType = static_cast<InstanceContainer::NodeSourceType>(instance.modelNode().nodeSourceType());
InstanceContainer::NodeMetaType nodeMetaType = nodeMetaType = InstanceContainer::ObjectMetaType;
if (instance.modelNode().metaInfo().isSubclassOf("QtQuick.Item", -1, -1))
nodeMetaType = InstanceContainer::ItemMetaType;
InstanceContainer container(instance.instanceId(), instance.modelNode().type(), instance.modelNode().majorVersion(), instance.modelNode().minorVersion(),
instance.modelNode().metaInfo().componentFileName(), instance.modelNode().nodeSource(), nodeSourceType);
instance.modelNode().metaInfo().componentFileName(), instance.modelNode().nodeSource(), nodeSourceType, nodeMetaType);
containerList.append(container);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment