Sort participants list in the chat lobby case insensitive.

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@5186 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
thunder2 2012-05-24 19:26:43 +00:00
parent 55b6211e7e
commit 50bc57b0fe
4 changed files with 124 additions and 4 deletions

View file

@ -0,0 +1,76 @@
/****************************************************************
* This file is distributed under the following license:
*
* Copyright (c) 2012, RetroShare Team
*
* 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.
****************************************************************/
#include "RSListWidgetItem.h"
RSListWidgetItem::RSListWidgetItem(QListWidget *view, int type) : QListWidgetItem(view, type)
{
}
RSListWidgetItem::RSListWidgetItem(const QString &text, QListWidget *view, int type) : QListWidgetItem(text, view, type)
{
}
RSListWidgetItem::RSListWidgetItem(const QIcon &icon, const QString &text, QListWidget *view, int type) : QListWidgetItem(icon, text, view, type)
{
}
RSListWidgetItem::RSListWidgetItem(const QListWidgetItem &other) : QListWidgetItem(other)
{
}
static uint typeOfVariant(const QVariant &value)
{
//return 0 for integer, 1 for floating point and 2 for other
switch (value.userType()) {
case QVariant::Bool:
case QVariant::Int:
case QVariant::UInt:
case QVariant::LongLong:
case QVariant::ULongLong:
case QVariant::Char:
case QMetaType::Short:
case QMetaType::UShort:
case QMetaType::UChar:
case QMetaType::ULong:
case QMetaType::Long:
return 0;
case QVariant::Double:
case QMetaType::Float:
return 1;
}
return 2;
}
bool RSListWidgetItem::operator<(const QListWidgetItem &other) const
{
const QVariant v1 = data(Qt::DisplayRole);
const QVariant v2 = other.data(Qt::DisplayRole);
switch (qMax(typeOfVariant(v1), typeOfVariant(v2))) {
case 0: //integer type
return v1.toLongLong() < v2.toLongLong();
case 1: //floating point
return v1.toReal() < v2.toReal();
}
return (v1.toString().compare (v2.toString(), Qt::CaseInsensitive) < 0);
}

View file

@ -0,0 +1,39 @@
/****************************************************************
* This file is distributed under the following license:
*
* Copyright (c) 2012, RetroShare Team
*
* 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.
****************************************************************/
#ifndef _RSLISTWIDGETITEM_H
#define _RSLISTWIDGETITEM_H
#include <QListWidgetItem>
class RSListWidgetItem : public QListWidgetItem
{
public:
RSListWidgetItem(QListWidget *view = 0, int type = Type);
RSListWidgetItem(const QString &text, QListWidget *view = 0, int type = Type);
RSListWidgetItem(const QIcon &icon, const QString &text, QListWidget *view = 0, int type = Type);
RSListWidgetItem(const QListWidgetItem &other);
bool operator<(const QListWidgetItem &other) const;
};
#endif