From: Manuel Nickschas Date: Tue, 7 Jan 2020 17:39:48 +0000 (+0100) Subject: common: Always let QVariant::fromValue() deduce the type X-Git-Tag: test-travis-01~19 X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=commitdiff_plain;h=41bf70c263ee0af80ad1850fabe77ffffee188f4 common: Always let QVariant::fromValue() deduce the type 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()). --- diff --git a/src/client/coreaccountmodel.cpp b/src/client/coreaccountmodel.cpp index 91b697b4..21ebc019 100644 --- a/src/client/coreaccountmodel.cpp +++ b/src/client/coreaccountmodel.cpp @@ -98,7 +98,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 49676e32..97cf8929 100644 --- a/src/client/messagefilter.cpp +++ b/src/client/messagefilter.cpp @@ -186,7 +186,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 61c6bbdd..1211af9a 100644 --- a/src/client/messagemodel.cpp +++ b/src/client/messagemodel.cpp @@ -439,11 +439,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: @@ -451,9 +451,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 b3986135..280ca18a 100644 --- a/src/client/networkmodel.cpp +++ b/src/client/networkmodel.cpp @@ -70,7 +70,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: @@ -377,11 +377,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: @@ -389,9 +389,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); } @@ -483,7 +483,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: @@ -696,7 +696,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); } @@ -1063,7 +1063,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 1c432a48..b4c15887 100644 --- a/src/common/buffersyncer.cpp +++ b/src/common/buffersyncer.cpp @@ -82,7 +82,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; @@ -102,7 +102,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; @@ -122,7 +122,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; @@ -180,7 +180,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 af5f00e9..bb9b6bf9 100644 --- a/src/common/network.cpp +++ b/src/common/network.cpp @@ -1156,8 +1156,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 809aef92..139b0532 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/signalproxy.h b/src/common/signalproxy.h index e3bc1d50..35c43564 100644 --- a/src/common/signalproxy.h +++ b/src/common/signalproxy.h @@ -333,7 +333,7 @@ bool SignalProxy::attachSignal(const typename FunctionTraits::ClassType* // Upon signal emission, marshall the signal's arguments into a QVariantList and dispatch an RpcCall message connect(sender, signal, this, [this, signalName = std::move(name)](auto&&... args) { - this->dispatchSignal(std::move(signalName), {QVariant::fromValue(args)...}); + this->dispatchSignal(std::move(signalName), {QVariant::fromValue(args)...}); }); return true; diff --git a/src/common/types.h b/src/common/types.h index e2a9aab5..5cd002a6 100644 --- a/src/common/types.h +++ b/src/common/types.h @@ -140,7 +140,7 @@ 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 @@ -148,7 +148,7 @@ 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 @@ -156,7 +156,7 @@ 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 @@ -164,7 +164,7 @@ 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 @@ -172,7 +172,7 @@ 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 bbe89f51..19aeb4fe 100644 --- a/src/common/util.h +++ b/src/common/util.h @@ -55,7 +55,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 b0c02c12..cf01e5f5 100644 --- a/src/core/core.cpp +++ b/src/core/core.cpp @@ -302,7 +302,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 913c81e7..fe2e3e70 100644 --- a/src/qtui/chatitem.cpp +++ b/src/qtui/chatitem.cpp @@ -824,7 +824,7 @@ void ContentsChatItem::addActionsToMenu(QMenu* menu, const QPointF& pos) case Clickable::Url: { privateData()->activeClickable = click; auto action = new Action{icon::get("edit-copy"), tr("Copy Link Address"), menu, &_actionProxy, &ActionProxy::copyLinkToClipboard}; - action->setData(QVariant::fromValue(this)); + action->setData(QVariant::fromValue(static_cast(this))); menu->addAction(action); break; } diff --git a/src/qtui/chatlinemodelitem.cpp b/src/qtui/chatlinemodelitem.cpp index 9ebc1264..5c355821 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; auto col = (MessageModel::ColumnType)column; @@ -110,8 +110,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(); } @@ -128,8 +128,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(); } @@ -145,11 +145,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(); } @@ -171,7 +171,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/chatviewsettings.cpp b/src/qtui/chatviewsettings.cpp index 107478b1..685e6ed0 100644 --- a/src/qtui/chatviewsettings.cpp +++ b/src/qtui/chatviewsettings.cpp @@ -70,7 +70,7 @@ void ChatViewSettings::setTimestampFormatString(const QString& format) UiStyle::SenderPrefixMode ChatViewSettings::senderPrefixDisplay() const { return static_cast( - localValue("SenderPrefixMode", QVariant::fromValue(UiStyle::SenderPrefixMode::HighestMode)).toInt()); + localValue("SenderPrefixMode", QVariant::fromValue(UiStyle::SenderPrefixMode::HighestMode)).toInt()); // Cast the QVariant to an integer, then cast that to the enum class. // .canConvert() returned true, but // .value(); always gave the default value 0. diff --git a/src/qtui/mainwin.cpp b/src/qtui/mainwin.cpp index 5b0118a2..b126dd9c 100644 --- a/src/qtui/mainwin.cpp +++ b/src/qtui/mainwin.cpp @@ -1725,7 +1725,7 @@ void MainWin::clientNetworkCreated(NetworkId id) const Network* net = Client::network(id); auto* 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, &SyncableObject::updatedRemotely, this, &MainWin::clientNetworkUpdated); connect(act, &QAction::triggered, this, &MainWin::connectOrDisconnectFromNet); diff --git a/src/qtui/settingsdlg.cpp b/src/qtui/settingsdlg.cpp index f943c9af..13e6a33b 100644 --- a/src/qtui/settingsdlg.cpp +++ b/src/qtui/settingsdlg.cpp @@ -91,7 +91,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 812a6e6c..73d962b4 100644 --- a/src/qtui/settingspages/chatmonitorsettingspage.cpp +++ b/src/qtui/settingspages/chatmonitorsettingspage.cpp @@ -156,7 +156,7 @@ void ChatMonitorSettingsPage::save() // save list of active buffers QVariantList saveableBufferIdList; foreach (BufferId id, _configActive->bufferList()) { - saveableBufferIdList << QVariant::fromValue(id); + saveableBufferIdList << QVariant::fromValue(id); } chatViewSettings.setValue("Buffers", saveableBufferIdList); diff --git a/src/qtui/settingspages/networkssettingspage.cpp b/src/qtui/settingspages/networkssettingspage.cpp index fa654a95..57f898f6 100644 --- a/src/qtui/settingspages/networkssettingspage.cpp +++ b/src/qtui/settingspages/networkssettingspage.cpp @@ -556,7 +556,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 bdf07be0..fe93e610 100644 --- a/src/qtui/settingspages/shortcutsmodel.cpp +++ b/src/qtui/settingspages/shortcutsmodel.cpp @@ -149,7 +149,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 2ac35368..c7eab5cb 100644 --- a/src/uisupport/networkmodelcontroller.cpp +++ b/src/uisupport/networkmodelcontroller.cpp @@ -564,7 +564,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 c65a62dd..36b76e7d 100644 --- a/src/uisupport/toolbaractionprovider.cpp +++ b/src/uisupport/toolbaractionprovider.cpp @@ -150,7 +150,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, &Network::updatedRemotely, this, [this]() { networkUpdated(); }); connect(act, &QAction::triggered, this, &ToolBarActionProvider::connectOrDisconnectNet); networkUpdated(net);