Skip to content

Conversation

@JWWTSL
Copy link
Contributor

@JWWTSL JWWTSL commented Oct 30, 2025

log: The calculator's regional format is currently out of sync with the Control Center's regional settings. This causes users in regions like Portuguese overseas territories to see a comma instead of a period as the thousands separator when using the calculator.

task: https://pms.uniontech.com/story-view-39605.html

Summary by Sourcery

Synchronize calculator formatting with system regional settings by retrieving decimal and grouping symbols from Control Center, updating all relevant UI components and formatting logic to use dynamic separators, and bumping the package version.

New Features:

  • Add Settings methods to fetch system decimal and digit grouping symbols from Control Center via D-Bus with QLocale fallback

Enhancements:

  • Refactor numeric input, formatting, and parsing across ExpressionBar, SciExpressionBar, InputEdit, MemoryWidget, SimpleListModel, and Utils to normalize and restore locale-specific decimal and grouping separators using placeholder conversion

Build:

  • Bump application version to 6.5.28.1 in multiple linglong.yaml packaging files

@github-actions
Copy link

TAG Bot

TAG: 6.5.28
EXISTED: no
DISTRIBUTION: unstable

@sourcery-ai
Copy link

sourcery-ai bot commented Oct 30, 2025

Reviewer's Guide

This PR adds system-wide regional format synchronization by fetching decimal and grouping symbols from the Control Center (via D-Bus with QLocale fallback) and updating all calculator components to use those symbols instead of hard-coded "." and "," separators.

Sequence diagram for fetching regional format symbols from Control Center

sequenceDiagram
    participant Calculator
    participant Settings
    participant D_Bus_org_deepin_dde_Format1 as D-Bus_org.deepin.dde.Format1
    participant QLocale
    Calculator->>Settings: getSystemDecimalSymbol()
    Settings->>D_Bus_org_deepin_dde_Format1: Request DecimalSymbol
    alt D-Bus returns value
        D_Bus_org_deepin_dde_Format1-->>Settings: DecimalSymbol
        Settings-->>Calculator: DecimalSymbol
    else D-Bus fails
        Settings->>QLocale: Get decimalPoint()
        QLocale-->>Settings: decimalPoint
        Settings-->>Calculator: decimalPoint
    end
    Calculator->>Settings: getSystemDigitGroupingSymbol()
    Settings->>D_Bus_org_deepin_dde_Format1: Request DigitGroupingSymbol
    alt D-Bus returns value
        D_Bus_org_deepin_dde_Format1-->>Settings: DigitGroupingSymbol
        Settings-->>Calculator: DigitGroupingSymbol
    else D-Bus fails
        Settings->>QLocale: Get groupSeparator()
        QLocale-->>Settings: groupSeparator
        Settings-->>Calculator: groupSeparator
    end
Loading

Class diagram for Settings and regional format symbol access

classDiagram
    class Settings {
        +QString getSystemDecimalSymbol() const
        +QString getSystemDigitGroupingSymbol() const
        +bool getSystemDigitGrouping() const
    }
    Settings <.. Calculator : uses
    Settings <.. InputEdit : uses
    Settings <.. ExpressionBar : uses
    Settings <.. SciExpressionBar : uses
    Settings <.. ProgrammerKeypad : uses
    Settings <.. ScientificKeyPad : uses
    Settings <.. BasicKeypad : uses
    Settings <.. Utils : uses
Loading

Class diagram for InputEdit normalization and filtering

classDiagram
    class InputEdit {
        +void handleTextChanged(const QString &text)
        +QString pointFaultTolerance(const QString &text)
        +QString formatExpression(const int &probase, const QString &text)
        -void normalizeInput(const QString &text)
    }
    InputEdit <.. Settings : uses
Loading

Class diagram for ExpressionBar and SciExpressionBar format adaptation

classDiagram
    class ExpressionBar {
        +void enterPointEvent()
        +QString formatExpression(const QString &text)
        +QString pointFaultTolerance(const QString &text)
        +void expressionCheck()
    }
    class SciExpressionBar {
        +void enterPointEvent()
        +QString formatExpression(const QString &text)
        +QString pointFaultTolerance(const QString &text)
        +void expressionCheck()
    }
    ExpressionBar <.. Settings : uses
    SciExpressionBar <.. Settings : uses
Loading

Class diagram for keypad classes updating decimal symbol

classDiagram
    class ProgrammerKeypad {
        +void initButtons()
        +void radixChanged(int row)
    }
    class ScientificKeyPad {
        +void initButtons()
    }
    class BasicKeypad {
        +void initButtons()
    }
    ProgrammerKeypad <.. Settings : uses
    ScientificKeyPad <.. Settings : uses
    BasicKeypad <.. Settings : uses
Loading

Class diagram for Utils formatting with regional symbols

classDiagram
    class Utils {
        +QString formatThousandsSeparators(const QString &str)
        +QString formatThousandsSeparatorsPro(const QString &str, const int Base)
    }
    Utils <.. Settings : uses
Loading

File-Level Changes

Change Details Files
New D-Bus based regional format API in Settings
  • Implement getSystemDecimalSymbol(), getSystemDigitGroupingSymbol(), getSystemDigitGrouping() using org.deepin.dde.Format1 D-Bus interface with QLocale fallback
  • Expose these new methods in settings.h
3rdparty/core/settings.cpp
3rdparty/core/settings.h
ExpressionBar and SciExpressionBar adapt to locale symbols
  • Replace hard-coded "."/"," logic in enterPointEvent with system symbols and regex patterns
  • Use placeholders to convert between display and internal formats in formatExpression and pointFaultTolerance
  • Adjust expressionCheck to normalize separators before processing and restore locale symbols on output
src/widgets/expressionbar.cpp
src/widgets/sciexpressionbar.cpp
InputEdit normalizes and filters input by locale
  • Convert locale decimal/group symbols to internal placeholders on text change
  • Use QSignalBlocker to prevent recursive signals on setText
  • Filter allowed characters based on system separators
  • Reapply locale symbols before updating the display
src/widgets/inputedit.cpp
Utils.formatThousandsSeparators uses system settings
  • Fetch decimal, grouping symbols and groupingEnabled from Settings
  • Split exponent/fraction/integer parts and insert groupingSymbol at correct intervals
  • Delegate Pro mode to formatThousandsSeparators for base-10
src/utils.cpp
Keypad UIs synchronize decimal point button text
  • On init and radixChanged, set Key_Point button text to system decimal symbol in ProgrammerKeypad
  • Set decimal button in BasicKeypad and ScientificKeyPad to system symbol
src/control/programmerkeypad.cpp
src/control/basickeypad.cpp
src/control/scientifickeypad.cpp
Other UI formatting functions adopt locale symbols
  • Update MemoryWidget::formatExpression to normalize and restore locale symbols
  • Update SimpleListModel::formatExpression similarly
src/views/memorywidget.cpp
src/views/simplelistmodel.cpp
Version bump for app packaging
  • Increment version to 6.5.28.1 in all linglong.yaml files and debian/changelog
arm64/linglong.yaml
linglong.yaml
loong64/linglong.yaml
sw64/linglong.yaml
debian/changelog

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

@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 there - I've reviewed your changes - here's some feedback:

  • There’s a lot of repeated locale‐normalization logic scattered across files—consider refactoring it into a shared utility to reduce duplication and simplify maintenance.
  • You’re creating a QDBusInterface and querying properties on every call; it would be more efficient to cache the interface or the retrieved symbols rather than re‐instantiating every time.
  • The PR introduces many qInfo()/qDebug() logs; please review and remove or guard any excessive logging before merging to avoid performance and noise issues.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- There’s a lot of repeated locale‐normalization logic scattered across files—consider refactoring it into a shared utility to reduce duplication and simplify maintenance.
- You’re creating a QDBusInterface and querying properties on every call; it would be more efficient to cache the interface or the retrieved symbols rather than re‐instantiating every time.
- The PR introduces many qInfo()/qDebug() logs; please review and remove or guard any excessive logging before merging to avoid performance and noise issues.

## Individual Comments

### Comment 1
<location> `src/widgets/expressionbar.cpp:1009` </location>
<code_context>
+    const auto sys = Settings::instance();
+    const QString decSym = sys->getSystemDecimalSymbol();
+    const QString grpSym = sys->getSystemDigitGroupingSymbol();
+    const QString decimalPlaceholder = QString(QChar(0x1D));
+
+    if (!decSym.isEmpty() && decSym != QLatin1String("."))
</code_context>

<issue_to_address>
**suggestion (bug_risk):** Use of Unicode control characters as placeholders may cause confusion.

Using Unicode control characters as placeholders may cause bugs or display issues if processed or rendered externally. Consider a more explicit placeholder unlikely to conflict with user input or locale settings.

Suggested implementation:

```cpp
    const QString decimalPlaceholder = QStringLiteral("__DECIMAL__");

```

```cpp
    if (!decSym.isEmpty() && decSym != QLatin1String("."))
        t.replace(decSym, decimalPlaceholder);
    if (!grpSym.isEmpty() && grpSym != decSym)
        t.replace(grpSym, "");
    if (!decSym.isEmpty() && decSym != QLatin1String("."))
        t.replace(decimalPlaceholder, QLatin1String("."));

```
</issue_to_address>

### Comment 2
<location> `src/widgets/inputedit.cpp:549` </location>
<code_context>
+    const QString allowedStatic = QString::fromUtf8("+-×÷.,%()/");
+    QString filtered;
+    filtered.reserve(reformatStr.size());
+    for (const QChar &ch : std::as_const(reformatStr)) {
+        if (ch.isDigit() || ch.isLetter() || allowedStatic.contains(ch) || decSym.contains(ch) || grpSym.contains(ch)) {
+            filtered.append(ch);
</code_context>

<issue_to_address>
**issue:** Filtering logic may exclude valid locale-specific symbols.

The current logic may fail for multi-character symbols used in some locales. Please update the filtering to handle such cases or adopt a locale-aware method.
</issue_to_address>

### Comment 3
<location> `3rdparty/core/settings.cpp:405-410` </location>
<code_context>
+QString Settings::getSystemDecimalSymbol() const
+{
+    // 尝试从 D-Bus 获取控制中心设置
+    QDBusInterface interface("org.deepin.dde.Timedate1",
+                             "/org/deepin/dde/Format1",
+                             "org.deepin.dde.Format1",
+                             QDBusConnection::sessionBus());
+    
+    if (interface.isValid()) {
+        QVariant variant = interface.property("DecimalSymbol");
+        QString result = qvariant_cast<QString>(variant);
</code_context>

<issue_to_address>
**suggestion:** No error handling for D-Bus failures or timeouts.

Please add logging or error reporting for D-Bus failures to improve visibility and debugging.
</issue_to_address>

### Comment 4
<location> `src/widgets/expressionbar.cpp:1002` </location>
<code_context>
  */
 QString ExpressionBar::formatExpression(const QString &text)
 {
-    return QString(text)
</code_context>

<issue_to_address>
**issue (complexity):** Consider extracting locale symbol conversion logic into two helper methods to centralize repeated code and improve readability.

Here are a few straightforward extractions that will collapse all of this repeated “get settings → swap in placeholders → strip/insert separators → swap back” logic into two self-documenting routines and make each of your core methods far easier to read and maintain.

1. Add in `expressionbar.h`:
```cpp
private:
    QString toInternalLocale(const QString &text) const;
    QString toDisplayLocale(const QString &text) const;
```

2. In `expressionbar.cpp`, implement them once:
```cpp
QString ExpressionBar::toInternalLocale(const QString &text) const
{
    const auto sys = Settings::instance();
    QString grp = sys->getSystemDigitGroupingSymbol();
    QString dec = sys->getSystemDecimalSymbol();
    // strip grouping, map decimal to '.'
    QString t = text;
    if (!grp.isEmpty() && grp != ",")
        t.replace(grp, "");
    if (!dec.isEmpty() && dec != ".")
        t.replace(dec, ".");
    return t;
}

QString ExpressionBar::toDisplayLocale(const QString &text) const
{
    const auto sys = Settings::instance();
    QString grp = sys->getSystemDigitGroupingSymbol();
    QString dec = sys->getSystemDecimalSymbol();
    QString t = text;
    // first map '.' → placeholder → eventually back to localized decimal
    QChar DEC_PH(0x1D), GRP_PH(0x1C);
    t.replace(dec == "." ? QString() : dec, DEC_PH);
    t.replace(grp == "," ? QString() : grp, GRP_PH);
    t.replace(".", grp.isEmpty() ? "." : grp);
    t.replace(",", dec.isEmpty() ? "." : dec);
    t.replace(DEC_PH, dec.isEmpty() ? "." : dec);
    t.replace(GRP_PH, grp.isEmpty() ? "," : grp);
    return t;
}
```

3. Then simplify each method down to the essentials. For example **formatExpression** becomes:
```cpp
QString ExpressionBar::formatExpression(const QString &text)
{
    // convert locale → internal symbols, strip grouping, then map operators
    QString expr = toInternalLocale(text);
    return expr.replace(QString::fromUtf8("+"), "+")
               .replace(QString::fromUtf8("-"), "-")
               .replace(QString::fromUtf8("×"), "*")
               .replace(QString::fromUtf8("÷"), "/")
               .replace(QString::fromUtf8(","), "");
}
```

And **expressionCheck** roughly:
```cpp
void ExpressionBar::expressionCheck()
{
    QString internal = toInternalLocale(m_inputEdit->text());
    // ... do your fault-tolerance/zero-padding logic on `internal` ...
    QString display = toDisplayLocale(internal);
    m_inputEdit->setText(display);
    // adjust cursor…
}
```

4. In **enterPointEvent**, you can now do:
```cpp
const auto decSym = Settings::instance()->getSystemDecimalSymbol();
const QString dot = decSym.isEmpty() ? "." : decSym;
// …use `toInternalLocale` or `toDisplayLocale` around your insertion logic…
```

By centralizing the locale‐symbol mapping you remove dozens of lines of near‐identical code from each of the four methods, and you keep each method focused on its own core job: inserting a point, fault-tolerance, formatting, or checking.
</issue_to_address>

### Comment 5
<location> `src/widgets/inputedit.cpp:466` </location>
<code_context>
 void InputEdit::handleTextChanged(const QString &text)
 {
     qDebug() << "handleTextChanged called, text:" << text;
</code_context>

<issue_to_address>
**issue (complexity):** Consider refactoring the normalization, symbol-mapping, and filtering logic into dedicated helper functions to simplify handleTextChanged and formatExpression.

Here’s one way to collapse all of that inline normalization/reformatting/filtering into a small set of helpers, then call them from handleTextChanged (and formatExpression).  You keep 100% of the behavior but handleTextChanged becomes a few calls instead of 100+ lines of fiddly `replace()`/loops.

```cpp
// InputFormatter.h
#pragma once

namespace InputFormatter {
    // 1) normalize all locale‐specific symbols to “.” and strip grouping
    QString normalizeLocale(const QString &input);

    // 2) apply your +→+, -→- etc. mappings
    QString sanitizeSymbols(const QString &input);

    // 3) drop any character not in your allowed set
    QString filterAllowed(const QString &input);
}
```

```cpp
// InputFormatter.cpp
#include "InputFormatter.h"
#include "../dsettings.h"

QString InputFormatter::normalizeLocale(const QString &expr) {
    auto sys = Settings::instance();
    QString s = expr;
    const QString dec = sys->getSystemDecimalSymbol();
    const QString grp = sys->getSystemDigitGroupingSymbol();
    const QChar placeholder(0x1D);

    if (!dec.isEmpty() && dec != ".")
        s.replace(dec, placeholder);
    if (!grp.isEmpty() && grp != dec)
        s.remove(grp);
    if (!dec.isEmpty() && dec != ".")
        s.replace(placeholder, ".");
    return s;
}

QString InputFormatter::sanitizeSymbols(const QString &input) {
    static const std::vector<std::pair<QString, QString>> reps = {
        { "+", QString::fromUtf8("+") },
        { "-", QString::fromUtf8("-") },
        { "_", QString::fromUtf8("-") },
        { "*", QString::fromUtf8("×") },
        { QString::fromUtf8("*"), QString::fromUtf8("×") },
        { "X", QString::fromUtf8("×") },
        { QString::fromUtf8("("), "(" },
        { QString::fromUtf8(")"), ")" },
        { QString::fromUtf8("——"), QString::fromUtf8("-") },
        { QString::fromUtf8("%"), "%" }
    };
    QString s = input;
    for (auto &p : reps)
        s.replace(p.first, p.second);
    return s;
}

QString InputFormatter::filterAllowed(const QString &input) {
    auto sys = Settings::instance();
    QString allowed = QString::fromUtf8("+-×÷.,%()/");
    QString dec = sys->getSystemDecimalSymbol();
    QString grp = sys->getSystemDigitGroupingSymbol();

    QString out;
    out.reserve(input.size());
    for (QChar c : input) {
        if (c.isDigit() || c.isLetter()
            || allowed.contains(c)
            || dec.contains(c)
            || grp.contains(c))
        {
            out.append(c);
        }
    }
    return out;
}
```

Then in your handleTextChanged():

```cpp
void InputEdit::handleTextChanged(const QString &text) {
    // … keep the cursor‐/ans‐logic above …
    QString expr = InputFormatter::normalizeLocale(text);
    QString reformatted = (Settings::instance()->programmerBase == 0)
        ? Utils::reformatSeparators(expr)
        : Utils::reformatSeparatorsPro(expr, Settings::instance()->programmerBase);

    reformatted = InputFormatter::sanitizeSymbols(reformatted);
    multipleArithmetic(reformatted);
    reformatted = InputFormatter::filterAllowed(reformatted);

    if (reformatted != text) {
        QSignalBlocker blocker(this);
        setText(reformatted);
    }

    // … rest of cursor positioning, m_oldText, etc. …
}
```

And in formatExpression() you can also just:

```cpp
QString InputEdit::formatExpression(int probase, const QString &text) {
    QString expr = InputFormatter::normalizeLocale(text);
    // strip your UI symbols back to ascii operators:
    expr.replace(QString::fromUtf8("+"), "+")
        .replace(QString::fromUtf8("-"), "-")
        // … etc …
    // then the rest of your base‐conversion switch…
    return expr;
}
```

This pulls all of the localization, symbol-mapping and filtering into three tiny, testable functions and makes both handleTextChanged and formatExpression far shorter and easier to scan.
</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.

const QString grpSym = sys->getSystemDigitGroupingSymbol();
const QString decimalPlaceholder = QString(QChar(0x1D));

if (!decSym.isEmpty() && decSym != QLatin1String("."))
Copy link

Choose a reason for hiding this comment

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

suggestion (bug_risk): Use of Unicode control characters as placeholders may cause confusion.

Using Unicode control characters as placeholders may cause bugs or display issues if processed or rendered externally. Consider a more explicit placeholder unlikely to conflict with user input or locale settings.

Suggested implementation:

    const QString decimalPlaceholder = QStringLiteral("__DECIMAL__");
    if (!decSym.isEmpty() && decSym != QLatin1String("."))
        t.replace(decSym, decimalPlaceholder);
    if (!grpSym.isEmpty() && grpSym != decSym)
        t.replace(grpSym, "");
    if (!decSym.isEmpty() && decSym != QLatin1String("."))
        t.replace(decimalPlaceholder, QLatin1String("."));

const QString allowedStatic = QString::fromUtf8("+-×÷.,%()/");
QString filtered;
filtered.reserve(reformatStr.size());
for (const QChar &ch : std::as_const(reformatStr)) {
Copy link

Choose a reason for hiding this comment

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

issue: Filtering logic may exclude valid locale-specific symbols.

The current logic may fail for multi-character symbols used in some locales. Please update the filtering to handle such cases or adopt a locale-aware method.

@JWWTSL JWWTSL force-pushed the master branch 2 times, most recently from 42244b0 to 3d36edb Compare October 30, 2025 07:45
@github-actions
Copy link

github-actions bot commented Oct 30, 2025

CLA Assistant Lite bot:

如果你是以企业贡献者的身份进行提交,请联系我们签署企业贡献者许可协议
If you submit as corporate contributor, please contact us to sign our Corporate Contributor License Agreement

感谢您的提交,我们非常感谢。 像许多开源项目一样,在接受您的贡献之前,我们要求您签署我们的个人贡献者许可协议。 您只需发布与以下格式相同的评论即可签署个人贡献者许可协议
Thank you for your submission, we really appreciate it. Like many open-source projects, we ask that you sign our Individual Contributor License Agreement before we can accept your contribution. You can sign the Individual Contributor License Agreement by just posting a Pull Request Comment same as the below format.


I have read the CLA Document and I hereby sign the CLA.

You can retrigger this bot by commenting recheck in this Pull Request

log: The calculator's regional format is currently out of sync with the Control Center's regional settings. This causes users in regions like Portuguese overseas territories to see a comma instead of a period as the thousands separator when using the calculator.

task: https://pms.uniontech.com/story-view-39605.html
@deepin-ci-robot
Copy link

deepin pr auto review

我将对这个diff进行详细的代码审查:

  1. 代码结构改进建议:
  • Settings类新增了三个方法来获取系统格式设置,建议将这些方法声明为static const,因为它们只是读取系统设置,不需要修改类状态。
  1. 性能优化建议:
  • 在formatThousandsSeparators函数中,多次调用sys->getSystem*方法,建议将结果缓存到局部变量中。
  • 在多个地方重复了相同的格式转换逻辑,建议提取为公共函数。
  1. 安全性改进建议:
  • DBus接口调用没有添加错误处理,建议添加try-catch块来处理可能的异常。
  • 在处理用户输入时,需要更严格的输入验证,特别是在处理特殊字符时。
  1. 代码质量问题:
  • 在多个文件中重复了相同的本地化处理代码,违反了DRY原则。建议创建一个专门的工具类来处理本地化相关的转换。
  • normalizeSpace lambda函数在getSystemDigitGroupingSymbol中定义,但这个函数可能在其他地方也有用,建议将其提取为独立的工具函数。
  • 代码中使用了大量的QString替换操作,这可能会影响性能,建议考虑使用QRegularExpression或其他更高效的方式。
  1. 具体改进建议:
// 在settings.h中
class Settings {
    // ...
    static QString getSystemDecimalSymbol();
    static QString getSystemDigitGroupingSymbol();
    static bool getSystemDigitGrouping();
    // ...
};

// 创建新的工具类LocaleHelper
class LocaleHelper {
public:
    static QString normalizeGroupingSymbol(const QString &symbol);
    static QString convertToInternalFormat(const QString &input, const QString &decSym, const QString &grpSym);
    static QString convertToDisplayFormat(const QString &input, const QString &decSym, const QString &grpSym);
};

// 在settings.cpp中
QString Settings::getSystemDecimalSymbol()
{
    try {
        QDBusInterface interface("org.deepin.dde.Timedate1",
                                 "/org/deepin/dde/Format1",
                                 "org.deepin.dde.Format1",
                                 QDBusConnection::sessionBus());
        
        if (interface.isValid()) {
            QVariant variant = interface.property("DecimalSymbol");
            QString result = qvariant_cast<QString>(variant);
            if (!result.isEmpty()) {
                return result;
            }
        }
    } catch (const std::exception &e) {
        qWarning() << "Failed to get decimal symbol from D-Bus:" << e.what();
    }
    
    return QLocale().decimalPoint();
}

// 在formatThousandsSeparators中使用缓存
QString Utils::formatThousandsSeparators(const QString &str)
{
    static const auto sys = Settings::instance();
    static const QString decSym = sys->getSystemDecimalSymbol();
    static const QString grpSym = sys->getSystemDigitGroupingSymbol();
    static const bool groupingEnabled = sys->getSystemDigitGrouping();
    
    // 使用缓存的值进行处理...
}
  1. 其他建议:
  • 考虑添加单元测试来验证本地化功能的正确性。
  • 建议添加详细的文档说明,特别是关于本地化处理的部分。
  • 考虑添加配置选项,允许用户覆盖系统默认的本地化设置。

这些改进将使代码更加健壮、可维护,并且性能更好。

@deepin-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

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

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

@JWWTSL
Copy link
Contributor Author

JWWTSL commented Oct 30, 2025

/forcemerge

@deepin-bot
Copy link
Contributor

deepin-bot bot commented Oct 30, 2025

This pr force merged! (status: unstable)

@deepin-bot deepin-bot bot merged commit 6d25f60 into linuxdeepin:master Oct 30, 2025
15 of 18 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