Fix Speed/Queue Position column sorting

This commit is contained in:
Phenom 2017-10-29 16:45:45 +01:00
parent 37f6e7e13b
commit c5c406bb98
2 changed files with 34 additions and 42 deletions

View File

@ -187,15 +187,32 @@ void DLListDelegate::paint(QPainter * painter, const QStyleOptionViewItem & opti
}
painter->drawText(option.rect, Qt::AlignCenter, newopt.text);
break;
case COLUMN_SOURCES:
{
double dblValue = index.data().toDouble();
case COLUMN_SOURCES:
{
double dblValue = index.data().toDouble();
temp = dblValue!=0 ? QString("%1 (%2)").arg((int)dblValue).arg((int)((fmod(dblValue,1)*1000)+0.5)) : "";
painter->drawText(option.rect, Qt::AlignCenter, temp);
}
break;
case COLUMN_DOWNLOADTIME:
temp = dblValue!=0 ? QString("%1 (%2)").arg((int)dblValue).arg((int)((fmod(dblValue,1)*1000)+0.5)) : "";
painter->drawText(option.rect, Qt::AlignCenter, temp);
}
break;
case COLUMN_PRIORITY:
{
double dblValue = index.data().toDouble();
if (dblValue == 0.0)
temp = "";
else if (dblValue == 0.1)
temp = tr("Faster");
else if (dblValue == 0.2)
temp = tr("Average");
else if (dblValue == 0.3)
temp = tr("Slower");
else
temp = QString::number((uint32_t)dblValue);
painter->drawText(option.rect, Qt::AlignCenter, temp);
}
break;
case COLUMN_DOWNLOADTIME:
downloadtime = index.data().toLongLong();
minutes = downloadtime / 60;
seconds = downloadtime % 60;

View File

@ -159,32 +159,6 @@ public:
}
};
class PriorityItem : public SortByNameItem
{
public:
PriorityItem(QHeaderView *header) : SortByNameItem(header) {}
virtual bool operator<(const QStandardItem &other) const
{
const int role = model() ? model()->sortRole() : Qt::DisplayRole;
QString l = data(role).value<QString>();
QString r = other.data(role).value<QString>();
bool bl,br ;
int nl = l.toInt(&bl) ;
int nr = r.toInt(&br) ;
if(bl && br)
return nl < nr ;
if(bl ^ br)
return br ;
return SortByNameItem::operator<(other);
}
};
/** Constructor */
TransfersDialog::TransfersDialog(QWidget *parent)
: RsAutoUpdatePage(1000,parent)
@ -911,16 +885,18 @@ int TransfersDialog::addDLItem(int row, const FileInfo &fileInfo)
default: status = tr("Unknown"); break;
}
QString priority;
double priority = 0;
if (fileInfo.downloadStatus == FT_STATE_QUEUED) {
priority = QString::number(fileInfo.queue_position);
priority = fileInfo.queue_position;
} else if (fileInfo.downloadStatus == FT_STATE_COMPLETE) {
priority = 0;
} else {
switch (fileInfo.priority) {
case SPEED_LOW: priority = tr("Slower");break;
case SPEED_NORMAL: priority = tr("Average");break;
case SPEED_HIGH: priority = tr("Faster");break;
default: priority = tr("Average");break;
case SPEED_LOW: priority = 0.3; break;
case SPEED_NORMAL: priority = 0.2; break;
case SPEED_HIGH: priority = 0.1; break;
default: priority = 0.2; break;
}
}
@ -982,7 +958,6 @@ int TransfersDialog::addDLItem(int row, const FileInfo &fileInfo)
// change progress column to own class for sorting
DLListModel->setItem(row, COLUMN_PROGRESS, new ProgressItem(NULL));
DLListModel->setItem(row, COLUMN_PRIORITY, new PriorityItem(NULL));
DLListModel->setData(DLListModel->index(row, COLUMN_SIZE), QVariant((qlonglong) fileInfo.size));
DLListModel->setData(DLListModel->index(row, COLUMN_ID), fileHash, Qt::DisplayRole);
@ -1107,7 +1082,7 @@ int TransfersDialog::addPeerToDLItem(QStandardItem *dlItem, const RsPeerId& peer
iProgress->setData(QVariant::fromValue(peerInfo), Qt::UserRole);
iSource->setData(QVariant(QString()), Qt::DisplayRole);
iPriority->setData(QVariant(QString()), Qt::DisplayRole); // blank field for priority
iPriority->setData(QVariant((double)0.0), Qt::DisplayRole); // blank field for priority
iRemaining->setData(QVariant(QString()), Qt::DisplayRole);
iDownloadTime->setData(QVariant(QString()), Qt::DisplayRole);
iID->setData(QVariant() , Qt::DisplayRole);