Coding Standards¶
Qwt source follows the rules below for formatting, C++ version compatibility, naming and Qt usage.
Key Requirements¶
Qwt source is formatted with the .clang-format configuration, uses the project's C++11 compatibility macros, prefers modern syntax such as override, nullptr and using, and follows Qt development guidelines.
Code Formatting¶
The project uses a .clang-format configuration file for code formatting.
Tip — 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¶
Use qwt_make_unique to create a std::unique_ptr in a C++11-compatible way, as shown below:
1 2 | |
Container Iteration¶
Wrap Qt containers with qwt_as_const when iterating to avoid implicit-sharing deep copies:
1 2 3 4 | |
Compile-Time Constants¶
Declare compile-time constants with constexpr, as shown below:
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¶
Declare null pointers with nullptr instead of NULL:
1 2 3 4 5 | |
3. Use static_cast Instead of C-Style Casts¶
Convert with static_cast<>:
1 2 3 4 5 | |
4. Use using Instead of typedef¶
Replace typedef with a using alias:
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 | |
Warning — Important
Qt containers may undergo implicit sharing detachment (deep copy) during iteration. Using
qwt_as_constavoids 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 | |
Warning — Prohibited
Do not use lowercase macros such as
slotorsignal, 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