This commit is contained in:
Christopher T. Johnson
2025-02-20 18:18:49 -05:00
parent 72a262c718
commit 1bdd6f0c1e

View File

@@ -40,10 +40,14 @@ class dateDelegate(QStyledItemDelegate):
options = cast(QStyleOptionViewItemInit, option) options = cast(QStyleOptionViewItemInit, option)
super().initStyleOption(options, index) super().initStyleOption(options, index)
assert isinstance(index, QModelIndex) assert isinstance(index, QModelIndex)
if index.siblingAtColumn(5).data(Qt.ItemDataRole.CheckStateRole) == Qt.CheckState.Unchecked: if (
index.siblingAtColumn(5).data(Qt.ItemDataRole.CheckStateRole)
== Qt.CheckState.Unchecked
):
options.backgroundBrush = QColor(0x444444) options.backgroundBrush = QColor(0x444444)
return return
class activeDelegate(QStyledItemDelegate): class activeDelegate(QStyledItemDelegate):
def initStyleOption( def initStyleOption(
self, self,
@@ -54,36 +58,58 @@ class activeDelegate(QStyledItemDelegate):
options = cast(QStyleOptionViewItemInit, option) options = cast(QStyleOptionViewItemInit, option)
super().initStyleOption(options, index) super().initStyleOption(options, index)
assert isinstance(index, QModelIndex) assert isinstance(index, QModelIndex)
if index.siblingAtColumn(5).data(Qt.ItemDataRole.CheckStateRole) == Qt.CheckState.Unchecked: if (
index.siblingAtColumn(5).data(Qt.ItemDataRole.CheckStateRole)
== Qt.CheckState.Unchecked
):
options.backgroundBrush = QColor(0x444444) options.backgroundBrush = QColor(0x444444)
return return
class casesModel(QSqlTableModel): class casesModel(QSqlTableModel):
def flags(self, index: QModelIndex | QPersistentModelIndex) -> Qt.ItemFlag: def flags(self, index: QModelIndex | QPersistentModelIndex) -> Qt.ItemFlag:
if not index.isValid(): if not index.isValid():
return Qt.ItemFlag.NoItemFlags return Qt.ItemFlag.NoItemFlags
flags = super(casesModel, self).flags(index) flags = super(casesModel, self).flags(index)
if index.column() == 5: if index.column() == 5:
flags = Qt.ItemFlag.ItemIsEnabled | Qt.ItemFlag.ItemIsEditable | Qt.ItemFlag.ItemIsUserCheckable flags = (
Qt.ItemFlag.ItemIsEnabled
| Qt.ItemFlag.ItemIsEditable
| Qt.ItemFlag.ItemIsUserCheckable
)
return flags return flags
def data(self, index: QModelIndex | QPersistentModelIndex, role: int) -> Any: def data(
self,
index: QModelIndex | QPersistentModelIndex,
role: int = Qt.ItemDataRole.DisplayRole,
) -> Any:
if not index.isValid(): if not index.isValid():
return None return None
if index.column() == 5: if index.column() == 5:
if role == Qt.ItemDataRole.CheckStateRole: if role == Qt.ItemDataRole.CheckStateRole:
value = super(casesModel, self).data(index) value = super(casesModel, self).data(index)
return Qt.CheckState.Checked if value == 1 else Qt.CheckState.Unchecked return (
Qt.CheckState.Checked
if value == 1
else Qt.CheckState.Unchecked
)
elif role == Qt.ItemDataRole.DisplayRole: elif role == Qt.ItemDataRole.DisplayRole:
return '' return ""
return super().data(index, role) return super().data(index, role)
def setData(self, index: QModelIndex | QPersistentModelIndex, value: Any, role: int) -> bool: def setData(
self,
index: QModelIndex | QPersistentModelIndex,
value: Any,
role: int = Qt.ItemDataRole.DisplayRole,
) -> bool:
if role == Qt.ItemDataRole.CheckStateRole and index.column() == 5: if role == Qt.ItemDataRole.CheckStateRole and index.column() == 5:
super(casesModel, self).setData(index, 1 if value else 0) super(casesModel, self).setData(index, 1 if value else 0)
return True return True
return super().setData(index, value, role) return super().setData(index, value, role)
class MainWindow(QMainWindow, Ui_MainWindow): class MainWindow(QMainWindow, Ui_MainWindow):
show_entries = Signal(int) show_entries = Signal(int)
@@ -96,7 +122,9 @@ class MainWindow(QMainWindow, Ui_MainWindow):
model = casesModel() model = casesModel()
model.setTable("cases") model.setTable("cases")
# model.sort(1, Qt.SortOrder.AscendingOrder) # model.sort(1, Qt.SortOrder.AscendingOrder)
model.setFilter("1=1 ORDER BY SUBSTRING(docket_id, 1, 3), CAST(SUBSTRING(docket_id,4) AS INTEGER)") model.setFilter(
"1=1 ORDER BY SUBSTRING(docket_id, 1, 3), CAST(SUBSTRING(docket_id,4) AS INTEGER)"
)
model.select() model.select()
model.setHeaderData(1, Qt.Orientation.Horizontal, "Docket") model.setHeaderData(1, Qt.Orientation.Horizontal, "Docket")
model.setHeaderData(2, Qt.Orientation.Horizontal, "Petitioners") model.setHeaderData(2, Qt.Orientation.Horizontal, "Petitioners")