diff options
author | Lars Knoll <lars.knoll@qt.io> | 2019-05-06 14:00:53 +0200 |
---|---|---|
committer | Lars Knoll <lars.knoll@qt.io> | 2019-05-07 14:15:44 +0000 |
commit | 92f984273262531f909ede17a324f546fe502b5c (patch) | |
tree | ac4d4cb8796d9838607084629cf127e1641c28c0 /src/corelib | |
parent | d510e1e7f919e01a3b875ff5a575b818e5ee03e8 (diff) |
Deprecate conversion functions between QList and QSet
Users should use range constructors instead to do the conversion.
Keep conversion methods between QList and QVector as these will turn
into a no-op in Qt 6, whereas forcing people to use range constructors
would lead to deep copies of the data.
Change-Id: Id9fc9e4d007044e019826da523e8418857c91283
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'src/corelib')
-rw-r--r-- | src/corelib/statemachine/qstatemachine.cpp | 13 | ||||
-rw-r--r-- | src/corelib/tools/qlist.h | 8 | ||||
-rw-r--r-- | src/corelib/tools/qset.h | 13 | ||||
-rw-r--r-- | src/corelib/tools/qvector.h | 3 |
4 files changed, 22 insertions, 15 deletions
diff --git a/src/corelib/statemachine/qstatemachine.cpp b/src/corelib/statemachine/qstatemachine.cpp index ee3f7be279..be48dbc92f 100644 --- a/src/corelib/statemachine/qstatemachine.cpp +++ b/src/corelib/statemachine/qstatemachine.cpp @@ -370,10 +370,11 @@ static QList<QAbstractState *> getEffectiveTargetStates(QAbstractTransition *tra QList<QAbstractState*> historyConfiguration = QHistoryStatePrivate::get(historyState)->configuration; if (!historyConfiguration.isEmpty()) { // There is a saved history, so apply that. - targets.unite(historyConfiguration.toSet()); + targets.unite(QSet<QAbstractState *>(historyConfiguration.constBegin(), historyConfiguration.constEnd())); } else if (QAbstractTransition *defaultTransition = historyState->defaultTransition()) { // No saved history, take all default transition targets. - targets.unite(defaultTransition->targetStates().toSet()); + const auto &targetStates = defaultTransition->targetStates(); + targets.unite(QSet<QAbstractState *>(targetStates.constBegin(), targetStates.constEnd())); } else { // Woops, we found a history state without a default state. That's not valid! QStateMachinePrivate *m = QStateMachinePrivate::get(historyState->machine()); @@ -384,7 +385,7 @@ static QList<QAbstractState *> getEffectiveTargetStates(QAbstractTransition *tra } } - targetsList = targets.toList(); + targetsList = targets.values(); cache->insert(transition, targetsList); return targetsList; } @@ -740,7 +741,7 @@ QList<QAbstractState*> QStateMachinePrivate::computeExitSet(const QList<QAbstrac { Q_ASSERT(cache); - QList<QAbstractState*> statesToExit_sorted = computeExitSet_Unordered(enabledTransitions, cache).toList(); + QList<QAbstractState*> statesToExit_sorted = computeExitSet_Unordered(enabledTransitions, cache).values(); std::sort(statesToExit_sorted.begin(), statesToExit_sorted.end(), stateExitLessThan); return statesToExit_sorted; } @@ -777,7 +778,7 @@ QSet<QAbstractState*> QStateMachinePrivate::computeExitSet_Unordered(QAbstractTr // makes the state machine invalid. if (error == QStateMachine::NoError) setError(QStateMachine::NoCommonAncestorForTransitionError, t->sourceState()); - QList<QAbstractState *> lst = pendingErrorStates.toList(); + QList<QAbstractState *> lst = pendingErrorStates.values(); lst.prepend(t->sourceState()); domain = findLCCA(lst); @@ -879,7 +880,7 @@ QList<QAbstractState*> QStateMachinePrivate::computeEntrySet(const QList<QAbstra pendingErrorStatesForDefaultEntry.clear(); } - QList<QAbstractState*> statesToEnter_sorted = statesToEnter.toList(); + QList<QAbstractState*> statesToEnter_sorted = statesToEnter.values(); std::sort(statesToEnter_sorted.begin(), statesToEnter_sorted.end(), stateEntryLessThan); return statesToEnter_sorted; } diff --git a/src/corelib/tools/qlist.h b/src/corelib/tools/qlist.h index 25380d45ec..04c1f12f5f 100644 --- a/src/corelib/tools/qlist.h +++ b/src/corelib/tools/qlist.h @@ -403,13 +403,15 @@ public: inline QList<T> &operator<<(const QList<T> &l) { *this += l; return *this; } + static QList<T> fromVector(const QVector<T> &vector); QVector<T> toVector() const; - QSet<T> toSet() const; - static QList<T> fromVector(const QVector<T> &vector); +#if QT_VERSION < QT_VERSION_CHECK(6,0,0) + Q_DECL_DEPRECATED_X("Use QList<T>(set.begin(), set.end()) instead.") static QList<T> fromSet(const QSet<T> &set); + Q_DECL_DEPRECATED_X("Use QSet<T>(list.begin(), list.end()) instead.") + QSet<T> toSet() const; -#if QT_VERSION < QT_VERSION_CHECK(6,0,0) Q_DECL_DEPRECATED_X("Use QList<T>(list.begin(), list.end()) instead.") static inline QList<T> fromStdList(const std::list<T> &list) { QList<T> tmp; std::copy(list.begin(), list.end(), std::back_inserter(tmp)); return tmp; } diff --git a/src/corelib/tools/qset.h b/src/corelib/tools/qset.h index 8b31de71a9..83e574bf1c 100644 --- a/src/corelib/tools/qset.h +++ b/src/corelib/tools/qset.h @@ -245,10 +245,13 @@ public: inline QSet<T> operator-(const QSet<T> &other) const { QSet<T> result = *this; result -= other; return result; } - QList<T> toList() const; - inline QList<T> values() const { return toList(); } - + QList<T> values() const; +#if QT_VERSION < QT_VERSION_CHECK(6,0,0) + Q_DECL_DEPRECATED_X("Use values() instead.") + QList<T> toList() const { return values(); } + Q_DECL_DEPRECATED_X("Use QSet<T>(list.begin(), list.end()) instead.") static QSet<T> fromList(const QList<T> &list); +#endif private: Hash q_hash; @@ -368,7 +371,7 @@ Q_INLINE_TEMPLATE bool QSet<T>::contains(const QSet<T> &other) const } template <typename T> -Q_OUTOFLINE_TEMPLATE QList<T> QSet<T>::toList() const +Q_OUTOFLINE_TEMPLATE QList<T> QSet<T>::values() const { QList<T> result; result.reserve(size()); @@ -380,6 +383,7 @@ Q_OUTOFLINE_TEMPLATE QList<T> QSet<T>::toList() const return result; } +#if QT_VERSION < QT_VERSION_CHECK(6,0,0) template <typename T> Q_OUTOFLINE_TEMPLATE QSet<T> QList<T>::toSet() const { @@ -401,6 +405,7 @@ QList<T> QList<T>::fromSet(const QSet<T> &set) { return set.toList(); } +#endif Q_DECLARE_SEQUENTIAL_ITERATOR(Set) diff --git a/src/corelib/tools/qvector.h b/src/corelib/tools/qvector.h index b763d6e7e2..492afeac75 100644 --- a/src/corelib/tools/qvector.h +++ b/src/corelib/tools/qvector.h @@ -297,9 +297,8 @@ public: inline QVector<T> &operator<<(T &&t) { append(std::move(t)); return *this; } - QList<T> toList() const; - static QVector<T> fromList(const QList<T> &list); + QList<T> toList() const; #if QT_VERSION < QT_VERSION_CHECK(6,0,0) Q_DECL_DEPRECATED_X("Use QVector<T>(vector.begin(), vector.end()) instead.") |