QColor: clean up qcolor_p.h
Only qt_get_hex_rgb(const char*, QRgb*) is used outside qcolor.cpp (in qxpmhandler.cpp), so remove all other function declarations from qcolor_p.h, and make the functions file-static in qcolor.cpp, removing their qt_ prefix to avoid confusion. Exception: it turned out that qt_get_named_rgb(const char *, QRgb*) wasn't actually used anywhere, but a follow-up commit will fix this. Adjust interface to that of the QChar overload (add explicit int len). Simplify conditional compilation of QT_NO_COLORNAMES: move the ifdef inside get_colornames, to avoid duplicating the declaration, and remove the empty implementation of get_named_rgb, since their use is already conditional on QT_NO_COLORNAMES not being defined. Change-Id: Iaf685dfbea0b9d3bd010448dac0e95be7b097ce5 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
This commit is contained in:
parent
ced4d167a2
commit
a41393d0bc
@ -79,12 +79,12 @@ static inline int hex2int(char s)
|
||||
return h < 0 ? h : (h << 4) | h;
|
||||
}
|
||||
|
||||
bool qt_get_hex_rgb(const char *name, QRgb *rgb)
|
||||
static bool get_hex_rgb(const char *name, int len, QRgb *rgb)
|
||||
{
|
||||
if (name[0] != '#')
|
||||
return false;
|
||||
name++;
|
||||
int len = qstrlen(name);
|
||||
--len;
|
||||
int a, r, g, b;
|
||||
a = 255;
|
||||
if (len == 12) {
|
||||
@ -119,15 +119,19 @@ bool qt_get_hex_rgb(const char *name, QRgb *rgb)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool qt_get_hex_rgb(const QChar *str, int len, QRgb *rgb)
|
||||
bool qt_get_hex_rgb(const char *name, QRgb *rgb)
|
||||
{
|
||||
return get_hex_rgb(name, qstrlen(name), rgb);
|
||||
}
|
||||
|
||||
static bool get_hex_rgb(const QChar *str, int len, QRgb *rgb)
|
||||
{
|
||||
if (len > 13)
|
||||
return false;
|
||||
char tmp[16];
|
||||
for (int i = 0; i < len; ++i)
|
||||
tmp[i] = str[i].toLatin1();
|
||||
tmp[len] = 0;
|
||||
return qt_get_hex_rgb(tmp, rgb);
|
||||
return get_hex_rgb(tmp, len, rgb);
|
||||
}
|
||||
|
||||
#ifndef QT_NO_COLORNAMES
|
||||
@ -309,7 +313,7 @@ inline bool operator<(const char *name, const RGBData &data)
|
||||
inline bool operator<(const RGBData &data, const char *name)
|
||||
{ return qstrcmp(data.name, name) < 0; }
|
||||
|
||||
static bool get_named_rgb(const char *name_no_space, QRgb *rgb)
|
||||
static bool get_named_rgb_no_space(const char *name_no_space, QRgb *rgb)
|
||||
{
|
||||
const RGBData *r = std::lower_bound(rgbTbl, rgbTbl + rgbTblSize, name_no_space);
|
||||
if ((r != rgbTbl + rgbTblSize) && !(name_no_space < *r)) {
|
||||
@ -319,9 +323,9 @@ static bool get_named_rgb(const char *name_no_space, QRgb *rgb)
|
||||
return false;
|
||||
}
|
||||
|
||||
bool qt_get_named_rgb(const char *name, QRgb* rgb)
|
||||
#ifdef QCOLOR_THIS_IS_CURRENTLY_UNUSED_BUT_WILL_BE_USED_SOON
|
||||
static bool get_named_rgb(const char *name, int len, QRgb* rgb)
|
||||
{
|
||||
int len = int(strlen(name));
|
||||
if (len > 255)
|
||||
return false;
|
||||
char name_no_space[256];
|
||||
@ -332,10 +336,11 @@ bool qt_get_named_rgb(const char *name, QRgb* rgb)
|
||||
}
|
||||
name_no_space[pos] = 0;
|
||||
|
||||
return get_named_rgb(name_no_space, rgb);
|
||||
return get_named_rgb_no_space(name_no_space, rgb);
|
||||
}
|
||||
#endif
|
||||
|
||||
bool qt_get_named_rgb(const QChar *name, int len, QRgb *rgb)
|
||||
static bool get_named_rgb(const QChar *name, int len, QRgb *rgb)
|
||||
{
|
||||
if (len > 255)
|
||||
return false;
|
||||
@ -346,32 +351,22 @@ bool qt_get_named_rgb(const QChar *name, int len, QRgb *rgb)
|
||||
name_no_space[pos++] = name[i].toLower().toLatin1();
|
||||
}
|
||||
name_no_space[pos] = 0;
|
||||
return get_named_rgb(name_no_space, rgb);
|
||||
return get_named_rgb_no_space(name_no_space, rgb);
|
||||
}
|
||||
|
||||
QStringList qt_get_colornames()
|
||||
#endif // QT_NO_COLORNAMES
|
||||
|
||||
static QStringList get_colornames()
|
||||
{
|
||||
int i = 0;
|
||||
QStringList lst;
|
||||
#ifndef QT_NO_COLORNAMES
|
||||
lst.reserve(rgbTblSize);
|
||||
for (i = 0; i < rgbTblSize; i++)
|
||||
for (int i = 0; i < rgbTblSize; i++)
|
||||
lst << QLatin1String(rgbTbl[i].name);
|
||||
#endif
|
||||
return lst;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
bool qt_get_named_rgb(const char *, QRgb*)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
QStringList qt_get_colornames()
|
||||
{
|
||||
return QStringList();
|
||||
}
|
||||
#endif // QT_NO_COLORNAMES
|
||||
|
||||
/*!
|
||||
\class QColor
|
||||
\brief The QColor class provides colors based on RGB, HSV or CMYK values.
|
||||
@ -911,7 +906,7 @@ bool QColor::setColorFromString(const QString &name)
|
||||
|
||||
if (name.startsWith(QLatin1Char('#'))) {
|
||||
QRgb rgba;
|
||||
if (qt_get_hex_rgb(name.constData(), name.length(), &rgba)) {
|
||||
if (get_hex_rgb(name.constData(), name.length(), &rgba)) {
|
||||
setRgba(rgba);
|
||||
return true;
|
||||
} else {
|
||||
@ -922,7 +917,7 @@ bool QColor::setColorFromString(const QString &name)
|
||||
|
||||
#ifndef QT_NO_COLORNAMES
|
||||
QRgb rgb;
|
||||
if (qt_get_named_rgb(name.constData(), name.length(), &rgb)) {
|
||||
if (get_named_rgb(name.constData(), name.length(), &rgb)) {
|
||||
setRgba(rgb);
|
||||
return true;
|
||||
} else
|
||||
@ -940,11 +935,7 @@ bool QColor::setColorFromString(const QString &name)
|
||||
*/
|
||||
QStringList QColor::colorNames()
|
||||
{
|
||||
#ifndef QT_NO_COLORNAMES
|
||||
return qt_get_colornames();
|
||||
#else
|
||||
return QStringList();
|
||||
#endif
|
||||
return get_colornames();
|
||||
}
|
||||
|
||||
/*!
|
||||
|
@ -53,15 +53,10 @@
|
||||
|
||||
#include <QtGui/private/qtguiglobal_p.h>
|
||||
#include "QtGui/qrgb.h"
|
||||
#include "QtCore/qstringlist.h"
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
bool qt_get_named_rgb(const char *, QRgb*);
|
||||
bool qt_get_named_rgb(const QChar *, int len, QRgb*);
|
||||
bool qt_get_hex_rgb(const char *, QRgb *);
|
||||
bool qt_get_hex_rgb(const QChar *, int len, QRgb *);
|
||||
QStringList qt_get_colornames();
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user