From 0c7fa243e8b610344dd04466ca2b2b0459053921 Mon Sep 17 00:00:00 2001 From: PrimozGodec Date: Fri, 29 Sep 2023 16:13:09 +0200 Subject: [PATCH] Associate - Adopt model clear for pyqt6 --- orangecontrib/associate/widgets/owassociate.py | 17 +++++++++-------- .../associate/widgets/tests/test_owassociate.py | 5 +++++ 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/orangecontrib/associate/widgets/owassociate.py b/orangecontrib/associate/widgets/owassociate.py index a093325..951b680 100644 --- a/orangecontrib/associate/widgets/owassociate.py +++ b/orangecontrib/associate/widgets/owassociate.py @@ -126,7 +126,10 @@ def selectionChanged(self, selected, deselected): table.verticalHeader().setVisible(False) table.verticalHeader().setDefaultSectionSize(table.verticalHeader().minimumSectionSize()) table.horizontalHeader().setStretchLastSection(True) - table.setModel(QStandardItemModel(table)) + proxy_model = self.proxy_model + proxy_model.setSourceModel(QStandardItemModel(table)) + table.setModel(proxy_model) + self.mainArea.layout().addWidget(table) box = gui.widgetBox(self.controlArea, "Info") @@ -323,7 +326,8 @@ def find_rules(self): self._is_running = True data = self.data - self.table.model().clear() + model = self.table.model().sourceModel() + model.clear() n_examples = len(data) NumericItem = self.NumericItem @@ -349,7 +353,6 @@ def find_rules(self): if var is data.domain.class_var} if self.classify else set() assert bool(class_items) == bool(self.classify) - model = QStandardItemModel(self.table) for col, (label, _, tooltip) in enumerate(self.header): item = QStandardItem(label) item.setToolTip(tooltip) @@ -424,20 +427,18 @@ def find_rules(self): table = self.table table.setHidden(True) table.setSortingEnabled(False) - proxy_model = self.proxy_model - proxy_model.setSourceModel(model) - table.setModel(proxy_model) + for i in range(model.columnCount()): table.resizeColumnToContents(i) table.setSortingEnabled(True) table.setHidden(False) - self.table_rules = proxy_model.get_data() + self.table_rules = self.table.model().get_data() self.Outputs.rules.send(self.table_rules) self.button.setText('Find Rules') self.nRules = nRules - self.nFilteredRules = proxy_model.rowCount() # TODO: continue; also add in owitemsets + self.nFilteredRules = model.rowCount() # TODO: continue; also add in owitemsets if not self.nFilteredRules: self.Warning.filter_no_match() self.nSelectedRules = 0 diff --git a/orangecontrib/associate/widgets/tests/test_owassociate.py b/orangecontrib/associate/widgets/tests/test_owassociate.py index 3416d65..4e590ce 100644 --- a/orangecontrib/associate/widgets/tests/test_owassociate.py +++ b/orangecontrib/associate/widgets/tests/test_owassociate.py @@ -29,6 +29,8 @@ def test_filter(self): self.widget.find_rules() output = self.get_output(self.widget.Outputs.rules) self.assertEqual(38, len(output)) + self.assertEqual(38, self.widget.table.model().rowCount()) + self.assertEqual(9, self.widget.table.model().columnCount()) # filter by existing column self.widget.filterKeywordsAntecedent = match_filter @@ -36,6 +38,8 @@ def test_filter(self): self.widget.find_rules() output = self.get_output(self.widget.Outputs.rules) self.assertEqual(5, len(output)) + self.assertEqual(5, self.widget.table.model().rowCount()) + self.assertEqual(9, self.widget.table.model().columnCount()) # filter by non-existing word self.widget.filterKeywordsAntecedent = no_match_filter @@ -44,6 +48,7 @@ def test_filter(self): self.assertTrue(self.widget.Warning.filter_no_match.is_shown()) output = self.get_output(self.widget.Outputs.rules) self.assertIsNone(output) + self.assertEqual(0, self.widget.table.model().rowCount()) # run again with defaults self.widget.filterKeywordsAntecedent = ""