Commit 155296b0 authored by Christiaan Janssen's avatar Christiaan Janssen
Browse files

QmlDesigner.StatesEditor: Showing message box when wrong state name is entered

parent ac030f6d
......@@ -31,6 +31,7 @@
#include "stateseditorview.h"
#include <QtCore/QDebug>
#include <QMessageBox>
enum {
debug = false
......@@ -118,10 +119,14 @@ void StatesEditorModel::renameState(int i, const QString &newName)
Q_ASSERT(i > 0 && i < m_stateNames.count());
if (m_stateNames[i] != newName) {
m_stateNames.replace(i, newName);
m_statesView->renameState(i,newName);
if (m_stateNames.contains(newName) || newName.isEmpty()) {
QMessageBox::warning(0, tr("Invalid state name"), newName.isEmpty()?tr("The empty string as a name is reserved for the base state."):tr("Name already used in another state"));
} else {
m_stateNames.replace(i, newName);
m_statesView->renameState(i,newName);
emit dataChanged(createIndex(i, 0), createIndex(i, 0));
emit dataChanged(createIndex(i, 0), createIndex(i, 0));
}
}
}
......
......@@ -360,9 +360,10 @@ Rectangle {
border.color:"#4f4f4f"
radius:4
function unFocus() {
if (visible)
if (visible) {
visible=false;
statesEditorModel.renameState(index,stateNameInput.text);
visible=false;
}
}
// There is no QFontMetrics equivalent in QML
......@@ -399,8 +400,10 @@ Rectangle {
x = -cM;
}
onAccepted: {
statesEditorModel.renameState(index,text);
stateNameEditor.visible=false;
if (stateNameEditor.visible) {
stateNameEditor.visible=false;
statesEditorModel.renameState(index,text);
}
}
}
}
......
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