Skip to content

Commit 92f9842

Browse files
committed
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>
1 parent d510e1e commit 92f9842

File tree

24 files changed

+98
-49
lines changed

24 files changed

+98
-49
lines changed

examples/opengl/contextinfo/widget.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ void Widget::renderWindowReady()
384384
m_output->append(tr("Qt OpenGL library handle: %1")
385385
.arg(QString::number(qintptr(QOpenGLContext::openGLModuleHandle()), 16)));
386386

387-
QList<QByteArray> extensionList = context->extensions().toList();
387+
QList<QByteArray> extensionList = context->extensions().values();
388388
std::sort(extensionList.begin(), extensionList.end());
389389
m_extensions->append(tr("Found %1 extensions:").arg(extensionList.count()));
390390
for (const QByteArray &ext : qAsConst(extensionList))

examples/widgets/painting/pathstroke/pathstroke.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -611,7 +611,8 @@ bool PathStrokeRenderer::event(QEvent *e)
611611
case Qt::TouchPointPressed:
612612
{
613613
// find the point, move it
614-
QSet<int> activePoints = QSet<int>::fromList(m_fingerPointMapping.values());
614+
const auto mappedPoints = m_fingerPointMapping.values();
615+
QSet<int> activePoints = QSet<int>(mappedPoints.begin(), mappedPoints.end());
615616
int activePoint = -1;
616617
qreal distance = -1;
617618
const int pointsCount = m_points.size();

examples/widgets/painting/shared/hoverpoints.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,8 @@ bool HoverPoints::eventFilter(QObject *object, QEvent *event)
180180
case Qt::TouchPointPressed:
181181
{
182182
// find the point, move it
183-
QSet<int> activePoints = QSet<int>::fromList(m_fingerPointMapping.values());
183+
const auto mappedPoints = m_fingerPointMapping.values();
184+
QSet<int> activePoints = QSet<int>(mappedPoints.begin(), mappedPoints.end());
184185
int activePoint = -1;
185186
qreal distance = -1;
186187
const int pointsCount = m_points.size();

qmake/generators/makefile.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2696,7 +2696,8 @@ MakefileGenerator::writeSubTargets(QTextStream &t, QList<MakefileGenerator::SubT
26962696
QSet<QString> recurse;
26972697
const ProKey rkey(*qut_it + ".recurse");
26982698
if (project->isSet(rkey)) {
2699-
recurse = project->values(rkey).toQStringList().toSet();
2699+
const QStringList values = project->values(rkey).toQStringList();
2700+
recurse = QSet<QString>(values.begin(), values.end());
27002701
} else {
27012702
for(int target = 0; target < targets.size(); ++target)
27022703
recurse.insert(targets.at(target)->name);

qmake/generators/win32/msvc_nmake.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ void NmakeMakefileGenerator::writeImplicitRulesPart(QTextStream &t)
346346
QHash<QString, QString> fileNames;
347347
bool duplicatesFound = false;
348348
const QStringList sourceFilesFilter = sourceFilesForImplicitRulesFilter();
349-
QStringList fixifiedSourceDirs = fileFixify(source_directories.toList(), FileFixifyAbsolute);
349+
QStringList fixifiedSourceDirs = fileFixify(QList<QString>(source_directories.constBegin(), source_directories.constEnd()), FileFixifyAbsolute);
350350
fixifiedSourceDirs.removeDuplicates();
351351
for (const QString &sourceDir : qAsConst(fixifiedSourceDirs)) {
352352
QDirIterator dit(sourceDir, sourceFilesFilter, QDir::Files | QDir::NoDotAndDotDot);

src/corelib/statemachine/qstatemachine.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -370,10 +370,11 @@ static QList<QAbstractState *> getEffectiveTargetStates(QAbstractTransition *tra
370370
QList<QAbstractState*> historyConfiguration = QHistoryStatePrivate::get(historyState)->configuration;
371371
if (!historyConfiguration.isEmpty()) {
372372
// There is a saved history, so apply that.
373-
targets.unite(historyConfiguration.toSet());
373+
targets.unite(QSet<QAbstractState *>(historyConfiguration.constBegin(), historyConfiguration.constEnd()));
374374
} else if (QAbstractTransition *defaultTransition = historyState->defaultTransition()) {
375375
// No saved history, take all default transition targets.
376-
targets.unite(defaultTransition->targetStates().toSet());
376+
const auto &targetStates = defaultTransition->targetStates();
377+
targets.unite(QSet<QAbstractState *>(targetStates.constBegin(), targetStates.constEnd()));
377378
} else {
378379
// Woops, we found a history state without a default state. That's not valid!
379380
QStateMachinePrivate *m = QStateMachinePrivate::get(historyState->machine());
@@ -384,7 +385,7 @@ static QList<QAbstractState *> getEffectiveTargetStates(QAbstractTransition *tra
384385
}
385386
}
386387

387-
targetsList = targets.toList();
388+
targetsList = targets.values();
388389
cache->insert(transition, targetsList);
389390
return targetsList;
390391
}
@@ -740,7 +741,7 @@ QList<QAbstractState*> QStateMachinePrivate::computeExitSet(const QList<QAbstrac
740741
{
741742
Q_ASSERT(cache);
742743

743-
QList<QAbstractState*> statesToExit_sorted = computeExitSet_Unordered(enabledTransitions, cache).toList();
744+
QList<QAbstractState*> statesToExit_sorted = computeExitSet_Unordered(enabledTransitions, cache).values();
744745
std::sort(statesToExit_sorted.begin(), statesToExit_sorted.end(), stateExitLessThan);
745746
return statesToExit_sorted;
746747
}
@@ -777,7 +778,7 @@ QSet<QAbstractState*> QStateMachinePrivate::computeExitSet_Unordered(QAbstractTr
777778
// makes the state machine invalid.
778779
if (error == QStateMachine::NoError)
779780
setError(QStateMachine::NoCommonAncestorForTransitionError, t->sourceState());
780-
QList<QAbstractState *> lst = pendingErrorStates.toList();
781+
QList<QAbstractState *> lst = pendingErrorStates.values();
781782
lst.prepend(t->sourceState());
782783

783784
domain = findLCCA(lst);
@@ -879,7 +880,7 @@ QList<QAbstractState*> QStateMachinePrivate::computeEntrySet(const QList<QAbstra
879880
pendingErrorStatesForDefaultEntry.clear();
880881
}
881882

882-
QList<QAbstractState*> statesToEnter_sorted = statesToEnter.toList();
883+
QList<QAbstractState*> statesToEnter_sorted = statesToEnter.values();
883884
std::sort(statesToEnter_sorted.begin(), statesToEnter_sorted.end(), stateEntryLessThan);
884885
return statesToEnter_sorted;
885886
}

src/corelib/tools/qlist.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -403,13 +403,15 @@ class QList
403403
inline QList<T> &operator<<(const QList<T> &l)
404404
{ *this += l; return *this; }
405405

406+
static QList<T> fromVector(const QVector<T> &vector);
406407
QVector<T> toVector() const;
407-
QSet<T> toSet() const;
408408

409-
static QList<T> fromVector(const QVector<T> &vector);
409+
#if QT_VERSION < QT_VERSION_CHECK(6,0,0)
410+
Q_DECL_DEPRECATED_X("Use QList<T>(set.begin(), set.end()) instead.")
410411
static QList<T> fromSet(const QSet<T> &set);
412+
Q_DECL_DEPRECATED_X("Use QSet<T>(list.begin(), list.end()) instead.")
413+
QSet<T> toSet() const;
411414

412-
#if QT_VERSION < QT_VERSION_CHECK(6,0,0)
413415
Q_DECL_DEPRECATED_X("Use QList<T>(list.begin(), list.end()) instead.")
414416
static inline QList<T> fromStdList(const std::list<T> &list)
415417
{ QList<T> tmp; std::copy(list.begin(), list.end(), std::back_inserter(tmp)); return tmp; }

src/corelib/tools/qset.h

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -245,10 +245,13 @@ class QSet
245245
inline QSet<T> operator-(const QSet<T> &other) const
246246
{ QSet<T> result = *this; result -= other; return result; }
247247

248-
QList<T> toList() const;
249-
inline QList<T> values() const { return toList(); }
250-
248+
QList<T> values() const;
249+
#if QT_VERSION < QT_VERSION_CHECK(6,0,0)
250+
Q_DECL_DEPRECATED_X("Use values() instead.")
251+
QList<T> toList() const { return values(); }
252+
Q_DECL_DEPRECATED_X("Use QSet<T>(list.begin(), list.end()) instead.")
251253
static QSet<T> fromList(const QList<T> &list);
254+
#endif
252255

253256
private:
254257
Hash q_hash;
@@ -368,7 +371,7 @@ Q_INLINE_TEMPLATE bool QSet<T>::contains(const QSet<T> &other) const
368371
}
369372

370373
template <typename T>
371-
Q_OUTOFLINE_TEMPLATE QList<T> QSet<T>::toList() const
374+
Q_OUTOFLINE_TEMPLATE QList<T> QSet<T>::values() const
372375
{
373376
QList<T> result;
374377
result.reserve(size());
@@ -380,6 +383,7 @@ Q_OUTOFLINE_TEMPLATE QList<T> QSet<T>::toList() const
380383
return result;
381384
}
382385

386+
#if QT_VERSION < QT_VERSION_CHECK(6,0,0)
383387
template <typename T>
384388
Q_OUTOFLINE_TEMPLATE QSet<T> QList<T>::toSet() const
385389
{
@@ -401,6 +405,7 @@ QList<T> QList<T>::fromSet(const QSet<T> &set)
401405
{
402406
return set.toList();
403407
}
408+
#endif
404409

405410
Q_DECLARE_SEQUENTIAL_ITERATOR(Set)
406411

src/corelib/tools/qvector.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -297,9 +297,8 @@ class QVector
297297
inline QVector<T> &operator<<(T &&t)
298298
{ append(std::move(t)); return *this; }
299299

300-
QList<T> toList() const;
301-
302300
static QVector<T> fromList(const QList<T> &list);
301+
QList<T> toList() const;
303302

304303
#if QT_VERSION < QT_VERSION_CHECK(6,0,0)
305304
Q_DECL_DEPRECATED_X("Use QVector<T>(vector.begin(), vector.end()) instead.")

src/gui/opengl/qopengl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ QOpenGLExtensionMatcher::QOpenGLExtensionMatcher()
8080
if (extensionStr) {
8181
QByteArray ba(extensionStr);
8282
QList<QByteArray> extensions = ba.split(' ');
83-
m_extensions = extensions.toSet();
83+
m_extensions = QSet<QByteArray>(extensions.constBegin(), extensions.constEnd());
8484
} else {
8585
#ifdef QT_OPENGL_3
8686
// clear error state

0 commit comments

Comments
 (0)