From ce77ebdfe159acdf47e458fe1af091fa84de35ef Mon Sep 17 00:00:00 2001 From: thalieht Date: Thu, 9 Mar 2017 18:25:41 +0200 Subject: [PATCH 1/9] Coding style of whole trackerlist.h and a little in trackerlist.cpp --- src/gui/properties/trackerlist.cpp | 52 +++++++++++--------- src/gui/properties/trackerlist.h | 79 +++++++++++++++++------------- 2 files changed, 74 insertions(+), 57 deletions(-) diff --git a/src/gui/properties/trackerlist.cpp b/src/gui/properties/trackerlist.cpp index 716be9c52..350f73ddd 100644 --- a/src/gui/properties/trackerlist.cpp +++ b/src/gui/properties/trackerlist.cpp @@ -30,31 +30,34 @@ #include "trackerlist.h" -#include -#include -#include -#include -#include #include +#include #include #include -#include +#include +#include +#include #include +#include #include -#include +#include +#include +#include "base/bittorrent/peerinfo.h" #include "base/bittorrent/session.h" #include "base/bittorrent/torrenthandle.h" -#include "base/bittorrent/peerinfo.h" #include "base/bittorrent/trackerentry.h" #include "base/preferences.h" #include "base/utils/misc.h" +#include "autoexpandabledialog.h" +#include "guiiconprovider.h" #include "propertieswidget.h" #include "trackersadditiondlg.h" -#include "guiiconprovider.h" -#include "autoexpandabledialog.h" -TrackerList::TrackerList(PropertiesWidget *properties): QTreeWidget(), properties(properties) { +TrackerList::TrackerList(PropertiesWidget *properties) + : QTreeWidget() + , properties(properties) +{ // Graphical settings setRootIsDecorated(false); setAllColumnsShowFocus(true); @@ -98,11 +101,12 @@ TrackerList::TrackerList(PropertiesWidget *properties): QTreeWidget(), propertie loadSettings(); } -TrackerList::~TrackerList() { - delete editHotkey; - delete deleteHotkey; - delete copyHotkey; - saveSettings(); +TrackerList::~TrackerList() +{ + delete editHotkey; + delete deleteHotkey; + delete copyHotkey; + saveSettings(); } QList TrackerList::getSelectedTrackerItems() const { @@ -524,13 +528,15 @@ void TrackerList::showTrackerListMenu(QPoint) { } } -void TrackerList::loadSettings() { - if (!header()->restoreState(Preferences::instance()->getPropTrackerListState())) { - setColumnWidth(0, 30); - setColumnWidth(1, 300); - } +void TrackerList::loadSettings() +{ + if (!header()->restoreState(Preferences::instance()->getPropTrackerListState())) { + setColumnWidth(0, 30); + setColumnWidth(1, 300); + } } -void TrackerList::saveSettings() const { - Preferences::instance()->setPropTrackerListState(header()->saveState()); +void TrackerList::saveSettings() const +{ + Preferences::instance()->setPropTrackerListState(header()->saveState()); } diff --git a/src/gui/properties/trackerlist.h b/src/gui/properties/trackerlist.h index dc964c71f..0d7521b9e 100644 --- a/src/gui/properties/trackerlist.h +++ b/src/gui/properties/trackerlist.h @@ -31,14 +31,13 @@ #ifndef TRACKERLIST_H #define TRACKERLIST_H +#include +#include #include #include -#include -#include #include "propertieswidget.h" -enum TrackerListColumn {COL_TIER, COL_URL, COL_STATUS, COL_RECEIVED, COL_SEEDS, COL_PEERS, COL_DOWNLOADED, COL_MSG}; #define NB_STICKY_ITEM 3 namespace BitTorrent @@ -46,45 +45,57 @@ namespace BitTorrent class TorrentHandle; } -class TrackerList: public QTreeWidget { - Q_OBJECT - Q_DISABLE_COPY(TrackerList) - -private: - PropertiesWidget *properties; - QHash tracker_items; - QTreeWidgetItem* dht_item; - QTreeWidgetItem* pex_item; - QTreeWidgetItem* lsd_item; - QShortcut *editHotkey; - QShortcut *deleteHotkey; - QShortcut *copyHotkey; +class TrackerList: public QTreeWidget +{ + Q_OBJECT + Q_DISABLE_COPY(TrackerList) public: - TrackerList(PropertiesWidget *properties); - ~TrackerList(); + enum TrackerListColumn + { + COL_TIER, + COL_URL, + COL_STATUS, + COL_RECEIVED, + COL_SEEDS, + COL_PEERS, + COL_DOWNLOADED, + COL_MSG + }; -protected: - QList getSelectedTrackerItems() const; + TrackerList(PropertiesWidget *properties); + ~TrackerList(); public slots: - void setRowColor(int row, QColor color); + void setRowColor(int row, QColor color); - void moveSelectionUp(); - void moveSelectionDown(); + void moveSelectionUp(); + void moveSelectionDown(); - void clear(); - void loadStickyItems(BitTorrent::TorrentHandle *const torrent); - void loadTrackers(); - void askForTrackers(); - void copyTrackerUrl(); - void reannounceSelected(); - void deleteSelectedTrackers(); - void editSelectedTracker(); - void showTrackerListMenu(QPoint); - void loadSettings(); - void saveSettings() const; + void clear(); + void loadStickyItems(BitTorrent::TorrentHandle *const torrent); + void loadTrackers(); + void askForTrackers(); + void copyTrackerUrl(); + void reannounceSelected(); + void deleteSelectedTrackers(); + void editSelectedTracker(); + void showTrackerListMenu(QPoint); + void loadSettings(); + void saveSettings() const; +protected: + QList getSelectedTrackerItems() const; + +private: + PropertiesWidget *properties; + QHash tracker_items; + QTreeWidgetItem *dht_item; + QTreeWidgetItem *pex_item; + QTreeWidgetItem *lsd_item; + QShortcut *editHotkey; + QShortcut *deleteHotkey; + QShortcut *copyHotkey; }; #endif // TRACKERLIST_H From b360c5453be640eccd3f510c5eda0febb4e87cd4 Mon Sep 17 00:00:00 2001 From: thalieht Date: Fri, 10 Mar 2017 12:36:06 +0200 Subject: [PATCH 2/9] PropertiesWidget: Some coding style --- src/gui/properties/propertieswidget.cpp | 38 ++++++++++++------------- src/gui/properties/propertieswidget.h | 30 ++++++++++--------- 2 files changed, 35 insertions(+), 33 deletions(-) diff --git a/src/gui/properties/propertieswidget.cpp b/src/gui/properties/propertieswidget.cpp index 77466c748..1b76e4f36 100644 --- a/src/gui/properties/propertieswidget.cpp +++ b/src/gui/properties/propertieswidget.cpp @@ -30,40 +30,40 @@ #include "propertieswidget.h" +#include +#include #include -#include -#include -#include -#include -#include +#include #include -#include +#include #include -#include -#include +#include +#include #include +#include +#include #include "base/bittorrent/session.h" #include "base/preferences.h" +#include "base/unicodestrings.h" #include "base/utils/fs.h" #include "base/utils/misc.h" #include "base/utils/string.h" -#include "base/unicodestrings.h" -#include "proplistdelegate.h" -#include "torrentcontentfiltermodel.h" -#include "torrentcontentmodel.h" -#include "peerlistwidget.h" -#include "speedwidget.h" -#include "trackerlist.h" +#include "autoexpandabledialog.h" +#include "downloadedpiecesbar.h" +#include "guiiconprovider.h" +#include "lineedit.h" #include "mainwindow.h" #include "messageboxraised.h" -#include "downloadedpiecesbar.h" +#include "peerlistwidget.h" #include "pieceavailabilitybar.h" +#include "proplistdelegate.h" #include "proptabbar.h" -#include "guiiconprovider.h" -#include "lineedit.h" +#include "speedwidget.h" +#include "torrentcontentfiltermodel.h" +#include "torrentcontentmodel.h" +#include "trackerlist.h" #include "transferlistwidget.h" -#include "autoexpandabledialog.h" #include "ui_propertieswidget.h" diff --git a/src/gui/properties/propertieswidget.h b/src/gui/properties/propertieswidget.h index 1b8fbeb3f..9bfefe10c 100644 --- a/src/gui/properties/propertieswidget.h +++ b/src/gui/properties/propertieswidget.h @@ -33,8 +33,8 @@ #include #include -#include "base/bittorrent/torrenthandle.h" +#include "base/bittorrent/torrenthandle.h" class TransferListWidget; class TorrentContentFilterModel; @@ -67,9 +67,12 @@ class PropertiesWidget: public QWidget Q_DISABLE_COPY(PropertiesWidget) public: - enum SlideState {REDUCED, VISIBLE}; + enum SlideState + { + REDUCED, + VISIBLE + }; -public: PropertiesWidget(QWidget *parent, MainWindow *main_window, TransferListWidget *transferList); ~PropertiesWidget(); BitTorrent::TorrentHandle *getCurrentTorrent() const; @@ -78,6 +81,16 @@ public: QTreeView *getFilesList() const; SpeedWidget *getSpeedWidget() const { return speedWidget; } +public slots: + void setVisibility(bool visible); + void loadDynamicData(); + void clear(); + void readSettings(); + void saveSettings(); + void reloadPreferences(); + void openDoubleClickedFile(const QModelIndex &); + void loadTrackers(BitTorrent::TorrentHandle *const torrent); + protected: QPushButton *getButtonFromIndex(int index); bool applyPriorities(); @@ -98,21 +111,10 @@ protected slots: void renameSelectedFile(); void openSelectedFile(); -public slots: - void setVisibility(bool visible); - void loadDynamicData(); - void clear(); - void readSettings(); - void saveSettings(); - void reloadPreferences(); - void openDoubleClickedFile(const QModelIndex &); - void loadTrackers(BitTorrent::TorrentHandle *const torrent); - private: void openFile(const QModelIndex &index); void openFolder(const QModelIndex &index, bool containing_folder); -private: Ui::PropertiesWidget *m_ui; TransferListWidget *transferList; MainWindow *main_window; From e00be240b07d5691b5265a3c5d6980db4e44f5d0 Mon Sep 17 00:00:00 2001 From: thalieht Date: Fri, 10 Mar 2017 12:38:18 +0200 Subject: [PATCH 3/9] PropertiesWidget: Change 0 to nullptr --- src/gui/properties/propertieswidget.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/gui/properties/propertieswidget.cpp b/src/gui/properties/propertieswidget.cpp index 1b76e4f36..7f3bac7e8 100644 --- a/src/gui/properties/propertieswidget.cpp +++ b/src/gui/properties/propertieswidget.cpp @@ -72,7 +72,7 @@ PropertiesWidget::PropertiesWidget(QWidget *parent, MainWindow *main_window, Tra , m_ui(new Ui::PropertiesWidget()) , transferList(transferList) , main_window(main_window) - , m_torrent(0) + , m_torrent(nullptr) { m_ui->setupUi(this); setAutoFillBackground(true); @@ -582,9 +582,9 @@ void PropertiesWidget::displayFilesListMenu(const QPoint &) if (selectedRows.empty()) return; QMenu myFilesLlistMenu; - QAction *actOpen = 0; - QAction *actOpenContainingFolder = 0; - QAction *actRename = 0; + QAction *actOpen = nullptr; + QAction *actOpenContainingFolder = nullptr; + QAction *actRename = nullptr; if (selectedRows.size() == 1) { actOpen = myFilesLlistMenu.addAction(GuiIconProvider::instance()->getIcon("folder-documents"), tr("Open")); actOpenContainingFolder = myFilesLlistMenu.addAction(GuiIconProvider::instance()->getIcon("inode-directory"), tr("Open Containing Folder")); @@ -644,9 +644,9 @@ void PropertiesWidget::displayWebSeedListMenu(const QPoint &) QMenu seedMenu; QModelIndexList rows = m_ui->listWebSeeds->selectionModel()->selectedRows(); QAction *actAdd = seedMenu.addAction(GuiIconProvider::instance()->getIcon("list-add"), tr("New Web seed")); - QAction *actDel = 0; - QAction *actCpy = 0; - QAction *actEdit = 0; + QAction *actDel = nullptr; + QAction *actCpy = nullptr; + QAction *actEdit = nullptr; if (rows.size()) { actDel = seedMenu.addAction(GuiIconProvider::instance()->getIcon("list-remove"), tr("Remove Web seed")); From e82a1522c8ebf12e7b34225aa7056475d8c8f267 Mon Sep 17 00:00:00 2001 From: thalieht Date: Thu, 9 Mar 2017 18:45:34 +0200 Subject: [PATCH 4/9] Trackerlist: Change 0 to nullptr --- src/gui/properties/trackerlist.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/gui/properties/trackerlist.cpp b/src/gui/properties/trackerlist.cpp index 350f73ddd..1b4abb22a 100644 --- a/src/gui/properties/trackerlist.cpp +++ b/src/gui/properties/trackerlist.cpp @@ -483,23 +483,23 @@ void TrackerList::showTrackerListMenu(QPoint) { QMenu menu; // Add actions QAction *addAct = menu.addAction(GuiIconProvider::instance()->getIcon("list-add"), tr("Add a new tracker...")); - QAction *copyAct = 0; - QAction *delAct = 0; - QAction *editAct = 0; + QAction *copyAct = nullptr; + QAction *delAct = nullptr; + QAction *editAct = nullptr; if (!getSelectedTrackerItems().isEmpty()) { delAct = menu.addAction(GuiIconProvider::instance()->getIcon("list-remove"), tr("Remove tracker")); copyAct = menu.addAction(GuiIconProvider::instance()->getIcon("edit-copy"), tr("Copy tracker URL")); editAct = menu.addAction(GuiIconProvider::instance()->getIcon("edit-rename"),tr("Edit selected tracker URL")); } - QAction *reannounceSelAct = NULL; - QAction *reannounceAct = NULL; + QAction *reannounceSelAct = nullptr; + QAction *reannounceAct = nullptr; if (!torrent->isPaused()) { reannounceSelAct = menu.addAction(GuiIconProvider::instance()->getIcon("view-refresh"), tr("Force reannounce to selected trackers")); menu.addSeparator(); reannounceAct = menu.addAction(GuiIconProvider::instance()->getIcon("view-refresh"), tr("Force reannounce to all trackers")); } QAction *act = menu.exec(QCursor::pos()); - if (act == 0) return; + if (act == nullptr) return; if (act == addAct) { askForTrackers(); return; From 33979cb41c46c47bc30934f2a7fe031f637777b3 Mon Sep 17 00:00:00 2001 From: thalieht Date: Fri, 10 Mar 2017 11:47:59 +0200 Subject: [PATCH 5/9] TransferListWidget: Remove unnecessary deletes from the destructor --- src/gui/transferlistwidget.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/gui/transferlistwidget.cpp b/src/gui/transferlistwidget.cpp index 584e52fdf..367072613 100644 --- a/src/gui/transferlistwidget.cpp +++ b/src/gui/transferlistwidget.cpp @@ -172,8 +172,6 @@ TransferListWidget::~TransferListWidget() delete nameFilterModel; delete listModel; delete listDelegate; - delete editHotkey; - delete deleteHotkey; qDebug() << Q_FUNC_INFO << "EXIT"; } From 5d33399000977183ab5421735c395a99b58ceabf Mon Sep 17 00:00:00 2001 From: thalieht Date: Wed, 5 Apr 2017 17:36:35 +0300 Subject: [PATCH 6/9] TrackerList: Remove unnecessary deletes from the destructor --- src/gui/properties/trackerlist.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/gui/properties/trackerlist.cpp b/src/gui/properties/trackerlist.cpp index 1b4abb22a..92021cfd6 100644 --- a/src/gui/properties/trackerlist.cpp +++ b/src/gui/properties/trackerlist.cpp @@ -103,9 +103,6 @@ TrackerList::TrackerList(PropertiesWidget *properties) TrackerList::~TrackerList() { - delete editHotkey; - delete deleteHotkey; - delete copyHotkey; saveSettings(); } From d9555a9e9dc3cf75404d4f80098a7203bfd63ff8 Mon Sep 17 00:00:00 2001 From: thalieht Date: Fri, 10 Mar 2017 20:23:11 +0200 Subject: [PATCH 7/9] Trackerlist: Set text alignment of columns with numbers to the right --- src/gui/properties/trackerlist.cpp | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/gui/properties/trackerlist.cpp b/src/gui/properties/trackerlist.cpp index 92021cfd6..ac7aacae4 100644 --- a/src/gui/properties/trackerlist.cpp +++ b/src/gui/properties/trackerlist.cpp @@ -86,6 +86,26 @@ TrackerList::TrackerList(PropertiesWidget *properties) lsd_item = new QTreeWidgetItem({ "", "** [LSD] **", "", "0", "", "", "0" }); insertTopLevelItem(2, lsd_item); setRowColor(2, QColor("grey")); + // Set static items alignment + dht_item->setTextAlignment(COL_RECEIVED, (Qt::AlignRight | Qt::AlignVCenter)); + pex_item->setTextAlignment(COL_RECEIVED, (Qt::AlignRight | Qt::AlignVCenter)); + lsd_item->setTextAlignment(COL_RECEIVED, (Qt::AlignRight | Qt::AlignVCenter)); + dht_item->setTextAlignment(COL_SEEDS, (Qt::AlignRight | Qt::AlignVCenter)); + pex_item->setTextAlignment(COL_SEEDS, (Qt::AlignRight | Qt::AlignVCenter)); + lsd_item->setTextAlignment(COL_SEEDS, (Qt::AlignRight | Qt::AlignVCenter)); + dht_item->setTextAlignment(COL_PEERS, (Qt::AlignRight | Qt::AlignVCenter)); + pex_item->setTextAlignment(COL_PEERS, (Qt::AlignRight | Qt::AlignVCenter)); + lsd_item->setTextAlignment(COL_PEERS, (Qt::AlignRight | Qt::AlignVCenter)); + dht_item->setTextAlignment(COL_DOWNLOADED, (Qt::AlignRight | Qt::AlignVCenter)); + pex_item->setTextAlignment(COL_DOWNLOADED, (Qt::AlignRight | Qt::AlignVCenter)); + lsd_item->setTextAlignment(COL_DOWNLOADED, (Qt::AlignRight | Qt::AlignVCenter)); + // Set header alignment + headerItem()->setTextAlignment(COL_TIER, (Qt::AlignRight | Qt::AlignVCenter)); + headerItem()->setTextAlignment(COL_RECEIVED, (Qt::AlignRight | Qt::AlignVCenter)); + headerItem()->setTextAlignment(COL_SEEDS, (Qt::AlignRight | Qt::AlignVCenter)); + headerItem()->setTextAlignment(COL_PEERS, (Qt::AlignRight | Qt::AlignVCenter)); + headerItem()->setTextAlignment(COL_DOWNLOADED, (Qt::AlignRight | Qt::AlignVCenter)); + // Set hotkeys editHotkey = new QShortcut(Qt::Key_F2, this, SLOT(editSelectedTracker()), 0, Qt::WidgetShortcut); connect(this, SIGNAL(doubleClicked(QModelIndex)), SLOT(editSelectedTracker())); deleteHotkey = new QShortcut(QKeySequence::Delete, this, SLOT(deleteSelectedTrackers()), 0, Qt::WidgetShortcut); @@ -335,6 +355,11 @@ void TrackerList::loadTrackers() { item->setText(COL_DOWNLOADED, "0"); #endif + item->setTextAlignment(COL_TIER, (Qt::AlignRight | Qt::AlignVCenter)); + item->setTextAlignment(COL_RECEIVED, (Qt::AlignRight | Qt::AlignVCenter)); + item->setTextAlignment(COL_SEEDS, (Qt::AlignRight | Qt::AlignVCenter)); + item->setTextAlignment(COL_PEERS, (Qt::AlignRight | Qt::AlignVCenter)); + item->setTextAlignment(COL_DOWNLOADED, (Qt::AlignRight | Qt::AlignVCenter)); } // Remove old trackers foreach (const QString &tracker, old_trackers_urls) { From 14f50f10383bf7633afdc6e28a7e19debb020353 Mon Sep 17 00:00:00 2001 From: thalieht Date: Fri, 10 Mar 2017 11:43:59 +0200 Subject: [PATCH 8/9] Trackerlist: Allow to toggle columns --- src/gui/properties/trackerlist.cpp | 94 ++++++++++++++++++++++++------ src/gui/properties/trackerlist.h | 9 ++- 2 files changed, 83 insertions(+), 20 deletions(-) diff --git a/src/gui/properties/trackerlist.cpp b/src/gui/properties/trackerlist.cpp index ac7aacae4..96968dbb3 100644 --- a/src/gui/properties/trackerlist.cpp +++ b/src/gui/properties/trackerlist.cpp @@ -58,25 +58,33 @@ TrackerList::TrackerList(PropertiesWidget *properties) : QTreeWidget() , properties(properties) { + // Set header + // Must be set before calling loadSettings() otherwise the header is reset on restart + setHeaderLabels(headerLabels()); + // Load settings + loadSettings(); // Graphical settings setRootIsDecorated(false); setAllColumnsShowFocus(true); setItemsExpandable(false); setSelectionMode(QAbstractItemView::ExtendedSelection); + header()->setStretchLastSection(false); // Must be set after loadSettings() in order to work + // Ensure that at least one column is visible at all times + if (visibleColumnsCount() == 0) + setColumnHidden(COL_URL, 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. + for (unsigned int i = 0; i < COL_COUNT; ++i) + if ((columnWidth(i) <= 0) && !isColumnHidden(i)) + resizeColumnToContents(i); // Context menu setContextMenuPolicy(Qt::CustomContextMenu); connect(this, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(showTrackerListMenu(QPoint))); - // Set header - QStringList header; - header << "#"; - header << tr("URL"); - header << tr("Status"); - header << tr("Received"); - header << tr("Seeds"); - header << tr("Peers"); - header << tr("Downloaded"); - header << tr("Message"); - setHeaderItem(new QTreeWidgetItem(header)); + // Header context menu + header()->setContextMenuPolicy(Qt::CustomContextMenu); + connect(header(), SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(displayToggleColumnsMenu(const QPoint&))); + // Set DHT, PeX, LSD items dht_item = new QTreeWidgetItem({ "", "** [DHT] **", "", "0", "", "", "0" }); insertTopLevelItem(0, dht_item); setRowColor(0, QColor("grey")); @@ -114,11 +122,9 @@ TrackerList::TrackerList(PropertiesWidget *properties) // This hack fixes reordering of first column with Qt5. // https://github.com/qtproject/qtbase/commit/e0fc088c0c8bc61dbcaf5928b24986cd61a22777 QTableView unused; - unused.setVerticalHeader(this->header()); - this->header()->setParent(this); + unused.setVerticalHeader(header()); + header()->setParent(this); unused.setVerticalHeader(new QHeaderView(Qt::Horizontal)); - - loadSettings(); } TrackerList::~TrackerList() @@ -552,13 +558,63 @@ void TrackerList::showTrackerListMenu(QPoint) { void TrackerList::loadSettings() { - if (!header()->restoreState(Preferences::instance()->getPropTrackerListState())) { - setColumnWidth(0, 30); - setColumnWidth(1, 300); - } + header()->restoreState(Preferences::instance()->getPropTrackerListState()); } void TrackerList::saveSettings() const { Preferences::instance()->setPropTrackerListState(header()->saveState()); } + +QStringList TrackerList::headerLabels() +{ + static const QStringList header { + "#" + , tr("URL") + , tr("Status") + , tr("Received") + , tr("Seeds") + , tr("Peers") + , tr("Downloaded") + , tr("Message") + }; + + return header; +} + +int TrackerList::visibleColumnsCount() const +{ + int visibleCols = 0; + for (unsigned int i = 0; i < COL_COUNT; ++i) { + if (!isColumnHidden(i)) + ++visibleCols; + } + + return visibleCols; +} + +void TrackerList::displayToggleColumnsMenu(const QPoint &) +{ + QMenu hideshowColumn(this); + hideshowColumn.setTitle(tr("Column visibility")); + for (int i = 0; i < COL_COUNT; ++i) { + QAction *myAct = hideshowColumn.addAction(headerLabels().at(i)); + myAct->setCheckable(true); + myAct->setChecked(!isColumnHidden(i)); + myAct->setData(i); + } + + // Call menu + QAction *act = hideshowColumn.exec(QCursor::pos()); + if (!act) return; + + int col = act->data().toInt(); + Q_ASSERT(visibleColumnsCount() > 0); + if (!isColumnHidden(col) && (visibleColumnsCount() == 1)) + return; + qDebug("Toggling column %d visibility", col); + setColumnHidden(col, !isColumnHidden(col)); + if (!isColumnHidden(col) && (columnWidth(col) <= 5)) + setColumnWidth(col, 100); + saveSettings(); +} diff --git a/src/gui/properties/trackerlist.h b/src/gui/properties/trackerlist.h index 0d7521b9e..6190aaa3e 100644 --- a/src/gui/properties/trackerlist.h +++ b/src/gui/properties/trackerlist.h @@ -60,12 +60,16 @@ public: COL_SEEDS, COL_PEERS, COL_DOWNLOADED, - COL_MSG + COL_MSG, + + COL_COUNT }; TrackerList(PropertiesWidget *properties); ~TrackerList(); + int visibleColumnsCount() const; + public slots: void setRowColor(int row, QColor color); @@ -81,6 +85,7 @@ public slots: void deleteSelectedTrackers(); void editSelectedTracker(); void showTrackerListMenu(QPoint); + void displayToggleColumnsMenu(const QPoint &); void loadSettings(); void saveSettings() const; @@ -96,6 +101,8 @@ private: QShortcut *editHotkey; QShortcut *deleteHotkey; QShortcut *copyHotkey; + + static QStringList headerLabels(); }; #endif // TRACKERLIST_H From 73c37cc46069708ad59a257fd7adadb9a2196eee Mon Sep 17 00:00:00 2001 From: thalieht Date: Thu, 11 May 2017 18:58:50 +0300 Subject: [PATCH 9/9] Trackerlist: add "m_" to private members and make them camelCase --- src/gui/properties/trackerlist.cpp | 132 ++++++++++++++--------------- src/gui/properties/trackerlist.h | 16 ++-- 2 files changed, 74 insertions(+), 74 deletions(-) diff --git a/src/gui/properties/trackerlist.cpp b/src/gui/properties/trackerlist.cpp index 96968dbb3..efd64a8eb 100644 --- a/src/gui/properties/trackerlist.cpp +++ b/src/gui/properties/trackerlist.cpp @@ -56,7 +56,7 @@ TrackerList::TrackerList(PropertiesWidget *properties) : QTreeWidget() - , properties(properties) + , m_properties(properties) { // Set header // Must be set before calling loadSettings() otherwise the header is reset on restart @@ -85,28 +85,28 @@ TrackerList::TrackerList(PropertiesWidget *properties) header()->setContextMenuPolicy(Qt::CustomContextMenu); connect(header(), SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(displayToggleColumnsMenu(const QPoint&))); // Set DHT, PeX, LSD items - dht_item = new QTreeWidgetItem({ "", "** [DHT] **", "", "0", "", "", "0" }); - insertTopLevelItem(0, dht_item); + m_DHTItem = new QTreeWidgetItem({ "", "** [DHT] **", "", "0", "", "", "0" }); + insertTopLevelItem(0, m_DHTItem); setRowColor(0, QColor("grey")); - pex_item = new QTreeWidgetItem({ "", "** [PeX] **", "", "0", "", "", "0" }); - insertTopLevelItem(1, pex_item); + m_PEXItem = new QTreeWidgetItem({ "", "** [PeX] **", "", "0", "", "", "0" }); + insertTopLevelItem(1, m_PEXItem); setRowColor(1, QColor("grey")); - lsd_item = new QTreeWidgetItem({ "", "** [LSD] **", "", "0", "", "", "0" }); - insertTopLevelItem(2, lsd_item); + m_LSDItem = new QTreeWidgetItem({ "", "** [LSD] **", "", "0", "", "", "0" }); + insertTopLevelItem(2, m_LSDItem); setRowColor(2, QColor("grey")); // Set static items alignment - dht_item->setTextAlignment(COL_RECEIVED, (Qt::AlignRight | Qt::AlignVCenter)); - pex_item->setTextAlignment(COL_RECEIVED, (Qt::AlignRight | Qt::AlignVCenter)); - lsd_item->setTextAlignment(COL_RECEIVED, (Qt::AlignRight | Qt::AlignVCenter)); - dht_item->setTextAlignment(COL_SEEDS, (Qt::AlignRight | Qt::AlignVCenter)); - pex_item->setTextAlignment(COL_SEEDS, (Qt::AlignRight | Qt::AlignVCenter)); - lsd_item->setTextAlignment(COL_SEEDS, (Qt::AlignRight | Qt::AlignVCenter)); - dht_item->setTextAlignment(COL_PEERS, (Qt::AlignRight | Qt::AlignVCenter)); - pex_item->setTextAlignment(COL_PEERS, (Qt::AlignRight | Qt::AlignVCenter)); - lsd_item->setTextAlignment(COL_PEERS, (Qt::AlignRight | Qt::AlignVCenter)); - dht_item->setTextAlignment(COL_DOWNLOADED, (Qt::AlignRight | Qt::AlignVCenter)); - pex_item->setTextAlignment(COL_DOWNLOADED, (Qt::AlignRight | Qt::AlignVCenter)); - lsd_item->setTextAlignment(COL_DOWNLOADED, (Qt::AlignRight | Qt::AlignVCenter)); + m_DHTItem->setTextAlignment(COL_RECEIVED, (Qt::AlignRight | Qt::AlignVCenter)); + m_PEXItem->setTextAlignment(COL_RECEIVED, (Qt::AlignRight | Qt::AlignVCenter)); + m_LSDItem->setTextAlignment(COL_RECEIVED, (Qt::AlignRight | Qt::AlignVCenter)); + m_DHTItem->setTextAlignment(COL_SEEDS, (Qt::AlignRight | Qt::AlignVCenter)); + m_PEXItem->setTextAlignment(COL_SEEDS, (Qt::AlignRight | Qt::AlignVCenter)); + m_LSDItem->setTextAlignment(COL_SEEDS, (Qt::AlignRight | Qt::AlignVCenter)); + m_DHTItem->setTextAlignment(COL_PEERS, (Qt::AlignRight | Qt::AlignVCenter)); + m_PEXItem->setTextAlignment(COL_PEERS, (Qt::AlignRight | Qt::AlignVCenter)); + m_LSDItem->setTextAlignment(COL_PEERS, (Qt::AlignRight | Qt::AlignVCenter)); + m_DHTItem->setTextAlignment(COL_DOWNLOADED, (Qt::AlignRight | Qt::AlignVCenter)); + m_PEXItem->setTextAlignment(COL_DOWNLOADED, (Qt::AlignRight | Qt::AlignVCenter)); + m_LSDItem->setTextAlignment(COL_DOWNLOADED, (Qt::AlignRight | Qt::AlignVCenter)); // Set header alignment headerItem()->setTextAlignment(COL_TIER, (Qt::AlignRight | Qt::AlignVCenter)); headerItem()->setTextAlignment(COL_RECEIVED, (Qt::AlignRight | Qt::AlignVCenter)); @@ -114,10 +114,10 @@ TrackerList::TrackerList(PropertiesWidget *properties) headerItem()->setTextAlignment(COL_PEERS, (Qt::AlignRight | Qt::AlignVCenter)); headerItem()->setTextAlignment(COL_DOWNLOADED, (Qt::AlignRight | Qt::AlignVCenter)); // Set hotkeys - editHotkey = new QShortcut(Qt::Key_F2, this, SLOT(editSelectedTracker()), 0, Qt::WidgetShortcut); + m_editHotkey = new QShortcut(Qt::Key_F2, this, SLOT(editSelectedTracker()), 0, Qt::WidgetShortcut); connect(this, SIGNAL(doubleClicked(QModelIndex)), SLOT(editSelectedTracker())); - deleteHotkey = new QShortcut(QKeySequence::Delete, this, SLOT(deleteSelectedTrackers()), 0, Qt::WidgetShortcut); - copyHotkey = new QShortcut(QKeySequence::Copy, this, SLOT(copyTrackerUrl()), 0, Qt::WidgetShortcut); + m_deleteHotkey = new QShortcut(QKeySequence::Delete, this, SLOT(deleteSelectedTrackers()), 0, Qt::WidgetShortcut); + m_copyHotkey = new QShortcut(QKeySequence::Copy, this, SLOT(copyTrackerUrl()), 0, Qt::WidgetShortcut); // This hack fixes reordering of first column with Qt5. // https://github.com/qtproject/qtbase/commit/e0fc088c0c8bc61dbcaf5928b24986cd61a22777 @@ -152,7 +152,7 @@ void TrackerList::setRowColor(int row, QColor color) { } void TrackerList::moveSelectionUp() { - BitTorrent::TorrentHandle *const torrent = properties->getCurrentTorrent(); + BitTorrent::TorrentHandle *const torrent = m_properties->getCurrentTorrent(); if (!torrent) { clear(); return; @@ -190,7 +190,7 @@ void TrackerList::moveSelectionUp() { } void TrackerList::moveSelectionDown() { - BitTorrent::TorrentHandle *const torrent = properties->getCurrentTorrent(); + BitTorrent::TorrentHandle *const torrent = m_properties->getCurrentTorrent(); if (!torrent) { clear(); return; @@ -229,20 +229,20 @@ void TrackerList::moveSelectionDown() { void TrackerList::clear() { - qDeleteAll(tracker_items.values()); - tracker_items.clear(); - dht_item->setText(COL_STATUS, ""); - dht_item->setText(COL_SEEDS, ""); - dht_item->setText(COL_PEERS, ""); - dht_item->setText(COL_MSG, ""); - pex_item->setText(COL_STATUS, ""); - pex_item->setText(COL_SEEDS, ""); - pex_item->setText(COL_PEERS, ""); - pex_item->setText(COL_MSG, ""); - lsd_item->setText(COL_STATUS, ""); - lsd_item->setText(COL_SEEDS, ""); - lsd_item->setText(COL_PEERS, ""); - lsd_item->setText(COL_MSG, ""); + qDeleteAll(m_trackerItems.values()); + m_trackerItems.clear(); + m_DHTItem->setText(COL_STATUS, ""); + m_DHTItem->setText(COL_SEEDS, ""); + m_DHTItem->setText(COL_PEERS, ""); + m_DHTItem->setText(COL_MSG, ""); + m_PEXItem->setText(COL_STATUS, ""); + m_PEXItem->setText(COL_SEEDS, ""); + m_PEXItem->setText(COL_PEERS, ""); + m_PEXItem->setText(COL_MSG, ""); + m_LSDItem->setText(COL_STATUS, ""); + m_LSDItem->setText(COL_SEEDS, ""); + m_LSDItem->setText(COL_PEERS, ""); + m_LSDItem->setText(COL_MSG, ""); } void TrackerList::loadStickyItems(BitTorrent::TorrentHandle *const torrent) { @@ -251,27 +251,27 @@ void TrackerList::loadStickyItems(BitTorrent::TorrentHandle *const torrent) { // load DHT information if (BitTorrent::Session::instance()->isDHTEnabled() && !torrent->isPrivate()) - dht_item->setText(COL_STATUS, working); + m_DHTItem->setText(COL_STATUS, working); else - dht_item->setText(COL_STATUS, disabled); + m_DHTItem->setText(COL_STATUS, disabled); // Load PeX Information if (BitTorrent::Session::instance()->isPeXEnabled() && !torrent->isPrivate()) - pex_item->setText(COL_STATUS, working); + m_PEXItem->setText(COL_STATUS, working); else - pex_item->setText(COL_STATUS, disabled); + m_PEXItem->setText(COL_STATUS, disabled); // Load LSD Information if (BitTorrent::Session::instance()->isLSDEnabled() && !torrent->isPrivate()) - lsd_item->setText(COL_STATUS, working); + m_LSDItem->setText(COL_STATUS, working); else - lsd_item->setText(COL_STATUS, disabled); + m_LSDItem->setText(COL_STATUS, disabled); if (torrent->isPrivate()) { QString privateMsg = tr("This torrent is private"); - dht_item->setText(COL_MSG, privateMsg); - pex_item->setText(COL_MSG, privateMsg); - lsd_item->setText(COL_MSG, privateMsg); + m_DHTItem->setText(COL_MSG, privateMsg); + m_PEXItem->setText(COL_MSG, privateMsg); + m_LSDItem->setText(COL_MSG, privateMsg); } // XXX: libtorrent should provide this info... @@ -300,31 +300,31 @@ void TrackerList::loadStickyItems(BitTorrent::TorrentHandle *const torrent) { } } - dht_item->setText(COL_SEEDS, QString::number(seedsDHT)); - dht_item->setText(COL_PEERS, QString::number(peersDHT)); - pex_item->setText(COL_SEEDS, QString::number(seedsPeX)); - pex_item->setText(COL_PEERS, QString::number(peersPeX)); - lsd_item->setText(COL_SEEDS, QString::number(seedsLSD)); - lsd_item->setText(COL_PEERS, QString::number(peersLSD)); + m_DHTItem->setText(COL_SEEDS, QString::number(seedsDHT)); + m_DHTItem->setText(COL_PEERS, QString::number(peersDHT)); + m_PEXItem->setText(COL_SEEDS, QString::number(seedsPeX)); + m_PEXItem->setText(COL_PEERS, QString::number(peersPeX)); + m_LSDItem->setText(COL_SEEDS, QString::number(seedsLSD)); + m_LSDItem->setText(COL_PEERS, QString::number(peersLSD)); } void TrackerList::loadTrackers() { // Load trackers from torrent handle - BitTorrent::TorrentHandle *const torrent = properties->getCurrentTorrent(); + BitTorrent::TorrentHandle *const torrent = m_properties->getCurrentTorrent(); if (!torrent) return; loadStickyItems(torrent); // Load actual trackers information QHash trackers_data = torrent->trackerInfos(); - QStringList old_trackers_urls = tracker_items.keys(); + QStringList old_trackers_urls = m_trackerItems.keys(); foreach (const BitTorrent::TrackerEntry &entry, torrent->trackers()) { QString trackerUrl = entry.url(); - QTreeWidgetItem *item = tracker_items.value(trackerUrl, 0); + QTreeWidgetItem *item = m_trackerItems.value(trackerUrl, 0); if (!item) { item = new QTreeWidgetItem(); item->setText(COL_URL, trackerUrl); addTopLevelItem(item); - tracker_items[trackerUrl] = item; + m_trackerItems[trackerUrl] = item; } else { old_trackers_urls.removeOne(trackerUrl); } @@ -369,13 +369,13 @@ void TrackerList::loadTrackers() { } // Remove old trackers foreach (const QString &tracker, old_trackers_urls) { - delete tracker_items.take(tracker); + delete m_trackerItems.take(tracker); } } // Ask the user for new trackers and add them to the torrent void TrackerList::askForTrackers() { - BitTorrent::TorrentHandle *const torrent = properties->getCurrentTorrent(); + BitTorrent::TorrentHandle *const torrent = m_properties->getCurrentTorrent(); if (!torrent) return; QList trackers; @@ -398,7 +398,7 @@ void TrackerList::copyTrackerUrl() { void TrackerList::deleteSelectedTrackers() { - BitTorrent::TorrentHandle *const torrent = properties->getCurrentTorrent(); + BitTorrent::TorrentHandle *const torrent = m_properties->getCurrentTorrent(); if (!torrent) { clear(); return; @@ -411,7 +411,7 @@ void TrackerList::deleteSelectedTrackers() { foreach (QTreeWidgetItem *item, selected_items) { QString tracker_url = item->data(COL_URL, Qt::DisplayRole).toString(); urls_to_remove << tracker_url; - tracker_items.remove(tracker_url); + m_trackerItems.remove(tracker_url); delete item; } @@ -430,7 +430,7 @@ void TrackerList::deleteSelectedTrackers() { } void TrackerList::editSelectedTracker() { - BitTorrent::TorrentHandle *const torrent = properties->getCurrentTorrent(); + BitTorrent::TorrentHandle *const torrent = m_properties->getCurrentTorrent(); if (!torrent) return; QString hash = torrent->hash(); @@ -481,13 +481,13 @@ void TrackerList::reannounceSelected() { QList selected_items = selectedItems(); if (selected_items.isEmpty()) return; - BitTorrent::TorrentHandle *const torrent = properties->getCurrentTorrent(); + BitTorrent::TorrentHandle *const torrent = m_properties->getCurrentTorrent(); if (!torrent) return; QList trackers = torrent->trackers(); foreach (QTreeWidgetItem* item, selected_items) { // DHT case - if (item == dht_item) { + if (item == m_DHTItem) { torrent->forceDHTAnnounce(); continue; } @@ -505,7 +505,7 @@ void TrackerList::reannounceSelected() { } void TrackerList::showTrackerListMenu(QPoint) { - BitTorrent::TorrentHandle *const torrent = properties->getCurrentTorrent(); + BitTorrent::TorrentHandle *const torrent = m_properties->getCurrentTorrent(); if (!torrent) return; //QList selected_items = getSelectedTrackerItems(); QMenu menu; @@ -545,7 +545,7 @@ void TrackerList::showTrackerListMenu(QPoint) { return; } if (act == reannounceAct) { - BitTorrent::TorrentHandle *h = properties->getCurrentTorrent(); + BitTorrent::TorrentHandle *h = m_properties->getCurrentTorrent(); h->forceReannounce(); h->forceDHTAnnounce(); return; diff --git a/src/gui/properties/trackerlist.h b/src/gui/properties/trackerlist.h index 6190aaa3e..b8ba05eec 100644 --- a/src/gui/properties/trackerlist.h +++ b/src/gui/properties/trackerlist.h @@ -93,14 +93,14 @@ protected: QList getSelectedTrackerItems() const; private: - PropertiesWidget *properties; - QHash tracker_items; - QTreeWidgetItem *dht_item; - QTreeWidgetItem *pex_item; - QTreeWidgetItem *lsd_item; - QShortcut *editHotkey; - QShortcut *deleteHotkey; - QShortcut *copyHotkey; + PropertiesWidget *m_properties; + QHash m_trackerItems; + QTreeWidgetItem *m_DHTItem; + QTreeWidgetItem *m_PEXItem; + QTreeWidgetItem *m_LSDItem; + QShortcut *m_editHotkey; + QShortcut *m_deleteHotkey; + QShortcut *m_copyHotkey; static QStringList headerLabels(); };