summaryrefslogtreecommitdiffstats
path: root/src/gui/painting/qcolor.h
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@kdab.com>2016-08-19 09:48:14 +0200
committerMarc Mutz <marc.mutz@kdab.com>2016-09-23 04:39:41 +0000
commit0889e9da20b8f016795ec2e7352b1e2f1678098d (patch)
treef311b708338554057dec9e5ba758c8cb18ac2c07 /src/gui/painting/qcolor.h
parentceb3c2ea621a5c5542eb6d127625a934b865e869 (diff)
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 <edward.welbourne@qt.io> Reviewed-by: Anton Kudryavtsev <a.kudryavtsev@netris.ru>
Diffstat (limited to 'src/gui/painting/qcolor.h')
-rw-r--r--src/gui/painting/qcolor.h13
1 files changed, 9 insertions, 4 deletions
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 <typename String>
+ 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); }