From 21feaf46da6b19351574c7af7dbf9d93578c6db6 Mon Sep 17 00:00:00 2001 From: csoler Date: Mon, 26 Sep 2011 21:39:28 +0000 Subject: [PATCH] fixed sorting of transfer by priority git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@4617 b45a01b8-16f6-495d-af2f-9b41ad6348cc --- retroshare-gui/src/gui/TransfersDialog.cpp | 27 ++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/retroshare-gui/src/gui/TransfersDialog.cpp b/retroshare-gui/src/gui/TransfersDialog.cpp index 84fbe5d9e..55fde595c 100644 --- a/retroshare-gui/src/gui/TransfersDialog.cpp +++ b/retroshare-gui/src/gui/TransfersDialog.cpp @@ -141,6 +141,32 @@ 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) @@ -580,6 +606,7 @@ int TransfersDialog::addItem(const QString&, const QString& name, const QString& // change progress column to own class for sorting DLListModel->setItem(row, PROGRESS, new ProgressItem (NULL)); + DLListModel->setItem(row, PRIORITY, new PriorityItem (NULL)); } DLListModel->setData(DLListModel->index(row, NAME), QVariant(name));