Skip to content

Commit

Permalink
VizRank: Add filter
Browse files Browse the repository at this point in the history
  • Loading branch information
janezd committed Nov 11, 2016
1 parent 9316b84 commit 80b10d2
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions Orange/widgets/visualize/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
from bisect import bisect_left
from operator import attrgetter

from AnyQt.QtCore import Qt, QSize, pyqtSignal as Signal
from AnyQt.QtCore import Qt, QSize, pyqtSignal as Signal, QSortFilterProxyModel
from AnyQt.QtGui import QStandardItemModel, QStandardItem, QColor, QBrush, QPen
from AnyQt.QtWidgets import (
QTableView, QGraphicsTextItem, QGraphicsRectItem, QGraphicsView, QDialog,
QVBoxLayout
QVBoxLayout, QLineEdit
)
from Orange.data import Variable
from Orange.widgets import gui
Expand Down Expand Up @@ -96,7 +96,16 @@ def __init__(self, master):
self.saved_progress = 0
self.scores = []

self.filter = QLineEdit()
self.filter.setPlaceholderText("Filter ...")
self.filter.textChanged.connect(self.filter_changed)
self.layout().addWidget(self.filter)
# Remove focus from line edit
self.setFocus(Qt.ActiveWindowFocusReason)

self.rank_model = QStandardItemModel(self)
self.model_proxy = QSortFilterProxyModel(self)
self.model_proxy.setSourceModel(self.rank_model)
self.rank_table = view = QTableView(
selectionBehavior=QTableView.SelectRows,
selectionMode=QTableView.SingleSelection,
Expand All @@ -105,7 +114,7 @@ def __init__(self, master):
view.setItemDelegate(TableBarItem())
else:
view.setItemDelegate(HorizontalGridDelegate())
view.setModel(self.rank_model)
view.setModel(self.model_proxy)
view.selectionModel().selectionChanged.connect(
self.on_selection_changed)
view.horizontalHeader().setStretchLastSection(True)
Expand Down Expand Up @@ -185,6 +194,9 @@ def initialize(self):
self.button.setText("Start")
self.button.setEnabled(self.check_preconditions())

def filter_changed(self, text):
self.model_proxy.setFilterFixedString(text)

def stop_and_reset(self, reset_method=None):
if self.keep_running:
self.scheduled_call = reset_method or self.initialize
Expand Down Expand Up @@ -388,6 +400,9 @@ def check_preconditions(self):
return can_rank

def on_selection_changed(self, selected, deselected):
selection = selected.indexes()
if not selection:
return
attrs = selected.indexes()[0].data(self._AttrRole)
self.selectionChanged.emit(attrs)

Expand Down

0 comments on commit 80b10d2

Please sign in to comment.