Skip to content

Commit e805379

Browse files
feat: button/application abstractions
1 parent 66bdaac commit e805379

68 files changed

Lines changed: 8216 additions & 28 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.clangd

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,15 @@ Diagnostics:
99
- builtin-requires-header
1010
- incompatible-library-redeclaration
1111
- builtin-declaration-mismatch
12-
- builtin_definition
12+
- builtin_definition
13+
14+
Complete:
15+
Include:
16+
InsertIncludes: Keep
17+
MaxPathLength: 30
18+
PathWhitelist:
19+
- Qt.*
20+
21+
InlayHints:
22+
Enabled: No
23+
ParameterNames: No
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#pragma once
2+
3+
#ifndef CF_PLAIN_PROPERTY
4+
# define CF_PLAIN_PROPERTY(val_type, val_name, default_value) \
5+
public: \
6+
val_type& get_##val_name() { \
7+
return val_name; \
8+
} \
9+
const val_type& get_##val_name##_const() const { \
10+
return val_name; \
11+
} \
12+
void set_##val_name(const val_type& v) { \
13+
val_name = v; \
14+
} \
15+
\
16+
private: \
17+
val_type val_name{default_value};
18+
19+
#endif

base/include/base/weak_ptr/weak_ptr.h

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,50 @@ template <typename T> class WeakPtr {
323323
*/
324324
bool operator!=(std::nullptr_t) const noexcept { return IsValid(); }
325325

326+
// ------------------------------------------------------------
327+
// Dynamic Cast (Base -> Derived conversion)
328+
// ------------------------------------------------------------
329+
330+
/**
331+
* @brief Dynamically converts WeakPtr<Base> to WeakPtr<Derived>.
332+
*
333+
* @details Performs a dynamic_cast on the underlying pointer.
334+
* Returns a valid WeakPtr<Derived> if the cast succeeds,
335+
* otherwise returns an invalid WeakPtr.
336+
*
337+
* @tparam Source Source type (base class).
338+
* @param other WeakPtr to the source object.
339+
*
340+
* @return WeakPtr<Derived> pointing to the same object if
341+
* the object is of type Derived, otherwise invalid.
342+
*
343+
* @throws None
344+
* @note The returned WeakPtr shares the same weak reference
345+
* flag as the source.
346+
* @warning Always check the returned WeakPtr's validity before use.
347+
* @since N/A
348+
* @ingroup none
349+
*
350+
* @code
351+
* WeakPtr<BaseClass> basePtr = ...;
352+
* auto derivedPtr = WeakPtr<DerivedClass>::DynamicCast(basePtr);
353+
* if (derivedPtr) {
354+
* derivedPtr->DerivedMethod();
355+
* }
356+
* @endcode
357+
*/
358+
template <typename Source>
359+
static WeakPtr DynamicCast(const WeakPtr<Source>& other) noexcept {
360+
if (!other.flag_ || !other.flag_->IsAlive()) {
361+
return WeakPtr();
362+
}
363+
T* casted = dynamic_cast<T*>(other.ptr_);
364+
if (casted) {
365+
return WeakPtr(casted, other.flag_);
366+
}
367+
return WeakPtr();
368+
}
369+
326370
private:
327371
// Only WeakPtrFactory can construct valid WeakPtr instances
328372

cmake/QtDeployUtils.cmake

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# ============================================================
2+
# Qt Unified Deployment Utilities
3+
# ============================================================
4+
# 提供动态注册机制,让子项目自动注册到统一部署列表
5+
6+
# 定义一个全局列表变量,用于收集所有需要部署的可执行文件
7+
set(QT_DEPLOY_EXECUTABLES "" CACHE INTERNAL "List of executables for Qt deployment")
8+
9+
# ============================================================
10+
# 宏: cf_register_qt_deployment
11+
# ============================================================
12+
# 子项目调用此宏注册自己到统一部署列表
13+
#
14+
# 用法:
15+
# cf_register_qt_deployment(target_name)
16+
#
17+
macro(cf_register_qt_deployment TARGET_NAME)
18+
list(APPEND QT_DEPLOY_EXECUTABLES ${TARGET_NAME})
19+
set(QT_DEPLOY_EXECUTABLES "${QT_DEPLOY_EXECUTABLES}" CACHE INTERNAL "List of executables for Qt deployment")
20+
endmacro()
21+
22+
# ============================================================
23+
# 函数: cf_setup_unified_qt_deployment
24+
# ============================================================
25+
# 在顶层调用,设置统一的 Qt 部署
26+
# 必须在所有子项目 add_subdirectory 之后调用
27+
#
28+
function(cf_setup_unified_qt_deployment)
29+
if(WIN32 AND NOT CMAKE_CROSSCOMPILING AND QT_DEPLOY_EXECUTABLES)
30+
# 找到 windeployqt
31+
find_program(WINDEPLOYQT_EXECUTABLE windeployqt
32+
HINTS "${CMAKE_PREFIX_DIR}/bin" "${_qt_install_prefix}/bin"
33+
)
34+
35+
if(WINDEPLOYQT_EXECUTABLE)
36+
set(DEPLOY_BIN_DIR "${CMAKE_BINARY_DIR}/bin")
37+
set(DEPLOY_MARKER "${DEPLOY_BIN_DIR}/.deploy_done")
38+
39+
message(STATUS "Setting up unified Qt deployment for: ${QT_DEPLOY_EXECUTABLES}")
40+
41+
# 创建统一的部署 target
42+
add_custom_target(deploy_qt_dlls ALL)
43+
44+
# 让部署 target 依赖所有已注册的可执行文件
45+
foreach(exe ${QT_DEPLOY_EXECUTABLES})
46+
if(TARGET ${exe})
47+
add_dependencies(deploy_qt_dlls ${exe})
48+
# 确保输出到 bin 目录
49+
set_target_properties(${exe} PROPERTIES
50+
RUNTIME_OUTPUT_DIRECTORY ${DEPLOY_BIN_DIR}
51+
)
52+
else()
53+
message(WARNING "Registered deployment target '${exe}' not found")
54+
endif()
55+
endforeach()
56+
57+
# 使用第一个可执行文件作为 windeployqt 的入口
58+
list(GET QT_DEPLOY_EXECUTABLES 0 FIRST_EXE)
59+
60+
# 执行部署
61+
add_custom_command(TARGET deploy_qt_dlls POST_BUILD
62+
COMMAND ${CMAKE_COMMAND} -E env QT_HASH_SEED=0
63+
"${WINDEPLOYQT_EXECUTABLE}"
64+
--dir "${DEPLOY_BIN_DIR}"
65+
--no-compiler-runtime
66+
--no-translations
67+
--no-system-d3d-compiler
68+
--no-opengl-sw
69+
--verbose 1
70+
"$<TARGET_FILE:${FIRST_EXE}>"
71+
COMMAND ${CMAKE_COMMAND} -E touch "${DEPLOY_MARKER}"
72+
COMMENT "Unified Qt deployment to ${DEPLOY_BIN_DIR}"
73+
VERBATIM
74+
)
75+
else()
76+
message(WARNING "windeployqt not found, skipping automatic Qt deployment")
77+
endif()
78+
endif()
79+
endfunction()

example/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
log_info("Example" "Managing Example Components")
22

33
add_subdirectory(base)
4+
add_subdirectory(ui)
45
add_subdirectory(gui)
56

example/gui/CMakeLists.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,17 @@
11
log_info("Example GUI" "Managing GUI Examples")
22

3+
# 包含统一部署工具(在子项目之前)
4+
if(WIN32)
5+
include(${CMAKE_SOURCE_DIR}/cmake/QtDeployUtils.cmake)
6+
endif()
7+
38
add_subdirectory(material)
49
add_subdirectory(theme)
10+
11+
# ============================================================
12+
# Unified Qt Deployment (Windows only)
13+
# ============================================================
14+
# 在所有子项目之后调用,统一部署已注册的可执行文件
15+
if(WIN32)
16+
cf_setup_unified_qt_deployment()
17+
endif()

example/gui/material/material_color_scheme/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@ if(WIN32)
1919
set_target_properties(material_color_scheme_gallery PROPERTIES
2020
WIN32_EXECUTABLE TRUE
2121
)
22-
# 自动部署 Qt DLL
23-
qt_add_windows_deploy(material_color_scheme_gallery AUTO_DEPLOY)
22+
# 注册到统一部署列表
23+
cf_register_qt_deployment(material_color_scheme_gallery)
2424
endif()

example/gui/material/material_motion_spec/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@ if(WIN32)
1919
set_target_properties(material_motion_spec_gallery PROPERTIES
2020
WIN32_EXECUTABLE TRUE
2121
)
22-
# 自动部署 Qt DLL
23-
qt_add_windows_deploy(material_motion_spec_gallery AUTO_DEPLOY)
22+
# 注册到统一部署列表
23+
cf_register_qt_deployment(material_motion_spec_gallery)
2424
endif()

example/gui/material/material_radius_scale/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@ if(WIN32)
1919
set_target_properties(material_radius_scale_gallery PROPERTIES
2020
WIN32_EXECUTABLE TRUE
2121
)
22-
# 自动部署 Qt DLL
23-
qt_add_windows_deploy(material_radius_scale_gallery AUTO_DEPLOY)
22+
# 注册到统一部署列表
23+
cf_register_qt_deployment(material_radius_scale_gallery)
2424
endif()

example/gui/material/material_typography/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@ if(WIN32)
1919
set_target_properties(material_typography_gallery PROPERTIES
2020
WIN32_EXECUTABLE TRUE
2121
)
22-
# 自动部署 Qt DLL
23-
qt_add_windows_deploy(material_typography_gallery AUTO_DEPLOY)
22+
# 注册到统一部署列表
23+
cf_register_qt_deployment(material_typography_gallery)
2424
endif()

0 commit comments

Comments
 (0)