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)
committerManuel Nickschas <sputnick@quassel-irc.org>
Wed, 8 Jan 2020 18:41:46 +0000 (19:41 +0100)
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.

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 48f1617..e3cdbc4 100644 (file)
@@ -35,36 +35,30 @@ BacklogRequester::BacklogRequester(bool buffering, RequesterType requesterType,
     Q_ASSERT(backlogManager);
 }
 
     Q_ASSERT(backlogManager);
 }
 
-void BacklogRequester::setWaitingBuffers(const QSet<BufferId>& buffers)
+void BacklogRequester::setWaitingBuffers(const BufferIdList& buffers)
 {
 {
-    _buffersWaiting = buffers;
-    _totalBuffers = _buffersWaiting.count();
-}
-
-void BacklogRequester::addWaitingBuffer(BufferId buffer)
-{
-    _buffersWaiting << buffer;
-    _totalBuffers++;
+    _buffersWaiting = {buffers.begin(), buffers.end()};
+    _totalBuffers = int(_buffersWaiting.size());
 }
 
 bool BacklogRequester::buffer(BufferId bufferId, const MessageList& messages)
 {
     _bufferedMessages << messages;
 }
 
 bool BacklogRequester::buffer(BufferId bufferId, const MessageList& messages)
 {
     _bufferedMessages << messages;
-    _buffersWaiting.remove(bufferId);
-    return !_buffersWaiting.isEmpty();
+    _buffersWaiting.erase(bufferId);
+    return !_buffersWaiting.empty();
 }
 
 BufferIdList BacklogRequester::allBufferIds() const
 {
     QSet<BufferId> bufferIds = Client::bufferViewOverlay()->bufferIds();
     bufferIds += Client::bufferViewOverlay()->tempRemovedBufferIds();
 }
 
 BufferIdList BacklogRequester::allBufferIds() const
 {
     QSet<BufferId> bufferIds = Client::bufferViewOverlay()->bufferIds();
     bufferIds += Client::bufferViewOverlay()->tempRemovedBufferIds();
-    return bufferIds.toList();
+    return bufferIds.values();
 }
 
 void BacklogRequester::flushBuffer()
 {
 }
 
 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;
     }
     _bufferedMessages.clear();
     _totalBuffers = 0;
index 2ecb09a..c8a51e6 100644 (file)
@@ -18,8 +18,9 @@
  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
  ***************************************************************************/
 
  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
  ***************************************************************************/
 
-#ifndef BACKLOGREQUESTER_H
-#define BACKLOGREQUESTER_H
+#pragma once
+
+#include <set>
 
 #include <QList>
 
 
 #include <QList>
 
@@ -48,7 +49,7 @@ public:
     inline RequesterType type() { return _requesterType; }
     inline const QList<Message>& bufferedMessages() { return _bufferedMessages; }
 
     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
     inline int totalBuffers() const { return _totalBuffers; }
 
     bool buffer(BufferId bufferId, const MessageList& messages);  //! returns false if it was the last missing backlogpart
@@ -60,9 +61,7 @@ public:
 
 protected:
     BufferIdList allBufferIds() const;
 
 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;
 
 
     ClientBacklogManager* backlogManager;
 
@@ -71,7 +70,7 @@ private:
     RequesterType _requesterType;
     MessageList _bufferedMessages;
     int _totalBuffers;
     RequesterType _requesterType;
     MessageList _bufferedMessages;
     int _totalBuffers;
-    QSet<BufferId> _buffersWaiting;
+    std::set<BufferId> _buffersWaiting;
 };
 
 // ========================================
 };
 
 // ========================================
@@ -115,5 +114,3 @@ private:
     int _limit;
     int _additional;
 };
     int _limit;
     int _additional;
 };
-
-#endif  // BACKLOGREQUESTER_H
index fe0d97a..455f273 100644 (file)
@@ -27,6 +27,7 @@
 #include "clientbacklogmanager.h"
 #include "clientbufferviewmanager.h"
 #include "networkmodel.h"
 #include "clientbacklogmanager.h"
 #include "clientbufferviewmanager.h"
 #include "networkmodel.h"
+#include "util.h"
 
 const int BufferViewOverlay::_updateEventId = QEvent::registerEventType();
 
 
 const int BufferViewOverlay::_updateEventId = QEvent::registerEventType();
 
@@ -92,13 +93,13 @@ void BufferViewOverlay::addView(int viewId)
                     if (Client::networkModel()->networkId(bufferId) == config->networkId())
                         buffers << bufferId;
                 }
                     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 {
                     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);
         }
             }
             Client::backlogManager()->checkForBacklog(buffers);
         }
@@ -207,12 +208,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);
 
             // 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
             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);
 
 
         buffers.intersect(availableBuffers);
 
index b969251..35403c0 100644 (file)
@@ -29,6 +29,7 @@
 #include "backlogrequester.h"
 #include "backlogsettings.h"
 #include "client.h"
 #include "backlogrequester.h"
 #include "backlogsettings.h"
 #include "client.h"
+#include "util.h"
 
 ClientBacklogManager::ClientBacklogManager(QObject* parent)
     : BacklogManager(parent)
 
 ClientBacklogManager::ClientBacklogManager(QObject* parent)
     : BacklogManager(parent)
@@ -117,7 +118,7 @@ void ClientBacklogManager::requestInitialBacklog()
 BufferIdList ClientBacklogManager::filterNewBufferIds(const BufferIdList& bufferIds)
 {
     BufferIdList newBuffers;
 BufferIdList ClientBacklogManager::filterNewBufferIds(const BufferIdList& bufferIds)
 {
     BufferIdList newBuffers;
-    QSet<BufferId> availableBuffers = Client::networkModel()->allBufferIds().toSet();
+    QSet<BufferId> availableBuffers = toQSet(Client::networkModel()->allBufferIds());
     foreach (BufferId bufferId, bufferIds) {
         if (_buffersRequested.contains(bufferId) || !availableBuffers.contains(bufferId))
             continue;
     foreach (BufferId bufferId, bufferIds) {
         if (_buffersRequested.contains(bufferId) || !availableBuffers.contains(bufferId))
             continue;
index 97cf892..6ff6378 100644 (file)
@@ -28,6 +28,7 @@
 #include "clientignorelistmanager.h"
 #include "messagemodel.h"
 #include "networkmodel.h"
 #include "clientignorelistmanager.h"
 #include "messagemodel.h"
 #include "networkmodel.h"
+#include "util.h"
 
 MessageFilter::MessageFilter(QAbstractItemModel* source, QObject* parent)
     : QSortFilterProxyModel(parent)
 
 MessageFilter::MessageFilter(QAbstractItemModel* source, QObject* parent)
     : QSortFilterProxyModel(parent)
@@ -39,7 +40,7 @@ MessageFilter::MessageFilter(QAbstractItemModel* source, QObject* parent)
 
 MessageFilter::MessageFilter(MessageModel* source, const QList<BufferId>& buffers, QObject* parent)
     : QSortFilterProxyModel(parent)
 
 MessageFilter::MessageFilter(MessageModel* source, const QList<BufferId>& buffers, QObject* parent)
     : QSortFilterProxyModel(parent)
-    , _validBuffers(buffers.toSet())
+    , _validBuffers(toQSet(buffers))
     , _messageTypeFilter(0)
 {
     init();
     , _messageTypeFilter(0)
 {
     init();
@@ -114,7 +115,7 @@ QString MessageFilter::idString() const
     if (_validBuffers.isEmpty())
         return "*";
 
     if (_validBuffers.isEmpty())
         return "*";
 
-    QList<BufferId> bufferIds = _validBuffers.toList();
+    QList<BufferId> bufferIds = _validBuffers.values();
     std::sort(bufferIds.begin(), bufferIds.end());
 
     QStringList bufferIdStrings;
     std::sort(bufferIds.begin(), bufferIds.end());
 
     QStringList bufferIdStrings;
index a23595c..d7b65f0 100644 (file)
@@ -317,7 +317,7 @@ void IrcUser::partChannel(const QString& channelname)
 
 void IrcUser::quit()
 {
 
 void IrcUser::quit()
 {
-    QList<IrcChannel*> channels = _channels.toList();
+    QList<IrcChannel*> channels = _channels.values();
     _channels.clear();
     foreach (IrcChannel* channel, channels) {
         disconnect(channel, nullptr, this, nullptr);
     _channels.clear();
     foreach (IrcChannel* channel, channels) {
         disconnect(channel, nullptr, this, nullptr);
index 19aeb4f..f638dfe 100644 (file)
@@ -23,6 +23,7 @@
 #include "common-export.h"
 
 #include <QList>
 #include "common-export.h"
 
 #include <QList>
+#include <QSet>
 #include <QString>
 #include <QVariant>
 
 #include <QString>
 #include <QVariant>
 
@@ -50,6 +51,16 @@ COMMON_EXPORT QString decodeString(const QByteArray& input, QTextCodec* codec =
 
 COMMON_EXPORT uint editingDistance(const QString& s1, const QString& s2);
 
 
 COMMON_EXPORT uint editingDistance(const QString& s1, const QString& s2);
 
+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>
 QVariantList toVariantList(const QList<T>& list)
 {
 template<typename T>
 QVariantList toVariantList(const QList<T>& list)
 {
index 266f344..d7b3b5c 100644 (file)
@@ -28,6 +28,7 @@
 #include "corenetwork.h"
 #include "coresession.h"
 #include "ircchannel.h"
 #include "corenetwork.h"
 #include "coresession.h"
 #include "ircchannel.h"
+#include "util.h"
 
 class PurgeEvent : public QEvent
 {
 
 class PurgeEvent : public QEvent
 {
@@ -193,7 +194,7 @@ void CoreBufferSyncer::purgeBufferIds()
     std::transform(bufferInfos.cbegin(), bufferInfos.cend(), std::inserter(actualBuffers, actualBuffers.end()),
                    [](auto&& bufferInfo) { return bufferInfo.bufferId(); });
 
     std::transform(bufferInfos.cbegin(), bufferInfos.cend(), std::inserter(actualBuffers, actualBuffers.end()),
                    [](auto&& bufferInfo) { return bufferInfo.bufferId(); });
 
-    QSet<BufferId> storedIds = lastSeenBufferIds().toSet() + markerLineBufferIds().toSet();
+    QSet<BufferId> storedIds = toQSet(lastSeenBufferIds()) + toQSet(markerLineBufferIds());
     foreach (BufferId bufferId, storedIds) {
         if (actualBuffers.find(bufferId) == actualBuffers.end()) {
             BufferSyncer::removeBuffer(bufferId);
     foreach (BufferId bufferId, storedIds) {
         if (actualBuffers.find(bufferId) == actualBuffers.end()) {
             BufferSyncer::removeBuffer(bufferId);
index da331b6..132565e 100644 (file)
@@ -35,6 +35,7 @@
 #include "messagefilter.h"
 #include "qtui.h"
 #include "qtuistyle.h"
 #include "messagefilter.h"
 #include "qtui.h"
 #include "qtuistyle.h"
+#include "util.h"
 
 ChatView::ChatView(BufferId bufferId, QWidget* parent)
     : QGraphicsView(parent)
 
 ChatView::ChatView(BufferId bufferId, QWidget* parent)
     : QGraphicsView(parent)
@@ -293,7 +294,7 @@ QSet<ChatLine*> ChatView::visibleChatLines(Qt::ItemSelectionMode mode) const
 
 QList<ChatLine*> ChatView::visibleChatLinesSorted(Qt::ItemSelectionMode mode) const
 {
 
 QList<ChatLine*> ChatView::visibleChatLinesSorted(Qt::ItemSelectionMode mode) const
 {
-    QList<ChatLine*> result = visibleChatLines(mode).toList();
+    QList<ChatLine*> result = visibleChatLines(mode).values();
     std::sort(result.begin(), result.end(), chatLinePtrLessThan);
     return result;
 }
     std::sort(result.begin(), result.end(), chatLinePtrLessThan);
     return result;
 }
index 57ca2c0..dd1ca08 100644 (file)
@@ -118,7 +118,7 @@ void ChatViewSearchController::updateHighlights(bool reuse)
             if (line)
                 chatLines << line;
         }
             if (line)
                 chatLines << line;
         }
-        foreach (ChatLine* line, QList<ChatLine*>(chatLines.toList())) {
+        foreach (ChatLine* line, chatLines) {
             updateHighlights(line);
         }
     }
             updateHighlights(line);
         }
     }
@@ -302,8 +302,7 @@ void ChatViewSearchController::repositionHighlights()
         if (line)
             chatLines << line;
     }
         if (line)
             chatLines << line;
     }
-    QList<ChatLine*> chatLineList(chatLines.toList());
-    foreach (ChatLine* line, chatLineList) {
+    foreach (ChatLine* line, chatLines) {
         repositionHighlights(line);
     }
 }
         repositionHighlights(line);
     }
 }
index 73d962b..8a8faf7 100644 (file)
@@ -30,6 +30,7 @@
 #include "client.h"
 #include "icon.h"
 #include "networkmodel.h"
 #include "client.h"
 #include "icon.h"
 #include "networkmodel.h"
+#include "util.h"
 
 ChatMonitorSettingsPage::ChatMonitorSettingsPage(QWidget* parent)
     : SettingsPage(tr("Interface"), tr("Chat Monitor"), parent)
 
 ChatMonitorSettingsPage::ChatMonitorSettingsPage(QWidget* parent)
     : SettingsPage(tr("Interface"), tr("Chat Monitor"), parent)
@@ -189,7 +190,7 @@ bool ChatMonitorSettingsPage::testHasChanged()
     if (_configActive->bufferList().count() != settings["Buffers"].toList().count())
         return true;
 
     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>();
     QSet<BufferId> settingsBufs;
     foreach (QVariant v, settings["Buffers"].toList())
         settingsBufs << v.value<BufferId>();
index 9a531e2..780d0bf 100644 (file)
@@ -32,6 +32,7 @@
 #include "graphicalui.h"
 #include "networkmodel.h"
 #include "uistyle.h"
 #include "graphicalui.h"
 #include "networkmodel.h"
 #include "uistyle.h"
+#include "util.h"
 
 /*****************************************
  * The Filter for the Tree View
 
 /*****************************************
  * The Filter for the Tree View
@@ -141,7 +142,7 @@ void BufferViewFilter::enableEditMode(bool enable)
         return;
 
     if (enable == false) {
         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))
         QSet<BufferId>::const_iterator iter;
         for (iter = _toTempRemove.constBegin(); iter != _toTempRemove.constEnd(); ++iter) {
             if (config()->temporarilyRemovedBuffers().contains(*iter))