From daad701f52f1113cba8767d19a2c49b3829272f8 Mon Sep 17 00:00:00 2001 From: defnax Date: Wed, 16 Feb 2011 20:07:06 +0000 Subject: [PATCH] Added Search Filter for Search Results git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@4039 b45a01b8-16f6-495d-af2f-9b41ad6348cc --- retroshare-gui/src/gui/SearchDialog.cpp | 97 ++++++ retroshare-gui/src/gui/SearchDialog.h | 10 +- retroshare-gui/src/gui/SearchDialog.ui | 438 +++++++++++++++--------- 3 files changed, 383 insertions(+), 162 deletions(-) diff --git a/retroshare-gui/src/gui/SearchDialog.cpp b/retroshare-gui/src/gui/SearchDialog.cpp index 21130e0ac..951369450 100644 --- a/retroshare-gui/src/gui/SearchDialog.cpp +++ b/retroshare-gui/src/gui/SearchDialog.cpp @@ -74,6 +74,18 @@ const int SearchDialog::FILETYPE_IDX_DIRECTORY = 8; QMap * SearchDialog::FileTypeExtensionMap = new QMap(); bool SearchDialog::initialised = false; +static int FilterColumnFromComboBox(int nIndex) +{ + switch (nIndex) { + case 0: + return SR_NAME_COL; + case 1: + return SR_SIZE_COL; + } + + return SR_NAME_COL; +} + /** Constructor */ SearchDialog::SearchDialog(QWidget *parent) : MainPage(parent), @@ -113,6 +125,10 @@ SearchDialog::SearchDialog(QWidget *parent) this, SLOT( selectSearchResults( void ) ) ); connect(ui.FileTypeComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(selectSearchResults(int))); + + connect( ui.filterPatternLineEdit, SIGNAL(textChanged(const QString &)), this, SLOT(filterRegExpChanged())); + connect( ui.filterColumnComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(filterColumnChanged())); + connect( ui.clearButton, SIGNAL(clicked()), this, SLOT(clearFilter())); /* hide the Tree +/- */ ui.searchResultWidget -> setRootIsDecorated( true ); @@ -163,6 +179,7 @@ SearchDialog::SearchDialog(QWidget *parent) ui.searchResultWidget->sortItems(SR_NAME_COL, Qt::AscendingOrder); ui.resetButton->hide(); + ui.clearButton->hide(); ui._ownFiles_CB->setMinimumWidth(20); ui._friendListsearch_SB->setMinimumWidth(20); @@ -760,6 +777,10 @@ void SearchDialog::insertDirectory(const std::string &txt, qulonglong searchId, insertDirectory(txt, searchId, details, child); } } + + if (ui.filterPatternLineEdit->text().isEmpty() == false) { + FilterItems(); + } } void SearchDialog::insertDirectory(const std::string &txt, qulonglong searchId, const DirDetails &dir) @@ -808,6 +829,10 @@ void SearchDialog::insertDirectory(const std::string &txt, qulonglong searchId, } selectSearchResults(); + + if (ui.filterPatternLineEdit->text().isEmpty() == false) { + FilterItems(); + } // TODO: check for duplicate directories } @@ -1039,6 +1064,10 @@ void SearchDialog::insertFile(const std::string& txt,qulonglong searchId, const /* select this search result */ selectSearchResults(); + + if (ui.filterPatternLineEdit->text().isEmpty() == false) { + FilterItems(); + } } void SearchDialog::resultsToTree(std::string txt,qulonglong searchId, const std::list& results) @@ -1113,6 +1142,7 @@ void SearchDialog::selectSearchResults(int index) } } ui.searchResultWidget->update(); + ui.filterPatternLineEdit->clear(); } void SearchDialog::setIconAndType(QTreeWidgetItem *item, QString ext) @@ -1317,3 +1347,70 @@ void SearchDialog::onComboIndexChanged(int index) } } } + +/* clear Filter */ +void SearchDialog::clearFilter() +{ + ui.filterPatternLineEdit->clear(); + ui.filterPatternLineEdit->setFocus(); +} + +void SearchDialog::filterRegExpChanged() +{ + + QString text = ui.filterPatternLineEdit->text(); + + if (text.isEmpty()) { + ui.clearButton->hide(); + } else { + ui.clearButton->show(); + } + + FilterItems(); +} + +void SearchDialog::filterColumnChanged() +{ + + FilterItems(); + +} + +void SearchDialog::FilterItems() +{ + QString sPattern = ui.filterPatternLineEdit->text(); + int nFilterColumn = FilterColumnFromComboBox(ui.filterColumnComboBox->currentIndex()); + + int nCount = ui.searchResultWidget->topLevelItemCount (); + for (int nIndex = 0; nIndex < nCount; nIndex++) { + FilterItem(ui.searchResultWidget->topLevelItem(nIndex), sPattern, nFilterColumn); + } + +} + +bool SearchDialog::FilterItem(QTreeWidgetItem *pItem, QString &sPattern, int nFilterColumn) +{ + bool bVisible = true; + + if (sPattern.isEmpty() == false) { + if (pItem->text(nFilterColumn).contains(sPattern, Qt::CaseInsensitive) == false) { + bVisible = false; + } + } + + int nVisibleChildCount = 0; + int nCount = pItem->childCount(); + for (int nIndex = 0; nIndex < nCount; nIndex++) { + if (FilterItem(pItem->child(nIndex), sPattern, nFilterColumn)) { + nVisibleChildCount++; + } + } + + if (bVisible || nVisibleChildCount) { + pItem->setHidden(false); + } else { + pItem->setHidden(true); + } + + return (bVisible || nVisibleChildCount); +} diff --git a/retroshare-gui/src/gui/SearchDialog.h b/retroshare-gui/src/gui/SearchDialog.h index fc274b27b..a3fb35522 100644 --- a/retroshare-gui/src/gui/SearchDialog.h +++ b/retroshare-gui/src/gui/SearchDialog.h @@ -88,6 +88,10 @@ private slots: void onComboIndexChanged(int index); + void filterColumnChanged(); + void filterRegExpChanged(); + void clearFilter(); + private: @@ -122,10 +126,8 @@ private: static bool initialised; void initialiseFileTypeMappings(); -/**** -QTreeWidget *searchtableWidget; -QTreeWidget *searchtablewidget2; -****/ + void FilterItems(); + bool FilterItem(QTreeWidgetItem *pItem, QString &sPattern, int nFilterColumn); int nextSearchId; diff --git a/retroshare-gui/src/gui/SearchDialog.ui b/retroshare-gui/src/gui/SearchDialog.ui index 6c2cfb435..1c22e40d9 100644 --- a/retroshare-gui/src/gui/SearchDialog.ui +++ b/retroshare-gui/src/gui/SearchDialog.ui @@ -6,8 +6,8 @@ 0 0 - 580 - 376 + 574 + 344 @@ -502,14 +502,14 @@ - + 6 0 - + @@ -931,7 +931,7 @@ border-image: url(:/images/btn_26_pressed.png) 4; - + Qt::Horizontal @@ -985,75 +985,199 @@ border-image: url(:/images/btn_26_pressed.png) 4; - - - - 1 - 0 - - - - - 9 - - - - Qt::CustomContextMenu - - - true - - - QAbstractItemView::DragOnly - - - true - - - - Filename - - - - - Size - - - - - Sources - - - - - Type - - - - - Age - - - - - Hash - - + + + + + + 6 + + + 6 + + + + + 2 + + + + + + + + :/images/find-16.png + + + + + + + + 0 + 0 + + + + <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> +<html><head><meta name="qrichtext" content="1" /><style type="text/css"> +p, li { white-space: pre-wrap; } +</style></head><body style=" font-family:'Arial'; font-size:8pt; font-weight:400; font-style:normal;"> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Filter Search Result</p></body></html> + + + + + + + + 16 + 16 + + + + + 16 + 16 + + + + + MS Shell Dlg 2 + + + + Clear Filter + + + QPushButton +{ + border-image: url(:/images/closenormal.png) +} + +QPushButton:hover +{ +border-image: url(:/images/closehover.png) +} + +QPushButton:pressed { +border-image: url(:/images/closepressed.png) +} + + + + + + + + + + + + false + + + + 0 + 0 + + + + + 0 + 0 + + + + + MS Shell Dlg 2 + + + + 0 + + + + File Name + + + + + File Size + + + + + + + + + + + 1 + 0 + + + + + 9 + + + + Qt::CustomContextMenu + + + true + + + QAbstractItemView::DragOnly + + + true + + + + Filename + + + + + Size + + + + + Sources + + + + + Type + + + + + Age + + + + + Hash + + + + + - - - 6 + + + Close all Search Resullts - - - - Close all Search Resullts - - - QToolButton, QPushButton, QComboBox { + + QToolButton, QPushButton, QComboBox { border-image: url(:/images/btn_26.png) 4; border-width: 4; padding: 0px 6px; @@ -1093,96 +1217,94 @@ QToolButton:pressed, QPushButton:pressed{ border-image: url(:/images/btn_26_pressed.png) 4; } - - - Close All Search Results - - - - - - - Qt::Horizontal - - - - 200 - 17 - - - - - - - - - 120 - 0 - - - - - 16777215 - 26 - - - - Download Selected - - - QToolButton, QPushButton, QComboBox { -border-image: url(:/images/btn_26.png) 4; -border-width: 4; -padding: 0px 6px; -font-size: 12px; -} - -*{ -color: black; -} - -QComboBox QAbstractItemView { -background-color:white; -} - -QComboBox::down-arrow { -image: url(:/images/combobox_arrow.png); -} - -QComboBox:drop-down -{ -subcontrol-origin: padding; -subcontrol-position: top right; -border-left-style: none; -border-top-right-radius: 1px; -border-bottom-right-radius: 1px; -} - -QToolButton:hover, QPushButton:hover, QComboBox:hover { -border-image: url(:/images/btn_26_hover.png) 4; -} - -QToolButton:disabled, QPushButton:disabled, QComboBox::disabled { -color:gray; -} - -QToolButton:pressed, QPushButton:pressed{ -border-image: url(:/images/btn_26_pressed.png) 4; -} - - - - Download - - - - :/images/download16.png:/images/download16.png - - - - + + + Close All Search Results + + - + + + + Qt::Horizontal + + + + 29 + 17 + + + + + + + + + 120 + 0 + + + + + 16777215 + 26 + + + + Download Selected + + + QToolButton, QPushButton, QComboBox { +border-image: url(:/images/btn_26.png) 4; +border-width: 4; +padding: 0px 6px; +font-size: 12px; +} + +*{ +color: black; +} + +QComboBox QAbstractItemView { +background-color:white; +} + +QComboBox::down-arrow { +image: url(:/images/combobox_arrow.png); +} + +QComboBox:drop-down +{ +subcontrol-origin: padding; +subcontrol-position: top right; +border-left-style: none; +border-top-right-radius: 1px; +border-bottom-right-radius: 1px; +} + +QToolButton:hover, QPushButton:hover, QComboBox:hover { +border-image: url(:/images/btn_26_hover.png) 4; +} + +QToolButton:disabled, QPushButton:disabled, QComboBox::disabled { +color:gray; +} + +QToolButton:pressed, QPushButton:pressed{ +border-image: url(:/images/btn_26_pressed.png) 4; +} + + + + Download + + + + :/images/download16.png:/images/download16.png + + + +