From 48faf525fc79913012e1a1aeca0b5124b919eda7 Mon Sep 17 00:00:00 2001 From: Manuel Nickschas Date: Tue, 7 Jan 2020 18:39:48 +0100 Subject: [PATCH] [PATCH 2/6] common: Always let QVariant::fromValue() deduce the type From 41bf70c263ee0af80ad1850fabe77ffffee188f4 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/41bf70c263ee0af80ad1850fabe77ffffee188f4 In some places, we would explicitly give the type to QVariant::fromValue(), forgoing automatic type deduction. This is almost always redundant, and in the cases where it is not, the input type should be explicitly cast. Additionally, the implementation of QVariant::fromValue() subtly changed in Qt 5.14, leading to compile errors when giving a non-decayed type (as we did in SignalProxy::attachSignal()). Gbp-Pq: Topic qt514 Gbp-Pq: Name 0002-common-Always-let-QVariant-fromValue-deduce-the-type.patch --- src/client/coreaccountmodel.cpp | 2 +- src/client/messagefilter.cpp | 2 +- src/client/messagemodel.cpp | 10 +++++----- src/client/networkmodel.cpp | 18 +++++++++--------- src/common/buffersyncer.cpp | 12 ++++-------- src/common/network.cpp | 4 ++-- src/common/serializers/serializers.cpp | 2 +- src/common/types.h | 10 +++++----- src/common/util.h | 2 +- src/core/core.cpp | 2 +- src/qtui/chatitem.cpp | 2 +- src/qtui/chatlinemodelitem.cpp | 14 ++++++++------ src/qtui/mainwin.cpp | 2 +- src/qtui/settingsdlg.cpp | 2 +- .../settingspages/chatmonitorsettingspage.cpp | 4 ++-- .../settingspages/networkssettingspage.cpp | 2 +- src/qtui/settingspages/shortcutsmodel.cpp | 2 +- src/uisupport/networkmodelcontroller.cpp | 2 +- src/uisupport/toolbaractionprovider.cpp | 2 +- 19 files changed, 47 insertions(+), 49 deletions(-) diff --git a/src/client/coreaccountmodel.cpp b/src/client/coreaccountmodel.cpp index 43c8bf1..7f66491 100644 --- a/src/client/coreaccountmodel.cpp +++ b/src/client/coreaccountmodel.cpp @@ -107,7 +107,7 @@ QVariant CoreAccountModel::data(const QModelIndex &index, int role) const case Qt::DisplayRole: return acc.accountName(); case AccountIdRole: - return QVariant::fromValue(acc.accountId()); + return QVariant::fromValue(acc.accountId()); case UuidRole: return acc.uuid().toString(); diff --git a/src/client/messagefilter.cpp b/src/client/messagefilter.cpp index c836c73..20b997b 100644 --- a/src/client/messagefilter.cpp +++ b/src/client/messagefilter.cpp @@ -191,7 +191,7 @@ bool MessageFilter::filterAcceptsRow(int sourceRow, const QModelIndex &sourcePar if (!redirectedTo.isValid()) { BufferId redirectedTo = Client::bufferModel()->currentIndex().data(NetworkModel::BufferIdRole).value(); if (redirectedTo.isValid()) - sourceModel()->setData(sourceIdx, QVariant::fromValue(redirectedTo), MessageModel::RedirectedToRole); + sourceModel()->setData(sourceIdx, QVariant::fromValue(redirectedTo), MessageModel::RedirectedToRole); } if (_validBuffers.contains(redirectedTo)) diff --git a/src/client/messagemodel.cpp b/src/client/messagemodel.cpp index 3cddb8a..d8a57ff 100644 --- a/src/client/messagemodel.cpp +++ b/src/client/messagemodel.cpp @@ -448,11 +448,11 @@ QVariant MessageModelItem::data(int column, int role) const switch (role) { case MessageModel::MessageRole: - return QVariant::fromValue(message()); + return QVariant::fromValue(message()); case MessageModel::MsgIdRole: - return QVariant::fromValue(msgId()); + return QVariant::fromValue(msgId()); case MessageModel::BufferIdRole: - return QVariant::fromValue(bufferId()); + return QVariant::fromValue(bufferId()); case MessageModel::TypeRole: return msgType(); case MessageModel::FlagsRole: @@ -460,9 +460,9 @@ QVariant MessageModelItem::data(int column, int role) const case MessageModel::TimestampRole: return timestamp(); case MessageModel::RedirectedToRole: - return qVariantFromValue(_redirectedTo); + return QVariant::fromValue(_redirectedTo); default: - return QVariant(); + return {}; } } diff --git a/src/client/networkmodel.cpp b/src/client/networkmodel.cpp index 649e368..6377232 100644 --- a/src/client/networkmodel.cpp +++ b/src/client/networkmodel.cpp @@ -72,7 +72,7 @@ QVariant NetworkItem::data(int column, int role) const else return QVariant(); case NetworkModel::NetworkIdRole: - return qVariantFromValue(_networkId); + return QVariant::fromValue(_networkId); case NetworkModel::ItemTypeRole: return NetworkModel::NetworkItemType; case NetworkModel::ItemActiveRole: @@ -406,11 +406,11 @@ QVariant BufferItem::data(int column, int role) const case NetworkModel::ItemTypeRole: return NetworkModel::BufferItemType; case NetworkModel::BufferIdRole: - return qVariantFromValue(bufferInfo().bufferId()); + return QVariant::fromValue(bufferInfo().bufferId()); case NetworkModel::NetworkIdRole: - return qVariantFromValue(bufferInfo().networkId()); + return QVariant::fromValue(bufferInfo().networkId()); case NetworkModel::BufferInfoRole: - return qVariantFromValue(bufferInfo()); + return QVariant::fromValue(bufferInfo()); case NetworkModel::BufferTypeRole: return int(bufferType()); case NetworkModel::ItemActiveRole: @@ -418,9 +418,9 @@ QVariant BufferItem::data(int column, int role) const case NetworkModel::BufferActivityRole: return (int)activityLevel(); case NetworkModel::BufferFirstUnreadMsgIdRole: - return qVariantFromValue(firstUnreadMsgId()); + return QVariant::fromValue(firstUnreadMsgId()); case NetworkModel::MarkerLineMsgIdRole: - return qVariantFromValue(markerLineMsgId()); + return QVariant::fromValue(markerLineMsgId()); default: return PropertyMapItem::data(column, role); } @@ -523,7 +523,7 @@ QVariant QueryBufferItem::data(int column, int role) const case Qt::EditRole: return BufferItem::data(column, Qt::DisplayRole); case NetworkModel::IrcUserRole: - return QVariant::fromValue(_ircUser); + return QVariant::fromValue(_ircUser); case NetworkModel::UserAwayRole: return (bool)_ircUser ? _ircUser->isAway() : false; default: @@ -750,7 +750,7 @@ QVariant ChannelBufferItem::data(int column, int role) const { switch (role) { case NetworkModel::IrcChannelRole: - return QVariant::fromValue(_ircChannel); + return QVariant::fromValue(_ircChannel); default: return BufferItem::data(column, role); } @@ -1147,7 +1147,7 @@ QVariant IrcUserItem::data(int column, int role) const case NetworkModel::IrcChannelRole: return parent()->data(column, role); case NetworkModel::IrcUserRole: - return QVariant::fromValue(_ircUser.data()); + return QVariant::fromValue(_ircUser.data()); case NetworkModel::UserAwayRole: return (bool)_ircUser ? _ircUser->isAway() : false; default: diff --git a/src/common/buffersyncer.cpp b/src/common/buffersyncer.cpp index ef2848e..837ee99 100644 --- a/src/common/buffersyncer.cpp +++ b/src/common/buffersyncer.cpp @@ -90,8 +90,7 @@ QVariantList BufferSyncer::initLastSeenMsg() const QVariantList list; QHash::const_iterator iter = _lastSeenMsg.constBegin(); while (iter != _lastSeenMsg.constEnd()) { - list << QVariant::fromValue(iter.key()) - << QVariant::fromValue(iter.value()); + list << QVariant::fromValue(iter.key()) << QVariant::fromValue(iter.value()); ++iter; } return list; @@ -113,8 +112,7 @@ QVariantList BufferSyncer::initMarkerLines() const QVariantList list; QHash::const_iterator iter = _markerLines.constBegin(); while (iter != _markerLines.constEnd()) { - list << QVariant::fromValue(iter.key()) - << QVariant::fromValue(iter.value()); + list << QVariant::fromValue(iter.key()) << QVariant::fromValue(iter.value()); ++iter; } return list; @@ -136,8 +134,7 @@ QVariantList BufferSyncer::initActivities() const QVariantList list; auto iter = _bufferActivities.constBegin(); while (iter != _bufferActivities.constEnd()) { - list << QVariant::fromValue(iter.key()) - << QVariant::fromValue((int) iter.value()); + list << QVariant::fromValue(iter.key()) << QVariant::fromValue((int)iter.value()); ++iter; } return list; @@ -197,8 +194,7 @@ QVariantList BufferSyncer::initHighlightCounts() const { QVariantList list; auto iter = _highlightCounts.constBegin(); while (iter != _highlightCounts.constEnd()) { - list << QVariant::fromValue(iter.key()) - << QVariant::fromValue((int) iter.value()); + list << QVariant::fromValue(iter.key()) << QVariant::fromValue((int)iter.value()); ++iter; } return list; diff --git a/src/common/network.cpp b/src/common/network.cpp index e9df78e..b337046 100644 --- a/src/common/network.cpp +++ b/src/common/network.cpp @@ -1209,8 +1209,8 @@ QDataStream &operator<<(QDataStream &out, const NetworkInfo &info) i["CodecForServer"] = info.codecForServer; i["CodecForEncoding"] = info.codecForEncoding; i["CodecForDecoding"] = info.codecForDecoding; - i["NetworkId"] = QVariant::fromValue(info.networkId); - i["Identity"] = QVariant::fromValue(info.identity); + i["NetworkId"] = QVariant::fromValue(info.networkId); + i["Identity"] = QVariant::fromValue(info.identity); i["MessageRateBurstSize"] = info.messageRateBurstSize; i["MessageRateDelay"] = info.messageRateDelay; i["AutoReconnectInterval"] = info.autoReconnectInterval; diff --git a/src/common/serializers/serializers.cpp b/src/common/serializers/serializers.cpp index 1cc4e76..b5ad884 100644 --- a/src/common/serializers/serializers.cpp +++ b/src/common/serializers/serializers.cpp @@ -29,7 +29,7 @@ bool toVariant(QDataStream& stream, Quassel::Features features, QVariant& data) if (!Serializers::deserialize(stream, features, content)) { return false; } - data = QVariant::fromValue(content); + data = QVariant::fromValue(content); return true; } diff --git a/src/common/types.h b/src/common/types.h index c4b9f36..e54fe81 100644 --- a/src/common/types.h +++ b/src/common/types.h @@ -100,27 +100,27 @@ inline uint qHash(const SignedId64 &id) { return qHash(id.toQint64()); } struct UserId : public SignedId { inline UserId(int _id = 0) : SignedId(_id) {} - //inline operator QVariant() const { return QVariant::fromValue(*this); } // no automatic conversion! + //inline operator QVariant() const { return QVariant::fromValue(*this); } // no automatic conversion! }; struct MsgId : public SignedId64 { inline MsgId(qint64 _id = 0) : SignedId64(_id) {} - //inline operator QVariant() const { return QVariant::fromValue(*this); } + //inline operator QVariant() const { return QVariant::fromValue(*this); } }; struct BufferId : public SignedId { inline BufferId(int _id = 0) : SignedId(_id) {} - //inline operator QVariant() const { return QVariant::fromValue(*this); } + //inline operator QVariant() const { return QVariant::fromValue(*this); } }; struct NetworkId : public SignedId { inline NetworkId(int _id = 0) : SignedId(_id) {} - //inline operator QVariant() const { return QVariant::fromValue(*this); } + //inline operator QVariant() const { return QVariant::fromValue(*this); } }; struct IdentityId : public SignedId { inline IdentityId(int _id = 0) : SignedId(_id) {} - //inline operator QVariant() const { return QVariant::fromValue(*this); } + //inline operator QVariant() const { return QVariant::fromValue(*this); } }; struct AccountId : public SignedId { diff --git a/src/common/util.h b/src/common/util.h index b721916..3f67129 100644 --- a/src/common/util.h +++ b/src/common/util.h @@ -53,7 +53,7 @@ QVariantList toVariantList(const QList &list) { QVariantList variants; for (int i = 0; i < list.count(); i++) { - variants << QVariant::fromValue(list[i]); + variants << QVariant::fromValue(list[i]); } return variants; } diff --git a/src/core/core.cpp b/src/core/core.cpp index 5d49ee2..11474a9 100644 --- a/src/core/core.cpp +++ b/src/core/core.cpp @@ -301,7 +301,7 @@ void Core::saveState() if (_storage) { QVariantList activeSessions; for (auto &&user : instance()->_sessions.keys()) - activeSessions << QVariant::fromValue(user); + activeSessions << QVariant::fromValue(user); _storage->setCoreState(activeSessions); } } diff --git a/src/qtui/chatitem.cpp b/src/qtui/chatitem.cpp index 04908d1..59a7cfb 100644 --- a/src/qtui/chatitem.cpp +++ b/src/qtui/chatitem.cpp @@ -871,7 +871,7 @@ void ContentsChatItem::addActionsToMenu(QMenu *menu, const QPointF &pos) case Clickable::Url: privateData()->activeClickable = click; menu->addAction(icon::get("edit-copy"), tr("Copy Link Address"), - &_actionProxy, SLOT(copyLinkToClipboard()))->setData(QVariant::fromValue(this)); + &_actionProxy, SLOT(copyLinkToClipboard()))->setData(QVariant::fromValue(static_cast(this))); break; case Clickable::Channel: { diff --git a/src/qtui/chatlinemodelitem.cpp b/src/qtui/chatlinemodelitem.cpp index 20888a1..fba94bf 100644 --- a/src/qtui/chatlinemodelitem.cpp +++ b/src/qtui/chatlinemodelitem.cpp @@ -76,7 +76,7 @@ bool ChatLineModelItem::setData(int column, const QVariant &value, int role) QVariant ChatLineModelItem::data(int column, int role) const { if (role == ChatLineModel::MsgLabelRole) - return QVariant::fromValue(messageLabel()); + return QVariant::fromValue(messageLabel()); QVariant variant; MessageModel::ColumnType col = (MessageModel::ColumnType)column; @@ -111,7 +111,8 @@ QVariant ChatLineModelItem::timestampData(int role) const case ChatLineModel::SelectedBackgroundRole: return backgroundBrush(UiStyle::FormatType::Timestamp, true); case ChatLineModel::FormatRole: - return QVariant::fromValue({std::make_pair(quint16{0}, UiStyle::Format{UiStyle::formatType(_styledMsg.type()) | UiStyle::FormatType::Timestamp, {}, {}})}); + return QVariant::fromValue(UiStyle::FormatList{ + std::make_pair(quint16{0}, UiStyle::Format{UiStyle::formatType(_styledMsg.type()) | UiStyle::FormatType::Timestamp, {}, {}})}); } return QVariant(); } @@ -129,7 +130,8 @@ QVariant ChatLineModelItem::senderData(int role) const case ChatLineModel::SelectedBackgroundRole: return backgroundBrush(UiStyle::FormatType::Sender, true); case ChatLineModel::FormatRole: - return QVariant::fromValue({std::make_pair(quint16{0}, UiStyle::Format{UiStyle::formatType(_styledMsg.type()) | UiStyle::FormatType::Sender, {}, {}})}); + return QVariant::fromValue(UiStyle::FormatList{ + std::make_pair(quint16{0}, UiStyle::Format{UiStyle::formatType(_styledMsg.type()) | UiStyle::FormatType::Sender, {}, {}})}); } return QVariant(); } @@ -146,11 +148,11 @@ QVariant ChatLineModelItem::contentsData(int role) const case ChatLineModel::SelectedBackgroundRole: return backgroundBrush(UiStyle::FormatType::Contents, true); case ChatLineModel::FormatRole: - return QVariant::fromValue(_styledMsg.contentsFormatList()); + return QVariant::fromValue(_styledMsg.contentsFormatList()); case ChatLineModel::WrapListRole: if (_wrapList.isEmpty()) computeWrapList(); - return QVariant::fromValue(_wrapList); + return QVariant::fromValue(_wrapList); } return QVariant(); } @@ -174,7 +176,7 @@ QVariant ChatLineModelItem::backgroundBrush(UiStyle::FormatType subelement, bool QTextCharFormat fmt = QtUi::style()->format({UiStyle::formatType(_styledMsg.type()) | subelement, {}, {}}, messageLabel() | (selected ? UiStyle::MessageLabel::Selected : UiStyle::MessageLabel::None)); if (fmt.hasProperty(QTextFormat::BackgroundBrush)) - return QVariant::fromValue(fmt.background()); + return QVariant::fromValue(fmt.background()); return QVariant(); } diff --git a/src/qtui/mainwin.cpp b/src/qtui/mainwin.cpp index 489c02c..17c1d1a 100644 --- a/src/qtui/mainwin.cpp +++ b/src/qtui/mainwin.cpp @@ -1774,7 +1774,7 @@ void MainWin::clientNetworkCreated(NetworkId id) const Network *net = Client::network(id); QAction *act = new QAction(net->networkName(), this); act->setObjectName(QString("NetworkAction-%1").arg(id.toInt())); - act->setData(QVariant::fromValue(id)); + act->setData(QVariant::fromValue(id)); connect(net, SIGNAL(updatedRemotely()), this, SLOT(clientNetworkUpdated())); connect(act, SIGNAL(triggered()), this, SLOT(connectOrDisconnectFromNet())); diff --git a/src/qtui/settingsdlg.cpp b/src/qtui/settingsdlg.cpp index 60c8b4f..8d36c2d 100644 --- a/src/qtui/settingsdlg.cpp +++ b/src/qtui/settingsdlg.cpp @@ -95,7 +95,7 @@ void SettingsDlg::registerSettingsPage(SettingsPage *sp) else item = new QTreeWidgetItem(cat, QStringList(sp->title())); - item->setData(0, SettingsPageRole, QVariant::fromValue(sp)); + item->setData(0, SettingsPageRole, QVariant::fromValue(sp)); pageIsLoaded[sp] = false; if (!ui.settingsTree->selectedItems().count()) ui.settingsTree->setCurrentItem(item); diff --git a/src/qtui/settingspages/chatmonitorsettingspage.cpp b/src/qtui/settingspages/chatmonitorsettingspage.cpp index d109ad8..bb1c35d 100644 --- a/src/qtui/settingspages/chatmonitorsettingspage.cpp +++ b/src/qtui/settingspages/chatmonitorsettingspage.cpp @@ -161,8 +161,8 @@ void ChatMonitorSettingsPage::save() // save list of active buffers QVariantList saveableBufferIdList; - foreach(BufferId id, _configActive->bufferList()) { - saveableBufferIdList << QVariant::fromValue(id); + foreach (BufferId id, _configActive->bufferList()) { + saveableBufferIdList << QVariant::fromValue(id); } chatViewSettings.setValue("Buffers", saveableBufferIdList); diff --git a/src/qtui/settingspages/networkssettingspage.cpp b/src/qtui/settingspages/networkssettingspage.cpp index 58409e8..dc62950 100644 --- a/src/qtui/settingspages/networkssettingspage.cpp +++ b/src/qtui/settingspages/networkssettingspage.cpp @@ -570,7 +570,7 @@ QListWidgetItem *NetworksSettingsPage::insertNetwork(const NetworkInfo &info) } if (!item) item = new QListWidgetItem(disconnectedIcon, info.networkName, ui.networkList); } - item->setData(Qt::UserRole, QVariant::fromValue(info.networkId)); + item->setData(Qt::UserRole, QVariant::fromValue(info.networkId)); setItemState(info.networkId, item); widgetHasChanged(); return item; diff --git a/src/qtui/settingspages/shortcutsmodel.cpp b/src/qtui/settingspages/shortcutsmodel.cpp index 72d87d6..93175df 100644 --- a/src/qtui/settingspages/shortcutsmodel.cpp +++ b/src/qtui/settingspages/shortcutsmodel.cpp @@ -156,7 +156,7 @@ QVariant ShortcutsModel::data(const QModelIndex &index, int role) const return QVariant(); case ActionRole: - return QVariant::fromValue(action); + return QVariant::fromValue(action); case DefaultShortcutRole: return action->shortcut(Action::DefaultShortcut); diff --git a/src/uisupport/networkmodelcontroller.cpp b/src/uisupport/networkmodelcontroller.cpp index ea88291..1617d2c 100644 --- a/src/uisupport/networkmodelcontroller.cpp +++ b/src/uisupport/networkmodelcontroller.cpp @@ -577,7 +577,7 @@ NetworkModelController::JoinDlg::JoinDlg(const QModelIndex &index, QWidget *pare foreach(NetworkId id, Client::networkIds()) { const Network *net = Client::network(id); if (net->isConnected()) { - networks->addItem(net->networkName(), QVariant::fromValue(id)); + networks->addItem(net->networkName(), QVariant::fromValue(id)); } } diff --git a/src/uisupport/toolbaractionprovider.cpp b/src/uisupport/toolbaractionprovider.cpp index 0af4c2a..5eabf15 100644 --- a/src/uisupport/toolbaractionprovider.cpp +++ b/src/uisupport/toolbaractionprovider.cpp @@ -165,7 +165,7 @@ void ToolBarActionProvider::networkCreated(NetworkId id) Action *act = new Action(net->networkName(), this); _networkActions[id] = act; act->setObjectName(QString("NetworkAction-%1").arg(id.toInt())); - act->setData(QVariant::fromValue(id)); + act->setData(QVariant::fromValue(id)); connect(net, SIGNAL(updatedRemotely()), SLOT(networkUpdated())); connect(act, SIGNAL(triggered()), SLOT(connectOrDisconnectNet())); networkUpdated(net); -- 2.30.2