common: Always let QVariant::fromValue() deduce the type
authorManuel Nickschas <sputnick@quassel-irc.org>
Tue, 7 Jan 2020 17:39:48 +0000 (18:39 +0100)
committerManuel Nickschas <sputnick@quassel-irc.org>
Wed, 8 Jan 2020 18:41:46 +0000 (19:41 +0100)
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()).

21 files changed:
src/client/coreaccountmodel.cpp
src/client/messagefilter.cpp
src/client/messagemodel.cpp
src/client/networkmodel.cpp
src/common/buffersyncer.cpp
src/common/network.cpp
src/common/serializers/serializers.cpp
src/common/signalproxy.h
src/common/types.h
src/common/util.h
src/core/core.cpp
src/qtui/chatitem.cpp
src/qtui/chatlinemodelitem.cpp
src/qtui/chatviewsettings.cpp
src/qtui/mainwin.cpp
src/qtui/settingsdlg.cpp
src/qtui/settingspages/chatmonitorsettingspage.cpp
src/qtui/settingspages/networkssettingspage.cpp
src/qtui/settingspages/shortcutsmodel.cpp
src/uisupport/networkmodelcontroller.cpp
src/uisupport/toolbaractionprovider.cpp

index 91b697b..21ebc01 100644 (file)
@@ -98,7 +98,7 @@ QVariant CoreAccountModel::data(const QModelIndex& index, int role) const
     case Qt::DisplayRole:
         return acc.accountName();
     case AccountIdRole:
-        return QVariant::fromValue<AccountId>(acc.accountId());
+        return QVariant::fromValue(acc.accountId());
     case UuidRole:
         return acc.uuid().toString();
 
index 49676e3..97cf892 100644 (file)
@@ -186,7 +186,7 @@ bool MessageFilter::filterAcceptsRow(int sourceRow, const QModelIndex& sourcePar
             if (!redirectedTo.isValid()) {
                 BufferId redirectedTo = Client::bufferModel()->currentIndex().data(NetworkModel::BufferIdRole).value<BufferId>();
                 if (redirectedTo.isValid())
-                    sourceModel()->setData(sourceIdx, QVariant::fromValue<BufferId>(redirectedTo), MessageModel::RedirectedToRole);
+                    sourceModel()->setData(sourceIdx, QVariant::fromValue(redirectedTo), MessageModel::RedirectedToRole);
             }
 
             if (_validBuffers.contains(redirectedTo))
index 61c6bbd..1211af9 100644 (file)
@@ -439,11 +439,11 @@ QVariant MessageModelItem::data(int column, int role) const
 
     switch (role) {
     case MessageModel::MessageRole:
-        return QVariant::fromValue<Message>(message());
+        return QVariant::fromValue(message());
     case MessageModel::MsgIdRole:
-        return QVariant::fromValue<MsgId>(msgId());
+        return QVariant::fromValue(msgId());
     case MessageModel::BufferIdRole:
-        return QVariant::fromValue<BufferId>(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<BufferId>(_redirectedTo);
+        return QVariant::fromValue(_redirectedTo);
     default:
-        return QVariant();
+        return {};
     }
 }
 
index b398613..280ca18 100644 (file)
@@ -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<QObject*>(_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<QObject*>(_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<QObject*>(_ircUser.data());
+        return QVariant::fromValue(_ircUser.data());
     case NetworkModel::UserAwayRole:
         return (bool)_ircUser ? _ircUser->isAway() : false;
     default:
index 1c432a4..b4c1588 100644 (file)
@@ -82,7 +82,7 @@ QVariantList BufferSyncer::initLastSeenMsg() const
     QVariantList list;
     QHash<BufferId, MsgId>::const_iterator iter = _lastSeenMsg.constBegin();
     while (iter != _lastSeenMsg.constEnd()) {
-        list << QVariant::fromValue<BufferId>(iter.key()) << QVariant::fromValue<MsgId>(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<BufferId, MsgId>::const_iterator iter = _markerLines.constBegin();
     while (iter != _markerLines.constEnd()) {
-        list << QVariant::fromValue<BufferId>(iter.key()) << QVariant::fromValue<MsgId>(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<BufferId>(iter.key()) << QVariant::fromValue<int>((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<BufferId>(iter.key()) << QVariant::fromValue<int>((int)iter.value());
+        list << QVariant::fromValue(iter.key()) << QVariant::fromValue((int)iter.value());
         ++iter;
     }
     return list;
index af5f00e..bb9b6bf 100644 (file)
@@ -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<NetworkId>(info.networkId);
-    i["Identity"]                  = QVariant::fromValue<IdentityId>(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;
index 809aef9..139b053 100644 (file)
@@ -29,7 +29,7 @@ bool toVariant(QDataStream& stream, Quassel::Features features, QVariant& data)
     if (!Serializers::deserialize(stream, features, content)) {
         return false;
     }
-    data = QVariant::fromValue<T>(content);
+    data = QVariant::fromValue(content);
     return true;
 }
 
index e3bc1d5..35c4356 100644 (file)
@@ -333,7 +333,7 @@ bool SignalProxy::attachSignal(const typename FunctionTraits<Signal>::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<decltype(args)>(args)...});
+        this->dispatchSignal(std::move(signalName), {QVariant::fromValue(args)...});
     });
 
     return true;
index e2a9aab..5cd002a 100644 (file)
@@ -140,7 +140,7 @@ struct UserId : public SignedId
     inline UserId(int _id = 0)
         : SignedId(_id)
     {}
-    // inline operator QVariant() const { return QVariant::fromValue<UserId>(*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<MsgId>(*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<BufferId>(*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<NetworkId>(*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<IdentityId>(*this); }
+    // inline operator QVariant() const { return QVariant::fromValue(*this); }
 };
 
 struct AccountId : public SignedId
index bbe89f5..19aeb4f 100644 (file)
@@ -55,7 +55,7 @@ QVariantList toVariantList(const QList<T>& list)
 {
     QVariantList variants;
     for (int i = 0; i < list.count(); i++) {
-        variants << QVariant::fromValue<T>(list[i]);
+        variants << QVariant::fromValue(list[i]);
     }
     return variants;
 }
index b0c02c1..cf01e5f 100644 (file)
@@ -302,7 +302,7 @@ void Core::saveState()
     if (_storage) {
         QVariantList activeSessions;
         for (auto&& user : instance()->_sessions.keys())
-            activeSessions << QVariant::fromValue<UserId>(user);
+            activeSessions << QVariant::fromValue(user);
         _storage->setCoreState(activeSessions);
     }
 }
index 913c81e..fe2e3e7 100644 (file)
@@ -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<void*>(this));
+            action->setData(QVariant::fromValue(static_cast<void*>(this)));
             menu->addAction(action);
             break;
         }
index 9ebc126..5c35582 100644 (file)
@@ -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<UiStyle::MessageLabel>(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<UiStyle::FormatList>(
-            {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<UiStyle::FormatList>(
-            {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<UiStyle::FormatList>(_styledMsg.contentsFormatList());
+        return QVariant::fromValue(_styledMsg.contentsFormatList());
     case ChatLineModel::WrapListRole:
         if (_wrapList.isEmpty())
             computeWrapList();
-        return QVariant::fromValue<ChatLineModel::WrapList>(_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<QBrush>(fmt.background());
+        return QVariant::fromValue(fmt.background());
     return QVariant();
 }
 
index 107478b..685e6ed 100644 (file)
@@ -70,7 +70,7 @@ void ChatViewSettings::setTimestampFormatString(const QString& format)
 UiStyle::SenderPrefixMode ChatViewSettings::senderPrefixDisplay() const
 {
     return static_cast<UiStyle::SenderPrefixMode>(
-        localValue("SenderPrefixMode", QVariant::fromValue<UiStyle::SenderPrefixMode>(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<UiStyle::SenderPrefixMode>() returned true, but
     // .value<UiStyle::SenderPrefixMode>(); always gave the default value 0.
index 5b0118a..b126dd9 100644 (file)
@@ -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<NetworkId>(id));
+    act->setData(QVariant::fromValue(id));
     connect(net, &SyncableObject::updatedRemotely, this, &MainWin::clientNetworkUpdated);
     connect(act, &QAction::triggered, this, &MainWin::connectOrDisconnectFromNet);
 
index f943c9a..13e6a33 100644 (file)
@@ -91,7 +91,7 @@ void SettingsDlg::registerSettingsPage(SettingsPage* sp)
     else
         item = new QTreeWidgetItem(cat, QStringList(sp->title()));
 
-    item->setData(0, SettingsPageRole, QVariant::fromValue<QObject*>(sp));
+    item->setData(0, SettingsPageRole, QVariant::fromValue(sp));
     pageIsLoaded[sp] = false;
     if (!ui.settingsTree->selectedItems().count())
         ui.settingsTree->setCurrentItem(item);
index 812a6e6..73d962b 100644 (file)
@@ -156,7 +156,7 @@ void ChatMonitorSettingsPage::save()
     // save list of active buffers
     QVariantList saveableBufferIdList;
     foreach (BufferId id, _configActive->bufferList()) {
-        saveableBufferIdList << QVariant::fromValue<BufferId>(id);
+        saveableBufferIdList << QVariant::fromValue(id);
     }
 
     chatViewSettings.setValue("Buffers", saveableBufferIdList);
index fa654a9..57f898f 100644 (file)
@@ -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<NetworkId>(info.networkId));
+    item->setData(Qt::UserRole, QVariant::fromValue(info.networkId));
     setItemState(info.networkId, item);
     widgetHasChanged();
     return item;
index bdf07be..fe93e61 100644 (file)
@@ -149,7 +149,7 @@ QVariant ShortcutsModel::data(const QModelIndex& index, int role) const
         return QVariant();
 
     case ActionRole:
-        return QVariant::fromValue<QObject*>(action);
+        return QVariant::fromValue(action);
 
     case DefaultShortcutRole:
         return action->shortcut(Action::DefaultShortcut);
index 2ac3536..c7eab5c 100644 (file)
@@ -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<NetworkId>(id));
+            networks->addItem(net->networkName(), QVariant::fromValue(id));
         }
     }
 
index c65a62d..36b76e7 100644 (file)
@@ -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<NetworkId>(id));
+    act->setData(QVariant::fromValue(id));
     connect(net, &Network::updatedRemotely, this, [this]() { networkUpdated(); });
     connect(act, &QAction::triggered, this, &ToolBarActionProvider::connectOrDisconnectNet);
     networkUpdated(net);