Skip to content

Conversation

@lichaofan2008
Copy link

@lichaofan2008 lichaofan2008 commented Dec 2, 2025

解决主分支在v20上的编译问题。

v20 BUG 分支合一到v25主线
Task: https://pms.uniontech.com/task-view-383477.html

Summary by Sourcery

Make the project build against both Qt5 and Qt6 while resolving v20 compilation issues.

Bug Fixes:

  • Fix compilation failures on v20 by updating Qt-related APIs and build configuration.

Enhancements:

  • Generalize CMake Qt/DTK detection and linking to support both Qt5 and Qt6 from a single configuration.
  • Unify SVG item handling to rely on QSvgRenderer and modern Qt APIs, reducing version-specific branching.
  • Adjust signal/slot connections and string splitting to use overload-safe and version-appropriate Qt patterns.
  • Simplify file name validation logic by dropping legacy Qt5-only regular expression handling.

Build:

  • Update top-level and src CMakeLists to detect Qt6 first, fall back to Qt5, and link Qt/DTK targets via versioned variables.

@sourcery-ai
Copy link

sourcery-ai bot commented Dec 2, 2025

Reviewer's Guide

This PR fixes compilation issues on v20 by making the build system and several source files properly support both Qt5 and Qt6, removing outdated Qt5-only branches and centralizing version selection via CMake variables.

File-Level Changes

Change Details Files
Make CMake configuration support both Qt5 and Qt6 and drive DTK/Qt selection via version variables.
  • Replace hard-coded Qt6 find_package call with conditional detection of Qt6 and fallback to Qt5, setting QT_VERSION_MAJOR and DTK_VERSION_MAJOR accordingly.
  • Parameterize Qt and DTK target names in LINK_LIBS using QT_VERSION_MAJOR and DTK_VERSION_MAJOR instead of hard-coded Qt6/Dtk6.
  • Update pkg_check_modules to use DTK_VERSION_MAJOR in dtk widget/gui/core module names so the same CMake works for different DTK versions.
CMakeLists.txt
src/CMakeLists.txt
Unify SVG item handling and painting code to compile with both Qt5 and Qt6.
  • Switch QGraphicsSvgItem include paths to use QtSvgWidgets for Qt6 and QtSvg for Qt5 via QT_VERSION checks.
  • Remove Qt5/Qt6 split logic in CSizeHandleRect::paint and boundingRect, using QSvgRenderer-based rendering path consistently.
  • Add conditional include of QGraphicsSvgItem in cdrawscene.cpp matching the Qt version.
src/drawshape/drawItems/csizehandlerect.h
src/drawshape/drawItems/csizehandlerect.cpp
src/drawshape/cdrawscene.cpp
Modernize or conditionalize Qt signal/slot connections and API usages for cross-version compatibility.
  • Use QOverload::of(&QComboBox::currentIndexChanged) for font family combo box connections to avoid ambiguity across Qt versions.
  • Use QOverload<QAbstractButton*, bool>::of(&QButtonGroup::buttonToggled) under a Qt5 guard instead of string-based SIGNAL macro.
  • Replace deprecated/Qt5-only QRegularExpression::indexIn loop with QRegularExpressionMatchIterator-based implementation unconditionally in Application::isFileNameLegal.
  • Guard QString::split behavior change with Qt version macro, using Qt::SkipEmptyParts only for Qt6 and above.
src/drawshape/drawTools/ctexttool.cpp
src/widgets/dialog/cexportimagedialog.cpp
src/application.cpp
src/frame/cmultiptabbarwidget.cpp
Minor cleanups for Qt6 logging and build metadata.
  • Remove usage of Qt::endl from qDebug call to match newer Qt logging API and avoid potential compilation or warning issues.
  • Comment out hard-coded QT_MINIMUM_VERSION 6.0.0 in CMake so the project can build against Qt5 where needed.
  • Leave debian/control unchanged, indicating packaging is unaffected by this PR.
src/frame/cgraphicsview.cpp
CMakeLists.txt
src/CMakeLists.txt
debian/control

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:

  • In CSizeHandleRect::paint you now call m_lightRenderer.render twice (once with boundingRect() and once with rect) regardless of Qt version, which is different from the previous Qt5 path and might cause redundant drawing or visual changes; consider whether one of these calls can be removed or guarded to preserve the original behavior.
  • In the top-level CMakeLists.txt you first call find_package(Qt6 QUIET) and then, if found, call find_package(Qt6 REQUIRED COMPONENTS ...); the initial QUIET call is redundant and can be dropped to simplify the configuration logic.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In CSizeHandleRect::paint you now call m_lightRenderer.render twice (once with boundingRect() and once with rect) regardless of Qt version, which is different from the previous Qt5 path and might cause redundant drawing or visual changes; consider whether one of these calls can be removed or guarded to preserve the original behavior.
- In the top-level CMakeLists.txt you first call find_package(Qt6 QUIET) and then, if found, call find_package(Qt6 REQUIRED COMPONENTS ...); the initial QUIET call is redundant and can be dropped to simplify the configuration logic.

## Individual Comments

### Comment 1
<location> `src/drawshape/drawItems/csizehandlerect.cpp:89-95` </location>
<code_context>

-    //在Qt6中,QGraphicsSvgItem的renderer()方法已经被移除。在Qt5中,renderer()方法是可用的,因此需要分别处理。
-    #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
     if (!m_isRotation) {
-        if (renderer() != &m_lightRenderer) {
-            setSharedRenderer(&m_lightRenderer);
-        }
-    }
-    #else
-    // Qt6 处理逻辑
-    if (!m_isRotation) {
-        //// 在Qt6中直接使用m_lightRenderer进行绘制
         m_lightRenderer.render(painter, this->boundingRect());
     }
-    #endif

     painter->setClipping(false);
     QRectF rect = this->boundingRect();
-
-    #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
-    this->renderer()->render(painter, rect);
-    #else
-    // 在Qt6中使用QSvgRenderer直接绘制
     m_lightRenderer.render(painter, rect);
-    #endif

</code_context>

<issue_to_address>
**issue (performance):** Rendering the same SVG twice for non-rotation cases may be redundant or unintentional.

`m_lightRenderer.render` is invoked twice when `!m_isRotation`: first with `this->boundingRect()` and then with `rect`, which currently has the same value. Unless a double render is required for a visual effect (e.g., blending or multipass painting), consider keeping only a single call to reduce redundant work and simplify the logic.
</issue_to_address>

### Comment 2
<location> `src/frame/cmultiptabbarwidget.cpp:304-307` </location>
<code_context>
 #include <DApplication>
 #include <QScrollBar>
 #include <QWindow>
+#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
 #include <QtSvgWidgets/QGraphicsSvgItem>
+#else
</code_context>

<issue_to_address>
**suggestion (bug_risk):** Different `split` behavior between Qt5 and Qt6 may introduce inconsistencies.

In Qt6 you use `suffixes.split(' ', Qt::SkipEmptyParts)`, but in Qt5 you call `suffixes.split(' ')` without the flag. Since Qt5 defaults to `KeepEmptyParts`, multiple spaces will create empty entries only in the Qt5 branch. If you need consistent behavior, update the Qt5 code to also use `Qt::SkipEmptyParts` (Qt5 supports this flag).
</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.

解决主分支在v20上的编译问题。

v20 BUG 分支合一到v25主线
Task: https://pms.uniontech.com/task-view-383477.html
@deepin-ci-robot
Copy link

deepin pr auto review

我来对这个diff进行审查,主要关注代码质量、性能和安全性方面的改进建议:

  1. CMakeLists.txt 改进:
# 建议将Qt版本检测逻辑改为更明确的方式
find_package(Qt6 QUIET)
if(NOT Qt6_FOUND)
    find_package(Qt5 REQUIRED)
    set(QT_VERSION_MAJOR 5)
    set(DTK_VERSION_MAJOR "")
else()
    find_package(Qt6 REQUIRED COMPONENTS Core Widgets Gui DBus Xml Svg Test)
    set(QT_VERSION_MAJOR 6)
    set(DTK_VERSION_MAJOR 6)
endif()

# 添加版本检查
if(QT_VERSION_MAJOR EQUAL 5 AND CMAKE_CXX_STANDARD LESS 17)
    message(WARNING "Qt5 requires C++17 standard")
endif()
  1. application.cpp 改进:
// 建议将正则表达式提取为类成员变量,避免重复编译
class Application {
private:
    static const QRegularExpression splitExp;  // 在cpp文件中初始化
    
    // 添加错误码枚举
    enum FileNameError {
        NoError = 0,
        PathNotFound = 2
    };
};
  1. cdrawscene.cpp 改进:
// 建议使用统一的头文件包含方式
#ifdef QT_VERSION_MAJOR
#if QT_VERSION_MAJOR >= 6
#include <QtSvgWidgets/QGraphicsSvgItem>
#else
#include <QtSvg/QGraphicsSvgItem>
#endif
#else
#error "Qt version not defined"
#endif
  1. csizehandlerect.cpp 改进:
// 建议使用RAII管理painter状态
class ScopedPainterState {
public:
    explicit ScopedPainterState(QPainter* painter) : m_painter(painter) {
        m_painter->save();
    }
    ~ScopedPainterState() {
        m_painter->restore();
    }
private:
    QPainter* m_painter;
};

void CSizeHandleRect::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) {
    ScopedPainterState state(painter);
    // ... 绘制代码 ...
}
  1. ctexttool.cpp 改进:
// 建议使用现代C++的lambda表达式
connect(fontComboBox, QOverload<int>::of(&QComboBox::currentIndexChanged), 
    this, [this](int index) {
        const QString family = fontComboBox->itemText(index);
        handleFontFamilyChange(family);
    });
  1. 安全性改进建议:
  • 添加输入验证,特别是在处理文件路径时
  • 使用const引用传递大型对象
  • 添加空指针检查
  • 使用智能指针管理资源
  1. 性能优化建议:
  • 缓存常用的正则表达式
  • 避免在循环中重复创建对象
  • 使用move语义减少不必要的拷贝
  • 对于频繁调用的函数考虑内联
  1. 代码质量改进:
  • 添加更多的注释说明复杂逻辑
  • 统一命名规范
  • 提取重复代码为公共函数
  • 使用enum替代魔法数字
  • 添加更多的单元测试
  1. 版本兼容性改进:
// 建议创建版本兼容性工具类
class QtCompat {
public:
    static QStringList splitSkipEmpty(const QString &str, const QString &sep) {
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
        return str.split(sep, Qt::SkipEmptyParts);
#else
        return str.split(sep, QString::SplitBehavior::SkipEmptyParts);
#endif
    }
};

这些改进建议主要围绕:

  1. 提高代码的可维护性和可读性
  2. 增强错误处理和安全性
  3. 优化性能
  4. 改善版本兼容性处理
  5. 统一代码风格和规范

建议在实施这些改进时,优先处理安全性和性能相关的问题,然后再逐步改进代码质量和可维护性。

@deepin-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

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

@lichaofan2008
Copy link
Author

/merge

@deepin-bot deepin-bot bot merged commit e20c65d into linuxdeepin:develop/snipe Dec 2, 2025
15 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