Skip to content

Commit

Permalink
Associate - Adopt model clear for pyqt6
Browse files Browse the repository at this point in the history
  • Loading branch information
PrimozGodec committed Sep 29, 2023
1 parent 41f20ab commit 0c7fa24
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
17 changes: 9 additions & 8 deletions orangecontrib/associate/widgets/owassociate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions orangecontrib/associate/widgets/tests/test_owassociate.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,17 @@ 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
self.widget.filter_change()
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
Expand All @@ -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 = ""
Expand Down

0 comments on commit 0c7fa24

Please sign in to comment.