setools/setoolsgui/widgets/models/objclass.py
Chris PeBenito 7e9d0fded9 Update to PyQt6.
Signed-off-by: Chris PeBenito <pebenito@ieee.org>
2024-02-14 09:11:35 -05:00

50 lines
1.4 KiB
Python

# Copyright 2016, Tresys Technology, LLC
#
# SPDX-License-Identifier: LGPL-2.1-only
#
#
from itertools import chain
from PyQt6 import QtCore
import setools
from . import modelroles
from .table import SEToolsTableModel
from .. import details
__all__ = ("ObjClassTable",)
class ObjClassTable(SEToolsTableModel[setools.ObjClass]):
"""Table-based model for object classes."""
headers = ["Name", "Permissions"]
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()
item = self.item_list[row]
match role:
case QtCore.Qt.ItemDataRole.DisplayRole:
match col:
case 0:
return item.name
case 1:
try:
return ", ".join(sorted(chain(item.common.perms, item.perms)))
except setools.exception.NoCommon:
return ", ".join(sorted(item.perms))
case modelroles.ContextMenuRole:
return (details.objclass_detail_action(item), )
case QtCore.Qt.ItemDataRole.ToolTipRole:
return details.objclass_tooltip(item)
return super().data(index, role)