# Copyright 2016, Tresys Technology, LLC # # SPDX-License-Identifier: LGPL-2.1-only # # import typing from PyQt6 import QtCore from .modelroles import ModelRoles from .table import SEToolsTableModel __all__: typing.Final[tuple[str, ...]] = ("CategoryTable", "SensitivityTable") class MLSComponentTable(SEToolsTableModel): """Table-based model for sensitivities and categories.""" headers = ["Name", "Aliases"] def data(self, index: QtCore.QModelIndex, role: int = ModelRoles.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 ModelRoles.DisplayRole: match col: case 0: return item.name case 1: return ", ".join(sorted(a for a in item.aliases())) return super().data(index, role) class CategoryTable(MLSComponentTable): """Table-based model for categories.""" def data(self, index: QtCore.QModelIndex, role: int = ModelRoles.DisplayRole): if not self.item_list or not index.isValid(): return None col = index.column() match role: case ModelRoles.WhatsThisRole: match col: case 0: column_whatsthis = "
This is the name of the category.
" case 1: column_whatsthis = "These are the alias(es) of the category.
" case _: column_whatsthis = "" return \ f"""Table Representation of MLS Categories
Each part of the declaration is represented as a column in the table.
{column_whatsthis} """ return super().data(index, role) class SensitivityTable(MLSComponentTable): """Table-based model for sensitivities.""" def data(self, index: QtCore.QModelIndex, role: int = ModelRoles.DisplayRole): if not self.item_list or not index.isValid(): return None col = index.column() match role: case ModelRoles.WhatsThisRole: match col: case 0: column_whatsthis = "This is the name of the sensitivity.
" case 1: column_whatsthis = "These are the alias(es) of the sensitivity.
" case _: column_whatsthis = "" return \ f"""Table Representation of MLS Sensitivities
Each part of the declaration is represented as a column in the table.
{column_whatsthis} """ return super().data(index, role)