Skip to content

Commit

Permalink
Merge pull request #4755 from janezd/selectrows-keep-operator
Browse files Browse the repository at this point in the history
Select Rows: Keep operator when possible
  • Loading branch information
janezd authored May 15, 2020
2 parents db06988 + f78462f commit 56a106f
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
10 changes: 8 additions & 2 deletions Orange/widgets/data/owselectrows.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,8 @@ def remove_all_rows(self):

def set_new_operators(self, attr_combo, adding_all,
selected_index=None, selected_values=None):
old_combo = self.cond_list.cellWidget(attr_combo.row, 1)
prev_text = old_combo.currentText() if old_combo else ""
oper_combo = QComboBox()
oper_combo.row = attr_combo.row
oper_combo.attr_combo = attr_combo
Expand All @@ -348,7 +350,11 @@ def set_new_operators(self, attr_combo, adding_all,
else:
var = self.data.domain[attr_name]
oper_combo.addItems(self.operator_names[type(var)])
oper_combo.setCurrentIndex(selected_index or 0)
if selected_index is None:
selected_index = oper_combo.findText(prev_text)
if selected_index == -1:
selected_index = 0
oper_combo.setCurrentIndex(selected_index)
self.cond_list.setCellWidget(oper_combo.row, 1, oper_combo)
self.set_new_values(oper_combo, adding_all, selected_values)
oper_combo.currentIndexChanged.connect(
Expand Down Expand Up @@ -789,4 +795,4 @@ def resizeEvent(self, QResizeEvent):


if __name__ == "__main__": # pragma: no cover
WidgetPreview(OWSelectRows).run(Table("zoo"))
WidgetPreview(OWSelectRows).run(Table("heart_disease"))
20 changes: 20 additions & 0 deletions Orange/widgets/data/tests/test_owselectrows.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,26 @@ def test_change_var_type(self):
new_iris = iris.transform(new_domain)
self.send_signal(self.widget.Inputs.data, new_iris)

def test_keep_operator(self):
data = Table("heart_disease")
domain = data.domain

self.send_signal(self.widget.Inputs.data, data)

self.widget.remove_all_button.click()
self.enterFilter(domain["age"], "is not", "42")
simulate.combobox_activate_item(
self.widget.cond_list.cellWidget(0, 0), "chest pain", delay=0)
self.assertEqual(
self.widget.cond_list.cellWidget(0, 1).currentText(), "is not")

self.widget.remove_all_button.click()
self.enterFilter(domain["age"], "is below", "42")
simulate.combobox_activate_item(
self.widget.cond_list.cellWidget(0, 0), "chest pain", delay=0)
self.assertEqual(
self.widget.cond_list.cellWidget(0, 1).currentText(), "is")

# Uncomment this on 2022/2/2
#
# def test_migration_to_version_1(self):
Expand Down

0 comments on commit 56a106f

Please sign in to comment.