Added new class RSTreeWidgetItem derived from QTreeWidgetItem for sorting strings case insensitive without proxy model.

Sort strings case insensitive in NetworkDialog, PeersDialog (changed to RSTreeWidgetItem), MessengerWindow (changed to RSTreeWidgetItem) and SharedFilesDialog (with folders first).
Sort the columns size and age in SharedFilesDialog by internal data and not by the shown string.
Save and load layout of the SharedFilesDialog in profile.


git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@3515 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
thunder2 2010-09-20 00:10:51 +00:00
parent 52e0d2a095
commit a51bf3da67
12 changed files with 407 additions and 106 deletions

View file

@ -42,8 +42,8 @@
#include "chat/PopupChatDialog.h"
#include "msgs/MessageComposer.h"
#include "ShareManager.h"
#include "gui/notifyqt.h"
#include "gui/connect/ConnectFriendWizard.h"
#include "notifyqt.h"
#include "connect/ConnectFriendWizard.h"
#endif // MINIMAL_RSGUI
#include "PeersDialog.h"
#include "connect/ConfCertDialog.h"
@ -51,6 +51,7 @@
#include "LogoBar.h"
#include "util/Widget.h"
#include "settings/rsharesettings.h"
#include "common/RSTreeWidgetItem.h"
#include "RetroShareLink.h"
@ -87,36 +88,6 @@
MessengerWindow* MessengerWindow::_instance = NULL;
static std::set<std::string> *expandedPeers = NULL;
// quick and dirty for sorting, better use QTreeView and QSortFilterProxyModel
class MyMessengerTreeWidgetItem : public QTreeWidgetItem
{
public:
MyMessengerTreeWidgetItem(QTreeWidget *pWidget, int type) : QTreeWidgetItem(type)
{
m_pWidget = pWidget; // can't access the member "view"
}
bool operator<(const QTreeWidgetItem &other) const
{
int column = m_pWidget ? m_pWidget->sortColumn() : 0;
switch (column) {
case COLUMN_NAME:
{
const QVariant v1 = data(column, ROLE_SORT);
const QVariant v2 = other.data(column, ROLE_SORT);
return (v1.toString().compare (v2.toString(), Qt::CaseInsensitive) < 0);
}
}
// let the standard do the sort
return QTreeWidgetItem::operator<(other);
}
private:
QTreeWidget *m_pWidget; // the member "view" is private
};
/*static*/ void MessengerWindow::showYourself ()
{
if (_instance == NULL) {
@ -156,6 +127,9 @@ MessengerWindow::MessengerWindow(QWidget* parent, Qt::WFlags flags)
setAttribute (Qt::WA_QuitOnClose, true);
#endif // MINIMAL_RSGUI
m_compareRole = new RSTreeWidgetItemCompareRole;
m_compareRole->addRole(COLUMN_NAME, ROLE_SORT);
connect( ui.messengertreeWidget, SIGNAL( customContextMenuRequested( QPoint ) ), this, SLOT( messengertreeWidgetCostumPopupMenu( QPoint ) ) );
#ifndef MINIMAL_RSGUI
connect( ui.messengertreeWidget, SIGNAL(itemDoubleClicked ( QTreeWidgetItem *, int)), this, SLOT(chatfriend(QTreeWidgetItem *)));
@ -265,6 +239,8 @@ MessengerWindow::~MessengerWindow ()
}
#endif // MINIMAL_RSGUI
delete(m_compareRole);
_instance = NULL;
}
@ -521,7 +497,7 @@ void MessengerWindow::insertPeers()
}
if (gpg_item == NULL) {
gpg_item = new MyMessengerTreeWidgetItem(peertreeWidget, 0); //set type to 0 for custom popup menu
gpg_item = new RSTreeWidgetItem(m_compareRole, 0); //set type to 0 for custom popup menu
gpg_item->setChildIndicatorPolicy(QTreeWidgetItem::DontShowIndicatorWhenChildless);
}
@ -579,7 +555,7 @@ void MessengerWindow::insertPeers()
}
if (sslItem == NULL) {
sslItem = new MyMessengerTreeWidgetItem(peertreeWidget, 1); //set type to 1 for custom popup menu
sslItem = new RSTreeWidgetItem(m_compareRole, 1); //set type to 1 for custom popup menu
}
/* not displayed, used to find back the item */