QmlDesigner: Fix material name editing issues

Material name field in material browser now ensures that the start
of the string is visible when editing is not focused.

Any click outside the name field will take the focus away from the
field, and name field state is properly updated when focus goes
away for any reason.

Trying to set same name as before is ignored instead of changing the
name to <oldName>1.

Fixes: QDS-8185
Change-Id: I723e3ae312e3e2c4ce8a95a3b05effcee2bae328
Reviewed-by: Mahmoud Badri <mahmoud.badri@qt.io>
This commit is contained in:
Miikka Heikkinen
2022-11-08 13:02:06 +02:00
parent 3f2c3324fd
commit d9d4d1829a
3 changed files with 27 additions and 3 deletions

View File

@@ -35,6 +35,17 @@ Item {
searchBox.clear(); searchBox.clear();
} }
MouseArea {
id: focusGrabber
anchors.fill: parent
acceptedButtons: Qt.LeftButton | Qt.RightButton
onPressed: (mouse) => {
forceActiveFocus() // Steal focus from name edit
mouse.accepted = false
}
z: 1
}
MouseArea { MouseArea {
id: rootMouseArea id: rootMouseArea

View File

@@ -23,6 +23,7 @@ Rectangle {
matName.readOnly = false matName.readOnly = false
matName.selectAll() matName.selectAll()
matName.forceActiveFocus() matName.forceActiveFocus()
matName.ensureVisible(matName.text.length)
nameMouseArea.enabled = false nameMouseArea.enabled = false
} }
@@ -31,10 +32,8 @@ Rectangle {
if (matName.readOnly) if (matName.readOnly)
return; return;
matName.readOnly = true
nameMouseArea.enabled = true
materialBrowserModel.renameMaterial(index, matName.text); materialBrowserModel.renameMaterial(index, matName.text);
mouseArea.forceActiveFocus()
} }
border.width: materialBrowserModel.selectedIndex === index ? 1 : 0 border.width: materialBrowserModel.selectedIndex === index ? 1 : 0
@@ -102,6 +101,16 @@ Rectangle {
onEditingFinished: root.commitRename() onEditingFinished: root.commitRename()
onActiveFocusChanged: {
if (!activeFocus) {
matName.readOnly = true
nameMouseArea.enabled = true
ensureVisible(0)
}
}
Component.onCompleted: ensureVisible(0)
MouseArea { MouseArea {
id: nameMouseArea id: nameMouseArea

View File

@@ -998,6 +998,10 @@ void MaterialEditorView::renameMaterial(ModelNode &material, const QString &newN
{ {
QTC_ASSERT(material.isValid(), return); QTC_ASSERT(material.isValid(), return);
QVariant objName = material.variantProperty("objectName").value();
if (objName.isValid() && objName.toString() == newName)
return;
executeInTransaction("MaterialEditorView:renameMaterial", [&] { executeInTransaction("MaterialEditorView:renameMaterial", [&] {
material.setIdWithRefactoring(model()->generateIdFromName(newName, "material")); material.setIdWithRefactoring(model()->generateIdFromName(newName, "material"));