summaryrefslogtreecommitdiffstats
path: root/src/gui/image
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@qt.io>2022-03-04 15:42:20 +0100
committerMarc Mutz <marc.mutz@qt.io>2022-03-08 05:51:11 +0000
commited5978effef3cc7138521d26946cab089aeb82b0 (patch)
treec05e105e0b001dd8c80da8be8ec6c5968e0c4dc5 /src/gui/image
parenta992f4b4c01883e34505e0eb4d03ee239fb839d1 (diff)
QColor: port string-parsing from out parameters to optional<>
Makes for easier reading of code, and allows qt_get_hex_rgb(), which is called from different TUs, to be marked as PURE. Change-Id: Ie7d4e5a164ca1daf521e18ff47f17885bc1443c1 Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Diffstat (limited to 'src/gui/image')
-rw-r--r--src/gui/image/qxpmhandler.cpp15
1 files changed, 6 insertions, 9 deletions
diff --git a/src/gui/image/qxpmhandler.cpp b/src/gui/image/qxpmhandler.cpp
index b9b0f443fa..ec3c7ce825 100644
--- a/src/gui/image/qxpmhandler.cpp
+++ b/src/gui/image/qxpmhandler.cpp
@@ -754,15 +754,12 @@ inline bool operator<(const char *name, const XPMRGBData &data)
inline bool operator<(const XPMRGBData &data, const char *name)
{ return qstrcmp(data.name, name) < 0; }
-static inline bool qt_get_named_xpm_rgb(const char *name_no_space, QRgb *rgb)
+static inline std::optional<QRgb> qt_get_named_xpm_rgb(const char *name_no_space)
{
const XPMRGBData *r = std::lower_bound(xpmRgbTbl, xpmRgbTbl + xpmRgbTblSize, name_no_space);
- if ((r != xpmRgbTbl + xpmRgbTblSize) && !(name_no_space < *r)) {
- *rgb = r->value;
- return true;
- } else {
- return false;
- }
+ if ((r != xpmRgbTbl + xpmRgbTblSize) && !(name_no_space < *r))
+ return r->value;
+ return {};
}
/*****************************************************************************
@@ -941,9 +938,9 @@ static bool read_xpm_body(
buf.truncate(((buf.length()-1) / 4 * 3) + 1); // remove alpha channel left by imagemagick
}
if (buf[0] == '#') {
- qt_get_hex_rgb(buf, &c_rgb);
+ c_rgb = qt_get_hex_rgb(buf).value_or(0);
} else {
- qt_get_named_xpm_rgb(buf, &c_rgb);
+ c_rgb = qt_get_named_xpm_rgb(buf).value_or(0);
}
if (ncols <= 256) {
image.setColor(currentColor, 0xff000000 | c_rgb);