mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-10-01 02:35:48 -04:00
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:
parent
249f2ff2e0
commit
c0cc792300
@ -71,3 +71,38 @@ void RSTreeWidget::mousePressEvent(QMouseEvent *event)
|
|||||||
|
|
||||||
QTreeWidget::mousePressEvent(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);
|
||||||
|
}
|
||||||
|
@ -34,9 +34,14 @@ public:
|
|||||||
|
|
||||||
void setPlaceholderText(const QString &text);
|
void setPlaceholderText(const QString &text);
|
||||||
|
|
||||||
|
void filterItems(int filterColumn, const QString &text);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void signalMouseMiddleButtonClicked(QTreeWidgetItem *item);
|
void signalMouseMiddleButtonClicked(QTreeWidgetItem *item);
|
||||||
|
|
||||||
|
private:
|
||||||
|
bool filterItem(QTreeWidgetItem *item, int filterColumn, const QString &text);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void paintEvent(QPaintEvent *event);
|
void paintEvent(QPaintEvent *event);
|
||||||
virtual void mousePressEvent(QMouseEvent *event);
|
virtual void mousePressEvent(QMouseEvent *event);
|
||||||
|
Loading…
Reference in New Issue
Block a user