Rewrite the shortcut settings filtering.

Makes more sense now, is more generic (regarding nesting level), and
even is shorter.

Change-Id: I77ce34aa25655f6b2690964107f4cab018e1d66f
Reviewed-by: Robert Löhning <robert.loehning@nokia.com>
Reviewed-by: Eike Ziller <eike.ziller@nokia.com>
This commit is contained in:
Eike Ziller
2012-05-22 14:56:37 +02:00
parent 928adb5d6b
commit 611ed2f251
2 changed files with 16 additions and 26 deletions

View File

@@ -161,38 +161,28 @@ void CommandMappings::filterChanged(const QString &f)
return; return;
for (int i=0; i<m_page->commandList->topLevelItemCount(); ++i) { for (int i=0; i<m_page->commandList->topLevelItemCount(); ++i) {
QTreeWidgetItem *item = m_page->commandList->topLevelItem(i); QTreeWidgetItem *item = m_page->commandList->topLevelItem(i);
item->setHidden(filter(f, item)); filter(f, item);
} }
} }
bool CommandMappings::filter(const QString &f, const QTreeWidgetItem *item) bool CommandMappings::filter(const QString &filterString, QTreeWidgetItem *item)
{ {
if (QTreeWidgetItem *parent = item->parent()) { bool visible = filterString.isEmpty();
if (parent->text(0).contains(f, Qt::CaseInsensitive)) int columnCount = item->columnCount();
return false; for (int i = 0; !visible && i < columnCount; ++i)
} visible |= (bool)item->text(i).contains(filterString, Qt::CaseInsensitive);
if (item->childCount() == 0) { int childCount = item->childCount();
if (f.isEmpty()) if (childCount > 0) {
return false; // force visibility if this item matches
for (int i = 0; i < item->columnCount(); ++i) { QString leafFilterString = visible ? QString() : filterString;
if (item->text(i).contains(f, Qt::CaseInsensitive)) for (int i = 0; i < childCount; ++i) {
return false;
}
return true;
}
bool found = false;
for (int i = 0; i < item->childCount(); ++i) {
QTreeWidgetItem *citem = item->child(i); QTreeWidgetItem *citem = item->child(i);
if (filter(f, citem)) { visible |= !filter(leafFilterString, citem); // parent visible if any child visible
citem->setHidden(true);
} else {
citem->setHidden(false);
found = true;
} }
} }
return !found; item->setHidden(!visible);
return !visible;
} }
void CommandMappings::setModified(QTreeWidgetItem *item , bool modified) void CommandMappings::setModified(QTreeWidgetItem *item , bool modified)

View File

@@ -68,7 +68,7 @@ protected:
virtual void finish(); virtual void finish();
virtual void initialize() = 0; virtual void initialize() = 0;
bool filter(const QString &f, const QTreeWidgetItem *item); bool filter(const QString &filterString, QTreeWidgetItem *item);
// access to m_page // access to m_page
void setImportExportEnabled(bool enabled); void setImportExportEnabled(bool enabled);