From 626f0ab1e2425b726d586954684719a0ca456725 Mon Sep 17 00:00:00 2001 From: Thomas Hartmann <Thomas.Hartmann@nokia.com> Date: Thu, 4 Nov 2010 11:08:39 +0100 Subject: [PATCH] QmlDesigner: fixes id renaming if there was no id before Refactoring only works of old and newId are not empty, otherwise we just fall back and use the model Task-number: QTCREATORBUG-2953 Reviewed-by: Kai Koehne --- .../components/navigator/navigatortreemodel.cpp | 12 ++++++++++-- .../components/propertyeditor/propertyeditor.cpp | 12 ++++++++++-- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/plugins/qmldesigner/components/navigator/navigatortreemodel.cpp b/src/plugins/qmldesigner/components/navigator/navigatortreemodel.cpp index 3533a95349e..25be6639416 100644 --- a/src/plugins/qmldesigner/components/navigator/navigatortreemodel.cpp +++ b/src/plugins/qmldesigner/components/navigator/navigatortreemodel.cpp @@ -299,8 +299,16 @@ void NavigatorTreeModel::handleChangedItem(QStandardItem *item) ItemRow itemRow = itemRowForNode(node); if (item == itemRow.idItem) { if (node.isValidId(item->text())) { - if (node.view()->rewriterView()) - node.view()->rewriterView()->renameId(node.id(), item->text()); + if (node.id().isEmpty() || item->text().isEmpty()) { //no id + try { + node.setId(item->text()); + } catch (InvalidIdException &e) { //better save then sorry + QMessageBox::warning(0, tr("Invalid Id"), e.description()); + } + } else { //there is already an id, so we refactor + if (node.view()->rewriterView()) + node.view()->rewriterView()->renameId(node.id(), item->text()); + } } else { QMessageBox::warning(0, tr("Invalid Id"), tr("%1 is an invalid id").arg(item->text())); item->setText(node.id()); diff --git a/src/plugins/qmldesigner/components/propertyeditor/propertyeditor.cpp b/src/plugins/qmldesigner/components/propertyeditor/propertyeditor.cpp index 51ce941ef32..2122d25c964 100644 --- a/src/plugins/qmldesigner/components/propertyeditor/propertyeditor.cpp +++ b/src/plugins/qmldesigner/components/propertyeditor/propertyeditor.cpp @@ -356,8 +356,16 @@ void PropertyEditor::changeValue(const QString &propertyName) const QString newId = value->value().toString(); if (m_selectedNode.isValidId(newId)) { - if (rewriterView()) - rewriterView()->renameId(m_selectedNode.id(), newId); + if (m_selectedNode.id().isEmpty() || newId.isEmpty()) { //no id + try { + m_selectedNode.setId(newId); + } catch (InvalidIdException &e) { //better save then sorry + QMessageBox::warning(0, tr("Invalid Id"), e.description()); + } + } else { //there is already an id, so we refactor + if (rewriterView()) + rewriterView()->renameId(m_selectedNode.id(), newId); + } } else { value->setValue(m_selectedNode.id()); QMessageBox::warning(0, tr("Invalid Id"), tr("%1 is an invalid id").arg(newId)); -- GitLab