From 35447c1cf1fc7dbd14712d3221736b0856e81973 Mon Sep 17 00:00:00 2001 From: Vesna Tanko Date: Wed, 7 Nov 2018 09:36:34 +0100 Subject: [PATCH] OWSelectAttributes: Enable filtering of used features --- Orange/widgets/data/owselectcolumns.py | 10 +++++----- .../data/tests/test_owselectcolumns.py | 19 ++++++++++++++++++- Orange/widgets/utils/listfilter.py | 4 ++-- 3 files changed, 25 insertions(+), 8 deletions(-) diff --git a/Orange/widgets/data/owselectcolumns.py b/Orange/widgets/data/owselectcolumns.py index 51f99f1e589..d68c240d013 100644 --- a/Orange/widgets/data/owselectcolumns.py +++ b/Orange/widgets/data/owselectcolumns.py @@ -169,13 +169,12 @@ def dropcompleted(action): box = gui.vBox(self.controlArea, "Features", addToLayout=False) self.used_attrs = VariablesListItemModel() + filter_edit, self.used_attrs_view = variables_filter( + parent=self, model=self.used_attrs, + accepted_type=(Orange.data.DiscreteVariable, + Orange.data.ContinuousVariable)) self.used_attrs.rowsInserted.connect(self.__used_attrs_changed) self.used_attrs.rowsRemoved.connect(self.__used_attrs_changed) - self.used_attrs_view = VariablesListItemView( - acceptedType=(Orange.data.DiscreteVariable, - Orange.data.ContinuousVariable)) - - self.used_attrs_view.setModel(self.used_attrs) self.used_attrs_view.selectionModel().selectionChanged.connect( partial(update_on_change, self.used_attrs_view)) self.used_attrs_view.dragDropActionDidComplete.connect(dropcompleted) @@ -187,6 +186,7 @@ def dropcompleted(action): ) self.enable_use_features_box() box.layout().addWidget(self.use_features_box) + box.layout().addWidget(filter_edit) box.layout().addWidget(self.used_attrs_view) layout.addWidget(box, 0, 2, 1, 1) diff --git a/Orange/widgets/data/tests/test_owselectcolumns.py b/Orange/widgets/data/tests/test_owselectcolumns.py index 6ab3bbcb420..86178e361c4 100644 --- a/Orange/widgets/data/tests/test_owselectcolumns.py +++ b/Orange/widgets/data/tests/test_owselectcolumns.py @@ -1,7 +1,8 @@ from unittest import TestCase from unittest.mock import Mock -from AnyQt.QtCore import Qt +from AnyQt.QtCore import QMimeData, QPoint, Qt +from AnyQt.QtGui import QDragEnterEvent from Orange.data import Table, ContinuousVariable, DiscreteVariable, Domain from Orange.widgets.data.contexthandlers import \ @@ -346,3 +347,19 @@ def test_use_features_checked(self): self.assertFalse(widget.use_features_box.checkbox.isChecked()) self.assertListEqual(out_features, AttributeList(attrs)) self.assertControlsEnabled(True, True, True, widget) + + def test_used_attrs_supported_types(self): + data = Table("zoo") + event = self._drag_enter_event(data.domain[:1]) + self.widget.used_attrs_view.dragEnterEvent(event) + self.assertTrue(event.isAccepted()) + + event = self._drag_enter_event(data.domain.metas) + self.widget.used_attrs_view.dragEnterEvent(event) + self.assertFalse(event.isAccepted()) + + def _drag_enter_event(self, variables): + self.event_data = mime = QMimeData() + mime.setProperty("_items", variables) + return QDragEnterEvent(QPoint(0, 0), Qt.MoveAction, mime, + Qt.NoButton, Qt.NoModifier) diff --git a/Orange/widgets/utils/listfilter.py b/Orange/widgets/utils/listfilter.py index 3b1eacf980d..df46e9dff3e 100644 --- a/Orange/widgets/utils/listfilter.py +++ b/Orange/widgets/utils/listfilter.py @@ -169,7 +169,7 @@ def eventFilter(self, obj, event): return False -def variables_filter(model, parent=None): +def variables_filter(model, parent=None, accepted_type=Orange.data.Variable): """ GUI components: ListView with a lineedit which works as a filter. One can write a variable name in a edit box and possible matches are then shown in a listview. @@ -221,7 +221,7 @@ def update_completer_prefix(): proxy = VariableFilterProxyModel() proxy.setSourceModel(model) - view = VariablesListItemView(acceptedType=Orange.data.Variable) + view = VariablesListItemView(acceptedType=accepted_type) view.setModel(proxy) model.dataChanged.connect(update_completer_model)