diff --git a/Orange/widgets/data/owrank.py b/Orange/widgets/data/owrank.py index f4b7fafc172..d61c5ec1edb 100644 --- a/Orange/widgets/data/owrank.py +++ b/Orange/widgets/data/owrank.py @@ -169,7 +169,7 @@ class Outputs: nSelected = Setting(5) auto_apply = Setting(True) - headerState = Setting(['', 1]) + sorting = Setting((0, 1)) selected_methods = Setting(set()) settings_version = 2 @@ -421,8 +421,9 @@ def updateScores(self): # Re-apply sort try: - sort_column, sort_order = self.headerState - self.ranksModel.sort(labels.index(sort_column) + 1, sort_order) + sort_column, sort_order = self.sorting + if sort_column < len(labels): + self.ranksModel.sort(sort_column + 1, sort_order) # +1 for '#' (discrete count) column except ValueError: pass @@ -471,8 +472,8 @@ def headerClick(self, index): # Store the header states sort_order = self.ranksModel.sortOrder() - sort_column = self.ranksModel.headerData(self.ranksModel.sortColumn(), Qt.Horizontal) - self.headerState = (sort_column, sort_order) + sort_column = self.ranksModel.sortColumn() - 1 # -1 for '#' (discrete count) column + self.sorting = (sort_column, sort_order) def methodSelectionChanged(self, state, method_name): if state == Qt.Checked: @@ -539,7 +540,26 @@ def migrate_settings(cls, settings, version): # If older settings, restore sort header to default # Saved selected_rows will likely be incorrect if version is None or version < 2: - settings['headerState'] = ('', 1) + column, order = 0, Qt.DescendingOrder + headerState = settings.pop("headerState") + + # Lacking knowledge of last problemType, use discrete ranks view's ordering + if isinstance(headerState, (tuple, list)): + headerState = headerState[0] + + if isinstance(headerState, bytes): + hview = QHeaderView(Qt.Horizontal) + hview.restoreState(headerState) + column, order = hview.sortIndicatorSection() - 1, hview.sortIndicatorOrder() + settings["sorting"] = (column, order) + + @classmethod + def migrate_context(cls, context, version): + if version is None or version < 2: + # Old selection was saved as sorted indices. New selection is original indices. + # Since we can't devise the latter without first computing the ranks, + # just reset the selection to avoid confusion. + context.values['selected_rows'] = [] if __name__ == "__main__": diff --git a/Orange/widgets/data/tests/test_owrank.py b/Orange/widgets/data/tests/test_owrank.py index 9a8c108279e..7272f700950 100644 --- a/Orange/widgets/data/tests/test_owrank.py +++ b/Orange/widgets/data/tests/test_owrank.py @@ -239,7 +239,7 @@ def test_data_which_make_scorer_nan(self): self.widget.selected_methods.add('ANOVA') self.send_signal(self.widget.Inputs.data, table) - def test_setting_migration_extends_header_state(self): + def test_setting_migration_fixes_header_state(self): # Settings as of version 3.3.5 settings = { 'auto_apply': True, @@ -266,4 +266,4 @@ def test_setting_migration_extends_header_state(self): w = self.create_widget(OWRank, stored_settings=settings) - self.assertEqual(len(w.headerState), 3) + self.assertEqual(w.headerState, (1, Qt.AscendingOrder))