From bfb4b10dce030b30071689b8563ab1ac8b65bc25 Mon Sep 17 00:00:00 2001 From: zhanghongyuan Date: Tue, 28 Apr 2026 09:22:17 +0800 Subject: [PATCH] fix(info-dialog): auto-save filename on focus loss MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add focus handling to property delegates and auto-save filename when input loses focus, preventing data loss when clicking other items. 为属性委托添加焦点处理,输入框失去焦点时自动保存文件名, 防止点击其他项时数据丢失。 Log: 修复信息对话框文件名编辑失去焦点时自动保存 PMS: BUG-323761 Influence: 修复文件名编辑功能,用户在信息对话框中编辑文件名后点击其他区域时,会自动保存文件名,避免数据丢失。 --- .gitignore | 1 + .../PropertyActionItemDelegate.qml | 50 ++++++++++++++++++- .../PropertyItemDelegate.qml | 14 +++++- 3 files changed, 62 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index d383427ab..374fdf436 100644 --- a/.gitignore +++ b/.gitignore @@ -13,6 +13,7 @@ *.a build*/ +obj-x86_64-linux-gnu/ include*/ *.txt.user* diff --git a/src/qml/InformationDialog/PropertyActionItemDelegate.qml b/src/qml/InformationDialog/PropertyActionItemDelegate.qml index 386f45d61..7382b7502 100644 --- a/src/qml/InformationDialog/PropertyActionItemDelegate.qml +++ b/src/qml/InformationDialog/PropertyActionItemDelegate.qml @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd. +// SPDX-FileCopyrightText: 2023 - 2026 UnionTech Software Technology Co., Ltd. // // SPDX-License-Identifier: GPL-3.0-or-later @@ -39,6 +39,9 @@ Control { } property string title + // 允许组件接收焦点(用于转移焦点) + focus: true + signal clicked function dealShowPicLabelClick() { @@ -56,11 +59,27 @@ Control { } } - // 复位当前属性编辑组件,关闭编辑框 + // 复位当前属性编辑组件,关闭编辑框(不保存) function reset() { showPicLabel.visible = true; } + // 提交更改并关闭编辑框(保存文件名) + function commitAndClose() { + if (!showPicLabel.visible) { + var name = nameedit.text; + if (!IV.FileControl.isShowToolTip(IV.GControl.currentSource, name) && name.length > 0) { + IV.FileControl.slotFileReName(name, IV.GControl.currentSource); + } + showPicLabel.visible = true; + } + } + + // 检查是否处于编辑状态 + function isEditing() { + return !showPicLabel.visible; + } + bottomPadding: 4 leftPadding: 10 rightPadding: 10 @@ -116,6 +135,33 @@ Control { } } + // 焦点变化时处理 - 失去焦点时保存文件名 + onActiveFocusChanged: { + // 失去焦点且输入框可见时,保存文件名 + if (!activeFocus && visible && !showPicLabel.visible) { + // 延迟执行,避免与其他焦点事件冲突 + commitAndCloseTimer.restart(); + } + } + + // 失去焦点时保存文件名(备用方案) + onEditingFinished: { + // 只有当输入框可见时才处理(避免在 reset 时触发) + if (visible && !showPicLabel.visible) { + dealShowPicLabelClick(); + } + } + + Timer { + id: commitAndCloseTimer + interval: 10 + onTriggered: { + if (!nameedit.activeFocus && nameedit.visible && !showPicLabel.visible) { + dealShowPicLabelClick(); + } + } + } + anchors { leftMargin: 10 topMargin: 5 diff --git a/src/qml/InformationDialog/PropertyItemDelegate.qml b/src/qml/InformationDialog/PropertyItemDelegate.qml index b05b9d558..b7ebf41ad 100644 --- a/src/qml/InformationDialog/PropertyItemDelegate.qml +++ b/src/qml/InformationDialog/PropertyItemDelegate.qml @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd. +// SPDX-FileCopyrightText: 2023 - 2026 UnionTech Software Technology Co., Ltd. // // SPDX-License-Identifier: GPL-3.0-or-later @@ -42,6 +42,18 @@ Control { signal clicked + // 允许接收焦点,点击时可以转移其他元素的焦点 + focus: true + + // 点击时获取焦点,使用 forceActiveFocus 确保能跨焦点作用域抢走焦点 + MouseArea { + anchors.fill: parent + onClicked: { + control.forceActiveFocus(); + } + cursorShape: Qt.ArrowCursor + } + bottomPadding: 4 implicitWidth: contrlImplicitWidth leftPadding: 10