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)
23 self.
immutable_infoh_=ImmutablePresetInfoHandler(PresetListModel.IMMUTABLE_PRESET_PATH)
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)
31 self.
infoh_=PresetInfoHandler(mutable_path)
34 def AddItem(self, preset, row, editable, save):
38 self.
data_[row] = [preset, icon, editable]
39 model_index = self.createIndex(row,0)
40 index = self.index(row)
41 end_index = self.createIndex(self.
rowCount(),0)
44 self.dataChanged.emit(model_index, end_index)
49 return self.
data_[row][2]
53 name = self.
data_[row][0].GetName()
55 model_index = self.createIndex(row,0)
56 self.infoh_.RemovePreset(name)
57 self.dataChanged.emit(model_index, model_index)
62 self.infoh_.StorePreset(preset)
66 presets = self.immutable_infoh_.GetPresets()
67 for k, v
in presets.items():
70 presets = self.infoh_.GetPresets()
71 for k, v
in presets.items():
75 if model_index.isValid():
76 return self.
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_:
91 if string == values[0].GetName():
96 def rowCount(self, parent=QtCore.QModelIndex()):
97 return len(self.
data_)
99 def data(self, index, role):
100 if index.isValid()
and index.row()< self.
rowCount():
101 data = self.
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_[row]:
112 self.
data_[row] = list()
113 if role == QtCore.Qt.EditRole
and self.
NameIsValid(value.toString()):
114 old_name = str(self.
data_[row][0].GetName())
115 new_name = value.toString()
116 self.
data_[row][0].SetName(str(new_name))
117 self.infoh_.RenamePreset(old_name,str(new_name))
118 self.dataChanged.emit(index, index)
120 elif role == QtCore.Qt.DisplayRole:
121 self.
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_.insert(position,list())
142 self.beginRemoveRows(index, position, position)
143 del self.
data_[position]
String DLLEXPORT_OST_BASE GetSharedDataPath()