Added Search Filter for Search Results

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@4039 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
defnax 2011-02-16 20:07:06 +00:00
parent 9de341953d
commit daad701f52
3 changed files with 383 additions and 162 deletions

View File

@ -74,6 +74,18 @@ const int SearchDialog::FILETYPE_IDX_DIRECTORY = 8;
QMap<int, QString> * SearchDialog::FileTypeExtensionMap = new QMap<int, QString>();
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<DirDetails>& 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);
}

View File

@ -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;

View File

@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>580</width>
<height>376</height>
<width>574</width>
<height>344</height>
</rect>
</property>
<property name="sizePolicy">
@ -502,14 +502,14 @@
<property name="styleSheet">
<string notr="true"/>
</property>
<layout class="QGridLayout" name="gridLayout_4">
<layout class="QGridLayout" name="gridLayout_5">
<property name="horizontalSpacing">
<number>6</number>
</property>
<property name="verticalSpacing">
<number>0</number>
</property>
<item row="0" column="0">
<item row="0" column="0" colspan="3">
<widget class="QFrame" name="frame">
<property name="maximumSize">
<size>
@ -931,7 +931,7 @@ border-image: url(:/images/btn_26_pressed.png) 4;
</layout>
</widget>
</item>
<item row="1" column="0">
<item row="1" column="0" colspan="3">
<widget class="QSplitter" name="splitter">
<property name="orientation">
<enum>Qt::Horizontal</enum>
@ -985,75 +985,199 @@ border-image: url(:/images/btn_26_pressed.png) 4;
</property>
</column>
</widget>
<widget class="SearchTreeWidget" name="searchResultWidget">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="MinimumExpanding">
<horstretch>1</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="font">
<font>
<pointsize>9</pointsize>
</font>
</property>
<property name="contextMenuPolicy">
<enum>Qt::CustomContextMenu</enum>
</property>
<property name="dragEnabled">
<bool>true</bool>
</property>
<property name="dragDropMode">
<enum>QAbstractItemView::DragOnly</enum>
</property>
<property name="sortingEnabled">
<bool>true</bool>
</property>
<column>
<property name="text">
<string>Filename</string>
</property>
</column>
<column>
<property name="text">
<string>Size</string>
</property>
</column>
<column>
<property name="text">
<string>Sources</string>
</property>
</column>
<column>
<property name="text">
<string>Type</string>
</property>
</column>
<column>
<property name="text">
<string>Age</string>
</property>
</column>
<column>
<property name="text">
<string>Hash</string>
</property>
</column>
<widget class="QWidget" name="layoutWidget">
<layout class="QGridLayout" name="gridLayout_4">
<item row="0" column="0">
<layout class="QHBoxLayout" name="horizontalLayout_3">
<property name="spacing">
<number>6</number>
</property>
<property name="topMargin">
<number>6</number>
</property>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<property name="spacing">
<number>2</number>
</property>
<item>
<widget class="QLabel" name="label_3">
<property name="text">
<string/>
</property>
<property name="pixmap">
<pixmap resource="images.qrc">:/images/find-16.png</pixmap>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="filterPatternLineEdit">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
p, li { white-space: pre-wrap; }
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'Arial'; font-size:8pt; font-weight:400; font-style:normal;&quot;&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;Filter Search Result&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="clearButton">
<property name="minimumSize">
<size>
<width>16</width>
<height>16</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>16</width>
<height>16</height>
</size>
</property>
<property name="font">
<font>
<family>MS Shell Dlg 2</family>
</font>
</property>
<property name="toolTip">
<string>Clear Filter</string>
</property>
<property name="styleSheet">
<string notr="true">QPushButton
{
border-image: url(:/images/closenormal.png)
}
QPushButton:hover
{
border-image: url(:/images/closehover.png)
}
QPushButton:pressed {
border-image: url(:/images/closepressed.png)
}</string>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QComboBox" name="filterColumnComboBox">
<property name="enabled">
<bool>false</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="font">
<font>
<family>MS Shell Dlg 2</family>
</font>
</property>
<property name="currentIndex">
<number>0</number>
</property>
<item>
<property name="text">
<string>File Name</string>
</property>
</item>
<item>
<property name="text">
<string>File Size</string>
</property>
</item>
</widget>
</item>
</layout>
</item>
<item row="1" column="0">
<widget class="SearchTreeWidget" name="searchResultWidget">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="MinimumExpanding">
<horstretch>1</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="font">
<font>
<pointsize>9</pointsize>
</font>
</property>
<property name="contextMenuPolicy">
<enum>Qt::CustomContextMenu</enum>
</property>
<property name="dragEnabled">
<bool>true</bool>
</property>
<property name="dragDropMode">
<enum>QAbstractItemView::DragOnly</enum>
</property>
<property name="sortingEnabled">
<bool>true</bool>
</property>
<column>
<property name="text">
<string>Filename</string>
</property>
</column>
<column>
<property name="text">
<string>Size</string>
</property>
</column>
<column>
<property name="text">
<string>Sources</string>
</property>
</column>
<column>
<property name="text">
<string>Type</string>
</property>
</column>
<column>
<property name="text">
<string>Age</string>
</property>
</column>
<column>
<property name="text">
<string>Hash</string>
</property>
</column>
</widget>
</item>
</layout>
</widget>
</widget>
</item>
<item row="2" column="0">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<property name="spacing">
<number>6</number>
<widget class="QPushButton" name="cloaseallsearchresultsButton">
<property name="toolTip">
<string>Close all Search Resullts</string>
</property>
<item>
<widget class="QPushButton" name="cloaseallsearchresultsButton">
<property name="toolTip">
<string>Close all Search Resullts</string>
</property>
<property name="styleSheet">
<string notr="true">QToolButton, QPushButton, QComboBox {
<property name="styleSheet">
<string notr="true">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;
}
</string>
</property>
<property name="text">
<string>Close All Search Results</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>200</width>
<height>17</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="pushButtonDownload">
<property name="minimumSize">
<size>
<width>120</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>26</height>
</size>
</property>
<property name="toolTip">
<string>Download Selected</string>
</property>
<property name="styleSheet">
<string notr="true">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;
}
</string>
</property>
<property name="text">
<string>Download</string>
</property>
<property name="icon">
<iconset resource="images.qrc">
<normaloff>:/images/download16.png</normaloff>:/images/download16.png</iconset>
</property>
</widget>
</item>
</layout>
</property>
<property name="text">
<string>Close All Search Results</string>
</property>
</widget>
</item>
<item row="3" column="0">
<item row="2" column="1">
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>29</width>
<height>17</height>
</size>
</property>
</spacer>
</item>
<item row="2" column="2">
<widget class="QPushButton" name="pushButtonDownload">
<property name="minimumSize">
<size>
<width>120</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>26</height>
</size>
</property>
<property name="toolTip">
<string>Download Selected</string>
</property>
<property name="styleSheet">
<string notr="true">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;
}
</string>
</property>
<property name="text">
<string>Download</string>
</property>
<property name="icon">
<iconset resource="images.qrc">
<normaloff>:/images/download16.png</normaloff>:/images/download16.png</iconset>
</property>
</widget>
</item>
<item row="3" column="0" colspan="3">
<widget class="QFrame" name="frame_3">
<property name="maximumSize">
<size>