Skip to content

Commit 391b899

Browse files
committed
owtable: output sorted data
1 parent 3a27881 commit 391b899

File tree

1 file changed

+3
-35
lines changed

1 file changed

+3
-35
lines changed

Orange/widgets/data/owtable.py

Lines changed: 3 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -602,6 +602,7 @@ def _setup_table_view(self, view, data):
602602
header = view.horizontalHeader()
603603
header.setSectionsClickable(is_sortable(data))
604604
header.setSortIndicatorShown(is_sortable(data))
605+
header.sortIndicatorChanged.connect(self.update_selection)
605606

606607
view.setModel(datamodel)
607608

@@ -856,7 +857,6 @@ def get_selection(view):
856857
rows = numpy.array(rows, dtype=numpy.intp)
857858
# map the rows through the applied sorting (if any)
858859
rows = model.mapToSourceRows(rows)
859-
rows.sort()
860860
rows = rows.tolist()
861861
return rows, cols
862862

@@ -887,21 +887,6 @@ def commit(self):
887887
rowsel, colsel = self.get_selection(view)
888888
self.selected_rows, self.selected_cols = rowsel, colsel
889889

890-
def select(data, rows, domain):
891-
"""
892-
Select the data subset with specified rows and domain subsets.
893-
894-
If either rows or domain is None they mean select all.
895-
"""
896-
if rows is not None and domain is not None:
897-
return data.from_table(domain, data, rows)
898-
elif rows is not None:
899-
return data.from_table(data.domain, rows)
900-
elif domain is not None:
901-
return data.from_table(domain, data)
902-
else:
903-
return data
904-
905890
domain = table.domain
906891

907892
if len(colsel) < len(domain) + len(domain.metas):
@@ -924,13 +909,11 @@ def select_vars(role):
924909
metas = select_vars(TableModel.Meta)
925910
domain = Orange.data.Domain(attrs, class_vars, metas)
926911

927-
# Avoid a copy if all/none rows are selected.
912+
# Avoid a copy if none rows are selected.
928913
if not rowsel:
929914
selected_data = None
930-
elif len(rowsel) == len(table):
931-
selected_data = select(table, None, domain)
932915
else:
933-
selected_data = select(table, rowsel, domain)
916+
selected_data = table.from_table(domain, table, rowsel)
934917

935918
self.Outputs.selected_data.send(selected_data)
936919
self.Outputs.annotated_data.send(create_annotated_table(table, rowsel))
@@ -1097,21 +1080,6 @@ def is_sortable(table):
10971080
return False
10981081

10991082

1100-
def test_model():
1101-
app = QApplication([])
1102-
view = QTableView(
1103-
sortingEnabled=True
1104-
)
1105-
data = Orange.data.Table("lenses")
1106-
model = TableModel(data)
1107-
1108-
view.setModel(model)
1109-
1110-
view.show()
1111-
view.raise_()
1112-
return app.exec()
1113-
1114-
11151083
if __name__ == "__main__": # pragma: no cover
11161084
WidgetPreview(OWDataTable).run(
11171085
[(Table("iris"), "iris"),

0 commit comments

Comments
 (0)