Skip to content

Commit

Permalink
Remove deprecated API usage
Browse files Browse the repository at this point in the history
  • Loading branch information
dantti committed Jul 18, 2021
1 parent 10903d7 commit a36f56d
Show file tree
Hide file tree
Showing 11 changed files with 79 additions and 43 deletions.
12 changes: 6 additions & 6 deletions templates/defaultfilters/datetime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,11 @@ QVariant DateFilter::doFilter(const QVariant &input, const QVariant &argument,
{
Q_UNUSED(autoescape)
QDateTime d;
if (input.type() == QVariant::DateTime) {
if (input.userType() == QMetaType::QDateTime) {
d = input.toDateTime();
} else if (input.type() == QVariant::Date) {
} else if (input.userType() == QMetaType::QDate) {
d.setDate(input.toDate());
} else if (input.type() == QVariant::Time) {
} else if (input.userType() == QMetaType::QTime) {
d.setTime(input.toTime());
} else {
#if QT_VERSION < QT_VERSION_CHECK(5, 11, 0)
Expand All @@ -116,11 +116,11 @@ QVariant TimeFilter::doFilter(const QVariant &input, const QVariant &argument,
{
Q_UNUSED(autoescape)
QDateTime d;
if (input.type() == QVariant::DateTime) {
if (input.userType() == QMetaType::QDateTime) {
d = input.toDateTime();
} else if (input.type() == QVariant::Date) {
} else if (input.userType() == QMetaType::QDate) {
d.setDate(input.toDate());
} else if (input.type() == QVariant::Time) {
} else if (input.userType() == QMetaType::QTime) {
d.setTime(input.toTime());
} else {
#if QT_VERSION < QT_VERSION_CHECK(5, 11, 0)
Expand Down
2 changes: 1 addition & 1 deletion templates/defaultfilters/integers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ QVariant AddFilter::doFilter(const QVariant &input, const QVariant &argument,
}

if (input.userType() == qMetaTypeId<QStringList>()) {
if (argument == QVariant::StringList)
if (argument.userType() == QMetaType::QStringList)
return input.toStringList() + argument.toStringList();
return input;
}
Expand Down
29 changes: 17 additions & 12 deletions templates/defaultfilters/lists.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,13 @@ QVariant MakeListFilter::doFilter(const QVariant &_input,

auto input = _input;

if (input.userType() == qMetaTypeId<int>())
input.convert(QVariant::String);
if (input.userType() == qMetaTypeId<int>()) {
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
input.convert(QMetaType::QString);
#else
input.convert(QMetaType(QMetaType::QString));
#endif
}

if (input.userType() == qMetaTypeId<SafeString>()
|| input.userType() == qMetaTypeId<QString>()) {
Expand Down Expand Up @@ -260,27 +265,27 @@ struct DictSortLessThan {
const auto l = lp.first;
const auto r = rp.first;
switch (l.userType()) {
case QVariant::Invalid:
case QMetaType::UnknownType:
return (r.isValid());
case QVariant::Int:
case QMetaType::Int:
return l.value<int>() < r.value<int>();
case QVariant::UInt:
case QMetaType::UInt:
return l.value<uint>() < r.value<uint>();
case QVariant::LongLong:
case QMetaType::LongLong:
return l.value<long long>() < r.value<long long>();
case QVariant::ULongLong:
case QMetaType::ULongLong:
return l.value<unsigned long long>() < r.value<unsigned long long>();
case QMetaType::Float:
return l.value<float>() < r.value<float>();
case QVariant::Double:
case QMetaType::Double:
return l.value<double>() < r.value<double>();
case QVariant::Char:
case QMetaType::Char:
return l.toChar() < r.toChar();
case QVariant::Date:
case QMetaType::QDate:
return l.toDate() < r.toDate();
case QVariant::Time:
case QMetaType::QTime:
return l.toTime() < r.toTime();
case QVariant::DateTime:
case QMetaType::QDateTime:
return l.toDateTime() < r.toDateTime();
case QMetaType::QObjectStar:
return l.value<QObject *>() < r.value<QObject *>();
Expand Down
12 changes: 6 additions & 6 deletions templates/defaultfilters/stringfilters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -388,12 +388,12 @@ QVariant FloatFormatFilter::doFilter(const QVariant &input,
{
Q_UNUSED(autoescape)
double inputDouble;
switch (input.type()) {
case QVariant::Int:
case QVariant::UInt:
case QVariant::LongLong:
case QVariant::ULongLong:
case QVariant::Double:
switch (input.userType()) {
case QMetaType::Int:
case QMetaType::UInt:
case QMetaType::LongLong:
case QMetaType::ULongLong:
case QMetaType::Double:
inputDouble = input.toDouble();
break;
default:
Expand Down
8 changes: 8 additions & 0 deletions templates/lib/customtyperegistry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,23 @@ QVariant CustomTypeRegistry::lookup(const QVariant &object,
auto it = types.constFind(id);
if (it == types.constEnd()) {
qCWarning(CUTELEE_CUSTOMTYPE)
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
<< "Don't know how to handle metatype" << QMetaType::typeName(id);
#else
<< "Don't know how to handle metatype" << QMetaType(id).name();
#endif
// :TODO: Print out error message
return QVariant();
}

const CustomTypeInfo &info = it.value();
if (!info.lookupFunction) {
qCWarning(CUTELEE_CUSTOMTYPE)
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
<< "No lookup function for metatype" << QMetaType::typeName(id);
#else
<< "No lookup function for metatype" << QMetaType(id).name();
#endif
lf = 0;
// :TODO: Print out error message
return QVariant();
Expand Down
6 changes: 5 additions & 1 deletion templates/lib/metatype.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,11 @@ QVariant Cutelee::MetaType::lookup(const QVariant &object,

return QVariant();
}
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
auto mo = QMetaType::metaObjectForType(object.userType());
#else
auto mo = QMetaType(object.userType()).metaObject();
#endif
if (mo) {
QMetaType mt(object.userType());
if (mt.flags().testFlag(QMetaType::IsGadget)) {
Expand Down Expand Up @@ -302,4 +306,4 @@ QVariant Cutelee::MetaType::lookup(const QVariant &object,
bool Cutelee::MetaType::lookupAlreadyRegistered(int id)
{
return customTypes()->lookupAlreadyRegistered(id);
}
}
4 changes: 4 additions & 0 deletions templates/lib/qtlocalizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,11 @@ void QtLocalizer::pushLocale(const QString &localeName)
localeStruct = new Locale(QLocale(localeName));
auto qtTranslator = new QTranslator;
qtTranslator->load(QStringLiteral("qt_") + localeName,
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
QLibraryInfo::location(QLibraryInfo::TranslationsPath));
#else
QLibraryInfo::path(QLibraryInfo::TranslationsPath));
#endif
localeStruct->systemTranslators.append(qtTranslator);
auto appTranslator = new QTranslator;
appTranslator->load(d->m_appTranslatorPrefix + localeName,
Expand Down
30 changes: 15 additions & 15 deletions templates/lib/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,22 +40,22 @@ bool Cutelee::variantIsTrue(const QVariant &variant)
if (!variant.isValid())
return false;
switch (variant.userType()) {
case QVariant::Bool: {
case QMetaType::Bool: {
return variant.toBool();
}
case QVariant::Int: {
case QMetaType::Int: {
return variant.value<int>() > 0;
}
case QVariant::UInt: {
case QMetaType::UInt: {
return variant.value<uint>() > 0;
}
case QVariant::LongLong: {
case QMetaType::LongLong: {
return variant.value<qlonglong>() > 0;
}
case QVariant::ULongLong: {
case QMetaType::ULongLong: {
return variant.value<qulonglong>() > 0;
}
case QVariant::Double: {
case QMetaType::Double: {
return variant.value<double>() > 0;
}
case QMetaType::Float: {
Expand All @@ -74,10 +74,10 @@ bool Cutelee::variantIsTrue(const QVariant &variant)
}
return true;
}
case QVariant::List: {
case QMetaType::QVariantList: {
return !variant.value<QVariantList>().isEmpty();
}
case QVariant::Hash: {
case QMetaType::QVariantHash: {
return !variant.value<QVariantHash>().isEmpty();
}
}
Expand Down Expand Up @@ -116,16 +116,16 @@ bool Cutelee::isSafeString(const QVariant &input)
{
const auto type = input.userType();
return ((type == qMetaTypeId<Cutelee::SafeString>())
|| type == QVariant::String);
|| type == QMetaType::QString);
}

static QList<int> getPrimitives()
{
QList<int> primitives;
primitives << qMetaTypeId<Cutelee::SafeString>() << QVariant::String
<< QVariant::Bool << QVariant::Int << QVariant::Double
<< QMetaType::Float << QVariant::Date << QVariant::Time
<< QVariant::DateTime;
primitives << qMetaTypeId<Cutelee::SafeString>() << QMetaType::QString
<< QMetaType::Bool << QMetaType::Int << QMetaType::Double
<< QMetaType::Float << QMetaType::QDate << QMetaType::QTime
<< QMetaType::QDateTime;
return primitives;
}

Expand All @@ -146,11 +146,11 @@ bool Cutelee::equals(const QVariant &lhs, const QVariant &rhs)
if (rhs.userType() == qMetaTypeId<Cutelee::SafeString>()) {
equal = (lhs.value<Cutelee::SafeString>()
== rhs.value<Cutelee::SafeString>());
} else if (rhs.userType() == QVariant::String) {
} else if (rhs.userType() == QMetaType::QString) {
equal = (lhs.value<Cutelee::SafeString>() == rhs.toString());
}
} else if (rhs.userType() == qMetaTypeId<Cutelee::SafeString>()
&& lhs.userType() == QVariant::String) {
&& lhs.userType() == QMetaType::QString) {
equal = (rhs.value<Cutelee::SafeString>() == lhs.toString());
} else if (rhs.userType() == qMetaTypeId<MetaEnumVariable>()) {
if (lhs.userType() == qMetaTypeId<MetaEnumVariable>()) {
Expand Down
4 changes: 4 additions & 0 deletions templates/tests/testbuiltins.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,11 @@ void TestBuiltinSyntax::testObjects()
SafeString s3(s1);
Q_UNUSED(s3);

#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
QMetaType::construct(qMetaTypeId<MetaEnumVariable>(), 0, 0);
#else
QMetaType(qMetaTypeId<MetaEnumVariable>()).construct(0, 0);
#endif
}

void TestBuiltinSyntax::testTruthiness_data()
Expand Down
14 changes: 13 additions & 1 deletion textdocument/lib/markupdirector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -590,8 +590,12 @@ void MarkupDirector::processOpeningElements(QTextBlock::iterator it)
d->m_openFontPointSize = fragmentFormat.font().pointSize();
break;
case SpanFontFamily:
m_builder->beginFontFamily(fragmentFormat.fontFamily());
#if QT_VERSION < QT_VERSION_CHECK(6, 1, 0)
d->m_openFontFamily = fragmentFormat.fontFamily();
#else
d->m_openFontFamily = fragmentFormat.fontFamilies().toStringList().first();
#endif
m_builder->beginFontFamily(d->m_openFontFamily);
break;
case SpanBackground:
m_builder->beginBackground(fragmentFormat.background());
Expand Down Expand Up @@ -669,7 +673,11 @@ QSet<int> MarkupDirector::getElementsToClose(QTextBlock::iterator it) const
auto fontForeground = fragmentFormat.foreground();
auto fontBackground = fragmentFormat.background();

#if QT_VERSION < QT_VERSION_CHECK(6, 1, 0)
auto fontFamily = fragmentFormat.fontFamily();
#else
auto fontFamily = fragmentFormat.fontFamilies().toStringList().first();
#endif
auto fontPointSize = fragmentFormat.font().pointSize();
auto anchorHref = fragmentFormat.anchorHref();

Expand Down Expand Up @@ -767,7 +775,11 @@ QList<int> MarkupDirector::getElementsToOpen(QTextBlock::iterator it)
auto fontForeground = fragmentFormat.foreground();
auto fontBackground = fragmentFormat.background();

#if QT_VERSION < QT_VERSION_CHECK(6, 1, 0)
auto fontFamily = fragmentFormat.fontFamily();
#else
auto fontFamily = fragmentFormat.fontFamilies().toStringList().first();
#endif
auto fontPointSize = fragmentFormat.font().pointSize();
auto anchorHref = fragmentFormat.anchorHref();

Expand Down
1 change: 0 additions & 1 deletion textdocument/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,3 @@ cutelee_textdocument_unit_tests(
htmlbuildertest
plainmarkupbuildertest
)
target_compile_definitions(plainmarkupbuildertest_exec PRIVATE QT_TESTCASE_BUILDDIR="${CMAKE_BINARY_DIR}")

0 comments on commit a36f56d

Please sign in to comment.