Skip to content

Conversation

@dengzhongyuan365-dev
Copy link
Contributor

  • Refactored signal-slot connections in ColorWidgetAction.cpp to use modern syntax for Qt 6 compatibility.
  • Maintained backward compatibility with Qt versions prior to 6.0.0.

This change improves code clarity and ensures proper functionality across different Qt versions.

bug: https://pms.uniontech.com/bug-view-304093.html

- Refactored signal-slot connections in ColorWidgetAction.cpp to use modern syntax for Qt 6 compatibility.
- Maintained backward compatibility with Qt versions prior to 6.0.0.

This change improves code clarity and ensures proper functionality across different Qt versions.

bug: https://pms.uniontech.com/bug-view-304093.html
@deepin-ci-robot
Copy link

deepin pr auto review

我来帮你审查这段代码的修改。这是一个关于Qt版本兼容性修改的diff,主要涉及信号槽连接方式的更新。让我从几个方面来分析:

  1. 语法逻辑:
  • 修改正确地处理了Qt5和Qt6之间的差异
  • 使用了版本条件编译来适配不同Qt版本
  • 在Qt6中使用了新的函数指针语法和lambda表达式
  1. 代码质量:
  • 优点:
    • 正确使用了Qt版本检查宏
    • 保持了向后兼容性
    • 代码结构清晰
  • 可以改进的地方:
    • 在Qt6部分,lambda表达式的使用可能会增加内存开销
    • 代码中有重复的版本检查,可以考虑重构
  1. 代码性能:
  • Qt6版本使用lambda表达式可能比使用QSignalMapper有轻微的内存开销
  • 但这种差异在实际使用中几乎可以忽略不计
  1. 代码安全:
  • 修改是安全的,没有引入潜在的安全问题
  • 正确处理了信号槽的连接

改进建议:

  1. 考虑重构以减少重复的版本检查代码:
void ColorWidgetAction::initWidget(DWidget *pParent)
{
    // ... 其他代码保持不变 ...

    for (int iLoop = 0; iLoop < colorlst.size(); ++iLoop) {
        // ... 按钮创建代码保持不变 ...

#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
        connect(btn, SIGNAL(clicked()), sigMap, SLOT(map()));
        sigMap->setMapping(btn, iLoop);
#else
        connect(btn, &RoundColorWidget::clicked, this, [this, iLoop]() {
            slotBtnClicked(iLoop);
        });
#endif

        buttonLayout->addWidget(btn);
    }

#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
    connect(sigMap, SIGNAL(mapped(int)), SLOT(slotBtnClicked(int)));
#endif
}
  1. 可以考虑使用一个辅助函数来处理信号连接:
void ColorWidgetAction::connectColorButton(RoundColorWidget* btn, int index)
{
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
    connect(btn, SIGNAL(clicked()), sigMap, SLOT(map()));
    sigMap->setMapping(btn, index);
#else
    connect(btn, &RoundColorWidget::clicked, this, [this, index]() {
        slotBtnClicked(index);
    });
#endif
}
  1. 移除不必要的调试日志:
// qCDebug(appLog) << "Color widget initialization completed";
// 这个日志在循环中会打印多次,可能不是必要的

总的来说,这个修改是合理的,主要目的是为了适配Qt6的新特性。代码质量良好,但可以通过一些小的重构来提高可维护性。

@deepin-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

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

@dengzhongyuan365-dev
Copy link
Contributor Author

/forcemerge

@deepin-bot deepin-bot bot merged commit 8d15fe5 into linuxdeepin:master Dec 30, 2025
6 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