Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] Adopt Associate widget to PyQt6 #59

Merged
merged 1 commit into from
Oct 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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