Skip to content

fix: use dynamic integer range from fcitx5 config properties#143

Merged
deepin-bot[bot] merged 1 commit intolinuxdeepin:masterfrom
wyu71:master
Apr 17, 2026
Merged

fix: use dynamic integer range from fcitx5 config properties#143
deepin-bot[bot] merged 1 commit intolinuxdeepin:masterfrom
wyu71:master

Conversation

@wyu71
Copy link
Copy Markdown
Contributor

@wyu71 wyu71 commented Apr 17, 2026

Pass IntMax/IntMin properties for Integer type options to QML SpinBox, enable editable input and set fixed width to prevent layout stretching.

将Integer类型选项的IntMax/IntMin属性传递到QML SpinBox,启用可编辑输入并设置固定宽度防止布局拉伸。

Log: SpinBox支持动态整数范围和可编辑输入
PMS: BUG-357563
Influence: Integer类型配置项的SpinBox现在使用fcitx5配置中定义的实际范围,支持手动输入数值。

Summary by Sourcery

Use fcitx5 Integer option metadata to define dynamic ranges for SpinBox-based integer configuration entries and allow direct value editing in the config UI.

New Features:

  • Support dynamic integer min/max ranges on SpinBox controls based on fcitx5 IntMin/IntMax properties.
  • Enable editable text input for integer SpinBox configuration fields.

Bug Fixes:

  • Ensure integer configuration SpinBoxes respect the actual fcitx5-defined bounds instead of using hardcoded defaults.

Enhancements:

  • Adjust SpinBox width to a fixed larger size to avoid layout stretching while accommodating editable input.

@sourcery-ai
Copy link
Copy Markdown

sourcery-ai Bot commented Apr 17, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Propagates fcitx5 Integer option IntMin/IntMax properties through the config proxy into the QML SpinBox, and updates the SpinBox to be editable, slightly wider, and to respect a dynamic integer range with sensible fallbacks.

Sequence diagram for Integer option range propagation from fcitx5 to QML SpinBox

sequenceDiagram
    actor User
    participant DetailConfigItem_qml
    participant Fcitx5ConfigProxy
    participant Fcitx5

    User->>DetailConfigItem_qml: Open Integer config item UI
    DetailConfigItem_qml->>Fcitx5ConfigProxy: globalConfigOptions(type, allowInputMethodOverride)
    Fcitx5ConfigProxy->>Fcitx5: Request config options
    Fcitx5-->>Fcitx5ConfigProxy: Option data with properties including IntMin, IntMax
    Fcitx5ConfigProxy->>Fcitx5ConfigProxy: Build item QVariantMap
    Fcitx5ConfigProxy->>Fcitx5ConfigProxy: If type Integer, copy IntMin to intMin and IntMax to intMax
    Fcitx5ConfigProxy-->>DetailConfigItem_qml: List of options including intMin, intMax
    DetailConfigItem_qml->>DetailConfigItem_qml: Bind SpinBox.from to modelData.intMin or 0
    DetailConfigItem_qml->>DetailConfigItem_qml: Bind SpinBox.to to modelData.intMax or 9999

    User->>DetailConfigItem_qml: Edit SpinBox value (within [from, to])
    DetailConfigItem_qml->>Fcitx5ConfigProxy: setValue(section, name, newValue)
    Fcitx5ConfigProxy->>Fcitx5: Apply updated Integer config
    Fcitx5-->>User: Integer option updated with enforced range
Loading

Class diagram for Fcitx5ConfigProxy and Integer config option item structure

classDiagram
    class Fcitx5ConfigProxy {
        +QVariantList globalConfigOptions(QString type, bool allowInputMethodOverride)
        +void setValue(QString section, QString name, QVariant value)
    }

    class ConfigOptionItem {
        +QString type
        +QVariant value
        +int intMin
        +int intMax
    }

    Fcitx5ConfigProxy "1" --> "*" ConfigOptionItem : builds_items_with_intMin_intMax_for_Integer_type
Loading

File-Level Changes

Change Details Files
Expose IntMin/IntMax for Integer options from the fcitx5 config proxy to QML models.
  • When building the config item map for each option, detect Integer-typed options.
  • If Integer type, read IntMax and IntMin from the properties map when present.
  • Store these values as intMax/intMin fields on the item so they are available in the QML model.
src/dcc-fcitx5configtool/operation/fcitx5configproxy.cpp
Update the QML SpinBox for Integer options to support editable input and dynamic range.
  • Enable editable input on the SpinBox so users can type values directly.
  • Increase the SpinBox width and implicitWidth to 75 to accommodate typed values and avoid layout stretching.
  • Bind the SpinBox from/to properties to intMin/intMax coming from the model, with default fallbacks when undefined.
  • Continue to initialize the SpinBox value from the model’s value and propagate onValueChanged via fcitx5ConfigProxy.setValue.
src/dcc-fcitx5configtool/qml/DetailConfigItem.qml

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Copy Markdown

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

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

Hey - I've found 1 issue, and left some high level feedback:

  • Consider avoiding the hardcoded default range (0–9999) in the SpinBox and instead deriving a safer fallback (e.g., based on the current value or a shared constant) to avoid silently clamping valid existing values when IntMin/IntMax are not provided.
  • It may be worth validating that intMin is not greater than intMax when reading the Integer properties and handling any inconsistent configuration (e.g., by swapping or ignoring the bounds) to prevent unexpected SpinBox behavior.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Consider avoiding the hardcoded default range (0–9999) in the SpinBox and instead deriving a safer fallback (e.g., based on the current value or a shared constant) to avoid silently clamping valid existing values when IntMin/IntMax are not provided.
- It may be worth validating that intMin is not greater than intMax when reading the Integer properties and handling any inconsistent configuration (e.g., by swapping or ignoring the bounds) to prevent unexpected SpinBox behavior.

## Individual Comments

### Comment 1
<location path="src/dcc-fcitx5configtool/qml/DetailConfigItem.qml" line_range="118-119" />
<code_context>
+                                editable: true
+                                width: 75
+                                implicitWidth: 75
+                                from: modelData.intMin !== undefined ? modelData.intMin : 0
+                                to: modelData.intMax !== undefined ? modelData.intMax : 9999
                                 value: parseInt(modelData.value)
                                 onValueChanged: {
</code_context>
<issue_to_address>
**suggestion (bug_risk):** Hard-coded default range 0–9999 may not match actual valid range for all integer options.

If `IntMin`/`IntMax` are missing, defaulting to `[0, 9999]` can prevent valid negative or large values and silently clamp user input. Consider either not constraining the SpinBox when no range is defined, or using a more permissive default that aligns with the config semantics.

```suggestion
                                from: modelData.intMin !== undefined ? modelData.intMin : -2147483648
                                to: modelData.intMax !== undefined ? modelData.intMax : 2147483647
```
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment on lines +118 to +119
from: modelData.intMin !== undefined ? modelData.intMin : 0
to: modelData.intMax !== undefined ? modelData.intMax : 9999
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

suggestion (bug_risk): Hard-coded default range 0–9999 may not match actual valid range for all integer options.

If IntMin/IntMax are missing, defaulting to [0, 9999] can prevent valid negative or large values and silently clamp user input. Consider either not constraining the SpinBox when no range is defined, or using a more permissive default that aligns with the config semantics.

Suggested change
from: modelData.intMin !== undefined ? modelData.intMin : 0
to: modelData.intMax !== undefined ? modelData.intMax : 9999
from: modelData.intMin !== undefined ? modelData.intMin : -2147483648
to: modelData.intMax !== undefined ? modelData.intMax : 2147483647

lzwind
lzwind previously approved these changes Apr 17, 2026
Pass IntMax/IntMin properties for Integer type options to QML SpinBox,
enable editable input and set fixed width to prevent layout stretching.

将Integer类型选项的IntMax/IntMin属性传递到QML SpinBox,启用可编辑输入并设置固定宽度防止布局拉伸。

Log: SpinBox支持动态整数范围和可编辑输入
PMS: BUG-357563
Influence: Integer类型配置项的SpinBox现在使用fcitx5配置中定义的实际范围,支持手动输入数值。
@deepin-ci-robot
Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: lzwind, wyu71

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@wyu71
Copy link
Copy Markdown
Contributor Author

wyu71 commented Apr 17, 2026

/forcemerge

@deepin-ci-robot
Copy link
Copy Markdown

deepin pr auto review

这段代码的diff主要做了两处修改:

  1. 修改了版权年份声明
  2. 为整数类型的配置项添加了最小值和最大值的处理逻辑

下面是对代码的详细审查和改进建议:

1. 语法逻辑审查

优点:

  • 新增的整数范围检查逻辑基本正确,能够处理配置中的IntMin和IntMax属性
  • 使用了toInt(&ok)进行安全的类型转换
  • 提供了合理的默认值(0和9999)

问题与改进:

// 当前代码
if (option.type() == "Integer") {
    bool ok = false;
    int maxVal = properties.contains("IntMax") ? properties["IntMax"].toInt(&ok) : 9999;
    item["intMax"] = ok ? maxVal : 9999;
    int minVal = properties.contains("IntMin") ? properties["IntMin"].toInt(&ok) : 0;
    item["intMin"] = ok ? minVal : 0;
}

改进建议:

  1. ok变量在第二次使用时没有重置,可能导致逻辑错误
  2. 应该检查minVal是否小于maxVal
  3. 常量值应该定义为类成员或命名常量

改进后的代码:

if (option.type() == "Integer") {
    bool ok = false;
    const int DEFAULT_MIN = 0;
    const int DEFAULT_MAX = 9999;
    
    // 处理最大值
    int maxVal = DEFAULT_MAX;
    if (properties.contains("IntMax")) {
        maxVal = properties["IntMax"].toInt(&ok);
        if (!ok) maxVal = DEFAULT_MAX;
    }
    item["intMax"] = maxVal;
    
    // 处理最小值
    int minVal = DEFAULT_MIN;
    if (properties.contains("IntMin")) {
        ok = false;  // 重置ok标志
        minVal = properties["IntMin"].toInt(&ok);
        if (!ok) minVal = DEFAULT_MIN;
    }
    item["intMin"] = minVal;
    
    // 确保最小值不大于最大值
    if (item["intMin"].toInt() > item["intMax"].toInt()) {
        qWarning() << "Invalid integer range: min > max, swapping values";
        int temp = item["intMin"].toInt();
        item["intMin"] = item["intMax"];
        item["intMax"] = temp;
    }
}

2. 代码质量审查

QML部分:

D.SpinBox {
    editable: true
    width: 75
    implicitWidth: 75
    from: modelData.intMin !== undefined ? modelData.intMin : 0
    to: modelData.intMax !== undefined ? modelData.intMax : 9999
    value: parseInt(modelData.value)

改进建议:

  1. 魔法数字应该提取为常量
  2. 应该添加输入验证
  3. 考虑添加stepSize属性以改善用户体验

改进后的QML代码:

D.SpinBox {
    id: spinBox
    editable: true
    width: 75
    implicitWidth: 75
    from: modelData.intMin !== undefined ? modelData.intMin : 0
    to: modelData.intMax !== undefined ? modelData.intMax : 9999
    value: parseInt(modelData.value) || 0
    stepSize: 1
    
    validator: IntValidator {
        bottom: spinBox.from
        top: spinBox.to
    }
    
    onValueChanged: {
        if (value >= from && value <= to) {
            dccData.fcitx5ConfigProxy.setValue(...)
        }
    }
}

3. 代码性能审查

  1. 类型转换优化:当前代码对同一个属性可能进行多次类型转换,可以缓存结果
  2. 字符串比较option.type() == "Integer"每次都会创建临时字符串,可以考虑使用枚举类型

4. 代码安全审查

  1. 输入验证

    • 应该验证modelData.value是否为有效整数
    • 应该确保min和max在合理范围内
  2. 整数溢出

    • 当前没有检查转换后的值是否在int范围内
    • 建议添加边界检查
  3. 空指针检查

    • 应该确保modelData不为null

安全改进示例:

if (option.type() == "Integer") {
    bool ok = false;
    const int DEFAULT_MIN = 0;
    const int DEFAULT_MAX = 9999;
    
    // 安全地获取最大值
    int maxVal = DEFAULT_MAX;
    if (properties.contains("IntMax")) {
        bool maxOk = false;
        int tempMax = properties["IntMax"].toInt(&maxOk);
        if (maxOk && tempMax >= DEFAULT_MIN && tempMax <= std::numeric_limits<int>::max()) {
            maxVal = tempMax;
        }
    }
    item["intMax"] = maxVal;
    
    // 安全地获取最小值
    int minVal = DEFAULT_MIN;
    if (properties.contains("IntMin")) {
        bool minOk = false;
        int tempMin = properties["IntMin"].toInt(&minOk);
        if (minOk && tempMin >= std::numeric_limits<int>::min() && tempMin <= DEFAULT_MAX) {
            minVal = tempMin;
        }
    }
    item["intMin"] = minVal;
    
    // 确保范围有效
    if (minVal > maxVal) {
        qWarning() << "Invalid integer range, using defaults";
        item["intMin"] = DEFAULT_MIN;
        item["intMax"] = DEFAULT_MAX;
    }
}

5. 其他建议

  1. 日志记录:添加适当的日志记录,便于调试和问题追踪
  2. 单元测试:为新增的整数范围处理逻辑编写单元测试
  3. 文档注释:为新增的代码添加详细的文档注释
  4. 国际化:如果需要支持多语言,确保错误消息可以被翻译

总结来说,这段代码的基本功能是正确的,但在错误处理、边界条件检查和代码健壮性方面还有改进空间。建议采纳上述改进建议以提高代码质量和安全性。

@deepin-bot
Copy link
Copy Markdown

deepin-bot Bot commented Apr 17, 2026

This pr force merged! (status: blocked)

@deepin-bot deepin-bot Bot merged commit 37bd242 into linuxdeepin:master Apr 17, 2026
12 of 14 checks passed
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.

3 participants