Coding Standards¶
This document defines the coding standards for the DAWidgets project, ensuring consistent code style and quality.
Core Requirements¶
Features
- ✅ Code Formatting: Automatic formatting via
.clang-formatconfiguration - ✅ Modern C++ Style: Uses
override,nullptr,using, and other modern syntax - ✅ Qt Best Practices: Follows Qt development guidelines
- ✅ Qt5/Qt6 Dual Compatibility: Version differences handled via compatibility macros
Code Formatting¶
The project uses a .clang-format configuration file for code formatting.
Formatting Recommendations
- Run clang-format before committing code
- Configure your IDE to format on save
- Stay consistent with existing code style
Key Coding Standards¶
1. Use Q_SIGNALS / Q_SLOTS¶
Use the Qt-recommended macros instead of lowercase keywords:
1 2 3 4 5 6 7 8 9 10 11 | |
Prohibited
Do not use lowercase signals / slots — some compilers may have issues with them.
2. Use override and final¶
1 2 3 4 5 | |
3. Use nullptr Instead of NULL¶
1 2 3 4 5 | |
4. Use static_cast Instead of C-Style Casts¶
1 2 3 4 5 | |
5. Use using Instead of typedef¶
1 2 3 4 5 | |
Qt Development Best Practices¶
Signal-Slot Syntax¶
Use the Qt5+ function pointer syntax:
1 2 3 4 5 | |
Q_PROPERTY Usage¶
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | |
Naming Conventions¶
Class Names¶
- Use the
DAprefix + PascalCase:DASelectComboBox,DACollapseItem - All classes are placed in the
DAnamespace
1 2 3 4 5 6 7 8 | |
Method Names¶
- camelCase, first letter lowercase
- Getters omit the
getprefix:tags(),options() - Setters use the
setprefix:setTags(),setOptions()
1 2 | |
Variable Names¶
- Member variables (in PIMPL private data classes) have no special prefix:
title,value - Local variables use camelCase:
sampleCount - Constants are ALL_CAPS:
MAX_COUNT
Enumerations¶
- Use
enum class, PascalCase naming - Enum values are PascalCase
1 2 3 4 5 6 | |
qss Selector Convention¶
For custom widgets under the DA namespace, qss selectors use the DA--ClassName form (Qt uses -- in place of ::):
1 2 3 4 5 6 7 | |
API Design Conventions¶
Enum-First¶
Fixed-value parameters provide both an enum overload and a string overload:
1 2 3 4 5 | |
Design Philosophy
Enums provide compile-time type safety — users know the supported values without consulting documentation. String APIs are retained for runtime configuration scenarios.