Commit c3be93f2 authored by Marco Bubke's avatar Marco Bubke

QmlDesigner: Refactor QmlItemNode::createQmlItemNodeFromImage

Change-Id: I1fa0eb94d36ae48bb131da2ceca75e19a4175a4d
Reviewed-by: default avatarThomas Hartmann <Thomas.Hartmann@digia.com>
parent 1c3e9e01
......@@ -171,16 +171,8 @@ QmlItemNode QmlItemNode::createQmlItemNode(AbstractView *view, const ItemLibrary
return newQmlItemNode;
}
QmlItemNode QmlItemNode::createQmlItemNodeFromImage(AbstractView *view, const QString &imageName, const QPointF &position, QmlItemNode parentQmlItemNode)
static void checkImageImport(AbstractView *view)
{
if (!parentQmlItemNode.isValid() && QmlItemNode::isValidQmlItemNode(view->rootModelNode()))
parentQmlItemNode = QmlItemNode(view->rootModelNode());
else
return QmlItemNode();
QmlItemNode newQmlItemNode;
RewriterTransaction transaction = view->beginRewriterTransaction();
{
const QString newImportUrl = QLatin1String("QtQuick");
const QString newImportVersion = QLatin1String("1.1");
Import newImport = Import::createLibraryImport(newImportUrl, newImportVersion);
......@@ -196,7 +188,21 @@ QmlItemNode QmlItemNode::createQmlItemNodeFromImage(AbstractView *view, const QS
if (!view->model()->hasImport(newImport, true, true))
view->model()->changeImports(QList<Import>() << newImport, QList<Import>());
}
QmlItemNode QmlItemNode::createQmlItemNodeFromImage(AbstractView *view, const QString &imageName, const QPointF &position, QmlItemNode parentQmlItemNode)
{
QmlItemNode newQmlItemNode;
if (!parentQmlItemNode.isValid())
parentQmlItemNode = QmlItemNode(view->rootModelNode());
if (parentQmlItemNode.isValid()) {
RewriterTransaction transaction = view->beginRewriterTransaction();
checkImageImport(view);
if (view->model()->hasNodeMetaInfo("QtQuick.Image")) {
NodeMetaInfo metaInfo = view->model()->metaInfo("QtQuick.Image");
QList<QPair<PropertyName, QVariant> > propertyPairList;
propertyPairList.append(qMakePair(PropertyName("x"), QVariant(qRound(position.x()))));
propertyPairList.append(qMakePair(PropertyName("y"), QVariant(qRound(position.y()))));
......@@ -207,18 +213,11 @@ QmlItemNode QmlItemNode::createQmlItemNodeFromImage(AbstractView *view, const QS
if (QFileInfo(view->model()->fileUrl().toLocalFile()).exists()) {
QDir fileDir(QFileInfo(view->model()->fileUrl().toLocalFile()).absolutePath());
relativeImageName = fileDir.relativeFilePath(imageName);
}
propertyPairList.append(qMakePair(PropertyName("source"), QVariant(relativeImageName)));
NodeMetaInfo metaInfo = view->model()->metaInfo("QtQuick.Image");
if (metaInfo.isValid()) {
int minorVersion = metaInfo.minorVersion();
int majorVersion = metaInfo.majorVersion();
newQmlItemNode = QmlItemNode(view->createModelNode("QtQuick.Image", majorVersion, minorVersion, propertyPairList));
parentQmlItemNode.nodeAbstractProperty("data").reparentHere(newQmlItemNode);
}
Q_ASSERT(newQmlItemNode.isValid());
newQmlItemNode = QmlItemNode(view->createModelNode("QtQuick.Image", metaInfo.majorVersion(), metaInfo.minorVersion(), propertyPairList));
parentQmlItemNode.defaultNodeAbstractProperty().reparentHere(newQmlItemNode);
newQmlItemNode.setId(view->generateNewId("image"));
......@@ -229,8 +228,9 @@ QmlItemNode QmlItemNode::createQmlItemNodeFromImage(AbstractView *view, const QS
Q_ASSERT(newQmlItemNode.isValid());
}
Q_ASSERT(newQmlItemNode.isValid());
}
return newQmlItemNode;
}
......
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