Get rid of the additional bool * parameter to the internal convert method
That parameter is duplicating the return value, get rid of it. Change-Id: I8d6ecee8aca90aecaf08e6d0072d83e9a08ce3d6 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
parent
47b5821c4e
commit
7f009b648f
@ -372,22 +372,17 @@ static QMetaEnum metaEnumFromType(QMetaType t)
|
|||||||
|
|
||||||
Converts \a d to type \a t, which is placed in \a result.
|
Converts \a d to type \a t, which is placed in \a result.
|
||||||
*/
|
*/
|
||||||
static bool convert(const QVariant::Private *d, int t, void *result, bool *ok)
|
static bool convert(const QVariant::Private *d, int t, void *result)
|
||||||
{
|
{
|
||||||
Q_ASSERT(d->type().id() != t);
|
Q_ASSERT(d->type().id() != t);
|
||||||
Q_ASSERT(result);
|
Q_ASSERT(result);
|
||||||
|
|
||||||
if (d->type().id() >= QMetaType::User || t >= QMetaType::User) {
|
if (d->type().id() >= QMetaType::User || t >= QMetaType::User) {
|
||||||
const bool isOk = QMetaType::convert(constData(*d), d->type().id(), result, t);
|
if (QMetaType::convert(constData(*d), d->type().id(), result, t))
|
||||||
if (ok)
|
|
||||||
*ok = isOk;
|
|
||||||
if (isOk)
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool dummy;
|
bool ok = true;
|
||||||
if (!ok)
|
|
||||||
ok = &dummy;
|
|
||||||
|
|
||||||
switch (uint(t)) {
|
switch (uint(t)) {
|
||||||
#ifndef QT_BOOTSTRAPPED
|
#ifndef QT_BOOTSTRAPPED
|
||||||
@ -504,8 +499,8 @@ static bool convert(const QVariant::Private *d, int t, void *result, bool *ok)
|
|||||||
{
|
{
|
||||||
QMetaEnum en = metaEnumFromType(d->type());
|
QMetaEnum en = metaEnumFromType(d->type());
|
||||||
if (en.isValid()) {
|
if (en.isValid()) {
|
||||||
*str = QString::fromUtf8(en.valueToKey(qConvertToNumber(d, ok)));
|
*str = QString::fromUtf8(en.valueToKey(qConvertToNumber(d, &ok)));
|
||||||
return *ok;
|
return ok;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -705,8 +700,8 @@ static bool convert(const QVariant::Private *d, int t, void *result, bool *ok)
|
|||||||
{
|
{
|
||||||
QMetaEnum en = metaEnumFromType(d->type());
|
QMetaEnum en = metaEnumFromType(d->type());
|
||||||
if (en.isValid()) {
|
if (en.isValid()) {
|
||||||
*ba = en.valueToKey(qConvertToNumber(d, ok));
|
*ba = en.valueToKey(qConvertToNumber(d, &ok));
|
||||||
return *ok;
|
return ok;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -715,38 +710,38 @@ static bool convert(const QVariant::Private *d, int t, void *result, bool *ok)
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case QMetaType::Short:
|
case QMetaType::Short:
|
||||||
*static_cast<short *>(result) = short(qConvertToNumber(d, ok));
|
*static_cast<short *>(result) = short(qConvertToNumber(d, &ok));
|
||||||
return *ok;
|
return ok;
|
||||||
case QMetaType::Long:
|
case QMetaType::Long:
|
||||||
*static_cast<long *>(result) = long(qConvertToNumber(d, ok));
|
*static_cast<long *>(result) = long(qConvertToNumber(d, &ok));
|
||||||
return *ok;
|
return ok;
|
||||||
case QMetaType::UShort:
|
case QMetaType::UShort:
|
||||||
*static_cast<ushort *>(result) = ushort(qConvertToUnsignedNumber(d, ok));
|
*static_cast<ushort *>(result) = ushort(qConvertToUnsignedNumber(d, &ok));
|
||||||
return *ok;
|
return ok;
|
||||||
case QMetaType::ULong:
|
case QMetaType::ULong:
|
||||||
*static_cast<ulong *>(result) = ulong(qConvertToUnsignedNumber(d, ok));
|
*static_cast<ulong *>(result) = ulong(qConvertToUnsignedNumber(d, &ok));
|
||||||
return *ok;
|
return ok;
|
||||||
case QMetaType::Int:
|
case QMetaType::Int:
|
||||||
*static_cast<int *>(result) = int(qConvertToNumber(d, ok));
|
*static_cast<int *>(result) = int(qConvertToNumber(d, &ok));
|
||||||
return *ok;
|
return ok;
|
||||||
case QMetaType::UInt:
|
case QMetaType::UInt:
|
||||||
*static_cast<uint *>(result) = uint(qConvertToUnsignedNumber(d, ok));
|
*static_cast<uint *>(result) = uint(qConvertToUnsignedNumber(d, &ok));
|
||||||
return *ok;
|
return ok;
|
||||||
case QMetaType::LongLong:
|
case QMetaType::LongLong:
|
||||||
*static_cast<qlonglong *>(result) = qConvertToNumber(d, ok);
|
*static_cast<qlonglong *>(result) = qConvertToNumber(d, &ok);
|
||||||
return *ok;
|
return ok;
|
||||||
case QMetaType::ULongLong: {
|
case QMetaType::ULongLong: {
|
||||||
*static_cast<qulonglong *>(result) = qConvertToUnsignedNumber(d, ok);
|
*static_cast<qulonglong *>(result) = qConvertToUnsignedNumber(d, &ok);
|
||||||
return *ok;
|
return ok;
|
||||||
}
|
}
|
||||||
case QMetaType::SChar: {
|
case QMetaType::SChar: {
|
||||||
signed char s = qConvertToNumber(d, ok);
|
signed char s = qConvertToNumber(d, &ok);
|
||||||
*static_cast<signed char*>(result) = s;
|
*static_cast<signed char*>(result) = s;
|
||||||
return *ok;
|
return ok;
|
||||||
}
|
}
|
||||||
case QMetaType::UChar: {
|
case QMetaType::UChar: {
|
||||||
*static_cast<uchar *>(result) = qConvertToUnsignedNumber(d, ok);
|
*static_cast<uchar *>(result) = qConvertToUnsignedNumber(d, &ok);
|
||||||
return *ok;
|
return ok;
|
||||||
}
|
}
|
||||||
case QMetaType::Bool: {
|
case QMetaType::Bool: {
|
||||||
bool *b = static_cast<bool *>(result);
|
bool *b = static_cast<bool *>(result);
|
||||||
@ -799,11 +794,11 @@ static bool convert(const QVariant::Private *d, int t, void *result, bool *ok)
|
|||||||
double *f = static_cast<double *>(result);
|
double *f = static_cast<double *>(result);
|
||||||
switch (d->type().id()) {
|
switch (d->type().id()) {
|
||||||
case QMetaType::QString:
|
case QMetaType::QString:
|
||||||
*f = v_cast<QString>(d)->toDouble(ok);
|
*f = v_cast<QString>(d)->toDouble(&ok);
|
||||||
break;
|
return ok;
|
||||||
case QMetaType::QByteArray:
|
case QMetaType::QByteArray:
|
||||||
*f = v_cast<QByteArray>(d)->toDouble(ok);
|
*f = v_cast<QByteArray>(d)->toDouble(&ok);
|
||||||
break;
|
return ok;
|
||||||
case QMetaType::Bool:
|
case QMetaType::Bool:
|
||||||
*f = double(d->data.b);
|
*f = double(d->data.b);
|
||||||
break;
|
break;
|
||||||
@ -847,11 +842,11 @@ static bool convert(const QVariant::Private *d, int t, void *result, bool *ok)
|
|||||||
float *f = static_cast<float *>(result);
|
float *f = static_cast<float *>(result);
|
||||||
switch (d->type().id()) {
|
switch (d->type().id()) {
|
||||||
case QMetaType::QString:
|
case QMetaType::QString:
|
||||||
*f = v_cast<QString>(d)->toFloat(ok);
|
*f = v_cast<QString>(d)->toFloat(&ok);
|
||||||
break;
|
return ok;
|
||||||
case QMetaType::QByteArray:
|
case QMetaType::QByteArray:
|
||||||
*f = v_cast<QByteArray>(d)->toFloat(ok);
|
*f = v_cast<QByteArray>(d)->toFloat(&ok);
|
||||||
break;
|
return ok;
|
||||||
case QMetaType::Bool:
|
case QMetaType::Bool:
|
||||||
*f = float(d->data.b);
|
*f = float(d->data.b);
|
||||||
break;
|
break;
|
||||||
@ -994,8 +989,8 @@ static bool convert(const QVariant::Private *d, int t, void *result, bool *ok)
|
|||||||
break;
|
break;
|
||||||
case QMetaType::Char:
|
case QMetaType::Char:
|
||||||
{
|
{
|
||||||
*static_cast<qint8 *>(result) = qint8(qConvertToNumber(d, ok));
|
*static_cast<qint8 *>(result) = qint8(qConvertToNumber(d, &ok));
|
||||||
return *ok;
|
return ok;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
case QMetaType::QUuid:
|
case QMetaType::QUuid:
|
||||||
@ -1060,7 +1055,7 @@ static bool convert(const QVariant::Private *d, int t, void *result, bool *ok)
|
|||||||
case QMetaType::Char:
|
case QMetaType::Char:
|
||||||
case QMetaType::SChar:
|
case QMetaType::SChar:
|
||||||
case QMetaType::Short:
|
case QMetaType::Short:
|
||||||
*static_cast<QJsonValue *>(result) = QJsonValue(qConvertToRealNumber(d, ok));
|
*static_cast<QJsonValue *>(result) = QJsonValue(qConvertToRealNumber(d, &ok));
|
||||||
Q_ASSERT(ok);
|
Q_ASSERT(ok);
|
||||||
break;
|
break;
|
||||||
case QMetaType::QString:
|
case QMetaType::QString:
|
||||||
@ -1188,12 +1183,12 @@ static bool convert(const QVariant::Private *d, int t, void *result, bool *ok)
|
|||||||
case QMetaType::Char:
|
case QMetaType::Char:
|
||||||
case QMetaType::SChar:
|
case QMetaType::SChar:
|
||||||
case QMetaType::Short:
|
case QMetaType::Short:
|
||||||
*static_cast<QCborValue *>(result) = QCborValue(qConvertToNumber(d, ok));
|
*static_cast<QCborValue *>(result) = QCborValue(qConvertToNumber(d, &ok));
|
||||||
Q_ASSERT(ok);
|
Q_ASSERT(ok);
|
||||||
break;
|
break;
|
||||||
case QMetaType::Double:
|
case QMetaType::Double:
|
||||||
case QMetaType::Float:
|
case QMetaType::Float:
|
||||||
*static_cast<QCborValue *>(result) = QCborValue(qConvertToRealNumber(d, ok));
|
*static_cast<QCborValue *>(result) = QCborValue(qConvertToRealNumber(d, &ok));
|
||||||
Q_ASSERT(ok);
|
Q_ASSERT(ok);
|
||||||
break;
|
break;
|
||||||
case QMetaType::QString:
|
case QMetaType::QString:
|
||||||
@ -1332,8 +1327,8 @@ static bool convert(const QVariant::Private *d, int t, void *result, bool *ok)
|
|||||||
QByteArray keys = (d->type().id() == QMetaType::QString)
|
QByteArray keys = (d->type().id() == QMetaType::QString)
|
||||||
? v_cast<QString>(d)->toUtf8()
|
? v_cast<QString>(d)->toUtf8()
|
||||||
: *v_cast<QByteArray>(d);
|
: *v_cast<QByteArray>(d);
|
||||||
int value = en.keysToValue(keys.constData(), ok);
|
int value = en.keysToValue(keys.constData(), &ok);
|
||||||
if (*ok) {
|
if (ok) {
|
||||||
switch (QMetaType::sizeOf(t)) {
|
switch (QMetaType::sizeOf(t)) {
|
||||||
case 1:
|
case 1:
|
||||||
*static_cast<signed char *>(result) = value;
|
*static_cast<signed char *>(result) = value;
|
||||||
@ -1354,8 +1349,8 @@ static bool convert(const QVariant::Private *d, int t, void *result, bool *ok)
|
|||||||
#endif
|
#endif
|
||||||
if (QMetaType::typeFlags(t) & QMetaType::IsEnumeration
|
if (QMetaType::typeFlags(t) & QMetaType::IsEnumeration
|
||||||
|| d->type().id() == QMetaType::QCborSimpleType) {
|
|| d->type().id() == QMetaType::QCborSimpleType) {
|
||||||
qlonglong value = qConvertToNumber(d, ok);
|
qlonglong value = qConvertToNumber(d, &ok);
|
||||||
if (*ok) {
|
if (ok) {
|
||||||
switch (QMetaType::sizeOf(t)) {
|
switch (QMetaType::sizeOf(t)) {
|
||||||
case 1:
|
case 1:
|
||||||
*static_cast<signed char *>(result) = value;
|
*static_cast<signed char *>(result) = value;
|
||||||
@ -1371,7 +1366,7 @@ static bool convert(const QVariant::Private *d, int t, void *result, bool *ok)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return *ok;
|
return ok;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -1382,7 +1377,8 @@ const QVariant::Handler qt_kernel_variant_handler = {
|
|||||||
convert
|
convert
|
||||||
};
|
};
|
||||||
|
|
||||||
static bool dummyConvert(const QVariant::Private *, int, void *, bool *) { Q_ASSERT_X(false, "QVariant", "Trying to convert an unknown type"); return false; }
|
static bool dummyConvert(const QVariant::Private *, int, void *)
|
||||||
|
{ Q_ASSERT_X(false, "QVariant", "Trying to convert an unknown type"); return false; }
|
||||||
const QVariant::Handler qt_dummy_variant_handler = {
|
const QVariant::Handler qt_dummy_variant_handler = {
|
||||||
dummyConvert,
|
dummyConvert,
|
||||||
};
|
};
|
||||||
@ -1421,16 +1417,14 @@ static void customClear(QVariant::Private *d)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool customConvert(const QVariant::Private *d, int t, void *result, bool *ok)
|
static bool customConvert(const QVariant::Private *d, int t, void *result)
|
||||||
{
|
{
|
||||||
if (d->type().id() >= QMetaType::User || t >= QMetaType::User) {
|
if (d->type().id() >= QMetaType::User || t >= QMetaType::User) {
|
||||||
if (QMetaType::convert(constData(*d), d->type().id(), result, t)) {
|
if (QMetaType::convert(constData(*d), d->type().id(), result, t))
|
||||||
if (ok)
|
|
||||||
*ok = true;
|
|
||||||
return true;
|
return true;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return convert(d, t, result, ok);
|
|
||||||
|
return convert(d, t, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
const QVariant::Handler qt_custom_variant_handler = {
|
const QVariant::Handler qt_custom_variant_handler = {
|
||||||
@ -2542,7 +2536,7 @@ inline T qVariantToHelper(const QVariant::Private &d)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
handlerManager[d.type().id()]->convert(&d, targetType.id(), &ret, nullptr);
|
handlerManager[d.type().id()]->convert(&d, targetType.id(), &ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2975,8 +2969,9 @@ inline T qNumVariantToHelper(const QVariant::Private &d,
|
|||||||
&& QMetaType::convert(constData(d), d.type().id(), &ret, t))
|
&& QMetaType::convert(constData(d), d.type().id(), &ret, t))
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
if (!handlerManager[d.type().id()]->convert(&d, t, &ret, ok) && ok)
|
bool success = handlerManager[d.type().id()]->convert(&d, t, &ret);
|
||||||
*ok = false;
|
if (ok)
|
||||||
|
*ok = success;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3076,7 +3071,7 @@ bool QVariant::toBool() const
|
|||||||
return d.data.b;
|
return d.data.b;
|
||||||
|
|
||||||
bool res = false;
|
bool res = false;
|
||||||
handlerManager[d.type().id()]->convert(&d, Bool, &res, nullptr);
|
handlerManager[d.type().id()]->convert(&d, Bool, &res);
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
@ -3613,10 +3608,8 @@ bool QVariant::convert(int targetTypeId)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isOk = true;
|
|
||||||
int converterType = std::max(oldValue.userType(), targetTypeId);
|
int converterType = std::max(oldValue.userType(), targetTypeId);
|
||||||
if (!handlerManager[converterType]->convert(&oldValue.d, targetTypeId, data(), &isOk))
|
bool isOk = handlerManager[converterType]->convert(&oldValue.d, targetTypeId, data());
|
||||||
isOk = false;
|
|
||||||
d.is_null = !isOk;
|
d.is_null = !isOk;
|
||||||
return isOk;
|
return isOk;
|
||||||
}
|
}
|
||||||
@ -3628,7 +3621,7 @@ bool QVariant::convert(int targetTypeId)
|
|||||||
*/
|
*/
|
||||||
bool QVariant::convert(const int type, void *ptr) const
|
bool QVariant::convert(const int type, void *ptr) const
|
||||||
{
|
{
|
||||||
return handlerManager[type]->convert(&d, type, ptr, nullptr);
|
return handlerManager[type]->convert(&d, type, ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -499,7 +499,7 @@ class Q_CORE_EXPORT QVariant
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
public:
|
public:
|
||||||
typedef bool (*f_convert)(const QVariant::Private *d, int t, void *, bool *);
|
typedef bool (*f_convert)(const QVariant::Private *d, int t, void *);
|
||||||
struct Handler {
|
struct Handler {
|
||||||
f_convert convert;
|
f_convert convert;
|
||||||
};
|
};
|
||||||
|
@ -101,8 +101,7 @@ struct GuiTypesFilter {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
static bool convert(const QVariant::Private *d, int t,
|
static bool convert(const QVariant::Private *d, int t, void *result)
|
||||||
void *result, bool *ok)
|
|
||||||
{
|
{
|
||||||
switch (t) {
|
switch (t) {
|
||||||
case QMetaType::QByteArray:
|
case QMetaType::QByteArray:
|
||||||
@ -222,15 +221,13 @@ static bool convert(const QVariant::Private *d, int t,
|
|||||||
#endif
|
#endif
|
||||||
#ifndef QT_NO_ICON
|
#ifndef QT_NO_ICON
|
||||||
case QMetaType::QIcon: {
|
case QMetaType::QIcon: {
|
||||||
if (ok)
|
|
||||||
*ok = false;
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return qcoreVariantHandler()->convert(d, t, result, ok);
|
return qcoreVariantHandler()->convert(d, t, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
const QVariant::Handler qt_gui_variant_handler = {
|
const QVariant::Handler qt_gui_variant_handler = {
|
||||||
|
Loading…
Reference in New Issue
Block a user