Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions Orange/widgets/data/owrank.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ def __init__(self):
self.mainArea.layout().addWidget(view)
view.setModel(model)
view.setColumnWidth(0, 30)
view.selectionModel().selectionChanged.connect(self.commit)
view.selectionModel().selectionChanged.connect(self.on_select)

def _set_select_manual():
self.setSelectionMethod(OWRank.SelectManual)
Expand Down Expand Up @@ -331,7 +331,7 @@ def handleNewSignals(self):
self.setStatusMessage('Running')
self.updateScores()
self.setStatusMessage('')
self.commit()
self.on_select()

@Inputs.scorer
def set_learner(self, scorer, id):
Expand Down Expand Up @@ -438,12 +438,18 @@ def updateScores(self):
self.autoSelection()
self.Outputs.scores.send(self.create_scores_table(labels))

def on_select(self):
# Save indices of attributes in the original, unsorted domain
self.selected_rows = self.ranksModel.mapToSourceRows([
i.row() for i in self.ranksView.selectionModel().selectedRows(0)])
self.commit()

def setSelectionMethod(self, method):
if self.selectionMethod != method:
self.selectionMethod = method
self.selectButtons.button(method).setChecked(True)
self.autoSelection()
self.commit()
self.on_select()

def autoSelection(self):
selModel = self.ranksView.selectionModel()
Expand Down Expand Up @@ -500,10 +506,6 @@ def send_report(self):
self.report_items("Output", self.out_domain_desc)

def commit(self):
# Save indices of attributes in the original, unsorted domain
self.selected_rows = self.ranksModel.mapToSourceRows([
i.row() for i in self.ranksView.selectionModel().selectedRows(0)])

selected_attrs = []
if self.data is not None:
attributes = self.data.domain.attributes
Expand All @@ -512,8 +514,7 @@ def commit(self):
self.selectButtons.button(self.selectionMethod).setChecked(True)
selected_attrs = [attributes[i]
for i in self.selected_rows]

if self.data is None or not selected_attrs:
if not selected_attrs:
self.Outputs.reduced_data.send(None)
self.out_domain_desc = None
else:
Expand Down
32 changes: 31 additions & 1 deletion Orange/widgets/data/tests/test_owrank.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from Orange.widgets.data.owrank import OWRank, ProblemType, CLS_SCORES, REG_SCORES
from Orange.widgets.tests.base import WidgetTest

from AnyQt.QtCore import Qt
from AnyQt.QtCore import Qt, QItemSelection
from AnyQt.QtWidgets import QCheckBox


Expand Down Expand Up @@ -295,3 +295,33 @@ def test_setting_migration_fixes_header_state(self):
w = self.create_widget(OWRank, stored_settings=settings)

self.assertEqual(w.sorting, (0, Qt.AscendingOrder))

def test_auto_send(self):
widget = self.widget
model = widget.ranksModel
selectionModel = widget.ranksView.selectionModel()

# Auto-send disabled
widget.controls.auto_apply.setChecked(False)
self.send_signal(self.widget.Inputs.data, self.iris)
self.assertIsNone(self.get_output(widget.Outputs.reduced_data))

# Make selection, but auto-send disabled
selection = QItemSelection(model.index(1, 0),
model.index(1, model.columnCount() - 1))
selectionModel.select(selection, selectionModel.ClearAndSelect)
self.assertIsNone(self.get_output(widget.Outputs.reduced_data))

# Enable auto-send: should output data
widget.controls.auto_apply.setChecked(True)
reduced_data = self.get_output(widget.Outputs.reduced_data)
self.assertEqual(reduced_data.domain.attributes,
(self.iris.domain["petal width"], ))

# Change selection: should change the output immediately
selection = QItemSelection(model.index(0, 0),
model.index(0, model.columnCount() - 1))
selectionModel.select(selection, selectionModel.ClearAndSelect)
reduced_data = self.get_output(widget.Outputs.reduced_data)
self.assertEqual(reduced_data.domain.attributes,
(self.iris.domain["petal length"], ))