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

QmlDesigner: fix for duplicate ids

Duplicate ids for not handled 100% correctly in the property editor
and in the navigator.

Reviewed-by: Kai Koehne
parent 4844ead3
...@@ -315,7 +315,7 @@ void NavigatorTreeModel::handleChangedItem(QStandardItem *item) ...@@ -315,7 +315,7 @@ void NavigatorTreeModel::handleChangedItem(QStandardItem *item)
ItemRow itemRow = itemRowForNode(node); ItemRow itemRow = itemRowForNode(node);
if (item == itemRow.idItem) { if (item == itemRow.idItem) {
if (node.isValidId(item->text())) { if (node.isValidId(item->text()) && !node.view()->modelNodeForId(item->text()).isValid()) {
if (node.id().isEmpty() || item->text().isEmpty()) { //no id if (node.id().isEmpty() || item->text().isEmpty()) { //no id
try { try {
node.setId(item->text()); node.setId(item->text());
...@@ -327,8 +327,14 @@ void NavigatorTreeModel::handleChangedItem(QStandardItem *item) ...@@ -327,8 +327,14 @@ void NavigatorTreeModel::handleChangedItem(QStandardItem *item)
node.view()->rewriterView()->renameId(node.id(), item->text()); node.view()->rewriterView()->renameId(node.id(), item->text());
} }
} else { } else {
QMessageBox::warning(0, tr("Invalid Id"), tr("%1 is an invalid id").arg(item->text()));
item->setText(node.id()); if (!node.isValidId(item->text()))
QMessageBox::warning(0, tr("Invalid Id"), tr("%1 is an invalid id").arg(item->text()));
else
QMessageBox::warning(0, tr("Invalid Id"), tr("%1 already exists").arg(item->text()));
bool blockSingals = blockItemChangedSignal(true);
item->setText(node.id());
blockItemChangedSignal(blockSingals);
} }
} else if (item == itemRow.visibilityItem) { } else if (item == itemRow.visibilityItem) {
bool invisible = (item->checkState() == Qt::Unchecked); bool invisible = (item->checkState() == Qt::Unchecked);
......
...@@ -368,12 +368,17 @@ void PropertyEditor::changeValue(const QString &propertyName) ...@@ -368,12 +368,17 @@ void PropertyEditor::changeValue(const QString &propertyName)
PropertyEditorValue *value = qobject_cast<PropertyEditorValue*>(QDeclarativeMetaType::toQObject(m_currentType->m_backendValuesPropertyMap.value(propertyName))); PropertyEditorValue *value = qobject_cast<PropertyEditorValue*>(QDeclarativeMetaType::toQObject(m_currentType->m_backendValuesPropertyMap.value(propertyName)));
const QString newId = value->value().toString(); const QString newId = value->value().toString();
if (m_selectedNode.isValidId(newId)) { if (newId == m_selectedNode.id())
return;
if (m_selectedNode.isValidId(newId) && !modelNodeForId(newId).isValid() ) {
if (m_selectedNode.id().isEmpty() || newId.isEmpty()) { //no id if (m_selectedNode.id().isEmpty() || newId.isEmpty()) { //no id
try { try {
m_selectedNode.setId(newId); m_selectedNode.setId(newId);
} catch (InvalidIdException &e) { //better save then sorry } catch (InvalidIdException &e) { //better save then sorry
m_locked = true;
value->setValue(m_selectedNode.id()); value->setValue(m_selectedNode.id());
m_locked = false;
QMessageBox::warning(0, tr("Invalid Id"), e.description()); QMessageBox::warning(0, tr("Invalid Id"), e.description());
} }
} else { //there is already an id, so we refactor } else { //there is already an id, so we refactor
...@@ -381,8 +386,13 @@ void PropertyEditor::changeValue(const QString &propertyName) ...@@ -381,8 +386,13 @@ void PropertyEditor::changeValue(const QString &propertyName)
rewriterView()->renameId(m_selectedNode.id(), newId); rewriterView()->renameId(m_selectedNode.id(), newId);
} }
} else { } else {
m_locked = true;
value->setValue(m_selectedNode.id()); value->setValue(m_selectedNode.id());
QMessageBox::warning(0, tr("Invalid Id"), tr("%1 is an invalid id").arg(newId)); m_locked = false;
if (!m_selectedNode.isValidId(newId))
QMessageBox::warning(0, tr("Invalid Id"), tr("%1 is an invalid id").arg(newId));
else
QMessageBox::warning(0, tr("Invalid Id"), tr("%1 already exists").arg(newId));
} }
return; return;
} }
......
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