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>(); QMap<int, QString> * SearchDialog::FileTypeExtensionMap = new QMap<int, QString>();
bool SearchDialog::initialised = false; 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 */ /** Constructor */
SearchDialog::SearchDialog(QWidget *parent) SearchDialog::SearchDialog(QWidget *parent)
: MainPage(parent), : MainPage(parent),
@ -114,6 +126,10 @@ SearchDialog::SearchDialog(QWidget *parent)
connect(ui.FileTypeComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(selectSearchResults(int))); 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 +/- */ /* hide the Tree +/- */
ui.searchResultWidget -> setRootIsDecorated( true ); ui.searchResultWidget -> setRootIsDecorated( true );
ui.searchResultWidget -> setColumnHidden( SR_UID_COL,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.searchResultWidget->sortItems(SR_NAME_COL, Qt::AscendingOrder);
ui.resetButton->hide(); ui.resetButton->hide();
ui.clearButton->hide();
ui._ownFiles_CB->setMinimumWidth(20); ui._ownFiles_CB->setMinimumWidth(20);
ui._friendListsearch_SB->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); insertDirectory(txt, searchId, details, child);
} }
} }
if (ui.filterPatternLineEdit->text().isEmpty() == false) {
FilterItems();
}
} }
void SearchDialog::insertDirectory(const std::string &txt, qulonglong searchId, const DirDetails &dir) 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(); selectSearchResults();
if (ui.filterPatternLineEdit->text().isEmpty() == false) {
FilterItems();
}
// TODO: check for duplicate directories // TODO: check for duplicate directories
} }
@ -1039,6 +1064,10 @@ void SearchDialog::insertFile(const std::string& txt,qulonglong searchId, const
/* select this search result */ /* select this search result */
selectSearchResults(); selectSearchResults();
if (ui.filterPatternLineEdit->text().isEmpty() == false) {
FilterItems();
}
} }
void SearchDialog::resultsToTree(std::string txt,qulonglong searchId, const std::list<DirDetails>& results) 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.searchResultWidget->update();
ui.filterPatternLineEdit->clear();
} }
void SearchDialog::setIconAndType(QTreeWidgetItem *item, QString ext) 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 onComboIndexChanged(int index);
void filterColumnChanged();
void filterRegExpChanged();
void clearFilter();
private: private:
@ -122,10 +126,8 @@ private:
static bool initialised; static bool initialised;
void initialiseFileTypeMappings(); void initialiseFileTypeMappings();
/**** void FilterItems();
QTreeWidget *searchtableWidget; bool FilterItem(QTreeWidgetItem *pItem, QString &sPattern, int nFilterColumn);
QTreeWidget *searchtablewidget2;
****/
int nextSearchId; int nextSearchId;

View File

@ -6,8 +6,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>580</width> <width>574</width>
<height>376</height> <height>344</height>
</rect> </rect>
</property> </property>
<property name="sizePolicy"> <property name="sizePolicy">
@ -502,14 +502,14 @@
<property name="styleSheet"> <property name="styleSheet">
<string notr="true"/> <string notr="true"/>
</property> </property>
<layout class="QGridLayout" name="gridLayout_4"> <layout class="QGridLayout" name="gridLayout_5">
<property name="horizontalSpacing"> <property name="horizontalSpacing">
<number>6</number> <number>6</number>
</property> </property>
<property name="verticalSpacing"> <property name="verticalSpacing">
<number>0</number> <number>0</number>
</property> </property>
<item row="0" column="0"> <item row="0" column="0" colspan="3">
<widget class="QFrame" name="frame"> <widget class="QFrame" name="frame">
<property name="maximumSize"> <property name="maximumSize">
<size> <size>
@ -931,7 +931,7 @@ border-image: url(:/images/btn_26_pressed.png) 4;
</layout> </layout>
</widget> </widget>
</item> </item>
<item row="1" column="0"> <item row="1" column="0" colspan="3">
<widget class="QSplitter" name="splitter"> <widget class="QSplitter" name="splitter">
<property name="orientation"> <property name="orientation">
<enum>Qt::Horizontal</enum> <enum>Qt::Horizontal</enum>
@ -985,6 +985,132 @@ border-image: url(:/images/btn_26_pressed.png) 4;
</property> </property>
</column> </column>
</widget> </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"> <widget class="SearchTreeWidget" name="searchResultWidget">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="MinimumExpanding"> <sizepolicy hsizetype="Expanding" vsizetype="MinimumExpanding">
@ -1040,14 +1166,12 @@ border-image: url(:/images/btn_26_pressed.png) 4;
</property> </property>
</column> </column>
</widget> </widget>
</item>
</layout>
</widget>
</widget> </widget>
</item> </item>
<item row="2" column="0"> <item row="2" column="0">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<property name="spacing">
<number>6</number>
</property>
<item>
<widget class="QPushButton" name="cloaseallsearchresultsButton"> <widget class="QPushButton" name="cloaseallsearchresultsButton">
<property name="toolTip"> <property name="toolTip">
<string>Close all Search Resullts</string> <string>Close all Search Resullts</string>
@ -1099,20 +1223,20 @@ border-image: url(:/images/btn_26_pressed.png) 4;
</property> </property>
</widget> </widget>
</item> </item>
<item> <item row="2" column="1">
<spacer name="horizontalSpacer_2"> <spacer name="horizontalSpacer_2">
<property name="orientation"> <property name="orientation">
<enum>Qt::Horizontal</enum> <enum>Qt::Horizontal</enum>
</property> </property>
<property name="sizeHint" stdset="0"> <property name="sizeHint" stdset="0">
<size> <size>
<width>200</width> <width>29</width>
<height>17</height> <height>17</height>
</size> </size>
</property> </property>
</spacer> </spacer>
</item> </item>
<item> <item row="2" column="2">
<widget class="QPushButton" name="pushButtonDownload"> <widget class="QPushButton" name="pushButtonDownload">
<property name="minimumSize"> <property name="minimumSize">
<size> <size>
@ -1180,9 +1304,7 @@ border-image: url(:/images/btn_26_pressed.png) 4;
</property> </property>
</widget> </widget>
</item> </item>
</layout> <item row="3" column="0" colspan="3">
</item>
<item row="3" column="0">
<widget class="QFrame" name="frame_3"> <widget class="QFrame" name="frame_3">
<property name="maximumSize"> <property name="maximumSize">
<size> <size>