mirror of
https://github.com/transmission/transmission.git
synced 2025-12-24 20:35:36 +00:00
refactor: prefer std::map over QMap in transmission-qt (#5641)
* refactor: use std::map instead of QMap in PrefsDialog.cc * refactor: use std::map instead of QMap in DetailsDialog.cc * refactor: use std::map instead of QMap in OptionsDialog.cc * refactor: use std::map instead of QMap in FileTreeModel.cc
This commit is contained in:
@@ -21,7 +21,6 @@
|
||||
#include <QItemSelectionModel>
|
||||
#include <QLabel>
|
||||
#include <QList>
|
||||
#include <QMap>
|
||||
#include <QMessageBox>
|
||||
#include <QResizeEvent>
|
||||
#include <QRegularExpression>
|
||||
@@ -1098,20 +1097,23 @@ void DetailsDialog::refreshUI()
|
||||
/// Peers tab
|
||||
///
|
||||
|
||||
QMap<QString, QTreeWidgetItem*> peers2;
|
||||
auto peers2 = decltype(peers_){};
|
||||
QList<QTreeWidgetItem*> new_items;
|
||||
|
||||
for (Torrent const* const t : torrents)
|
||||
{
|
||||
QString const id_str(QString::number(t->id()));
|
||||
PeerList const peers = t->peers();
|
||||
|
||||
for (Peer const& peer : peers)
|
||||
for (Peer const& peer : t->peers())
|
||||
{
|
||||
QString const key = id_str + QLatin1Char(':') + peer.address;
|
||||
auto* item = dynamic_cast<PeerItem*>(peers_.value(key, nullptr));
|
||||
|
||||
if (item == nullptr) // new peer has connected
|
||||
PeerItem* item = nullptr;
|
||||
if (auto iter = peers_.find(key); iter != std::end(peers_))
|
||||
{
|
||||
item = dynamic_cast<PeerItem*>(iter->second);
|
||||
}
|
||||
else // new peer has connected
|
||||
{
|
||||
item = new PeerItem(peer);
|
||||
item->setTextAlignment(COL_UP, Qt::AlignRight | Qt::AlignVCenter);
|
||||
@@ -1124,7 +1126,7 @@ void DetailsDialog::refreshUI()
|
||||
new_items << item;
|
||||
}
|
||||
|
||||
QString const code = peer.flags;
|
||||
auto const& code = peer.flags;
|
||||
item->setStatus(code);
|
||||
item->refresh(peer);
|
||||
|
||||
@@ -1207,23 +1209,22 @@ void DetailsDialog::refreshUI()
|
||||
item->setText(COL_STATUS, code);
|
||||
item->setToolTip(COL_STATUS, code_tip);
|
||||
|
||||
peers2.insert(key, item);
|
||||
peers2.try_emplace(key, item);
|
||||
}
|
||||
}
|
||||
|
||||
ui_.peersView->addTopLevelItems(new_items);
|
||||
|
||||
for (QString const& key : peers_.keys())
|
||||
for (auto const& [key, item] : peers_)
|
||||
{
|
||||
if (!peers2.contains(key)) // old peer has disconnected
|
||||
if (peers2.count(key) == 0U) // old peer has disconnected
|
||||
{
|
||||
QTreeWidgetItem* item = peers_.value(key, nullptr);
|
||||
ui_.peersView->takeTopLevelItem(ui_.peersView->indexOfTopLevelItem(item));
|
||||
delete item;
|
||||
}
|
||||
}
|
||||
|
||||
peers_ = peers2;
|
||||
peers_ = std::move(peers2);
|
||||
|
||||
if (single)
|
||||
{
|
||||
|
||||
@@ -5,11 +5,11 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <unordered_set>
|
||||
|
||||
#include <QString>
|
||||
#include <QMap>
|
||||
#include <QSet>
|
||||
#include <QTimer>
|
||||
|
||||
@@ -137,7 +137,7 @@ private:
|
||||
std::shared_ptr<TrackerModelFilter> tracker_filter_;
|
||||
std::shared_ptr<TrackerDelegate> tracker_delegate_;
|
||||
|
||||
QMap<QString, QTreeWidgetItem*> peers_;
|
||||
std::map<QString, QTreeWidgetItem*> peers_;
|
||||
|
||||
QIcon const icon_encrypted_ = QIcon(QStringLiteral(":/icons/encrypted.svg"));
|
||||
QIcon const icon_unencrypted_ = {};
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
|
||||
#include <algorithm>
|
||||
#include <cassert>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
|
||||
#include <libtransmission/transmission.h> // priorities
|
||||
@@ -463,7 +464,7 @@ void FileTreeModel::emitSubtreeChanged(QModelIndex const& idx, int first_column,
|
||||
|
||||
void FileTreeModel::twiddleWanted(QModelIndexList const& indices)
|
||||
{
|
||||
QMap<bool, QModelIndexList> wanted_indices;
|
||||
std::map<bool, QModelIndexList> wanted_indices;
|
||||
|
||||
for (QModelIndex const& i : getOrphanIndices(indices))
|
||||
{
|
||||
@@ -473,7 +474,7 @@ void FileTreeModel::twiddleWanted(QModelIndexList const& indices)
|
||||
|
||||
for (int i = 0; i <= 1; ++i)
|
||||
{
|
||||
if (wanted_indices.contains(i))
|
||||
if (wanted_indices.count(i) != 0)
|
||||
{
|
||||
setWanted(wanted_indices[i], i != 0);
|
||||
}
|
||||
@@ -482,7 +483,7 @@ void FileTreeModel::twiddleWanted(QModelIndexList const& indices)
|
||||
|
||||
void FileTreeModel::twiddlePriority(QModelIndexList const& indices)
|
||||
{
|
||||
QMap<int, QModelIndexList> priority_indices;
|
||||
std::map<int, QModelIndexList> priority_indices;
|
||||
|
||||
for (QModelIndex const& i : getOrphanIndices(indices))
|
||||
{
|
||||
@@ -508,7 +509,7 @@ void FileTreeModel::twiddlePriority(QModelIndexList const& indices)
|
||||
|
||||
for (int i = TR_PRI_LOW; i <= TR_PRI_HIGH; ++i)
|
||||
{
|
||||
if (priority_indices.contains(i))
|
||||
if (priority_indices.count(i) != 0U)
|
||||
{
|
||||
setPriority(priority_indices[i], i);
|
||||
}
|
||||
|
||||
@@ -5,12 +5,12 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <map>
|
||||
#include <optional>
|
||||
#include <vector>
|
||||
|
||||
#include <QDir>
|
||||
#include <QFile>
|
||||
#include <QMap>
|
||||
#include <QSet>
|
||||
#include <QString>
|
||||
#include <QTimer>
|
||||
@@ -54,7 +54,7 @@ private slots:
|
||||
void onSessionUpdated();
|
||||
|
||||
private:
|
||||
using mybins_t = QMap<uint32_t, int32_t>;
|
||||
using mybins_t = std::map<uint32_t, int32_t>;
|
||||
|
||||
void reload();
|
||||
void updateWidgetsLocality();
|
||||
|
||||
@@ -203,7 +203,7 @@ void PrefsDialog::linkWidgetToPref(QWidget* widget, int pref_key)
|
||||
|
||||
pref_widget.setPrefKey(pref_key);
|
||||
updateWidgetValue(widget, pref_key);
|
||||
widgets_.insert(pref_key, widget);
|
||||
widgets_.try_emplace(pref_key, widget);
|
||||
|
||||
if (auto const* check_box = qobject_cast<QCheckBox*>(widget); check_box != nullptr)
|
||||
{
|
||||
@@ -807,11 +807,9 @@ void PrefsDialog::refreshPref(int key)
|
||||
break;
|
||||
}
|
||||
|
||||
key2widget_t::iterator const it(widgets_.find(key));
|
||||
|
||||
if (it != widgets_.end())
|
||||
if (auto iter = widgets_.find(key); iter != std::end(widgets_))
|
||||
{
|
||||
QWidget* w(it.value());
|
||||
QWidget* const w = iter->second;
|
||||
|
||||
w->blockSignals(true);
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QMap>
|
||||
#include <map>
|
||||
|
||||
#include <libtransmission/tr-macros.h>
|
||||
|
||||
@@ -50,7 +50,7 @@ private slots:
|
||||
void onBlocklistUpdated(int n);
|
||||
|
||||
private:
|
||||
using key2widget_t = QMap<int, QWidget*>;
|
||||
using key2widget_t = std::map<int, QWidget*>;
|
||||
|
||||
bool updateWidgetValue(QWidget* widget, int pref_key) const;
|
||||
void linkWidgetToPref(QWidget* widget, int pref_key);
|
||||
|
||||
Reference in New Issue
Block a user