Skip to content

Conversation

@mhduiy
Copy link
Contributor

@mhduiy mhduiy commented Nov 25, 2025

  1. Added explicit deletion of copy constructor and copy assignment operator
  2. Prevents unintended copying of singleton-like Util class instances
  3. Ensures proper singleton pattern implementation by restricting object duplication
  4. Improves code safety by preventing potential issues with multiple instances

Influence:

  1. Verify that Util class cannot be copied in any context
  2. Test that existing functionality remains unchanged
  3. Check compilation fails when attempting to copy Util instances
  4. Ensure all Util usage remains through proper singleton access

refactor: 禁用 Util 类的复制操作

  1. 显式删除了复制构造函数和复制赋值运算符
  2. 防止意外复制单例模式的 Util 类实例
  3. 通过限制对象复制确保正确的单例模式实现
  4. 防止多实例导致的潜在问题,提高代码安全性

Influence:

  1. 验证 Util 类在任何上下文中都无法被复制
  2. 测试现有功能保持不变
  3. 检查尝试复制 Util 实例时编译失败
  4. 确保所有 Util 使用仍通过正确的单例访问方式

Summary by Sourcery

Enhancements:

  • Make the Util class non-copyable by deleting its copy constructor and copy assignment operator.

@sourcery-ai
Copy link

sourcery-ai bot commented Nov 25, 2025

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

This PR reinforces the singleton-like semantics of the Util class by explicitly deleting its copy constructor and copy assignment operator, preventing accidental copying while preserving existing behavior and usage patterns.

Class diagram for Util singleton copy prevention refactor

classDiagram
    class Util {
        -Util()
        -~Util()
        -Util(Util other) delete
        -Util operatorAssign(Util other) delete
        -bool isTransparentImage(QImage image)
    }
Loading

File-Level Changes

Change Details Files
Harden Util as a non-copyable singleton-like class
  • Explicitly delete the Util copy constructor to prevent creating new instances via copying
  • Explicitly delete the Util copy assignment operator to prevent assigning between instances
  • Rely on compiler errors to surface any existing unintended copies of Util, ensuring all access goes through the singleton mechanism
plugins/application-tray/util.h

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:

  • Since this class is effectively a singleton, consider also deleting the move constructor and move assignment operator to fully prevent unintended object transfers (e.g., Util(Util&&) = delete; Util& operator=(Util&&) = delete;).
  • Given this is Qt code, you might want to use the Q_DISABLE_COPY(Util) macro instead of manually deleting the copy operations for consistency with the rest of the codebase.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Since this class is effectively a singleton, consider also deleting the move constructor and move assignment operator to fully prevent unintended object transfers (e.g., Util(Util&&) = delete; Util& operator=(Util&&) = delete;).
- Given this is Qt code, you might want to use the Q_DISABLE_COPY(Util) macro instead of manually deleting the copy operations for consistency with the rest of the codebase.

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.

1. Added explicit deletion of copy constructor and copy assignment
operator
2. Prevents unintended copying of singleton-like Util class instances
3. Ensures proper singleton pattern implementation by restricting object
duplication
4. Improves code safety by preventing potential issues with multiple
instances

Influence:
1. Verify that Util class cannot be copied in any context
2. Test that existing functionality remains unchanged
3. Check compilation fails when attempting to copy Util instances
4. Ensure all Util usage remains through proper singleton access

refactor: 禁用 Util 类的复制操作

1. 显式删除了复制构造函数和复制赋值运算符
2. 防止意外复制单例模式的 Util 类实例
3. 通过限制对象复制确保正确的单例模式实现
4. 防止多实例导致的潜在问题,提高代码安全性

Influence:
1. 验证 Util 类在任何上下文中都无法被复制
2. 测试现有功能保持不变
3. 检查尝试复制 Util 实例时编译失败
4. 确保所有 Util 使用仍通过正确的单例访问方式
@deepin-ci-robot
Copy link

deepin pr auto review

这是一个很好的改进,我来分析一下这个变更:

  1. 语法逻辑:
  • 语法完全正确,使用了C++11的特性来显式删除拷贝构造函数和拷贝赋值运算符。
  • 这种做法符合现代C++的最佳实践。
  1. 代码质量:
  • 这是一个很好的改进,因为Util类看起来是一个工具类,通常不应该被拷贝。
  • 通过删除拷贝构造函数和拷贝赋值运算符,可以防止意外的对象拷贝,提高了代码的健壮性。
  • 这种做法也明确表达了类的设计意图:这是一个不可拷贝的类。
  1. 代码性能:
  • 虽然这个改动本身不会直接带来性能提升,但它可以在编译期就防止不必要的拷贝操作,从整体上帮助优化程序性能。
  1. 代码安全:
  • 提高了代码的安全性,防止了潜在的对象切片问题。
  • 避免了可能出现的浅拷贝问题,特别是如果类中有指针成员或资源管理时。

建议:

  1. 考虑是否也需要删除移动构造函数和移动赋值运算符:
Util(Util&&) = delete;
Util& operator=(Util&&) = delete;
  1. 如果这个类确实是一个单例类(从私有构造函数来看),建议:
  • 添加注释说明这是一个单例类
  • 考虑使用C++11的delete关键字来删除默认构造函数,而不是将其设为private
  • 或者考虑使用static方法来获取单例实例
  1. 如果这是一个纯工具类,也可以考虑:
  • 将所有成员函数和变量都声明为static
  • 这样就不需要实例化对象,直接通过类名调用方法

总的来说,这是一个很好的改进,使代码更加安全和明确。

@deepin-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: mhduiy, yixinshark

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

@mhduiy
Copy link
Contributor Author

mhduiy commented Nov 25, 2025

/forcemerge

@deepin-bot
Copy link

deepin-bot bot commented Nov 25, 2025

This pr force merged! (status: blocked)

@deepin-bot deepin-bot bot merged commit d0d82cd into linuxdeepin:master Nov 25, 2025
8 of 10 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