Commit 599b72a2 authored by Marco Bubke's avatar Marco Bubke

QmlDesigner: Use is valid functons instead of create a invalid node

Change-Id: I5f7cdcede593cdce2c577315ccead95e8841870e
Reviewed-by: default avatarTim Jenssen <tim.jenssen@digia.com>
parent 07147a32
......@@ -53,7 +53,7 @@ static inline bool checkIfNodeIsAView(const ModelNode &node)
static inline void getProperties(const ModelNode node, QHash<PropertyName, QVariant> &propertyHash)
{
if (QmlObjectNode(node).isValid()) {
if (QmlObjectNode::isValidQmlObjectNode(node)) {
foreach (const PropertyName &propertyName, node.propertyNames()) {
if (node.property(propertyName).isVariantProperty() ||
(node.property(propertyName).isBindingProperty() &&
......@@ -61,15 +61,17 @@ static inline void getProperties(const ModelNode node, QHash<PropertyName, QVari
propertyHash.insert(propertyName, QmlObjectNode(node).instanceValue(propertyName));
}
}
}
QmlItemNode itemNode(node);
if (itemNode.isValid()) {
propertyHash.insert("width", itemNode.instanceValue("width"));
propertyHash.insert("height", itemNode.instanceValue("height"));
propertyHash.remove("x");
propertyHash.remove("y");
propertyHash.remove("rotation");
propertyHash.remove("opacity");
if (QmlItemNode::isValidQmlItemNode(node)) {
QmlItemNode itemNode(node);
propertyHash.insert("width", itemNode.instanceValue("width"));
propertyHash.insert("height", itemNode.instanceValue("height"));
propertyHash.remove("x");
propertyHash.remove("y");
propertyHash.remove("rotation");
propertyHash.remove("opacity");
}
}
}
......
......@@ -104,8 +104,8 @@ void FormEditorView::modelAttached(Model *model)
Q_ASSERT(m_scene->formLayerItem());
if (rootQmlObjectNode().toQmlItemNode().isValid())
setupFormEditorItemTree(rootQmlObjectNode().toQmlItemNode());
if (QmlItemNode::isValidQmlItemNode(rootModelNode()))
setupFormEditorItemTree(rootModelNode());
m_formEditorWidget->updateActions();
}
......@@ -159,7 +159,7 @@ void FormEditorView::nodeCreated(const ModelNode &createdNode)
QmlModelView::nodeCreated(createdNode);
ModelNode node(createdNode);
//If the node has source for components/custom parsers we ignore it.
if (QmlItemNode(node).isValid() && node.nodeSourceType() == ModelNode::NodeWithoutSource) //only setup QmlItems
if (QmlItemNode::isValidQmlItemNode(node) && node.nodeSourceType() == ModelNode::NodeWithoutSource) //only setup QmlItems
setupFormEditorItemTree(QmlItemNode(node));
}
......@@ -648,8 +648,8 @@ void FormEditorView::delayedReset()
m_resizeTool->clear();
m_dragTool->clear();
m_scene->clearFormEditorItems();
if (rootQmlObjectNode().toQmlItemNode().isValid())
setupFormEditorItemTree(rootQmlObjectNode().toQmlItemNode());
if (QmlItemNode::isValidQmlItemNode(rootModelNode()))
setupFormEditorItemTree(rootModelNode());
}
......
......@@ -347,12 +347,12 @@ void MoveManipulator::reparentTo(FormEditorItem *newParent)
QVector<ModelNode> nodeReparentVector;
NodeAbstractProperty parentProperty;
QmlItemNode parent(newParent->qmlItemNode());
if (parent.isValid()) {
if (parent.hasDefaultProperty())
parentProperty = parent.nodeAbstractProperty(parent.defaultProperty());
QmlItemNode parentItemNode(newParent->qmlItemNode());
if (parentItemNode.isValid()) {
if (parentItemNode.hasDefaultProperty())
parentProperty = parentItemNode.nodeAbstractProperty(parentItemNode.defaultProperty());
else
parentProperty = parent.nodeAbstractProperty("data");
parentProperty = parentItemNode.nodeAbstractProperty("data");
foreach (FormEditorItem* item, m_itemList) {
if (!item || !item->qmlItemNode().isValid())
......
......@@ -139,8 +139,9 @@ void ComponentView::searchForComponentAndAddToList(const ModelNode &node)
m_standardItemModel->appendRow(item);
} else {
QString description;
ModelNode parentNode = node.parentProperty().parentModelNode();
if (parentNode.isValid()) {
if (node.hasParentProperty()) {
ModelNode parentNode = node.parentProperty().parentModelNode();
if (parentNode.id().isEmpty())
description = parentNode.simplifiedTypeName() + QLatin1Char(' ');
else
......
......@@ -379,7 +379,7 @@ void DesignDocument::deleteSelected()
RewriterTransaction transaction(rewriterView());
QList<ModelNode> toDelete = qmlModelView()->selectedModelNodes();
foreach (ModelNode node, toDelete) {
if (node.isValid() && !node.isRootNode() && QmlObjectNode(node).isValid())
if (node.isValid() && !node.isRootNode() && QmlObjectNode::isValidQmlObjectNode(node))
QmlObjectNode(node).destroy();
}
......@@ -562,7 +562,7 @@ void DesignDocument::paste()
if (!targetNode.isValid())
targetNode = view.rootModelNode();
if (targetNode.parentProperty().isValid() &&
if (targetNode.hasParentProperty() &&
(pastedNode.simplifiedTypeName() == targetNode.simplifiedTypeName()) &&
(pastedNode.variantProperty("width").value() == targetNode.variantProperty("width").value()) &&
(pastedNode.variantProperty("height").value() == targetNode.variantProperty("height").value()))
......@@ -572,7 +572,7 @@ void DesignDocument::paste()
PropertyName defaultProperty(targetNode.metaInfo().defaultPropertyName());
scatterItem(pastedNode, targetNode);
if (targetNode.nodeListProperty(defaultProperty).isValid())
if (targetNode.hasNodeListProperty(defaultProperty))
targetNode.nodeListProperty(defaultProperty).reparentHere(pastedNode);
transaction.commit();
......
......@@ -47,8 +47,8 @@
static inline void setScenePos(const QmlDesigner::ModelNode &modelNode,const QPointF &pos)
{
QmlDesigner::QmlItemNode parentNode = modelNode.parentProperty().parentQmlObjectNode().toQmlItemNode();
if (parentNode.isValid()) {
if (modelNode.hasParentProperty() && QmlDesigner::QmlItemNode::isValidQmlItemNode(modelNode.parentProperty().parentModelNode())) {
QmlDesigner::QmlItemNode parentNode = modelNode.parentProperty().parentQmlObjectNode().toQmlItemNode();
QPointF localPos = parentNode.instanceSceneTransform().inverted().map(pos);
modelNode.variantProperty("x") = localPos.toPoint().x();
modelNode.variantProperty("y") = localPos.toPoint().y();
......
......@@ -42,8 +42,8 @@
static inline void setScenePos(const QmlDesigner::ModelNode &modelNode,const QPointF &pos)
{
QmlDesigner::QmlItemNode parentNode = modelNode.parentProperty().parentQmlObjectNode().toQmlItemNode();
if (parentNode.isValid()) {
if (modelNode.hasParentProperty() && QmlDesigner::QmlItemNode::isValidQmlItemNode(modelNode.parentProperty().parentModelNode())) {
QmlDesigner::QmlItemNode parentNode = modelNode.parentProperty().parentQmlObjectNode().toQmlItemNode();
QPointF localPos = parentNode.instanceSceneTransform().inverted().map(pos);
modelNode.variantProperty("x") = localPos.toPoint().x();
modelNode.variantProperty("y") = localPos.toPoint().y();
......@@ -303,7 +303,7 @@ void NavigatorView::leftButtonClicked()
foreach (const ModelNode &node, selectedModelNodes()) {
if (!node.isRootNode() && !node.parentProperty().parentModelNode().isRootNode()) {
if (QmlItemNode(node).isValid()) {
if (QmlItemNode::isValidQmlItemNode(node)) {
QPointF scenePos = QmlItemNode(node).instanceScenePosition();
node.parentProperty().parentModelNode().parentProperty().reparentHere(node);
if (!scenePos.isNull())
......@@ -330,7 +330,7 @@ void NavigatorView::rightButtonClicked()
if (index >= 0) { //for the first node the semantics are not clear enough. Wrapping would be irritating.
ModelNode newParent = node.parentProperty().toNodeListProperty().at(index);
if (QmlItemNode(node).isValid()) {
if (QmlItemNode::isValidQmlItemNode(node)) {
QPointF scenePos = QmlItemNode(node).instanceScenePosition();
newParent.nodeAbstractProperty(newParent.metaInfo().defaultPropertyName()).reparentHere(node);
if (!scenePos.isNull())
......
......@@ -356,14 +356,14 @@ void PropertyEditorNodeWrapper::changeValue(const QString &propertyName)
if (name.isNull())
return;
if (m_modelNode.isValid()) {
QmlDesigner::QmlObjectNode fxObjectNode(m_modelNode);
QmlDesigner::QmlObjectNode qmlObjectNode(m_modelNode);
PropertyEditorValue *valueObject = qvariant_cast<PropertyEditorValue *>(m_valuesPropertyMap.value(name));
if (valueObject->value().isValid())
fxObjectNode.setVariantProperty(name, valueObject->value());
qmlObjectNode.setVariantProperty(name, valueObject->value());
else
fxObjectNode.removeProperty(name);
qmlObjectNode.removeProperty(name);
}
}
......@@ -372,17 +372,17 @@ void PropertyEditorNodeWrapper::setup()
Q_ASSERT(m_editorValue);
Q_ASSERT(m_editorValue->modelNode().isValid());
if ((m_editorValue->modelNode().isValid() && m_modelNode.isValid())) {
QmlDesigner::QmlObjectNode fxObjectNode(m_modelNode);
QmlDesigner::QmlObjectNode qmlObjectNode(m_modelNode);
foreach ( const QString &propertyName, m_valuesPropertyMap.keys())
m_valuesPropertyMap.clear(propertyName);
foreach (QObject *object, m_valuesPropertyMap.children())
delete object;
foreach (const QmlDesigner::PropertyName &propertyName, m_modelNode.metaInfo().propertyNames()) {
if (fxObjectNode.isValid()) {
if (qmlObjectNode.isValid()) {
PropertyEditorValue *valueObject = new PropertyEditorValue(&m_valuesPropertyMap);
valueObject->setName(propertyName);
valueObject->setValue(fxObjectNode.instanceValue(propertyName));
valueObject->setValue(qmlObjectNode.instanceValue(propertyName));
connect(valueObject, SIGNAL(valueChanged(QString,QVariant)), &m_valuesPropertyMap, SIGNAL(valueChanged(QString,QVariant)));
m_valuesPropertyMap.insert(propertyName, QVariant::fromValue(valueObject));
}
......
......@@ -92,7 +92,7 @@ public:
bool horizontalCentered();
bool verticalCentered();
QVariant itemNode() const { return QVariant::fromValue(m_fxItemNode.modelNode()); }
QVariant itemNode() const { return QVariant::fromValue(m_qmlItemNode.modelNode()); }
QVariant topTarget() const { return QVariant::fromValue(m_topTarget.modelNode()); }
QVariant bottomTarget() const { return QVariant::fromValue(m_bottomTarget.modelNode()); }
......@@ -151,7 +151,7 @@ private:
ModelNode modelNode() const;
QmlItemNode m_fxItemNode;
QmlItemNode m_qmlItemNode;
QRectF parentBoundingBox();
......
......@@ -64,9 +64,11 @@ public:
QString name() const;
void setName(const QString &name);
bool isValid() const;
static bool isValidQmlModelState(const ModelNode &modelNode);
void destroy();
bool isBaseState() const;
static bool isBaseState(const ModelNode &modelNode);
QmlModelState duplicate(const QString &name) const;
QmlModelStateGroup stateGroup() const;
......
......@@ -72,7 +72,7 @@ QStringList QmlModelStateGroup::names() const
if (modelNode().property("states").isNodeListProperty()) {
foreach (const ModelNode &node, modelNode().nodeListProperty("states").toModelNodeList()) {
if (QmlModelState(node).isValid())
if (QmlModelState::isValidQmlModelState(node))
returnList.append(QmlModelState(node).name());
}
}
......@@ -110,7 +110,7 @@ QList<QmlItemNode> QmlItemNode::children() const
}
foreach (const ModelNode &modelNode, modelNodeList) {
if (QmlItemNode(modelNode).isValid()) //if ModelNode is FxItem
if (QmlItemNode::isValidQmlItemNode(modelNode)) //if ModelNode is FxItem
returnList.append(modelNode);
}
}
......@@ -134,7 +134,7 @@ QList<QmlObjectNode> QmlItemNode::resources() const
}
foreach (const ModelNode &node, modelNodeList) {
if (!QmlObjectNode(node).isValid()) //if ModelNode is no FxItem
if (!QmlObjectNode::isValidQmlObjectNode(node)) //if ModelNode is no FxItem
returnList.append(node);
}
}
......@@ -150,7 +150,7 @@ QList<QmlObjectNode> QmlItemNode::defaultPropertyChildren() const
modelNodeList.append(modelNode().nodeListProperty(defaultProperty()).toModelNodeList());
foreach (const ModelNode &node, modelNodeList) {
if (!QmlObjectNode(node).isValid()) //if ModelNode is no FxItem
if (!QmlObjectNode::isValidQmlObjectNode(node)) //if ModelNode is no FxItem
returnList.append(node);
}
}
......@@ -272,11 +272,10 @@ QTransform QmlItemNode::instanceSceneContentItemTransform() const
QPointF QmlItemNode::instanceScenePosition() const
{
QmlItemNode parentNode = instanceParent().toQmlItemNode();
if (!parentNode.isValid())
parentNode = modelNode().parentProperty().parentQmlObjectNode().toQmlItemNode();
if (parentNode.isValid())
return parentNode.instanceSceneTransform().map(nodeInstance().position());
if (hasInstanceParentItem())
return instanceParentItem().instanceSceneTransform().map(nodeInstance().position());
else if (modelNode().hasParentProperty() && QmlItemNode::isValidQmlItemNode(modelNode().parentProperty().parentModelNode()))
return QmlItemNode(modelNode().parentProperty().parentModelNode()).instanceSceneTransform().map(nodeInstance().position());
return QPointF();
}
......@@ -331,8 +330,8 @@ QList<QmlModelState> QmlModelStateGroup::allStates() const
if (modelNode().property("states").isNodeListProperty()) {
foreach (const ModelNode &node, modelNode().nodeListProperty("states").toModelNodeList()) {
if (QmlModelState(node).isValid())
returnList.append(QmlModelState(node));
if (QmlModelState::isValidQmlModelState(node))
returnList.append(node);
}
}
return returnList;
......
......@@ -58,10 +58,7 @@ QmlModelView::QmlModelView(QObject *parent)
void QmlModelView::setCurrentState(const QmlModelState &state)
{
if (!state.isValid())
return;
if (!model())
if (!model() && !state.isValid())
return;
if (actualStateNode() != state.modelNode())
......@@ -101,10 +98,9 @@ QmlItemNode QmlModelView::createQmlItemNode(const TypeName &typeString,
QmlItemNode QmlModelView::createQmlItemNodeFromImage(const QString &imageName, const QPointF &position, QmlItemNode parentNode)
{
if (!parentNode.isValid())
if (!parentNode.isValid() && rootQmlItemNode().isValid())
parentNode = rootQmlItemNode();
if (!parentNode.isValid())
else
return QmlItemNode();
QmlItemNode newNode;
......
......@@ -320,19 +320,19 @@ QList<QmlModelStateOperation> QmlObjectNode::allAffectingStatesOperations() cons
return returnList;
}
static QList<QmlItemNode> allFxItemsRecursive(const QmlItemNode &fxNode)
static QList<QmlItemNode> allQmlItemsRecursive(const QmlItemNode &qmlItemNode)
{
QList<QmlItemNode> returnList;
if (fxNode.isValid()) {
returnList.append(fxNode);
if (qmlItemNode.isValid()) {
returnList.append(qmlItemNode);
QList<QmlItemNode> allChildNodes;
foreach (const ModelNode &node, fxNode.modelNode().allDirectSubModelNodes()) {
if (QmlItemNode(node).isValid())
foreach (const ModelNode &node, qmlItemNode.modelNode().allDirectSubModelNodes()) {
if (QmlItemNode::isValidQmlItemNode(node))
allChildNodes.append(node);
}
foreach (const QmlItemNode &node, allChildNodes) {
returnList.append(allFxItemsRecursive(node));
returnList.append(allQmlItemsRecursive(node));
}
}
return returnList;
......@@ -345,14 +345,12 @@ QList<QmlModelState> QmlObjectNode::allDefinedStates() const
QList<QmlModelState> returnList;
QList<QmlItemNode> allFxItems;
QList<QmlItemNode> allQmlItems;
QmlItemNode rootNode(qmlModelView()->rootModelNode());
if (QmlItemNode::isValidQmlItemNode(qmlModelView()->rootModelNode()))
allQmlItems.append(allQmlItemsRecursive(qmlModelView()->rootModelNode()));
if (rootNode.isValid())
allFxItems.append(allFxItemsRecursive(rootNode));
foreach (const QmlItemNode &item, allFxItems) {
foreach (const QmlItemNode &item, allQmlItems) {
returnList.append(item.states().allStates());
}
......@@ -378,12 +376,12 @@ void QmlObjectNode::removeProperty(const PropertyName &name)
}
}
QList<ModelNode> toModelNodeList(const QList<QmlObjectNode> &fxObjectNodeList)
QList<ModelNode> toModelNodeList(const QList<QmlObjectNode> &qmlObjectNodeList)
{
QList<ModelNode> modelNodeList;
foreach (const QmlObjectNode &fxObjectNode, fxObjectNodeList)
modelNodeList.append(fxObjectNode.modelNode());
foreach (const QmlObjectNode &qmlObjectNode, qmlObjectNodeList)
modelNodeList.append(qmlObjectNode.modelNode());
return modelNodeList;
}
......@@ -393,9 +391,8 @@ QList<QmlObjectNode> toQmlObjectNodeList(const QList<ModelNode> &modelNodeList)
QList<QmlObjectNode> qmlObjectNodeList;
foreach (const ModelNode &modelNode, modelNodeList) {
QmlObjectNode objectNode(modelNode);
if (objectNode.isValid())
qmlObjectNodeList.append(objectNode);
if (QmlObjectNode::isValidQmlObjectNode(modelNode))
qmlObjectNodeList.append(modelNode);
}
return qmlObjectNodeList;
......
......@@ -58,7 +58,9 @@ QmlPropertyChanges QmlModelState::propertyChanges(const ModelNode &node)
addChangeSetIfNotExists(node);
foreach (const ModelNode &childNode, modelNode().nodeListProperty("changes").toModelNodeList()) {
//### exception if not valid QmlModelStateOperation
if (QmlPropertyChanges(childNode).target().isValid() && QmlPropertyChanges(childNode).target() == node && QmlPropertyChanges(childNode).isValid())
if (QmlPropertyChanges::isValidQmlPropertyChanges(childNode)
&& QmlPropertyChanges(childNode).target().isValid()
&& QmlPropertyChanges(childNode).target() == node)
return QmlPropertyChanges(childNode); //### exception if not valid(childNode);
}
return QmlPropertyChanges(); //not found
......@@ -78,14 +80,14 @@ QList<QmlModelStateOperation> QmlModelState::stateOperations(const ModelNode &no
Q_ASSERT(modelNode().property("changes").isNodeListProperty());
foreach (const ModelNode &childNode, modelNode().nodeListProperty("changes").toModelNodeList()) {
QmlModelStateOperation stateOperation(childNode);
if (stateOperation.isValid()) {
if (QmlModelStateOperation::isValidQmlModelStateOperation(childNode)) {
QmlModelStateOperation stateOperation(childNode);
ModelNode targetNode = stateOperation.target();
if (targetNode.isValid()
&& targetNode == node)
returnList.append(stateOperation); //### exception if not valid(childNode);
if (targetNode.isValid() && targetNode == node)
returnList.append(stateOperation); //### exception if not valid(childNode);
}
}
return returnList; //not found
}
......@@ -246,9 +248,14 @@ void QmlModelState::setName(const QString &name)
bool QmlModelState::isValid() const
{
return QmlModelNodeFacade::isValid() &&
modelNode().metaInfo().isValid() &&
(modelNode().metaInfo().isSubclassOf("QtQuick.State", -1, -1) || isBaseState());
return isValidQmlModelState(modelNode());
}
bool QmlModelState::isValidQmlModelState(const ModelNode &modelNode)
{
return isValidQmlModelNodeFacade(modelNode)
&& modelNode.metaInfo().isValid()
&& (modelNode.metaInfo().isSubclassOf("QtQuick.State", -1, -1) || isBaseState(modelNode));
}
/**
......@@ -267,7 +274,12 @@ void QmlModelState::destroy()
bool QmlModelState::isBaseState() const
{
return !modelNode().isValid() || modelNode().isRootNode();
return isBaseState(modelNode());
}
bool QmlModelState::isBaseState(const ModelNode &modelNode)
{
return !modelNode.isValid() || modelNode.isRootNode();
}
QmlModelState QmlModelState::duplicate(const QString &name) const
......
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