Skip to content

Conversation

@deepin-ci-robot
Copy link
Contributor

@deepin-ci-robot deepin-ci-robot commented Aug 18, 2025

Synchronize source files from linuxdeepin/dtkdeclarative.

Source-pull-request: linuxdeepin/dtkdeclarative#519

Summary by Sourcery

Sync source files from linuxdeepin/dtkdeclarative and adapt code for Qt6 compatibility, deprecation suppression, and minor cleanup across containers, controls, window management, loader, and examples.

Bug Fixes:

  • Use correct DGuiApplicationHelper::IsWaylandPlatform attribute instead of IsTreelandPlatform
  • Add Q_UNUSED for unused function parameter to suppress warnings

Enhancements:

  • Replace qAsConst iterations with std::as_const under QT6 guards for modern container handling
  • Add Qt version guards around DPI attribute setup in example applications
  • Default-initialize effect scene and type members instead of explicit zero construction

Build:

  • Define D_IGNORE_DEPRECATIONS in library targets to suppress deprecation warnings

Tests:

  • Simplify test destructor to rely on QScopedPointer automatic cleanup

Chores:

  • Remove redundant inline specifiers and unused code (static_assert, temporary variables)
  • Include <qglobal.h> where needed for version checks

@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 Aug 18, 2025

Reviewer's Guide

This PR synchronizes upstream changes from linuxdeepin/dtkdeclarative, introducing Qt6 compatibility via conditional std::as_const usage, refining function declarations and default initializations, adjusting build definitions, correcting platform attribute checks, and removing dead code across multiple modules.

Class diagram for updated SettingsContainer and SettingsGroup iteration logic

classDiagram
    class SettingsContainer {
        -QVector<SettingsGroup *> m_groups
        +QVector<SettingsGroup *> groupList() const
        +bool groupVisible(const QString &key) const
        +void resetSettings()
    }
    class SettingsGroup {
        -QList<SettingsGroup *> m_children
        -QList<Option *> m_options
        +void setConfig(QObject *config)
        +void setBackground(QQmlComponent *background)
    }
    SettingsContainer "1" *-- "*" SettingsGroup
    SettingsGroup "1" *-- "*" Option
Loading

Class diagram for WaterPopAttribute method signature changes

classDiagram
    class WaterPopAttribute {
        +qreal sizeRatio() const
        +qreal yOffset() const
        +void setYOffset(qreal offset)
        +signal xSpeedChanged()
    }
Loading

File-Level Changes

Change Details Files
Introduce Qt6-compatible iteration with std::as_const under version checks
  • Replace qAsConst(...) loops with conditional std::as_const for Qt 6
  • Maintain qAsConst for older Qt versions
src/private/dsettingscontainer.cpp
src/private/dquickcontrolpalette.cpp
src/dquickwindow.cpp
src/dapploader.cpp
src/private/dquickwindow_p.h
src/private/dquickcontrolpalette.cpp
src/private/dquickcontrolpalette.cpp
src/private/dquickcontrolpalette.cpp
src/private/dquickcontrolpalette.cpp
Fix platform attribute check in DQuickWindowAttached
  • Change testAttribute from IsTreelandPlatform to IsWaylandPlatform
src/dquickwindow.cpp
Simplify inline function signature
  • Remove redundant const qualifier from static inline heightValid
src/dapploader.cpp
Normalize function declarations by removing inline qualifiers
  • Convert inline yOffset() and setYOffset() to regular declarations
src/private/dquickwaterprogressattribute_p.h
Use value initialization for enum members
  • Replace cast-based default values with {} initialization for explicitEffectScene and explicitEffectType
src/private/dquickwindow_p.h
Add D_IGNORE_DEPRECATIONS define to CMake targets
  • Insert target_compile_definitions PRIVATE D_IGNORE_DEPRECATIONS in CMakeLists.txt
qt6/src/CMakeLists.txt
src/CMakeLists.txt
Leverage QScopedPointer auto-cleanup in test destructor
  • Remove manual app.take() and rely on QScopedPointer for cleanup
tests/ut_dapploader.cpp
Guard high-DPI pixmap attribute for Qt versions
  • Wrap QCoreApplication::setAttribute(Qt::AA_UseHighDpiPixmaps) in QT_VERSION < 6 checks
examples/exhibition/main.cpp
examples/qml-inspect/main.cpp
Remove dead code and suppress unused parameter warnings
  • Delete static_assert in DataManager resolve
  • Remove unused auto rhi assignment
  • Add Q_UNUSED(requestedSize) in shadow provider
src/private/dbackdropnode.cpp
src/private/dquickimageprovider.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 there - I've reviewed your changes - here's some feedback:

  • There are numerous repeated #if QT_VERSION checks to switch between qAsConst and std::as_const—consider introducing a compatibility alias or helper to avoid redundant code blocks and improve readability.
  • The D_IGNORE_DEPRECATIONS compile definition is added in multiple CMakeLists (src and qt6/src); you may want to centralize it in a single location to ensure consistency and ease maintenance.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- There are numerous repeated #if QT_VERSION checks to switch between qAsConst and std::as_const—consider introducing a compatibility alias or helper to avoid redundant code blocks and improve readability.
- The D_IGNORE_DEPRECATIONS compile definition is added in multiple CMakeLists (src and qt6/src); you may want to centralize it in a single location to ensure consistency and ease maintenance.

## Individual Comments

### Comment 1
<location> `src/private/dbackdropnode.cpp:148` </location>
<code_context>
     }

     static DataManagerPointer<Derive> resolve(const DataManagerPointer<Derive> &other, QQuickWindow *owner) {
-        static_assert(&Derive::metaObject);
         Q_ASSERT(owner);
         if (other && other->owner() == owner)
</code_context>

<issue_to_address>
Removing static_assert may reduce compile-time type safety.

Consider if removing this compile-time check could allow incorrect template instantiations, leading to runtime errors. If so, evaluate whether an alternative validation is necessary.
</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.

}

static DataManagerPointer<Derive> resolve(const DataManagerPointer<Derive> &other, QQuickWindow *owner) {
static_assert(&Derive::metaObject);
Copy link

Choose a reason for hiding this comment

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

issue: Removing static_assert may reduce compile-time type safety.

Consider if removing this compile-time check could allow incorrect template instantiations, leading to runtime errors. If so, evaluate whether an alternative validation is necessary.

Synchronize source files from linuxdeepin/dtkdeclarative.

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

deepin pr auto review

根据提供的代码差异,我来对代码进行审查,并提出改进意见:

1. Qt版本兼容性改进

优点:

  • 代码正确处理了Qt5和Qt6版本之间的差异,特别是在容器访问方式上(qAsConst vs std::as_const
  • 高DPI支持代码使用了条件编译,确保在不同Qt版本下的正确性

改进建议:

  • main.cpp中添加Qt版本检查是好的做法,但可以考虑在CMake配置阶段就检查Qt版本,这样可以提前发现兼容性问题
  • 建议创建一个统一的版本兼容性头文件,集中处理所有Qt版本相关的差异,避免代码中散布大量版本检查

2. 代码质量和可维护性

优点:

  • 使用了现代C++特性,如std::as_const
  • 移除了不必要的内联函数(如heightValid函数)
  • 使用了更清晰的初始化方式(如explicitEffectScene {}

改进建议:

  • DQuickShadowProvider::requestImage中,虽然标记了Q_UNUSED(requestedSize),但最好添加注释说明为什么不使用这个参数
  • dapploader.cpp中的循环重复使用了相同的条件判断,可以考虑提取为辅助函数
  • dsettingscontainer.cpp中大量重复的版本检查代码,建议使用宏或模板来简化

3. 代码安全性

优点:

  • 使用了Q_ASSERT进行运行时检查
  • 正确处理了对象的所有权和生命周期(如DAppLoaderSimulator中的资源管理)

改进建议:

  • dbackdropnode.cpp中移除了static_assertrhi检查,这可能影响安全性,建议保留这些检查或提供替代方案
  • DQuickWindowAttached中的平台判断从IsTreelandPlatform改为IsWaylandPlatform,建议添加注释说明原因
  • 在多线程环境下访问共享数据时,建议添加适当的同步机制

4. 性能优化

优点:

  • 使用了const引用传递,避免不必要的拷贝
  • DQuickWindowAttachedPrivate::_q_updateBlurAreaForWindow中合理使用了continue跳过无效项

改进建议:

  • dsettingscontainer.cpp中的递归遍历可以考虑使用迭代方式,避免潜在的栈溢出风险
  • 在频繁调用的函数中(如findAndSetControlParent),可以考虑缓存一些计算结果
  • 对于大型容器遍历,可以考虑使用基于范围的for循环,提高代码可读性

5. 其他建议

  1. 代码注释:

    • 对重要的版本兼容性处理添加详细注释
    • 对平台相关的特殊处理添加说明
  2. 测试覆盖:

    • 建议为Qt版本兼容性相关的代码添加单元测试
    • 对平台相关功能添加多平台测试用例
  3. 文档更新:

    • 更新项目文档,说明Qt版本兼容性策略
    • 记录平台相关代码的特殊处理原因

总体来说,这些改动主要是为了提高Qt6兼容性,代码质量整体良好。主要的改进空间在于减少重复代码、提高安全性,以及优化性能。建议在后续开发中继续保持对版本兼容性的重视,并逐步完善代码的可维护性。

@18202781743 18202781743 merged commit d5dbea1 into master Aug 18, 2025
12 of 15 checks passed
@18202781743 18202781743 deleted the sync-pr-519-nosync branch August 18, 2025 08:48
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