diff --git a/src/gui/painting/qcolor.cpp b/src/gui/painting/qcolor.cpp index 653e56a3c8..4e7cb78624 100644 --- a/src/gui/painting/qcolor.cpp +++ b/src/gui/painting/qcolor.cpp @@ -994,7 +994,7 @@ bool QColor::isValidColor(QLatin1String name) noexcept */ bool QColor::isValidColorName(QAnyStringView name) noexcept { - return name.size() && QColor().setColorFromString(name); + return fromString(name).isValid(); } /*! @@ -1024,40 +1024,19 @@ bool QColor::isValidColorName(QAnyStringView name) noexcept */ QColor QColor::fromString(QAnyStringView name) noexcept { - QColor c; - c.setColorFromString(name); - return c; -} - -bool QColor::setColorFromString(QAnyStringView name) noexcept -{ - if (!name.size()) { - invalidate(); - return true; - } + if (!name.size()) + return {}; if (name.front() == u'#') { - QRgba64 rgba; - if (get_hex_rgb(name, &rgba)) { - setRgba64(rgba); - return true; - } else { - invalidate(); - return false; - } + if (QRgba64 r; get_hex_rgb(name, &r)) + return QColor::fromRgba64(r); +#ifndef QT_NO_COLORNAMES + } else if (QRgb r; get_named_rgb(name, &r)) { + return QColor::fromRgba(r); +#endif } -#ifndef QT_NO_COLORNAMES - QRgb rgb; - if (get_named_rgb(name, &rgb)) { - setRgba(rgb); - return true; - } else -#endif - { - invalidate(); - return false; - } + return {}; } /*! diff --git a/src/gui/painting/qcolor.h b/src/gui/painting/qcolor.h index a2ff932460..5bb4da87cf 100644 --- a/src/gui/painting/qcolor.h +++ b/src/gui/painting/qcolor.h @@ -231,7 +231,6 @@ public: private: void invalidate() noexcept; - bool setColorFromString(QAnyStringView) noexcept; static constexpr bool isRgbaValid(int r, int g, int b, int a = 255) noexcept Q_DECL_CONST_FUNCTION {