Invert include dependencies between QList and QVector

This is a very slight source incompatibility, but required as
a preparation for Qt 6, where QList should inherit QVector or
share the implementation with it.

This requires some special work to correctly instantiate and
export QVector<QPoint> from Qt Core on MSVC.

Change-Id: I1d042c5fafdde7afe59409eda2580871d4832fcd
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
Lars Knoll 2018-10-08 11:55:13 +02:00
parent 4b1ce72c23
commit 972f8845a8
3 changed files with 52 additions and 43 deletions

View File

@ -47,6 +47,23 @@
QT_BEGIN_NAMESPACE
/*
### Qt 5:
### This needs to be removed for next releases of Qt. It is a workaround for vc++ because
### Qt exports QPolygon and QPolygonF that inherit QVector<QPoint> and
### QVector<QPointF> respectively.
*/
#if defined(Q_CC_MSVC) && defined(QT_BUILD_CORE_LIB)
QT_BEGIN_INCLUDE_NAMESPACE
#include <QtCore/qpoint.h>
QT_END_INCLUDE_NAMESPACE
template class Q_CORE_EXPORT QVector<QPointF>;
template class Q_CORE_EXPORT QVector<QPoint>;
#endif
/*
QList as an array-list combines the easy-of-use of a random
access interface with fast list operations and the low memory

View File

@ -45,6 +45,7 @@
#include <QtCore/qrefcount.h>
#include <QtCore/qarraydata.h>
#include <QtCore/qhashfunctions.h>
#include <QtCore/qvector.h>
#include <iterator>
#include <list>
@ -1051,6 +1052,37 @@ inline int QList<T>::count_impl(const T &t, QListData::ArrayCompatibleLayout) co
t));
}
template <typename T>
Q_OUTOFLINE_TEMPLATE QVector<T> QList<T>::toVector() const
{
QVector<T> result(size());
for (int i = 0; i < size(); ++i)
result[i] = at(i);
return result;
}
template <typename T>
QList<T> QList<T>::fromVector(const QVector<T> &vector)
{
return vector.toList();
}
template <typename T>
Q_OUTOFLINE_TEMPLATE QList<T> QVector<T>::toList() const
{
QList<T> result;
result.reserve(size());
for (int i = 0; i < size(); ++i)
result.append(at(i));
return result;
}
template <typename T>
QVector<T> QVector<T>::fromList(const QList<T> &list)
{
return list.toVector();
}
Q_DECLARE_SEQUENTIAL_ITERATOR(List)
Q_DECLARE_MUTABLE_SEQUENTIAL_ITERATOR(List)

View File

@ -42,7 +42,6 @@
#include <QtCore/qalgorithms.h>
#include <QtCore/qiterator.h>
#include <QtCore/qlist.h>
#include <QtCore/qrefcount.h>
#include <QtCore/qarraydata.h>
#include <QtCore/qhashfunctions.h>
@ -968,37 +967,6 @@ Q_OUTOFLINE_TEMPLATE QVector<T> QVector<T>::mid(int pos, int len) const
return midResult;
}
template <typename T>
Q_OUTOFLINE_TEMPLATE QList<T> QVector<T>::toList() const
{
QList<T> result;
result.reserve(size());
for (int i = 0; i < size(); ++i)
result.append(at(i));
return result;
}
template <typename T>
Q_OUTOFLINE_TEMPLATE QVector<T> QList<T>::toVector() const
{
QVector<T> result(size());
for (int i = 0; i < size(); ++i)
result[i] = at(i);
return result;
}
template <typename T>
QVector<T> QVector<T>::fromList(const QList<T> &list)
{
return list.toVector();
}
template <typename T>
QList<T> QList<T>::fromVector(const QVector<T> &vector)
{
return vector.toList();
}
Q_DECLARE_SEQUENTIAL_ITERATOR(Vector)
Q_DECLARE_MUTABLE_SEQUENTIAL_ITERATOR(Vector)
@ -1046,20 +1014,12 @@ inline bool operator>=(const QVector<T> &lhs, const QVector<T> &rhs)
### QVector<QPointF> respectively.
*/
#ifdef Q_CC_MSVC
#if defined(Q_CC_MSVC) && !defined(QT_BUILD_CORE_LIB)
QT_BEGIN_INCLUDE_NAMESPACE
#include <QtCore/qpoint.h>
QT_END_INCLUDE_NAMESPACE
#ifndef Q_TEMPLATE_EXTERN
#if defined(QT_BUILD_CORE_LIB)
#define Q_TEMPLATE_EXTERN
#else
#define Q_TEMPLATE_EXTERN extern
#endif
#endif
Q_TEMPLATE_EXTERN template class Q_CORE_EXPORT QVector<QPointF>;
Q_TEMPLATE_EXTERN template class Q_CORE_EXPORT QVector<QPoint>;
extern template class Q_CORE_EXPORT QVector<QPointF>;
extern template class Q_CORE_EXPORT QVector<QPoint>;
#endif
QVector<uint> QStringView::toUcs4() const { return QtPrivate::convertToUcs4(*this); }