Skip to content

Commit

Permalink
Add basic sortfiltermodel
Browse files Browse the repository at this point in the history
  • Loading branch information
jfeil committed Mar 1, 2022
1 parent 6e95c34 commit d828f5e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
6 changes: 4 additions & 2 deletions src/main_application.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from . import controller, document_builder
from .basic_config import app_version, check_for_update, display_name, is_bundled
from .datatypes import Rulegroup, create_rulegroups, create_questions_and_mchoice
from .question_tree import RulegroupView, RuleDataModel
from .question_tree import RulegroupView, RuleDataModel, RuleSortFilterProxyModel
from .regeltestcreator import RegeltestSaveDialog, RegeltestSetup
from .ui_mainwindow import Ui_MainWindow
from .ui_update_checker import Ui_UpdateChecker
Expand Down Expand Up @@ -156,7 +156,9 @@ def create_ruletabs(self, rulegroups: List[Rulegroup]):
tab = QWidget()
view = RulegroupView(tab, rulegroup_id=rulegroup.id)
model = RuleDataModel(rulegroup.id, view)
view.setModel(model)
filter_model = RuleSortFilterProxyModel()
filter_model.setSourceModel(model)
view.setModel(filter_model)
self.ruletabs[rulegroup.id] = view
self.ui.tabWidget.addTab(tab, "")
self.ui.tabWidget.setTabText(self.ui.tabWidget.indexOf(tab), f"{rulegroup.id:02d} {rulegroup.name}")
Expand Down
6 changes: 5 additions & 1 deletion src/question_tree.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from typing import Dict, Union, Any

import PySide6
from PySide6.QtCore import Qt, QPoint, QAbstractTableModel
from PySide6.QtCore import Qt, QPoint, QAbstractTableModel, QSortFilterProxyModel
from PySide6.QtGui import QAction, QDrag
from PySide6.QtWidgets import QTreeWidget, QTreeWidgetItem, QVBoxLayout, QDialog, QMessageBox, QMenu, QListView, \
QTableView, QStyledItemDelegate, QWidget
Expand All @@ -24,6 +24,10 @@ def createEditor(self, parent: PySide6.QtWidgets.QWidget, option: PySide6.QtWidg
return editor


class RuleSortFilterProxyModel(QSortFilterProxyModel):
pass


class RuleDataModel(QAbstractTableModel):
# When subclassing QAbstractTableModel, you must implement rowCount(), columnCount(), and data(). Default
# implementations of the index() and parent() functions are provided by QAbstractTableModel. Well behaved models
Expand Down

0 comments on commit d828f5e

Please sign in to comment.