setools/setoolsgui/widgets/models/mls.py
Chris PeBenito 2d755c46ca Clean up item model classes.
* Remove "Model" from names of model classes.
* Remove remaining *_detail() functions.
* Add typing.
* Make models dir a package.
* Update for superclass data() method as fallback.
* Switch to match/case statements.

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

34 lines
876 B
Python

# Copyright 2016, Tresys Technology, LLC
#
# SPDX-License-Identifier: LGPL-2.1-only
#
#
from PyQt5 import QtCore
from .table import SEToolsTableModel
class MLSComponentTable(SEToolsTableModel):
"""Table-based model for sensitivities and categories."""
headers = ["Name", "Aliases"]
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:
return ", ".join(sorted(a for a in item.aliases()))
return super().data(index, role)