Skip to content

Commit

Permalink
Merge pull request #3363 from VesnaT/sel_cols_filter
Browse files Browse the repository at this point in the history
[ENH] Select Columns: Enable filtering of used features
  • Loading branch information
lanzagar authored Nov 7, 2018
2 parents 8f65ffe + 35447c1 commit 89df563
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 8 deletions.
10 changes: 5 additions & 5 deletions Orange/widgets/data/owselectcolumns.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)

Expand Down
19 changes: 18 additions & 1 deletion Orange/widgets/data/tests/test_owselectcolumns.py
Original file line number Diff line number Diff line change
@@ -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 \
Expand Down Expand Up @@ -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)
4 changes: 2 additions & 2 deletions Orange/widgets/utils/listfilter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 89df563

Please sign in to comment.