Commit b40d056b authored by Thomas Hartmann's avatar Thomas Hartmann
Browse files

QmlDesigner.navigator: fixes crash for context menu

We have to add a check if the item we want to set visibility on
is really an item. See: isItem()

For general safety I added try catch blocks for RewritingExceptions


Task-Number: QTCREATORBUG-5731
Change-Id: I72f4f5ae69067a04b09880ae071265c83f880b4c
Reviewed-on: http://codereview.qt.nokia.com/2637


Reviewed-by: default avatarMarco Bubke <marco.bubke@nokia.com>
Reviewed-by: default avatarThomas Hartmann <Thomas.Hartmann@nokia.com>
parent 1a5fe565
......@@ -32,6 +32,7 @@
#include "modelnodecontextmenu.h"
#include <QApplication>
#include <QMessageBox>
#include <coreplugin/editormanager/editormanager.h>
#include <nodeabstractproperty.h>
#include <nodelistproperty.h>
......@@ -40,6 +41,7 @@
#include <qmlitemnode.h>
#include <variantproperty.h>
#include <nodeproperty.h>
#include <rewritingexception.h>
#include <rewritertransaction.h>
#include <designdocumentcontroller.h>
......@@ -67,6 +69,11 @@ static inline bool checkIfNodeIsAView(const ModelNode &node)
node.metaInfo().isSubclassOf("QtQuick.PathView", -1, -1));
}
static inline bool isItem(const ModelNode &node)
{
return node.metaInfo().isValid() && node.metaInfo().isSubclassOf("QtQuick.Item", -1, -1);
}
static inline QList<QmlItemNode> siblingsForNode(const QmlItemNode &itemNode)
{
QList<QmlItemNode> siblingList;
......@@ -242,7 +249,10 @@ void ModelNodeContextMenu::execute(const QPoint &pos, bool selectionMenuBool)
if (!modelNodesHaveProperty(selectedModelNodes, QLatin1String("width")) && !modelNodesHaveProperty(selectedModelNodes, QLatin1String("height")))
action->setDisabled(true);
editMenu->addAction(action);
editMenu->addAction(createModelNodeAction(tr("Visibility"), editMenu, QList<ModelNode>() << currentSingleNode, ModelNodeAction::ModelNodeVisibility, singleSelected));
action = createModelNodeAction(tr("Visibility"), editMenu, QList<ModelNode>() << currentSingleNode, ModelNodeAction::ModelNodeVisibility, singleSelected);
editMenu->addAction(action);
if (!isItem(currentSingleNode))
action->setDisabled(true);
} else {
editMenu->setEnabled(false);
......@@ -358,11 +368,15 @@ void ModelNodeAction::toFront()
if (!m_view)
return;
QmlItemNode node = m_modelNodeList.first();
if (node.isValid()) {
signed int maximumZ = getMaxZValue(siblingsForNode(node));
maximumZ++;
node.setVariantProperty("z", maximumZ);
try {
QmlItemNode node = m_modelNodeList.first();
if (node.isValid()) {
signed int maximumZ = getMaxZValue(siblingsForNode(node));
maximumZ++;
node.setVariantProperty("z", maximumZ);
}
} catch (RewritingException &e) { //better save then sorry
QMessageBox::warning(0, "Error", e.description());
}
}
......@@ -371,12 +385,16 @@ void ModelNodeAction::toBack()
{
if (!m_view)
return;
try {
QmlItemNode node = m_modelNodeList.first();
if (node.isValid()) {
signed int minimumZ = getMinZValue(siblingsForNode(node));
minimumZ--;
node.setVariantProperty("z", minimumZ);
}
QmlItemNode node = m_modelNodeList.first();
if (node.isValid()) {
signed int minimumZ = getMinZValue(siblingsForNode(node));
minimumZ--;
node.setVariantProperty("z", minimumZ);
} catch (RewritingException &e) { //better save then sorry
QMessageBox::warning(0, "Error", e.description());
}
}
......@@ -385,14 +403,18 @@ void ModelNodeAction::raise()
if (!m_view)
return;
RewriterTransaction(m_view);
foreach (ModelNode modelNode, m_modelNodeList) {
QmlItemNode node = modelNode;
if (node.isValid()) {
signed int z = node.instanceValue("z").toInt();
z++;
node.setVariantProperty("z", z);
try {
RewriterTransaction(m_view);
foreach (ModelNode modelNode, m_modelNodeList) {
QmlItemNode node = modelNode;
if (node.isValid()) {
signed int z = node.instanceValue("z").toInt();
z++;
node.setVariantProperty("z", z);
}
}
} catch (RewritingException &e) { //better save then sorry
QMessageBox::warning(0, "Error", e.description());
}
}
......@@ -400,15 +422,18 @@ void ModelNodeAction::lower()
{
if (!m_view)
return;
RewriterTransaction(m_view);
foreach (ModelNode modelNode, m_modelNodeList) {
QmlItemNode node = modelNode;
if (node.isValid()) {
signed int z = node.instanceValue("z").toInt();
z--;
node.setVariantProperty("z", z);
try {
RewriterTransaction(m_view);
foreach (ModelNode modelNode, m_modelNodeList) {
QmlItemNode node = modelNode;
if (node.isValid()) {
signed int z = node.instanceValue("z").toInt();
z--;
node.setVariantProperty("z", z);
}
}
} catch (RewritingException &e) { //better save then sorry
QMessageBox::warning(0, "Error", e.description());
}
}
......@@ -426,7 +451,13 @@ void ModelNodeAction::redo()
void ModelNodeAction::setVisible(bool b)
{
m_modelNodeList.first().variantProperty("visible") = b;
if (!m_view)
return;
try {
m_modelNodeList.first().variantProperty("visible") = b;
} catch (RewritingException &e) { //better save then sorry
QMessageBox::warning(0, "Error", e.description());
}
}
......@@ -434,11 +465,14 @@ void ModelNodeAction::resetSize()
{
if (!m_view)
return;
RewriterTransaction(m_view);
foreach (ModelNode node, m_modelNodeList) {
node.removeProperty("width");
node.removeProperty("height");
try {
RewriterTransaction(m_view);
foreach (ModelNode node, m_modelNodeList) {
node.removeProperty("width");
node.removeProperty("height");
}
} catch (RewritingException &e) { //better save then sorry
QMessageBox::warning(0, "Error", e.description());
}
}
......@@ -446,11 +480,14 @@ void ModelNodeAction::resetPosition()
{
if (!m_view)
return;
RewriterTransaction(m_view);
foreach (ModelNode node, m_modelNodeList) {
node.removeProperty("x");
node.removeProperty("y");
try {
RewriterTransaction(m_view);
foreach (ModelNode node, m_modelNodeList) {
node.removeProperty("x");
node.removeProperty("y");
}
} catch (RewritingException &e) { //better save then sorry
QMessageBox::warning(0, "Error", e.description());
}
}
......
Supports Markdown
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