mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-05-19 14:30:43 -04:00
fixed the sorting of SearchDialog by age and by size, by using proper delegates for displaying the numbers. Removed the SR_REALSIZE_COL column, that is no longer necessary.
git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@2840 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
996e930f70
commit
bffcbfe467
4 changed files with 121 additions and 63 deletions
70
retroshare-gui/src/gui/RSHumanReadableDelegate.h
Normal file
70
retroshare-gui/src/gui/RSHumanReadableDelegate.h
Normal file
|
@ -0,0 +1,70 @@
|
|||
/****************************************************************
|
||||
* RetroShare is distributed under the following license:
|
||||
*
|
||||
* Copyright (C) 2010 Cyril Soler
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
****************************************************************/
|
||||
|
||||
|
||||
/** Use this class for displaying dates and sizes in a readable format, while allowing to read the
|
||||
* real size in the column.
|
||||
*
|
||||
* To use:
|
||||
*
|
||||
* - in the QABstractItemView constructor, do a
|
||||
*
|
||||
* myView->setItemDelegateForColumn(SR_SIZE_COL,new RSHumanReadableSizeDelegate()) ;
|
||||
*
|
||||
* - each field must be filled with a string that allows a proper sorting based on lexicographic
|
||||
* order. For Sizes, use this:
|
||||
*
|
||||
* myView->setText(SR_SIZE_COL, QString("%1").arg(dir.count,(int)15,(int)10));
|
||||
*
|
||||
* Note: there's no .cpp file, because the code here is really simple.
|
||||
*/
|
||||
|
||||
#include <QItemDelegate>
|
||||
#include <util/misc.h>
|
||||
|
||||
class RSHumanReadableDelegate: public QAbstractItemDelegate
|
||||
{
|
||||
public:
|
||||
virtual QSize sizeHint(const QStyleOptionViewItem&, const QModelIndex&) const
|
||||
{
|
||||
return QSize(50,17) ;
|
||||
}
|
||||
virtual void paint(QPainter *painter,const QStyleOptionViewItem & option, const QModelIndex & index) const = 0;
|
||||
};
|
||||
|
||||
class RSHumanReadableAgeDelegate: public RSHumanReadableDelegate
|
||||
{
|
||||
public:
|
||||
virtual void paint(QPainter *painter,const QStyleOptionViewItem & option, const QModelIndex & index) const
|
||||
{
|
||||
painter->drawText(option.rect, Qt::AlignCenter, misc::userFriendlyDuration(index.data().toLongLong())) ;
|
||||
}
|
||||
};
|
||||
|
||||
class RSHumanReadableSizeDelegate: public RSHumanReadableDelegate
|
||||
{
|
||||
public:
|
||||
virtual void paint(QPainter *painter,const QStyleOptionViewItem & option, const QModelIndex & index) const
|
||||
{
|
||||
painter->drawText(option.rect, Qt::AlignRight, misc::friendlyUnit(index.data().toULongLong()));
|
||||
}
|
||||
};
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue