Commit 7f66d8fe authored by Marco Bubke's avatar Marco Bubke

QmlDesigner: Raise exception for a invalid parent property

Change-Id: I0272b0aefc0598ad524aa1d9e6b434ef2dcd79a9
Reviewed-by: default avatarThomas Hartmann <Thomas.Hartmann@digia.com>
parent d3c299cb
......@@ -56,7 +56,7 @@ static inline QList<QmlItemNode> siblingsForNode(const QmlItemNode &itemNode)
{
QList<QmlItemNode> siblingList;
if (itemNode.isValid() && itemNode.modelNode().parentProperty().isValid()) {
if (itemNode.isValid() && itemNode.modelNode().hasParentProperty()) {
QList<ModelNode> modelNodes = itemNode.modelNode().parentProperty().parentModelNode().allDirectSubModelNodes();
foreach (const ModelNode &node, modelNodes) {
QmlItemNode childItemNode = node;
......
......@@ -236,7 +236,7 @@ void FormEditorView::propertiesAboutToBeRemoved(const QList<AbstractProperty>& p
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();
if (parent.nodeSourceType() != ModelNode::NodeWithoutSource)
return true;
......
......@@ -488,7 +488,7 @@ void DesignDocument::paste()
targetNode = view.selectedModelNodes().first();
//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();
if (!targetNode.isValid())
......
......@@ -38,6 +38,7 @@
#include "invalidargumentexception.h"
#include "invalididexception.h"
#include "invalidmodelnodeexception.h"
#include "invalidpropertyexception.h"
#include "model_p.h"
#include "variantproperty.h"
#include "bindingproperty.h"
......@@ -277,8 +278,11 @@ NodeAbstractProperty ModelNode::parentProperty() const
Q_ASSERT_X(isValid(), Q_FUNC_INFO, "model node is invalid");
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());
}
......
......@@ -65,7 +65,7 @@ void NodeAbstractProperty::reparentHere(const ModelNode &modelNode)
void NodeAbstractProperty::reparentHere(const ModelNode &modelNode, bool isNodeList)
{
if (modelNode.parentProperty() == *this)
if (modelNode.hasParentProperty() && modelNode.parentProperty() == *this)
return;
Internal::WriteLocker locker(model());
if (!isValid())
......
......@@ -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.
......@@ -1656,7 +1656,7 @@ void ModelAmender::typeDiffers(bool isRootNode,
QmlJS::AST::UiObjectMember *astNode,
ReadingContext *context)
{
const bool propertyTakesComponent = propertyIsComponentType(modelNode.parentProperty(), typeName, modelNode.model());
const bool propertyTakesComponent = modelNode.hasParentProperty() && propertyIsComponentType(modelNode.parentProperty(), typeName, modelNode.model());
if (isRootNode) {
modelNode.view()->changeRootNodeType(typeName, majorVersion, minorVersion);
......
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