-
-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
qcolor-from-literal: Update documentation to includes more prescise c…
…hecks and fixits
- Loading branch information
Showing
2 changed files
with
24 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,3 +7,6 @@ Files: tests/qcolor-from-literal/* | |
Copyright: Alexander Lohnau <[email protected]> | ||
License: CC0-1.0 | ||
|
||
Files: docs/checks/README-qcolor-from-literal.md | ||
Copyright: Alexander Lohnau <[email protected]> | ||
License: CC0-1.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,28 @@ | ||
# qcolor-from-literal | ||
|
||
Warns when a `QColor` is being constructed from a string literal such as "#RRGGBB". | ||
Next to the constructor call, this includes QColor::setNamedColor and the static QColor::fromString method. | ||
This is less performant than calling the ctor that takes `int`s, since it creates temporary `QString`s. | ||
Also, the pattern is checked in regards to it only containing hexadecimal values and being of a supported length. | ||
|
||
Example: | ||
### Fixits | ||
This check provides fixits for #RGB, #RRGGBB and #AARRGGBB patterns. | ||
For QColor object needing more precision, you should manually create a QRgba64 object. | ||
|
||
`QColor c("#000000");` // Use QColor c(0, 0, 0) instead | ||
For example: | ||
``` | ||
testfile.cpp:92:16: warning: The QColor ctor taking RGB int value is cheaper than one taking string literals [-Wclazy-qcolor-from-literal] | ||
QColor("#123"); | ||
^~~~~~ | ||
0x112233 | ||
`c.setNamedColor("#001122");` // Use c = QColor(0, 0x11, 0x22) instead | ||
testfile.cpp:93:16: warning: The QColor ctor taking RGB int value is cheaper than one taking string literals [-Wclazy-qcolor-from-lite | ||
QColor("#112233"); | ||
^~~~~~~~~ | ||
0x112233 | ||
testfile.cpp:92:16: warning: The QColor ctor taking ints is cheaper than one taking string literals [-Wclazy-qcolor-from-literal] | ||
QColor("#9931363b"); | ||
^~~~~~~~~~~ | ||
0x31, 0x36, 0x3b, 0x99 | ||
``` |