qBittorrent/src/gui/properties/peerlistwidget.cpp

495 lines
20 KiB
C++
Raw Normal View History

2009-11-14 13:37:45 +03:00
/*
* Bittorrent Client using Qt and libtorrent.
* Copyright (C) 2006 Christophe Dumez <chris@qbittorrent.org>
2009-11-14 13:37:45 +03:00
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* In addition, as a special exception, the copyright holders give permission to
* link this program with the OpenSSL project's "OpenSSL" library (or with
* modified versions of it that use the same license as the "OpenSSL" library),
* and distribute the linked executables. You must obey the GNU General Public
* License in all respects for all of the code used other than "OpenSSL". If you
* modify file(s), you may extend this exception to your version of the file(s),
* but you are not obligated to do so. If you do not wish to do so, delete this
* exception statement from your version.
*/
#include "peerlistwidget.h"
#include <algorithm>
#include <QApplication>
#include <QClipboard>
2015-06-02 12:09:15 +03:00
#include <QHeaderView>
#include <QHostAddress>
2015-06-02 12:09:15 +03:00
#include <QMenu>
#include <QMessageBox>
#include <QSet>
#include <QShortcut>
#include <QSortFilterProxyModel>
#include <QStandardItemModel>
#include <QTableView>
#include <QVector>
#include <QWheelEvent>
2015-06-02 12:09:15 +03:00
#include "base/bittorrent/peeraddress.h"
2015-09-25 11:10:05 +03:00
#include "base/bittorrent/peerinfo.h"
2018-11-02 08:45:16 +03:00
#include "base/bittorrent/session.h"
#include "base/bittorrent/torrenthandle.h"
2019-08-23 12:04:55 +03:00
#include "base/global.h"
2015-09-25 11:10:05 +03:00
#include "base/logger.h"
#include "base/net/geoipmanager.h"
#include "base/net/reverseresolution.h"
#include "base/preferences.h"
#include "base/utils/misc.h"
#include "base/utils/string.h"
2020-04-30 10:53:43 +03:00
#include "gui/uithememanager.h"
2015-06-02 12:09:15 +03:00
#include "peerlistsortmodel.h"
#include "peersadditiondialog.h"
#include "propertieswidget.h"
struct PeerEndpoint
{
BitTorrent::PeerAddress address;
QString connectionType; // matches return type of `PeerInfo::connectionType()`
};
bool operator==(const PeerEndpoint &left, const PeerEndpoint &right)
{
return (left.address == right.address) && (left.connectionType == right.connectionType);
}
uint qHash(const PeerEndpoint &peerEndpoint, const uint seed)
{
return (qHash(peerEndpoint.address, seed) ^ ::qHash(peerEndpoint.connectionType));
}
PeerListWidget::PeerListWidget(PropertiesWidget *parent)
: QTreeView(parent)
, m_properties(parent)
2012-02-25 23:02:19 +04:00
{
// Load settings
loadSettings();
// Visual settings
setUniformRowHeights(true);
setRootIsDecorated(false);
setItemsExpandable(false);
setAllColumnsShowFocus(true);
2020-07-30 09:20:25 +03:00
setEditTriggers(QAbstractItemView::NoEditTriggers);
setSelectionMode(QAbstractItemView::ExtendedSelection);
2016-02-07 20:46:56 +03:00
header()->setStretchLastSection(false);
// List Model
m_listModel = new QStandardItemModel(0, PeerListColumns::COL_COUNT, this);
m_listModel->setHeaderData(PeerListColumns::COUNTRY, Qt::Horizontal, tr("Country/Region")); // Country flag column
m_listModel->setHeaderData(PeerListColumns::IP, Qt::Horizontal, tr("IP"));
m_listModel->setHeaderData(PeerListColumns::PORT, Qt::Horizontal, tr("Port"));
m_listModel->setHeaderData(PeerListColumns::FLAGS, Qt::Horizontal, tr("Flags"));
m_listModel->setHeaderData(PeerListColumns::CONNECTION, Qt::Horizontal, tr("Connection"));
m_listModel->setHeaderData(PeerListColumns::CLIENT, Qt::Horizontal, tr("Client", "i.e.: Client application"));
m_listModel->setHeaderData(PeerListColumns::PROGRESS, Qt::Horizontal, tr("Progress", "i.e: % downloaded"));
m_listModel->setHeaderData(PeerListColumns::DOWN_SPEED, Qt::Horizontal, tr("Down Speed", "i.e: Download speed"));
m_listModel->setHeaderData(PeerListColumns::UP_SPEED, Qt::Horizontal, tr("Up Speed", "i.e: Upload speed"));
m_listModel->setHeaderData(PeerListColumns::TOT_DOWN, Qt::Horizontal, tr("Downloaded", "i.e: total data downloaded"));
m_listModel->setHeaderData(PeerListColumns::TOT_UP, Qt::Horizontal, tr("Uploaded", "i.e: total data uploaded"));
m_listModel->setHeaderData(PeerListColumns::RELEVANCE, Qt::Horizontal, tr("Relevance", "i.e: How relevant this peer is to us. How many pieces it has that we don't."));
m_listModel->setHeaderData(PeerListColumns::DOWNLOADING_PIECE, Qt::Horizontal, tr("Files", "i.e. files that are being downloaded right now"));
// Set header text alignment
m_listModel->setHeaderData(PeerListColumns::PORT, Qt::Horizontal, QVariant(Qt::AlignRight | Qt::AlignVCenter), Qt::TextAlignmentRole);
m_listModel->setHeaderData(PeerListColumns::PROGRESS, Qt::Horizontal, QVariant(Qt::AlignRight | Qt::AlignVCenter), Qt::TextAlignmentRole);
m_listModel->setHeaderData(PeerListColumns::DOWN_SPEED, Qt::Horizontal, QVariant(Qt::AlignRight | Qt::AlignVCenter), Qt::TextAlignmentRole);
m_listModel->setHeaderData(PeerListColumns::UP_SPEED, Qt::Horizontal, QVariant(Qt::AlignRight | Qt::AlignVCenter), Qt::TextAlignmentRole);
m_listModel->setHeaderData(PeerListColumns::TOT_DOWN, Qt::Horizontal, QVariant(Qt::AlignRight | Qt::AlignVCenter), Qt::TextAlignmentRole);
m_listModel->setHeaderData(PeerListColumns::TOT_UP, Qt::Horizontal, QVariant(Qt::AlignRight | Qt::AlignVCenter), Qt::TextAlignmentRole);
m_listModel->setHeaderData(PeerListColumns::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(this);
m_proxyModel->setDynamicSortFilter(true);
m_proxyModel->setSourceModel(m_listModel);
m_proxyModel->setSortCaseSensitivity(Qt::CaseInsensitive);
setModel(m_proxyModel);
hideColumn(PeerListColumns::IP_HIDDEN);
hideColumn(PeerListColumns::COL_COUNT);
m_resolveCountries = Preferences::instance()->resolvePeerCountries();
if (!m_resolveCountries)
hideColumn(PeerListColumns::COUNTRY);
2017-04-05 10:21:12 +03:00
// Ensure that at least one column is visible at all times
2016-02-07 20:46:56 +03:00
bool atLeastOne = false;
for (int i = 0; i < PeerListColumns::IP_HIDDEN; ++i) {
2016-02-07 20:46:56 +03:00
if (!isColumnHidden(i)) {
atLeastOne = true;
break;
}
}
if (!atLeastOne)
setColumnHidden(PeerListColumns::IP, false);
2017-04-05 10:21:12 +03:00
// 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 (int i = 0; i < PeerListColumns::IP_HIDDEN; ++i) {
if ((columnWidth(i) <= 0) && !isColumnHidden(i))
resizeColumnToContents(i);
2019-08-23 12:04:55 +03:00
}
// Context menu
setContextMenuPolicy(Qt::CustomContextMenu);
2018-04-18 16:59:41 +03:00
connect(this, &QWidget::customContextMenuRequested, this, &PeerListWidget::showPeerListMenu);
// Enable sorting
setSortingEnabled(true);
// IP to Hostname resolver
updatePeerHostNameResolutionState();
// SIGNAL/SLOT
2016-02-07 20:46:56 +03:00
header()->setContextMenuPolicy(Qt::CustomContextMenu);
2018-04-18 16:59:41 +03:00
connect(header(), &QWidget::customContextMenuRequested, this, &PeerListWidget::displayToggleColumnsMenu);
connect(header(), &QHeaderView::sectionClicked, this, &PeerListWidget::handleSortColumnChanged);
connect(header(), &QHeaderView::sectionMoved, this, &PeerListWidget::saveSettings);
connect(header(), &QHeaderView::sectionResized, this, &PeerListWidget::saveSettings);
connect(header(), &QHeaderView::sortIndicatorChanged, this, &PeerListWidget::saveSettings);
handleSortColumnChanged(header()->sortIndicatorSection());
const auto *copyHotkey = new QShortcut(QKeySequence::Copy, this, nullptr, nullptr, Qt::WidgetShortcut);
connect(copyHotkey, &QShortcut::activated, this, &PeerListWidget::copySelectedPeers);
// 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(new QHeaderView(Qt::Horizontal));
2009-11-14 13:37:45 +03:00
}
2012-02-25 23:02:19 +04:00
PeerListWidget::~PeerListWidget()
{
saveSettings();
}
2017-04-05 10:21:12 +03:00
void PeerListWidget::displayToggleColumnsMenu(const QPoint &)
2016-02-07 20:46:56 +03:00
{
QMenu *menu = new QMenu(this);
menu->setAttribute(Qt::WA_DeleteOnClose);
menu->setTitle(tr("Column visibility"));
for (int i = 0; i < PeerListColumns::IP_HIDDEN; ++i) {
if ((i == PeerListColumns::COUNTRY) && !Preferences::instance()->resolvePeerCountries())
continue;
QAction *myAct = menu->addAction(m_listModel->headerData(i, Qt::Horizontal, Qt::DisplayRole).toString());
2016-02-07 20:46:56 +03:00
myAct->setCheckable(true);
myAct->setChecked(!isColumnHidden(i));
myAct->setData(i);
2016-02-07 20:46:56 +03:00
}
connect(menu, &QMenu::triggered, this, [this](const QAction *action)
{
int visibleCols = 0;
for (int i = 0; i < PeerListColumns::IP_HIDDEN; ++i) {
if (!isColumnHidden(i))
++visibleCols;
if (visibleCols > 1)
break;
}
const int col = action->data().toInt();
2016-02-07 20:46:56 +03:00
if (!isColumnHidden(col) && (visibleCols == 1))
return;
2016-02-07 20:46:56 +03:00
setColumnHidden(col, !isColumnHidden(col));
2016-02-07 20:46:56 +03:00
if (!isColumnHidden(col) && (columnWidth(col) <= 5))
resizeColumnToContents(col);
2016-02-07 20:46:56 +03:00
saveSettings();
});
menu->popup(QCursor::pos());
2016-02-07 20:46:56 +03:00
}
2012-02-25 23:02:19 +04:00
void PeerListWidget::updatePeerHostNameResolutionState()
{
if (Preferences::instance()->resolvePeerHostNames()) {
if (!m_resolver) {
m_resolver = new Net::ReverseResolution(this);
2019-08-23 12:04:55 +03:00
connect(m_resolver, &Net::ReverseResolution::ipResolved, this, &PeerListWidget::handleResolved);
loadPeers(m_properties->getCurrentTorrent());
}
}
2019-08-23 12:04:55 +03:00
else {
delete m_resolver;
2019-08-23 12:04:55 +03:00
m_resolver = nullptr;
}
}
2012-02-25 23:02:19 +04:00
void PeerListWidget::updatePeerCountryResolutionState()
{
2019-08-23 12:04:55 +03:00
const bool resolveCountries = Preferences::instance()->resolvePeerCountries();
if (resolveCountries == m_resolveCountries)
return;
m_resolveCountries = resolveCountries;
if (m_resolveCountries) {
loadPeers(m_properties->getCurrentTorrent());
showColumn(PeerListColumns::COUNTRY);
if (columnWidth(PeerListColumns::COUNTRY) <= 0)
resizeColumnToContents(PeerListColumns::COUNTRY);
2019-08-23 12:04:55 +03:00
}
else {
hideColumn(PeerListColumns::COUNTRY);
}
}
2017-04-05 10:21:12 +03:00
void PeerListWidget::showPeerListMenu(const QPoint &)
2012-02-25 23:02:19 +04:00
{
BitTorrent::TorrentHandle *const torrent = m_properties->getCurrentTorrent();
if (!torrent) return;
QMenu *menu = new QMenu(this);
menu->setAttribute(Qt::WA_DeleteOnClose);
// Add Peer Action
// Do not allow user to add peers in a private torrent
if (!torrent->isQueued() && !torrent->isChecking() && !torrent->isPrivate()) {
const QAction *addPeerAct = menu->addAction(UIThemeManager::instance()->getIcon("user-group-new"), tr("Add a new peer..."));
connect(addPeerAct, &QAction::triggered, this, [this, torrent]()
{
2019-08-02 07:55:06 +03:00
const QVector<BitTorrent::PeerAddress> peersList = PeersAdditionDialog::askForPeers(this);
const int peerCount = std::count_if(peersList.cbegin(), peersList.cend(), [torrent](const BitTorrent::PeerAddress &peer)
{
return torrent->connectPeer(peer);
});
if (peerCount < peersList.length())
2019-08-23 12:04:55 +03:00
QMessageBox::information(this, tr("Adding peers"), tr("Some peers cannot be added. Check the Log for details."));
else if (peerCount > 0)
2019-08-23 12:04:55 +03:00
QMessageBox::information(this, tr("Adding peers"), tr("Peers are added to this torrent."));
});
}
if (!selectionModel()->selectedRows().isEmpty()) {
const QAction *copyPeerAct = menu->addAction(UIThemeManager::instance()->getIcon("edit-copy"), tr("Copy IP:port"));
connect(copyPeerAct, &QAction::triggered, this, &PeerListWidget::copySelectedPeers);
2017-10-26 10:10:30 +03:00
menu->addSeparator();
const QAction *banAct = menu->addAction(UIThemeManager::instance()->getIcon("user-group-delete"), tr("Ban peer permanently"));
connect(banAct, &QAction::triggered, this, &PeerListWidget::banSelectedPeers);
}
if (menu->isEmpty())
delete menu;
else
menu->popup(QCursor::pos());
}
void PeerListWidget::banSelectedPeers()
2012-02-25 23:02:19 +04:00
{
// Store selected rows first as selected peers may disconnect
const QModelIndexList selectedIndexes = selectionModel()->selectedRows();
QVector<QString> selectedIPs;
selectedIPs.reserve(selectedIndexes.size());
for (const QModelIndex &index : selectedIndexes) {
2019-08-23 12:04:55 +03:00
const int row = m_proxyModel->mapToSource(index).row();
const QString ip = m_listModel->item(row, PeerListColumns::IP_HIDDEN)->text();
selectedIPs += ip;
}
// Confirm before banning peer
const QMessageBox::StandardButton btn = QMessageBox::question(this, tr("Ban peer permanently")
, tr("Are you sure you want to permanently ban the selected peers?"));
if (btn != QMessageBox::Yes) return;
for (const QString &ip : selectedIPs) {
BitTorrent::Session::instance()->banIP(ip);
2019-08-23 12:04:55 +03:00
LogMsg(tr("Peer \"%1\" is manually banned").arg(ip));
}
// Refresh list
loadPeers(m_properties->getCurrentTorrent());
}
void PeerListWidget::copySelectedPeers()
{
const QModelIndexList selectedIndexes = selectionModel()->selectedRows();
QStringList selectedPeers;
2019-08-23 12:04:55 +03:00
for (const QModelIndex &index : selectedIndexes) {
2019-08-23 12:04:55 +03:00
const int row = m_proxyModel->mapToSource(index).row();
const QString ip = m_listModel->item(row, PeerListColumns::IP_HIDDEN)->text();
const QString port = m_listModel->item(row, PeerListColumns::PORT)->text();
2019-08-23 12:04:55 +03:00
if (!ip.contains('.')) // IPv6
selectedPeers << ('[' + ip + "]:" + port);
else // IPv4
selectedPeers << (ip + ':' + port);
}
2019-08-23 12:04:55 +03:00
2018-06-06 16:48:17 +03:00
QApplication::clipboard()->setText(selectedPeers.join('\n'));
}
void PeerListWidget::clear()
{
m_peerItems.clear();
m_itemsByIP.clear();
2019-08-23 12:04:55 +03:00
const int nbrows = m_listModel->rowCount();
if (nbrows > 0)
2018-11-06 18:49:17 +03:00
m_listModel->removeRows(0, nbrows);
2009-11-14 13:37:45 +03:00
}
void PeerListWidget::loadSettings()
{
header()->restoreState(Preferences::instance()->getPeerListState());
}
void PeerListWidget::saveSettings() const
{
Preferences::instance()->setPeerListState(header()->saveState());
}
2019-08-23 12:04:55 +03:00
void PeerListWidget::loadPeers(const BitTorrent::TorrentHandle *torrent)
{
if (!torrent) return;
2019-08-02 07:55:06 +03:00
const QVector<BitTorrent::PeerInfo> peers = torrent->peers();
QSet<PeerEndpoint> existingPeers;
2019-08-23 12:04:55 +03:00
for (auto i = m_peerItems.cbegin(); i != m_peerItems.cend(); ++i)
existingPeers << i.key();
for (const BitTorrent::PeerInfo &peer : peers) {
if (peer.address().ip.isNull()) continue;
2019-08-23 12:04:55 +03:00
bool isNewPeer = false;
updatePeer(torrent, peer, isNewPeer);
if (!isNewPeer) {
const PeerEndpoint peerEndpoint {peer.address(), peer.connectionType()};
existingPeers.remove(peerEndpoint);
}
}
2019-08-23 12:04:55 +03:00
// Remove peers that are gone
for (const PeerEndpoint &peerEndpoint : asConst(existingPeers)) {
QStandardItem *item = m_peerItems.take(peerEndpoint);
QSet<QStandardItem *> &items = m_itemsByIP[peerEndpoint.address.ip];
items.remove(item);
if (items.isEmpty())
m_itemsByIP.remove(peerEndpoint.address.ip);
m_listModel->removeRow(item->row());
}
2009-11-14 13:37:45 +03:00
}
void PeerListWidget::updatePeer(const BitTorrent::TorrentHandle *torrent, const BitTorrent::PeerInfo &peer, bool &isNewPeer)
{
const PeerEndpoint peerEndpoint {peer.address(), peer.connectionType()};
const QString peerIp = peerEndpoint.address.ip.toString();
const Qt::Alignment intDataTextAlignment = Qt::AlignRight | Qt::AlignVCenter;
const auto setModelData =
[this] (const int row, const int column, const QString &displayData
, const QVariant &underlyingData, const Qt::Alignment textAlignmentData = {}
, const QString &toolTip = {})
{
const QMap<int, QVariant> data =
{
2020-07-30 09:20:25 +03:00
{Qt::DisplayRole, displayData},
{PeerListSortModel::UnderlyingDataRole, underlyingData},
{Qt::TextAlignmentRole, QVariant {textAlignmentData}},
{Qt::ToolTipRole, toolTip}
};
m_listModel->setItemData(m_listModel->index(row, column), data);
};
auto itemIter = m_peerItems.find(peerEndpoint);
2019-08-23 12:04:55 +03:00
isNewPeer = (itemIter == m_peerItems.end());
if (isNewPeer) {
// new item
const int row = m_listModel->rowCount();
m_listModel->insertRow(row);
setModelData(row, PeerListColumns::IP, peerIp, peerIp, {}, peerIp);
setModelData(row, PeerListColumns::PORT, QString::number(peer.address().port), peer.address().port, intDataTextAlignment);
setModelData(row, PeerListColumns::IP_HIDDEN, peerIp, peerIp);
itemIter = m_peerItems.insert(peerEndpoint, m_listModel->item(row, PeerListColumns::IP));
m_itemsByIP[peerEndpoint.address.ip].insert(itemIter.value());
}
2019-08-23 12:04:55 +03:00
const int row = (*itemIter)->row();
setModelData(row, PeerListColumns::CONNECTION, peer.connectionType(), peer.connectionType());
setModelData(row, PeerListColumns::FLAGS, peer.flags(), peer.flags(), {}, peer.flagsDescription());
const QString client = peer.client().toHtmlEscaped();
setModelData(row, PeerListColumns::CLIENT, client, client);
setModelData(row, PeerListColumns::PROGRESS, (Utils::String::fromDouble(peer.progress() * 100, 1) + '%'), peer.progress(), intDataTextAlignment);
setModelData(row, PeerListColumns::DOWN_SPEED, Utils::Misc::friendlyUnit(peer.payloadDownSpeed(), 1), peer.payloadDownSpeed(), intDataTextAlignment);
setModelData(row, PeerListColumns::UP_SPEED, Utils::Misc::friendlyUnit(peer.payloadUpSpeed(), true), peer.payloadUpSpeed(), intDataTextAlignment);
setModelData(row, PeerListColumns::TOT_DOWN, Utils::Misc::friendlyUnit(peer.totalDownload()), peer.totalDownload(), intDataTextAlignment);
setModelData(row, PeerListColumns::TOT_UP, Utils::Misc::friendlyUnit(peer.totalUpload()), peer.totalUpload(), intDataTextAlignment);
setModelData(row, PeerListColumns::RELEVANCE, (Utils::String::fromDouble(peer.relevance() * 100, 1) + '%'), peer.relevance(), intDataTextAlignment);
2019-08-23 12:04:55 +03:00
const QStringList downloadingFiles {torrent->info().filesForPiece(peer.downloadingPieceIndex())};
const QString downloadingFilesDisplayValue = downloadingFiles.join(';');
setModelData(row, PeerListColumns::DOWNLOADING_PIECE, downloadingFilesDisplayValue, downloadingFilesDisplayValue, {}, downloadingFiles.join('\n'));
2019-08-23 12:04:55 +03:00
if (m_resolver)
m_resolver->resolve(peerEndpoint.address.ip);
2009-11-14 13:37:45 +03:00
if (m_resolveCountries) {
2019-08-23 12:04:55 +03:00
const QIcon icon = UIThemeManager::instance()->getFlagIcon(peer.country());
if (!icon.isNull()) {
m_listModel->setData(m_listModel->index(row, PeerListColumns::COUNTRY), icon, Qt::DecorationRole);
const QString countryName = Net::GeoIPManager::CountryName(peer.country());
m_listModel->setData(m_listModel->index(row, PeerListColumns::COUNTRY), countryName, Qt::ToolTipRole);
}
}
2009-11-14 13:37:45 +03:00
}
void PeerListWidget::handleResolved(const QHostAddress &ip, const QString &hostname) const
{
if (hostname.isEmpty())
return;
const QSet<QStandardItem *> items = m_itemsByIP.value(ip);
for (QStandardItem *item : items)
item->setData(hostname, Qt::DisplayRole);
}
2010-10-24 13:32:28 +04:00
2019-08-23 12:04:55 +03:00
void PeerListWidget::handleSortColumnChanged(const int col)
2010-10-24 13:32:28 +04:00
{
if (col == PeerListColumns::COUNTRY)
m_proxyModel->setSortRole(Qt::ToolTipRole);
2019-08-23 12:04:55 +03:00
else
m_proxyModel->setSortRole(PeerListSortModel::UnderlyingDataRole);
2010-10-24 13:32:28 +04:00
}
2011-04-17 18:42:38 +04:00
void PeerListWidget::wheelEvent(QWheelEvent *event)
{
2017-04-05 10:21:12 +03:00
if (event->modifiers() & Qt::ShiftModifier) {
// Shift + scroll = horizontal scroll
event->accept();
#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0))
QWheelEvent scrollHEvent(event->position(), event->globalPosition()
, event->pixelDelta(), event->angleDelta().transposed(), event->buttons()
, event->modifiers(), event->phase(), event->inverted(), event->source());
#else
QWheelEvent scrollHEvent(event->pos(), event->globalPos()
, event->delta(), event->buttons(), event->modifiers(), Qt::Horizontal);
#endif
QTreeView::wheelEvent(&scrollHEvent);
return;
}
QTreeView::wheelEvent(event); // event delegated to base class
}