Skip to content

feat: 同时显示ConfigItem配置值和外显值的设置卡#2222

Open
ShadowLemoon wants to merge 2 commits into
mainfrom
feat/value-display-card
Open

feat: 同时显示ConfigItem配置值和外显值的设置卡#2222
ShadowLemoon wants to merge 2 commits into
mainfrom
feat/value-display-card

Conversation

@ShadowLemoon
Copy link
Copy Markdown
Collaborator

@ShadowLemoon ShadowLemoon commented May 4, 2026

Summary by CodeRabbit

新增功能

  • 新增可编辑组合框设置卡片,支持用户自由输入的同时,在右侧实时显示所选项的说明文本,并自动调整布局以优化使用体验

其他改进

  • 优化内部依赖导入结构

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 4, 2026

📝 Walkthrough

演进概览

此PR更新了类型导入并引入了一个新的可编辑组合框设置卡小部件,该小部件在右侧显示标签中显示所选选项的显示文本,同时支持自由文本输入并保持底层值与UI同步。

变更内容

ValueDisplayEditableComboBoxSettingCard 小部件

层级 / 文件 摘要
类型注解支持
deploy/module_manifest.py
collections.abc 导入 Iterable 以支持新小部件的类型注解。
小部件初始化与事件连接
src/one_dragon_qt/widgets/setting_card/value_display_editable_combo_box_setting_card.py (第 15-72 行)
ValueDisplayEditableComboBoxSettingCard 构造函数初始化固定内容、右对齐标签、组合框事件处理器,并同步初始选中项的值与显示标签。
值同步事件处理
src/one_dragon_qt/widgets/setting_card/value_display_editable_combo_box_setting_card.py (第 73-99 行)
实现索引变化、重复激活和文本编辑事件处理,保证底层值与输入字段同步。
显示与布局管理
src/one_dragon_qt/widgets/setting_card/value_display_editable_combo_box_setting_card.py (第 100-185 行)
动态计算组合框最小宽度和文本边距、更新显示标签、确保当前值可见。
数据访问与值处理
src/one_dragon_qt/widgets/setting_card/value_display_editable_combo_box_setting_card.py (第 107-190 行)
覆盖 setValuegetValueset_options_by_list 及内部值应用逻辑,实现文本正规化和选项匹配。

代码审查工作量评估

🎯 3 (中等) | ⏱️ ~20 分钟

兔子的诗

🐰 小兔跳过代码田野
新的小部件闪闪发光,
标签舞动在右侧,
数值与显示齐声唱,
导入有序,布局完美~

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 21.43% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed PR标题准确描述了主要变更:引入一个新的设置卡组件,同时显示ConfigItem的配置值和外显值。
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/value-display-card

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
Review rate limit: 7/8 reviews remaining, refill in 7 minutes and 30 seconds.

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4

🧹 Nitpick comments (2)
src/one_dragon_qt/widgets/setting_card/value_display_editable_combo_box_setting_card.py (2)

36-48: ⚡ Quick win

建议使用 super().__init__(...) 替代显式类名调用

直接调用 EditableComboBoxSettingCard.__init__(self, ...) 绕过了 MRO,在未来引入多重继承时可能产生问题,且不符合 Python 惯用写法。

♻️ 建议改写
-        EditableComboBoxSettingCard.__init__(
-            self,
-            icon=icon,
-            title=title,
-            content=content,
-            icon_size=icon_size,
-            margins=margins,
-            options_enum=options_enum,
-            options_list=options_list,
-            input_placeholder=input_placeholder,
-            tooltip=tooltip,
-            parent=parent,
-        )
+        super().__init__(
+            icon=icon,
+            title=title,
+            content=content,
+            icon_size=icon_size,
+            margins=margins,
+            options_enum=options_enum,
+            options_list=options_list,
+            input_placeholder=input_placeholder,
+            tooltip=tooltip,
+            parent=parent,
+        )
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@src/one_dragon_qt/widgets/setting_card/value_display_editable_combo_box_setting_card.py`
around lines 36 - 48, Replace the explicit base-class constructor call
EditableComboBoxSettingCard.__init__(self, ...) with the standard cooperative
call using super().__init__(...), i.e. invoke super().__init__(icon=icon,
title=title, content=content, icon_size=icon_size, margins=margins,
options_enum=options_enum, options_list=options_list,
input_placeholder=input_placeholder, tooltip=tooltip, parent=parent) inside the
class initializer so the __init__ participates correctly in Python's MRO and
supports future multiple inheritance changes.

100-105: ⚡ Quick win

set_options_by_list 中存在重复的 hasattr 检查

两个连续的 if hasattr(self, 'display_label') 条件完全相同,可合并为一个 if 块。

♻️ 建议改写
     def set_options_by_list(self, options: list[ConfigItem]) -> None:
         super().set_options_by_list(options)
-        if hasattr(self, 'display_label'):
-            self._update_combo_box_minimum_width()
-        if hasattr(self, 'display_label'):
-            self._sync_display_name(self.getValue())
+        if hasattr(self, 'display_label'):
+            self._update_combo_box_minimum_width()
+            self._sync_display_name(self.getValue())
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@src/one_dragon_qt/widgets/setting_card/value_display_editable_combo_box_setting_card.py`
around lines 100 - 105, In set_options_by_list, remove the duplicated
hasattr(self, 'display_label') checks and combine them into a single if block so
both _update_combo_box_minimum_width() and _sync_display_name(self.getValue())
are executed when display_label exists; update the method to call
_update_combo_box_minimum_width() then _sync_display_name(self.getValue())
inside one if and leave the call to super().set_options_by_list(options)
untouched.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In
`@src/one_dragon_qt/widgets/setting_card/value_display_editable_combo_box_setting_card.py`:
- Around line 126-127: getValue currently annotates its return type as object
but it always returns a str because it calls _normalize_value on
combo_box.text().strip(); update the signature of getValue (the method named
getValue) to return str instead of object so the annotation matches the actual
return type from _normalize_value and combo_box.text().strip().
- Line 31: The constructor parameter parent is missing a type annotation; update
the signature (in class ValueDisplayEditableComboBoxSettingCard) from
parent=None to parent: Optional[QWidget] = None (or parent: Optional[QObject] =
None if the class expects a QObject parent), and add the required imports (from
typing import Optional and the appropriate Qt class such as QWidget/QObject) at
the top of the file.
- Around line 23-24: Update the __init__ signature in class
ValueDisplayEditableComboBoxSettingCard to annotate parent as parent: QWidget |
None = None (and import QWidget from your GUI lib) instead of untyped
parent=None; change the return annotation of getValue() to -> str because
_normalize_value always returns a string; and simplify the repeated
hasattr(self, 'display_label') checks around the display_label usage (currently
in the block that initializes/updates the label) by merging them into a single
hasattr check to avoid duplicate conditionals.
- Around line 136-148: _sync_display_name is comparing item.value (which can be
non-string) to value (always a str), causing the match to fail and display_label
to remain empty; update the comparison in _sync_display_name to compare strings
by using str(item.value) == value (or handle None by converting to ''), so the
loop can find the correct item from self._opts_list and set
display_label/text/toolTip and call _update_combo_box_text_margins correctly;
check related places that produce value (like _apply_value, setValue,
_normalize_value) to ensure they still provide a str and keep this string
comparison consistent.

---

Nitpick comments:
In
`@src/one_dragon_qt/widgets/setting_card/value_display_editable_combo_box_setting_card.py`:
- Around line 36-48: Replace the explicit base-class constructor call
EditableComboBoxSettingCard.__init__(self, ...) with the standard cooperative
call using super().__init__(...), i.e. invoke super().__init__(icon=icon,
title=title, content=content, icon_size=icon_size, margins=margins,
options_enum=options_enum, options_list=options_list,
input_placeholder=input_placeholder, tooltip=tooltip, parent=parent) inside the
class initializer so the __init__ participates correctly in Python's MRO and
supports future multiple inheritance changes.
- Around line 100-105: In set_options_by_list, remove the duplicated
hasattr(self, 'display_label') checks and combine them into a single if block so
both _update_combo_box_minimum_width() and _sync_display_name(self.getValue())
are executed when display_label exists; update the method to call
_update_combo_box_minimum_width() then _sync_display_name(self.getValue())
inside one if and leave the call to super().set_options_by_list(options)
untouched.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: ac16b018-5659-4efd-87a5-4ca2ed65cbdc

📥 Commits

Reviewing files that changed from the base of the PR and between cd5b4b9 and 9deea18.

📒 Files selected for processing (2)
  • deploy/module_manifest.py
  • src/one_dragon_qt/widgets/setting_card/value_display_editable_combo_box_setting_card.py

Comment on lines +136 to +148
def _sync_display_name(self, value: object) -> None:
if not hasattr(self, 'display_label'):
return

display = ''
for item in self._opts_list:
if item.value == value:
display = item.ui_text
break
self.display_label.setText(display)
self.display_label.setToolTip(display)
self.display_label.setVisible(bool(display))
self._update_combo_box_text_margins(display)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# 1. 确认 ConfigItem.value 的类型定义
ast-grep --pattern 'class ConfigItem {
  $$$
}'

# 2. 确认父类如何向 combo_box 存储 item data
rg -n "addItem\|setItemData\|itemData" --type py -C 3 src/one_dragon_qt/widgets/setting_card/

# 3. 查看 _opts_list 的构建方式
rg -n "_opts_list" --type py -C 3 src/one_dragon_qt/widgets/setting_card/

Repository: OneDragon-Anything/ZenlessZoneZero-OneDragon

Length of output: 12240


🏁 Script executed:

#!/bin/bash
# Find ConfigItem class definition
rg -n "class ConfigItem" --type py -A 10

Repository: OneDragon-Anything/ZenlessZoneZero-OneDragon

Length of output: 942


🏁 Script executed:

#!/bin/bash
# Check the target file's _apply_value, setValue, and _on_text_changed methods
cat -n src/one_dragon_qt/widgets/setting_card/value_display_editable_combo_box_setting_card.py | head -200

Repository: OneDragon-Anything/ZenlessZoneZero-OneDragon

Length of output: 8223


🏁 Script executed:

#!/bin/bash
# Check the parent class EditableComboBoxSettingCard for _apply_value
rg -n "_apply_value\|def setValue" src/one_dragon_qt/widgets/setting_card/editable_combo_box_setting_card.py --type py -B 2 -A 8

Repository: OneDragon-Anything/ZenlessZoneZero-OneDragon

Length of output: 70


_sync_display_name 的类型比较导致显示标签为空

方法接收的 value 参数始终为 str 类型(来自 _apply_valuestr(value) 转换、setValuestr(value) 转换、以及 _normalize_value 的返回值),但第 142 行比较 item.value == value 时,item.valueAny 类型(可能是 intEnum 等)。当 item.value 非字符串时,等式永远不成立,外显标签将始终为空。

改为 str(item.value) == value

🛠️ 修复方案
     def _sync_display_name(self, value: object) -> None:
         if not hasattr(self, 'display_label'):
             return

         display = ''
         for item in self._opts_list:
-            if item.value == value:
+            if str(item.value) == value:
                 display = item.ui_text
                 break
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@src/one_dragon_qt/widgets/setting_card/value_display_editable_combo_box_setting_card.py`
around lines 136 - 148, _sync_display_name is comparing item.value (which can be
non-string) to value (always a str), causing the match to fail and display_label
to remain empty; update the comparison in _sync_display_name to compare strings
by using str(item.value) == value (or handle None by converting to ''), so the
loop can find the correct item from self._opts_list and set
display_label/text/toolTip and call _update_combo_box_text_margins correctly;
check related places that produce value (like _apply_value, setValue,
_normalize_value) to ensure they still provide a str and keep this string
comparison consistent.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant