refactor: replace #define private public hacks with template accessor…#745
Conversation
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: zccrs The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
There was a problem hiding this comment.
Pull request overview
Refactors several Qt-private access sites to remove #define private/protected public hacks by introducing a template-based private accessor helper, and updates build/CI to support the new internal header usage.
Changes:
- Added
src/util/dprivateaccessor_p.hprovidingD_DECLARE_PRIVATE_*andD_PRIVATE_*macros for standards-based access to private/protected members. - Updated widget sources to use the accessor pattern (or removed now-unneeded hacks) for Qt internals.
- Updated build include paths and added new CI workflows for Deepin/Arch container builds.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
src/widgets/dtabbar.cpp |
Replaces direct Qt-private member access in drag-stop logic with accessor macros. |
src/widgets/dstyleoption.cpp |
Accesses QFont::d via accessor instead of macro-based access hack. |
src/widgets/dlineedit.cpp |
Removes unnecessary #define private public around Qt private header include. |
src/widgets/dblureffectwidget.cpp |
Uses accessor to iterate QWidgetRepaintManager::dirtyWidgets (Qt ≥ 5.14). |
src/widgets/dapplication.cpp |
Removes Linux-only #define private public include block that’s no longer needed. |
src/util/dprivateaccessor_p.h |
Introduces template-based private accessor mechanism and helper macros. |
src/CMakeLists.txt |
Adds src/ as a private include directory to allow util/... internal includes. |
.github/workflows/dtkwidget-deepin-build.yml |
Adds Deepin (crimson) container CI build workflow. |
.github/workflows/dtkwidget-archlinux-build.yml |
Adds Arch Linux container CI build workflow. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
8a5a217 to
dbd1135
Compare
deepin pr auto review这份代码变更(Git Diff)主要完成了两件重要工作:
整体来看,这是一个质量非常高的重构。但在代码规范、安全性、CI 健壮性和 C++ 模板语法细节上,仍有改进空间。以下是详细的审查意见: 一、 语法与逻辑1.
|
|
TAG Bot New tag: 6.7.43 |
|
TAG Bot New tag: 6.7.44 |
Add CI workflows to verify the project builds correctly on both Arch Linux (latest) and Deepin crimson. This helps catch any platform-specific compilation issues introduced by the accessor pattern refactor.
… pattern Remove all '#define private/protected public' hacks and replace them with a proper C++ template-based private accessor pattern using explicit template instantiation (friend injection trick), mirroring the approach used in linuxdeepin/treeland#875. Adds src/util/dprivateaccessor_p.h with Accessor/AccessorImpl templates and D_DECLARE_PRIVATE_MEMBER, D_PRIVATE_MEMBER macros. All helpers live at global scope so ADL correctly resolves the friend-injected get() function.
|
/forcemerge |
|
This pr force merged! (status: blocked) |
… pattern
Replace UB-prone #define private/protected public access hacks in 5 source files with a standards-compliant C++ template-based private accessor pattern, using [temp.explicit]/12 to bypass access control without undefined behavior.
Add src/util/dprivateaccessor_p.h with DtkWidgetPrivateAccessor / DtkWidgetPrivateAccessorImpl templates and supporting macros:
D_DECLARE_PRIVATE_MEMBER, D_DECLARE_PRIVATE_METHOD,
D_DECLARE_PRIVATE_CONST_METHOD, D_PRIVATE_MEMBER, D_PRIVATE_CALL
Changes per file:
Use ::get(tag) qualified call in macros to avoid shadowing by class-scope get() methods (e.g. DFontSizeManager::get()).