Skip to content

Commit

Permalink
allow to filter layer list in config
Browse files Browse the repository at this point in the history
  • Loading branch information
3nids committed Jun 19, 2018
1 parent 309f3b0 commit 9138dd6
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 18 deletions.
24 changes: 22 additions & 2 deletions swiss_locator/gui/config_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"""

import os
from PyQt5.QtCore import Qt
from PyQt5.QtCore import Qt, pyqtSlot
from PyQt5.QtWidgets import QDialog, QTableWidgetItem, QAbstractItemView
from PyQt5.uic import loadUiType

Expand All @@ -49,7 +49,9 @@ def __init__(self, parent=None):
self.crs.addItem('CH 1903+ (EPSG:2056)', '2056')
self.crs.addItem('CH 1903 (EPSG:21781)', '21781')

self.search_line_edit.textChanged.connect(self.filter_rows)
self.feature_search_restrict.toggled.connect(self.feature_search_layers_list.setEnabled)
self.feature_search_restrict.toggled.connect(self.search_line_edit.setEnabled)
self.feature_search_restrict.toggled.connect(self.select_all_button.setEnabled)
self.feature_search_restrict.toggled.connect(self.unselect_all_button.setEnabled)
self.select_all_button.pressed.connect(self.select_all)
Expand All @@ -59,6 +61,7 @@ def __init__(self, parent=None):
layers = searchable_layers(lang)
self.feature_search_layers_list.setRowCount(len(layers))
self.feature_search_layers_list.setColumnCount(2)
self.feature_search_layers_list.setHorizontalHeaderLabels((self.tr('Layer'), self.tr('Description')))
self.feature_search_layers_list.setSelectionBehavior(QAbstractItemView.SelectRows)
self.feature_search_layers_list.setSelectionMode(QAbstractItemView.SingleSelection)
r = 0
Expand All @@ -69,11 +72,28 @@ def __init__(self, parent=None):
self.feature_search_layers_list.setItem(r, 0, item)
self.feature_search_layers_list.setItem(r, 1, QTableWidgetItem(description))
r += 1
self.feature_search_layers_list.horizontalHeader().setStretchLastSection(True)

self.settings = settings
self.init_widgets()

def select_all(self, select:bool =True):
for r in range(self.feature_search_layers_list.rowCount()):
item = self.feature_search_layers_list.item(r, 0)
item.setCheckState(Qt.Checked if select else Qt.Unchecked)
item.setCheckState(Qt.Checked if select else Qt.Unchecked)

@pyqtSlot(str)
def filter_rows(self, text: str):
if text:
items = self.feature_search_layers_list.findItems(text, Qt.MatchContains)
print(text)
print(len(items))
shown_rows = []
for item in items:
shown_rows.append(item.row())
shown_rows = list(set(shown_rows))
for r in range(self.feature_search_layers_list.rowCount()):
self.feature_search_layers_list.setRowHidden(r, r not in shown_rows)
else:
for r in range(self.feature_search_layers_list.rowCount()):
self.feature_search_layers_list.setRowHidden(r, False)
52 changes: 36 additions & 16 deletions swiss_locator/ui/config.ui
Original file line number Diff line number Diff line change
Expand Up @@ -91,16 +91,6 @@
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QPushButton" name="unselect_all_button">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>unselect all</string>
</property>
</widget>
</item>
<item row="1" column="2">
<spacer name="horizontalSpacer">
<property name="orientation">
Expand All @@ -114,14 +104,37 @@
</property>
</spacer>
</item>
<item row="2" column="0" colspan="3">
<item row="1" column="1">
<widget class="QPushButton" name="unselect_all_button">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>unselect all</string>
</property>
</widget>
</item>
<item row="1" column="3">
<widget class="QgsFilterLineEdit" name="search_line_edit">
<property name="enabled">
<bool>false</bool>
</property>
<property name="showSearchIcon">
<bool>true</bool>
</property>
<property name="qgisRelation" stdset="0">
<string notr="true"/>
</property>
</widget>
</item>
<item row="2" column="0" colspan="4">
<widget class="QTableWidget" name="feature_search_layers_list">
<property name="enabled">
<bool>false</bool>
</property>
</widget>
</item>
<item row="0" column="0" colspan="3">
<item row="0" column="0" colspan="4">
<widget class="QCheckBox" name="feature_search_restrict">
<property name="text">
<string>Restrict feature search to specific layers</string>
Expand All @@ -134,6 +147,13 @@
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>QgsFilterLineEdit</class>
<extends>QLineEdit</extends>
<header>qgsfilterlineedit.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections>
<connection>
Expand All @@ -143,8 +163,8 @@
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
<x>254</x>
<y>419</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
Expand All @@ -159,8 +179,8 @@
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
<x>322</x>
<y>419</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
Expand Down

0 comments on commit 9138dd6

Please sign in to comment.