setools/setoolsgui/widgets/models/initsid.py
Chris PeBenito b219b44b53 models: Merge list models into table models.
The table model can handle lists as a single/first column.

Signed-off-by: Chris PeBenito <pebenito@ieee.org>
2024-02-14 09:11:35 -05:00

37 lines
897 B
Python

# Copyright 2016, Tresys Technology, LLC
#
# SPDX-License-Identifier: LGPL-2.1-only
#
#
from PyQt5 import QtCore
import setools
from .table import SEToolsTableModel
__all__ = ("InitialSIDTable",)
class InitialSIDTable(SEToolsTableModel[setools.InitialSID]):
"""Table-based model for initial SIDs."""
headers = ["SID", "Context"]
def data(self, index: QtCore.QModelIndex, role: int = QtCore.Qt.ItemDataRole.DisplayRole):
if not self.item_list or not index.isValid():
return None
row = index.row()
col = index.column()
rule = self.item_list[row]
match role:
case QtCore.Qt.ItemDataRole.DisplayRole:
match col:
case 0:
return rule.name
case 1:
return str(rule.context)
return super().data(index, role)