From 2b2b3a4fe77f22829cb53aaa154682ed8e013c33 Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Wed, 8 Mar 2017 12:05:20 +0800 Subject: [PATCH 1/6] Fix downloaded/uploaded columns were not highlighted properly when selected. Refactor --- src/gui/properties/peerlistdelegate.h | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/gui/properties/peerlistdelegate.h b/src/gui/properties/peerlistdelegate.h index 82c2d70c3..fe2ec9b3b 100644 --- a/src/gui/properties/peerlistdelegate.h +++ b/src/gui/properties/peerlistdelegate.h @@ -67,14 +67,16 @@ public: ~PeerListDelegate() {} - void paint(QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index) const + void paint(QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index) const override { painter->save(); + const bool hideValues = Preferences::instance()->getHideZeroValues(); QStyleOptionViewItem opt = QItemDelegate::setOptions(index, option); + QItemDelegate::drawBackground(painter, opt, index); + switch(index.column()) { case PORT: { - QItemDelegate::drawBackground(painter, opt, index); opt.displayAlignment = Qt::AlignRight | Qt::AlignVCenter; QItemDelegate::drawDisplay(painter, opt, option.rect, index.data().toString()); } @@ -84,23 +86,21 @@ public: qlonglong size = index.data().toLongLong(); if (hideValues && (size <= 0)) break; - QItemDelegate::drawBackground(painter, opt, index); opt.displayAlignment = Qt::AlignRight | Qt::AlignVCenter; QItemDelegate::drawDisplay(painter, opt, option.rect, Utils::Misc::friendlyUnit(size)); } break; case DOWN_SPEED: case UP_SPEED:{ - QItemDelegate::drawBackground(painter, opt, index); qreal speed = index.data().toDouble(); + if (speed == 0.0) + break; opt.displayAlignment = Qt::AlignRight | Qt::AlignVCenter; - if (speed > 0.0) - QItemDelegate::drawDisplay(painter, opt, opt.rect, Utils::Misc::friendlyUnit(speed, true)); + QItemDelegate::drawDisplay(painter, opt, opt.rect, Utils::Misc::friendlyUnit(speed, true)); } break; case PROGRESS: case RELEVANCE: { - QItemDelegate::drawBackground(painter, opt, index); qreal progress = index.data().toDouble(); opt.displayAlignment = Qt::AlignRight | Qt::AlignVCenter; QItemDelegate::drawDisplay(painter, opt, opt.rect, Utils::String::fromDouble(progress*100.0, 1)+"%"); @@ -109,15 +109,15 @@ public: default: QItemDelegate::paint(painter, option, index); } + painter->restore(); } - QWidget* createEditor(QWidget*, const QStyleOptionViewItem &, const QModelIndex &) const + QWidget* createEditor(QWidget*, const QStyleOptionViewItem &, const QModelIndex &) const override { // No editor here - return 0; + return nullptr; } - }; #endif // PEERLISTDELEGATE_H From a16c557137cbf73a2053ef4b78577fd488846d45 Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Wed, 8 Mar 2017 13:10:45 +0800 Subject: [PATCH 2/6] Always draw background --- src/gui/properties/proplistdelegate.cpp | 8 +------- src/gui/search/searchlistdelegate.cpp | 8 ++------ 2 files changed, 3 insertions(+), 13 deletions(-) diff --git a/src/gui/properties/proplistdelegate.cpp b/src/gui/properties/proplistdelegate.cpp index 607e0f522..d8ab3aff8 100644 --- a/src/gui/properties/proplistdelegate.cpp +++ b/src/gui/properties/proplistdelegate.cpp @@ -72,14 +72,13 @@ void PropListDelegate::paint(QPainter *painter, const QStyleOptionViewItem &opti { painter->save(); QStyleOptionViewItem opt = QItemDelegate::setOptions(index, option); + QItemDelegate::drawBackground(painter, opt, index); switch(index.column()) { case PCSIZE: - QItemDelegate::drawBackground(painter, opt, index); QItemDelegate::drawDisplay(painter, opt, option.rect, Utils::Misc::friendlyUnit(index.data().toLongLong())); break; case REMAINING: - QItemDelegate::drawBackground(painter, opt, index); QItemDelegate::drawDisplay(painter, opt, option.rect, Utils::Misc::friendlyUnit(index.data().toLongLong())); break; case PROGRESS: @@ -106,13 +105,8 @@ void PropListDelegate::paint(QPainter *painter, const QStyleOptionViewItem &opti st.drawControl(QStyle::CE_ProgressBar, &newopt, painter, 0); #endif } - else { - // Do not display anything if the file is disabled (progress == 0) - QItemDelegate::drawBackground(painter, opt, index); - } break; case PRIORITY: { - QItemDelegate::drawBackground(painter, opt, index); QString text = ""; switch (index.data().toInt()) { case prio::MIXED: diff --git a/src/gui/search/searchlistdelegate.cpp b/src/gui/search/searchlistdelegate.cpp index dc286f5d9..233133c1f 100644 --- a/src/gui/search/searchlistdelegate.cpp +++ b/src/gui/search/searchlistdelegate.cpp @@ -47,19 +47,15 @@ void SearchListDelegate::paint(QPainter *painter, const QStyleOptionViewItem &op painter->save(); QStyleOptionViewItem opt = QItemDelegate::setOptions(index, option); + QItemDelegate::drawBackground(painter, opt, index); + switch(index.column()) { case SearchSortModel::SIZE: - QItemDelegate::drawBackground(painter, opt, index); opt.displayAlignment = Qt::AlignRight | Qt::AlignVCenter; QItemDelegate::drawDisplay(painter, opt, option.rect, Utils::Misc::friendlyUnit(index.data().toLongLong())); break; case SearchSortModel::SEEDS: - QItemDelegate::drawBackground(painter, opt, index); - opt.displayAlignment = Qt::AlignRight | Qt::AlignVCenter; - QItemDelegate::drawDisplay(painter, opt, option.rect, (index.data().toLongLong() >= 0) ? index.data().toString() : tr("Unknown")); - break; case SearchSortModel::LEECHES: - QItemDelegate::drawBackground(painter, opt, index); opt.displayAlignment = Qt::AlignRight | Qt::AlignVCenter; QItemDelegate::drawDisplay(painter, opt, option.rect, (index.data().toLongLong() >= 0) ? index.data().toString() : tr("Unknown")); break; From 86e82c71e5efa875777c6ed5a701c955d941f5f3 Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Wed, 8 Mar 2017 13:01:59 +0800 Subject: [PATCH 3/6] Setup parent pointer Rely on Qt to do the delete, since the parent ownership is setup correctly. --- src/gui/addnewtorrentdialog.cpp | 2 +- src/gui/properties/peerlistwidget.cpp | 8 ++------ src/gui/properties/proplistdelegate.cpp | 4 ++-- src/gui/properties/proplistdelegate.h | 2 +- src/gui/search/searchlistdelegate.h | 2 +- 5 files changed, 7 insertions(+), 11 deletions(-) diff --git a/src/gui/addnewtorrentdialog.cpp b/src/gui/addnewtorrentdialog.cpp index c773a9cbd..eee00034c 100644 --- a/src/gui/addnewtorrentdialog.cpp +++ b/src/gui/addnewtorrentdialog.cpp @@ -718,7 +718,7 @@ void AddNewTorrentDialog::setupTreeview() m_contentModel = new TorrentContentFilterModel(this); connect(m_contentModel->model(), SIGNAL(filteredFilesChanged()), SLOT(updateDiskSpaceLabel())); ui->contentTreeView->setModel(m_contentModel); - m_contentDelegate = new PropListDelegate(); + m_contentDelegate = new PropListDelegate(nullptr); ui->contentTreeView->setItemDelegate(m_contentDelegate); connect(ui->contentTreeView, SIGNAL(clicked(const QModelIndex &)), ui->contentTreeView, SLOT(edit(const QModelIndex &))); connect(ui->contentTreeView, SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(displayContentTreeMenu(const QPoint &))); diff --git a/src/gui/properties/peerlistwidget.cpp b/src/gui/properties/peerlistwidget.cpp index dadf2c0b2..da2f50951 100644 --- a/src/gui/properties/peerlistwidget.cpp +++ b/src/gui/properties/peerlistwidget.cpp @@ -67,7 +67,7 @@ PeerListWidget::PeerListWidget(PropertiesWidget *parent) setSelectionMode(QAbstractItemView::ExtendedSelection); header()->setStretchLastSection(false); // List Model - m_listModel = new QStandardItemModel(0, PeerListDelegate::COL_COUNT); + m_listModel = new QStandardItemModel(0, PeerListDelegate::COL_COUNT, this); m_listModel->setHeaderData(PeerListDelegate::COUNTRY, Qt::Horizontal, tr("Country")); // Country flag column m_listModel->setHeaderData(PeerListDelegate::IP, Qt::Horizontal, tr("IP")); m_listModel->setHeaderData(PeerListDelegate::PORT, Qt::Horizontal, tr("Port")); @@ -90,7 +90,7 @@ PeerListWidget::PeerListWidget(PropertiesWidget *parent) m_listModel->setHeaderData(PeerListDelegate::TOT_UP, Qt::Horizontal, QVariant(Qt::AlignRight | Qt::AlignVCenter), Qt::TextAlignmentRole); m_listModel->setHeaderData(PeerListDelegate::RELEVANCE, Qt::Horizontal, QVariant(Qt::AlignRight | Qt::AlignVCenter), Qt::TextAlignmentRole); // Proxy model to support sorting without actually altering the underlying model - m_proxyModel = new PeerListSortModel(); + m_proxyModel = new PeerListSortModel(this); m_proxyModel->setDynamicSortFilter(true); m_proxyModel->setSourceModel(m_listModel); m_proxyModel->setSortCaseSensitivity(Qt::CaseInsensitive); @@ -144,12 +144,8 @@ PeerListWidget::PeerListWidget(PropertiesWidget *parent) PeerListWidget::~PeerListWidget() { saveSettings(); - delete m_proxyModel; - delete m_listModel; - delete m_listDelegate; if (m_resolver) delete m_resolver; - delete m_copyHotkey; } void PeerListWidget::displayToggleColumnsMenu(const QPoint&) diff --git a/src/gui/properties/proplistdelegate.cpp b/src/gui/properties/proplistdelegate.cpp index d8ab3aff8..68bc859ca 100644 --- a/src/gui/properties/proplistdelegate.cpp +++ b/src/gui/properties/proplistdelegate.cpp @@ -62,8 +62,8 @@ namespace { } } -PropListDelegate::PropListDelegate(PropertiesWidget *properties, QObject *parent) - : QItemDelegate(parent) +PropListDelegate::PropListDelegate(PropertiesWidget *properties) + : QItemDelegate(properties) , m_properties(properties) { } diff --git a/src/gui/properties/proplistdelegate.h b/src/gui/properties/proplistdelegate.h index 7f1ecc251..5c70fd2d7 100644 --- a/src/gui/properties/proplistdelegate.h +++ b/src/gui/properties/proplistdelegate.h @@ -54,7 +54,7 @@ class PropListDelegate : public QItemDelegate Q_OBJECT public: - PropListDelegate(PropertiesWidget *properties = 0, QObject *parent = 0); + PropListDelegate(PropertiesWidget *properties); void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const; void setEditorData(QWidget *editor, const QModelIndex &index) const; diff --git a/src/gui/search/searchlistdelegate.h b/src/gui/search/searchlistdelegate.h index 27d813735..91e0e46a4 100644 --- a/src/gui/search/searchlistdelegate.h +++ b/src/gui/search/searchlistdelegate.h @@ -36,7 +36,7 @@ class SearchListDelegate: public QItemDelegate { public: - explicit SearchListDelegate(QObject *parent = 0); + explicit SearchListDelegate(QObject *parent); void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const; QWidget* createEditor(QWidget*, const QStyleOptionViewItem &, const QModelIndex &) const; From 59556dfc6a07a076d398bf48a092c02c18068fdc Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Wed, 8 Mar 2017 13:22:50 +0800 Subject: [PATCH 4/6] Cleanup & refactor --- src/gui/properties/proplistdelegate.cpp | 45 +++++++++++++------------ src/gui/properties/proplistdelegate.h | 10 +++--- src/gui/search/searchlistdelegate.cpp | 2 +- src/gui/search/searchlistdelegate.h | 4 +-- 4 files changed, 31 insertions(+), 30 deletions(-) diff --git a/src/gui/properties/proplistdelegate.cpp b/src/gui/properties/proplistdelegate.cpp index 68bc859ca..cb4e86ce9 100644 --- a/src/gui/properties/proplistdelegate.cpp +++ b/src/gui/properties/proplistdelegate.cpp @@ -76,33 +76,34 @@ void PropListDelegate::paint(QPainter *painter, const QStyleOptionViewItem &opti switch(index.column()) { case PCSIZE: - QItemDelegate::drawDisplay(painter, opt, option.rect, Utils::Misc::friendlyUnit(index.data().toLongLong())); - break; case REMAINING: QItemDelegate::drawDisplay(painter, opt, option.rect, Utils::Misc::friendlyUnit(index.data().toLongLong())); break; - case PROGRESS: - if (index.data().toDouble() >= 0) { - QStyleOptionProgressBar newopt; - qreal progress = index.data().toDouble() * 100.; - newopt.rect = opt.rect; - newopt.text = ((progress == 100.0) ? QString("100%") : Utils::String::fromDouble(progress, 1) + "%"); - newopt.progress = (int)progress; - newopt.maximum = 100; - newopt.minimum = 0; - newopt.textVisible = true; - if (index.sibling(index.row(), PRIORITY).data().toInt() == prio::IGNORED) { - newopt.state &= ~QStyle::State_Enabled; - newopt.palette = progressBarDisabledPalette(); - } - else - newopt.state |= QStyle::State_Enabled; + case PROGRESS: { + if (index.data().toDouble() < 0) + break; + + QStyleOptionProgressBar newopt; + qreal progress = index.data().toDouble() * 100.; + newopt.rect = opt.rect; + newopt.text = ((progress == 100.0) ? QString("100%") : Utils::String::fromDouble(progress, 1) + "%"); + newopt.progress = int(progress); + newopt.maximum = 100; + newopt.minimum = 0; + newopt.textVisible = true; + if (index.sibling(index.row(), PRIORITY).data().toInt() == prio::IGNORED) { + newopt.state &= ~QStyle::State_Enabled; + newopt.palette = progressBarDisabledPalette(); + } + else { + newopt.state |= QStyle::State_Enabled; + } + #ifndef Q_OS_WIN - QApplication::style()->drawControl(QStyle::CE_ProgressBar, &newopt, painter); + QApplication::style()->drawControl(QStyle::CE_ProgressBar, &newopt, painter); #else - // XXX: To avoid having the progress text on the right of the bar - QProxyStyle st("fusion"); - st.drawControl(QStyle::CE_ProgressBar, &newopt, painter, 0); + // XXX: To avoid having the progress text on the right of the bar + QProxyStyle("fusion").drawControl(QStyle::CE_ProgressBar, &newopt, painter, 0); #endif } break; diff --git a/src/gui/properties/proplistdelegate.h b/src/gui/properties/proplistdelegate.h index 5c70fd2d7..90b8babe9 100644 --- a/src/gui/properties/proplistdelegate.h +++ b/src/gui/properties/proplistdelegate.h @@ -56,13 +56,13 @@ class PropListDelegate : public QItemDelegate public: PropListDelegate(PropertiesWidget *properties); - void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const; - void setEditorData(QWidget *editor, const QModelIndex &index) const; - QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &/* option */, const QModelIndex &index) const; + void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override; + void setEditorData(QWidget *editor, const QModelIndex &index) const override; + QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &/* option */, const QModelIndex &index) const override; public slots: - void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const; - void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &/* index */) const; + void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const override; + void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &/* index */) const override; signals: void filteredFilesChanged() const; diff --git a/src/gui/search/searchlistdelegate.cpp b/src/gui/search/searchlistdelegate.cpp index 233133c1f..16c79afff 100644 --- a/src/gui/search/searchlistdelegate.cpp +++ b/src/gui/search/searchlistdelegate.cpp @@ -69,5 +69,5 @@ void SearchListDelegate::paint(QPainter *painter, const QStyleOptionViewItem &op QWidget *SearchListDelegate::createEditor(QWidget *, const QStyleOptionViewItem &, const QModelIndex &) const { // No editor here - return 0; + return nullptr; } diff --git a/src/gui/search/searchlistdelegate.h b/src/gui/search/searchlistdelegate.h index 91e0e46a4..2131d5bfa 100644 --- a/src/gui/search/searchlistdelegate.h +++ b/src/gui/search/searchlistdelegate.h @@ -38,8 +38,8 @@ class SearchListDelegate: public QItemDelegate public: explicit SearchListDelegate(QObject *parent); - void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const; - QWidget* createEditor(QWidget*, const QStyleOptionViewItem &, const QModelIndex &) const; + void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override; + QWidget* createEditor(QWidget*, const QStyleOptionViewItem &, const QModelIndex &) const override; }; #endif From a86f189f5336080c754a2b64a5340bc8cf36ed04 Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Wed, 5 Apr 2017 15:03:14 +0800 Subject: [PATCH 5/6] Relax comparsion for floating point --- src/gui/properties/peerlistdelegate.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gui/properties/peerlistdelegate.h b/src/gui/properties/peerlistdelegate.h index fe2ec9b3b..f883123d7 100644 --- a/src/gui/properties/peerlistdelegate.h +++ b/src/gui/properties/peerlistdelegate.h @@ -93,7 +93,7 @@ public: case DOWN_SPEED: case UP_SPEED:{ qreal speed = index.data().toDouble(); - if (speed == 0.0) + if (speed <= 0.0) break; opt.displayAlignment = Qt::AlignRight | Qt::AlignVCenter; QItemDelegate::drawDisplay(painter, opt, opt.rect, Utils::Misc::friendlyUnit(speed, true)); From 812bd4c83a7a8e9218f3eec29c013f8b03084cbf Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Wed, 5 Apr 2017 15:21:12 +0800 Subject: [PATCH 6/6] Uncrustify --- src/gui/addnewtorrentdialog.cpp | 38 ++++++------- src/gui/properties/peerlistdelegate.h | 13 ++--- src/gui/properties/peerlistwidget.cpp | 24 ++++----- src/gui/properties/peerlistwidget.h | 6 +-- src/gui/properties/proplistdelegate.cpp | 72 ++++++++++++------------- src/gui/properties/proplistdelegate.h | 6 +-- src/gui/search/searchlistdelegate.cpp | 2 +- src/gui/search/searchlistdelegate.h | 2 +- 8 files changed, 83 insertions(+), 80 deletions(-) diff --git a/src/gui/addnewtorrentdialog.cpp b/src/gui/addnewtorrentdialog.cpp index eee00034c..d12ff566c 100644 --- a/src/gui/addnewtorrentdialog.cpp +++ b/src/gui/addnewtorrentdialog.cpp @@ -68,8 +68,11 @@ const QString KEY_SAVEPATHHISTORY = SETTINGS_KEY("SavePathHistory"); namespace { - //just a shortcut - inline SettingsStorage *settings() { return SettingsStorage::instance(); } + // just a shortcut + inline SettingsStorage *settings() + { + return SettingsStorage::instance(); + } } AddNewTorrentDialog::AddNewTorrentDialog(QWidget *parent) @@ -88,7 +91,7 @@ AddNewTorrentDialog::AddNewTorrentDialog(QWidget *parent) auto session = BitTorrent::Session::instance(); ui->startTorrentCheckBox->setChecked(!session->isAddTorrentPaused()); - ui->comboTTM->blockSignals(true); //the TreeView size isn't correct if the slot does it job at this point + ui->comboTTM->blockSignals(true); // the TreeView size isn't correct if the slot does it job at this point ui->comboTTM->setCurrentIndex(!session->isAutoTMMDisabledByDefault()); ui->comboTTM->blockSignals(false); populateSavePathComboBox(); @@ -181,9 +184,9 @@ void AddNewTorrentDialog::show(QString source, QWidget *parent) if (Utils::Misc::isUrl(source)) { // Launch downloader Net::DownloadHandler *handler = Net::DownloadManager::instance()->downloadUrl(source, true, 10485760 /* 10MB */, true); - connect(handler, SIGNAL(downloadFinished(QString, QString)), dlg, SLOT(handleDownloadFinished(QString, QString))); - connect(handler, SIGNAL(downloadFailed(QString, QString)), dlg, SLOT(handleDownloadFailed(QString, QString))); - connect(handler, SIGNAL(redirectedToMagnet(QString, QString)), dlg, SLOT(handleRedirectedToMagnet(QString, QString))); + connect(handler, SIGNAL(downloadFinished(QString,QString)), dlg, SLOT(handleDownloadFinished(QString,QString))); + connect(handler, SIGNAL(downloadFailed(QString,QString)), dlg, SLOT(handleDownloadFailed(QString,QString))); + connect(handler, SIGNAL(redirectedToMagnet(QString,QString)), dlg, SLOT(handleRedirectedToMagnet(QString,QString))); } else { bool ok = false; @@ -309,7 +312,6 @@ void AddNewTorrentDialog::showEvent(QShowEvent *event) raise(); } - void AddNewTorrentDialog::showAdvancedSettings(bool show) { const int minimumW = minimumWidth(); @@ -319,7 +321,7 @@ void AddNewTorrentDialog::showAdvancedSettings(bool show) ui->settings_group->setVisible(true); ui->infoGroup->setVisible(true); ui->contentTreeView->setVisible(m_hasMetadata); - static_cast(layout())->insertWidget(layout()->indexOf(ui->never_show_cb) + 1, ui->adv_button); + static_cast(layout())->insertWidget(layout()->indexOf(ui->never_show_cb) + 1, ui->adv_button); } else { ui->adv_button->setText(QString::fromUtf8(C_DOWN)); @@ -337,7 +339,7 @@ void AddNewTorrentDialog::saveSavePathHistory() const // Get current history QStringList history = settings()->loadValue(KEY_SAVEPATHHISTORY).toStringList(); QList historyDirs; - foreach(const QString dir, history) + foreach (const QString dir, history) historyDirs << QDir(dir); if (!historyDirs.contains(selectedSavePath)) { // Add save path to history @@ -381,8 +383,8 @@ void AddNewTorrentDialog::updateDiskSpaceLabel() QString size_string = torrent_size ? Utils::Misc::friendlyUnit(torrent_size) : QString(tr("Not Available", "This size is unavailable.")); size_string += " ("; size_string += tr("Free space on disk: %1").arg(Utils::Misc::friendlyUnit(Utils::Fs::freeDiskSpaceOnPath( - ui->savePathComboBox->itemData( - ui->savePathComboBox->currentIndex()).toString()))); + ui->savePathComboBox->itemData( + ui->savePathComboBox->currentIndex()).toString()))); size_string += ")"; ui->size_lbl->setText(size_string); } @@ -392,8 +394,8 @@ void AddNewTorrentDialog::onSavePathChanged(int index) // Toggle default save path setting checkbox visibility ui->defaultSavePathCheckBox->setChecked(false); ui->defaultSavePathCheckBox->setVisible( - QDir(ui->savePathComboBox->itemData(ui->savePathComboBox->currentIndex()).toString()) - != QDir(BitTorrent::Session::instance()->defaultSavePath())); + QDir(ui->savePathComboBox->itemData(ui->savePathComboBox->currentIndex()).toString()) + != QDir(BitTorrent::Session::instance()->defaultSavePath())); // Remember index m_oldIndex = index; @@ -502,7 +504,7 @@ void AddNewTorrentDialog::renameSelectedFile() QStringList path_items; path_items << index.data().toString(); QModelIndex parent = m_contentModel->parent(index); - while(parent.isValid()) { + while (parent.isValid()) { path_items.prepend(parent.data().toString()); parent = m_contentModel->parent(parent); } @@ -577,7 +579,7 @@ void AddNewTorrentDialog::populateSavePathComboBox() ui->savePathComboBox->addItem(Utils::Fs::toNativePath(savePath), savePath); } -void AddNewTorrentDialog::displayContentTreeMenu(const QPoint&) +void AddNewTorrentDialog::displayContentTreeMenu(const QPoint &) { QMenu myFilesLlistMenu; const QModelIndexList selectedRows = ui->contentTreeView->selectionModel()->selectedRows(0); @@ -620,7 +622,7 @@ void AddNewTorrentDialog::displayContentTreeMenu(const QPoint&) void AddNewTorrentDialog::accept() { if (!m_hasMetadata) - disconnect(this, SLOT(updateMetadata(const BitTorrent::TorrentInfo &))); + disconnect(this, SLOT(updateMetadata(const BitTorrent::TorrentInfo&))); BitTorrent::AddTorrentParams params; @@ -720,8 +722,8 @@ void AddNewTorrentDialog::setupTreeview() ui->contentTreeView->setModel(m_contentModel); m_contentDelegate = new PropListDelegate(nullptr); ui->contentTreeView->setItemDelegate(m_contentDelegate); - connect(ui->contentTreeView, SIGNAL(clicked(const QModelIndex &)), ui->contentTreeView, SLOT(edit(const QModelIndex &))); - connect(ui->contentTreeView, SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(displayContentTreeMenu(const QPoint &))); + connect(ui->contentTreeView, SIGNAL(clicked(const QModelIndex&)), ui->contentTreeView, SLOT(edit(const QModelIndex&))); + connect(ui->contentTreeView, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(displayContentTreeMenu(const QPoint&))); // List files in torrent m_contentModel->model()->setupModelData(m_torrentInfo); diff --git a/src/gui/properties/peerlistdelegate.h b/src/gui/properties/peerlistdelegate.h index f883123d7..bfd79bcbc 100644 --- a/src/gui/properties/peerlistdelegate.h +++ b/src/gui/properties/peerlistdelegate.h @@ -38,7 +38,8 @@ #include "base/utils/misc.h" #include "base/utils/string.h" -class PeerListDelegate: public QItemDelegate { +class PeerListDelegate: public QItemDelegate +{ Q_OBJECT public: @@ -67,7 +68,7 @@ public: ~PeerListDelegate() {} - void paint(QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index) const override + void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override { painter->save(); @@ -75,7 +76,7 @@ public: QStyleOptionViewItem opt = QItemDelegate::setOptions(index, option); QItemDelegate::drawBackground(painter, opt, index); - switch(index.column()) { + switch (index.column()) { case PORT: { opt.displayAlignment = Qt::AlignRight | Qt::AlignVCenter; QItemDelegate::drawDisplay(painter, opt, option.rect, index.data().toString()); @@ -91,7 +92,7 @@ public: } break; case DOWN_SPEED: - case UP_SPEED:{ + case UP_SPEED: { qreal speed = index.data().toDouble(); if (speed <= 0.0) break; @@ -103,7 +104,7 @@ public: case RELEVANCE: { qreal progress = index.data().toDouble(); opt.displayAlignment = Qt::AlignRight | Qt::AlignVCenter; - QItemDelegate::drawDisplay(painter, opt, opt.rect, Utils::String::fromDouble(progress*100.0, 1)+"%"); + QItemDelegate::drawDisplay(painter, opt, opt.rect, Utils::String::fromDouble(progress * 100.0, 1) + "%"); } break; default: @@ -113,7 +114,7 @@ public: painter->restore(); } - QWidget* createEditor(QWidget*, const QStyleOptionViewItem &, const QModelIndex &) const override + QWidget *createEditor(QWidget *, const QStyleOptionViewItem &, const QModelIndex &) const override { // No editor here return nullptr; diff --git a/src/gui/properties/peerlistwidget.cpp b/src/gui/properties/peerlistwidget.cpp index da2f50951..038ecce2f 100644 --- a/src/gui/properties/peerlistwidget.cpp +++ b/src/gui/properties/peerlistwidget.cpp @@ -100,7 +100,7 @@ PeerListWidget::PeerListWidget(PropertiesWidget *parent) m_resolveCountries = Preferences::instance()->resolvePeerCountries(); if (!m_resolveCountries) hideColumn(PeerListDelegate::COUNTRY); - //Ensure that at least one column is visible at all times + // Ensure that at least one column is visible at all times bool atLeastOne = false; for (unsigned int i = 0; i < PeerListDelegate::IP_HIDDEN; i++) { if (!isColumnHidden(i)) { @@ -110,9 +110,9 @@ PeerListWidget::PeerListWidget(PropertiesWidget *parent) } if (!atLeastOne) setColumnHidden(PeerListDelegate::IP, false); - //To also mitigate the above issue, we have to resize each column when - //its size is 0, because explicitly 'showing' the column isn't enough - //in the above scenario. + // To also mitigate the above issue, we have to resize each column when + // its size is 0, because explicitly 'showing' the column isn't enough + // in the above scenario. for (unsigned int i = 0; i < PeerListDelegate::IP_HIDDEN; i++) if ((columnWidth(i) <= 0) && !isColumnHidden(i)) resizeColumnToContents(i); @@ -128,7 +128,7 @@ PeerListWidget::PeerListWidget(PropertiesWidget *parent) updatePeerHostNameResolutionState(); // SIGNAL/SLOT header()->setContextMenuPolicy(Qt::CustomContextMenu); - connect(header(), SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(displayToggleColumnsMenu(const QPoint &))); + connect(header(), SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(displayToggleColumnsMenu(const QPoint&))); connect(header(), SIGNAL(sectionClicked(int)), SLOT(handleSortColumnChanged(int))); handleSortColumnChanged(header()->sortIndicatorSection()); m_copyHotkey = new QShortcut(QKeySequence::Copy, this, SLOT(copySelectedPeers()), 0, Qt::WidgetShortcut); @@ -148,11 +148,11 @@ PeerListWidget::~PeerListWidget() delete m_resolver; } -void PeerListWidget::displayToggleColumnsMenu(const QPoint&) +void PeerListWidget::displayToggleColumnsMenu(const QPoint &) { QMenu hideshowColumn(this); hideshowColumn.setTitle(tr("Column visibility")); - QList actions; + QList actions; for (int i = 0; i < PeerListDelegate::IP_HIDDEN; ++i) { if ((i == PeerListDelegate::COUNTRY) && !Preferences::instance()->resolvePeerCountries()) { actions.append(nullptr); // keep the index in sync @@ -193,7 +193,7 @@ void PeerListWidget::updatePeerHostNameResolutionState() if (Preferences::instance()->resolvePeerHostNames()) { if (!m_resolver) { m_resolver = new Net::ReverseResolution(this); - connect(m_resolver, SIGNAL(ipResolved(QString, QString)), SLOT(handleResolved(QString, QString))); + connect(m_resolver, SIGNAL(ipResolved(QString,QString)), SLOT(handleResolved(QString,QString))); loadPeers(m_properties->getCurrentTorrent(), true); } } @@ -218,7 +218,7 @@ void PeerListWidget::updatePeerCountryResolutionState() } } -void PeerListWidget::showPeerListMenu(const QPoint&) +void PeerListWidget::showPeerListMenu(const QPoint &) { QMenu menu; bool emptyMenu = true; @@ -362,7 +362,7 @@ void PeerListWidget::loadPeers(BitTorrent::TorrentHandle *const torrent, bool fo // Delete peers that are gone QSetIterator it(oldeersSet); while (it.hasNext()) { - const QString& ip = it.next(); + const QString &ip = it.next(); m_missingFlags.remove(ip); m_peerAddresses.remove(ip); QStandardItem *item = m_peerItems.take(ip); @@ -370,7 +370,7 @@ void PeerListWidget::loadPeers(BitTorrent::TorrentHandle *const torrent, bool fo } } -QStandardItem* PeerListWidget::addPeer(const QString& ip, BitTorrent::TorrentHandle *const torrent, const BitTorrent::PeerInfo &peer) +QStandardItem *PeerListWidget::addPeer(const QString &ip, BitTorrent::TorrentHandle *const torrent, const BitTorrent::PeerInfo &peer) { int row = m_listModel->rowCount(); // Adding Peer to peer list @@ -460,7 +460,7 @@ void PeerListWidget::wheelEvent(QWheelEvent *event) { event->accept(); - if(event->modifiers() & Qt::ShiftModifier) { + if (event->modifiers() & Qt::ShiftModifier) { // Shift + scroll = horizontal scroll QWheelEvent scrollHEvent(event->pos(), event->globalPos(), event->delta(), event->buttons(), event->modifiers(), Qt::Horizontal); QTreeView::wheelEvent(&scrollHEvent); diff --git a/src/gui/properties/peerlistwidget.h b/src/gui/properties/peerlistwidget.h index 6a6de5abb..3d4a8483b 100644 --- a/src/gui/properties/peerlistwidget.h +++ b/src/gui/properties/peerlistwidget.h @@ -77,8 +77,8 @@ public: private slots: void loadSettings(); void saveSettings() const; - void displayToggleColumnsMenu(const QPoint&); - void showPeerListMenu(const QPoint&); + void displayToggleColumnsMenu(const QPoint &); + void showPeerListMenu(const QPoint &); void banSelectedPeers(); void copySelectedPeers(); void handleSortColumnChanged(int col); @@ -90,7 +90,7 @@ private: QStandardItemModel *m_listModel; PeerListDelegate *m_listDelegate; PeerListSortModel *m_proxyModel; - QHash m_peerItems; + QHash m_peerItems; QHash m_peerAddresses; QSet m_missingFlags; QPointer m_resolver; diff --git a/src/gui/properties/proplistdelegate.cpp b/src/gui/properties/proplistdelegate.cpp index cb4e86ce9..fcf498101 100644 --- a/src/gui/properties/proplistdelegate.cpp +++ b/src/gui/properties/proplistdelegate.cpp @@ -45,18 +45,18 @@ #include "proplistdelegate.h" #include "torrentcontentmodelitem.h" -namespace { +namespace +{ QPalette progressBarDisabledPalette() { - auto getPalette = []() - { - QProgressBar bar; - bar.setEnabled(false); - QStyleOptionProgressBar opt; - opt.initFrom(&bar); - return opt.palette; - }; + auto getPalette = []() { + QProgressBar bar; + bar.setEnabled(false); + QStyleOptionProgressBar opt; + opt.initFrom(&bar); + return opt.palette; + }; static QPalette palette = getPalette(); return palette; } @@ -74,7 +74,7 @@ void PropListDelegate::paint(QPainter *painter, const QStyleOptionViewItem &opti QStyleOptionViewItem opt = QItemDelegate::setOptions(index, option); QItemDelegate::drawBackground(painter, opt, index); - switch(index.column()) { + switch (index.column()) { case PCSIZE: case REMAINING: QItemDelegate::drawDisplay(painter, opt, option.rect, Utils::Misc::friendlyUnit(index.data().toLongLong())); @@ -105,28 +105,28 @@ void PropListDelegate::paint(QPainter *painter, const QStyleOptionViewItem &opti // XXX: To avoid having the progress text on the right of the bar QProxyStyle("fusion").drawControl(QStyle::CE_ProgressBar, &newopt, painter, 0); #endif - } - break; + } + break; case PRIORITY: { - QString text = ""; - switch (index.data().toInt()) { - case prio::MIXED: - text = tr("Mixed", "Mixed (priorities"); - break; - case prio::IGNORED: - text = tr("Not downloaded"); - break; - case prio::HIGH: - text = tr("High", "High (priority)"); - break; - case prio::MAXIMUM: - text = tr("Maximum", "Maximum (priority)"); - break; - default: - text = tr("Normal", "Normal (priority)"); - break; - } - QItemDelegate::drawDisplay(painter, opt, option.rect, text); + QString text = ""; + switch (index.data().toInt()) { + case prio::MIXED: + text = tr("Mixed", "Mixed (priorities"); + break; + case prio::IGNORED: + text = tr("Not downloaded"); + break; + case prio::HIGH: + text = tr("High", "High (priority)"); + break; + case prio::MAXIMUM: + text = tr("Maximum", "Maximum (priority)"); + break; + default: + text = tr("Normal", "Normal (priority)"); + break; + } + QItemDelegate::drawDisplay(painter, opt, option.rect, text); } break; default: @@ -138,9 +138,9 @@ void PropListDelegate::paint(QPainter *painter, const QStyleOptionViewItem &opti void PropListDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const { - QComboBox *combobox = static_cast(editor); + QComboBox *combobox = static_cast(editor); // Set combobox index - switch(index.data().toInt()) { + switch (index.data().toInt()) { case prio::IGNORED: combobox->setCurrentIndex(0); break; @@ -169,7 +169,7 @@ QWidget *PropListDelegate::createEditor(QWidget *parent, const QStyleOptionViewI if (index.data().toInt() == prio::MIXED) return 0; - QComboBox* editor = new QComboBox(parent); + QComboBox *editor = new QComboBox(parent); editor->setFocusPolicy(Qt::StrongFocus); editor->addItem(tr("Do not download", "Do not download (priority)")); editor->addItem(tr("Normal", "Normal (priority)")); @@ -180,11 +180,11 @@ QWidget *PropListDelegate::createEditor(QWidget *parent, const QStyleOptionViewI void PropListDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const { - QComboBox *combobox = static_cast(editor); + QComboBox *combobox = static_cast(editor); int value = combobox->currentIndex(); qDebug("PropListDelegate: setModelData(%d)", value); - switch(value) { + switch (value) { case 0: model->setData(index, prio::IGNORED); // IGNORED break; diff --git a/src/gui/properties/proplistdelegate.h b/src/gui/properties/proplistdelegate.h index 90b8babe9..2d5e41335 100644 --- a/src/gui/properties/proplistdelegate.h +++ b/src/gui/properties/proplistdelegate.h @@ -49,7 +49,7 @@ enum PropColumn REMAINING }; -class PropListDelegate : public QItemDelegate +class PropListDelegate: public QItemDelegate { Q_OBJECT @@ -58,11 +58,11 @@ public: void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override; void setEditorData(QWidget *editor, const QModelIndex &index) const override; - QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &/* option */, const QModelIndex &index) const override; + QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem & /* option */, const QModelIndex &index) const override; public slots: void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const override; - void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &/* index */) const override; + void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex & /* index */) const override; signals: void filteredFilesChanged() const; diff --git a/src/gui/search/searchlistdelegate.cpp b/src/gui/search/searchlistdelegate.cpp index 16c79afff..04d030d3e 100644 --- a/src/gui/search/searchlistdelegate.cpp +++ b/src/gui/search/searchlistdelegate.cpp @@ -49,7 +49,7 @@ void SearchListDelegate::paint(QPainter *painter, const QStyleOptionViewItem &op QStyleOptionViewItem opt = QItemDelegate::setOptions(index, option); QItemDelegate::drawBackground(painter, opt, index); - switch(index.column()) { + switch (index.column()) { case SearchSortModel::SIZE: opt.displayAlignment = Qt::AlignRight | Qt::AlignVCenter; QItemDelegate::drawDisplay(painter, opt, option.rect, Utils::Misc::friendlyUnit(index.data().toLongLong())); diff --git a/src/gui/search/searchlistdelegate.h b/src/gui/search/searchlistdelegate.h index 2131d5bfa..1af6e19ce 100644 --- a/src/gui/search/searchlistdelegate.h +++ b/src/gui/search/searchlistdelegate.h @@ -39,7 +39,7 @@ public: explicit SearchListDelegate(QObject *parent); void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override; - QWidget* createEditor(QWidget*, const QStyleOptionViewItem &, const QModelIndex &) const override; + QWidget *createEditor(QWidget *, const QStyleOptionViewItem &, const QModelIndex &) const override; }; #endif