Added filter of items to RSTreeWidget.

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@6493 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
thunder2 2013-07-09 11:58:55 +00:00
parent 249f2ff2e0
commit c0cc792300
2 changed files with 40 additions and 0 deletions

View File

@ -71,3 +71,38 @@ void RSTreeWidget::mousePressEvent(QMouseEvent *event)
QTreeWidget::mousePressEvent(event);
}
void RSTreeWidget::filterItems(int filterColumn, const QString &text)
{
int count = topLevelItemCount();
for (int index = 0; index < count; ++index) {
filterItem(topLevelItem(index), filterColumn, text);
}
}
bool RSTreeWidget::filterItem(QTreeWidgetItem *item, int filterColumn, const QString &text)
{
bool itemVisible = true;
if (!text.isEmpty()) {
if (!item->text(filterColumn).contains(text, Qt::CaseInsensitive)) {
itemVisible = false;
}
}
int visibleChildCount = 0;
int count = item->childCount();
for (int index = 0; index < count; ++index) {
if (filterItem(item->child(index), filterColumn, text)) {
++visibleChildCount;
}
}
if (itemVisible || visibleChildCount) {
item->setHidden(false);
} else {
item->setHidden(true);
}
return (itemVisible || visibleChildCount);
}

View File

@ -34,9 +34,14 @@ public:
void setPlaceholderText(const QString &text);
void filterItems(int filterColumn, const QString &text);
signals:
void signalMouseMiddleButtonClicked(QTreeWidgetItem *item);
private:
bool filterItem(QTreeWidgetItem *item, int filterColumn, const QString &text);
protected:
void paintEvent(QPaintEvent *event);
virtual void mousePressEvent(QMouseEvent *event);