summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@qt.io>2019-05-06 14:00:53 +0200
committerLars Knoll <lars.knoll@qt.io>2019-05-07 14:15:44 +0000
commit92f984273262531f909ede17a324f546fe502b5c (patch)
treeac4d4cb8796d9838607084629cf127e1641c28c0 /src
parentd510e1e7f919e01a3b875ff5a575b818e5ee03e8 (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')
-rw-r--r--src/corelib/statemachine/qstatemachine.cpp13
-rw-r--r--src/corelib/tools/qlist.h8
-rw-r--r--src/corelib/tools/qset.h13
-rw-r--r--src/corelib/tools/qvector.h3
-rw-r--r--src/gui/opengl/qopengl.cpp2
-rw-r--r--src/gui/text/qtextodfwriter.cpp2
-rw-r--r--src/network/ssl/qsslsocket_openssl_symbols.cpp2
-rw-r--r--src/tools/uic/cpp/cppwriteinitialization.cpp2
-rw-r--r--src/widgets/graphicsview/qgraphicsanchorlayout_p.cpp2
-rw-r--r--src/widgets/graphicsview/qgraphicsscene.cpp10
-rw-r--r--src/widgets/graphicsview/qsimplex_p.cpp2
-rw-r--r--src/widgets/itemviews/qtableview.cpp4
-rw-r--r--src/widgets/kernel/qapplication.cpp2
-rw-r--r--src/widgets/kernel/qgesturemanager.cpp2
14 files changed, 37 insertions, 30 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.")
diff --git a/src/gui/opengl/qopengl.cpp b/src/gui/opengl/qopengl.cpp
index 6b701fe52b..667d16317f 100644
--- a/src/gui/opengl/qopengl.cpp
+++ b/src/gui/opengl/qopengl.cpp
@@ -80,7 +80,7 @@ QOpenGLExtensionMatcher::QOpenGLExtensionMatcher()
if (extensionStr) {
QByteArray ba(extensionStr);
QList<QByteArray> extensions = ba.split(' ');
- m_extensions = extensions.toSet();
+ m_extensions = QSet<QByteArray>(extensions.constBegin(), extensions.constEnd());
} else {
#ifdef QT_OPENGL_3
// clear error state
diff --git a/src/gui/text/qtextodfwriter.cpp b/src/gui/text/qtextodfwriter.cpp
index a62e7e425a..8eaad403d0 100644
--- a/src/gui/text/qtextodfwriter.cpp
+++ b/src/gui/text/qtextodfwriter.cpp
@@ -1007,7 +1007,7 @@ bool QTextOdfWriter::writeAll()
// add objects for lists, frames and tables
const QVector<QTextFormat> allFormats = m_document->allFormats();
- const QList<int> copy = formats.toList();
+ const QList<int> copy = formats.values();
for (auto index : copy) {
QTextObject *object = m_document->objectForFormat(allFormats[index]);
if (object) {
diff --git a/src/network/ssl/qsslsocket_openssl_symbols.cpp b/src/network/ssl/qsslsocket_openssl_symbols.cpp
index e04d45c10c..6f935a02e4 100644
--- a/src/network/ssl/qsslsocket_openssl_symbols.cpp
+++ b/src/network/ssl/qsslsocket_openssl_symbols.cpp
@@ -693,7 +693,7 @@ static QStringList libraryPathList()
// discover paths of already loaded libraries
QSet<QString> loadedPaths;
dl_iterate_phdr(dlIterateCallback, &loadedPaths);
- paths.append(loadedPaths.toList());
+ paths.append(loadedPaths.values());
#endif
return paths;
diff --git a/src/tools/uic/cpp/cppwriteinitialization.cpp b/src/tools/uic/cpp/cppwriteinitialization.cpp
index a1ff26ba04..2510fd0edc 100644
--- a/src/tools/uic/cpp/cppwriteinitialization.cpp
+++ b/src/tools/uic/cpp/cppwriteinitialization.cpp
@@ -2607,7 +2607,7 @@ static void generateMultiDirectiveBegin(QTextStream &outputStream, const QSet<QS
return;
}
- auto list = directives.toList();
+ auto list = directives.values();
// sort (always generate in the same order):
std::sort(list.begin(), list.end());
diff --git a/src/widgets/graphicsview/qgraphicsanchorlayout_p.cpp b/src/widgets/graphicsview/qgraphicsanchorlayout_p.cpp
index 008560d856..4f44373cad 100644
--- a/src/widgets/graphicsview/qgraphicsanchorlayout_p.cpp
+++ b/src/widgets/graphicsview/qgraphicsanchorlayout_p.cpp
@@ -2066,7 +2066,7 @@ QList<AnchorData *> getVariables(const QList<QSimplexConstraint *> &constraints)
for (auto it = c->variables.cbegin(), end = c->variables.cend(); it != end; ++it)
variableSet.insert(static_cast<AnchorData *>(it.key()));
}
- return variableSet.toList();
+ return variableSet.values();
}
/*!
diff --git a/src/widgets/graphicsview/qgraphicsscene.cpp b/src/widgets/graphicsview/qgraphicsscene.cpp
index 3897823e98..e5bd65d61e 100644
--- a/src/widgets/graphicsview/qgraphicsscene.cpp
+++ b/src/widgets/graphicsview/qgraphicsscene.cpp
@@ -6352,7 +6352,7 @@ void QGraphicsScenePrivate::gestureEventHandler(QGestureEvent *event)
<< "delivering override to"
<< item.data() << gestures;
// send gesture override
- QGestureEvent ev(gestures.toList());
+ QGestureEvent ev(gestures.values());
ev.t = QEvent::GestureOverride;
ev.setWidget(event->widget());
// mark event and individual gestures as ignored
@@ -6442,7 +6442,7 @@ void QGraphicsScenePrivate::gestureEventHandler(QGestureEvent *event)
DEBUG() << "QGraphicsScenePrivate::gestureEventHandler:"
<< "delivering to"
<< receiver.data() << gestures;
- QGestureEvent ev(gestures.toList());
+ QGestureEvent ev(gestures.values());
ev.setWidget(event->widget());
sendEvent(receiver.data(), &ev);
QSet<QGesture *> ignoredGestures;
@@ -6473,7 +6473,7 @@ void QGraphicsScenePrivate::gestureEventHandler(QGestureEvent *event)
// look for new potential targets for gestures that were ignored
// and should be propagated.
- QSet<QGraphicsObject *> targetsSet = cachedTargetItems.toSet();
+ QSet<QGraphicsObject *> targetsSet(cachedTargetItems.constBegin(), cachedTargetItems.constEnd());
if (receiver) {
// first if the gesture should be propagated to parents only
@@ -6505,7 +6505,7 @@ void QGraphicsScenePrivate::gestureEventHandler(QGestureEvent *event)
gestureTargetsAtHotSpots(ignoredGestures, Qt::ReceivePartialGestures,
&cachedItemGestures, &targetsSet, 0, 0);
- cachedTargetItems = targetsSet.toList();
+ cachedTargetItems = targetsSet.values();
std::sort(cachedTargetItems.begin(), cachedTargetItems.end(), qt_closestItemFirst);
DEBUG() << "QGraphicsScenePrivate::gestureEventHandler:"
<< "new targets:" << cachedTargetItems;
@@ -6583,7 +6583,7 @@ void QGraphicsScenePrivate::cancelGesturesForChildren(QGesture *original)
}
Q_ASSERT(target);
- const QList<QGesture *> list = gestures.toList();
+ const QList<QGesture *> list = gestures.values();
QGestureEvent ev(list);
sendEvent(target, &ev);
diff --git a/src/widgets/graphicsview/qsimplex_p.cpp b/src/widgets/graphicsview/qsimplex_p.cpp
index e6ffa856f1..e18f1fa4c4 100644
--- a/src/widgets/graphicsview/qsimplex_p.cpp
+++ b/src/widgets/graphicsview/qsimplex_p.cpp
@@ -164,7 +164,7 @@ bool QSimplex::setConstraints(const QList<QSimplexConstraint *> &newConstraints)
for (auto it = v.cbegin(), end = v.cend(); it != end; ++it)
variablesSet.insert(it.key());
}
- variables = variablesSet.toList();
+ variables = variablesSet.values();
// Set Variables reverse mapping
// We also need to be able to find the index for a given variable, to do that
diff --git a/src/widgets/itemviews/qtableview.cpp b/src/widgets/itemviews/qtableview.cpp
index 9e9aa63b53..0e03ff2a97 100644
--- a/src/widgets/itemviews/qtableview.cpp
+++ b/src/widgets/itemviews/qtableview.cpp
@@ -191,7 +191,7 @@ QList<QSpanCollection::Span *> QSpanCollection::spansInRect(int x, int y, int w,
break;
--it_y;
}
- return list.toList();
+ return list.values();
}
#undef DEBUG_SPAN_UPDATE
@@ -875,7 +875,7 @@ void QTableViewPrivate::drawAndClipSpans(const QRegion &area, QPainter *painter,
for(int y = firstVisualRow; y <= lastVisualRow; y++)
set.insert(spans.spanAt(x,y));
set.remove(0);
- visibleSpans = set.toList();
+ visibleSpans = set.values();
}
for (QSpanCollection::Span *span : qAsConst(visibleSpans)) {
diff --git a/src/widgets/kernel/qapplication.cpp b/src/widgets/kernel/qapplication.cpp
index c1c4014c6b..ca48a9e145 100644
--- a/src/widgets/kernel/qapplication.cpp
+++ b/src/widgets/kernel/qapplication.cpp
@@ -1721,7 +1721,7 @@ QWidgetList QApplication::topLevelWidgets()
QWidgetList QApplication::allWidgets()
{
if (QWidgetPrivate::allWidgets)
- return QWidgetPrivate::allWidgets->toList();
+ return QWidgetPrivate::allWidgets->values();
return QWidgetList();
}
diff --git a/src/widgets/kernel/qgesturemanager.cpp b/src/widgets/kernel/qgesturemanager.cpp
index cd27c9c5be..390602205c 100644
--- a/src/widgets/kernel/qgesturemanager.cpp
+++ b/src/widgets/kernel/qgesturemanager.cpp
@@ -171,7 +171,7 @@ void QGestureManager::cleanupCachedGestures(QObject *target, Qt::GestureType typ
while (iter != m_objectGestures.end()) {
ObjectGesture objectGesture = iter.key();
if (objectGesture.gesture == type && target == objectGesture.object) {
- QSet<QGesture *> gestures = iter.value().toSet();
+ QSet<QGesture *> gestures = QSet<QGesture *>(iter.value().constBegin(), iter.value().constEnd());
for (QHash<QGestureRecognizer *, QSet<QGesture *> >::iterator
it = m_obsoleteGestures.begin(), e = m_obsoleteGestures.end(); it != e; ++it) {
it.value() -= gestures;