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,66 +171,66 @@ QmlItemNode QmlItemNode::createQmlItemNode(AbstractView *view, const ItemLibrary ...@@ -171,66 +171,66 @@ QmlItemNode QmlItemNode::createQmlItemNode(AbstractView *view, const ItemLibrary
return newQmlItemNode; return newQmlItemNode;
} }
static void checkImageImport(AbstractView *view)
{
const QString newImportUrl = QLatin1String("QtQuick");
const QString newImportVersion = QLatin1String("1.1");
Import newImport = Import::createLibraryImport(newImportUrl, newImportVersion);
foreach (const Import &import, view->model()->imports()) {
if (import.isLibraryImport()
&& import.url() == newImport.url()) {
// reuse this import
newImport = import;
break;
}
}
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 QmlItemNode::createQmlItemNodeFromImage(AbstractView *view, const QString &imageName, const QPointF &position, QmlItemNode parentQmlItemNode)
{ {
if (!parentQmlItemNode.isValid() && QmlItemNode::isValidQmlItemNode(view->rootModelNode())) QmlItemNode newQmlItemNode;
if (!parentQmlItemNode.isValid())
parentQmlItemNode = QmlItemNode(view->rootModelNode()); parentQmlItemNode = QmlItemNode(view->rootModelNode());
else
return QmlItemNode();
QmlItemNode newQmlItemNode; if (parentQmlItemNode.isValid()) {
RewriterTransaction transaction = view->beginRewriterTransaction(); RewriterTransaction transaction = view->beginRewriterTransaction();
{
const QString newImportUrl = QLatin1String("QtQuick");
const QString newImportVersion = QLatin1String("1.1");
Import newImport = Import::createLibraryImport(newImportUrl, newImportVersion);
foreach (const Import &import, view->model()->imports()) {
if (import.isLibraryImport()
&& import.url() == newImport.url()) {
// reuse this import
newImport = import;
break;
}
}
if (!view->model()->hasImport(newImport, true, true)) checkImageImport(view);
view->model()->changeImports(QList<Import>() << newImport, QList<Import>());
QList<QPair<PropertyName, QVariant> > propertyPairList; if (view->model()->hasNodeMetaInfo("QtQuick.Image")) {
propertyPairList.append(qMakePair(PropertyName("x"), QVariant(qRound(position.x())))); NodeMetaInfo metaInfo = view->model()->metaInfo("QtQuick.Image");
propertyPairList.append(qMakePair(PropertyName("y"), QVariant(qRound(position.y())))); QList<QPair<PropertyName, QVariant> > propertyPairList;
propertyPairList.append(qMakePair(PropertyName("x"), QVariant(qRound(position.x()))));
propertyPairList.append(qMakePair(PropertyName("y"), QVariant(qRound(position.y()))));
QString relativeImageName = imageName; QString relativeImageName = imageName;
//use relative path //use relative path
if (QFileInfo(view->model()->fileUrl().toLocalFile()).exists()) { if (QFileInfo(view->model()->fileUrl().toLocalFile()).exists()) {
QDir fileDir(QFileInfo(view->model()->fileUrl().toLocalFile()).absolutePath()); QDir fileDir(QFileInfo(view->model()->fileUrl().toLocalFile()).absolutePath());
relativeImageName = fileDir.relativeFilePath(imageName); relativeImageName = fileDir.relativeFilePath(imageName);
} propertyPairList.append(qMakePair(PropertyName("source"), QVariant(relativeImageName)));
}
propertyPairList.append(qMakePair(PropertyName("source"), QVariant(relativeImageName))); newQmlItemNode = QmlItemNode(view->createModelNode("QtQuick.Image", metaInfo.majorVersion(), metaInfo.minorVersion(), propertyPairList));
NodeMetaInfo metaInfo = view->model()->metaInfo("QtQuick.Image"); parentQmlItemNode.defaultNodeAbstractProperty().reparentHere(newQmlItemNode);
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.setId(view->generateNewId("image"));
newQmlItemNode.setId(view->generateNewId("image")); if (!QmlModelState(view->actualStateNode()).isBaseState()) {
newQmlItemNode.modelNode().variantProperty("opacity").setValue(0);
newQmlItemNode.setVariantProperty("opacity", 1);
}
if (!QmlModelState(view->actualStateNode()).isBaseState()) { Q_ASSERT(newQmlItemNode.isValid());
newQmlItemNode.modelNode().variantProperty("opacity").setValue(0);
newQmlItemNode.setVariantProperty("opacity", 1);
} }
Q_ASSERT(newQmlItemNode.isValid()); Q_ASSERT(newQmlItemNode.isValid());
} }
Q_ASSERT(newQmlItemNode.isValid());
return newQmlItemNode; 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