5 from PyQt5
import QtCore, QtWidgets, QtGui
6 from .immutable_preset_info_handler
import ImmutablePresetInfoHandler
7 from .preset_info_handler
import PresetInfoHandler
12 MUTABLE_PRESET_PATH =
"user_presets.xml"
14 dataChanged = QtCore.pyqtSignal(int, int, name=
"dataChanged")
17 QtCore.QAbstractListModel.__init__(self, parent, *args)
24 data_loc=str(QtCore.QStandardPaths.writableLocation(QtCore.QStandardPaths.DataLocation))
26 mutable_path=os.path.join(str(data_loc),
'config',
27 PresetListModel.MUTABLE_PRESET_PATH)
28 qdir=QtCore.QDir(data_loc)
34 def AddItem(self, preset, row, editable, save):
36 icon = self.
GetIconGetIcon(preset)
37 self.
insertRowinsertRow(row, QtCore.QModelIndex())
38 self.
data_data_[row] = [preset, icon, editable]
39 model_index = self.createIndex(row,0)
40 index = self.index(row)
41 end_index = self.createIndex(self.
rowCountrowCount(),0)
44 self.
dataChangeddataChanged.emit(model_index, end_index)
49 return self.
data_data_[row][2]
53 name = self.
data_data_[row][0].GetName()
54 self.
removeRowremoveRow(row, QtCore.QModelIndex())
55 model_index = self.createIndex(row,0)
56 self.
infoh_infoh_.RemovePreset(name)
57 self.
dataChangeddataChanged.emit(model_index, model_index)
62 self.
infoh_infoh_.StorePreset(preset)
67 for k, v
in presets.items():
70 presets = self.
infoh_infoh_.GetPresets()
71 for k, v
in presets.items():
75 if model_index.isValid():
76 return self.
data_data_[model_index.row()][0]
83 pixmap = QtGui.QPixmap(64, 64)
84 pixmap.fill(QtCore.Qt.transparent)
85 return QtGui.QIcon(pixmap)
90 for values
in self.
data_data_:
91 if string == values[0].GetName():
96 def rowCount(self, parent=QtCore.QModelIndex()):
97 return len(self.
data_data_)
99 def data(self, index, role):
100 if index.isValid()
and index.row()< self.
rowCountrowCount():
101 data = self.
data_data_[index.row()]
102 if role == QtCore.Qt.DisplayRole:
103 return QtCore.QVariant(data[0].GetName())
104 elif role == QtCore.Qt.DecorationRole:
105 return QtCore.QVariant(data[1])
106 return QtCore.QVariant()
111 if not self.
data_data_[row]:
112 self.
data_data_[row] = list()
113 if role == QtCore.Qt.EditRole
and self.
NameIsValidNameIsValid(value.toString()):
114 old_name = str(self.
data_data_[row][0].GetName())
115 new_name = value.toString()
116 self.
data_data_[row][0].SetName(str(new_name))
117 self.
infoh_infoh_.RenamePreset(old_name,str(new_name))
120 elif role == QtCore.Qt.DisplayRole:
121 self.
data_data_[row][0].SetName(value.toString())
122 elif role == QtCore.Qt.DecorationRole:
123 self.dat_[row][1] = value.toPyObject()
128 flags = QtCore.QAbstractItemModel.flags(self,index)
130 return flags | QtCore.Qt.ItemIsEditable
133 return QtCore.Qt.ItemIsEnabled
136 self.beginInsertRows(index, position, position)
137 self.
data_data_.insert(position,list())
142 self.beginRemoveRows(index, position, position)
143 del self.
data_data_[position]
def RemoveItem(self, row)
def LoadPresetsFromInfo(self)
def IsEditable(self, row)
def data(self, index, role)
def AddItem(self, preset, row, editable, save)
def insertRow(self, position, index)
def GetPreset(self, model_index)
def GetIcon(self, preset)
def __init__(self, parent=None, *args)
def setData(self, index, value, role)
def removeRow(self, position, index)
def NameIsValid(self, string)
def AddPresetToInfo(self, preset)
def rowCount(self, parent=QtCore.QModelIndex())
String DLLEXPORT_OST_BASE GetSharedDataPath()