Commit 626f0ab1 authored by Thomas Hartmann's avatar Thomas Hartmann

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
parent 3d2aae07
......@@ -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());
......
......@@ -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));
......
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