Get rid of the custom debug stream handling in QVariant

Use the builtin support in QMetaType instead.

Change-Id: Ifc0e88719a384aa7fb525652bada22b6f7ee1c45
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
This commit is contained in:
Lars Knoll 2020-07-06 21:52:06 +02:00
parent ed8acbeb7c
commit ef6c5f29ab
5 changed files with 6 additions and 138 deletions

View File

@ -1378,35 +1378,13 @@ static bool convert(const QVariant::Private *d, int t, void *result, bool *ok)
return true;
}
#if !defined(QT_NO_DEBUG_STREAM)
static void streamDebug(QDebug dbg, const QVariant &v)
{
QVariant::Private *d = const_cast<QVariant::Private *>(&v.data_ptr());
QVariantDebugStream<CoreTypesFilter> stream(dbg, d);
QMetaTypeSwitcher::switcher<void>(stream, d->type().id());
}
#endif
const QVariant::Handler qt_kernel_variant_handler = {
convert,
#if !defined(QT_NO_DEBUG_STREAM)
streamDebug
#else
nullptr
#endif
convert
};
static bool dummyConvert(const QVariant::Private *, int, void *, bool *) { Q_ASSERT_X(false, "QVariant", "Trying to convert an unknown type"); return false; }
#if !defined(QT_NO_DEBUG_STREAM)
static void dummyStreamDebug(QDebug, const QVariant &) { Q_ASSERT_X(false, "QVariant", "Trying to convert an unknown type"); }
#endif
const QVariant::Handler qt_dummy_variant_handler = {
dummyConvert,
#if !defined(QT_NO_DEBUG_STREAM)
dummyStreamDebug
#else
nullptr
#endif
};
// the type of d has already been set, but other field are not set
@ -1464,26 +1442,8 @@ static bool customConvert(const QVariant::Private *d, int t, void *result, bool
return convert(d, t, result, ok);
}
#if !defined(QT_NO_DEBUG_STREAM)
static void customStreamDebug(QDebug dbg, const QVariant &variant) {
#ifndef QT_BOOTSTRAPPED
QMetaType::TypeFlags flags = QMetaType::typeFlags(variant.userType());
if (flags & QMetaType::PointerToQObject)
dbg.nospace() << qvariant_cast<QObject*>(variant);
#else
Q_UNUSED(dbg);
Q_UNUSED(variant);
#endif
}
#endif
const QVariant::Handler qt_custom_variant_handler = {
customConvert,
#if !defined(QT_NO_DEBUG_STREAM)
customStreamDebug
#else
nullptr
#endif
customConvert
};
} // annonymous used to hide QVariant handlers
@ -3975,16 +3935,9 @@ QDebug operator<<(QDebug dbg, const QVariant &v)
dbg.nospace() << "QVariant(";
if (typeId != QMetaType::UnknownType) {
dbg << QMetaType::typeName(typeId) << ", ";
bool userStream = false;
bool canConvertToString = false;
if (typeId >= QMetaType::User) {
userStream = v.d.type().debugStream(dbg, constData(v.d));
canConvertToString = v.canConvert<QString>();
}
if (!userStream && canConvertToString)
bool streamed = v.d.type().debugStream(dbg, constData(v.d));
if (!streamed && v.canConvert<QString>())
dbg << v.toString();
else if (!userStream)
handlerManager[typeId]->debugStream(dbg, v);
} else {
dbg << "Invalid";
}

View File

@ -469,10 +469,8 @@ class Q_CORE_EXPORT QVariant
};
public:
typedef bool (*f_convert)(const QVariant::Private *d, int t, void *, bool *);
typedef void (*f_debugStream)(QDebug, const QVariant &);
struct Handler {
f_convert convert;
f_debugStream debugStream;
};
inline bool operator==(const QVariant &v) const

View File

@ -55,7 +55,6 @@
#include <QtCore/qglobal.h>
#include <QtCore/qvariant.h>
#include <QtCore/private/qmetatype_p.h>
#include <QtCore/qdebug.h>
#include "qmetatypeswitcher_p.h"
@ -188,55 +187,6 @@ namespace QVariantPrivate {
Q_CORE_EXPORT void registerHandler(const int /* Modules::Names */ name, const QVariant::Handler *handler);
}
#if !defined(QT_NO_DEBUG_STREAM)
template<class Filter>
class QVariantDebugStream
{
template<typename T, bool IsAcceptedType = Filter::template Acceptor<T>::IsAccepted>
struct Filtered {
Filtered(QDebug dbg, QVariant::Private *d)
{
dbg.nospace() << *v_cast<T>(d);
}
};
template<typename T>
struct Filtered<T, /* IsAcceptedType = */ false> {
Filtered(QDebug /* dbg */, QVariant::Private *)
{
// It is not possible to construct not acccepted type, QVariantConstructor creates an invalid variant for them
Q_ASSERT(false);
}
};
public:
QVariantDebugStream(QDebug dbg, QVariant::Private *d)
: m_debugStream(dbg)
, m_d(d)
{}
template<typename T>
void delegate(const T*)
{
Filtered<T> streamIt(m_debugStream, m_d);
Q_UNUSED(streamIt);
}
void delegate(const QMetaTypeSwitcher::NotBuiltinType*)
{
// QVariantDebugStream class is used only for a built-in type
Q_ASSERT(false);
}
void delegate(const QMetaTypeSwitcher::UnknownType*)
{
m_debugStream.nospace() << "QVariant::Invalid";
}
void delegate(const void*) { Q_ASSERT(false); }
private:
QDebug m_debugStream;
QVariant::Private *m_d;
};
#endif
QT_END_NAMESPACE
#endif // QVARIANT_P_H

View File

@ -233,22 +233,8 @@ static bool convert(const QVariant::Private *d, int t,
return qcoreVariantHandler()->convert(d, t, result, ok);
}
#if !defined(QT_NO_DEBUG_STREAM)
static void streamDebug(QDebug dbg, const QVariant &v)
{
QVariant::Private *d = const_cast<QVariant::Private *>(&v.data_ptr());
QVariantDebugStream<GuiTypesFilter> stream(dbg, d);
QMetaTypeSwitcher::switcher<void>(stream, d->type().id(), nullptr);
}
#endif
const QVariant::Handler qt_gui_variant_handler = {
convert,
#if !defined(QT_NO_DEBUG_STREAM)
streamDebug
#else
nullptr
#endif
convert
};
#define QT_IMPL_METATYPEINTERFACE_GUI_TYPES(MetaTypeName, MetaTypeId, RealName) \

View File

@ -59,27 +59,8 @@ static bool convert(const QVariant::Private *d, int type, void *result, bool *ok
return false;
}
#if !defined(QT_NO_DEBUG_STREAM)
static void streamDebug(QDebug dbg, const QVariant &v)
{
QVariant::Private *d = const_cast<QVariant::Private *>(&v.data_ptr());
switch (d->type().id()) {
case QMetaType::QSizePolicy:
dbg.nospace() << *v_cast<QSizePolicy>(d);
break;
default:
dbg.nospace() << "QMetaType::Type(" << d->type().id() << ')';
}
}
#endif
static const QVariant::Handler widgets_handler = {
convert,
#if !defined(QT_NO_DEBUG_STREAM)
streamDebug
#else
nullptr
#endif
convert
};
static const struct : QMetaTypeModuleHelper