mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-12-29 01:16:20 -05:00
Fixed sorting (case insensitive, numbers) in SearchDialog.
git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@5207 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
e5a25b94f0
commit
0989897696
@ -86,6 +86,9 @@ ChatLobbyWidget::ChatLobbyWidget(QWidget *parent, Qt::WFlags flags)
|
||||
|
||||
ChatLobbyWidget::~ChatLobbyWidget()
|
||||
{
|
||||
if (compareRole) {
|
||||
delete(compareRole);
|
||||
}
|
||||
}
|
||||
|
||||
void ChatLobbyWidget::lobbyTreeWidgetCostumPopupMenu()
|
||||
|
@ -33,6 +33,7 @@
|
||||
#include "gui/common/FilesDefs.h"
|
||||
#include "settings/rsharesettings.h"
|
||||
#include "advsearch/advancedsearchdialog.h"
|
||||
#include "common/RSTreeWidgetItem.h"
|
||||
|
||||
#include <retroshare/rsfiles.h>
|
||||
#include <retroshare/rsturtle.h>
|
||||
@ -55,6 +56,7 @@
|
||||
#define SS_DATA_COL SS_TEXT_COL
|
||||
|
||||
#define ROLE_KEYWORDS Qt::UserRole
|
||||
#define ROLE_SORT Qt::UserRole + 1
|
||||
|
||||
#define IMAGE_COPYLINK ":/images/copyrslink.png"
|
||||
|
||||
@ -126,6 +128,13 @@ SearchDialog::SearchDialog(QWidget *parent)
|
||||
connect(ui.filterLineEdit, SIGNAL(textChanged(QString)), this, SLOT(filterItems()));
|
||||
connect( ui.filterColumnComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(filterItems()));
|
||||
|
||||
compareSummaryRole = new RSTreeWidgetItemCompareRole;
|
||||
compareSummaryRole->setRole(SS_COUNT_COL, ROLE_SORT);
|
||||
|
||||
compareResultRole = new RSTreeWidgetItemCompareRole;
|
||||
compareResultRole->setRole(SR_SIZE_COL, ROLE_SORT);
|
||||
compareResultRole->setRole(SR_AGE_COL, ROLE_SORT);
|
||||
|
||||
/* hide the Tree +/- */
|
||||
ui.searchResultWidget -> setRootIsDecorated( true );
|
||||
ui.searchResultWidget -> setColumnHidden( SR_UID_COL,true );
|
||||
@ -200,6 +209,13 @@ SearchDialog::~SearchDialog()
|
||||
{
|
||||
// save settings
|
||||
processSettings(false);
|
||||
|
||||
if (compareSummaryRole) {
|
||||
delete(compareSummaryRole);
|
||||
}
|
||||
if (compareResultRole) {
|
||||
delete(compareResultRole);
|
||||
}
|
||||
}
|
||||
|
||||
void SearchDialog::processSettings(bool bLoad)
|
||||
@ -545,13 +561,14 @@ void SearchDialog::initSearchResult(const QString& txt, qulonglong searchId, int
|
||||
{
|
||||
QString sid_hexa = QString::number(searchId,16) ;
|
||||
|
||||
QTreeWidgetItem *item2 = new QTreeWidgetItem();
|
||||
QTreeWidgetItem *item2 = new RSTreeWidgetItem(compareSummaryRole);
|
||||
if (fileType == FILETYPE_IDX_ANY) {
|
||||
item2->setText(SS_TEXT_COL, txt);
|
||||
} else {
|
||||
item2->setText(SS_TEXT_COL, txt + " (" + ui.FileTypeComboBox->itemText(fileType) + ")");
|
||||
}
|
||||
item2->setText(SS_COUNT_COL, QString::number(0));
|
||||
item2->setData(SS_COUNT_COL, ROLE_SORT, 0);
|
||||
item2->setText(SS_SEARCH_ID_COL, sid_hexa);
|
||||
item2->setText(SS_FILE_TYPE_COL, QString::number(fileType));
|
||||
|
||||
@ -749,19 +766,16 @@ void SearchDialog::insertDirectory(const QString &txt, qulonglong searchId, cons
|
||||
|
||||
if (dir.type == DIR_TYPE_FILE)
|
||||
{
|
||||
QTreeWidgetItem *child;
|
||||
if (item == NULL) {
|
||||
child = new QTreeWidgetItem(ui.searchResultWidget);
|
||||
} else {
|
||||
child = new QTreeWidgetItem(item);
|
||||
}
|
||||
QTreeWidgetItem *child = new RSTreeWidgetItem(compareResultRole);
|
||||
|
||||
/* translate search result for a file */
|
||||
|
||||
child->setText(SR_NAME_COL, QString::fromUtf8(dir.name.c_str()));
|
||||
child->setText(SR_HASH_COL, QString::fromStdString(dir.hash));
|
||||
child->setText(SR_SIZE_COL, QString("%1").arg(dir.count,(int)15,(int)10)); // very important for sorting
|
||||
child->setText(SR_AGE_COL, QString("%1").arg(dir.age,15,10));
|
||||
child->setText(SR_SIZE_COL, QString::number(dir.count));
|
||||
child->setData(SR_SIZE_COL, ROLE_SORT, dir.count);
|
||||
child->setText(SR_AGE_COL, QString::number(dir.age));
|
||||
child->setData(SR_AGE_COL, ROLE_SORT, dir.age);
|
||||
child->setTextAlignment( SR_SIZE_COL, Qt::AlignRight );
|
||||
|
||||
child->setText(SR_ID_COL, QString::number(1));
|
||||
@ -778,26 +792,21 @@ void SearchDialog::insertDirectory(const QString &txt, qulonglong searchId, cons
|
||||
}
|
||||
else
|
||||
{ /* it is a directory */
|
||||
QTreeWidgetItem *child;
|
||||
if (item == NULL) {
|
||||
child = new QTreeWidgetItem(ui.searchResultWidget);
|
||||
} else {
|
||||
child = new QTreeWidgetItem(item);
|
||||
}
|
||||
|
||||
QTreeWidgetItem *child = new RSTreeWidgetItem(compareResultRole);
|
||||
|
||||
child->setIcon(SR_NAME_COL, QIcon(IMAGE_DIRECTORY));
|
||||
child->setText(SR_NAME_COL, QString::fromUtf8(dir.name.c_str()));
|
||||
child->setText(SR_HASH_COL, QString::fromStdString(dir.hash));
|
||||
//child->setText(SR_SIZE_COL, misc::toQString(dir.count));
|
||||
child->setText(SR_SIZE_COL, QString("%1").arg(dir.count,15,10)); // very important for sorting
|
||||
child->setText(SR_AGE_COL, QString("%1").arg(dir.age,15,10));
|
||||
child->setText(SR_SIZE_COL, QString::number(dir.count));
|
||||
child->setData(SR_SIZE_COL, ROLE_SORT, dir.count);
|
||||
child->setText(SR_AGE_COL, QString::number(dir.age));
|
||||
child->setData(SR_AGE_COL, ROLE_SORT, dir.age);
|
||||
child->setTextAlignment( SR_SIZE_COL, Qt::AlignRight );
|
||||
child->setText(SR_ID_COL, QString::number(1));
|
||||
child->setTextAlignment( SR_ID_COL, Qt::AlignRight );
|
||||
child->setText(SR_SEARCH_ID_COL, sid_hexa);
|
||||
child->setText(SR_TYPE_COL, tr("Folder"));
|
||||
|
||||
|
||||
if (item == NULL) {
|
||||
ui.searchResultWidget->addTopLevelItem(child);
|
||||
|
||||
@ -813,14 +822,16 @@ void SearchDialog::insertDirectory(const QString &txt, qulonglong searchId, cons
|
||||
// increment result since every item is new
|
||||
int s = ui.searchSummaryWidget->topLevelItem(i)->text(SS_COUNT_COL).toInt() ;
|
||||
ui.searchSummaryWidget->topLevelItem(i)->setText(SS_COUNT_COL,QString::number(s+1));
|
||||
ui.searchSummaryWidget->topLevelItem(i)->setData(SS_COUNT_COL, ROLE_SORT, s+1);
|
||||
found = true ;
|
||||
}
|
||||
}
|
||||
if(!found)
|
||||
{
|
||||
QTreeWidgetItem *item2 = new QTreeWidgetItem();
|
||||
QTreeWidgetItem *item2 = new RSTreeWidgetItem(compareSummaryRole);
|
||||
item2->setText(SS_TEXT_COL, txt);
|
||||
item2->setText(SS_COUNT_COL, QString::number(1));
|
||||
item2->setData(SS_COUNT_COL, ROLE_SORT, 1);
|
||||
item2->setTextAlignment( SS_COUNT_COL, Qt::AlignRight );
|
||||
item2->setText(SS_SEARCH_ID_COL, sid_hexa);
|
||||
|
||||
@ -848,13 +859,15 @@ void SearchDialog::insertDirectory(const QString &txt, qulonglong searchId, cons
|
||||
return ; // Remove this statement to allow adding directories to the search results.
|
||||
|
||||
QString sid_hexa = QString::number(searchId,16) ;
|
||||
QTreeWidgetItem *child = new QTreeWidgetItem(ui.searchResultWidget);
|
||||
QTreeWidgetItem *child = new RSTreeWidgetItem(compareResultRole);
|
||||
|
||||
child->setIcon(SR_NAME_COL, QIcon(IMAGE_DIRECTORY));
|
||||
child->setText(SR_NAME_COL, QString::fromUtf8(dir.name.c_str()));
|
||||
child->setText(SR_HASH_COL, QString::fromStdString(dir.hash));
|
||||
child->setText(SR_SIZE_COL, QString("%1").arg(dir.count,(int)15,(int)10)); // very important for sorting
|
||||
child->setText(SR_AGE_COL, QString("%1").arg(dir.min_age,15,10));
|
||||
child->setText(SR_SIZE_COL, QString::number(dir.count));
|
||||
child->setData(SR_SIZE_COL, ROLE_SORT, dir.count);
|
||||
child->setText(SR_AGE_COL, QString::number(dir.min_age));
|
||||
child->setData(SR_AGE_COL, ROLE_SORT, dir.min_age);
|
||||
child->setTextAlignment( SR_SIZE_COL, Qt::AlignRight );
|
||||
child->setText(SR_ID_COL, QString::number(1));
|
||||
child->setTextAlignment( SR_ID_COL, Qt::AlignRight );
|
||||
@ -875,14 +888,16 @@ void SearchDialog::insertDirectory(const QString &txt, qulonglong searchId, cons
|
||||
// increment result since every item is new
|
||||
int s = ui.searchSummaryWidget->topLevelItem(i)->text(SS_COUNT_COL).toInt() ;
|
||||
ui.searchSummaryWidget->topLevelItem(i)->setText(SS_COUNT_COL,QString::number(s+1));
|
||||
ui.searchSummaryWidget->topLevelItem(i)->setData(SS_COUNT_COL, ROLE_SORT, s+1);
|
||||
found = true ;
|
||||
}
|
||||
}
|
||||
if(!found)
|
||||
{
|
||||
QTreeWidgetItem *item2 = new QTreeWidgetItem();
|
||||
RSTreeWidgetItem *item2 = new RSTreeWidgetItem(compareSummaryRole);
|
||||
item2->setText(SS_TEXT_COL, txt);
|
||||
item2->setText(SS_COUNT_COL, QString::number(1));
|
||||
item2->setData(SS_COUNT_COL, ROLE_SORT, 1);
|
||||
item2->setTextAlignment( SS_COUNT_COL, Qt::AlignRight );
|
||||
item2->setText(SS_SEARCH_ID_COL, sid_hexa);
|
||||
|
||||
@ -1041,7 +1056,7 @@ void SearchDialog::insertFile(qulonglong searchId, const FileDetail& file, int s
|
||||
|
||||
/* translate search results */
|
||||
|
||||
QTreeWidgetItem *item = new QTreeWidgetItem();
|
||||
QTreeWidgetItem *item = new RSTreeWidgetItem(compareResultRole);
|
||||
item->setText(SR_NAME_COL, QString::fromUtf8(file.name.c_str()));
|
||||
item->setText(SR_HASH_COL, QString::fromStdString(file.hash));
|
||||
|
||||
@ -1051,8 +1066,10 @@ void SearchDialog::insertFile(qulonglong searchId, const FileDetail& file, int s
|
||||
* to facilitate downloads we need to save the file size too
|
||||
*/
|
||||
|
||||
item->setText(SR_SIZE_COL, QString::number(file.size).rightJustified(15, '0')); // very important for sorting
|
||||
item->setText(SR_AGE_COL, QString::number(file.age).rightJustified(15, '0'));
|
||||
item->setText(SR_SIZE_COL, QString::number(file.size));
|
||||
item->setData(SR_SIZE_COL, ROLE_SORT, file.size);
|
||||
item->setText(SR_AGE_COL, QString::number(file.age));
|
||||
item->setData(SR_AGE_COL, ROLE_SORT, file.age);
|
||||
item->setTextAlignment( SR_SIZE_COL, Qt::AlignRight );
|
||||
if(searchType == FRIEND_SEARCH)
|
||||
{
|
||||
@ -1108,6 +1125,7 @@ void SearchDialog::insertFile(qulonglong searchId, const FileDetail& file, int s
|
||||
{
|
||||
int s = ui.searchSummaryWidget->topLevelItem(summaryItemIndex)->text(SS_COUNT_COL).toInt() ;
|
||||
ui.searchSummaryWidget->topLevelItem(summaryItemIndex)->setText(SS_COUNT_COL,QString::number(s+1));
|
||||
ui.searchSummaryWidget->topLevelItem(summaryItemIndex)->setData(SS_COUNT_COL, ROLE_SORT, s+1);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -28,6 +28,7 @@
|
||||
|
||||
class AdvancedSearchDialog;
|
||||
class Expression;
|
||||
class RSTreeWidgetItemCompareRole;
|
||||
|
||||
#define FRIEND_SEARCH 1
|
||||
#define ANONYMOUS_SEARCH 2
|
||||
@ -126,6 +127,9 @@ private:
|
||||
|
||||
int nextSearchId;
|
||||
|
||||
RSTreeWidgetItemCompareRole *compareSummaryRole;
|
||||
RSTreeWidgetItemCompareRole *compareResultRole;
|
||||
|
||||
/** Qt Designer generated object */
|
||||
Ui::SearchDialog ui;
|
||||
|
||||
|
@ -65,6 +65,11 @@ RSTreeWidgetItem::RSTreeWidgetItem(const RSTreeWidgetItemCompareRole *compareRol
|
||||
m_compareRole = compareRole;
|
||||
}
|
||||
|
||||
RSTreeWidgetItem::RSTreeWidgetItem(const RSTreeWidgetItemCompareRole *compareRole, QTreeWidget *view, int type) : QTreeWidgetItem(view, type)
|
||||
{
|
||||
m_compareRole = compareRole;
|
||||
}
|
||||
|
||||
RSTreeWidgetItem::RSTreeWidgetItem(const RSTreeWidgetItemCompareRole *compareRole, QTreeWidget *view, const QStringList &strings, int type) : QTreeWidgetItem(view, strings, type)
|
||||
{
|
||||
m_compareRole = compareRole;
|
||||
@ -75,6 +80,11 @@ RSTreeWidgetItem::RSTreeWidgetItem(const RSTreeWidgetItemCompareRole *compareRol
|
||||
m_compareRole = compareRole;
|
||||
}
|
||||
|
||||
RSTreeWidgetItem::RSTreeWidgetItem(const RSTreeWidgetItemCompareRole *compareRole, QTreeWidgetItem *parent, int type) : QTreeWidgetItem(parent, type)
|
||||
{
|
||||
m_compareRole = compareRole;
|
||||
}
|
||||
|
||||
RSTreeWidgetItem::RSTreeWidgetItem(const RSTreeWidgetItemCompareRole *compareRole, QTreeWidgetItem *parent, const QStringList &strings, int type) : QTreeWidgetItem(parent, strings, type)
|
||||
{
|
||||
m_compareRole = compareRole;
|
||||
|
@ -43,8 +43,10 @@ class RSTreeWidgetItem : public QTreeWidgetItem
|
||||
public:
|
||||
RSTreeWidgetItem(const RSTreeWidgetItemCompareRole *compareRole = NULL, int type = Type);
|
||||
RSTreeWidgetItem(const RSTreeWidgetItemCompareRole *compareRole, const QStringList &strings, int type = Type);
|
||||
RSTreeWidgetItem(const RSTreeWidgetItemCompareRole *compareRole, QTreeWidget *view, int type = Type);
|
||||
RSTreeWidgetItem(const RSTreeWidgetItemCompareRole *compareRole, QTreeWidget *view, const QStringList &strings, int type = Type);
|
||||
RSTreeWidgetItem(const RSTreeWidgetItemCompareRole *compareRole, QTreeWidget *view, QTreeWidgetItem *after, int type = Type);
|
||||
RSTreeWidgetItem(const RSTreeWidgetItemCompareRole *compareRole, QTreeWidgetItem *parent, int type = Type);
|
||||
RSTreeWidgetItem(const RSTreeWidgetItemCompareRole *compareRole, QTreeWidgetItem *parent, const QStringList &strings, int type = Type);
|
||||
RSTreeWidgetItem(const RSTreeWidgetItemCompareRole *compareRole, QTreeWidgetItem *parent, QTreeWidgetItem *after, int type = Type);
|
||||
RSTreeWidgetItem(const RSTreeWidgetItemCompareRole *compareRole, const QTreeWidgetItem &other);
|
||||
|
Loading…
Reference in New Issue
Block a user