diff --git a/CMakeLists.txt b/CMakeLists.txt index 88a449169..5f190727e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -523,6 +523,17 @@ else() endif() endif() +if(NOT CMAKE_VERSION VERSION_LESS "3.7.2") + message(STATUS "Looking for clang-tidy") + find_program(CLANG_TIDY clang-tidy) + if (CLANG_TIDY STREQUAL "CLANG_TIDY-NOTFOUND") + message(STATUS "Looking for clang-tidy - not found") + else() + message(STATUS "Looking for clang-tidy - found") + set(CMAKE_CXX_CLANG_TIDY "${CLANG_TIDY}") + endif() +endif() + if(ENABLE_TESTS) enable_testing() endif() diff --git a/qt/.clang-tidy b/qt/.clang-tidy new file mode 100644 index 000000000..a36ed4845 --- /dev/null +++ b/qt/.clang-tidy @@ -0,0 +1,30 @@ +--- +Checks: "-*,\ + bugprone-*, + -bugprone-branch-clone, + -bugprone-narrowing-conversions, + cert-*, + -cert-err58-cpp, + clang-analyzer-optin*, + cppcoreguidelines-*, + hicpp-*, + misc-*, + -misc-non-private-member-variables-in-classes, + modernize-*, + -modernize-avoid-c-arrays, + -modernize-loop-convert, + -modernize-pass-by-value, + -modernize-raw-string-literal, + -modernize-use-nodiscard, + -modernize-use-trailing-return-type, + readability-*, + -readability-convert-member-functions-to-static, + -readability-implicit-bool-conversion, + -readability-inconsistent-declaration-parameter-name, + -readability-isolate-declaration, + -readability-magic-numbers, + -readability-redundant-access-specifiers, + -readability-static-accessed-through-instance, +WarningsAsErrors: "*" +... + diff --git a/qt/AboutDialog.cc b/qt/AboutDialog.cc index 8854114c2..b3ba569e0 100644 --- a/qt/AboutDialog.cc +++ b/qt/AboutDialog.cc @@ -19,8 +19,7 @@ #include "Utils.h" AboutDialog::AboutDialog(QWidget* parent) : - BaseDialog(parent), - myLicenseDialog() + BaseDialog(parent) { ui.setupUi(this); diff --git a/qt/Application.cc b/qt/Application.cc index 64969216e..b6dd12700 100644 --- a/qt/Application.cc +++ b/qt/Application.cc @@ -208,9 +208,6 @@ Application::Application(int& argc, char** argv) : break; case AddData::FILENAME: - metainfo = QString::fromLatin1(a.toBase64()); - break; - case AddData::METAINFO: metainfo = QString::fromLatin1(a.toBase64()); break; @@ -339,7 +336,7 @@ Application::Application(int& argc, char** argv) : if (!myPrefs->getBool(Prefs::USER_HAS_GIVEN_INFORMED_CONSENT)) { - QMessageBox* dialog = new QMessageBox(QMessageBox::Information, QString(), + auto* dialog = new QMessageBox(QMessageBox::Information, QString(), tr("Transmission is a file sharing program."), QMessageBox::Ok | QMessageBox::Cancel, myWindow); dialog->setInformativeText(tr("When you run a torrent, its data will be made available to others by means of upload. " "Any content you share is your sole responsibility.")); @@ -573,7 +570,7 @@ void Application::addTorrent(AddData const& addme) } else { - auto o = new OptionsDialog(*mySession, *myPrefs, addme, myWindow); + auto* o = new OptionsDialog(*mySession, *myPrefs, addme, myWindow); o->show(); } diff --git a/qt/ColumnResizer.cc b/qt/ColumnResizer.cc index b01fe9cfe..37c330e2c 100644 --- a/qt/ColumnResizer.cc +++ b/qt/ColumnResizer.cc @@ -36,8 +36,7 @@ int itemColumnSpan(QGridLayout* layout, QLayoutItem const* item) ColumnResizer::ColumnResizer(QObject* parent) : QObject(parent), - myTimer(new QTimer(this)), - myLayouts() + myTimer(new QTimer(this)) { myTimer->setSingleShot(true); connect(myTimer, SIGNAL(timeout()), SLOT(update())); diff --git a/qt/ComInteropHelper.cc b/qt/ComInteropHelper.cc index 36fb70944..089e2da3a 100644 --- a/qt/ComInteropHelper.cc +++ b/qt/ComInteropHelper.cc @@ -32,9 +32,7 @@ ComInteropHelper::ComInteropHelper() : { } -ComInteropHelper::~ComInteropHelper() -{ -} +ComInteropHelper::~ComInteropHelper() = default; bool ComInteropHelper::isConnected() const { diff --git a/qt/DetailsDialog.cc b/qt/DetailsDialog.cc index 5b7810879..2738366b8 100644 --- a/qt/DetailsDialog.cc +++ b/qt/DetailsDialog.cc @@ -99,11 +99,8 @@ public: { } - virtual ~PeerItem() - { - } + ~PeerItem() override = default; -public: void refresh(Peer const& p) { if (p.address != peer.address) @@ -119,9 +116,9 @@ public: status = s; } - virtual bool operator <(QTreeWidgetItem const& other) const + bool operator <(QTreeWidgetItem const& other) const override { - PeerItem const* i = dynamic_cast(&other); + auto const* i = dynamic_cast(&other); QTreeWidget* tw(treeWidget()); int const column = tw != nullptr ? tw->sortColumn() : 0; @@ -516,11 +513,7 @@ void DetailsDialog::refresh() ui.haveValueLabel->setText(string); // myAvailabilityLabel - if (torrents.empty()) - { - string = none; - } - else if (sizeWhenDone == 0) + if (torrents.empty() || sizeWhenDone == 0) { string = none; } @@ -1189,7 +1182,7 @@ void DetailsDialog::initInfoTab() int const h = QFontMetrics(ui.commentBrowser->font()).lineSpacing() * 4; ui.commentBrowser->setFixedHeight(h); - ColumnResizer* cr(new ColumnResizer(this)); + auto* cr = new ColumnResizer(this); cr->addLayout(ui.activitySectionLayout); cr->addLayout(ui.detailsSectionLayout); cr->update(); @@ -1225,7 +1218,7 @@ void DetailsDialog::onSpinBoxEditingFinished() { QObject const* spin = sender(); tr_quark const key = spin->property(PREF_KEY).toInt(); - QDoubleSpinBox const* d = qobject_cast(spin); + auto const* d = qobject_cast(spin); if (d != nullptr) { @@ -1332,7 +1325,7 @@ void DetailsDialog::onEditTrackerClicked() QModelIndexList selectedRows = selectionModel->selectedRows(); assert(selectedRows.size() == 1); QModelIndex i = selectionModel->currentIndex(); - TrackerInfo const trackerInfo = ui.trackersView->model()->data(i, TrackerModel::TrackerRole).value(); + auto const trackerInfo = ui.trackersView->model()->data(i, TrackerModel::TrackerRole).value(); bool ok = false; QString const newval = QInputDialog::getText(this, tr("Edit URL "), tr("Edit tracker announce URL:"), QLineEdit::Normal, @@ -1366,7 +1359,7 @@ void DetailsDialog::onRemoveTrackerClicked() for (QModelIndex const& i : selectedRows) { - TrackerInfo const inf = ui.trackersView->model()->data(i, TrackerModel::TrackerRole).value(); + auto const inf = ui.trackersView->model()->data(i, TrackerModel::TrackerRole).value(); torrentId_to_trackerIds.insertMulti(inf.torrentId, inf.st.id); } @@ -1406,7 +1399,7 @@ void DetailsDialog::initOptionsTab() ui.idleCombo->addItem(tr("Seed regardless of activity"), TR_IDLELIMIT_UNLIMITED); ui.idleCombo->addItem(tr("Stop seeding if idle for:"), TR_IDLELIMIT_SINGLE); - ColumnResizer* cr(new ColumnResizer(this)); + auto* cr = new ColumnResizer(this); cr->addLayout(ui.speedSectionLayout); cr->addLayout(ui.seedingLimitsSectionRatioLayout); cr->addLayout(ui.seedingLimitsSectionIdleLayout); @@ -1510,14 +1503,14 @@ void DetailsDialog::onFilePriorityChanged(QSet const& indices, int priority break; } - mySession.torrentSet(myIds, key, indices.toList()); + mySession.torrentSet(myIds, key, indices.values()); getNewData(); } void DetailsDialog::onFileWantedChanged(QSet const& indices, bool wanted) { tr_quark const key = wanted ? TR_KEY_files_wanted : TR_KEY_files_unwanted; - mySession.torrentSet(myIds, key, indices.toList()); + mySession.torrentSet(myIds, key, indices.values()); getNewData(); } diff --git a/qt/FileTreeModel.cc b/qt/FileTreeModel.cc index fb484e7ba..324e59f3c 100644 --- a/qt/FileTreeModel.cc +++ b/qt/FileTreeModel.cc @@ -6,6 +6,7 @@ * */ +#include #include #include // priorities @@ -27,7 +28,6 @@ protected: myToken.reserve(path.size() / 2); } -protected: QString const& myPath; int mySlashIndex; QString myToken; @@ -94,8 +94,7 @@ public: FileTreeModel::FileTreeModel(QObject* parent, bool isEditable) : QAbstractItemModel(parent), myIsEditable(isEditable), - myRootItem(new FileTreeItem), - myIndexCache() + myRootItem(new FileTreeItem) { } @@ -126,7 +125,7 @@ QModelIndexList FileTreeModel::getOrphanIndices(QModelIndexList const& indices) { QModelIndexList orphanIndices = indices; - qSort(orphanIndices); + std::sort(orphanIndices.begin(), orphanIndices.end()); for (QMutableListIterator it(orphanIndices); it.hasNext();) { @@ -141,7 +140,7 @@ QModelIndexList FileTreeModel::getOrphanIndices(QModelIndexList const& indices) break; } - if (qBinaryFind(orphanIndices, walk) != orphanIndices.end()) + if (std::binary_search(orphanIndices.begin(), orphanIndices.end(), walk)) { it.remove(); break; diff --git a/qt/FileTreeModel.h b/qt/FileTreeModel.h index fe966ca8f..ed8034499 100644 --- a/qt/FileTreeModel.h +++ b/qt/FileTreeModel.h @@ -17,7 +17,7 @@ class FileTreeItem; -class FileTreeModel : public QAbstractItemModel +class FileTreeModel final : public QAbstractItemModel { Q_OBJECT diff --git a/qt/FileTreeView.cc b/qt/FileTreeView.cc index 5182af7f3..bb4a76082 100644 --- a/qt/FileTreeView.cc +++ b/qt/FileTreeView.cc @@ -283,7 +283,7 @@ void FileTreeView::onlyCheckSelectedItems() QModelIndexList wantedIndices = selectedSourceRows(); myModel->setWanted(wantedIndices, true); - qSort(wantedIndices); + std::sort(wantedIndices.begin(), wantedIndices.end()); QSet wantedIndicesParents; @@ -303,7 +303,7 @@ void FileTreeView::onlyCheckSelectedItems() { QModelIndex const parentIndex = parentsQueue.dequeue(); - if (qBinaryFind(wantedIndices, parentIndex) != wantedIndices.end()) + if (std::binary_search(wantedIndices.begin(), wantedIndices.end(), parentIndex)) { continue; } @@ -313,7 +313,7 @@ void FileTreeView::onlyCheckSelectedItems() QModelIndex const childIndex = parentIndex.child(i, 0); int const childCheckState = childIndex.data(FileTreeModel::WantedRole).toInt(); - if (childCheckState == Qt::Unchecked || qBinaryFind(wantedIndices, childIndex) != wantedIndices.end()) + if (childCheckState == Qt::Unchecked || std::binary_search(wantedIndices.begin(), wantedIndices.end(), childIndex)) { continue; } @@ -341,7 +341,7 @@ void FileTreeView::onlyCheckSelectedItems() void FileTreeView::setSelectedItemsPriority() { - QAction* action = qobject_cast(sender()); + auto* action = qobject_cast(sender()); assert(action != nullptr); myModel->setPriority(selectedSourceRows(), action->property(PRIORITY_KEY).toInt()); } diff --git a/qt/FilterBar.cc b/qt/FilterBar.cc index d84258642..3969a8746 100644 --- a/qt/FilterBar.cc +++ b/qt/FilterBar.cc @@ -38,13 +38,13 @@ enum FilterBarComboBox* FilterBar::createActivityCombo() { - FilterBarComboBox* c = new FilterBarComboBox(this); - FilterBarComboBoxDelegate* delegate = new FilterBarComboBoxDelegate(this, c); + auto* c = new FilterBarComboBox(this); + auto* delegate = new FilterBarComboBoxDelegate(this, c); c->setItemDelegate(delegate); - QStandardItemModel* model = new QStandardItemModel(this); + auto* model = new QStandardItemModel(this); - QStandardItem* row = new QStandardItem(tr("All")); + auto* row = new QStandardItem(tr("All")); row->setData(FilterMode::SHOW_ALL, ActivityRole); model->appendRow(row); @@ -115,7 +115,7 @@ void FilterBar::refreshTrackers() // update the "All" row auto const num_trackers = torrentsPerHost.size(); - auto item = myTrackerModel->item(ROW_TOTALS); + auto* item = myTrackerModel->item(ROW_TOTALS); item->setData(int(num_trackers), FilterBarComboBox::CountRole); item->setData(getCountString(num_trackers), FilterBarComboBox::CountStringRole); @@ -173,11 +173,11 @@ void FilterBar::refreshTrackers() FilterBarComboBox* FilterBar::createTrackerCombo(QStandardItemModel* model) { - FilterBarComboBox* c = new FilterBarComboBox(this); - FilterBarComboBoxDelegate* delegate = new FilterBarComboBoxDelegate(this, c); + auto* c = new FilterBarComboBox(this); + auto* delegate = new FilterBarComboBoxDelegate(this, c); c->setItemDelegate(delegate); - QStandardItem* row = new QStandardItem(tr("All")); + auto* row = new QStandardItem(tr("All")); row->setData(QString(), TrackerRole); int const count = myTorrents.rowCount(); row->setData(count, FilterBarComboBox::CountRole); @@ -203,7 +203,7 @@ FilterBar::FilterBar(Prefs& prefs, TorrentModel const& torrents, TorrentFilter c myRecountTimer(new QTimer(this)), myIsBootstrapping(true) { - QHBoxLayout* h = new QHBoxLayout(this); + auto* h = new QHBoxLayout(this); h->setContentsMargins(3, 3, 3, 3); myCountLabel = new QLabel(tr("Show:"), this); @@ -272,7 +272,7 @@ void FilterBar::refreshPref(int key) { case Prefs::FILTER_MODE: { - FilterMode const m = myPrefs.get(key); + auto const m = myPrefs.get(key); QAbstractItemModel* model = myActivityCombo->model(); QModelIndexList indices = model->match(model->index(0, 0), ActivityRole, m.mode()); myActivityCombo->setCurrentIndex(indices.isEmpty() ? 0 : indices.first().row()); diff --git a/qt/FilterBarComboBox.cc b/qt/FilterBarComboBox.cc index 81a7a1473..262437885 100644 --- a/qt/FilterBarComboBox.cc +++ b/qt/FilterBarComboBox.cc @@ -114,7 +114,7 @@ void FilterBarComboBox::paintEvent(QPaintEvent* e) QPen const pen = painter.pen(); painter.setPen(Utils::getFadedColor(pen.color())); QRect const textRect = QStyle::alignedRect(opt.direction, Qt::AlignRight | Qt::AlignVCenter, - QSize(opt.fontMetrics.width(text), rect.height()), rect); + QSize(opt.fontMetrics.boundingRect(text).width(), rect.height()), rect); painter.drawText(textRect, Qt::AlignRight | Qt::AlignVCenter, text); Utils::narrowRect(rect, 0, textRect.width() + hmargin, opt.direction); painter.setPen(pen); diff --git a/qt/FilterBarComboBoxDelegate.cc b/qt/FilterBarComboBoxDelegate.cc index fabd11144..06f56376a 100644 --- a/qt/FilterBarComboBoxDelegate.cc +++ b/qt/FilterBarComboBoxDelegate.cc @@ -41,7 +41,7 @@ void FilterBarComboBoxDelegate::setSeparator(QAbstractItemModel* model, QModelIn { model->setData(index, QString::fromLatin1("separator"), Qt::AccessibleDescriptionRole); - if (QStandardItemModel* m = qobject_cast(model)) + if (auto* m = qobject_cast(model)) { if (QStandardItem* item = m->itemFromIndex(index)) { @@ -56,7 +56,7 @@ void FilterBarComboBoxDelegate::paint(QPainter* painter, QStyleOptionViewItem co { QRect rect = option.rect; - if (QAbstractItemView const* view = qobject_cast(option.widget)) + if (auto const* view = qobject_cast(option.widget)) { rect.setWidth(view->viewport()->width()); } @@ -106,16 +106,14 @@ QSize FilterBarComboBoxDelegate::sizeHint(QStyleOptionViewItem const& option, QM int const pm = myCombo->style()->pixelMetric(QStyle::PM_DefaultFrameWidth, nullptr, myCombo); return QSize(pm, pm + 10); } - else - { - QStyle* s = myCombo->style(); - int const hmargin = getHSpacing(myCombo); - QSize size = QItemDelegate::sizeHint(option, index); - size.setHeight(qMax(size.height(), myCombo->iconSize().height() + 6)); - size.rwidth() += s->pixelMetric(QStyle::PM_FocusFrameHMargin, nullptr, myCombo); - size.rwidth() += rect(option, index, FilterBarComboBox::CountStringRole).width(); - size.rwidth() += hmargin * 4; - return size; - } + QStyle* s = myCombo->style(); + int const hmargin = getHSpacing(myCombo); + + QSize size = QItemDelegate::sizeHint(option, index); + size.setHeight(qMax(size.height(), myCombo->iconSize().height() + 6)); + size.rwidth() += s->pixelMetric(QStyle::PM_FocusFrameHMargin, nullptr, myCombo); + size.rwidth() += rect(option, index, FilterBarComboBox::CountStringRole).width(); + size.rwidth() += hmargin * 4; + return size; } diff --git a/qt/FreeSpaceLabel.cc b/qt/FreeSpaceLabel.cc index 630c1448d..ab04d3576 100644 --- a/qt/FreeSpaceLabel.cc +++ b/qt/FreeSpaceLabel.cc @@ -19,7 +19,7 @@ namespace { -static int const INTERVAL_MSEC = 15000; +int const INTERVAL_MSEC = 15000; } // namespace @@ -68,7 +68,7 @@ void FreeSpaceLabel::onTimer() tr_variantInitDict(&args, 1); tr_variantDictAddStr(&args, TR_KEY_path, myPath.toUtf8().constData()); - RpcQueue* q = new RpcQueue(); + auto* q = new RpcQueue(); q->add([this, &args]() { diff --git a/qt/MainWindow.cc b/qt/MainWindow.cc index bc01ba2c2..af17ba3fd 100644 --- a/qt/MainWindow.cc +++ b/qt/MainWindow.cc @@ -66,7 +66,7 @@ class ListViewProxyStyle : public QProxyStyle { public: int styleHint(StyleHint hint, QStyleOption const* option = nullptr, QWidget const* widget = nullptr, - QStyleHintReturn* returnData = nullptr) const + QStyleHintReturn* returnData = nullptr) const override { if (hint == QStyle::SH_ItemView_ActivateItemOnSingleClick) { @@ -83,7 +83,7 @@ QIcon MainWindow::getStockIcon(QString const& name, int fallback) if (icon.isNull() && fallback >= 0) { - icon = style()->standardIcon(QStyle::StandardPixmap(fallback), 0, this); + icon = style()->standardIcon(QStyle::StandardPixmap(fallback), nullptr, this); } return icon; @@ -140,11 +140,6 @@ MainWindow::MainWindow(Session& session, Prefs& prefs, TorrentModel& model, bool myPrefs(prefs), myModel(model), myLastFullUpdateTime(0), - mySessionDialog(), - myPrefsDialog(), - myAboutDialog(), - myStatsDialog(), - myDetailsDialog(), myFilterModel(prefs), myTorrentDelegate(new TorrentDelegate(this)), myTorrentDelegateMin(new TorrentDelegateMin(this)), @@ -156,7 +151,7 @@ MainWindow::MainWindow(Session& session, Prefs& prefs, TorrentModel& model, bool { setAcceptDrops(true); - QAction* sep = new QAction(this); + auto* sep = new QAction(this); sep->setSeparator(true); ui.setupUi(this); @@ -271,7 +266,7 @@ MainWindow::MainWindow(Session& session, Prefs& prefs, TorrentModel& model, bool qMakePair(ui.action_SortByState, static_cast(SortMode::SORT_BY_STATE)) }; - QActionGroup* actionGroup = new QActionGroup(this); + auto* actionGroup = new QActionGroup(this); for (auto const& mode : sortModes) { @@ -286,7 +281,7 @@ MainWindow::MainWindow(Session& session, Prefs& prefs, TorrentModel& model, bool myAltSpeedAction->setCheckable(true); connect(myAltSpeedAction, SIGNAL(triggered()), this, SLOT(toggleSpeedMode())); - QMenu* menu = new QMenu(this); + auto* menu = new QMenu(this); menu->addAction(ui.action_OpenFile); menu->addAction(ui.action_AddURL); menu->addSeparator(); @@ -354,9 +349,7 @@ MainWindow::MainWindow(Session& session, Prefs& prefs, TorrentModel& model, bool refreshSoon(); } -MainWindow::~MainWindow() -{ -} +MainWindow::~MainWindow() = default; void MainWindow::onSessionSourceChanged() { @@ -390,8 +383,8 @@ void MainWindow::initStatusBar() { ui.optionsButton->setMenu(createOptionsMenu()); - int const minimumSpeedWidth = ui.downloadSpeedLabel->fontMetrics().width(Formatter::uploadSpeedToString(Speed::fromKBps( - 999.99))); + int const minimumSpeedWidth = + ui.downloadSpeedLabel->fontMetrics().boundingRect(Formatter::uploadSpeedToString(Speed::fromKBps(999.99))).width(); ui.downloadSpeedLabel->setMinimumWidth(minimumSpeedWidth); ui.uploadSpeedLabel->setMinimumWidth(minimumSpeedWidth); @@ -407,7 +400,7 @@ QMenu* MainWindow::createOptionsMenu() int const stockSpeeds[] = { 5, 10, 20, 30, 40, 50, 75, 100, 150, 200, 250, 500, 750 }; int const currentValue = myPrefs.get(pref); - QActionGroup* actionGroup = new QActionGroup(this); + auto* actionGroup = new QActionGroup(this); offAction = menu->addAction(tr("Unlimited")); offAction->setCheckable(true); @@ -434,9 +427,9 @@ QMenu* MainWindow::createOptionsMenu() auto const initSeedRatioSubMenu = [this](QMenu* menu, QAction*& offAction, QAction*& onAction, int pref, int enabledPref) { double const stockRatios[] = { 0.25, 0.50, 0.75, 1, 1.5, 2, 3 }; - double const currentValue = myPrefs.get(pref); + auto const currentValue = myPrefs.get(pref); - QActionGroup* actionGroup = new QActionGroup(this); + auto* actionGroup = new QActionGroup(this); offAction = menu->addAction(tr("Seed Forever")); offAction->setCheckable(true); @@ -460,7 +453,7 @@ QMenu* MainWindow::createOptionsMenu() } }; - QMenu* menu = new QMenu(this); + auto* menu = new QMenu(this); initSpeedSubMenu(menu->addMenu(tr("Limit Download Speed")), myDlimitOffAction, myDlimitOnAction, Prefs::DSPEED, Prefs::DSPEED_ENABLED); @@ -485,8 +478,8 @@ QMenu* MainWindow::createStatsModeMenu() qMakePair(ui.action_SessionTransfer, SessionTransferStatsModeName) }; - QActionGroup* actionGroup = new QActionGroup(this); - QMenu* menu = new QMenu(this); + auto* actionGroup = new QActionGroup(this); + auto* menu = new QMenu(this); for (auto const& mode : statsModes) { @@ -561,7 +554,7 @@ void MainWindow::openProperties() void MainWindow::setLocation() { - RelocateDialog* d = new RelocateDialog(mySession, myModel, getSelectedTorrents(), this); + auto* d = new RelocateDialog(mySession, myModel, getSelectedTorrents(), this); d->setAttribute(Qt::WA_DeleteOnClose, true); d->show(); } @@ -947,7 +940,7 @@ torrent_ids_t MainWindow::getSelectedTorrents(bool withMetadataOnly) const for (QModelIndex const& index : ui.listView->selectionModel()->selectedRows()) { - Torrent const* tor(index.data(TorrentModel::TorrentRole).value()); + auto const* tor(index.data(TorrentModel::TorrentRole).value()); if (tor != nullptr && (!withMetadataOnly || tor->hasMetadata())) { @@ -1261,7 +1254,7 @@ QLatin1String const SHOW_OPTIONS_CHECKBOX_NAME("show-options-checkbox"); void MainWindow::newTorrent() { - MakeDialog* dialog = new MakeDialog(mySession, this); + auto* dialog = new MakeDialog(mySession, this); dialog->setAttribute(Qt::WA_DeleteOnClose); dialog->show(); } @@ -1274,11 +1267,11 @@ void MainWindow::openTorrent() d->setFileMode(QFileDialog::ExistingFiles); d->setAttribute(Qt::WA_DeleteOnClose); - auto const l = qobject_cast(d->layout()); + auto* const l = qobject_cast(d->layout()); if (l != nullptr) { - QCheckBox* b = new QCheckBox(tr("Show &options dialog")); + auto* b = new QCheckBox(tr("Show &options dialog")); b->setChecked(myPrefs.getBool(Prefs::OPTIONS_PROMPT)); b->setObjectName(SHOW_OPTIONS_CHECKBOX_NAME); l->addWidget(b, l->rowCount(), 0, 1, -1, Qt::AlignLeft); @@ -1310,11 +1303,11 @@ void MainWindow::addTorrents(QStringList const& filenames) { bool showOptions = myPrefs.getBool(Prefs::OPTIONS_PROMPT); - QFileDialog const* const fileDialog = qobject_cast(sender()); + auto const* const fileDialog = qobject_cast(sender()); if (fileDialog != nullptr) { - QCheckBox const* const b = fileDialog->findChild(SHOW_OPTIONS_CHECKBOX_NAME); + auto const* const b = fileDialog->findChild(SHOW_OPTIONS_CHECKBOX_NAME); if (b != nullptr) { @@ -1332,7 +1325,7 @@ void MainWindow::addTorrent(AddData const& addMe, bool showOptions) { if (showOptions) { - OptionsDialog* o = new OptionsDialog(mySession, myPrefs, addMe, this); + auto* o = new OptionsDialog(mySession, myPrefs, addMe, this); o->show(); qApp->alert(o); } @@ -1355,7 +1348,7 @@ void MainWindow::removeTorrents(bool const deleteFiles) for (QModelIndex const& index : ui.listView->selectionModel()->selectedRows()) { - Torrent const* tor(index.data(TorrentModel::TorrentRole).value()); + auto const* tor(index.data(TorrentModel::TorrentRole).value()); ids.insert(tor->id()); if (tor->connectedPeers()) @@ -1429,7 +1422,7 @@ void MainWindow::removeTorrents(bool const deleteFiles) msgBox.setDefaultButton(QMessageBox::Cancel); msgBox.setIcon(QMessageBox::Question); // hack needed to keep the dialog from being too narrow - auto layout = qobject_cast(msgBox.layout()); + auto* layout = qobject_cast(msgBox.layout()); if (layout == nullptr) { @@ -1437,7 +1430,7 @@ void MainWindow::removeTorrents(bool const deleteFiles) msgBox.setLayout(layout); } - QSpacerItem* spacer = new QSpacerItem(450, 0, QSizePolicy::Minimum, QSizePolicy::Expanding); + auto* spacer = new QSpacerItem(450, 0, QSizePolicy::Minimum, QSizePolicy::Expanding); layout->addItem(spacer, layout->rowCount(), 0, 1, layout->columnCount()); if (msgBox.exec() == QMessageBox::Ok) diff --git a/qt/MakeDialog.cc b/qt/MakeDialog.cc index 8c7cf6504..2cbece07e 100644 --- a/qt/MakeDialog.cc +++ b/qt/MakeDialog.cc @@ -35,7 +35,7 @@ public: MakeProgressDialog(Session& session, tr_metainfo_builder& builder, QWidget* parent = nullptr); private slots: - void onButtonBoxClicked(QAbstractButton*); + void onButtonBoxClicked(QAbstractButton* button); void onProgress(); private: @@ -181,7 +181,7 @@ void MakeDialog::makeTorrent() trackers.size(), comment.isEmpty() ? nullptr : comment.toUtf8().constData(), ui.privateCheck->isChecked()); // pop up the dialog - MakeProgressDialog* dialog = new MakeProgressDialog(mySession, *myBuilder, this); + auto* dialog = new MakeProgressDialog(mySession, *myBuilder, this); dialog->setAttribute(Qt::WA_DeleteOnClose); dialog->open(); } @@ -240,7 +240,7 @@ MakeDialog::MakeDialog(Session& session, QWidget* parent) : ui.sourceFolderButton->setMode(PathButton::DirectoryMode); ui.sourceFileButton->setMode(PathButton::FileMode); - ColumnResizer* cr(new ColumnResizer(this)); + auto* cr = new ColumnResizer(this); cr->addLayout(ui.filesSectionLayout); cr->addLayout(ui.propertiesSectionLayout); cr->update(); @@ -258,9 +258,7 @@ MakeDialog::MakeDialog(Session& session, QWidget* parent) : onSourceChanged(); } -MakeDialog::~MakeDialog() -{ -} +MakeDialog::~MakeDialog() = default; /*** **** diff --git a/qt/OptionsDialog.cc b/qt/OptionsDialog.cc index aa5d66bf1..1a04905a1 100644 --- a/qt/OptionsDialog.cc +++ b/qt/OptionsDialog.cc @@ -90,7 +90,7 @@ OptionsDialog::OptionsDialog(Session& session, Prefs const& prefs, AddData const if (myIsLocal) { - myLocalDestination = downloadDir; + myLocalDestination.setPath(downloadDir); } connect(ui.destinationButton, SIGNAL(pathChanged(QString)), this, SLOT(onDestinationChanged())); @@ -281,7 +281,7 @@ void OptionsDialog::onAccepted() for (int i = 0, n = myWanted.size(); i < n; ++i) { - if (myWanted.at(i) == false) + if (!myWanted.at(i)) { tr_variantListAddInt(l, i); } @@ -343,7 +343,7 @@ void OptionsDialog::onDestinationChanged() { if (ui.destinationStack->currentWidget() == ui.destinationButton) { - myLocalDestination = ui.destinationButton->path(); + myLocalDestination.setPath(ui.destinationButton->path()); ui.freeSpaceLabel->setPath(myLocalDestination.absolutePath()); } else diff --git a/qt/OptionsDialog.h b/qt/OptionsDialog.h index e9f4e3246..22e96e777 100644 --- a/qt/OptionsDialog.h +++ b/qt/OptionsDialog.h @@ -39,7 +39,7 @@ public: virtual ~OptionsDialog(); private: - typedef QMap mybins_t; + using mybins_t = QMap; private: void reload(); diff --git a/qt/PathButton.cc b/qt/PathButton.cc index 7903bfa98..c42e738b0 100644 --- a/qt/PathButton.cc +++ b/qt/PathButton.cc @@ -106,7 +106,7 @@ void PathButton::paintEvent(QPaintEvent* /*event*/) void PathButton::onClicked() { - QFileDialog* dialog = new QFileDialog(window(), effectiveTitle()); + auto* dialog = new QFileDialog(window(), effectiveTitle()); dialog->setFileMode(isDirMode() ? QFileDialog::Directory : QFileDialog::ExistingFile); if (isDirMode()) diff --git a/qt/Prefs.cc b/qt/Prefs.cc index 273e42aca..0e983ce99 100644 --- a/qt/Prefs.cc +++ b/qt/Prefs.cc @@ -341,7 +341,7 @@ void Prefs::initDefaults(tr_variant* d) tr_variantDictAddInt(d, TR_KEY_main_window_width, 300); tr_variantDictAddInt(d, TR_KEY_main_window_x, 50); tr_variantDictAddInt(d, TR_KEY_main_window_y, 50); - tr_variantDictAddInt(d, TR_KEY_remote_session_port, atoi(TR_DEFAULT_RPC_PORT_STR)); + tr_variantDictAddInt(d, TR_KEY_remote_session_port, strtol(TR_DEFAULT_RPC_PORT_STR, nullptr, 0)); tr_variantDictAddStr(d, TR_KEY_download_dir, tr_getDefaultDownloadDir()); tr_variantDictAddStr(d, TR_KEY_filter_mode, "all"); tr_variantDictAddStr(d, TR_KEY_main_window_layout_order, "menu,toolbar,filter,list,statusbar"); diff --git a/qt/PrefsDialog.cc b/qt/PrefsDialog.cc index 4094965dd..8648e865a 100644 --- a/qt/PrefsDialog.cc +++ b/qt/PrefsDialog.cc @@ -271,7 +271,7 @@ void PrefsDialog::lineEditingFinished() if (prefWidget.is()) { - QLineEdit const* const lineEdit = prefWidget.as(); + auto const* const lineEdit = prefWidget.as(); if (lineEdit->isModified()) { @@ -363,7 +363,7 @@ void PrefsDialog::initSpeedTab() mySchedWidgets << ui.altSpeedLimitStartTimeEdit << ui.altSpeedLimitToLabel << ui.altSpeedLimitEndTimeEdit << ui.altSpeedLimitDaysLabel << ui.altSpeedLimitDaysCombo; - ColumnResizer* cr(new ColumnResizer(this)); + auto* cr = new ColumnResizer(this); cr->addLayout(ui.speedLimitsSectionLayout); cr->addLayout(ui.altSpeedLimitsSectionLayout); cr->update(); @@ -418,7 +418,7 @@ void PrefsDialog::initNetworkTab() linkWidgetToPref(ui.enableDhtCheck, Prefs::DHT_ENABLED); linkWidgetToPref(ui.enableLpdCheck, Prefs::LPD_ENABLED); - ColumnResizer* cr(new ColumnResizer(this)); + auto* cr = new ColumnResizer(this); cr->addLayout(ui.incomingPeersSectionLayout); cr->addLayout(ui.peerLimitsSectionLayout); cr->update(); @@ -479,7 +479,7 @@ void PrefsDialog::initPrivacyTab() myBlockWidgets << ui.blocklistEdit << ui.blocklistStatusLabel << ui.updateBlocklistButton << ui.autoUpdateBlocklistCheck; - ColumnResizer* cr(new ColumnResizer(this)); + auto* cr = new ColumnResizer(this); cr->addLayout(ui.encryptionSectionLayout); cr->addLayout(ui.blocklistSectionLayout); cr->update(); @@ -564,7 +564,7 @@ void PrefsDialog::initDownloadingTab() linkWidgetToPref(ui.completionScriptButton, Prefs::SCRIPT_TORRENT_DONE_FILENAME); linkWidgetToPref(ui.completionScriptEdit, Prefs::SCRIPT_TORRENT_DONE_FILENAME); - ColumnResizer* cr(new ColumnResizer(this)); + auto* cr = new ColumnResizer(this); cr->addLayout(ui.addingSectionLayout); cr->addLayout(ui.downloadQueueSectionLayout); cr->addLayout(ui.incompleteSectionLayout); @@ -639,9 +639,7 @@ PrefsDialog::PrefsDialog(Session& session, Prefs& prefs, QWidget* parent) : adjustSize(); } -PrefsDialog::~PrefsDialog() -{ -} +PrefsDialog::~PrefsDialog() = default; void PrefsDialog::setPref(int key, QVariant const& v) { @@ -745,7 +743,7 @@ void PrefsDialog::refreshPref(int key) { if (key == Prefs::ENCRYPTION) { - QComboBox* comboBox(qobject_cast(w)); + auto* comboBox = qobject_cast(w); int const index = comboBox->findData(myPrefs.getInt(key)); comboBox->setCurrentIndex(index); } diff --git a/qt/PrefsDialog.h b/qt/PrefsDialog.h index 9d1095983..63529aa89 100644 --- a/qt/PrefsDialog.h +++ b/qt/PrefsDialog.h @@ -31,7 +31,7 @@ public: virtual ~PrefsDialog(); private: - typedef QMap key2widget_t; + using key2widget_t = QMap; private: bool updateWidgetValue(QWidget* widget, int prefKey); diff --git a/qt/RpcClient.cc b/qt/RpcClient.cc index 1d68a2d3e..0e7f1123c 100644 --- a/qt/RpcClient.cc +++ b/qt/RpcClient.cc @@ -15,8 +15,6 @@ #include #include -#include - #include #include #include // tr_free @@ -206,7 +204,7 @@ void RpcClient::localSessionCallback(tr_session* s, tr_variant* response, void* { Q_UNUSED(s) - RpcClient* self = static_cast(vself); + auto* self = static_cast(vself); TrVariantPtr json = createVariant(); *json = *response; @@ -221,7 +219,7 @@ void RpcClient::networkRequestFinished(QNetworkReply* reply) { reply->deleteLater(); - QFutureInterface promise = reply->property(REQUEST_FUTUREINTERFACE_PROPERTY_KEY). + auto promise = reply->property(REQUEST_FUTUREINTERFACE_PROPERTY_KEY). value>(); #ifdef DEBUG_HTTP diff --git a/qt/RpcClient.h b/qt/RpcClient.h index 7e22e7ff5..f9162b46a 100644 --- a/qt/RpcClient.h +++ b/qt/RpcClient.h @@ -25,7 +25,7 @@ class QByteArray; class QNetworkAccessManager; -typedef std::shared_ptr TrVariantPtr; +using TrVariantPtr = std::shared_ptr; Q_DECLARE_METATYPE(TrVariantPtr) extern "C" @@ -45,7 +45,7 @@ struct RpcResponse Q_DECLARE_METATYPE(QFutureInterface) // The response future -- the RPC engine returns one for each request made. -typedef QFuture RpcResponseFuture; +using RpcResponseFuture = QFuture; class RpcClient : public QObject { diff --git a/qt/RpcQueue.h b/qt/RpcQueue.h index 6976d0459..1df063aa3 100644 --- a/qt/RpcQueue.h +++ b/qt/RpcQueue.h @@ -50,10 +50,10 @@ public: private: // Internally queued function. Takes the last response future, makes a // request and returns a new response future. - typedef std::function QueuedFunction; + using QueuedFunction = std::function; // Internally stored error handler function. Takes the last response future and returns nothing. - typedef std::function ErrorHandlerFunction; + using ErrorHandlerFunction = std::function; private slots: void stepFinished(); @@ -65,7 +65,7 @@ private: // normal closure, takes response and returns new future template::type, RpcResponseFuture>::value + std::is_same_v, RpcResponseFuture> >::type* = nullptr> QueuedFunction normalizeFunc(Func const& func) { @@ -77,7 +77,7 @@ private: // closure without argument (first step), takes nothing and returns new future template::type, RpcResponseFuture>::value + std::is_same_v, RpcResponseFuture> >::type* = nullptr> QueuedFunction normalizeFunc(Func const& func) { @@ -89,7 +89,7 @@ private: // closure without return value ("auxiliary"), takes response and returns nothing -- internally we reuse the last future template::type, void>::value + std::is_same_v, void> >::type* = nullptr> QueuedFunction normalizeFunc(Func const& func) { @@ -102,7 +102,7 @@ private: // closure without argument and return value, takes nothing and returns nothing -- next function will also get nothing template::type, void>::value + std::is_same_v, void> >::type* = nullptr> QueuedFunction normalizeFunc(Func const& func) { @@ -115,7 +115,7 @@ private: // normal error handler, takes last response template::type, void>::value + std::is_same_v, void> >::type* = nullptr> ErrorHandlerFunction normalizeErrorHandler(Func const& func) { @@ -127,7 +127,7 @@ private: // error handler without an argument, takes nothing template::type, void>::value + std::is_same_v, void> >::type* = nullptr> ErrorHandlerFunction normalizeErrorHandler(Func const& func) { diff --git a/qt/Session.cc b/qt/Session.cc index 46f3bfbf5..4aaf041e3 100644 --- a/qt/Session.cc +++ b/qt/Session.cc @@ -42,7 +42,7 @@ namespace { -typedef Torrent::KeyList KeyList; +using KeyList = Torrent::KeyList; void addList(tr_variant* list, KeyList const& keys) { @@ -94,7 +94,7 @@ void Session::sessionSet(tr_quark const key, QVariant const& value) void Session::portTest() { - RpcQueue* q = new RpcQueue(); + auto* q = new RpcQueue(); q->add([this]() { @@ -123,7 +123,7 @@ void Session::copyMagnetLinkToClipboard(int torrentId) tr_variantListAddInt(tr_variantDictAddList(&args, TR_KEY_ids, 1), torrentId); tr_variantListAddStr(tr_variantDictAddList(&args, TR_KEY_fields, 1), "magnetLink"); - RpcQueue* q = new RpcQueue(); + auto* q = new RpcQueue(); q->add([this, &args]() { @@ -516,7 +516,7 @@ void Session::torrentRenamePath(torrent_ids_t const& ids, QString const& oldpath tr_variantDictAddStr(&args, TR_KEY_path, oldpath.toUtf8().constData()); tr_variantDictAddStr(&args, TR_KEY_name, newname.toUtf8().constData()); - RpcQueue* q = new RpcQueue(); + auto* q = new RpcQueue(); q->add([this, &args]() { @@ -529,7 +529,7 @@ void Session::torrentRenamePath(torrent_ids_t const& ids, QString const& oldpath tr_variantDictFindStr(r.args.get(), TR_KEY_path, &path, nullptr); tr_variantDictFindStr(r.args.get(), TR_KEY_name, &name, nullptr); - QMessageBox* d = new QMessageBox(QMessageBox::Information, tr("Error Renaming Path"), + auto* d = new QMessageBox(QMessageBox::Information, tr("Error Renaming Path"), tr("

Unable to rename \"%1\" as \"%2\": %3.

Please correct the errors and try again.

"). arg(QString::fromUtf8(path)).arg(QString::fromUtf8(name)).arg(r.result), QMessageBox::Close, qApp->activeWindow()); @@ -553,7 +553,7 @@ void Session::refreshTorrents(torrent_ids_t const& ids, KeyList const& keys) addList(tr_variantDictAddList(&args, TR_KEY_fields, 0), keys); addOptionalIds(&args, ids); - RpcQueue* q = new RpcQueue(); + auto* q = new RpcQueue(); q->add([this, &args]() { @@ -596,7 +596,7 @@ void Session::sendTorrentRequest(char const* request, torrent_ids_t const& ids) tr_variantInitDict(&args, 1); addOptionalIds(&args, ids); - RpcQueue* q = new RpcQueue(); + auto* q = new RpcQueue(); q->add([this, request, &args]() { @@ -663,7 +663,7 @@ void Session::initTorrents(torrent_ids_t const& ids) void Session::refreshSessionStats() { - RpcQueue* q = new RpcQueue(); + auto* q = new RpcQueue(); q->add([this]() { @@ -680,7 +680,7 @@ void Session::refreshSessionStats() void Session::refreshSessionInfo() { - RpcQueue* q = new RpcQueue(); + auto* q = new RpcQueue(); q->add([this]() { @@ -697,7 +697,7 @@ void Session::refreshSessionInfo() void Session::updateBlocklist() { - RpcQueue* q = new RpcQueue(); + auto* q = new RpcQueue(); q->add([this]() { @@ -972,7 +972,7 @@ void Session::addTorrent(AddData const& addMe, tr_variant* args, bool trashOrigi break; } - RpcQueue* q = new RpcQueue(); + auto* q = new RpcQueue(); q->add([this, args]() { @@ -980,7 +980,7 @@ void Session::addTorrent(AddData const& addMe, tr_variant* args, bool trashOrigi }, [addMe](RpcResponse const& r) { - QMessageBox* d = new QMessageBox(QMessageBox::Warning, tr("Error Adding Torrent"), + auto* d = new QMessageBox(QMessageBox::Warning, tr("Error Adding Torrent"), QString::fromLatin1("

%1

%2

").arg(r.result).arg(addMe.readableName()), QMessageBox::Close, qApp->activeWindow()); QObject::connect(d, &QMessageBox::rejected, d, &QMessageBox::deleteLater); @@ -1001,7 +1001,7 @@ void Session::addTorrent(AddData const& addMe, tr_variant* args, bool trashOrigi if (tr_variantDictFindStr(dup, TR_KEY_name, &str, nullptr)) { QString const name = QString::fromUtf8(str); - QMessageBox* d = new QMessageBox(QMessageBox::Warning, tr("Add Torrent"), + auto* d = new QMessageBox(QMessageBox::Warning, tr("Add Torrent"), tr("

Unable to add \"%1\".

It is a duplicate of \"%2\" which is already added.

"). arg(addMe.readableShortName()).arg(name), QMessageBox::Close, qApp->activeWindow()); QObject::connect(d, &QMessageBox::rejected, d, &QMessageBox::deleteLater); diff --git a/qt/StatsDialog.cc b/qt/StatsDialog.cc index afeb6d1a5..e8ec3b33f 100644 --- a/qt/StatsDialog.cc +++ b/qt/StatsDialog.cc @@ -25,7 +25,7 @@ StatsDialog::StatsDialog(Session& session, QWidget* parent) : { ui.setupUi(this); - ColumnResizer* cr(new ColumnResizer(this)); + auto* cr = new ColumnResizer(this); cr->addLayout(ui.currentSessionSectionLayout); cr->addLayout(ui.totalSectionLayout); cr->update(); @@ -38,9 +38,7 @@ StatsDialog::StatsDialog(Session& session, QWidget* parent) : mySession.refreshSessionStats(); } -StatsDialog::~StatsDialog() -{ -} +StatsDialog::~StatsDialog() = default; void StatsDialog::setVisible(bool visible) { diff --git a/qt/TorrentDelegate.cc b/qt/TorrentDelegate.cc index 548813cc7..4766a093d 100644 --- a/qt/TorrentDelegate.cc +++ b/qt/TorrentDelegate.cc @@ -57,7 +57,6 @@ public: QRect barRect; QRect progressRect; -public: ItemLayout(QString const& nameText, QString const& statusText, QString const& progressText, QIcon const& emblemIcon, QFont const& baseFont, Qt::LayoutDirection direction, QPoint const& topLeft, int width); @@ -439,7 +438,7 @@ QIcon& TorrentDelegate::getWarningEmblem() const void TorrentDelegate::paint(QPainter* painter, QStyleOptionViewItem const& option, QModelIndex const& index) const { - Torrent const* tor(index.data(TorrentModel::TorrentRole).value()); + auto const* tor(index.data(TorrentModel::TorrentRole).value()); painter->save(); painter->setClipRect(option.rect); drawTorrent(painter, option, *tor); diff --git a/qt/TorrentDelegateMin.cc b/qt/TorrentDelegateMin.cc index 2f9bdeffc..48d4c4c30 100644 --- a/qt/TorrentDelegateMin.cc +++ b/qt/TorrentDelegateMin.cc @@ -62,7 +62,6 @@ public: QRect statusRect; QRect barRect; -public: ItemLayout(QString const& nameText, QString const& statusText, QIcon const& emblemIcon, QFont const& baseFont, Qt::LayoutDirection direction, QPoint const& topLeft, int width); diff --git a/qt/TorrentFilter.cc b/qt/TorrentFilter.cc index acb54e3e3..343772bcb 100644 --- a/qt/TorrentFilter.cc +++ b/qt/TorrentFilter.cc @@ -27,9 +27,7 @@ TorrentFilter::TorrentFilter(Prefs const& prefs) : refilter(); } -TorrentFilter::~TorrentFilter() -{ -} +TorrentFilter::~TorrentFilter() = default; /*** **** @@ -101,8 +99,8 @@ int compare(T const a, T const b) bool TorrentFilter::lessThan(QModelIndex const& left, QModelIndex const& right) const { int val = 0; - Torrent const* a = sourceModel()->data(left, TorrentModel::TorrentRole).value(); - Torrent const* b = sourceModel()->data(right, TorrentModel::TorrentRole).value(); + auto const* a = sourceModel()->data(left, TorrentModel::TorrentRole).value(); + auto const* b = sourceModel()->data(right, TorrentModel::TorrentRole).value(); switch (myPrefs.get(Prefs::SORT_MODE).mode()) { @@ -285,12 +283,12 @@ bool TorrentFilter::activityFilterAcceptsTorrent(Torrent const* tor, FilterMode bool TorrentFilter::filterAcceptsRow(int sourceRow, QModelIndex const& sourceParent) const { QModelIndex childIndex = sourceModel()->index(sourceRow, 0, sourceParent); - Torrent const* tor = childIndex.model()->data(childIndex, TorrentModel::TorrentRole).value(); + auto const* tor = childIndex.model()->data(childIndex, TorrentModel::TorrentRole).value(); bool accepts = true; if (accepts) { - FilterMode const m = myPrefs.get(Prefs::FILTER_MODE); + auto const m = myPrefs.get(Prefs::FILTER_MODE); accepts = activityFilterAcceptsTorrent(tor, m); } diff --git a/qt/TorrentModel.cc b/qt/TorrentModel.cc index 6a3ae39f7..b7f0fc79d 100644 --- a/qt/TorrentModel.cc +++ b/qt/TorrentModel.cc @@ -106,7 +106,7 @@ QVariant TorrentModel::data(QModelIndex const& index, int role) const break; case TorrentRole: - var = qVariantFromValue(t); + var = QVariant::fromValue(t); break; default: @@ -443,7 +443,7 @@ void TorrentModel::rowsAdd(torrents_t const& torrents) { for (auto const& tor : torrents) { - auto const it = std::lower_bound(myTorrents.begin(), myTorrents.end(), tor, compare); + auto* const it = std::lower_bound(myTorrents.begin(), myTorrents.end(), tor, compare); auto const row = std::distance(myTorrents.begin(), it); beginInsertRows(QModelIndex(), row, row); diff --git a/qt/TorrentView.cc b/qt/TorrentView.cc index ebb58ae36..50185d4f3 100644 --- a/qt/TorrentView.cc +++ b/qt/TorrentView.cc @@ -29,7 +29,7 @@ public: } // QWidget - virtual QSize sizeHint() const + QSize sizeHint() const override { QStyleOptionHeader option; option.rect = QRect(0, 0, 100, 100); @@ -41,7 +41,7 @@ public: protected: // QWidget - virtual void paintEvent(QPaintEvent* /*event*/) + void paintEvent(QPaintEvent* /*event*/) override { QStyleOptionHeader option; option.initFrom(this); @@ -55,7 +55,7 @@ protected: painter.drawItemText(option.rect, Qt::AlignCenter, option.palette, true, myText, QPalette::ButtonText); } - virtual void mouseDoubleClickEvent(QMouseEvent* /*event*/) + void mouseDoubleClickEvent(QMouseEvent* /*event*/) override { emit static_cast(parent())->headerDoubleClicked(); } diff --git a/qt/TrackerDelegate.cc b/qt/TrackerDelegate.cc index b36d72dbc..0b8f606b5 100644 --- a/qt/TrackerDelegate.cc +++ b/qt/TrackerDelegate.cc @@ -41,7 +41,6 @@ public: QRect iconRect; QRect textRect; -public: ItemLayout(QString const& text, bool suppressColors, Qt::LayoutDirection direction, QPoint const& topLeft, int width); QSize size() const @@ -98,13 +97,13 @@ QSize TrackerDelegate::sizeHint(QStyleOptionViewItem const& option, TrackerInfo QSize TrackerDelegate::sizeHint(QStyleOptionViewItem const& option, QModelIndex const& index) const { - TrackerInfo const trackerInfo = index.data(TrackerModel::TrackerRole).value(); + auto const trackerInfo = index.data(TrackerModel::TrackerRole).value(); return sizeHint(option, trackerInfo); } void TrackerDelegate::paint(QPainter* painter, QStyleOptionViewItem const& option, QModelIndex const& index) const { - TrackerInfo const trackerInfo = index.data(TrackerModel::TrackerRole).value(); + auto const trackerInfo = index.data(TrackerModel::TrackerRole).value(); painter->save(); painter->setClipRect(option.rect); drawBackground(painter, option, index); diff --git a/qt/TrackerModel.cc b/qt/TrackerModel.cc index 94ff7bb3e..f6d3ab042 100644 --- a/qt/TrackerModel.cc +++ b/qt/TrackerModel.cc @@ -42,7 +42,7 @@ QVariant TrackerModel::data(QModelIndex const& index, int role) const break; case TrackerRole: - var = qVariantFromValue(trackerInfo); + var = QVariant::fromValue(trackerInfo); break; default: diff --git a/qt/TrackerModel.h b/qt/TrackerModel.h index 61b66d8dc..6b6b7bb9b 100644 --- a/qt/TrackerModel.h +++ b/qt/TrackerModel.h @@ -45,7 +45,7 @@ public: QVariant data(QModelIndex const& index, int role = Qt::DisplayRole) const override; private: - typedef QVector rows_t; + using rows_t = QVector; private: rows_t myRows; diff --git a/qt/TrackerModelFilter.cc b/qt/TrackerModelFilter.cc index e650dd858..dc71373ce 100644 --- a/qt/TrackerModelFilter.cc +++ b/qt/TrackerModelFilter.cc @@ -24,6 +24,6 @@ void TrackerModelFilter::setShowBackupTrackers(bool b) bool TrackerModelFilter::filterAcceptsRow(int sourceRow, QModelIndex const& sourceParent) const { QModelIndex index = sourceModel()->index(sourceRow, 0, sourceParent); - TrackerInfo const trackerInfo = index.data(TrackerModel::TrackerRole).value(); + auto const trackerInfo = index.data(TrackerModel::TrackerRole).value(); return myShowBackups || !trackerInfo.st.isBackup; } diff --git a/qt/Utils.cc b/qt/Utils.cc index ecd04b8a2..dd4bfeacc 100644 --- a/qt/Utils.cc +++ b/qt/Utils.cc @@ -112,7 +112,7 @@ QIcon fileIcon() std::unordered_map iconCache; -QIcon const getMimeIcon(QString const& filename) +QIcon getMimeIcon(QString const& filename) { // If the suffix doesn't match a mime type, treat it as a folder. // This heuristic is fast and yields good results for torrent names. @@ -183,10 +183,7 @@ QIcon Utils::guessMimeIcon(QString const& filename) addAssociatedFileIcon(fileInfo, SHGFI_LARGEICON, icon); } - if (!icon.isNull()) - { - return icon; - } + return icon; #else @@ -223,7 +220,7 @@ bool Utils::isValidUtf8(char const* s) n = 1; // ASCII } else if ((*c & 0xc0) == 0x80) - { + { // NOLINT(bugprone-branch-clone) return false; // not valid } else if ((*c & 0xe0) == 0xc0) diff --git a/qt/WatchDir.cc b/qt/WatchDir.cc index 673a7f88b..62418e1b7 100644 --- a/qt/WatchDir.cc +++ b/qt/WatchDir.cc @@ -67,7 +67,7 @@ int WatchDir::metainfoTest(QString const& filename) const void WatchDir::onTimeout() { - QTimer* t = qobject_cast(sender()); + auto* t = qobject_cast(sender()); QString const filename = t->objectName(); if (metainfoTest(filename) == OK) @@ -134,7 +134,7 @@ void WatchDir::watcherActivated(QString const& path) case ERROR: { // give the .torrent a few seconds to finish downloading - QTimer* t = new QTimer(this); + auto* t = new QTimer(this); t->setObjectName(dir.absoluteFilePath(name)); t->setSingleShot(true); connect(t, SIGNAL(timeout()), this, SLOT(onTimeout()));