Skip to content

Commit

Permalink
Deprecate conversion functions between QList and QSet
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
laknoll committed May 7, 2019
1 parent d510e1e commit 92f9842
Show file tree
Hide file tree
Showing 24 changed files with 98 additions and 49 deletions.
2 changes: 1 addition & 1 deletion examples/opengl/contextinfo/widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ void Widget::renderWindowReady()
m_output->append(tr("Qt OpenGL library handle: %1")
.arg(QString::number(qintptr(QOpenGLContext::openGLModuleHandle()), 16)));

QList<QByteArray> extensionList = context->extensions().toList();
QList<QByteArray> extensionList = context->extensions().values();
std::sort(extensionList.begin(), extensionList.end());
m_extensions->append(tr("Found %1 extensions:").arg(extensionList.count()));
for (const QByteArray &ext : qAsConst(extensionList))
Expand Down
3 changes: 2 additions & 1 deletion examples/widgets/painting/pathstroke/pathstroke.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -611,7 +611,8 @@ bool PathStrokeRenderer::event(QEvent *e)
case Qt::TouchPointPressed:
{
// find the point, move it
QSet<int> activePoints = QSet<int>::fromList(m_fingerPointMapping.values());
const auto mappedPoints = m_fingerPointMapping.values();
QSet<int> activePoints = QSet<int>(mappedPoints.begin(), mappedPoints.end());
int activePoint = -1;
qreal distance = -1;
const int pointsCount = m_points.size();
Expand Down
3 changes: 2 additions & 1 deletion examples/widgets/painting/shared/hoverpoints.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,8 @@ bool HoverPoints::eventFilter(QObject *object, QEvent *event)
case Qt::TouchPointPressed:
{
// find the point, move it
QSet<int> activePoints = QSet<int>::fromList(m_fingerPointMapping.values());
const auto mappedPoints = m_fingerPointMapping.values();
QSet<int> activePoints = QSet<int>(mappedPoints.begin(), mappedPoints.end());
int activePoint = -1;
qreal distance = -1;
const int pointsCount = m_points.size();
Expand Down
3 changes: 2 additions & 1 deletion qmake/generators/makefile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2696,7 +2696,8 @@ MakefileGenerator::writeSubTargets(QTextStream &t, QList<MakefileGenerator::SubT
QSet<QString> recurse;
const ProKey rkey(*qut_it + ".recurse");
if (project->isSet(rkey)) {
recurse = project->values(rkey).toQStringList().toSet();
const QStringList values = project->values(rkey).toQStringList();
recurse = QSet<QString>(values.begin(), values.end());
} else {
for(int target = 0; target < targets.size(); ++target)
recurse.insert(targets.at(target)->name);
Expand Down
2 changes: 1 addition & 1 deletion qmake/generators/win32/msvc_nmake.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ void NmakeMakefileGenerator::writeImplicitRulesPart(QTextStream &t)
QHash<QString, QString> fileNames;
bool duplicatesFound = false;
const QStringList sourceFilesFilter = sourceFilesForImplicitRulesFilter();
QStringList fixifiedSourceDirs = fileFixify(source_directories.toList(), FileFixifyAbsolute);
QStringList fixifiedSourceDirs = fileFixify(QList<QString>(source_directories.constBegin(), source_directories.constEnd()), FileFixifyAbsolute);
fixifiedSourceDirs.removeDuplicates();
for (const QString &sourceDir : qAsConst(fixifiedSourceDirs)) {
QDirIterator dit(sourceDir, sourceFilesFilter, QDir::Files | QDir::NoDotAndDotDot);
Expand Down
13 changes: 7 additions & 6 deletions src/corelib/statemachine/qstatemachine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -384,7 +385,7 @@ static QList<QAbstractState *> getEffectiveTargetStates(QAbstractTransition *tra
}
}

targetsList = targets.toList();
targetsList = targets.values();
cache->insert(transition, targetsList);
return targetsList;
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}
Expand Down
8 changes: 5 additions & 3 deletions src/corelib/tools/qlist.h
Original file line number Diff line number Diff line change
Expand Up @@ -403,13 +403,15 @@ class QList
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; }
Expand Down
13 changes: 9 additions & 4 deletions src/corelib/tools/qset.h
Original file line number Diff line number Diff line change
Expand Up @@ -245,10 +245,13 @@ class QSet
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;
Expand Down Expand Up @@ -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());
Expand All @@ -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
{
Expand All @@ -401,6 +405,7 @@ QList<T> QList<T>::fromSet(const QSet<T> &set)
{
return set.toList();
}
#endif

Q_DECLARE_SEQUENTIAL_ITERATOR(Set)

Expand Down
3 changes: 1 addition & 2 deletions src/corelib/tools/qvector.h
Original file line number Diff line number Diff line change
Expand Up @@ -297,9 +297,8 @@ class QVector
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.")
Expand Down
2 changes: 1 addition & 1 deletion src/gui/opengl/qopengl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/gui/text/qtextodfwriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion src/network/ssl/qsslsocket_openssl_symbols.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/tools/uic/cpp/cppwriteinitialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());

Expand Down
2 changes: 1 addition & 1 deletion src/widgets/graphicsview/qgraphicsanchorlayout_p.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

/*!
Expand Down
10 changes: 5 additions & 5 deletions src/widgets/graphicsview/qgraphicsscene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion src/widgets/graphicsview/qsimplex_p.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/widgets/itemviews/qtableview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)) {
Expand Down
2 changes: 1 addition & 1 deletion src/widgets/kernel/qapplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1721,7 +1721,7 @@ QWidgetList QApplication::topLevelWidgets()
QWidgetList QApplication::allWidgets()
{
if (QWidgetPrivate::allWidgets)
return QWidgetPrivate::allWidgets->toList();
return QWidgetPrivate::allWidgets->values();
return QWidgetList();
}

Expand Down
2 changes: 1 addition & 1 deletion src/widgets/kernel/qgesturemanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading

0 comments on commit 92f9842

Please sign in to comment.