Skip to content

Conversation

@add-uos
Copy link
Contributor

@add-uos add-uos commented Dec 2, 2025

…lity code

Replace hardcoded Qt version with automatic detection that supports both Qt5 and Qt6. Update all Qt version-specific code to use unified APIs, replacing QRegExp with QRegularExpression and removing version conditionals throughout the codebase.

…lity code

Replace hardcoded Qt version with automatic detection that supports both Qt5 and Qt6.
Update all Qt version-specific code to use unified APIs, replacing QRegExp with
QRegularExpression and removing version conditionals throughout the codebase.
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.

Sorry @add-uos, you have reached your weekly rate limit of 500000 diff characters.

Please try again later or upgrade to continue using Sourcery

@deepin-ci-robot
Copy link

deepin pr auto review

我来对这个 Git diff 进行审查,主要关注代码质量、性能、安全性和兼容性等方面。

  1. CMakeLists.txt 改进建议:
  • Qt版本检测逻辑合理,但建议增加对最低Qt版本的要求检查
  • 可以考虑添加对Qt版本兼容性的警告提示
  1. 代码质量改进:
  • 正则表达式处理:从 QRegExp 迁移到 QRegularExpression 是正确的,但要注意性能影响
  • 建议预编译常用的正则表达式,避免重复编译
  • 正则表达式匹配结果应该存储在变量中,避免重复调用 match()
  1. 性能优化建议:
  • 在 DeviceStorage.cpp 中,建议将正则表达式对象作为类的成员变量,避免重复创建
  • 对于频繁使用的正则表达式,应该使用 QRegularExpression::optimize() 进行优化
  1. 安全性改进:
  • 在处理外部输入时,建议增加输入验证
  • 文件路径操作时,建议使用 QDir::toNativeSeparators() 确保跨平台兼容性
  1. 代码风格建议:
  • 删除了大量的 Qt 版本判断代码,提高了代码可读性
  • 建议统一使用 QRegularExpressionMatch 变量存储匹配结果
  • 建议添加更多的注释说明正则表达式的用途
  1. 具体修改建议:
// 在 DeviceStorage.h 中添加成员变量
class DeviceStorage {
private:
    static const QRegularExpression sizeReg;
    static const QRegularExpression capacityReg;
    // ...
};

// 在 DeviceStorage.cpp 中初始化
const QRegularExpression DeviceStorage::sizeReg(".*\\[(\\d+\\.?\\d+).*\\]");
const QRegularExpression DeviceStorage::capacityReg(".*\\[(.*)\\]$");

// 使用优化后的正则表达式
QString DeviceStorage::compareSize(const QString &size1, const QString &size2) {
    QRegularExpressionMatch match1 = sizeReg.match(size1);
    QRegularExpressionMatch match2 = sizeReg.match(size2);
    
    if (match1.hasMatch() && match2.hasMatch()) {
        int num1 = match1.captured(1).toInt();
        int num2 = match2.captured(1).toInt();
        // ...
    }
}
  1. 错误处理改进:
  • 建议在正则表达式匹配失败时添加错误日志
  • 对关键操作添加异常处理
  1. 兼容性建议:
  • 虽然移除了 Qt5 的支持,但建议保留版本检查,以便在需要时能够快速回退
  • 考虑添加对 Qt6 特定功能的条件编译

这些改进将提高代码的可维护性、性能和安全性,同时保持良好的可读性。

@deepin-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: add-uos, 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

@add-uos
Copy link
Contributor Author

add-uos commented Dec 2, 2025

/forcemerge

@deepin-bot
Copy link
Contributor

deepin-bot bot commented Dec 2, 2025

This pr force merged! (status: unstable)

@deepin-bot deepin-bot bot merged commit df92c6a into linuxdeepin:master Dec 2, 2025
15 of 17 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