summaryrefslogtreecommitdiffstats
path: root/examples/corelib/serialization/convert
diff options
context:
space:
mode:
authorOlivier Goffart <ogoffart@woboq.com>2019-12-02 17:54:48 +0100
committerOlivier Goffart <ogoffart@woboq.com>2020-01-23 16:46:51 +0100
commit73d1476fb1397948a4d806bd921fce372bd8d63b (patch)
treea476349c26627027d78c1279da00ef633323311f /examples/corelib/serialization/convert
parenta78d66743171557d79b16c08be775e3ac15bb4ef (diff)
Replace most use of QVariant::type and occurrences of QVariant::Type
I made a clazy automated check that replaced the use of QVariant::Type by the equivalent in QMetaType. This has been deprecated since Qt 5.0, but many uses were not yet removed. In addition, there was some manual changes to fix the compilation errors. Adapted the Private API of QDateTimeParser and QMimeDataPrivate and adjust QDateTimeEdit and QSpinBox. QVariant(QVariant::Invalid) in qstylesheet made no sense. But note that in QVariant::save, we actually wanted to use the non-user type. In the SQL module, many changes were actually reverted because the API still expects QVarient::Type. Change-Id: I98c368490e4ee465ed3a3b63bda8b8eaa50ea67e Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'examples/corelib/serialization/convert')
-rw-r--r--examples/corelib/serialization/convert/cborconverter.cpp4
-rw-r--r--examples/corelib/serialization/convert/datastreamconverter.cpp6
-rw-r--r--examples/corelib/serialization/convert/textconverter.cpp6
-rw-r--r--examples/corelib/serialization/convert/xmlconverter.cpp20
4 files changed, 18 insertions, 18 deletions
diff --git a/examples/corelib/serialization/convert/cborconverter.cpp b/examples/corelib/serialization/convert/cborconverter.cpp
index 60410ed26a..77df367e50 100644
--- a/examples/corelib/serialization/convert/cborconverter.cpp
+++ b/examples/corelib/serialization/convert/cborconverter.cpp
@@ -134,7 +134,7 @@ static QVariant convertCborValue(const QCborValue &value)
enum TrimFloatingPoint { Double, Float, Float16 };
static QCborValue convertFromVariant(const QVariant &v, TrimFloatingPoint fpTrimming)
{
- if (v.userType() == QVariant::List) {
+ if (v.userType() == QMetaType::QVariantList) {
const QVariantList list = v.toList();
QCborArray array;
for (const QVariant &v : list)
@@ -152,7 +152,7 @@ static QCborValue convertFromVariant(const QVariant &v, TrimFloatingPoint fpTrim
return map;
}
- if (v.userType() == QVariant::Double && fpTrimming != Double) {
+ if (v.userType() == QMetaType::Double && fpTrimming != Double) {
float f = float(v.toDouble());
if (fpTrimming == Float16)
return float(qfloat16(f));
diff --git a/examples/corelib/serialization/convert/datastreamconverter.cpp b/examples/corelib/serialization/convert/datastreamconverter.cpp
index 7e9f5e1bdc..6f0ca41ff5 100644
--- a/examples/corelib/serialization/convert/datastreamconverter.cpp
+++ b/examples/corelib/serialization/convert/datastreamconverter.cpp
@@ -96,8 +96,8 @@ static QString dumpVariant(const QVariant &v, const QString &indent = QLatin1Str
QString indented = indent + QLatin1String(" ");
int type = v.userType();
- if (type == qMetaTypeId<VariantOrderedMap>() || type == QVariant::Map) {
- const auto map = (type == QVariant::Map) ?
+ if (type == qMetaTypeId<VariantOrderedMap>() || type == QMetaType::QVariantMap) {
+ const auto map = (type == QMetaType::QVariantMap) ?
VariantOrderedMap(v.toMap()) : qvariant_cast<VariantOrderedMap>(v);
result = QLatin1String("Map {");
@@ -109,7 +109,7 @@ static QString dumpVariant(const QVariant &v, const QString &indent = QLatin1Str
}
result.chop(1); // remove comma
result += indent + QLatin1String("},");
- } else if (type == QVariant::List) {
+ } else if (type == QMetaType::QVariantList) {
const QVariantList list = v.toList();
result = QLatin1String("List [");
diff --git a/examples/corelib/serialization/convert/textconverter.cpp b/examples/corelib/serialization/convert/textconverter.cpp
index 7aed08f96c..ae03b9a334 100644
--- a/examples/corelib/serialization/convert/textconverter.cpp
+++ b/examples/corelib/serialization/convert/textconverter.cpp
@@ -56,21 +56,21 @@
static void dumpVariant(QTextStream &out, const QVariant &v)
{
switch (v.userType()) {
- case QVariant::List: {
+ case QMetaType::QVariantList: {
const QVariantList list = v.toList();
for (const QVariant &item : list)
dumpVariant(out, item);
break;
}
- case QVariant::String: {
+ case QMetaType::QString: {
const QStringList list = v.toStringList();
for (const QString &s : list)
out << s << Qt::endl;
break;
}
- case QVariant::Map: {
+ case QMetaType::QVariantMap: {
const QVariantMap map = v.toMap();
for (auto it = map.begin(); it != map.end(); ++it) {
out << it.key() << " => ";
diff --git a/examples/corelib/serialization/convert/xmlconverter.cpp b/examples/corelib/serialization/convert/xmlconverter.cpp
index d9e724dfe1..42cb10100a 100644
--- a/examples/corelib/serialization/convert/xmlconverter.cpp
+++ b/examples/corelib/serialization/convert/xmlconverter.cpp
@@ -284,18 +284,18 @@ static QVariant variantFromXml(QXmlStreamReader &xml, Converter::Options options
ba.resize(n);
result = ba;
} else {
- int id = QVariant::Invalid;
+ int id = QMetaType::UnknownType;
if (type == QLatin1String("datetime"))
- id = QVariant::DateTime;
+ id = QMetaType::QDateTime;
else if (type == QLatin1String("url"))
- id = QVariant::Url;
+ id = QMetaType::QUrl;
else if (type == QLatin1String("uuid"))
- id = QVariant::Uuid;
+ id = QMetaType::QUuid;
else if (type == QLatin1String("regex"))
- id = QVariant::RegularExpression;
+ id = QMetaType::QRegularExpression;
else
id = QMetaType::type(type.toLatin1());
- if (id == QVariant::Invalid) {
+ if (id == QMetaType::UnknownType) {
fprintf(stderr, "%lld:%lld: Invalid XML: unknown type '%s'.\n",
xml.lineNumber(), xml.columnNumber(), qPrintable(type.toString()));
exit(EXIT_FAILURE);
@@ -327,14 +327,14 @@ static QVariant variantFromXml(QXmlStreamReader &xml, Converter::Options options
static void variantToXml(QXmlStreamWriter &xml, const QVariant &v)
{
int type = v.userType();
- if (type == QVariant::List) {
+ if (type == QMetaType::QVariantList) {
QVariantList list = v.toList();
xml.writeStartElement("list");
for (const QVariant &v : list)
variantToXml(xml, v);
xml.writeEndElement();
- } else if (type == QVariant::Map || type == qMetaTypeId<VariantOrderedMap>()) {
- const VariantOrderedMap map = (type == QVariant::Map) ?
+ } else if (type == QMetaType::QVariantMap || type == qMetaTypeId<VariantOrderedMap>()) {
+ const VariantOrderedMap map = (type == QMetaType::QVariantMap) ?
VariantOrderedMap(v.toMap()) :
qvariant_cast<VariantOrderedMap>(v);
@@ -433,7 +433,7 @@ static void variantToXml(QXmlStreamWriter &xml, const QVariant &v)
// does this convert to string?
const char *typeName = v.typeName();
QVariant copy = v;
- if (copy.convert(QVariant::String)) {
+ if (copy.convert(QMetaType::QString)) {
xml.writeAttribute(typeString, QString::fromLatin1(typeName));
xml.writeCharacters(copy.toString());
} else {