Commit 52438ef5 authored by Volker Krause's avatar Volker Krause
Browse files

Adapt AkRanges to Qt6 container changes

parent f39d575c
......@@ -60,6 +60,7 @@ template<class T> static void compareLists(const QList<T> &l1, const QList<T> &l
}
}
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
template<class T> static void compareLists(const QVector<T> &l1, const QVector<T> &l2)
{
QCOMPARE(l1.count(), l2.count());
......@@ -67,6 +68,7 @@ template<class T> static void compareLists(const QVector<T> &l1, const QVector<T
QVERIFY(l2.contains(entry));
}
}
#endif
template<typename T>
static T *extractAttribute(const QList<Attribute *> &attrs)
......
......@@ -170,9 +170,13 @@ private Q_SLOTS:
r.transformed = true;
return r;
})
| Actions::toQList; // 3rd copy (QList::append())
| Actions::toQList; // 3rd copy (QList::append()) (Qt5 only)
QCOMPARE(out.size(), in.size());
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
QCOMPARE(out[0].copyCount, 3);
#else
QCOMPARE(out[0].copyCount, 2);
#endif
QCOMPARE(out[0].transformed, true);
}
......@@ -239,7 +243,7 @@ private Q_SLOTS:
QStringList in = {QStringLiteral("foo"), QStringLiteral("foobar"), QStringLiteral("foob")};
QList<int> out = {3, 6, 4};
QCOMPARE(in | Views::transform([](const auto &str) {
return str.size();
return (int)str.size();
}) | Actions::toQList,
out);
}
......@@ -264,7 +268,11 @@ private Q_SLOTS:
{
{
QStringList in = {QStringLiteral("foo"), QStringLiteral("foobar"), QStringLiteral("foob")};
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
QList<int> out = {6};
#else
QList<qsizetype> out = {6};
#endif
QCOMPARE(in | Views::transform(&QString::size) | Views::filter([](int i) {
return i > 5;
}) | Actions::toQList,
......
......@@ -67,7 +67,11 @@ template<typename Iterator> struct IteratorTrait<Iterator *> {
// QTypedArrayData::iterator::iterator_category
using iterator_category = std::random_access_iterator_tag;
using value_type = Iterator;
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
using difference_type = int;
#else
using difference_type = qsizetype;
#endif
using pointer = Iterator *;
using reference = Iterator &;
};
......@@ -75,7 +79,11 @@ template<typename Iterator> struct IteratorTrait<Iterator *> {
template<typename Iterator> struct IteratorTrait<const Iterator *> {
using iterator_category = std::random_access_iterator_tag;
using value_type = Iterator;
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
using difference_type = int;
#else
using difference_type = qsizetype;
#endif
using pointer = const Iterator *;
using reference = const Iterator &;
};
......
......@@ -52,10 +52,28 @@ DECLARE_HAS_MEBER_TYPE(value_type)
#define DECLARE_HAS_METHOD_GENERIC(fun, R, ...) DECLARE_HAS_METHOD_GENERIC_IMPL(fun, fun, R (T::*)(__VA_ARGS__))
// deal with Qt6 interface changes in QList::push_back/QList::insert
template<typename T, typename = std::void_t<>>
struct parameter_type {
typedef const typename T::value_type &type;
};
template<typename T>
struct parameter_type<T, std::void_t<typename T::parameter_type>> {
typedef typename T::parameter_type type;
};
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
DECLARE_HAS_METHOD_GENERIC_CONST(size, int, void)
DECLARE_HAS_METHOD_GENERIC(push_back, void, const typename T::value_type &)
DECLARE_HAS_METHOD_GENERIC(insert, typename T::iterator, const typename T::value_type &)
#else
DECLARE_HAS_METHOD_GENERIC_CONST(size, qsizetype, void)
#endif
DECLARE_HAS_METHOD_GENERIC(push_back, void, typename parameter_type<T>::type)
DECLARE_HAS_METHOD_GENERIC(insert, typename T::iterator, typename parameter_type<T>::type)
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
DECLARE_HAS_METHOD_GENERIC(reserve, void, int)
#else
DECLARE_HAS_METHOD_GENERIC(reserve, void, qsizetype)
#endif
#define DECLARE_HAS_FUNCTION(name, fun) \
template<typename T> struct has_##name { \
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment