-
Notifications
You must be signed in to change notification settings - Fork 1
/
wakfuitemlist.py
50 lines (37 loc) · 1.33 KB
/
wakfuitemlist.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# This Python file uses the following encoding: utf-8
from PySide6.QtQml import QmlElement
from PySide6.QtCore import Slot,QObject,Signal,Qt,QAbstractListModel,QModelIndex,QByteArray
import settings
QML_IMPORT_NAME = "WakfuItemList"
QML_IMPORT_MAJOR_VERSION = 1
@QmlElement
class WakfuItemList(QAbstractListModel):
wakItemIdRole = Qt.UserRole + 1
wakItemNameRole = Qt.UserRole + 2
def __init__(self, parent=None):
super().__init__(parent=parent)
self.itemList = settings.OPTIMIZED_ITEM_LIST
def rowCount(self, parent=QModelIndex()):
return len(self.itemList)
def roleNames(self):
default = super().roleNames()
default[self.wakItemIdRole] = QByteArray(b"itemId")
default[self.wakItemNameRole] = QByteArray(b"itemName")
return default
def data(self, index, role: int):
if not self.itemList:
ret = None
elif not index.isValid():
ret = None
elif role == self.wakItemIdRole:
ret = self.itemList[index.row()]['id']
elif role == self.wakItemNameRole:
ret = self.itemList[index.row()]['name']
else:
ret = None
return ret
@Slot()
def reload(self):
self.beginResetModel()
self.itemList = settings.OPTIMIZED_ITEM_LIST
self.endResetModel()