5 from PyQt4
import QtCore, QtGui
6 from preset
import Preset
9 def __init__(self, preset, parent=None, *args):
10 QtCore.QAbstractListModel.__init__(self, parent, *args)
15 self.
insertRow(row, QtCore.QModelIndex(),op)
16 model_index = self.createIndex(row,0)
17 end_index = self.createIndex(self.
rowCount(),0)
18 self.emit(QtCore.SIGNAL(
"dataChanged"),model_index, end_index)
23 model_index = self.createIndex(row,0)
24 self.emit(QtCore.SIGNAL(
"dataChanged"),model_index, model_index)
28 if model_index.isValid():
29 return self.preset_.GetOp(model_index.row())
32 self.preset_.SetOp(model_index.row(), op)
38 def rowCount(self, parent=QtCore.QModelIndex()):
39 return self.preset_.GetOpCount()
41 def data(self, index, role):
42 if index.isValid()
and index.row()< self.
rowCount():
43 data = self.preset_.GetOp(index.row())
44 if role == QtCore.Qt.DisplayRole:
46 selection=str(data.GetSelection())
48 return QtCore.QVariant(str(
"%s (%s)"%(name,selection.replace(os.linesep,
" "))))
50 return QtCore.QVariant(str(
"%s (all)"%name))
51 return QtCore.QVariant()
56 data = self.preset_.GetOp(row)
57 if role == QtCore.Qt.EditRole:
59 elif role == QtCore.Qt.DisplayRole:
61 elif role == QtCore.Qt.DecorationRole:
67 flags = QtCore.QAbstractItemModel.flags(self,index)
68 return flags | QtCore.Qt.ItemIsEditable
69 return QtCore.Qt.ItemIsEnabled
72 self.beginInsertRows(index, position, position)
73 self.preset_.InsertOp(position, op)
78 self.beginRemoveRows(index, position, position)
79 self.preset_.RemoveOpAt(position)