[PATCH 4/6] qa: Avoid deprecation warnings for QList/QSet conversions
authorManuel Nickschas <sputnick@quassel-irc.org>
Tue, 7 Jan 2020 19:31:31 +0000 (20:31 +0100)
committerFelix Geyer <fgeyer@debian.org>
Fri, 12 Feb 2021 17:40:17 +0000 (17:40 +0000)
From 52209badc8e769e50aa3019b63689dda0e79e9d0 Mon Sep 17 00:00:00 2001
Bug: https://bugs.quassel-irc.org/issues/1544
Bug-Ubuntu: https://bugs.launchpad.net/quassel/+bug/1885436
Origin: upstream, https://github.com/quassel/quassel/pull/518
Origin: upstream, https://github.com/quassel/quassel/commit/52209badc8e769e50aa3019b63689dda0e79e9d0

Qt 5.14 deprecated the explicit functions for converting between
QSet and QList, preferring instead the use of range-based ctors.
Unfortunately, those ctors were only added in Qt 5.14, so we can't
use them when compiling against older versions.

Add a util function for QList->QSet to keep the version check in
a single place. Replace the other direction by using QSet::values().
In some cases, conversions could be avoided altogether, or an STL
container be used easily, so do that.

Gbp-Pq: Topic qt514
Gbp-Pq: Name 0004-qa-Avoid-deprecation-warnings-for-QList-QSet-convers.patch

12 files changed:
src/client/backlogrequester.cpp
src/client/backlogrequester.h
src/client/bufferviewoverlay.cpp
src/client/clientbacklogmanager.cpp
src/client/messagefilter.cpp
src/common/ircuser.cpp
src/common/util.h
src/core/corebuffersyncer.cpp
src/qtui/chatview.cpp
src/qtui/chatviewsearchcontroller.cpp
src/qtui/settingspages/chatmonitorsettingspage.cpp
src/uisupport/bufferviewfilter.cpp

index c3aef33e1d31336d7951102955293fa2b4385ca9..f26766aa3dd1e0fa1fec47379f60df5b7daf1aea 100644 (file)
@@ -35,26 +35,18 @@ BacklogRequester::BacklogRequester(bool buffering, RequesterType requesterType,
     Q_ASSERT(backlogManager);
 }
 
-
-void BacklogRequester::setWaitingBuffers(const QSet<BufferId> &buffers)
-{
-    _buffersWaiting = buffers;
-    _totalBuffers = _buffersWaiting.count();
-}
-
-
-void BacklogRequester::addWaitingBuffer(BufferId buffer)
+void BacklogRequester::setWaitingBuffers(const BufferIdList& buffers)
 {
-    _buffersWaiting << buffer;
-    _totalBuffers++;
+    _buffersWaiting = {buffers.begin(), buffers.end()};
+    _totalBuffers = int(_buffersWaiting.size());
 }
 
 
 bool BacklogRequester::buffer(BufferId bufferId, const MessageList &messages)
 {
     _bufferedMessages << messages;
-    _buffersWaiting.remove(bufferId);
-    return !_buffersWaiting.isEmpty();
+    _buffersWaiting.erase(bufferId);
+    return !_buffersWaiting.empty();
 }
 
 
@@ -62,15 +54,14 @@ BufferIdList BacklogRequester::allBufferIds() const
 {
     QSet<BufferId> bufferIds = Client::bufferViewOverlay()->bufferIds();
     bufferIds += Client::bufferViewOverlay()->tempRemovedBufferIds();
-    return bufferIds.toList();
+    return bufferIds.values();
 }
 
 
 void BacklogRequester::flushBuffer()
 {
-    if (!_buffersWaiting.isEmpty()) {
-        qWarning() << Q_FUNC_INFO << "was called before all backlog was received:"
-                   << _buffersWaiting.count() << "buffers are waiting.";
+    if (!_buffersWaiting.empty()) {
+        qWarning() << Q_FUNC_INFO << "was called before all backlog was received:" << _buffersWaiting.size() << "buffers are waiting.";
     }
     _bufferedMessages.clear();
     _totalBuffers = 0;
index a27a221f2e490955b61ea2f1d5584d447c0b6e7e..be9f7ef8b58d4fd9d58f222793b9d11415a188d9 100644 (file)
@@ -18,8 +18,9 @@
  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
  ***************************************************************************/
 
-#ifndef BACKLOGREQUESTER_H
-#define BACKLOGREQUESTER_H
+#pragma once
+
+#include <set>
 
 #include <QList>
 
@@ -47,7 +48,7 @@ public:
     inline RequesterType type() { return _requesterType; }
     inline const QList<Message> &bufferedMessages() { return _bufferedMessages; }
 
-    inline int buffersWaiting() const { return _buffersWaiting.count(); }
+    inline int buffersWaiting() const { return int(_buffersWaiting.size()); }
     inline int totalBuffers() const { return _totalBuffers; }
 
     bool buffer(BufferId bufferId, const MessageList &messages); //! returns false if it was the last missing backlogpart
@@ -59,9 +60,7 @@ public:
 
 protected:
     BufferIdList allBufferIds() const;
-    inline void setWaitingBuffers(const QList<BufferId> &buffers) { setWaitingBuffers(buffers.toSet()); }
-    void setWaitingBuffers(const QSet<BufferId> &buffers);
-    void addWaitingBuffer(BufferId buffer);
+    void setWaitingBuffers(const BufferIdList& buffers);
 
     ClientBacklogManager *backlogManager;
 
@@ -70,7 +69,7 @@ private:
     RequesterType _requesterType;
     MessageList _bufferedMessages;
     int _totalBuffers;
-    QSet<BufferId> _buffersWaiting;
+    std::set<BufferId> _buffersWaiting;
 };
 
 
@@ -117,6 +116,3 @@ private:
     int _limit;
     int _additional;
 };
-
-
-#endif //BACKLOGREQUESTER_H
index ea02af2d055664499cc93d73b50df726112fdcbf..e79d4c8ede1ca3096ae935bc8d19bbb76059b9f1 100644 (file)
@@ -27,6 +27,7 @@
 #include "clientbacklogmanager.h"
 #include "clientbufferviewmanager.h"
 #include "networkmodel.h"
+#include "util.h"
 
 const int BufferViewOverlay::_updateEventId = QEvent::registerEventType();
 
@@ -101,13 +102,13 @@ void BufferViewOverlay::addView(int viewId)
                     if (Client::networkModel()->networkId(bufferId) == config->networkId())
                         buffers << bufferId;
                 }
-                foreach(BufferId bufferId, config->temporarilyRemovedBuffers().toList()) {
+                for (BufferId bufferId : config->temporarilyRemovedBuffers()) {
                     if (Client::networkModel()->networkId(bufferId) == config->networkId())
                         buffers << bufferId;
                 }
             }
             else {
-                buffers = BufferIdList::fromSet(config->bufferList().toSet() + config->temporarilyRemovedBuffers());
+                buffers = (toQSet(config->bufferList()) + config->temporarilyRemovedBuffers()).values();
             }
             Client::backlogManager()->checkForBacklog(buffers);
         }
@@ -224,12 +225,12 @@ void BufferViewOverlay::updateHelper()
 
             // we have to apply several filters before we can add a buffer to a category (visible, removed, ...)
             buffers += filterBuffersByConfig(config->bufferList(), config);
-            tempRemovedBuffers += filterBuffersByConfig(config->temporarilyRemovedBuffers().toList(), config);
+            tempRemovedBuffers += filterBuffersByConfig(config->temporarilyRemovedBuffers().values(), config);
             removedBuffers += config->removedBuffers();
         }
 
         // prune the sets from overlap
-        QSet<BufferId> availableBuffers = Client::networkModel()->allBufferIds().toSet();
+        QSet<BufferId> availableBuffers = toQSet(Client::networkModel()->allBufferIds());
 
         buffers.intersect(availableBuffers);
 
index 29bbde0a352e33a419348380a80fa234cb8324da..ee4ad983f829ea2a10337e86c69562e3816df459 100644 (file)
@@ -24,6 +24,7 @@
 #include "backlogsettings.h"
 #include "backlogrequester.h"
 #include "client.h"
+#include "util.h"
 
 #include <ctime>
 
@@ -119,8 +120,8 @@ void ClientBacklogManager::requestInitialBacklog()
 BufferIdList ClientBacklogManager::filterNewBufferIds(const BufferIdList &bufferIds)
 {
     BufferIdList newBuffers;
-    QSet<BufferId> availableBuffers = Client::networkModel()->allBufferIds().toSet();
-    foreach(BufferId bufferId, bufferIds) {
+    QSet<BufferId> availableBuffers = toQSet(Client::networkModel()->allBufferIds());
+    foreach (BufferId bufferId, bufferIds) {
         if (_buffersRequested.contains(bufferId) || !availableBuffers.contains(bufferId))
             continue;
         newBuffers << bufferId;
index 20b997b579fa087eee053d7dc5ffa8a174d976e2..2889b136a3a93ee4a3a67f5d57125033be4b55a9 100644 (file)
@@ -28,6 +28,7 @@
 #include "messagemodel.h"
 #include "networkmodel.h"
 #include "clientignorelistmanager.h"
+#include "util.h"
 
 MessageFilter::MessageFilter(QAbstractItemModel *source, QObject *parent)
     : QSortFilterProxyModel(parent),
@@ -40,7 +41,7 @@ MessageFilter::MessageFilter(QAbstractItemModel *source, QObject *parent)
 
 MessageFilter::MessageFilter(MessageModel *source, const QList<BufferId> &buffers, QObject *parent)
     : QSortFilterProxyModel(parent),
-    _validBuffers(buffers.toSet()),
+    _validBuffers(toQSet(buffers)),
     _messageTypeFilter(0)
 {
     init();
@@ -119,7 +120,7 @@ QString MessageFilter::idString() const
     if (_validBuffers.isEmpty())
         return "*";
 
-    QList<BufferId> bufferIds = _validBuffers.toList();
+    QList<BufferId> bufferIds = _validBuffers.values();
     qSort(bufferIds);
 
     QStringList bufferIdStrings;
index aa10735709a8a814eb836d610e9e1bbcf2576ca6..a0936ed7053a45952aff8e14406900d972434aa9 100644 (file)
@@ -353,7 +353,7 @@ void IrcUser::partChannel(const QString &channelname)
 
 void IrcUser::quit()
 {
-    QList<IrcChannel *> channels = _channels.toList();
+    QList<IrcChannel*> channels = _channels.values();
     _channels.clear();
     foreach(IrcChannel *channel, channels) {
         disconnect(channel, 0, this, 0);
index 3f6712997f2eceaf6b298b9a1a79c5044dc1804f..c0cf18d2cbb16c442dab81cbb643fc5127378d66 100644 (file)
@@ -21,6 +21,7 @@
 #pragma once
 
 #include <QList>
+#include <QSet>
 #include <QString>
 #include <QVariant>
 
@@ -59,6 +60,16 @@ QVariantList toVariantList(const QList<T> &list)
 }
 
 
+template<typename T>
+QSet<T> toQSet(const QList<T>& list)
+{
+#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0)
+    return list.toSet();
+#else
+    return {list.begin(), list.end()};
+#endif
+}
+
 template<typename T>
 QList<T> fromVariantList(const QVariantList &variants)
 {
index 3fbbe2923f51294bfdc556bd80be75364db58eed..7409ccd6353890637307c79fc66393a5fdec2e57 100644 (file)
@@ -24,6 +24,7 @@
 #include "coresession.h"
 #include "corenetwork.h"
 #include "ircchannel.h"
+#include "util.h"
 
 class PurgeEvent : public QEvent
 {
@@ -193,7 +194,7 @@ void CoreBufferSyncer::purgeBufferIds()
         actualBuffers << bufferInfo.bufferId();
     }
 
-    QSet<BufferId> storedIds = lastSeenBufferIds().toSet() + markerLineBufferIds().toSet();
+    QSet<BufferId> storedIds = toQSet(lastSeenBufferIds()) + toQSet(markerLineBufferIds());
     foreach(BufferId bufferId, storedIds) {
         if (!actualBuffers.contains(bufferId)) {
             BufferSyncer::removeBuffer(bufferId);
index cd8f0c56055bec983e2d2097c9a9b5be47ccdca1..45c87e54fd725c28044e37b954a9052b61dfafe1 100644 (file)
@@ -31,6 +31,7 @@
 #include "qtui.h"
 #include "qtuistyle.h"
 #include "clientignorelistmanager.h"
+#include "util.h"
 
 #include "chatline.h"
 
@@ -316,7 +317,7 @@ QSet<ChatLine *> ChatView::visibleChatLines(Qt::ItemSelectionMode mode) const
 
 QList<ChatLine *> ChatView::visibleChatLinesSorted(Qt::ItemSelectionMode mode) const
 {
-    QList<ChatLine *> result = visibleChatLines(mode).toList();
+    QList<ChatLine *> result = visibleChatLines(mode).values();
     qSort(result.begin(), result.end(), chatLinePtrLessThan);
     return result;
 }
index c595f10083239cc703ec1bb5e4b4e6d1615e66cc..4e80411d6510cf785a1caa402c454b7f9ff57071 100644 (file)
@@ -128,7 +128,7 @@ void ChatViewSearchController::updateHighlights(bool reuse)
             if (line)
                 chatLines << line;
         }
-        foreach(ChatLine *line, QList<ChatLine *>(chatLines.toList())) {
+        foreach (ChatLine* line, chatLines) {
             updateHighlights(line);
         }
     }
@@ -314,8 +314,7 @@ void ChatViewSearchController::repositionHighlights()
         if (line)
             chatLines << line;
     }
-    QList<ChatLine *> chatLineList(chatLines.toList());
-    foreach(ChatLine *line, chatLineList) {
+    foreach (ChatLine* line, chatLines) {
         repositionHighlights(line);
     }
 }
index bb1c35d59b0a53ebbba8651ab1137274f206ab0b..d6e511944f0c14e13f66ff1a44ee36b5789a1570 100644 (file)
@@ -28,6 +28,7 @@
 #include "bufferview.h"
 #include "bufferviewfilter.h"
 #include "chatviewsettings.h"
+#include "util.h"
 
 #include <QVariant>
 
@@ -196,7 +197,7 @@ bool ChatMonitorSettingsPage::testHasChanged()
     if (_configActive->bufferList().count() != settings["Buffers"].toList().count())
         return true;
 
-    QSet<BufferId> uiBufs = _configActive->bufferList().toSet();
+    QSet<BufferId> uiBufs = toQSet(_configActive->bufferList());
     QSet<BufferId> settingsBufs;
     foreach(QVariant v, settings["Buffers"].toList())
     settingsBufs << v.value<BufferId>();
index 8c66f237df33aa743dda691237c849599c5ce62a..ff248afd98ee7b458f7405e98b97f93d975c76cb 100644 (file)
@@ -32,6 +32,7 @@
 #include "graphicalui.h"
 #include "networkmodel.h"
 #include "uistyle.h"
+#include "util.h"
 
 
 /*****************************************
@@ -159,7 +160,7 @@ void BufferViewFilter::enableEditMode(bool enable)
         return;
 
     if (enable == false) {
-        addBuffers(QList<BufferId>::fromSet(_toAdd));
+        addBuffers(_toAdd.values());
         QSet<BufferId>::const_iterator iter;
         for (iter = _toTempRemove.constBegin(); iter != _toTempRemove.constEnd(); ++iter) {
             if (config()->temporarilyRemovedBuffers().contains(*iter))