QModListModel: return QMod to qml instead of individual properties
This commit is contained in:
parent
058a8346bd
commit
669dd9168d
2 changed files with 14 additions and 22 deletions
|
|
@ -17,9 +17,7 @@ Kirigami.ApplicationWindow {
|
|||
}
|
||||
}
|
||||
component ModCardDelegate: Kirigami.AbstractCard {
|
||||
required property string name
|
||||
required property string description
|
||||
required property bool modEnabled
|
||||
required property QMod mod
|
||||
// headerOrientation: Qt.Horizontal
|
||||
contentItem: Item {
|
||||
implicitWidth: modCardLayout.implicitWidth
|
||||
|
|
@ -49,24 +47,25 @@ Kirigami.ApplicationWindow {
|
|||
ColumnLayout {
|
||||
Kirigami.Heading {
|
||||
Layout.fillWidth: true
|
||||
text: name
|
||||
text: mod.name
|
||||
type: Kirigami.Heading.Type.Primary
|
||||
}
|
||||
Kirigami.Separator {
|
||||
Layout.fillWidth: true
|
||||
}
|
||||
Controls.Label {
|
||||
property string desc: mod.description
|
||||
Layout.fillWidth: true
|
||||
wrapMode: Text.WordWrap
|
||||
text: description ? description : "No description available"
|
||||
font.italic: description ? false : true
|
||||
text: desc ? desc : "No description available"
|
||||
font.italic: desc ? false : true
|
||||
}
|
||||
}
|
||||
ColumnLayout {
|
||||
Layout.alignment: Qt.AlignRight
|
||||
Controls.Switch {
|
||||
text: "Enabled"
|
||||
checked: modEnabled
|
||||
checked: mod.enabled
|
||||
}
|
||||
Controls.Button {
|
||||
text: "Delete"
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
from PySide6.QtQml import QmlElement
|
||||
from PySide6.QtCore import QAbstractListModel, QModelIndex
|
||||
from leek.mod import Mod, InvalidModError
|
||||
from leek.mod import InvalidModError
|
||||
from leek.qmod import QMod
|
||||
from pathlib import Path
|
||||
|
||||
QML_IMPORT_NAME = "Leek"
|
||||
|
|
@ -16,11 +17,11 @@ MOD_PATH = Path(GAME_PATH, "mods")
|
|||
class QModListModel(QAbstractListModel):
|
||||
def __init__(self, parent=None) -> None:
|
||||
super().__init__(parent=parent)
|
||||
mods: list[Mod] = []
|
||||
mods: list[QMod] = []
|
||||
|
||||
for dir in MOD_PATH.iterdir():
|
||||
try:
|
||||
new_mod: Mod = Mod(dir)
|
||||
new_mod: QMod = QMod(dir, self)
|
||||
mods.append(new_mod)
|
||||
except InvalidModError as e:
|
||||
print(f"Found invalid mod at {dir}: {e.message}")
|
||||
|
|
@ -29,26 +30,18 @@ class QModListModel(QAbstractListModel):
|
|||
self.mods = mods
|
||||
|
||||
def roleNames(self) -> dict[int, bytes]:
|
||||
return {
|
||||
0: b"name",
|
||||
1: b"description",
|
||||
2: b"modEnabled"
|
||||
}
|
||||
return {0: b"mod"}
|
||||
|
||||
def rowCount(self, parent=QModelIndex()) -> int:
|
||||
return len(self.mods)
|
||||
|
||||
def data(self, index: QModelIndex, role: int) -> None | str | bool:
|
||||
def data(self, index: QModelIndex, role: int) -> None | QMod:
|
||||
i: int = index.row()
|
||||
result: None | str | bool
|
||||
result: None | QMod
|
||||
if not index.isValid():
|
||||
result = None
|
||||
elif role == 0:
|
||||
result = self.mods[i].name
|
||||
elif role == 1:
|
||||
result = self.mods[i].description
|
||||
elif role == 2:
|
||||
result = self.mods[i].enabled
|
||||
result = self.mods[i]
|
||||
else:
|
||||
result = None
|
||||
return result
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue