From c5c406bb984578fc88adda650b5f6b18c8e09560 Mon Sep 17 00:00:00 2001 From: Phenom Date: Sun, 29 Oct 2017 16:45:45 +0100 Subject: [PATCH] Fix Speed/Queue Position column sorting --- .../src/gui/FileTransfer/DLListDelegate.cpp | 33 ++++++++++---- .../src/gui/FileTransfer/TransfersDialog.cpp | 43 ++++--------------- 2 files changed, 34 insertions(+), 42 deletions(-) diff --git a/retroshare-gui/src/gui/FileTransfer/DLListDelegate.cpp b/retroshare-gui/src/gui/FileTransfer/DLListDelegate.cpp index 56c25ce15..70359ccc4 100644 --- a/retroshare-gui/src/gui/FileTransfer/DLListDelegate.cpp +++ b/retroshare-gui/src/gui/FileTransfer/DLListDelegate.cpp @@ -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; diff --git a/retroshare-gui/src/gui/FileTransfer/TransfersDialog.cpp b/retroshare-gui/src/gui/FileTransfer/TransfersDialog.cpp index b9e961457..2d9feb9b6 100644 --- a/retroshare-gui/src/gui/FileTransfer/TransfersDialog.cpp +++ b/retroshare-gui/src/gui/FileTransfer/TransfersDialog.cpp @@ -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 r = other.data(role).value(); - - 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);