QmlDesigner: Raise exception for a invalid parent property

Change-Id: I0272b0aefc0598ad524aa1d9e6b434ef2dcd79a9
Reviewed-by: Thomas Hartmann <Thomas.Hartmann@digia.com>
This commit is contained in:
Marco Bubke
2013-08-06 16:11:11 +02:00
parent d3c299cbe3
commit 7f66d8fe03
6 changed files with 12 additions and 8 deletions

View File

@@ -56,7 +56,7 @@ static inline QList<QmlItemNode> siblingsForNode(const QmlItemNode &itemNode)
{ {
QList<QmlItemNode> siblingList; QList<QmlItemNode> siblingList;
if (itemNode.isValid() && itemNode.modelNode().parentProperty().isValid()) { if (itemNode.isValid() && itemNode.modelNode().hasParentProperty()) {
QList<ModelNode> modelNodes = itemNode.modelNode().parentProperty().parentModelNode().allDirectSubModelNodes(); QList<ModelNode> modelNodes = itemNode.modelNode().parentProperty().parentModelNode().allDirectSubModelNodes();
foreach (const ModelNode &node, modelNodes) { foreach (const ModelNode &node, modelNodes) {
QmlItemNode childItemNode = node; QmlItemNode childItemNode = node;

View File

@@ -236,7 +236,7 @@ void FormEditorView::propertiesAboutToBeRemoved(const QList<AbstractProperty>& p
static inline bool hasNodeSourceParent(const ModelNode &node) static inline bool hasNodeSourceParent(const ModelNode &node)
{ {
if (node.parentProperty().isValid() && node.parentProperty().parentModelNode().isValid()) { if (node.hasParentProperty() && node.parentProperty().parentModelNode().isValid()) {
ModelNode parent = node.parentProperty().parentModelNode(); ModelNode parent = node.parentProperty().parentModelNode();
if (parent.nodeSourceType() != ModelNode::NodeWithoutSource) if (parent.nodeSourceType() != ModelNode::NodeWithoutSource)
return true; return true;

View File

@@ -488,7 +488,7 @@ void DesignDocument::paste()
targetNode = view.selectedModelNodes().first(); targetNode = view.selectedModelNodes().first();
//In case we copy and paste a selection we paste in the parent item //In case we copy and paste a selection we paste in the parent item
if ((view.selectedModelNodes().count() == selectedNodes.count()) && targetNode.isValid() && targetNode.parentProperty().isValid()) if ((view.selectedModelNodes().count() == selectedNodes.count()) && targetNode.isValid() && targetNode.hasParentProperty())
targetNode = targetNode.parentProperty().parentModelNode(); targetNode = targetNode.parentProperty().parentModelNode();
if (!targetNode.isValid()) if (!targetNode.isValid())

View File

@@ -38,6 +38,7 @@
#include "invalidargumentexception.h" #include "invalidargumentexception.h"
#include "invalididexception.h" #include "invalididexception.h"
#include "invalidmodelnodeexception.h" #include "invalidmodelnodeexception.h"
#include "invalidpropertyexception.h"
#include "model_p.h" #include "model_p.h"
#include "variantproperty.h" #include "variantproperty.h"
#include "bindingproperty.h" #include "bindingproperty.h"
@@ -277,8 +278,11 @@ NodeAbstractProperty ModelNode::parentProperty() const
Q_ASSERT_X(isValid(), Q_FUNC_INFO, "model node is invalid"); Q_ASSERT_X(isValid(), Q_FUNC_INFO, "model node is invalid");
throw InvalidModelNodeException(__LINE__, __FUNCTION__, __FILE__); throw InvalidModelNodeException(__LINE__, __FUNCTION__, __FILE__);
} }
if (m_internalNode->parentProperty().isNull())
return NodeAbstractProperty(); if (m_internalNode->parentProperty().isNull()) {
Q_ASSERT_X(m_internalNode->parentProperty(), Q_FUNC_INFO, "parentProperty is invalid");
throw InvalidPropertyException(__LINE__, __FUNCTION__, __FILE__, "parent");
}
return NodeAbstractProperty(m_internalNode->parentProperty()->name(), m_internalNode->parentProperty()->propertyOwner(), m_model.data(), view()); return NodeAbstractProperty(m_internalNode->parentProperty()->name(), m_internalNode->parentProperty()->propertyOwner(), m_model.data(), view());
} }

View File

@@ -65,7 +65,7 @@ void NodeAbstractProperty::reparentHere(const ModelNode &modelNode)
void NodeAbstractProperty::reparentHere(const ModelNode &modelNode, bool isNodeList) void NodeAbstractProperty::reparentHere(const ModelNode &modelNode, bool isNodeList)
{ {
if (modelNode.parentProperty() == *this) if (modelNode.hasParentProperty() && modelNode.parentProperty() == *this)
return; return;
Internal::WriteLocker locker(model()); Internal::WriteLocker locker(model());
if (!isValid()) if (!isValid())

View File

@@ -901,7 +901,7 @@ void TextToModelMerger::syncNode(ModelNode &modelNode,
} }
} }
bool isImplicitComponent = modelNode.parentProperty().isValid() && propertyIsComponentType(modelNode.parentProperty(), typeName, modelNode.model()); bool isImplicitComponent = modelNode.hasParentProperty() && propertyIsComponentType(modelNode.parentProperty(), typeName, modelNode.model());
if (modelNode.type() != typeName //If there is no valid parentProperty //the node has just been created. The type is correct then. if (modelNode.type() != typeName //If there is no valid parentProperty //the node has just been created. The type is correct then.
@@ -1656,7 +1656,7 @@ void ModelAmender::typeDiffers(bool isRootNode,
QmlJS::AST::UiObjectMember *astNode, QmlJS::AST::UiObjectMember *astNode,
ReadingContext *context) ReadingContext *context)
{ {
const bool propertyTakesComponent = propertyIsComponentType(modelNode.parentProperty(), typeName, modelNode.model()); const bool propertyTakesComponent = modelNode.hasParentProperty() && propertyIsComponentType(modelNode.parentProperty(), typeName, modelNode.model());
if (isRootNode) { if (isRootNode) {
modelNode.view()->changeRootNodeType(typeName, majorVersion, minorVersion); modelNode.view()->changeRootNodeType(typeName, majorVersion, minorVersion);