mirror of
https://github.com/qbittorrent/qBittorrent
synced 2025-08-19 04:49:47 -07:00
commit
2f28365bfa
12 changed files with 131 additions and 155 deletions
|
@ -489,7 +489,6 @@
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
<layoutdefault spacing="6" margin="11"/>
|
|
||||||
<resources/>
|
<resources/>
|
||||||
<connections/>
|
<connections/>
|
||||||
</ui>
|
</ui>
|
||||||
|
|
|
@ -561,9 +561,6 @@
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout_8">
|
<layout class="QHBoxLayout" name="horizontalLayout_8">
|
||||||
<property name="topMargin">
|
|
||||||
<number>0</number>
|
|
||||||
</property>
|
|
||||||
<item>
|
<item>
|
||||||
<widget class="QCheckBox" name="checkFileLogBackup">
|
<widget class="QCheckBox" name="checkFileLogBackup">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
|
@ -604,9 +601,6 @@
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout_9">
|
<layout class="QHBoxLayout" name="horizontalLayout_9">
|
||||||
<property name="topMargin">
|
|
||||||
<number>0</number>
|
|
||||||
</property>
|
|
||||||
<item>
|
<item>
|
||||||
<widget class="QCheckBox" name="checkFileLogDelete">
|
<widget class="QCheckBox" name="checkFileLogDelete">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
|
@ -730,9 +724,6 @@
|
||||||
<bool>true</bool>
|
<bool>true</bool>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QVBoxLayout" name="verticalLayout_18">
|
<layout class="QVBoxLayout" name="verticalLayout_18">
|
||||||
<property name="bottomMargin">
|
|
||||||
<number>0</number>
|
|
||||||
</property>
|
|
||||||
<item>
|
<item>
|
||||||
<widget class="QCheckBox" name="checkAdditionDialogFront">
|
<widget class="QCheckBox" name="checkAdditionDialogFront">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
|
@ -2274,9 +2265,6 @@
|
||||||
<bool>false</bool>
|
<bool>false</bool>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QGridLayout" name="gridLayout_2">
|
<layout class="QGridLayout" name="gridLayout_2">
|
||||||
<property name="bottomMargin">
|
|
||||||
<number>9</number>
|
|
||||||
</property>
|
|
||||||
<item row="0" column="0">
|
<item row="0" column="0">
|
||||||
<widget class="QLabel" name="label_max_active_dl">
|
<widget class="QLabel" name="label_max_active_dl">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
|
|
|
@ -50,23 +50,27 @@ PreviewListDelegate::PreviewListDelegate(QObject *parent)
|
||||||
void PreviewListDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
|
void PreviewListDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
|
||||||
{
|
{
|
||||||
painter->save();
|
painter->save();
|
||||||
|
|
||||||
QStyleOptionViewItem opt = QItemDelegate::setOptions(index, option);
|
QStyleOptionViewItem opt = QItemDelegate::setOptions(index, option);
|
||||||
|
drawBackground(painter, opt, index);
|
||||||
|
|
||||||
switch (index.column()) {
|
switch (index.column()) {
|
||||||
case PreviewSelectDialog::SIZE:
|
case PreviewSelectDialog::SIZE:
|
||||||
QItemDelegate::drawBackground(painter, opt, index);
|
|
||||||
QItemDelegate::drawDisplay(painter, opt, option.rect, Utils::Misc::friendlyUnit(index.data().toLongLong()));
|
QItemDelegate::drawDisplay(painter, opt, option.rect, Utils::Misc::friendlyUnit(index.data().toLongLong()));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case PreviewSelectDialog::PROGRESS: {
|
case PreviewSelectDialog::PROGRESS: {
|
||||||
|
const qreal progress = (index.data().toReal() * 100);
|
||||||
|
|
||||||
QStyleOptionProgressBar newopt;
|
QStyleOptionProgressBar newopt;
|
||||||
qreal progress = index.data().toDouble() * 100.;
|
|
||||||
newopt.rect = opt.rect;
|
newopt.rect = opt.rect;
|
||||||
newopt.text = ((progress == 100.0) ? QString("100%") : Utils::String::fromDouble(progress, 1) + '%');
|
newopt.text = ((progress == 100) ? QString("100%") : (Utils::String::fromDouble(progress, 1) + '%'));
|
||||||
newopt.progress = static_cast<int>(progress);
|
newopt.progress = static_cast<int>(progress);
|
||||||
newopt.maximum = 100;
|
newopt.maximum = 100;
|
||||||
newopt.minimum = 0;
|
newopt.minimum = 0;
|
||||||
newopt.state |= QStyle::State_Enabled;
|
newopt.state |= QStyle::State_Enabled;
|
||||||
newopt.textVisible = true;
|
newopt.textVisible = true;
|
||||||
|
|
||||||
#if defined(Q_OS_WIN) || defined(Q_OS_MACOS)
|
#if defined(Q_OS_WIN) || defined(Q_OS_MACOS)
|
||||||
// XXX: To avoid having the progress text on the right of the bar
|
// XXX: To avoid having the progress text on the right of the bar
|
||||||
QProxyStyle st("fusion");
|
QProxyStyle st("fusion");
|
||||||
|
@ -76,6 +80,7 @@ void PreviewListDelegate::paint(QPainter *painter, const QStyleOptionViewItem &o
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
QItemDelegate::paint(painter, option, index);
|
QItemDelegate::paint(painter, option, index);
|
||||||
}
|
}
|
||||||
|
|
|
@ -79,7 +79,7 @@ PreviewSelectDialog::PreviewSelectDialog(QWidget *parent, BitTorrent::TorrentHan
|
||||||
m_ui->previewList->setItemDelegate(m_listDelegate);
|
m_ui->previewList->setItemDelegate(m_listDelegate);
|
||||||
m_ui->previewList->setAlternatingRowColors(pref->useAlternatingRowColors());
|
m_ui->previewList->setAlternatingRowColors(pref->useAlternatingRowColors());
|
||||||
// Fill list in
|
// Fill list in
|
||||||
QVector<qreal> fp = torrent->filesProgress();
|
const QVector<qreal> fp = torrent->filesProgress();
|
||||||
int nbFiles = torrent->filesCount();
|
int nbFiles = torrent->filesCount();
|
||||||
for (int i = 0; i < nbFiles; ++i) {
|
for (int i = 0; i < nbFiles; ++i) {
|
||||||
QString fileName = torrent->fileName(i);
|
QString fileName = torrent->fileName(i);
|
||||||
|
@ -89,10 +89,10 @@ PreviewSelectDialog::PreviewSelectDialog(QWidget *parent, BitTorrent::TorrentHan
|
||||||
if (Utils::Misc::isPreviewable(extension)) {
|
if (Utils::Misc::isPreviewable(extension)) {
|
||||||
int row = m_previewListModel->rowCount();
|
int row = m_previewListModel->rowCount();
|
||||||
m_previewListModel->insertRow(row);
|
m_previewListModel->insertRow(row);
|
||||||
m_previewListModel->setData(m_previewListModel->index(row, NAME), QVariant(fileName));
|
m_previewListModel->setData(m_previewListModel->index(row, NAME), fileName);
|
||||||
m_previewListModel->setData(m_previewListModel->index(row, SIZE), QVariant(torrent->fileSize(i)));
|
m_previewListModel->setData(m_previewListModel->index(row, SIZE), torrent->fileSize(i));
|
||||||
m_previewListModel->setData(m_previewListModel->index(row, PROGRESS), QVariant(fp[i]));
|
m_previewListModel->setData(m_previewListModel->index(row, PROGRESS), fp[i]);
|
||||||
m_previewListModel->setData(m_previewListModel->index(row, FILE_INDEX), QVariant(i));
|
m_previewListModel->setData(m_previewListModel->index(row, FILE_INDEX), i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -44,6 +44,7 @@ void PeerListDelegate::paint(QPainter *painter, const QStyleOptionViewItem &opti
|
||||||
painter->save();
|
painter->save();
|
||||||
|
|
||||||
const bool hideValues = Preferences::instance()->getHideZeroValues();
|
const bool hideValues = Preferences::instance()->getHideZeroValues();
|
||||||
|
|
||||||
QStyleOptionViewItem opt = QItemDelegate::setOptions(index, option);
|
QStyleOptionViewItem opt = QItemDelegate::setOptions(index, option);
|
||||||
QItemDelegate::drawBackground(painter, opt, index);
|
QItemDelegate::drawBackground(painter, opt, index);
|
||||||
|
|
||||||
|
@ -54,7 +55,7 @@ void PeerListDelegate::paint(QPainter *painter, const QStyleOptionViewItem &opti
|
||||||
break;
|
break;
|
||||||
case TOT_DOWN:
|
case TOT_DOWN:
|
||||||
case TOT_UP: {
|
case TOT_UP: {
|
||||||
qlonglong size = index.data().toLongLong();
|
const qlonglong size = index.data().toLongLong();
|
||||||
if (hideValues && (size <= 0))
|
if (hideValues && (size <= 0))
|
||||||
break;
|
break;
|
||||||
opt.displayAlignment = Qt::AlignRight | Qt::AlignVCenter;
|
opt.displayAlignment = Qt::AlignRight | Qt::AlignVCenter;
|
||||||
|
@ -63,8 +64,8 @@ void PeerListDelegate::paint(QPainter *painter, const QStyleOptionViewItem &opti
|
||||||
break;
|
break;
|
||||||
case DOWN_SPEED:
|
case DOWN_SPEED:
|
||||||
case UP_SPEED: {
|
case UP_SPEED: {
|
||||||
qreal speed = index.data().toDouble();
|
const int speed = index.data().toInt();
|
||||||
if (speed <= 0.0)
|
if (speed <= 0)
|
||||||
break;
|
break;
|
||||||
opt.displayAlignment = Qt::AlignRight | Qt::AlignVCenter;
|
opt.displayAlignment = Qt::AlignRight | Qt::AlignVCenter;
|
||||||
QItemDelegate::drawDisplay(painter, opt, opt.rect, Utils::Misc::friendlyUnit(speed, true));
|
QItemDelegate::drawDisplay(painter, opt, opt.rect, Utils::Misc::friendlyUnit(speed, true));
|
||||||
|
@ -72,9 +73,9 @@ void PeerListDelegate::paint(QPainter *painter, const QStyleOptionViewItem &opti
|
||||||
break;
|
break;
|
||||||
case PROGRESS:
|
case PROGRESS:
|
||||||
case RELEVANCE: {
|
case RELEVANCE: {
|
||||||
qreal progress = index.data().toDouble();
|
const qreal progress = index.data().toReal();
|
||||||
opt.displayAlignment = Qt::AlignRight | Qt::AlignVCenter;
|
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, 1) + '%'));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
|
|
@ -301,7 +301,7 @@ void PeerListWidget::copySelectedPeers()
|
||||||
int row = m_proxyModel->mapToSource(index).row();
|
int row = m_proxyModel->mapToSource(index).row();
|
||||||
QString ip = m_listModel->data(m_listModel->index(row, PeerListDelegate::IP_HIDDEN)).toString();
|
QString ip = m_listModel->data(m_listModel->index(row, PeerListDelegate::IP_HIDDEN)).toString();
|
||||||
QString myport = m_listModel->data(m_listModel->index(row, PeerListDelegate::PORT)).toString();
|
QString myport = m_listModel->data(m_listModel->index(row, PeerListDelegate::PORT)).toString();
|
||||||
if (ip.indexOf('.') == -1) // IPv6
|
if (!ip.contains('.')) // IPv6
|
||||||
selectedPeers << '[' + ip + "]:" + myport;
|
selectedPeers << '[' + ip + "]:" + myport;
|
||||||
else // IPv4
|
else // IPv4
|
||||||
selectedPeers << ip + ':' + myport;
|
selectedPeers << ip + ':' + myport;
|
||||||
|
|
|
@ -49,17 +49,16 @@
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
|
|
||||||
QPalette progressBarDisabledPalette()
|
QPalette progressBarDisabledPalette()
|
||||||
{
|
{
|
||||||
auto getPalette = []() {
|
static const QPalette palette = []()
|
||||||
|
{
|
||||||
QProgressBar bar;
|
QProgressBar bar;
|
||||||
bar.setEnabled(false);
|
bar.setEnabled(false);
|
||||||
QStyleOptionProgressBar opt;
|
QStyleOptionProgressBar opt;
|
||||||
opt.initFrom(&bar);
|
opt.initFrom(&bar);
|
||||||
return opt.palette;
|
return opt.palette;
|
||||||
};
|
}();
|
||||||
static QPalette palette = getPalette();
|
|
||||||
return palette;
|
return palette;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -73,6 +72,7 @@ PropListDelegate::PropListDelegate(PropertiesWidget *properties)
|
||||||
void PropListDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
|
void PropListDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
|
||||||
{
|
{
|
||||||
painter->save();
|
painter->save();
|
||||||
|
|
||||||
QStyleOptionViewItem opt = QItemDelegate::setOptions(index, option);
|
QStyleOptionViewItem opt = QItemDelegate::setOptions(index, option);
|
||||||
QItemDelegate::drawBackground(painter, opt, index);
|
QItemDelegate::drawBackground(painter, opt, index);
|
||||||
|
|
||||||
|
@ -81,15 +81,16 @@ void PropListDelegate::paint(QPainter *painter, const QStyleOptionViewItem &opti
|
||||||
case REMAINING:
|
case REMAINING:
|
||||||
QItemDelegate::drawDisplay(painter, opt, option.rect, Utils::Misc::friendlyUnit(index.data().toLongLong()));
|
QItemDelegate::drawDisplay(painter, opt, option.rect, Utils::Misc::friendlyUnit(index.data().toLongLong()));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case PROGRESS: {
|
case PROGRESS: {
|
||||||
if (index.data().toDouble() < 0)
|
const qreal progress = (index.data().toReal() * 100);
|
||||||
|
if (progress < 0)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
QStyleOptionProgressBar newopt;
|
QStyleOptionProgressBar newopt;
|
||||||
qreal progress = index.data().toDouble() * 100.;
|
|
||||||
newopt.rect = opt.rect;
|
newopt.rect = opt.rect;
|
||||||
newopt.text = ((progress == 100.0) ? QString("100%") : Utils::String::fromDouble(progress, 1) + '%');
|
newopt.text = (progress == 100) ? QString("100%") : (Utils::String::fromDouble(progress, 1) + '%');
|
||||||
newopt.progress = int(progress);
|
newopt.progress = static_cast<int>(progress);
|
||||||
newopt.maximum = 100;
|
newopt.maximum = 100;
|
||||||
newopt.minimum = 0;
|
newopt.minimum = 0;
|
||||||
newopt.textVisible = true;
|
newopt.textVisible = true;
|
||||||
|
@ -101,14 +102,15 @@ void PropListDelegate::paint(QPainter *painter, const QStyleOptionViewItem &opti
|
||||||
newopt.state |= QStyle::State_Enabled;
|
newopt.state |= QStyle::State_Enabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if !defined(Q_OS_WIN) && !defined(Q_OS_MACOS)
|
#if defined(Q_OS_WIN) || defined(Q_OS_MACOS)
|
||||||
QApplication::style()->drawControl(QStyle::CE_ProgressBar, &newopt, painter);
|
|
||||||
#else
|
|
||||||
// XXX: To avoid having the progress text on the right of the bar
|
// XXX: To avoid having the progress text on the right of the bar
|
||||||
QProxyStyle("fusion").drawControl(QStyle::CE_ProgressBar, &newopt, painter, 0);
|
QProxyStyle("fusion").drawControl(QStyle::CE_ProgressBar, &newopt, painter, 0);
|
||||||
|
#else
|
||||||
|
QApplication::style()->drawControl(QStyle::CE_ProgressBar, &newopt, painter);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case PRIORITY: {
|
case PRIORITY: {
|
||||||
QString text = "";
|
QString text = "";
|
||||||
switch (static_cast<BitTorrent::DownloadPriority>(index.data().toInt())) {
|
switch (static_cast<BitTorrent::DownloadPriority>(index.data().toInt())) {
|
||||||
|
@ -131,23 +133,26 @@ void PropListDelegate::paint(QPainter *painter, const QStyleOptionViewItem &opti
|
||||||
QItemDelegate::drawDisplay(painter, opt, option.rect, text);
|
QItemDelegate::drawDisplay(painter, opt, option.rect, text);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case AVAILABILITY: {
|
case AVAILABILITY: {
|
||||||
const qreal availability = index.data().toDouble();
|
const qreal availability = index.data().toReal();
|
||||||
if (availability < 0) {
|
if (availability < 0) {
|
||||||
QItemDelegate::drawDisplay(painter, opt, option.rect, tr("N/A"));
|
QItemDelegate::drawDisplay(painter, opt, option.rect, tr("N/A"));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
const QString value = (availability >= 1.0)
|
const QString value = (availability >= 1.0)
|
||||||
? QLatin1String("100")
|
? QLatin1String("100")
|
||||||
: Utils::String::fromDouble(availability * 100., 1);
|
: Utils::String::fromDouble(availability * 100, 1);
|
||||||
QItemDelegate::drawDisplay(painter, opt, option.rect, value + C_THIN_SPACE + QLatin1Char('%'));
|
QItemDelegate::drawDisplay(painter, opt, option.rect, (value + C_THIN_SPACE + QLatin1Char('%')));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
QItemDelegate::paint(painter, option, index);
|
QItemDelegate::paint(painter, option, index);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
painter->restore();
|
painter->restore();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -176,7 +181,7 @@ QWidget *PropListDelegate::createEditor(QWidget *parent, const QStyleOptionViewI
|
||||||
if (index.column() != PRIORITY) return nullptr;
|
if (index.column() != PRIORITY) return nullptr;
|
||||||
|
|
||||||
if (m_properties) {
|
if (m_properties) {
|
||||||
BitTorrent::TorrentHandle *const torrent = m_properties->getCurrentTorrent();
|
const BitTorrent::TorrentHandle *torrent = m_properties->getCurrentTorrent();
|
||||||
if (!torrent || !torrent->hasMetadata() || torrent->isSeed())
|
if (!torrent || !torrent->hasMetadata() || torrent->isSeed())
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
@ -195,9 +200,8 @@ QWidget *PropListDelegate::createEditor(QWidget *parent, const QStyleOptionViewI
|
||||||
|
|
||||||
void PropListDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
|
void PropListDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
|
||||||
{
|
{
|
||||||
auto *combobox = static_cast<QComboBox *>(editor);
|
const auto *combobox = static_cast<QComboBox *>(editor);
|
||||||
int value = combobox->currentIndex();
|
const int value = combobox->currentIndex();
|
||||||
qDebug("PropListDelegate: setModelData(%d)", value);
|
|
||||||
|
|
||||||
BitTorrent::DownloadPriority prio = BitTorrent::DownloadPriority::Normal; // NORMAL
|
BitTorrent::DownloadPriority prio = BitTorrent::DownloadPriority::Normal; // NORMAL
|
||||||
switch (value) {
|
switch (value) {
|
||||||
|
@ -218,6 +222,5 @@ void PropListDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
|
||||||
|
|
||||||
void PropListDelegate::updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &) const
|
void PropListDelegate::updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &) const
|
||||||
{
|
{
|
||||||
qDebug("UpdateEditor Geometry called");
|
|
||||||
editor->setGeometry(option.rect);
|
editor->setGeometry(option.rect);
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,7 +35,6 @@
|
||||||
#include "base/utils/misc.h"
|
#include "base/utils/misc.h"
|
||||||
#include "searchsortmodel.h"
|
#include "searchsortmodel.h"
|
||||||
|
|
||||||
|
|
||||||
SearchListDelegate::SearchListDelegate(QObject *parent)
|
SearchListDelegate::SearchListDelegate(QObject *parent)
|
||||||
: QItemDelegate(parent)
|
: QItemDelegate(parent)
|
||||||
{
|
{
|
||||||
|
|
|
@ -43,7 +43,7 @@ SearchSortModel::SearchSortModel(QObject *parent)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void SearchSortModel::enableNameFilter(bool enabled)
|
void SearchSortModel::enableNameFilter(const bool enabled)
|
||||||
{
|
{
|
||||||
m_isNameFilterEnabled = enabled;
|
m_isNameFilterEnabled = enabled;
|
||||||
}
|
}
|
||||||
|
@ -51,7 +51,7 @@ void SearchSortModel::enableNameFilter(bool enabled)
|
||||||
void SearchSortModel::setNameFilter(const QString &searchTerm)
|
void SearchSortModel::setNameFilter(const QString &searchTerm)
|
||||||
{
|
{
|
||||||
m_searchTerm = searchTerm;
|
m_searchTerm = searchTerm;
|
||||||
if (searchTerm.length() > 2
|
if ((searchTerm.length() > 2)
|
||||||
&& searchTerm.startsWith(QLatin1Char('"')) && searchTerm.endsWith(QLatin1Char('"'))) {
|
&& searchTerm.startsWith(QLatin1Char('"')) && searchTerm.endsWith(QLatin1Char('"'))) {
|
||||||
m_searchTermWords = QStringList(m_searchTerm.mid(1, m_searchTerm.length() - 2));
|
m_searchTermWords = QStringList(m_searchTerm.mid(1, m_searchTerm.length() - 2));
|
||||||
}
|
}
|
||||||
|
@ -60,19 +60,19 @@ void SearchSortModel::setNameFilter(const QString &searchTerm)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SearchSortModel::setSizeFilter(qint64 minSize, qint64 maxSize)
|
void SearchSortModel::setSizeFilter(const qint64 minSize, const qint64 maxSize)
|
||||||
{
|
{
|
||||||
m_minSize = std::max(static_cast<qint64>(0), minSize);
|
m_minSize = std::max(static_cast<qint64>(0), minSize);
|
||||||
m_maxSize = std::max(static_cast<qint64>(-1), maxSize);
|
m_maxSize = std::max(static_cast<qint64>(-1), maxSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SearchSortModel::setSeedsFilter(int minSeeds, int maxSeeds)
|
void SearchSortModel::setSeedsFilter(const int minSeeds, const int maxSeeds)
|
||||||
{
|
{
|
||||||
m_minSeeds = std::max(0, minSeeds);
|
m_minSeeds = std::max(0, minSeeds);
|
||||||
m_maxSeeds = std::max(-1, maxSeeds);
|
m_maxSeeds = std::max(-1, maxSeeds);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SearchSortModel::setLeechesFilter(int minLeeches, int maxLeeches)
|
void SearchSortModel::setLeechesFilter(const int minLeeches, const int maxLeeches)
|
||||||
{
|
{
|
||||||
m_minLeeches = std::max(0, minLeeches);
|
m_minLeeches = std::max(0, minLeeches);
|
||||||
m_maxLeeches = std::max(-1, maxLeeches);
|
m_maxLeeches = std::max(-1, maxLeeches);
|
||||||
|
@ -124,42 +124,38 @@ bool SearchSortModel::lessThan(const QModelIndex &left, const QModelIndex &right
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SearchSortModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
|
bool SearchSortModel::filterAcceptsRow(const int sourceRow, const QModelIndex &sourceParent) const
|
||||||
{
|
{
|
||||||
const QAbstractItemModel *const sourceModel = this->sourceModel();
|
const QAbstractItemModel *const sourceModel = this->sourceModel();
|
||||||
|
|
||||||
if (m_isNameFilterEnabled && !m_searchTerm.isEmpty()) {
|
if (m_isNameFilterEnabled && !m_searchTerm.isEmpty()) {
|
||||||
QString name = sourceModel->data(sourceModel->index(sourceRow, NAME, sourceParent)).toString();
|
const QString name = sourceModel->data(sourceModel->index(sourceRow, NAME, sourceParent)).toString();
|
||||||
for (const QString &word : asConst(m_searchTermWords)) {
|
for (const QString &word : asConst(m_searchTermWords)) {
|
||||||
int i = name.indexOf(word, 0, Qt::CaseInsensitive);
|
if (!name.contains(word, Qt::CaseInsensitive))
|
||||||
if (i == -1) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if ((m_minSize > 0) || (m_maxSize >= 0)) {
|
if ((m_minSize > 0) || (m_maxSize >= 0)) {
|
||||||
qlonglong size = sourceModel->data(sourceModel->index(sourceRow, SIZE, sourceParent)).toLongLong();
|
const qlonglong size = sourceModel->data(sourceModel->index(sourceRow, SIZE, sourceParent)).toLongLong();
|
||||||
if (((m_minSize > 0) && (size < m_minSize))
|
if (((m_minSize > 0) && (size < m_minSize))
|
||||||
|| ((m_maxSize > 0) && (size > m_maxSize))) {
|
|| ((m_maxSize > 0) && (size > m_maxSize)))
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if ((m_minSeeds > 0) || (m_maxSeeds >= 0)) {
|
if ((m_minSeeds > 0) || (m_maxSeeds >= 0)) {
|
||||||
int seeds = sourceModel->data(sourceModel->index(sourceRow, SEEDS, sourceParent)).toInt();
|
const int seeds = sourceModel->data(sourceModel->index(sourceRow, SEEDS, sourceParent)).toInt();
|
||||||
if (((m_minSeeds > 0) && (seeds < m_minSeeds))
|
if (((m_minSeeds > 0) && (seeds < m_minSeeds))
|
||||||
|| ((m_maxSeeds > 0) && (seeds > m_maxSeeds))) {
|
|| ((m_maxSeeds > 0) && (seeds > m_maxSeeds)))
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if ((m_minLeeches > 0) || (m_maxLeeches >= 0)) {
|
if ((m_minLeeches > 0) || (m_maxLeeches >= 0)) {
|
||||||
int leeches = sourceModel->data(sourceModel->index(sourceRow, LEECHES, sourceParent)).toInt();
|
const int leeches = sourceModel->data(sourceModel->index(sourceRow, LEECHES, sourceParent)).toInt();
|
||||||
if (((m_minLeeches > 0) && (leeches < m_minLeeches))
|
if (((m_minLeeches > 0) && (leeches < m_minLeeches))
|
||||||
|| ((m_maxLeeches > 0) && (leeches > m_maxLeeches))) {
|
|| ((m_maxLeeches > 0) && (leeches > m_maxLeeches)))
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return base::filterAcceptsRow(sourceRow, sourceParent);
|
return base::filterAcceptsRow(sourceRow, sourceParent);
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,16 +54,18 @@ TransferListDelegate::TransferListDelegate(QObject *parent)
|
||||||
void TransferListDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
|
void TransferListDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
|
||||||
{
|
{
|
||||||
painter->save();
|
painter->save();
|
||||||
|
|
||||||
bool isHideState = true;
|
bool isHideState = true;
|
||||||
if (Preferences::instance()->getHideZeroComboValues() == 1) { // paused torrents only
|
if (Preferences::instance()->getHideZeroComboValues() == 1) { // paused torrents only
|
||||||
QModelIndex stateIndex = index.sibling(index.row(), TransferListModel::TR_STATUS);
|
const QModelIndex stateIndex = index.sibling(index.row(), TransferListModel::TR_STATUS);
|
||||||
if (stateIndex.data().value<BitTorrent::TorrentState>() != BitTorrent::TorrentState::PausedDownloading)
|
if (stateIndex.data().value<BitTorrent::TorrentState>() != BitTorrent::TorrentState::PausedDownloading)
|
||||||
isHideState = false;
|
isHideState = false;
|
||||||
}
|
}
|
||||||
const bool hideValues = Preferences::instance()->getHideZeroValues() & isHideState;
|
const bool hideValues = Preferences::instance()->getHideZeroValues() && isHideState;
|
||||||
|
|
||||||
QStyleOptionViewItem opt = QItemDelegate::setOptions(index, option);
|
QStyleOptionViewItem opt = QItemDelegate::setOptions(index, option);
|
||||||
QItemDelegate::drawBackground(painter, opt, index);
|
QItemDelegate::drawBackground(painter, opt, index);
|
||||||
|
|
||||||
switch (index.column()) {
|
switch (index.column()) {
|
||||||
case TransferListModel::TR_AMOUNT_DOWNLOADED:
|
case TransferListModel::TR_AMOUNT_DOWNLOADED:
|
||||||
case TransferListModel::TR_AMOUNT_UPLOADED:
|
case TransferListModel::TR_AMOUNT_UPLOADED:
|
||||||
|
@ -83,8 +85,8 @@ void TransferListDelegate::paint(QPainter *painter, const QStyleOptionViewItem &
|
||||||
case TransferListModel::TR_ETA: {
|
case TransferListModel::TR_ETA: {
|
||||||
opt.displayAlignment = Qt::AlignRight | Qt::AlignVCenter;
|
opt.displayAlignment = Qt::AlignRight | Qt::AlignVCenter;
|
||||||
QItemDelegate::drawDisplay(painter, opt, option.rect, Utils::Misc::userFriendlyDuration(index.data().toLongLong(), MAX_ETA));
|
QItemDelegate::drawDisplay(painter, opt, option.rect, Utils::Misc::userFriendlyDuration(index.data().toLongLong(), MAX_ETA));
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
case TransferListModel::TR_SEEDS:
|
case TransferListModel::TR_SEEDS:
|
||||||
case TransferListModel::TR_PEERS: {
|
case TransferListModel::TR_PEERS: {
|
||||||
qlonglong value = index.data().toLongLong();
|
qlonglong value = index.data().toLongLong();
|
||||||
|
@ -148,30 +150,32 @@ void TransferListDelegate::paint(QPainter *painter, const QStyleOptionViewItem &
|
||||||
case TransferListModel::TR_QUEUE_POSITION: {
|
case TransferListModel::TR_QUEUE_POSITION: {
|
||||||
const int queuePos = index.data().toInt();
|
const int queuePos = index.data().toInt();
|
||||||
opt.displayAlignment = Qt::AlignRight | Qt::AlignVCenter;
|
opt.displayAlignment = Qt::AlignRight | Qt::AlignVCenter;
|
||||||
if (queuePos > 0) {
|
if (queuePos > 0)
|
||||||
QItemDelegate::paint(painter, opt, index);
|
QItemDelegate::paint(painter, opt, index);
|
||||||
}
|
else
|
||||||
else {
|
|
||||||
QItemDelegate::drawDisplay(painter, opt, opt.rect, "*");
|
QItemDelegate::drawDisplay(painter, opt, opt.rect, "*");
|
||||||
}
|
}
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case TransferListModel::TR_PROGRESS: {
|
case TransferListModel::TR_PROGRESS: {
|
||||||
|
const qreal progress = index.data().toDouble() * 100;
|
||||||
|
|
||||||
QStyleOptionProgressBar newopt;
|
QStyleOptionProgressBar newopt;
|
||||||
qreal progress = index.data().toDouble() * 100.;
|
|
||||||
newopt.rect = opt.rect;
|
newopt.rect = opt.rect;
|
||||||
newopt.text = ((progress == 100.0) ? QString("100%") : Utils::String::fromDouble(progress, 1) + '%');
|
newopt.text = ((progress == 100)
|
||||||
|
? QString("100%")
|
||||||
|
: (Utils::String::fromDouble(progress, 1) + '%'));
|
||||||
newopt.progress = static_cast<int>(progress);
|
newopt.progress = static_cast<int>(progress);
|
||||||
newopt.maximum = 100;
|
newopt.maximum = 100;
|
||||||
newopt.minimum = 0;
|
newopt.minimum = 0;
|
||||||
newopt.state |= QStyle::State_Enabled;
|
newopt.state |= QStyle::State_Enabled;
|
||||||
newopt.textVisible = true;
|
newopt.textVisible = true;
|
||||||
#if !defined(Q_OS_WIN) && !defined(Q_OS_MACOS)
|
|
||||||
QApplication::style()->drawControl(QStyle::CE_ProgressBar, &newopt, painter);
|
#if defined(Q_OS_WIN) || defined(Q_OS_MACOS)
|
||||||
#else
|
|
||||||
// XXX: To avoid having the progress text on the right of the bar
|
// XXX: To avoid having the progress text on the right of the bar
|
||||||
QProxyStyle st("fusion");
|
QProxyStyle st("fusion");
|
||||||
st.drawControl(QStyle::CE_ProgressBar, &newopt, painter, 0);
|
st.drawControl(QStyle::CE_ProgressBar, &newopt, painter);
|
||||||
|
#else
|
||||||
|
QApplication::style()->drawControl(QStyle::CE_ProgressBar, &newopt, painter);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -207,6 +211,7 @@ void TransferListDelegate::paint(QPainter *painter, const QStyleOptionViewItem &
|
||||||
default:
|
default:
|
||||||
QItemDelegate::paint(painter, option, index);
|
QItemDelegate::paint(painter, option, index);
|
||||||
}
|
}
|
||||||
|
|
||||||
painter->restore();
|
painter->restore();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -225,7 +230,7 @@ QSize TransferListDelegate::sizeHint(const QStyleOptionViewItem &option, const Q
|
||||||
|
|
||||||
static int nameColHeight = -1;
|
static int nameColHeight = -1;
|
||||||
if (nameColHeight == -1) {
|
if (nameColHeight == -1) {
|
||||||
QModelIndex nameColumn = index.sibling(index.row(), TransferListModel::TR_NAME);
|
const QModelIndex nameColumn = index.sibling(index.row(), TransferListModel::TR_NAME);
|
||||||
nameColHeight = QItemDelegate::sizeHint(option, nameColumn).height();
|
nameColHeight = QItemDelegate::sizeHint(option, nameColumn).height();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -236,60 +241,41 @@ QSize TransferListDelegate::sizeHint(const QStyleOptionViewItem &option, const Q
|
||||||
|
|
||||||
QString TransferListDelegate::getStatusString(const BitTorrent::TorrentState state) const
|
QString TransferListDelegate::getStatusString(const BitTorrent::TorrentState state) const
|
||||||
{
|
{
|
||||||
QString str;
|
|
||||||
|
|
||||||
switch (state) {
|
switch (state) {
|
||||||
case BitTorrent::TorrentState::Downloading:
|
case BitTorrent::TorrentState::Downloading:
|
||||||
str = tr("Downloading");
|
return tr("Downloading");
|
||||||
break;
|
|
||||||
case BitTorrent::TorrentState::StalledDownloading:
|
case BitTorrent::TorrentState::StalledDownloading:
|
||||||
str = tr("Stalled", "Torrent is waiting for download to begin");
|
return tr("Stalled", "Torrent is waiting for download to begin");
|
||||||
break;
|
|
||||||
case BitTorrent::TorrentState::DownloadingMetadata:
|
case BitTorrent::TorrentState::DownloadingMetadata:
|
||||||
str = tr("Downloading metadata", "used when loading a magnet link");
|
return tr("Downloading metadata", "Used when loading a magnet link");
|
||||||
break;
|
|
||||||
case BitTorrent::TorrentState::ForcedDownloading:
|
case BitTorrent::TorrentState::ForcedDownloading:
|
||||||
str = tr("[F] Downloading", "used when the torrent is forced started. You probably shouldn't translate the F.");
|
return tr("[F] Downloading", "Used when the torrent is forced started. You probably shouldn't translate the F.");
|
||||||
break;
|
|
||||||
case BitTorrent::TorrentState::Allocating:
|
case BitTorrent::TorrentState::Allocating:
|
||||||
str = tr("Allocating", "qBittorrent is allocating the files on disk");
|
return tr("Allocating", "qBittorrent is allocating the files on disk");
|
||||||
break;
|
|
||||||
case BitTorrent::TorrentState::Uploading:
|
case BitTorrent::TorrentState::Uploading:
|
||||||
case BitTorrent::TorrentState::StalledUploading:
|
case BitTorrent::TorrentState::StalledUploading:
|
||||||
str = tr("Seeding", "Torrent is complete and in upload-only mode");
|
return tr("Seeding", "Torrent is complete and in upload-only mode");
|
||||||
break;
|
|
||||||
case BitTorrent::TorrentState::ForcedUploading:
|
case BitTorrent::TorrentState::ForcedUploading:
|
||||||
str = tr("[F] Seeding", "used when the torrent is forced started. You probably shouldn't translate the F.");
|
return tr("[F] Seeding", "Used when the torrent is forced started. You probably shouldn't translate the F.");
|
||||||
break;
|
|
||||||
case BitTorrent::TorrentState::QueuedDownloading:
|
case BitTorrent::TorrentState::QueuedDownloading:
|
||||||
case BitTorrent::TorrentState::QueuedUploading:
|
case BitTorrent::TorrentState::QueuedUploading:
|
||||||
str = tr("Queued", "i.e. torrent is queued");
|
return tr("Queued", "Torrent is queued");
|
||||||
break;
|
|
||||||
case BitTorrent::TorrentState::CheckingDownloading:
|
case BitTorrent::TorrentState::CheckingDownloading:
|
||||||
case BitTorrent::TorrentState::CheckingUploading:
|
case BitTorrent::TorrentState::CheckingUploading:
|
||||||
str = tr("Checking", "Torrent local data is being checked");
|
return tr("Checking", "Torrent local data is being checked");
|
||||||
break;
|
|
||||||
case BitTorrent::TorrentState::CheckingResumeData:
|
case BitTorrent::TorrentState::CheckingResumeData:
|
||||||
str = tr("Checking resume data", "used when loading the torrents from disk after qbt is launched. It checks the correctness of the .fastresume file. Normally it is completed in a fraction of a second, unless loading many many torrents.");
|
return tr("Checking resume data", "Used when loading the torrents from disk after qbt is launched. It checks the correctness of the .fastresume file. Normally it is completed in a fraction of a second, unless loading many many torrents.");
|
||||||
break;
|
|
||||||
case BitTorrent::TorrentState::PausedDownloading:
|
case BitTorrent::TorrentState::PausedDownloading:
|
||||||
str = tr("Paused");
|
return tr("Paused");
|
||||||
break;
|
|
||||||
case BitTorrent::TorrentState::PausedUploading:
|
case BitTorrent::TorrentState::PausedUploading:
|
||||||
str = tr("Completed");
|
return tr("Completed");
|
||||||
break;
|
|
||||||
case BitTorrent::TorrentState::Moving:
|
case BitTorrent::TorrentState::Moving:
|
||||||
str = tr("Moving", "Torrent local data are being moved/relocated");
|
return tr("Moving", "Torrent local data are being moved/relocated");
|
||||||
break;
|
|
||||||
case BitTorrent::TorrentState::MissingFiles:
|
case BitTorrent::TorrentState::MissingFiles:
|
||||||
str = tr("Missing Files");
|
return tr("Missing Files");
|
||||||
break;
|
|
||||||
case BitTorrent::TorrentState::Error:
|
case BitTorrent::TorrentState::Error:
|
||||||
str = tr("Errored", "torrent status, the torrent has an error");
|
return tr("Errored", "Torrent status, the torrent has an error");
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
str = "";
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
return str;
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -160,11 +160,11 @@ QVariant TransferListModel::headerData(int section, Qt::Orientation orientation,
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant TransferListModel::data(const QModelIndex &index, int role) const
|
QVariant TransferListModel::data(const QModelIndex &index, const int role) const
|
||||||
{
|
{
|
||||||
if (!index.isValid()) return {};
|
if (!index.isValid()) return {};
|
||||||
|
|
||||||
BitTorrent::TorrentHandle *const torrent = m_torrents.value(index.row());
|
const BitTorrent::TorrentHandle *torrent = m_torrents.value(index.row());
|
||||||
if (!torrent) return {};
|
if (!torrent) return {};
|
||||||
|
|
||||||
if ((role == Qt::DecorationRole) && (index.column() == TR_NAME))
|
if ((role == Qt::DecorationRole) && (index.column() == TR_NAME))
|
||||||
|
@ -258,7 +258,7 @@ bool TransferListModel::setData(const QModelIndex &index, const QVariant &value,
|
||||||
BitTorrent::TorrentHandle *const torrent = m_torrents.value(index.row());
|
BitTorrent::TorrentHandle *const torrent = m_torrents.value(index.row());
|
||||||
if (!torrent) return false;
|
if (!torrent) return false;
|
||||||
|
|
||||||
// Category, seed date and Name columns can be edited
|
// Category and Name columns can be edited
|
||||||
switch (index.column()) {
|
switch (index.column()) {
|
||||||
case TR_NAME:
|
case TR_NAME:
|
||||||
torrent->setName(value.toString());
|
torrent->setName(value.toString());
|
||||||
|
@ -275,7 +275,7 @@ bool TransferListModel::setData(const QModelIndex &index, const QVariant &value,
|
||||||
|
|
||||||
void TransferListModel::addTorrent(BitTorrent::TorrentHandle *const torrent)
|
void TransferListModel::addTorrent(BitTorrent::TorrentHandle *const torrent)
|
||||||
{
|
{
|
||||||
if (m_torrents.indexOf(torrent) == -1) {
|
if (!m_torrents.contains(torrent)) {
|
||||||
const int row = m_torrents.size();
|
const int row = m_torrents.size();
|
||||||
beginInsertRows(QModelIndex(), row, row);
|
beginInsertRows(QModelIndex(), row, row);
|
||||||
m_torrents << torrent;
|
m_torrents << torrent;
|
||||||
|
@ -322,7 +322,7 @@ void TransferListModel::handleTorrentsUpdated()
|
||||||
|
|
||||||
// Static functions
|
// Static functions
|
||||||
|
|
||||||
QIcon getIconByState(BitTorrent::TorrentState state)
|
QIcon getIconByState(const BitTorrent::TorrentState state)
|
||||||
{
|
{
|
||||||
switch (state) {
|
switch (state) {
|
||||||
case BitTorrent::TorrentState::Downloading:
|
case BitTorrent::TorrentState::Downloading:
|
||||||
|
@ -359,7 +359,7 @@ QIcon getIconByState(BitTorrent::TorrentState state)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QColor getColorByState(BitTorrent::TorrentState state)
|
QColor getColorByState(const BitTorrent::TorrentState state)
|
||||||
{
|
{
|
||||||
// Color names taken from http://cloford.com/resources/colours/500col.htm
|
// Color names taken from http://cloford.com/resources/colours/500col.htm
|
||||||
bool dark = isDarkTheme();
|
bool dark = isDarkTheme();
|
||||||
|
|
|
@ -114,13 +114,11 @@ bool TransferListSortModel::lessThan(const QModelIndex &left, const QModelIndex
|
||||||
|
|
||||||
case TransferListModel::TR_ADD_DATE:
|
case TransferListModel::TR_ADD_DATE:
|
||||||
case TransferListModel::TR_SEED_DATE:
|
case TransferListModel::TR_SEED_DATE:
|
||||||
case TransferListModel::TR_SEEN_COMPLETE_DATE: {
|
case TransferListModel::TR_SEEN_COMPLETE_DATE:
|
||||||
return dateLessThan(sortColumn(), left, right, true);
|
return dateLessThan(sortColumn(), left, right, true);
|
||||||
}
|
|
||||||
|
|
||||||
case TransferListModel::TR_QUEUE_POSITION: {
|
case TransferListModel::TR_QUEUE_POSITION:
|
||||||
return lowerPositionThan(left, right);
|
return lowerPositionThan(left, right);
|
||||||
}
|
|
||||||
|
|
||||||
case TransferListModel::TR_SEEDS:
|
case TransferListModel::TR_SEEDS:
|
||||||
case TransferListModel::TR_PEERS: {
|
case TransferListModel::TR_PEERS: {
|
||||||
|
@ -140,20 +138,22 @@ bool TransferListSortModel::lessThan(const QModelIndex &left, const QModelIndex
|
||||||
}
|
}
|
||||||
|
|
||||||
case TransferListModel::TR_ETA: {
|
case TransferListModel::TR_ETA: {
|
||||||
const TransferListModel *model = qobject_cast<TransferListModel *>(sourceModel());
|
|
||||||
|
|
||||||
// Sorting rules prioritized.
|
// Sorting rules prioritized.
|
||||||
// 1. Active torrents at the top
|
// 1. Active torrents at the top
|
||||||
// 2. Seeding torrents at the bottom
|
// 2. Seeding torrents at the bottom
|
||||||
// 3. Torrents with invalid ETAs at the bottom
|
// 3. Torrents with invalid ETAs at the bottom
|
||||||
|
|
||||||
const bool isActiveL = TorrentFilter::ActiveTorrent.match(model->torrentHandle(model->index(left.row())));
|
const TransferListModel *model = qobject_cast<TransferListModel *>(sourceModel());
|
||||||
const bool isActiveR = TorrentFilter::ActiveTorrent.match(model->torrentHandle(model->index(right.row())));
|
|
||||||
|
// From QSortFilterProxyModel::lessThan() documentation:
|
||||||
|
// "Note: The indices passed in correspond to the source model"
|
||||||
|
const bool isActiveL = TorrentFilter::ActiveTorrent.match(model->torrentHandle(left));
|
||||||
|
const bool isActiveR = TorrentFilter::ActiveTorrent.match(model->torrentHandle(right));
|
||||||
if (isActiveL != isActiveR)
|
if (isActiveL != isActiveR)
|
||||||
return isActiveL;
|
return isActiveL;
|
||||||
|
|
||||||
const int queuePosL = model->data(model->index(left.row(), TransferListModel::TR_QUEUE_POSITION)).toInt();
|
const int queuePosL = left.sibling(left.row(), TransferListModel::TR_QUEUE_POSITION).data().toInt();
|
||||||
const int queuePosR = model->data(model->index(right.row(), TransferListModel::TR_QUEUE_POSITION)).toInt();
|
const int queuePosR = right.sibling(right.row(), TransferListModel::TR_QUEUE_POSITION).data().toInt();
|
||||||
const bool isSeedingL = (queuePosL < 0);
|
const bool isSeedingL = (queuePosL < 0);
|
||||||
const bool isSeedingR = (queuePosR < 0);
|
const bool isSeedingR = (queuePosR < 0);
|
||||||
if (isSeedingL != isSeedingR) {
|
if (isSeedingL != isSeedingR) {
|
||||||
|
@ -201,22 +201,20 @@ bool TransferListSortModel::lessThan(const QModelIndex &left, const QModelIndex
|
||||||
return (vL < vR);
|
return (vL < vR);
|
||||||
}
|
}
|
||||||
|
|
||||||
default: {
|
default:
|
||||||
if (left.data() != right.data())
|
if (left.data() != right.data())
|
||||||
return QSortFilterProxyModel::lessThan(left, right);
|
return QSortFilterProxyModel::lessThan(left, right);
|
||||||
|
|
||||||
return lowerPositionThan(left, right);
|
return lowerPositionThan(left, right);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TransferListSortModel::lowerPositionThan(const QModelIndex &left, const QModelIndex &right) const
|
bool TransferListSortModel::lowerPositionThan(const QModelIndex &left, const QModelIndex &right) const
|
||||||
{
|
{
|
||||||
const TransferListModel *model = qobject_cast<TransferListModel *>(sourceModel());
|
|
||||||
|
|
||||||
// Sort according to TR_QUEUE_POSITION
|
// Sort according to TR_QUEUE_POSITION
|
||||||
const int queueL = model->data(model->index(left.row(), TransferListModel::TR_QUEUE_POSITION)).toInt();
|
const int queueL = left.sibling(left.row(), TransferListModel::TR_QUEUE_POSITION).data().toInt();
|
||||||
const int queueR = model->data(model->index(right.row(), TransferListModel::TR_QUEUE_POSITION)).toInt();
|
const int queueR = right.sibling(right.row(), TransferListModel::TR_QUEUE_POSITION).data().toInt();
|
||||||
|
|
||||||
if ((queueL > 0) || (queueR > 0)) {
|
if ((queueL > 0) || (queueR > 0)) {
|
||||||
if ((queueL > 0) && (queueR > 0))
|
if ((queueL > 0) && (queueR > 0))
|
||||||
return queueL < queueR;
|
return queueL < queueR;
|
||||||
|
@ -233,9 +231,9 @@ bool TransferListSortModel::lowerPositionThan(const QModelIndex &left, const QMo
|
||||||
// (detailed discussion in #2526 and #2158).
|
// (detailed discussion in #2526 and #2158).
|
||||||
bool TransferListSortModel::dateLessThan(const int dateColumn, const QModelIndex &left, const QModelIndex &right, bool sortInvalidInBottom) const
|
bool TransferListSortModel::dateLessThan(const int dateColumn, const QModelIndex &left, const QModelIndex &right, bool sortInvalidInBottom) const
|
||||||
{
|
{
|
||||||
const TransferListModel *model = qobject_cast<TransferListModel *>(sourceModel());
|
const QDateTime dateL = left.sibling(left.row(), dateColumn).data().toDateTime();
|
||||||
const QDateTime dateL = model->data(model->index(left.row(), dateColumn)).toDateTime();
|
const QDateTime dateR = right.sibling(right.row(), dateColumn).data().toDateTime();
|
||||||
const QDateTime dateR = model->data(model->index(right.row(), dateColumn)).toDateTime();
|
|
||||||
if (dateL.isValid() && dateR.isValid()) {
|
if (dateL.isValid() && dateR.isValid()) {
|
||||||
if (dateL != dateR)
|
if (dateL != dateR)
|
||||||
return dateL < dateR;
|
return dateL < dateR;
|
||||||
|
@ -248,23 +246,24 @@ bool TransferListSortModel::dateLessThan(const int dateColumn, const QModelIndex
|
||||||
}
|
}
|
||||||
|
|
||||||
// Finally, sort by hash
|
// Finally, sort by hash
|
||||||
const QString hashL(model->torrentHandle(model->index(left.row()))->hash());
|
const TransferListModel *model = qobject_cast<TransferListModel *>(sourceModel());
|
||||||
const QString hashR(model->torrentHandle(model->index(right.row()))->hash());
|
const QString hashL = model->torrentHandle(left)->hash();
|
||||||
|
const QString hashR = model->torrentHandle(right)->hash();
|
||||||
return hashL < hashR;
|
return hashL < hashR;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TransferListSortModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
|
bool TransferListSortModel::filterAcceptsRow(const int sourceRow, const QModelIndex &sourceParent) const
|
||||||
{
|
{
|
||||||
return matchFilter(sourceRow, sourceParent)
|
return matchFilter(sourceRow, sourceParent)
|
||||||
&& QSortFilterProxyModel::filterAcceptsRow(sourceRow, sourceParent);
|
&& QSortFilterProxyModel::filterAcceptsRow(sourceRow, sourceParent);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TransferListSortModel::matchFilter(int sourceRow, const QModelIndex &sourceParent) const
|
bool TransferListSortModel::matchFilter(const int sourceRow, const QModelIndex &sourceParent) const
|
||||||
{
|
{
|
||||||
auto *model = qobject_cast<TransferListModel *>(sourceModel());
|
const auto *model = qobject_cast<TransferListModel *>(sourceModel());
|
||||||
if (!model) return false;
|
if (!model) return false;
|
||||||
|
|
||||||
BitTorrent::TorrentHandle *const torrent = model->torrentHandle(model->index(sourceRow, 0, sourceParent));
|
const BitTorrent::TorrentHandle *torrent = model->torrentHandle(model->index(sourceRow, 0, sourceParent));
|
||||||
if (!torrent) return false;
|
if (!torrent) return false;
|
||||||
|
|
||||||
return m_filter.match(torrent);
|
return m_filter.match(torrent);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue