mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-06-06 21:58:57 -04:00
Merge pull request #1086 from PhenomRetroShare/Fix_SpeedQueuePositionSorting
Fix Speed/Queue Position column sorting
This commit is contained in:
commit
b42694165a
3 changed files with 39 additions and 42 deletions
|
@ -187,15 +187,32 @@ void DLListDelegate::paint(QPainter * painter, const QStyleOptionViewItem & opti
|
||||||
}
|
}
|
||||||
painter->drawText(option.rect, Qt::AlignCenter, newopt.text);
|
painter->drawText(option.rect, Qt::AlignCenter, newopt.text);
|
||||||
break;
|
break;
|
||||||
case COLUMN_SOURCES:
|
case COLUMN_SOURCES:
|
||||||
{
|
{
|
||||||
double dblValue = index.data().toDouble();
|
double dblValue = index.data().toDouble();
|
||||||
|
|
||||||
temp = dblValue!=0 ? QString("%1 (%2)").arg((int)dblValue).arg((int)((fmod(dblValue,1)*1000)+0.5)) : "";
|
temp = dblValue!=0 ? QString("%1 (%2)").arg((int)dblValue).arg((int)((fmod(dblValue,1)*1000)+0.5)) : "";
|
||||||
painter->drawText(option.rect, Qt::AlignCenter, temp);
|
painter->drawText(option.rect, Qt::AlignCenter, temp);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case COLUMN_DOWNLOADTIME:
|
case COLUMN_PRIORITY:
|
||||||
|
{
|
||||||
|
double dblValue = index.data().toDouble();
|
||||||
|
if (dblValue == PRIORITY_NULL)
|
||||||
|
temp = "";
|
||||||
|
else if (dblValue == PRIORITY_FASTER)
|
||||||
|
temp = tr("Faster");
|
||||||
|
else if (dblValue == PRIORITY_AVERAGE)
|
||||||
|
temp = tr("Average");
|
||||||
|
else if (dblValue == PRIORITY_SLOWER)
|
||||||
|
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();
|
downloadtime = index.data().toLongLong();
|
||||||
minutes = downloadtime / 60;
|
minutes = downloadtime / 60;
|
||||||
seconds = downloadtime % 60;
|
seconds = downloadtime % 60;
|
||||||
|
|
|
@ -42,6 +42,11 @@
|
||||||
#define COLUMN_PATH 12
|
#define COLUMN_PATH 12
|
||||||
#define COLUMN_COUNT 13
|
#define COLUMN_COUNT 13
|
||||||
|
|
||||||
|
#define PRIORITY_NULL 0.0
|
||||||
|
#define PRIORITY_FASTER 0.1
|
||||||
|
#define PRIORITY_AVERAGE 0.2
|
||||||
|
#define PRIORITY_SLOWER 0.3
|
||||||
|
|
||||||
|
|
||||||
#define MAX_CHAR_TMP 128
|
#define MAX_CHAR_TMP 128
|
||||||
|
|
||||||
|
|
|
@ -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 */
|
/** Constructor */
|
||||||
TransfersDialog::TransfersDialog(QWidget *parent)
|
TransfersDialog::TransfersDialog(QWidget *parent)
|
||||||
: RsAutoUpdatePage(1000,parent)
|
: RsAutoUpdatePage(1000,parent)
|
||||||
|
@ -911,16 +885,18 @@ int TransfersDialog::addDLItem(int row, const FileInfo &fileInfo)
|
||||||
default: status = tr("Unknown"); break;
|
default: status = tr("Unknown"); break;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString priority;
|
double priority = PRIORITY_NULL;
|
||||||
|
|
||||||
if (fileInfo.downloadStatus == FT_STATE_QUEUED) {
|
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 {
|
} else {
|
||||||
switch (fileInfo.priority) {
|
switch (fileInfo.priority) {
|
||||||
case SPEED_LOW: priority = tr("Slower");break;
|
case SPEED_LOW: priority = PRIORITY_SLOWER; break;
|
||||||
case SPEED_NORMAL: priority = tr("Average");break;
|
case SPEED_NORMAL: priority = PRIORITY_AVERAGE; break;
|
||||||
case SPEED_HIGH: priority = tr("Faster");break;
|
case SPEED_HIGH: priority = PRIORITY_FASTER; break;
|
||||||
default: priority = tr("Average");break;
|
default: priority = PRIORITY_AVERAGE; break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -982,7 +958,6 @@ int TransfersDialog::addDLItem(int row, const FileInfo &fileInfo)
|
||||||
|
|
||||||
// change progress column to own class for sorting
|
// change progress column to own class for sorting
|
||||||
DLListModel->setItem(row, COLUMN_PROGRESS, new ProgressItem(NULL));
|
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_SIZE), QVariant((qlonglong) fileInfo.size));
|
||||||
DLListModel->setData(DLListModel->index(row, COLUMN_ID), fileHash, Qt::DisplayRole);
|
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);
|
iProgress->setData(QVariant::fromValue(peerInfo), Qt::UserRole);
|
||||||
iSource->setData(QVariant(QString()), Qt::DisplayRole);
|
iSource->setData(QVariant(QString()), Qt::DisplayRole);
|
||||||
|
|
||||||
iPriority->setData(QVariant(QString()), Qt::DisplayRole); // blank field for priority
|
iPriority->setData(QVariant((double)PRIORITY_NULL), Qt::DisplayRole); // blank field for priority
|
||||||
iRemaining->setData(QVariant(QString()), Qt::DisplayRole);
|
iRemaining->setData(QVariant(QString()), Qt::DisplayRole);
|
||||||
iDownloadTime->setData(QVariant(QString()), Qt::DisplayRole);
|
iDownloadTime->setData(QVariant(QString()), Qt::DisplayRole);
|
||||||
iID->setData(QVariant() , Qt::DisplayRole);
|
iID->setData(QVariant() , Qt::DisplayRole);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue