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),
@ -114,6 +126,10 @@ SearchDialog::SearchDialog(QWidget *parent)
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 );
ui.searchResultWidget -> setColumnHidden( SR_UID_COL,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,6 +985,132 @@ border-image: url(:/images/btn_26_pressed.png) 4;
</property>
</column>
</widget>
<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">
@ -1040,14 +1166,12 @@ border-image: url(:/images/btn_26_pressed.png) 4;
</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>
</property>
<item>
<widget class="QPushButton" name="cloaseallsearchresultsButton">
<property name="toolTip">
<string>Close all Search Resullts</string>
@ -1099,20 +1223,20 @@ border-image: url(:/images/btn_26_pressed.png) 4;
</property>
</widget>
</item>
<item>
<item row="2" column="1">
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>200</width>
<width>29</width>
<height>17</height>
</size>
</property>
</spacer>
</item>
<item>
<item row="2" column="2">
<widget class="QPushButton" name="pushButtonDownload">
<property name="minimumSize">
<size>
@ -1180,9 +1304,7 @@ border-image: url(:/images/btn_26_pressed.png) 4;
</property>
</widget>
</item>
</layout>
</item>
<item row="3" column="0">
<item row="3" column="0" colspan="3">
<widget class="QFrame" name="frame_3">
<property name="maximumSize">
<size>