Browse Source

Clean up code related to show/hide columns

adaptive-webui-19844
Chocobo1 3 years ago
parent
commit
208234b934
No known key found for this signature in database
GPG Key ID: 210D9C873253A68C
  1. 1
      src/gui/addnewtorrentdialog.h
  2. 2
      src/gui/previewselectdialog.cpp
  3. 54
      src/gui/properties/peerlistwidget.cpp
  4. 3
      src/gui/properties/peerlistwidget.h
  5. 21
      src/gui/properties/propertieswidget.cpp
  6. 2
      src/gui/properties/propertieswidget.h
  7. 42
      src/gui/properties/trackerlistwidget.cpp
  8. 8
      src/gui/properties/trackerlistwidget.h
  9. 56
      src/gui/search/searchjobwidget.cpp
  10. 5
      src/gui/search/searchjobwidget.h
  11. 58
      src/gui/transferlistwidget.cpp
  12. 3
      src/gui/transferlistwidget.h

1
src/gui/addnewtorrentdialog.h

@ -79,6 +79,7 @@ public:
private slots: private slots:
void displayContentTreeMenu(const QPoint &); void displayContentTreeMenu(const QPoint &);
void displayColumnHeaderMenu();
void updateDiskSpaceLabel(); void updateDiskSpaceLabel();
void onSavePathChanged(const QString &newPath); void onSavePathChanged(const QString &newPath);
void onDownloadPathChanged(const QString &newPath); void onDownloadPathChanged(const QString &newPath);

2
src/gui/previewselectdialog.cpp

@ -82,11 +82,11 @@ PreviewSelectDialog::PreviewSelectDialog(QWidget *parent, const BitTorrent::Torr
m_ui->previewList->header()->setParent(m_ui->previewList); m_ui->previewList->header()->setParent(m_ui->previewList);
unused.setVerticalHeader(new QHeaderView(Qt::Horizontal)); unused.setVerticalHeader(new QHeaderView(Qt::Horizontal));
m_ui->previewList->setAlternatingRowColors(pref->useAlternatingRowColors());
m_ui->previewList->setModel(m_previewListModel); m_ui->previewList->setModel(m_previewListModel);
m_ui->previewList->hideColumn(FILE_INDEX); m_ui->previewList->hideColumn(FILE_INDEX);
m_listDelegate = new PreviewListDelegate(this); m_listDelegate = new PreviewListDelegate(this);
m_ui->previewList->setItemDelegate(m_listDelegate); m_ui->previewList->setItemDelegate(m_listDelegate);
m_ui->previewList->setAlternatingRowColors(pref->useAlternatingRowColors());
// Fill list in // Fill list in
const QVector<qreal> fp = torrent->filesProgress(); const QVector<qreal> fp = torrent->filesProgress();
for (int i = 0; i < torrent->filesCount(); ++i) for (int i = 0; i < torrent->filesCount(); ++i)

54
src/gui/properties/peerlistwidget.cpp

@ -155,7 +155,7 @@ PeerListWidget::PeerListWidget(PropertiesWidget *parent)
updatePeerHostNameResolutionState(); updatePeerHostNameResolutionState();
// SIGNAL/SLOT // SIGNAL/SLOT
header()->setContextMenuPolicy(Qt::CustomContextMenu); header()->setContextMenuPolicy(Qt::CustomContextMenu);
connect(header(), &QWidget::customContextMenuRequested, this, &PeerListWidget::displayToggleColumnsMenu); connect(header(), &QWidget::customContextMenuRequested, this, &PeerListWidget::displayColumnHeaderMenu);
connect(header(), &QHeaderView::sectionClicked, this, &PeerListWidget::handleSortColumnChanged); connect(header(), &QHeaderView::sectionClicked, this, &PeerListWidget::handleSortColumnChanged);
connect(header(), &QHeaderView::sectionMoved, this, &PeerListWidget::saveSettings); connect(header(), &QHeaderView::sectionMoved, this, &PeerListWidget::saveSettings);
connect(header(), &QHeaderView::sectionResized, this, &PeerListWidget::saveSettings); connect(header(), &QHeaderView::sectionResized, this, &PeerListWidget::saveSettings);
@ -177,7 +177,7 @@ PeerListWidget::~PeerListWidget()
saveSettings(); saveSettings();
} }
void PeerListWidget::displayToggleColumnsMenu(const QPoint &) void PeerListWidget::displayColumnHeaderMenu()
{ {
QMenu *menu = new QMenu(this); QMenu *menu = new QMenu(this);
menu->setAttribute(Qt::WA_DeleteOnClose); menu->setAttribute(Qt::WA_DeleteOnClose);
@ -188,36 +188,22 @@ void PeerListWidget::displayToggleColumnsMenu(const QPoint &)
if ((i == PeerListColumns::COUNTRY) && !Preferences::instance()->resolvePeerCountries()) if ((i == PeerListColumns::COUNTRY) && !Preferences::instance()->resolvePeerCountries())
continue; continue;
QAction *myAct = menu->addAction(m_listModel->headerData(i, Qt::Horizontal, Qt::DisplayRole).toString()); const auto columnName = m_listModel->headerData(i, Qt::Horizontal, Qt::DisplayRole).toString();
myAct->setCheckable(true); QAction *action = menu->addAction(columnName, this, [this, i](const bool checked)
myAct->setChecked(!isColumnHidden(i));
myAct->setData(i);
}
connect(menu, &QMenu::triggered, this, [this](const QAction *action)
{
int visibleCols = 0;
for (int i = 0; i < PeerListColumns::IP_HIDDEN; ++i)
{ {
if (!isColumnHidden(i)) if (!checked && (visibleColumnsCount() <= 1))
++visibleCols; return;
if (visibleCols > 1)
break;
}
const int col = action->data().toInt(); setColumnHidden(i, !checked);
if (!isColumnHidden(col) && (visibleCols == 1)) if (checked && (columnWidth(i) <= 5))
return; resizeColumnToContents(i);
setColumnHidden(col, !isColumnHidden(col)); saveSettings();
});
if (!isColumnHidden(col) && (columnWidth(col) <= 5)) action->setCheckable(true);
resizeColumnToContents(col); action->setChecked(!isColumnHidden(i));
}
saveSettings();
});
menu->popup(QCursor::pos()); menu->popup(QCursor::pos());
} }
@ -492,6 +478,18 @@ void PeerListWidget::updatePeer(const BitTorrent::Torrent *torrent, const BitTor
} }
} }
int PeerListWidget::visibleColumnsCount() const
{
int count = 0;
for (int i = 0, iMax = header()->count(); i < iMax; ++i)
{
if (!isColumnHidden(i))
++count;
}
return count;
}
void PeerListWidget::handleResolved(const QHostAddress &ip, const QString &hostname) const void PeerListWidget::handleResolved(const QHostAddress &ip, const QString &hostname) const
{ {
if (hostname.isEmpty()) if (hostname.isEmpty())

3
src/gui/properties/peerlistwidget.h

@ -88,7 +88,7 @@ public:
private slots: private slots:
void loadSettings(); void loadSettings();
void saveSettings() const; void saveSettings() const;
void displayToggleColumnsMenu(const QPoint &); void displayColumnHeaderMenu();
void showPeerListMenu(const QPoint &); void showPeerListMenu(const QPoint &);
void banSelectedPeers(); void banSelectedPeers();
void copySelectedPeers(); void copySelectedPeers();
@ -97,6 +97,7 @@ private slots:
private: private:
void updatePeer(const BitTorrent::Torrent *torrent, const BitTorrent::PeerInfo &peer, bool &isNewPeer); void updatePeer(const BitTorrent::Torrent *torrent, const BitTorrent::PeerInfo &peer, bool &isNewPeer);
int visibleColumnsCount() const;
void wheelEvent(QWheelEvent *event) override; void wheelEvent(QWheelEvent *event) override;

21
src/gui/properties/propertieswidget.cpp

@ -111,7 +111,7 @@ PropertiesWidget::PropertiesWidget(QWidget *parent)
, m_ui->filesList, qOverload<const QModelIndex &>(&QAbstractItemView::edit)); , m_ui->filesList, qOverload<const QModelIndex &>(&QAbstractItemView::edit));
connect(m_ui->filesList, &QWidget::customContextMenuRequested, this, &PropertiesWidget::displayFilesListMenu); connect(m_ui->filesList, &QWidget::customContextMenuRequested, this, &PropertiesWidget::displayFilesListMenu);
connect(m_ui->filesList, &QAbstractItemView::doubleClicked, this, &PropertiesWidget::openItem); connect(m_ui->filesList, &QAbstractItemView::doubleClicked, this, &PropertiesWidget::openItem);
connect(m_ui->filesList->header(), &QWidget::customContextMenuRequested, this, &PropertiesWidget::displayFileListHeaderMenu); connect(m_ui->filesList->header(), &QWidget::customContextMenuRequested, this, &PropertiesWidget::displayColumnHeaderMenu);
connect(m_ui->filesList->header(), &QHeaderView::sectionMoved, this, &PropertiesWidget::saveSettings); connect(m_ui->filesList->header(), &QHeaderView::sectionMoved, this, &PropertiesWidget::saveSettings);
connect(m_ui->filesList->header(), &QHeaderView::sectionResized, this, &PropertiesWidget::saveSettings); connect(m_ui->filesList->header(), &QHeaderView::sectionResized, this, &PropertiesWidget::saveSettings);
connect(m_ui->filesList->header(), &QHeaderView::sortIndicatorChanged, this, &PropertiesWidget::saveSettings); connect(m_ui->filesList->header(), &QHeaderView::sortIndicatorChanged, this, &PropertiesWidget::saveSettings);
@ -177,28 +177,29 @@ PropertiesWidget::~PropertiesWidget()
delete m_ui; delete m_ui;
} }
void PropertiesWidget::displayFileListHeaderMenu() void PropertiesWidget::displayColumnHeaderMenu()
{ {
QMenu *menu = new QMenu(this); QMenu *menu = new QMenu(this);
menu->setAttribute(Qt::WA_DeleteOnClose); menu->setAttribute(Qt::WA_DeleteOnClose);
menu->setTitle(tr("Column visibility"));
for (int i = 0; i < TorrentContentModelItem::TreeItemColumns::NB_COL; ++i) for (int i = 0; i < TorrentContentModelItem::TreeItemColumns::NB_COL; ++i)
{ {
QAction *myAct = menu->addAction(m_propListModel->headerData(i, Qt::Horizontal, Qt::DisplayRole).toString()); const auto columnName = m_propListModel->headerData(i, Qt::Horizontal, Qt::DisplayRole).toString();
myAct->setCheckable(true); QAction *action = menu->addAction(columnName, this, [this, i](const bool checked)
myAct->setChecked(!m_ui->filesList->isColumnHidden(i));
if (i == TorrentContentModelItem::TreeItemColumns::COL_NAME)
myAct->setEnabled(false);
connect(myAct, &QAction::toggled, this, [this, i](const bool checked)
{ {
m_ui->filesList->setColumnHidden(i, !checked); m_ui->filesList->setColumnHidden(i, !checked);
if (!m_ui->filesList->isColumnHidden(i) && (m_ui->filesList->columnWidth(i) <= 5)) if (checked && (m_ui->filesList->columnWidth(i) <= 5))
m_ui->filesList->resizeColumnToContents(i); m_ui->filesList->resizeColumnToContents(i);
saveSettings(); saveSettings();
}); });
action->setCheckable(true);
action->setChecked(!m_ui->filesList->isColumnHidden(i));
if (i == TorrentContentModelItem::TreeItemColumns::COL_NAME)
action->setEnabled(false);
} }
menu->popup(QCursor::pos()); menu->popup(QCursor::pos());

2
src/gui/properties/propertieswidget.h

@ -81,7 +81,6 @@ public slots:
void readSettings(); void readSettings();
void saveSettings(); void saveSettings();
void reloadPreferences(); void reloadPreferences();
void displayFileListHeaderMenu();
void openItem(const QModelIndex &index) const; void openItem(const QModelIndex &index) const;
void loadTrackers(BitTorrent::Torrent *const torrent); void loadTrackers(BitTorrent::Torrent *const torrent);
@ -101,6 +100,7 @@ protected slots:
private slots: private slots:
void configure(); void configure();
void displayColumnHeaderMenu();
void filterText(const QString &filter); void filterText(const QString &filter);
void updateSavePath(BitTorrent::Torrent *const torrent); void updateSavePath(BitTorrent::Torrent *const torrent);

42
src/gui/properties/trackerlistwidget.cpp

@ -86,7 +86,7 @@ TrackerListWidget::TrackerListWidget(PropertiesWidget *properties)
connect(this, &QWidget::customContextMenuRequested, this, &TrackerListWidget::showTrackerListMenu); connect(this, &QWidget::customContextMenuRequested, this, &TrackerListWidget::showTrackerListMenu);
// Header // Header
header()->setContextMenuPolicy(Qt::CustomContextMenu); header()->setContextMenuPolicy(Qt::CustomContextMenu);
connect(header(), &QWidget::customContextMenuRequested, this, &TrackerListWidget::displayToggleColumnsMenu); connect(header(), &QWidget::customContextMenuRequested, this, &TrackerListWidget::displayColumnHeaderMenu);
connect(header(), &QHeaderView::sectionMoved, this, &TrackerListWidget::saveSettings); connect(header(), &QHeaderView::sectionMoved, this, &TrackerListWidget::saveSettings);
connect(header(), &QHeaderView::sectionResized, this, &TrackerListWidget::saveSettings); connect(header(), &QHeaderView::sectionResized, this, &TrackerListWidget::saveSettings);
connect(header(), &QHeaderView::sortIndicatorChanged, this, &TrackerListWidget::saveSettings); connect(header(), &QHeaderView::sortIndicatorChanged, this, &TrackerListWidget::saveSettings);
@ -641,17 +641,17 @@ QStringList TrackerListWidget::headerLabels()
int TrackerListWidget::visibleColumnsCount() const int TrackerListWidget::visibleColumnsCount() const
{ {
int visibleCols = 0; int count = 0;
for (int i = 0; i < COL_COUNT; ++i) for (int i = 0, iMax = header()->count(); i < iMax; ++i)
{ {
if (!isColumnHidden(i)) if (!isColumnHidden(i))
++visibleCols; ++count;
} }
return visibleCols; return count;
} }
void TrackerListWidget::displayToggleColumnsMenu(const QPoint &) void TrackerListWidget::displayColumnHeaderMenu()
{ {
QMenu *menu = new QMenu(this); QMenu *menu = new QMenu(this);
menu->setAttribute(Qt::WA_DeleteOnClose); menu->setAttribute(Qt::WA_DeleteOnClose);
@ -659,27 +659,21 @@ void TrackerListWidget::displayToggleColumnsMenu(const QPoint &)
for (int i = 0; i < COL_COUNT; ++i) for (int i = 0; i < COL_COUNT; ++i)
{ {
QAction *myAct = menu->addAction(headerLabels().at(i)); QAction *action = menu->addAction(headerLabels().at(i), this, [this, i](const bool checked)
myAct->setCheckable(true); {
myAct->setChecked(!isColumnHidden(i)); if (!checked && (visibleColumnsCount() <= 1))
myAct->setData(i); return;
}
connect(menu, &QMenu::triggered, this, [this](const QAction *action)
{
const int col = action->data().toInt();
Q_ASSERT(visibleColumnsCount() > 0);
if (!isColumnHidden(col) && (visibleColumnsCount() == 1))
return;
setColumnHidden(col, !isColumnHidden(col)); setColumnHidden(i, !checked);
if (!isColumnHidden(col) && (columnWidth(col) <= 5)) if (checked && (columnWidth(i) <= 5))
resizeColumnToContents(col); resizeColumnToContents(i);
saveSettings(); saveSettings();
}); });
action->setCheckable(true);
action->setChecked(!isColumnHidden(i));
}
menu->popup(QCursor::pos()); menu->popup(QCursor::pos());
} }

8
src/gui/properties/trackerlistwidget.h

@ -61,8 +61,6 @@ public:
explicit TrackerListWidget(PropertiesWidget *properties); explicit TrackerListWidget(PropertiesWidget *properties);
~TrackerListWidget(); ~TrackerListWidget();
int visibleColumnsCount() const;
public slots: public slots:
void setRowColor(int row, const QColor &color); void setRowColor(int row, const QColor &color);
@ -78,14 +76,18 @@ public slots:
void deleteSelectedTrackers(); void deleteSelectedTrackers();
void editSelectedTracker(); void editSelectedTracker();
void showTrackerListMenu(const QPoint &); void showTrackerListMenu(const QPoint &);
void displayToggleColumnsMenu(const QPoint &);
void loadSettings(); void loadSettings();
void saveSettings() const; void saveSettings() const;
protected: protected:
QVector<QTreeWidgetItem *> getSelectedTrackerItems() const; QVector<QTreeWidgetItem *> getSelectedTrackerItems() const;
private slots:
void displayColumnHeaderMenu();
private: private:
int visibleColumnsCount() const;
static QStringList headerLabels(); static QStringList headerLabels();
PropertiesWidget *m_properties; PropertiesWidget *m_properties;

56
src/gui/search/searchjobwidget.cpp

@ -116,11 +116,13 @@ SearchJobWidget::SearchJobWidget(SearchHandler *searchHandler, QWidget *parent)
// its size is 0, because explicitly 'showing' the column isn't enough // its size is 0, because explicitly 'showing' the column isn't enough
// in the above scenario. // in the above scenario.
for (int i = 0; i < SearchSortModel::DL_LINK; ++i) for (int i = 0; i < SearchSortModel::DL_LINK; ++i)
{
if ((m_ui->resultsBrowser->columnWidth(i) <= 0) && !m_ui->resultsBrowser->isColumnHidden(i)) if ((m_ui->resultsBrowser->columnWidth(i) <= 0) && !m_ui->resultsBrowser->isColumnHidden(i))
m_ui->resultsBrowser->resizeColumnToContents(i); m_ui->resultsBrowser->resizeColumnToContents(i);
}
header()->setContextMenuPolicy(Qt::CustomContextMenu); header()->setContextMenuPolicy(Qt::CustomContextMenu);
connect(header(), &QWidget::customContextMenuRequested, this, &SearchJobWidget::displayToggleColumnsMenu); connect(header(), &QWidget::customContextMenuRequested, this, &SearchJobWidget::displayColumnHeaderMenu);
connect(header(), &QHeaderView::sectionResized, this, &SearchJobWidget::saveSettings); connect(header(), &QHeaderView::sectionResized, this, &SearchJobWidget::saveSettings);
connect(header(), &QHeaderView::sectionMoved, this, &SearchJobWidget::saveSettings); connect(header(), &QHeaderView::sectionMoved, this, &SearchJobWidget::saveSettings);
connect(header(), &QHeaderView::sortIndicatorChanged, this, &SearchJobWidget::saveSettings); connect(header(), &QHeaderView::sortIndicatorChanged, this, &SearchJobWidget::saveSettings);
@ -450,7 +452,19 @@ void SearchJobWidget::saveSettings() const
Preferences::instance()->setSearchTabHeaderState(header()->saveState()); Preferences::instance()->setSearchTabHeaderState(header()->saveState());
} }
void SearchJobWidget::displayToggleColumnsMenu(const QPoint &) int SearchJobWidget::visibleColumnsCount() const
{
int count = 0;
for (int i = 0, iMax = m_ui->resultsBrowser->header()->count(); i < iMax; ++i)
{
if (!m_ui->resultsBrowser->isColumnHidden(i))
++count;
}
return count;
}
void SearchJobWidget::displayColumnHeaderMenu()
{ {
auto menu = new QMenu(this); auto menu = new QMenu(this);
menu->setAttribute(Qt::WA_DeleteOnClose); menu->setAttribute(Qt::WA_DeleteOnClose);
@ -458,36 +472,22 @@ void SearchJobWidget::displayToggleColumnsMenu(const QPoint &)
for (int i = 0; i < SearchSortModel::DL_LINK; ++i) for (int i = 0; i < SearchSortModel::DL_LINK; ++i)
{ {
QAction *myAct = menu->addAction(m_searchListModel->headerData(i, Qt::Horizontal, Qt::DisplayRole).toString()); const auto columnName = m_searchListModel->headerData(i, Qt::Horizontal, Qt::DisplayRole).toString();
myAct->setCheckable(true); QAction *action = menu->addAction(columnName, this, [this, i](const bool checked)
myAct->setChecked(!m_ui->resultsBrowser->isColumnHidden(i));
myAct->setData(i);
}
connect(menu, &QMenu::triggered, this, [this](const QAction *action)
{
int visibleCols = 0;
for (int i = 0; i < SearchSortModel::DL_LINK; ++i)
{ {
if (!m_ui->resultsBrowser->isColumnHidden(i)) if (!checked && (visibleColumnsCount() <= 1))
++visibleCols; return;
if (visibleCols > 1)
break;
}
const int col = action->data().toInt();
if ((!m_ui->resultsBrowser->isColumnHidden(col)) && (visibleCols == 1)) m_ui->resultsBrowser->setColumnHidden(i, !checked);
return;
m_ui->resultsBrowser->setColumnHidden(col, !m_ui->resultsBrowser->isColumnHidden(col)); if (checked && (m_ui->resultsBrowser->columnWidth(i) <= 5))
m_ui->resultsBrowser->resizeColumnToContents(i);
if ((!m_ui->resultsBrowser->isColumnHidden(col)) && (m_ui->resultsBrowser->columnWidth(col) <= 5)) saveSettings();
m_ui->resultsBrowser->resizeColumnToContents(col); });
action->setCheckable(true);
saveSettings(); action->setChecked(!m_ui->resultsBrowser->isColumnHidden(i));
}); }
menu->popup(QCursor::pos()); menu->popup(QCursor::pos());
} }

5
src/gui/search/searchjobwidget.h

@ -88,6 +88,9 @@ signals:
protected: protected:
void keyPressEvent(QKeyEvent *event) override; void keyPressEvent(QKeyEvent *event) override;
private slots:
void displayColumnHeaderMenu();
private: private:
enum class AddTorrentOption enum class AddTorrentOption
{ {
@ -102,7 +105,6 @@ private:
void filterSearchResults(const QString &name); void filterSearchResults(const QString &name);
void showFilterContextMenu(const QPoint &); void showFilterContextMenu(const QPoint &);
void contextMenuEvent(QContextMenuEvent *event) override; void contextMenuEvent(QContextMenuEvent *event) override;
void displayToggleColumnsMenu(const QPoint &);
void onItemDoubleClicked(const QModelIndex &index); void onItemDoubleClicked(const QModelIndex &index);
void searchFinished(bool cancelled); void searchFinished(bool cancelled);
void searchFailed(); void searchFailed();
@ -115,6 +117,7 @@ private:
NameFilteringMode filteringMode() const; NameFilteringMode filteringMode() const;
QHeaderView *header() const; QHeaderView *header() const;
void setRowColor(int row, const QColor &color); void setRowColor(int row, const QColor &color);
int visibleColumnsCount() const;
void downloadTorrents(AddTorrentOption option = AddTorrentOption::Default); void downloadTorrents(AddTorrentOption option = AddTorrentOption::Default);
void openTorrentPages() const; void openTorrentPages() const;

58
src/gui/transferlistwidget.cpp

@ -195,8 +195,10 @@ TransferListWidget::TransferListWidget(QWidget *parent, MainWindow *mainWindow)
//end up being size 0 when the new version is launched with //end up being size 0 when the new version is launched with
//a conf file from the previous version. //a conf file from the previous version.
for (int i = 0; i < TransferListModel::NB_COLUMNS; ++i) for (int i = 0; i < TransferListModel::NB_COLUMNS; ++i)
{
if ((columnWidth(i) <= 0) && (!isColumnHidden(i))) if ((columnWidth(i) <= 0) && (!isColumnHidden(i)))
resizeColumnToContents(i); resizeColumnToContents(i);
}
setContextMenuPolicy(Qt::CustomContextMenu); setContextMenuPolicy(Qt::CustomContextMenu);
@ -204,7 +206,7 @@ TransferListWidget::TransferListWidget(QWidget *parent, MainWindow *mainWindow)
connect(this, &QAbstractItemView::doubleClicked, this, &TransferListWidget::torrentDoubleClicked); connect(this, &QAbstractItemView::doubleClicked, this, &TransferListWidget::torrentDoubleClicked);
connect(this, &QWidget::customContextMenuRequested, this, &TransferListWidget::displayListMenu); connect(this, &QWidget::customContextMenuRequested, this, &TransferListWidget::displayListMenu);
header()->setContextMenuPolicy(Qt::CustomContextMenu); header()->setContextMenuPolicy(Qt::CustomContextMenu);
connect(header(), &QWidget::customContextMenuRequested, this, &TransferListWidget::displayDLHoSMenu); connect(header(), &QWidget::customContextMenuRequested, this, &TransferListWidget::displayColumnHeaderMenu);
connect(header(), &QHeaderView::sectionMoved, this, &TransferListWidget::saveSettings); connect(header(), &QHeaderView::sectionMoved, this, &TransferListWidget::saveSettings);
connect(header(), &QHeaderView::sectionResized, this, &TransferListWidget::saveSettings); connect(header(), &QHeaderView::sectionResized, this, &TransferListWidget::saveSettings);
connect(header(), &QHeaderView::sortIndicatorChanged, this, &TransferListWidget::saveSettings); connect(header(), &QHeaderView::sortIndicatorChanged, this, &TransferListWidget::saveSettings);
@ -623,48 +625,46 @@ void TransferListWidget::reannounceSelectedTorrents()
torrent->forceReannounce(); torrent->forceReannounce();
} }
int TransferListWidget::visibleColumnsCount() const
{
int count = 0;
for (int i = 0, iMax = header()->count(); i < iMax; ++i)
{
if (!isColumnHidden(i))
++count;
}
return count;
}
// hide/show columns menu // hide/show columns menu
void TransferListWidget::displayDLHoSMenu(const QPoint&) void TransferListWidget::displayColumnHeaderMenu()
{ {
auto menu = new QMenu(this); auto menu = new QMenu(this);
menu->setAttribute(Qt::WA_DeleteOnClose); menu->setAttribute(Qt::WA_DeleteOnClose);
menu->setTitle(tr("Column visibility")); menu->setTitle(tr("Column visibility"));
for (int i = 0; i < m_listModel->columnCount(); ++i) for (int i = 0; i < TransferListModel::NB_COLUMNS; ++i)
{ {
if (!BitTorrent::Session::instance()->isQueueingSystemEnabled() && (i == TransferListModel::TR_QUEUE_POSITION)) if (!BitTorrent::Session::instance()->isQueueingSystemEnabled() && (i == TransferListModel::TR_QUEUE_POSITION))
continue; continue;
QAction *myAct = menu->addAction(m_listModel->headerData(i, Qt::Horizontal, Qt::DisplayRole).toString()); const auto columnName = m_listModel->headerData(i, Qt::Horizontal, Qt::DisplayRole).toString();
myAct->setCheckable(true); QAction *action = menu->addAction(columnName, this, [this, i](const bool checked)
myAct->setChecked(!isColumnHidden(i));
myAct->setData(i);
}
connect(menu, &QMenu::triggered, this, [this](const QAction *action)
{
int visibleCols = 0;
for (int i = 0; i < TransferListModel::NB_COLUMNS; ++i)
{ {
if (!isColumnHidden(i)) if (!checked && (visibleColumnsCount() <= 1))
++visibleCols; return;
if (visibleCols > 1)
break;
}
const int col = action->data().toInt();
if (!isColumnHidden(col) && visibleCols == 1) setColumnHidden(i, !checked);
return;
setColumnHidden(col, !isColumnHidden(col));
if (!isColumnHidden(col) && columnWidth(col) <= 5) if (checked && (columnWidth(i) <= 5))
resizeColumnToContents(col); resizeColumnToContents(i);
saveSettings(); saveSettings();
}); });
action->setCheckable(true);
action->setChecked(!isColumnHidden(i));
}
menu->popup(QCursor::pos()); menu->popup(QCursor::pos());
} }

3
src/gui/transferlistwidget.h

@ -91,7 +91,6 @@ public slots:
void setTorrentOptions(); void setTorrentOptions();
void previewSelectedTorrents(); void previewSelectedTorrents();
void hideQueuePosColumn(bool hide); void hideQueuePosColumn(bool hide);
void displayDLHoSMenu(const QPoint &);
void applyNameFilter(const QString &name); void applyNameFilter(const QString &name);
void applyStatusFilter(int f); void applyStatusFilter(int f);
void applyCategoryFilter(const QString &category); void applyCategoryFilter(const QString &category);
@ -107,6 +106,7 @@ signals:
private slots: private slots:
void torrentDoubleClicked(); void torrentDoubleClicked();
void displayListMenu(const QPoint &); void displayListMenu(const QPoint &);
void displayColumnHeaderMenu();
void currentChanged(const QModelIndex &current, const QModelIndex&) override; void currentChanged(const QModelIndex &current, const QModelIndex&) override;
void setSelectedTorrentsSuperSeeding(bool enabled) const; void setSelectedTorrentsSuperSeeding(bool enabled) const;
void setSelectedTorrentsSequentialDownload(bool enabled) const; void setSelectedTorrentsSequentialDownload(bool enabled) const;
@ -127,6 +127,7 @@ private:
QStringList askTagsForSelection(const QString &dialogTitle); QStringList askTagsForSelection(const QString &dialogTitle);
void applyToSelectedTorrents(const std::function<void (BitTorrent::Torrent *const)> &fn); void applyToSelectedTorrents(const std::function<void (BitTorrent::Torrent *const)> &fn);
QVector<BitTorrent::Torrent *> getVisibleTorrents() const; QVector<BitTorrent::Torrent *> getVisibleTorrents() const;
int visibleColumnsCount() const;
TransferListModel *m_listModel; TransferListModel *m_listModel;
TransferListSortModel *m_sortFilterModel; TransferListSortModel *m_sortFilterModel;

Loading…
Cancel
Save