Coding Standards¶
This document defines the coding standards for the Qwt project to ensure consistent code style and quality.
Key Requirements¶
Features
- ✅ Code Formatting: Automatic formatting using
.clang-formatconfiguration - ✅ C++11 Compatibility: Use the project-provided compatibility macros
- ✅ Modern C++ Style: Use modern syntax such as
override,nullptr,using, etc. - ✅ Qt Best Practices: Follow Qt development guidelines
Code Formatting¶
The project uses a .clang-format configuration file for code formatting.
Formatting Suggestions
- Run clang-format before committing code
- Configure your IDE for automatic formatting (triggered on save)
- Maintain consistency with existing code style
C++11 Compatibility Macros¶
The project provides a set of compatibility macros to ensure code compiles in both C++11 and C++17 environments.
Smart Pointers¶
1 2 | |
Container Iteration¶
1 2 3 4 | |
Compile-Time Constants¶
1 2 | |
Key Code Standards¶
1. Use override and final¶
Use standard C++ keywords instead of legacy macros:
1 2 3 4 5 | |
| Legacy Macro | New Keyword |
|---|---|
QWT_OVERRIDE |
override |
QWT_FINAL |
final |
2. Use nullptr Instead of NULL¶
1 2 3 4 5 | |
3. Use static_cast Instead of C-Style Casts¶
1 2 3 4 5 | |
4. Use using Instead of typedef¶
1 2 3 4 5 | |
5. Qt Container Iteration Standard¶
Use qwt_as_const to prevent Qt container deep copies:
1 2 3 4 5 | |
Important
Qt containers may undergo implicit sharing detachment (deep copy) during iteration. Using qwt_as_const avoids this issue.
Qt Development Best Practices¶
Signal-Slot Syntax¶
Use the Qt5+ signal-slot syntax:
1 2 3 4 5 | |
Q_PROPERTY Usage¶
Use the Q_PROPERTY macro correctly:
1 2 3 4 5 6 7 8 9 10 11 12 | |
Keyword Usage Standards¶
Use the macros officially recommended by Qt:
1 2 3 4 | |
Prohibited
Do not use lowercase macros such as slot or signal, as they may cause issues with certain compilers.
Naming Conventions¶
Class Names¶
- Use camel case with an uppercase first letter
- Prefix with
Qwt:QwtPlotCurve
Method Names¶
- Use camel case with a lowercase first letter
- No
getprefix for getters:boundingRect() - Use
setprefix for setters:setSamples()
Variable Names¶
- Member variables use the
m_prefix:m_data - Local variables use camel case:
sampleCount - Constants use all uppercase:
MAX_WIDTH