From 0889e9da20b8f016795ec2e7352b1e2f1678098d Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Fri, 19 Aug 2016 09:48:14 +0200 Subject: QColor: provide QLatin1String overloads of functions taking QString The inefficiency of QColor(const char*) came to light by a recent refactoring which showed that the existing char* overload of qt_get_hex_rgb() was never called. So, provide a QLatin1String interface for named colors that allows user code to reach that internal function without converting to QString first. Change-Id: I74df7b570ef28c00e35ca4adf46c4b7c7e9994b3 Reviewed-by: Edward Welbourne Reviewed-by: Anton Kudryavtsev --- src/gui/painting/qcolor.h | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'src/gui/painting/qcolor.h') diff --git a/src/gui/painting/qcolor.h b/src/gui/painting/qcolor.h index 6cf3a8e262..db6eb92916 100644 --- a/src/gui/painting/qcolor.h +++ b/src/gui/painting/qcolor.h @@ -73,7 +73,8 @@ public: QColor(QRgb rgb) Q_DECL_NOTHROW; QColor(QRgba64 rgba64) Q_DECL_NOTHROW; QColor(const QString& name); - QColor(const char *name); + QColor(const char *aname) : QColor(QLatin1String(aname)) {} + QColor(QLatin1String name); QColor(Spec spec) Q_DECL_NOTHROW; #if QT_VERSION < QT_VERSION_CHECK(6,0,0) @@ -93,7 +94,9 @@ public: // ### Qt 6: merge overloads QString name() const; QString name(NameFormat format) const; + void setNamedColor(const QString& name); + void setNamedColor(QLatin1String name); static QStringList colorNames(); @@ -219,11 +222,13 @@ public: operator QVariant() const; static bool isValidColor(const QString &name); + static bool isValidColor(QLatin1String) Q_DECL_NOTHROW; private: void invalidate() Q_DECL_NOTHROW; - bool setColorFromString(const QString &name); + template + bool setColorFromString(const String &name); Spec cspec; union { @@ -272,8 +277,8 @@ inline QColor::QColor() Q_DECL_NOTHROW inline QColor::QColor(int r, int g, int b, int a) { setRgb(r, g, b, a); } -inline QColor::QColor(const char *aname) -{ setNamedColor(QLatin1String(aname)); } +inline QColor::QColor(QLatin1String aname) +{ setNamedColor(aname); } inline QColor::QColor(const QString& aname) { setNamedColor(aname); } -- cgit v1.2.3