Skip to content

chore: use another QTranslator::load overload to tidy code#318

Merged
deepin-bot[bot] merged 1 commit intolinuxdeepin:masterfrom
BLumia:qtranslator-load
Jun 4, 2025
Merged

chore: use another QTranslator::load overload to tidy code#318
deepin-bot[bot] merged 1 commit intolinuxdeepin:masterfrom
BLumia:qtranslator-load

Conversation

@BLumia
Copy link
Copy Markdown
Member

@BLumia BLumia commented Jun 4, 2025

使用另一个 QTranslator::load() 重载来使代码更简洁,并潜在的支持 QLocale::uiLanguages().

@BLumia BLumia requested a review from 18202781743 June 4, 2025 07:23
deepin-ci-robot added a commit to linuxdeepin/dtk6gui that referenced this pull request Jun 4, 2025
Synchronize source files from linuxdeepin/dtkgui.

Source-pull-request: linuxdeepin/dtkgui#318
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jun 4, 2025

  • 敏感词检查失败, 检测到1个文件存在敏感词
详情
{
    "src/kernel/dguiapplicationhelper.cpp": [
        {
            "line": "    QString socket_key = \"_d_dtk_single_instance_\";",
            "line_number": 1468,
            "rule": "S106",
            "reason": "Var naming | 2ad926d35b"
        }
    ]
}

@BLumia BLumia force-pushed the qtranslator-load branch from e95cacf to 368853e Compare June 4, 2025 07:57
deepin-ci-robot added a commit to linuxdeepin/dtk6gui that referenced this pull request Jun 4, 2025
Synchronize source files from linuxdeepin/dtkgui.

Source-pull-request: linuxdeepin/dtkgui#318
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jun 4, 2025

  • 敏感词检查失败, 检测到1个文件存在敏感词
详情
{
    "src/kernel/dguiapplicationhelper.cpp": [
        {
            "line": "    QString socket_key = \"_d_dtk_single_instance_\";",
            "line_number": 1468,
            "rule": "S106",
            "reason": "Var naming | 2ad926d35b"
        }
    ]
}

@BLumia BLumia force-pushed the qtranslator-load branch from 368853e to ffc91c2 Compare June 4, 2025 08:49
deepin-ci-robot added a commit to linuxdeepin/dtk6gui that referenced this pull request Jun 4, 2025
Synchronize source files from linuxdeepin/dtkgui.

Source-pull-request: linuxdeepin/dtkgui#318
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jun 4, 2025

  • 敏感词检查失败, 检测到1个文件存在敏感词
详情
{
    "src/kernel/dguiapplicationhelper.cpp": [
        {
            "line": "    QString socket_key = \"_d_dtk_single_instance_\";",
            "line_number": 1468,
            "rule": "S106",
            "reason": "Var naming | 2ad926d35b"
        }
    ]
}

@BLumia BLumia force-pushed the qtranslator-load branch from ffc91c2 to cdfe9e7 Compare June 4, 2025 09:01
deepin-ci-robot added a commit to linuxdeepin/dtk6gui that referenced this pull request Jun 4, 2025
Synchronize source files from linuxdeepin/dtkgui.

Source-pull-request: linuxdeepin/dtkgui#318
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jun 4, 2025

  • 敏感词检查失败, 检测到1个文件存在敏感词
详情
{
    "src/kernel/dguiapplicationhelper.cpp": [
        {
            "line": "    QString socket_key = \"_d_dtk_single_instance_\";",
            "line_number": 1468,
            "rule": "S106",
            "reason": "Var naming | 2ad926d35b"
        }
    ]
}

Comment thread src/kernel/dguiapplicationhelper.cpp Outdated
使用另一个 QTranslator::load 重载来使代码更简洁,并潜在的支持
QLocale::uiLanguages().

并且添加了一个额外的接口来方便其他项目更方便的调用.

Log:
@BLumia BLumia force-pushed the qtranslator-load branch from cdfe9e7 to 90a3818 Compare June 4, 2025 09:24
deepin-ci-robot added a commit to linuxdeepin/dtk6gui that referenced this pull request Jun 4, 2025
Synchronize source files from linuxdeepin/dtkgui.

Source-pull-request: linuxdeepin/dtkgui#318
@deepin-ci-robot
Copy link
Copy Markdown
Contributor

deepin pr auto review

代码审查意见:

  1. 代码重复

    • loadTranslator函数中,translateDirs函数被多次调用,可以考虑将其结果缓存起来,避免重复计算。
  2. 错误处理

    • loadTranslator函数中,如果加载翻译文件失败,应该记录错误信息,而不是简单地删除translator对象。可以考虑使用QScopedPointer来自动管理translator的生命周期。
  3. 日志信息

    • loadTranslator函数中,当找不到翻译文件时,应该记录更详细的错误信息,包括尝试加载的文件路径和目录。
  4. 代码可读性

    • loadTranslator函数中,对于localeFallback的处理逻辑可以拆分成更小的函数,以提高代码的可读性和可维护性。
  5. 资源管理

    • loadTranslator函数中,当加载翻译文件失败时,应该释放已经创建的translator对象,避免内存泄漏。
  6. 参数默认值

    • loadTranslator函数中,localeFallback参数的默认值应该使用std::optional或其他方式来表示,而不是直接使用QList<QLocale>() << QLocale::system(),这样可以更清晰地表达参数的默认行为。
  7. 宏定义

    • loadTranslator函数中,QT_STRINGIFY宏的使用应该确保宏定义在所有使用它的地方都一致,避免潜在的编译错误。
  8. 代码风格

    • loadTranslator函数中,对于for循环的缩进和空格使用应该保持一致,以提高代码的可读性。

综上所述,代码在性能、错误处理、可读性和资源管理方面存在一些改进空间,建议进行相应的优化和重构。

@BLumia BLumia requested a review from 18202781743 June 4, 2025 09:25
@deepin-ci-robot
Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: 18202781743, BLumia

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

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jun 4, 2025

  • 敏感词检查失败, 检测到1个文件存在敏感词
详情
{
    "src/kernel/dguiapplicationhelper.cpp": [
        {
            "line": "    QString socket_key = \"_d_dtk_single_instance_\";",
            "line_number": 1468,
            "rule": "S106",
            "reason": "Var naming | 2ad926d35b"
        }
    ]
}

@18202781743
Copy link
Copy Markdown
Contributor

/forcemerge

@deepin-bot
Copy link
Copy Markdown
Contributor

deepin-bot Bot commented Jun 4, 2025

This pr force merged! (status: blocked)

@deepin-bot deepin-bot Bot merged commit 1f44c47 into linuxdeepin:master Jun 4, 2025
20 of 24 checks passed
18202781743 pushed a commit to linuxdeepin/dtk6gui that referenced this pull request Jun 4, 2025
Synchronize source files from linuxdeepin/dtkgui.

Source-pull-request: linuxdeepin/dtkgui#318
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