Merge pull request #11739 from Chocobo1/qt5_14

Migrate away from deprecated API in Qt 5.14
This commit is contained in:
Mike Tzou
2019-12-26 12:43:04 +08:00
committed by GitHub
8 changed files with 38 additions and 9 deletions

View File

@@ -501,7 +501,7 @@ Session::Session(QObject *parent)
m_storedCategories = map_cast(m_categories);
}
m_tags = QSet<QString>::fromList(m_storedTags.value());
m_tags = List::toSet(m_storedTags.value());
m_refreshTimer->setInterval(refreshInterval());
connect(m_refreshTimer, &QTimer::timeout, this, &Session::refresh);
@@ -4060,7 +4060,7 @@ void Session::startUpTorrents()
}
if (!queue.empty())
fastresumes = queue + fastresumes.toSet().subtract(queue.toSet()).values();
fastresumes = queue + List::toSet(fastresumes).subtract(List::toSet(queue)).values();
}
for (const QString &fastresumeName : asConst(fastresumes)) {

View File

@@ -1246,7 +1246,7 @@ QVector<int> TorrentHandle::pieceAvailability() const
std::vector<int> avail;
m_nativeHandle.piece_availability(avail);
return QVector<int>::fromStdVector(avail);
return Vector::fromStdVector(avail);
}
qreal TorrentHandle::distributedCopies() const

View File

@@ -48,3 +48,31 @@ constexpr typename std::add_const<T>::type asConst(T &&t) noexcept { return std:
// Prevent const rvalue arguments
template <typename T>
void asConst(const T &&) = delete;
namespace List
{
// Replacement for the deprecated`QSet<T> QSet::fromList(const QList<T> &list)`
template <typename T>
QSet<T> toSet(const QList<T> &list)
{
#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0))
return {list.cbegin(), list.cend()};
#else
return QSet<T>::fromList(list);
#endif
}
}
namespace Vector
{
// Replacement for the deprecated `QVector<T> QVector::fromStdVector(const std::vector<T> &vector)`
template <typename T>
QVector<T> fromStdVector(const std::vector<T> &vector)
{
#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0))
return {vector.cbegin(), vector.cend()};
#else
return QVector<T>::fromStdVector(vector);
#endif
}
}