Skip to content

Conversation

@deepin-ci-robot
Copy link
Contributor

@deepin-ci-robot deepin-ci-robot commented Jan 15, 2026

Synchronize source files from linuxdeepin/dtkdeclarative.

Source-pull-request: linuxdeepin/dtkdeclarative#557

Summary by Sourcery

Adjust build configuration to support selecting DTK5 or DTK6 via a DTK5 option and consistently derive versions and naming from a unified DTK version.

Enhancements:

  • Unify project version handling using VERSION file values and propagate DTK major/minor/patch into library and documentation versions.
  • Introduce a DTK5 CMake option to toggle between DTK5 and DTK6 builds, updating conditional logic and install paths accordingly.
  • Standardize CMake target, package, and namespace names using a DTK name suffix to differentiate DTK5 and DTK6 artifacts.
  • Align example, chameleon style plugin, QML plugin, and tests CMake configurations with the new DTK selection and naming scheme.
  • Ensure DQuickDciIconImage retains content while loading on Qt 6.8+ by enabling retainWhileLoading on the underlying image item.

Tests:

  • Enable CTest for the project when BUILD_TESTING is ON and adjust test sources and dependencies to honor the DTK5 option.

@deepin-ci-robot
Copy link
Contributor Author

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: deepin-ci-robot

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

@sourcery-ai
Copy link

sourcery-ai bot commented Jan 15, 2026

Reviewer's Guide

Refactors CMake configuration to derive versioning from the VERSION file, introduce a DTK5 build option that controls DTK/Qt major selection, and consistently use a DTK_NAME_SUFFIX-based naming convention across libraries, exports, examples, tests, and documentation, while adding a small runtime behavior tweak for DQuickDciIconImage.

Sequence diagram for DQuickDciIconImage retainWhileLoading behavior

sequenceDiagram
    participant QML as QMLCode
    participant Img as DQuickDciIconImage
    participant Priv as DQuickDciIconImagePrivate
    participant Icon as DQuickIconImage

    QML ->> Img: create DQuickDciIconImage
    activate Img
    Img ->> Priv: construct DQuickDciIconImagePrivate(this)
    activate Priv
    Priv ->> Icon: create DQuickIconImage
    Priv ->> Img: connect DQuickIconImage::cacheChanged
    Note over Priv,Img: For Qt >= 6.8.0
    Priv ->> Img: connect DQuickIconImage::retainWhileLoadingChanged
    Priv ->> Icon: setRetainWhileLoading(true)
    deactivate Priv
    deactivate Img
Loading

Flow diagram for DTK5 option-driven CMake configuration

flowchart TD
    A[Read VERSION file into FILE_VERSION] --> B[project DtkDeclarative VERSION FILE_VERSION]
    B --> C{DTK5 option ON?}

    C -- Yes --> D[set DTK_VERSION_MAJOR 5]
    D --> E[set DTK_NAME_SUFFIX empty]
    C -- No --> F[set DTK_VERSION_MAJOR 6]
    F --> G[set DTK_NAME_SUFFIX 6]

    D & F --> H[Derive DTK_VERSION_MINOR from PROJECT_VERSION_MINOR]
    H --> I[Derive DTK_VERSION_PATCH from PROJECT_VERSION_PATCH]
    I --> J[Compose DTK_VERSION = MAJOR.MINOR.PATCH]
    J --> K[Set QT_VERSION_MAJOR = DTK_VERSION_MAJOR]

    J --> L[Set LIB_NAME = dtk + DTK_NAME_SUFFIX + declarative]
    J --> M[Set INCLUDE_INSTALL_DIR using DTK_VERSION_MAJOR]
    J --> N[Set CONFIG_INSTALL_DIR using DTK_NAME_SUFFIX]
    J --> O[Set DDECLARATIVE_TRANSLATIONS_DIR using DTK_VERSION_MAJOR]

    C -- Yes --> P[Enable Qt5/DTK5 targets]
    P --> P1[add_subdirectory src]
    P --> P2[add_subdirectory qmlplugin]

    C -- No --> Q[Enable Qt6/DTK6 targets]
    Q --> Q1[add_subdirectory qt6]

    C -- Yes --> R[USE_QQuickStylePluginPrivate via Qt::QuickControls2]
    C -- No --> S[USE_QQuickStylePluginPrivate via Qt6::QuickControls2]

    J --> T[Generate Dtk + DTK_NAME_SUFFIX DeclarativeConfig.cmake]
    J --> U[Generate Dtk + DTK_NAME_SUFFIX DeclarativeConfigVersion.cmake]
    J --> V[Generate dtk + DTK_NAME_SUFFIX declarative.pc]

    C -- Yes --> W[Examples: BIN_NAME dtk-exhibition]
    W --> W1[find_package DtkCore, DtkGui]
    C -- No --> X[Examples: BIN_NAME dtk6-exhibition]
    X --> X1[find_package Dtk6Core, Dtk6Gui]
Loading

File-Level Changes

Change Details Files
Rework top-level CMake version handling and DTK/Qt variant selection to be driven by a DTK5 option and shared DTK_VERSION variables.
  • Read VERSION file into FILE_VERSION and use it directly for project(VERSION ...)
  • Introduce DTK5 option defaulting to ON and derive DTK_VERSION_MAJOR, DTK_NAME_SUFFIX, QT_VERSION_MAJOR, and DTK_VERSION from it and PROJECT_VERSION components
  • Replace EnableQt5/EnableQt6/EnableDtk5/EnableDtk6 conditionals with DTK5/NON-DTK5 checks, including which subdirectories (src/qmlplugin vs qt6) are built
  • Adjust library name LIB_NAME and install/include/config/translations paths to use DTK_VERSION_MAJOR or DTK_NAME_SUFFIX instead of PROJECT_VERSION_MAJOR
  • Fix write_basic_package_version_file to use DTK_VERSION instead of undefined VERSION and update config file names to include DTK_NAME_SUFFIX
  • Enable CTest via enable_testing() when BUILD_TESTING is ON and update unit-test dependencies and wizard template Qt version index to use DTK5 flag
CMakeLists.txt
Align example, src, plugin, and test CMake files with the new DTK_NAME_SUFFIX-based naming and DTK5 flag.
  • Rename example binaries and their install paths to incorporate DTK_NAME_SUFFIX and DTK_VERSION_MAJOR where appropriate
  • Update all find_package(Dtk* ...) and Dtk::* namespaces to use DTK_NAME_SUFFIX in examples, src targets, chameleon plugin, qmlplugin, and tests
  • Switch Qt5/Qt6 resource handling and QML file selection to DTK5 vs non-DTK5 branches in examples and test plugins
  • Adjust installation of *_properties and main libraries/exports to use DTK_NAME_SUFFIX in export set names, namespaces, and generated CMake target files
  • Update SOVERSION/VERSION on libraries and Doxygen project number to use DTK_VERSION and DTK_VERSION_MAJOR instead of CMAKE_PROJECT_VERSION values
examples/exhibition/CMakeLists.txt
examples/qml-inspect/CMakeLists.txt
src/targets.cmake
src/src.cmake
qt6/src/CMakeLists.txt
chameleon/CMakeLists.txt
qmlplugin/targets.cmake
src/CMakeLists.txt
tests/CMakeLists.txt
tests/apploaderplugindump/maincomponentplugin/CMakeLists.txt
tests/apploaderplugindump/preloadplugin/CMakeLists.txt
docs/CMakeLists.txt
Adjust source selection for DTK5/DTK6 builds and tweak DQuickDciIconImage behavior for newer Qt versions.
  • Use DTK5 flag instead of EnableDtk5/EnableDtk6 to include DTK5-only headers/sources and to strip DTK6 builds of dquicksystempalette-related files
  • For Qt >= 6.8.0, ensure DQuickDciIconImage's internal image item retains content while loading by calling setRetainWhileLoading(true) after connecting the signal
src/src.cmake
src/private/dquickdciiconimage.cpp

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 - I've found 1 issue

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location> `docs/CMakeLists.txt:20` </location>
<code_context>
+if (DTK5)
     find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Help)
 else()
     find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS ToolsTools)
</code_context>

<issue_to_address>
**issue (bug_risk):** Possible typo in Qt component name: "ToolsTools" looks duplicated.

`ToolsTools` is probably meant to be `Tools`. As written, this will likely cause `find_package(Qt...)` to fail and break the build.
</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.

if (DTK5)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Help)
else()
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS ToolsTools)
Copy link

Choose a reason for hiding this comment

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

issue (bug_risk): Possible typo in Qt component name: "ToolsTools" looks duplicated.

ToolsTools is probably meant to be Tools. As written, this will likely cause find_package(Qt...) to fail and break the build.

@github-actions
Copy link
Contributor

  • 敏感词检查失败, 检测到1个文件存在敏感词
详情
{
    "CMakeLists.txt": [
        {
            "line": "    HOMEPAGE_URL \"https://github.com/linuxdeepin/dtkdeclarative\"",
            "line_number": 9,
            "rule": "S35",
            "reason": "Url link | e63b02d733"
        }
    ]
}

@github-actions
Copy link
Contributor

  • 敏感词检查失败, 检测到1个文件存在敏感词
详情
{
    "CMakeLists.txt": [
        {
            "line": "    HOMEPAGE_URL \"https://github.com/linuxdeepin/dtkdeclarative\"",
            "line_number": 9,
            "rule": "S35",
            "reason": "Url link | e63b02d733"
        }
    ]
}

Synchronize source files from linuxdeepin/dtkdeclarative.

Source-pull-request: linuxdeepin/dtkdeclarative#557
@deepin-ci-robot
Copy link
Contributor Author

deepin pr auto review

CMakeLists 和代码变更审查

总体评价

这次变更主要重构了 DTK 项目中 Qt5/Qt6 版本的构建系统配置,将原来基于项目版本号判断的方式改为通过 CMake 选项显式控制。整体上提高了配置的灵活性和可维护性。

详细审查意见

1. 版本控制逻辑改进

优点

  • 将原来基于 PROJECT_VERSION_MAJOR 判断 Qt 版本的方式改为显式的 DTK5 选项,使构建配置更加明确和可控
  • 引入 DTK_NAME_SUFFIX 变量统一管理版本后缀,提高了代码一致性

建议

# 当前实现
option(DTK5 "Build DTK5." ON)
if(DTK5)
    set(DTK_VERSION_MAJOR "5")
    set(DTK_NAME_SUFFIX "")
else()
    set(DTK_VERSION_MAJOR "6")
    set(DTK_NAME_SUFFIX "6")
endif()

# 建议改进:增加对无效选项的检查
option(DTK5 "Build DTK5." ON)
if(DTK5)
    set(DTK_VERSION_MAJOR "5")
    set(DTK_NAME_SUFFIX "")
elseif(DTK6)  # 假设未来添加DTK6选项
    set(DTK_VERSION_MAJOR "6")
    set(DTK_NAME_SUFFIX "6")
else()
    message(FATAL_ERROR "Must specify either DTK5 or DTK6")
endif()

2. 变量命名一致性

问题

  • DTK_FILE_VERSION 改为 FILE_VERSION,但命名不够明确
  • 部分地方使用 DTK_VERSION_MAJOR,部分使用 DTK_NAME_SUFFIX,容易混淆

建议

# 更明确的命名
file(READ "${CMAKE_CURRENT_SOURCE_DIR}/VERSION" DTK_PROJECT_VERSION)
string(STRIP "${DTK_PROJECT_VERSION}" DTK_PROJECT_VERSION)

project(DtkDeclarative
    VERSION ${DTK_PROJECT_VERSION}
    ...
)

# 使用更一致的命名约定
set(DTK_MAJOR_VERSION "5")  # 主版本号
set(DTK_VERSION_SUFFIX "")  # 库名称后缀

3. CMake 配置文件路径

问题

  • CONFIG_INSTALL_DIR 路径中使用 DTK_NAME_SUFFIX 而不是 DTK_VERSION_MAJOR,可能导致版本6时配置文件路径不一致

建议

# 确保配置文件路径一致
set(CONFIG_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}/cmake/Dtk${DTK_MAJOR_VERSION}Declarative" CACHE STRING "CMake config file install directory")

4. C++ 代码变更

问题
src/private/dquickiconimage.cpp 中:

DQuickIconImage::DQuickIconImage(QQuickItem *parent)
    : DQuickIconImage(*(new DQuickIconImagePrivate), parent)  // 这里应该是QQuickImage
{
    // setAsynchronous(true) 被移除,但没有说明原因
}

建议

DQuickIconImage::DQuickIconImage(QQuickItem *parent)
    : QQuickImage(*(new DQuickIconImagePrivate), parent)  // 保持原有继承关系
{
    setAsynchronous(true);  // 保持原有行为,除非有特定原因移除
}

5. 条件编译逻辑

问题
在多处使用 if(NOT DTK5) 来判断是否为 Qt6,这种双重否定逻辑不够直观

建议

# 显式定义两个选项
option(DTK5 "Build DTK5." ON)
option(DTK6 "Build DTK6." OFF)

# 使用更明确的条件
if(DTK5)
    # Qt5 特定代码
elseif(DTK6)
    # Qt6 特定代码
endif()

6. 测试相关

优点

  • 添加了 enable_testing() 调用,确保测试功能正确启用

建议

if(BUILD_TESTING)
    enable_testing()
    add_subdirectory(tests)
    
    # 添加更详细的测试依赖说明
    add_dependencies(unit-test 
        ${PLUGIN_NAME} 
        ${STYLE_PLUGIN_NAME}
        $<$<NOT:$<BOOL:${DTK5}>>:dtkdeclarativeprivatesplugin dtkdeclarativesettingsplugin>
    )
endif()

7. 文档生成

问题
docs/CMakeLists.txt 中:

if (DTK5)
    find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Help)
else()
    find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS ToolsTools)
endif()

Qt6 的 ToolsTools 组件名称可能不正确

建议

if (DTK5)
    find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Help)
else()
    find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Help)  # Qt6 也使用 Help 组件
endif()

8. 性能优化

建议

# 在适当的地方使用生成器表达式减少重复配置
target_link_libraries(${LIB_NAME} PRIVATE
    Qt${QT_VERSION_MAJOR}::Quick
    Qt${QT_VERSION_MAJOR}::QuickControls2
    Dtk${DTK_NAME_SUFFIX}::Core
    Dtk${DTK_NAME_SUFFIX}::Gui
    $<$<BOOL:${DTK5}>:Qt${QT_VERSION_MAJOR}::QuickCompiler>
)

总结

这次变更整体上提高了构建系统的可维护性,但还有以下几点可以改进:

  1. 增加对无效选项的检查
  2. 统一变量命名约定
  3. 使用更直观的条件判断逻辑
  4. 修复 C++ 代码中的继承关系问题
  5. 验证 Qt6 组件名称的正确性
  6. 使用生成器表达式优化重复配置

建议在合并前进行全面的构建测试,确保所有平台和配置都能正常工作。

@github-actions
Copy link
Contributor

  • 敏感词检查失败, 检测到1个文件存在敏感词
详情
{
    "CMakeLists.txt": [
        {
            "line": "    HOMEPAGE_URL \"https://github.com/linuxdeepin/dtkdeclarative\"",
            "line_number": 9,
            "rule": "S35",
            "reason": "Url link | e63b02d733"
        }
    ]
}

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.

2 participants