mirror of
https://invent.kde.org/network/falkon.git
synced 2024-11-13 10:32:11 +01:00
Improved version of 'TreeWidget::filterString()'
This commit is contained in:
parent
b9858f98a4
commit
a7a4ef87a7
|
@ -57,7 +57,7 @@ BrowsingLibrary::BrowsingLibrary(QupZilla* mainClass, QWidget* parent)
|
||||||
ui->tabs->setFocus();
|
ui->tabs->setFocus();
|
||||||
|
|
||||||
connect(ui->tabs, SIGNAL(CurrentChanged(int)), this, SLOT(currentIndexChanged(int)));
|
connect(ui->tabs, SIGNAL(CurrentChanged(int)), this, SLOT(currentIndexChanged(int)));
|
||||||
connect(ui->searchLine, SIGNAL(cursorPositionChanged(int, int)), this, SLOT(search()));
|
connect(ui->searchLine, SIGNAL(textChanged(QString)), this, SLOT(search()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void BrowsingLibrary::currentIndexChanged(int index)
|
void BrowsingLibrary::currentIndexChanged(int index)
|
||||||
|
|
|
@ -328,49 +328,39 @@ QList<QTreeWidgetItem*> TreeWidget::allItems()
|
||||||
|
|
||||||
void TreeWidget::filterString(const QString &string)
|
void TreeWidget::filterString(const QString &string)
|
||||||
{
|
{
|
||||||
expandAll();
|
|
||||||
QList<QTreeWidgetItem*> _allItems = allItems();
|
QList<QTreeWidgetItem*> _allItems = allItems();
|
||||||
|
QList<QTreeWidgetItem*> parents;
|
||||||
if (string.isEmpty()) {
|
bool stringIsEmpty = string.isEmpty();
|
||||||
foreach(QTreeWidgetItem * item, _allItems)
|
foreach(QTreeWidgetItem * item, _allItems) {
|
||||||
item->setHidden(false);
|
bool containsString = stringIsEmpty || item->text(0).contains(string, Qt::CaseInsensitive);
|
||||||
for (int i = 0; i < topLevelItemCount(); i++) {
|
if (containsString) {
|
||||||
topLevelItem(i)->setHidden(false);
|
item->setHidden(false);
|
||||||
|
if (item->parent()) {
|
||||||
|
if (!parents.contains(item->parent())) {
|
||||||
|
parents << item->parent();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (m_showMode == ItemsCollapsed) {
|
else {
|
||||||
collapseAll();
|
item->setHidden(true);
|
||||||
|
if (item->parent()) {
|
||||||
|
item->parent()->setHidden(true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
foreach(QTreeWidgetItem * item, _allItems) {
|
for(int i = 0; i < parents.size(); ++i) {
|
||||||
item->setHidden(!item->text(0).contains(string, Qt::CaseInsensitive));
|
QTreeWidgetItem* parentItem = parents.at(i);
|
||||||
item->setExpanded(true);
|
parentItem->setHidden(false);
|
||||||
|
if (stringIsEmpty) {
|
||||||
|
parentItem->setExpanded(m_showMode == ItemsExpanded);
|
||||||
}
|
}
|
||||||
for (int i = 0; i < topLevelItemCount(); i++) {
|
else {
|
||||||
topLevelItem(i)->setHidden(false);
|
parentItem->setExpanded(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
QTreeWidgetItem* firstItem = topLevelItem(0);
|
if (parentItem->parent() && !parents.contains(parentItem->parent())) {
|
||||||
QTreeWidgetItem* belowItem = itemBelow(firstItem);
|
parents << parentItem->parent();
|
||||||
|
|
||||||
int topLvlIndex = 0;
|
|
||||||
while (firstItem) {
|
|
||||||
if (firstItem->text(0).contains(string, Qt::CaseInsensitive)) {
|
|
||||||
firstItem->setHidden(false);
|
|
||||||
}
|
|
||||||
else if (!firstItem->parent() && !belowItem) {
|
|
||||||
firstItem->setHidden(true);
|
|
||||||
}
|
|
||||||
else if (!belowItem) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
else if (!firstItem->parent() && !belowItem->parent()) {
|
|
||||||
firstItem->setHidden(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
topLvlIndex++;
|
|
||||||
firstItem = topLevelItem(topLvlIndex);
|
|
||||||
belowItem = itemBelow(firstItem);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user