refactor: re-enable some clang-tidy checks in qt/ (#2585)

* chore: re-enable readability-static-accessed-through-instance test in qt

* chore: re-enable clang-diagnostic-nonportable-system-include-path check in qt/

* chore: re-enable clang-diagnostic-undefined-reinterpret-cast test in qt/

* chore: re-enable cert-err58-cpp check in qt/

* chore: re-enable clang-diagnostic-switch-enum check in qt/

* chore: re-enable modernize-return-braced-init-list check in qt/

* chore: re-enable cppcoreguidelines-pro-type-static-cast-downcast check in qt/

* chore: re-enable cppcoreguidelines-pro-type-cstyle-cast check in qt/

* refactor: re-enable cppcoreguidelines-init-variables check in qt/

* chore: re-enable cppcoreguidelines-pro-type-vararg check in qt/

* chore: remove explicit disable of clang-diagnostic-old-style-cast check in qt/

* chore: re-enable bugprone-implicit-widening-of-multiplication-result check in qt/
This commit is contained in:
Charles Kerr 2022-02-07 21:56:04 -06:00 committed by GitHub
parent ebb2ab6aee
commit 8afbfecadb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
22 changed files with 139 additions and 241 deletions

View File

@ -5,25 +5,18 @@ Checks: >
bugprone-*,
-bugprone-branch-clone,
-bugprone-easily-swappable-parameters,
-bugprone-implicit-widening-of-multiplication-result,
-bugprone-narrowing-conversions,
cert-*,
-cert-err58-cpp,
clang-analyzer-optin*,
-clang-diagnostic-c++98*,
-clang-diagnostic-double-promotion,
-clang-diagnostic-exit-time-destructors,
-clang-diagnostic-global-constructors,
-clang-diagnostic-nonportable-system-include-path,
-clang-diagnostic-old-style-cast,
-clang-diagnostic-shorten-64-to-32,
-clang-diagnostic-sign-compare,
-clang-diagnostic-sign-conversion,
-clang-diagnostic-switch-enum,
-clang-diagnostic-undefined-reinterpret-cast,
cppcoreguidelines-*,
-cppcoreguidelines-avoid-magic-numbers,
-cppcoreguidelines-init-variables,
-cppcoreguidelines-macro-usage,
-cppcoreguidelines-narrowing-conversions,
-cppcoreguidelines-non-private-member-variables-in-classes,
@ -33,9 +26,6 @@ Checks: >
-cppcoreguidelines-pro-bounds-constant-array-index,
-cppcoreguidelines-pro-bounds-pointer-arithmetic,
-cppcoreguidelines-pro-type-const-cast,
-cppcoreguidelines-pro-type-cstyle-cast,
-cppcoreguidelines-pro-type-static-cast-downcast,
-cppcoreguidelines-pro-type-vararg,
google-readability-*,
-google-readability-casting,
google-runtime-operator,
@ -44,12 +34,10 @@ Checks: >
-hicpp-no-array-decay,
-hicpp-signed-bitwise,
-hicpp-special-member-functions,
-hicpp-vararg,
misc-*,
-misc-no-recursion,
-misc-non-private-member-variables-in-classes,
modernize-*,
-modernize-return-braced-init-list,
-modernize-use-trailing-return-type, # keep
performance-*,
readability-*,
@ -59,8 +47,7 @@ Checks: >
-readability-implicit-bool-conversion,
-readability-inconsistent-declaration-parameter-name,
-readability-magic-numbers,
-readability-redundant-access-specifiers,
-readability-static-accessed-through-instance
-readability-redundant-access-specifiers
CheckOptions:
- { key: readability-identifier-naming.ClassCase, value: CamelCase }

View File

@ -118,9 +118,9 @@ Application::Application(int& argc, char** argv)
#endif
// parse the command-line arguments
int c;
int c = 0;
bool minimized = false;
char const* optarg;
char const* optarg = nullptr;
QString host;
QString port;
QString username;

View File

@ -98,4 +98,4 @@ private:
#endif
};
#define trApp static_cast<Application*>(Application::instance())
#define trApp dynamic_cast<Application*>(Application::instance())

View File

@ -899,15 +899,11 @@ void DetailsDialog::refreshUI()
if (canEdit() && !torrents.empty())
{
int i;
bool uniform;
bool baseline_flag;
int baseline_int;
Torrent const& baseline = *torrents.front();
// mySessionLimitCheck
uniform = true;
baseline_flag = baseline.honorsSessionLimits();
bool uniform = true;
bool baseline_flag = baseline.honorsSessionLimits();
for (Torrent const* const tor : torrents)
{
@ -952,7 +948,7 @@ void DetailsDialog::refreshUI()
// myBandwidthPriorityCombo
uniform = true;
baseline_int = baseline.getBandwidthPriority();
int baseline_int = baseline.getBandwidthPriority();
for (Torrent const* const tor : torrents)
{
@ -963,14 +959,7 @@ void DetailsDialog::refreshUI()
}
}
if (uniform)
{
i = ui_.bandwidthPriorityCombo->findData(baseline_int);
}
else
{
i = -1;
}
int i = uniform ? ui_.bandwidthPriorityCombo->findData(baseline_int) : -1;
setIfIdle(ui_.bandwidthPriorityCombo, i);
@ -1042,7 +1031,7 @@ void DetailsDialog::refreshUI()
for (Peer const& peer : peers)
{
QString const key = id_str + QLatin1Char(':') + peer.address;
auto* item = static_cast<PeerItem*>(peers_.value(key, nullptr));
auto* item = dynamic_cast<PeerItem*>(peers_.value(key, nullptr));
if (item == nullptr) // new peer has connected
{
@ -1494,26 +1483,27 @@ void DetailsDialog::initFilesTab() const
connect(ui_.filesView, &FileTreeView::wantedChanged, this, &DetailsDialog::onFileWantedChanged);
}
void DetailsDialog::onFilePriorityChanged(QSet<int> const& indices, int priority)
static constexpr tr_quark priorityKey(int priority)
{
tr_quark key;
switch (priority)
{
case TR_PRI_LOW:
key = TR_KEY_priority_low;
return TR_KEY_priority_low;
break;
case TR_PRI_HIGH:
key = TR_KEY_priority_high;
return TR_KEY_priority_high;
break;
default:
key = TR_KEY_priority_normal;
return TR_KEY_priority_normal;
break;
}
}
torrentSet(key, indices.values());
void DetailsDialog::onFilePriorityChanged(QSet<int> const& indices, int priority)
{
torrentSet(priorityKey(priority), indices.values());
}
void DetailsDialog::onFileWantedChanged(QSet<int> const& indices, bool wanted)

View File

@ -166,7 +166,7 @@ FaviconCache::Key FaviconCache::getKey(QString const& displayName)
QSize FaviconCache::getIconSize()
{
return QSize(16, 16);
return { 16, 16 };
}
QPixmap FaviconCache::find(Key const& key)

View File

@ -170,7 +170,7 @@ Qt::ItemFlags FileTreeModel::flags(QModelIndex const& index) const
i |= Qt::ItemIsUserCheckable | Qt::ItemIsAutoTristate;
}
return Qt::ItemFlags(i);
return { i };
}
bool FileTreeModel::setData(QModelIndex const& index, QVariant const& newname, int role)
@ -221,30 +221,17 @@ QVariant FileTreeModel::headerData(int column, Qt::Orientation orientation, int
QModelIndex FileTreeModel::index(int row, int column, QModelIndex const& parent) const
{
QModelIndex i;
if (hasIndex(row, column, parent))
{
FileTreeItem* parent_item;
auto* const parent_item = parent.isValid() ? itemFromIndex(parent) : root_item_.get();
if (!parent.isValid())
if (auto* const child_item = parent_item->child(row); child_item != nullptr)
{
parent_item = root_item_.get();
}
else
{
parent_item = itemFromIndex(parent);
}
FileTreeItem* child_item = parent_item->child(row);
if (child_item != nullptr)
{
i = createIndex(row, column, child_item);
return createIndex(row, column, child_item);
}
}
return i;
return {};
}
QModelIndex FileTreeModel::parent(QModelIndex const& child) const
@ -282,7 +269,7 @@ QModelIndex FileTreeModel::indexOf(FileTreeItem* item, int column) const
{
if (item == nullptr || item == root_item_.get())
{
return QModelIndex();
return {};
}
return createIndex(item->row(), column, item);
@ -336,9 +323,7 @@ void FileTreeModel::addFile(
uint64_t have,
bool update_fields)
{
FileTreeItem* item;
item = findItemForFileIndex(file_index);
auto* item = findItemForFileIndex(file_index);
if (item != nullptr) // this file is already in the tree, we've added this
{

View File

@ -106,7 +106,7 @@ QSize FilterBarComboBoxDelegate::sizeHint(QStyleOptionViewItem const& option, QM
if (isSeparator(index))
{
int const pm = combo_->style()->pixelMetric(QStyle::PM_DefaultFrameWidth, nullptr, combo_);
return QSize(pm, pm + 10);
return { pm, pm + 10 };
}
QStyle* s = combo_->style();

View File

@ -1118,19 +1118,16 @@ void MainWindow::trayActivated(QSystemTrayIcon::ActivationReason reason)
void MainWindow::refreshPref(int key)
{
bool b;
int i;
QString str;
QActionGroup const* action_group;
auto b = bool{};
auto i = int{};
auto str = QString{};
switch (key)
{
case Prefs::STATUSBAR_STATS:
str = prefs_.getString(key);
action_group = ui_.action_TotalRatio->actionGroup();
assert(action_group != nullptr);
for (QAction* action : action_group->actions())
for (auto* action : ui_.action_TotalRatio->actionGroup()->actions())
{
action->setChecked(str == action->property(StatsModeKey).toString());
}
@ -1144,10 +1141,8 @@ void MainWindow::refreshPref(int key)
case Prefs::SORT_MODE:
i = prefs_.get<SortMode>(key).mode();
action_group = ui_.action_SortByActivity->actionGroup();
assert(action_group != nullptr);
for (QAction* action : action_group->actions())
for (auto* action : ui_.action_SortByActivity->actionGroup()->actions())
{
action->setChecked(i == action->property(SortModeKey).toInt());
}
@ -1260,8 +1255,7 @@ void MainWindow::newTorrent()
void MainWindow::openTorrent()
{
QFileDialog* d;
d = new QFileDialog(
auto* const d = new QFileDialog(
this,
tr("Open Torrent"),
prefs_.getString(Prefs::OPEN_DIALOG_FOLDER),
@ -1342,7 +1336,6 @@ void MainWindow::removeTorrents(bool const delete_files)
QString secondary_text;
int incomplete = 0;
int connected = 0;
int count;
for (QModelIndex const& index : ui_.listView->selectionModel()->selectedRows())
{
@ -1365,7 +1358,7 @@ void MainWindow::removeTorrents(bool const delete_files)
return;
}
count = ids.size();
int const count = ids.size();
if (!delete_files)
{
@ -1487,7 +1480,7 @@ void MainWindow::updateNetworkIcon()
{
tip = tr("%1 is responding").arg(url);
}
else if (seconds_since_last_read < 60 * 2)
else if (seconds_since_last_read < 120)
{
tip = tr("%1 last responded %2 ago").arg(url).arg(Formatter::get().timeToString(seconds_since_last_read));
}

View File

@ -71,7 +71,7 @@ QString const& PathButton::path() const
QSize PathButton::sizeHint() const
{
QSize const sh(QToolButton::sizeHint());
return QSize(qMin(sh.width(), 150), sh.height());
return { qMin(sh.width(), 150), sh.height() };
}
void PathButton::paintEvent(QPaintEvent* /*event*/)

View File

@ -156,7 +156,7 @@ std::array<Prefs::PrefItem, Prefs::PREFS_COUNT> const Prefs::Items{
namespace
{
auto const FilterModes = std::array<std::pair<int, std::string_view>, FilterMode::NUM_MODES>{ {
auto constexpr FilterModes = std::array<std::pair<int, std::string_view>, FilterMode::NUM_MODES>{ {
{ FilterMode::SHOW_ALL, "show-all" },
{ FilterMode::SHOW_ACTIVE, "show-active" },
{ FilterMode::SHOW_DOWNLOADING, "show-downloading" },
@ -167,7 +167,7 @@ auto const FilterModes = std::array<std::pair<int, std::string_view>, FilterMode
{ FilterMode::SHOW_ERROR, "show-error" },
} };
auto const SortModes = std::array<std::pair<int, std::string_view>, SortMode::NUM_MODES>{ {
auto constexpr SortModes = std::array<std::pair<int, std::string_view>, SortMode::NUM_MODES>{ {
{ SortMode::SORT_BY_NAME, "sort-by-name" },
{ SortMode::SORT_BY_ACTIVITY, "sort-by-activity" },
{ SortMode::SORT_BY_AGE, "sort-by-age" },

View File

@ -152,7 +152,7 @@ QString qtDayName(int day)
default:
assert(false && "Invalid day of week");
return QString();
return {};
}
}

View File

@ -31,8 +31,6 @@ namespace
char const constexpr* const RequestDataPropertyKey{ "requestData" };
char const constexpr* const RequestFutureinterfacePropertyKey{ "requestReplyFutureInterface" };
bool const Verbose = tr_env_key_exists("TR_RPC_VERBOSE");
void destroyVariant(tr_variant* json)
{
tr_variantFree(json);
@ -41,7 +39,7 @@ void destroyVariant(tr_variant* json)
TrVariantPtr createVariant()
{
return TrVariantPtr(tr_new0(tr_variant, 1), &destroyVariant);
return { tr_new0(tr_variant, 1), &destroyVariant };
}
} // namespace
@ -149,7 +147,7 @@ void RpcClient::sendNetworkRequest(TrVariantPtr json, QFutureInterface<RpcRespon
connect(reply, &QNetworkReply::downloadProgress, this, &RpcClient::dataReadProgress);
connect(reply, &QNetworkReply::uploadProgress, this, &RpcClient::dataSendProgress);
if (Verbose)
if (verbose_)
{
qInfo() << "sending"
<< "POST" << qPrintable(url_.path());
@ -228,7 +226,7 @@ void RpcClient::networkRequestFinished(QNetworkReply* reply)
auto promise = reply->property(RequestFutureinterfacePropertyKey).value<QFutureInterface<RpcResponse>>();
if (Verbose)
if (verbose_)
{
qInfo() << "http response header:";

View File

@ -19,11 +19,11 @@
#include <QUrl>
#include <libtransmission/transmission.h>
#include <libtransmission/quark.h>
#include <libtransmission/tr-macros.h>
#include <libtransmission/utils.h>
#include <libtransmission/variant.h>
class QByteArray;
class QNetworkAccessManager;
using TrVariantPtr = std::shared_ptr<tr_variant>;
@ -96,4 +96,5 @@ private:
QNetworkAccessManager* nam_ = {};
QHash<int64_t, QFutureInterface<RpcResponse>> local_requests_;
int64_t next_tag_ = {};
bool const verbose_ = tr_env_key_exists("TR_RPC_VERBOSE");
};

View File

@ -119,8 +119,7 @@ void Session::copyMagnetLinkToClipboard(int torrent_id)
q->add(
[](RpcResponse const& r)
{
tr_variant* torrents;
tr_variant* torrents = nullptr;
if (!tr_variantDictFindList(r.args.get(), TR_KEY_torrents, &torrents))
{
return;
@ -354,10 +353,8 @@ void Session::start()
rpc_.start(session_);
tr_ctor* ctor = tr_ctorNew(session_);
int torrent_count;
tr_torrent** torrents = tr_sessionLoadTorrents(session_, ctor, &torrent_count);
tr_free(torrents);
auto* const ctor = tr_ctorNew(session_);
tr_free(tr_sessionLoadTorrents(session_, ctor, nullptr));
tr_ctorFree(ctor);
}
@ -667,7 +664,7 @@ void Session::refreshTorrents(torrent_ids_t const& ids, TorrentProperties props)
q->add(
[this, all_torrents](RpcResponse const& r)
{
tr_variant* torrents;
tr_variant* torrents = nullptr;
if (tr_variantDictFindList(r.args.get(), TR_KEY_torrents, &torrents))
{
@ -846,18 +843,16 @@ void Session::updateStats(tr_variant* d, tr_session_stats* stats)
stats->ratio = static_cast<float>(tr_getRatio(stats->uploadedBytes, stats->downloadedBytes));
}
void Session::updateStats(tr_variant* d)
void Session::updateStats(tr_variant* dict)
{
tr_variant* c;
if (tr_variantDictFindDict(d, TR_KEY_current_stats, &c))
if (tr_variant* var = nullptr; tr_variantDictFindDict(dict, TR_KEY_current_stats, &var))
{
updateStats(c, &stats_);
updateStats(var, &stats_);
}
if (tr_variantDictFindDict(d, TR_KEY_cumulative_stats, &c))
if (tr_variant* var = nullptr; tr_variantDictFindDict(dict, TR_KEY_cumulative_stats, &var))
{
updateStats(c, &cumulative_stats_);
updateStats(var, &cumulative_stats_);
}
emit statsUpdated();
@ -1042,10 +1037,9 @@ void Session::addTorrent(AddData const& add_me, tr_variant* args, bool trash_ori
q->add(
[this, add_me](RpcResponse const& r)
{
tr_variant* dup;
bool session_has_torrent = false;
if (tr_variantDictFindDict(r.args.get(), TR_KEY_torrent_added, &dup))
if (tr_variant* dup = nullptr; tr_variantDictFindDict(r.args.get(), TR_KEY_torrent_added, &dup))
{
session_has_torrent = true;
}

View File

@ -35,31 +35,21 @@ Torrent::Torrent(Prefs const& prefs, int id)
****
***/
bool Torrent::getSeedRatio(double& setmeRatio) const
std::optional<double> Torrent::getSeedRatioLimit() const
{
bool is_limited;
auto const mode = seedRatioMode();
switch (seedRatioMode())
if (mode == TR_RATIOLIMIT_SINGLE)
{
case TR_RATIOLIMIT_SINGLE:
is_limited = true;
setmeRatio = seedRatioLimit();
break;
case TR_RATIOLIMIT_GLOBAL:
if ((is_limited = prefs_.getBool(Prefs::RATIO_ENABLED)))
{
setmeRatio = prefs_.getDouble(Prefs::RATIO);
}
break;
default: // TR_RATIOLIMIT_UNLIMITED:
is_limited = false;
break;
return seedRatioLimit();
}
return is_limited;
if (mode == TR_RATIOLIMIT_GLOBAL && prefs_.getBool(Prefs::RATIO_ENABLED))
{
return prefs_.getDouble(Prefs::RATIO);
}
return {};
}
bool Torrent::includesTracker(FaviconCache::Key const& key) const
@ -69,27 +59,25 @@ bool Torrent::includesTracker(FaviconCache::Key const& key) const
int Torrent::compareSeedRatio(Torrent const& that) const
{
double a;
double b;
bool const has_a = getSeedRatio(a);
bool const has_b = that.getSeedRatio(b);
auto const a = getSeedRatioLimit();
auto const b = that.getSeedRatioLimit();
if (!has_a && !has_b)
if (!a && !b)
{
return 0;
}
if (!has_a || !has_b)
if (!a || !b)
{
return has_a ? -1 : 1;
return a ? -1 : 1;
}
if (a < b)
if (*a < *b)
{
return -1;
}
if (a > b)
if (*a > *b)
{
return 1;
}

View File

@ -7,6 +7,7 @@
#include <bitset>
#include <ctime> // time_t
#include <optional>
#include <vector>
#include <QIcon>
@ -219,7 +220,7 @@ public:
return is_private_;
}
bool getSeedRatio(double& setmeRatio) const;
std::optional<double> getSeedRatioLimit() const;
uint64_t haveVerified() const
{

View File

@ -152,7 +152,7 @@ QSize TorrentDelegate::margin(QStyle const& style) const
{
Q_UNUSED(style)
return QSize(4, 4);
return { 4, 4 };
}
QString TorrentDelegate::progressString(Torrent const& tor)
@ -162,8 +162,7 @@ QString TorrentDelegate::progressString(Torrent const& tor)
bool const is_seed(tor.isSeed());
uint64_t const have_total(tor.haveTotal());
QString str;
double seed_ratio;
bool const has_seed_ratio(tor.getSeedRatio(seed_ratio));
auto const seed_ratio_limit = tor.getSeedRatioLimit();
if (is_magnet) // magnet link with no metadata
{
@ -185,7 +184,7 @@ QString TorrentDelegate::progressString(Torrent const& tor)
}
else if (!is_seed) // partial seed
{
if (has_seed_ratio)
if (seed_ratio_limit)
{
//: First part of torrent progress string,
//: %1 is how much we've got,
@ -200,7 +199,7 @@ QString TorrentDelegate::progressString(Torrent const& tor)
.arg(Formatter::get().percentToString(tor.percentComplete() * 100.0))
.arg(Formatter::get().sizeToString(tor.uploadedEver()))
.arg(Formatter::get().ratioToString(tor.ratio()))
.arg(Formatter::get().ratioToString(seed_ratio));
.arg(Formatter::get().ratioToString(*seed_ratio_limit));
}
else
{
@ -220,7 +219,7 @@ QString TorrentDelegate::progressString(Torrent const& tor)
}
else // seeding
{
if (has_seed_ratio)
if (seed_ratio_limit)
{
//: First part of torrent progress string,
//: %1 is the torrent's total size,
@ -231,7 +230,7 @@ QString TorrentDelegate::progressString(Torrent const& tor)
.arg(Formatter::get().sizeToString(have_total))
.arg(Formatter::get().sizeToString(tor.uploadedEver()))
.arg(Formatter::get().ratioToString(tor.ratio()))
.arg(Formatter::get().ratioToString(seed_ratio));
.arg(Formatter::get().ratioToString(*seed_ratio_limit));
}
else // seeding w/o a ratio
{
@ -247,7 +246,7 @@ QString TorrentDelegate::progressString(Torrent const& tor)
}
// add time when downloading
if ((has_seed_ratio && tor.isSeeding()) || tor.isDownloading())
if ((seed_ratio_limit && tor.isSeeding()) || tor.isDownloading())
{
if (tor.hasETA())
{
@ -426,7 +425,7 @@ QSize TorrentDelegate::sizeHint(QStyleOptionViewItem const& option, QModelIndex
height_hint_ = sizeHint(option, *tor).height();
}
return QSize(option.rect.width(), *height_hint_);
return { option.rect.width(), *height_hint_ };
}
QIcon& TorrentDelegate::getWarningEmblem() const
@ -452,11 +451,11 @@ void TorrentDelegate::paint(QPainter* painter, QStyleOptionViewItem const& optio
void TorrentDelegate::setProgressBarPercentDone(QStyleOptionViewItem const& option, Torrent const& tor) const
{
double seed_ratio_limit;
auto const seed_ratio_limit = tor.getSeedRatioLimit();
if (tor.isSeeding() && tor.getSeedRatio(seed_ratio_limit))
if (tor.isSeeding() && seed_ratio_limit)
{
auto const seed_rate_ratio = tor.ratio() / seed_ratio_limit;
auto const seed_rate_ratio = tor.ratio() / *seed_ratio_limit;
auto const scaled_progress = static_cast<int>(
seed_rate_ratio * (progress_bar_style_.maximum - progress_bar_style_.minimum));
progress_bar_style_.progress = progress_bar_style_.minimum + scaled_progress;
@ -496,54 +495,36 @@ void TorrentDelegate::drawTorrent(QPainter* painter, QStyleOptionViewItem const&
painter->fillRect(option.rect, option.palette.brush(cg, QPalette::Highlight));
}
QIcon::Mode im;
auto icon_mode = QIcon::Mode{};
if (is_paused || !is_item_enabled)
{
im = QIcon::Disabled;
icon_mode = QIcon::Disabled;
}
else if (is_item_selected)
{
im = QIcon::Selected;
icon_mode = QIcon::Selected;
}
else
{
im = QIcon::Normal;
icon_mode = QIcon::Normal;
}
QIcon::State qs;
auto const icon_state = is_paused ? QIcon::Off : QIcon::On;
if (is_paused)
{
qs = QIcon::Off;
}
else
{
qs = QIcon::On;
}
QPalette::ColorGroup cg = QPalette::Normal;
auto color_group = QPalette::Normal;
if (is_paused || !is_item_enabled)
{
cg = QPalette::Disabled;
color_group = QPalette::Disabled;
}
if (cg == QPalette::Normal && !is_item_active)
if (color_group == QPalette::Normal && !is_item_active)
{
cg = QPalette::Inactive;
color_group = QPalette::Inactive;
}
QPalette::ColorRole cr;
if (is_item_selected)
{
cr = QPalette::HighlightedText;
}
else
{
cr = QPalette::Text;
}
auto const color_role = is_item_selected ? QPalette::HighlightedText : QPalette::Text;
QStyle::State progress_bar_state(option.state | QStyle::State_Horizontal);
@ -577,14 +558,14 @@ void TorrentDelegate::drawTorrent(QPainter* painter, QStyleOptionViewItem const&
}
else
{
painter->setPen(option.palette.color(cg, cr));
painter->setPen(option.palette.color(color_group, color_role));
}
tor.getMimeTypeIcon().paint(painter, layout.icon_rect, Qt::AlignCenter, im, qs);
tor.getMimeTypeIcon().paint(painter, layout.icon_rect, Qt::AlignCenter, icon_mode, icon_state);
if (!emblem_icon.isNull())
{
emblem_icon.paint(painter, layout.emblem_rect, Qt::AlignCenter, emblem_im, qs);
emblem_icon.paint(painter, layout.emblem_rect, Qt::AlignCenter, emblem_im, icon_state);
}
painter->setFont(layout.name_font);

View File

@ -174,64 +174,46 @@ void TorrentDelegateMin::drawTorrent(QPainter* painter, QStyleOptionViewItem con
if (is_item_selected)
{
QPalette::ColorGroup cg = is_item_enabled ? QPalette::Normal : QPalette::Disabled;
auto color_group = is_item_enabled ? QPalette::Normal : QPalette::Disabled;
if (cg == QPalette::Normal && !is_item_active)
if (color_group == QPalette::Normal && !is_item_active)
{
cg = QPalette::Inactive;
color_group = QPalette::Inactive;
}
painter->fillRect(option.rect, option.palette.brush(cg, QPalette::Highlight));
painter->fillRect(option.rect, option.palette.brush(color_group, QPalette::Highlight));
}
QIcon::Mode im;
auto icon_mode = QIcon::Mode{};
if (is_paused || !is_item_enabled)
{
im = QIcon::Disabled;
icon_mode = QIcon::Disabled;
}
else if (is_item_selected)
{
im = QIcon::Selected;
icon_mode = QIcon::Selected;
}
else
{
im = QIcon::Normal;
icon_mode = QIcon::Normal;
}
QIcon::State qs;
auto const icon_state = is_paused ? QIcon::Off : QIcon::On;
if (is_paused)
{
qs = QIcon::Off;
}
else
{
qs = QIcon::On;
}
QPalette::ColorGroup cg = QPalette::Normal;
QPalette::ColorGroup color_group = QPalette::Normal;
if (is_paused || !is_item_enabled)
{
cg = QPalette::Disabled;
color_group = QPalette::Disabled;
}
if (cg == QPalette::Normal && !is_item_active)
if (color_group == QPalette::Normal && !is_item_active)
{
cg = QPalette::Inactive;
color_group = QPalette::Inactive;
}
QPalette::ColorRole cr;
if (is_item_selected)
{
cr = QPalette::HighlightedText;
}
else
{
cr = QPalette::Text;
}
auto const color_role = is_item_selected ? QPalette::HighlightedText : QPalette::Text;
QStyle::State progress_bar_state(option.state | QStyle::State_Horizontal);
@ -264,14 +246,14 @@ void TorrentDelegateMin::drawTorrent(QPainter* painter, QStyleOptionViewItem con
}
else
{
painter->setPen(option.palette.color(cg, cr));
painter->setPen(option.palette.color(color_group, color_role));
}
tor.getMimeTypeIcon().paint(painter, layout.icon_rect, Qt::AlignCenter, im, qs);
tor.getMimeTypeIcon().paint(painter, layout.icon_rect, Qt::AlignCenter, icon_mode, icon_state);
if (!emblem_icon.isNull())
{
emblem_icon.paint(painter, layout.emblem_rect, Qt::AlignCenter, emblem_im, qs);
emblem_icon.paint(painter, layout.emblem_rect, Qt::AlignCenter, emblem_im, icon_state);
}
painter->setFont(layout.name_font);

View File

@ -126,14 +126,12 @@ void TorrentModel::removeTorrents(tr_variant* list)
torrents.reserve(tr_variantListSize(list));
int i = 0;
tr_variant* child;
tr_variant* child = nullptr;
while ((child = tr_variantListChild(list, i++)) != nullptr)
{
auto const id = getValue<int>(child);
if (id)
if (auto const id = getValue<int>(child); id)
{
auto* torrent = getTorrentFromId(*id);
if (torrent != nullptr)
if (auto* const torrent = getTorrentFromId(*id); torrent != nullptr)
{
torrents.push_back(torrent);
}
@ -185,8 +183,8 @@ void TorrentModel::updateTorrents(tr_variant* torrents, bool is_complete_list)
else if (first_child != nullptr)
{
// In 'object' format, every entry is an object with the same set of properties
tr_quark key;
tr_variant* value;
auto key = tr_quark{};
tr_variant* value = nullptr;
for (size_t i = 0; tr_variantDictChild(first_child, i, &key, &value); ++i)
{
keys.push_back(key);
@ -206,8 +204,8 @@ void TorrentModel::updateTorrents(tr_variant* torrents, bool is_complete_list)
std::vector<tr_variant*> values;
values.reserve(keys.size());
size_t tor_index = table ? 1 : 0;
tr_variant* v;
processed.reserve(tr_variantListSize(torrents));
tr_variant* v = nullptr;
while ((v = tr_variantListChild(torrents, tor_index++)))
{
// Build an array of values
@ -216,7 +214,7 @@ void TorrentModel::updateTorrents(tr_variant* torrents, bool is_complete_list)
{
// In table mode, v is already a list of values
size_t i = 0;
tr_variant* val;
tr_variant* val = nullptr;
while ((val = tr_variantListChild(v, i++)))
{
values.push_back(val);
@ -226,8 +224,8 @@ void TorrentModel::updateTorrents(tr_variant* torrents, bool is_complete_list)
{
// In object mode, v is an object of torrent property key/vals
size_t i = 0;
tr_quark key;
tr_variant* value;
auto key = tr_quark{};
tr_variant* value = nullptr;
while (tr_variantDictChild(v, i++, &key, &value))
{
values.push_back(value);

View File

@ -32,7 +32,7 @@ public:
QRect const label_rect = style()->subElementRect(QStyle::SE_HeaderLabel, &option, this);
return QSize(100, fontMetrics().height() + (option.rect.height() - label_rect.height()));
return { 100, fontMetrics().height() + (option.rect.height() - label_rect.height()) };
}
protected:
@ -53,7 +53,7 @@ protected:
void mouseDoubleClickEvent(QMouseEvent* /*event*/) override
{
emit static_cast<TorrentView*>(parent())->headerDoubleClicked();
emit dynamic_cast<TorrentView*>(parent())->headerDoubleClicked();
}
private:

View File

@ -52,10 +52,10 @@ QIcon Utils::getIconFromIndex(QModelIndex const& index)
return qvariant_cast<QIcon>(variant);
case QVariant::Pixmap:
return QIcon(qvariant_cast<QPixmap>(variant));
return qvariant_cast<QPixmap>(variant);
default:
return QIcon();
return {};
}
}

View File

@ -44,11 +44,11 @@ bool change(TorrentHash& setme, tr_variant const* value)
bool change(Peer& setme, tr_variant const* value)
{
bool changed = false;
auto changed = bool{ false };
size_t pos = 0;
tr_quark key;
tr_variant* child;
auto pos = size_t{ 0 };
auto key = tr_quark{};
tr_variant* child = nullptr;
while (tr_variantDictChild(const_cast<tr_variant*>(value), pos++, &key, &child))
{
switch (key)
@ -84,11 +84,11 @@ bool change(Peer& setme, tr_variant const* value)
bool change(TorrentFile& setme, tr_variant const* value)
{
bool changed = false;
auto changed = bool{ false };
size_t pos = 0;
tr_quark key;
tr_variant* child;
auto pos = size_t{ 0 };
auto key = tr_quark{};
tr_variant* child = nullptr;
while (tr_variantDictChild(const_cast<tr_variant*>(value), pos++, &key, &child))
{
switch (key)
@ -121,11 +121,11 @@ bool change(TorrentFile& setme, tr_variant const* value)
bool change(TrackerStat& setme, tr_variant const* value)
{
bool changed = false;
auto changed = bool{ false };
size_t pos = 0;
tr_quark key;
tr_variant* child;
auto pos = size_t{ 0 };
auto key = tr_quark{};
tr_variant* child = nullptr;
while (tr_variantDictChild(const_cast<tr_variant*>(value), pos++, &key, &child))
{
bool field_changed = false;