mirror of
https://github.com/qbittorrent/qBittorrent
synced 2025-07-14 01:03:08 -07:00
Use ProgressbarDelegate for drawing progressbar in PropListDelegate
Also directly provide display data from model rather then generating it in delegate
This commit is contained in:
parent
49d5591f48
commit
02f19bfbee
9 changed files with 115 additions and 122 deletions
|
@ -180,7 +180,7 @@ namespace
|
|||
|
||||
TorrentContentModel::TorrentContentModel(QObject *parent)
|
||||
: QAbstractItemModel(parent)
|
||||
, m_rootItem(new TorrentContentModelFolder(QVector<QVariant>({ tr("Name"), tr("Size"), tr("Progress"), tr("Download Priority"), tr("Remaining"), tr("Availability") })))
|
||||
, m_rootItem(new TorrentContentModelFolder(QVector<QString>({ tr("Name"), tr("Size"), tr("Progress"), tr("Download Priority"), tr("Remaining"), tr("Availability") })))
|
||||
{
|
||||
#if defined(Q_OS_WIN)
|
||||
m_fileIconProvider = new WinShellFileIconProvider();
|
||||
|
@ -332,25 +332,34 @@ QVariant TorrentContentModel::data(const QModelIndex &index, int role) const
|
|||
|
||||
auto *item = static_cast<TorrentContentModelItem*>(index.internalPointer());
|
||||
|
||||
if ((index.column() == TorrentContentModelItem::COL_NAME) && (role == Qt::DecorationRole)) {
|
||||
if (item->itemType() == TorrentContentModelItem::FolderType)
|
||||
return m_fileIconProvider->icon(QFileIconProvider::Folder);
|
||||
switch (role) {
|
||||
case Qt::DecorationRole: {
|
||||
if (index.column() != TorrentContentModelItem::COL_NAME)
|
||||
return {};
|
||||
|
||||
return m_fileIconProvider->icon(QFileInfo(item->name()));
|
||||
if (item->itemType() == TorrentContentModelItem::FolderType)
|
||||
return m_fileIconProvider->icon(QFileIconProvider::Folder);
|
||||
return m_fileIconProvider->icon(QFileInfo(item->name()));
|
||||
}
|
||||
case Qt::CheckStateRole: {
|
||||
if (index.column() != TorrentContentModelItem::COL_NAME)
|
||||
return {};
|
||||
|
||||
if (item->priority() == BitTorrent::DownloadPriority::Ignored)
|
||||
return Qt::Unchecked;
|
||||
if (item->priority() == BitTorrent::DownloadPriority::Mixed)
|
||||
return Qt::PartiallyChecked;
|
||||
return Qt::Checked;
|
||||
}
|
||||
case Qt::DisplayRole:
|
||||
return item->displayData(index.column());
|
||||
|
||||
case Roles::UnderlyingDataRole:
|
||||
return item->underlyingData(index.column());
|
||||
|
||||
default:
|
||||
return {};
|
||||
}
|
||||
|
||||
if ((index.column() == TorrentContentModelItem::COL_NAME) && (role == Qt::CheckStateRole)) {
|
||||
if (item->data(TorrentContentModelItem::COL_PRIO).toInt() == static_cast<int>(BitTorrent::DownloadPriority::Ignored))
|
||||
return Qt::Unchecked;
|
||||
if (item->data(TorrentContentModelItem::COL_PRIO).toInt() == static_cast<int>(BitTorrent::DownloadPriority::Mixed))
|
||||
return Qt::PartiallyChecked;
|
||||
return Qt::Checked;
|
||||
}
|
||||
|
||||
if (role == Qt::DisplayRole)
|
||||
return item->data(index.column());
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
Qt::ItemFlags TorrentContentModel::flags(const QModelIndex &index) const
|
||||
|
@ -367,7 +376,7 @@ Qt::ItemFlags TorrentContentModel::flags(const QModelIndex &index) const
|
|||
QVariant TorrentContentModel::headerData(int section, Qt::Orientation orientation, int role) const
|
||||
{
|
||||
if ((orientation == Qt::Horizontal) && (role == Qt::DisplayRole))
|
||||
return m_rootItem->data(section);
|
||||
return m_rootItem->displayData(section);
|
||||
|
||||
return {};
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue