Skip to content

Commit

Permalink
(ref #14469) Processing options: search optimized. Cleanups.
Browse files Browse the repository at this point in the history
  • Loading branch information
sept-en committed Mar 22, 2016
1 parent 12aedac commit 6c31d89
Showing 1 changed file with 49 additions and 59 deletions.
108 changes: 49 additions & 59 deletions python/plugins/processing/gui/ConfigDialog.py
Expand Up @@ -67,24 +67,46 @@ def __init__(self, toolbox):
self.delegate = SettingDelegate()
self.tree.setItemDelegateForColumn(1, self.delegate)

self.searchBox.textChanged.connect(self.fillTree)
self.searchBox.textChanged.connect(self.textChanged)

self.fillTree()

self.tree.expanded.connect(self.adjustColumns)

def textChanged(self):
text = unicode(self.searchBox.text().lower())
self._filterItem(self.model.invisibleRootItem(), text)
if text:
self.tree.expandAll()
else:
self.tree.collapseAll()

def _filterItem(self, item, text):
if item.hasChildren():
show = False
for i in xrange(item.rowCount()):
child = item.child(i)
showChild = self._filterItem(child, text)
show = (showChild or show)
self.tree.setRowHidden (item.row(), item.index().parent(), not show)
return show

elif isinstance(item, QStandardItem):
hide = bool(text) and (text not in item.text().lower())
self.tree.setRowHidden (item.row(), item.index().parent(), hide)
return not hide

def fillTree(self):
self.fillTreeUsingProviders()

def fillTreeUsingProviders(self):
self.items = {}
self.model.clear()
self.model.setHorizontalHeaderLabels([self.tr('Setting'),
self.tr('Value')])

text = unicode(self.searchBox.text())
settings = ProcessingConfig.getSettings()

# Let's check if menu's children have any matches vs search wildcard
isAnyMenuChildMatchesWildcard = False

rootItem = self.model.invisibleRootItem()

"""
Expand All @@ -99,25 +121,18 @@ def fillTree(self):
emptyItem = QStandardItem()
emptyItem.setEditable(False)

isAnyMenuChildMatchesWildcard = False

rootItem.insertRow(0, [groupItem, emptyItem])
# add menu item only if it has any search matches
for setting in settings[group]:
if setting.hidden or setting.name.startswith("MENU_"):
continue

if text == '' or text.lower() in setting.description.lower():
labelItem = QStandardItem(setting.description)
labelItem.setIcon(icon)
labelItem.setEditable(False)
self.items[setting] = SettingItem(setting)
groupItem.insertRow(0, [labelItem, self.items[setting]])

isAnyMenuChildMatchesWildcard = True
labelItem = QStandardItem(setting.description)
labelItem.setIcon(icon)
labelItem.setEditable(False)
self.items[setting] = SettingItem(setting)
groupItem.insertRow(0, [labelItem, self.items[setting]])

# If menu have any search matches with children - show it
if isAnyMenuChildMatchesWildcard:
rootItem.insertRow(0, [groupItem, emptyItem])

"""
Filter 'Providers' items
Expand All @@ -129,9 +144,7 @@ def fillTree(self):
emptyItem = QStandardItem()
emptyItem.setEditable(False)

# Let's check if menu's children have any matches vs search wildcard
isAnyMenuChildMatchesWildcard = False

rootItem.insertRow(0, [providersItem, emptyItem])
for group in settings.keys():
if group in priorityKeys:
continue
Expand All @@ -141,29 +154,20 @@ def fillTree(self):
groupItem.setIcon(icon)
groupItem.setEditable(False)

isAnyChildMatchesWildcard = False

for setting in settings[group]:
if setting.hidden:
continue

if text == '' or text.lower() in setting.description.lower():
labelItem = QStandardItem(setting.description)
labelItem.setIcon(icon)
labelItem.setEditable(False)
self.items[setting] = SettingItem(setting)
groupItem.insertRow(0, [labelItem, self.items[setting]])
isAnyChildMatchesWildcard = True
isAnyMenuChildMatchesWildcard = True
labelItem = QStandardItem(setting.description)
labelItem.setIcon(icon)
labelItem.setEditable(False)
self.items[setting] = SettingItem(setting)
groupItem.insertRow(0, [labelItem, self.items[setting]])

emptyItem = QStandardItem()
emptyItem.setEditable(False)
providersItem.appendRow([groupItem, emptyItem])

if isAnyChildMatchesWildcard or text.lower() in group.lower():
providersItem.appendRow([groupItem, emptyItem])

if isAnyMenuChildMatchesWildcard:
rootItem.insertRow(0, [providersItem, emptyItem])

"""
Filter 'Menus' items
Expand All @@ -175,47 +179,33 @@ def fillTree(self):
emptyItem = QStandardItem()
emptyItem.setEditable(False)

# Let's check if menu's children have any matches vs search wildcard
isAnyMenuChildMatchesWildcard = False
rootItem.insertRow(0, [menusItem, emptyItem])

providers = Processing.providers
for provider in providers:
groupItem = QStandardItem(provider.getDescription())
providerDescription = provider.getDescription()
groupItem = QStandardItem(providerDescription)
icon = provider.getIcon()
groupItem.setIcon(icon)
groupItem.setEditable(False)

# Let's check if provider's children have any matches vs search wildcard
isAnyChildMatchesWildcard = False

for alg in provider.algs:
labelItem = QStandardItem(alg.name)
labelItem.setIcon(icon)
labelItem.setEditable(False)
setting = ProcessingConfig.settings["MENU_" + alg.commandLineName()]
try:
setting = ProcessingConfig.settings["MENU_" + alg.commandLineName()]
except:
continue
self.items[setting] = SettingItem(setting)

if text == '' or text.lower() in provider.getDescription().lower():
groupItem.insertRow(0, [labelItem, self.items[setting]])
# remember that provider have at least one child matching search wildcard
isAnyChildMatchesWildcard = True
isAnyMenuChildMatchesWildcard = True
groupItem.insertRow(0, [labelItem, self.items[setting]])

emptyItem = QStandardItem()
emptyItem.setEditable(False)

# Add provider to the list only if it have any children-matches
if isAnyChildMatchesWildcard:
menusItem.appendRow([groupItem, emptyItem])
menusItem.appendRow([groupItem, emptyItem])

# add menu item only if it has any search matches
if isAnyMenuChildMatchesWildcard:
rootItem.insertRow(0, [menusItem, emptyItem])

# we need to expand our trees if any searching is performing
needExpandTree = bool(text != "")
if needExpandTree:
self.tree.expandAll()

self.tree.sortByColumn(0, Qt.AscendingOrder)
self.adjustColumns()
Expand Down

0 comments on commit 6c31d89

Please sign in to comment.