Skip to content

Commit

Permalink
qcolor-from-literal: Update documentation to includes more prescise c…
Browse files Browse the repository at this point in the history
…hecks and fixits
  • Loading branch information
alex1701c committed Jan 20, 2024
1 parent 90ffaba commit 27cc60a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
3 changes: 3 additions & 0 deletions .reuse/dep5
Original file line number Diff line number Diff line change
Expand Up @@ -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
24 changes: 21 additions & 3 deletions docs/checks/README-qcolor-from-literal.md
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
```

0 comments on commit 27cc60a

Please sign in to comment.