5 from PyQt4
import QtCore, QtGui
6 from immutable_preset_info_handler
import ImmutablePresetInfoHandler
7 from preset_info_handler
import PresetInfoHandler
13 MUTABLE_PRESET_PATH =
"user_presets.xml"
16 QtCore.QAbstractListModel.__init__(self, parent, *args)
22 self.
immutable_infoh_=ImmutablePresetInfoHandler(PresetListModel.IMMUTABLE_PRESET_PATH)
23 data_loc=QDesktopServices.storageLocation(QDesktopServices.DataLocation)
24 mutable_path=os.path.join(str(data_loc),
'config',
25 PresetListModel.MUTABLE_PRESET_PATH)
26 qdir=QtCore.QDir(data_loc)
29 self.
infoh_=PresetInfoHandler(mutable_path)
32 def AddItem(self, preset, row, editable, save):
36 self.
data_[row] = [preset, icon, editable]
37 model_index = self.createIndex(row,0)
38 index = self.index(row)
39 end_index = self.createIndex(self.
rowCount(),0)
42 self.emit(QtCore.SIGNAL(
"dataChanged"),model_index, end_index)
47 return self.
data_[row][2]
51 name = self.
data_[row][0].GetName()
53 model_index = self.createIndex(row,0)
54 self.infoh_.RemovePreset(name)
55 self.emit(QtCore.SIGNAL(
"dataChanged"),model_index, model_index)
60 self.infoh_.StorePreset(preset)
64 presets = self.immutable_infoh_.GetPresets()
65 for k, v
in presets.iteritems():
68 presets = self.infoh_.GetPresets()
69 for k, v
in presets.iteritems():
73 if model_index.isValid():
74 return self.
data_[model_index.row()][0]
81 pixmap = QtGui.QPixmap(64, 64)
82 pixmap.fill(QtCore.Qt.transparent)
83 return QtGui.QIcon(pixmap)
88 for values
in self.
data_:
89 if string == values[0].GetName():
94 def rowCount(self, parent=QtCore.QModelIndex()):
95 return len(self.
data_)
97 def data(self, index, role):
98 if index.isValid()
and index.row()< self.
rowCount():
99 data = self.
data_[index.row()]
100 if role == QtCore.Qt.DisplayRole:
101 return QtCore.QVariant(data[0].GetName())
102 elif role == QtCore.Qt.DecorationRole:
103 return QtCore.QVariant(data[1])
104 return QtCore.QVariant()
109 if not self.
data_[row]:
110 self.
data_[row] = list()
111 if role == QtCore.Qt.EditRole
and self.
NameIsValid(value.toString()):
112 old_name = str(self.
data_[row][0].GetName())
113 new_name = value.toString()
114 self.
data_[row][0].SetName(str(new_name))
115 self.infoh_.RenamePreset(old_name,str(new_name))
116 self.emit(QtCore.SIGNAL(
"dataChanged"),index, index)
118 elif role == QtCore.Qt.DisplayRole:
119 self.
data_[row][0].SetName(value.toString())
120 elif role == QtCore.Qt.DecorationRole:
121 self.dat_[row][1] = value.toPyObject()
126 flags = QtCore.QAbstractItemModel.flags(self,index)
128 return flags | QtCore.Qt.ItemIsEditable
131 return QtCore.Qt.ItemIsEnabled
134 self.beginInsertRows(index, position, position)
135 self.data_.insert(position,list())
140 self.beginRemoveRows(index, position, position)
141 del self.
data_[position]
String DLLEXPORT_OST_BASE GetSharedDataPath()