00001 from ost import gui
00002 from ost import gfx
00003 import os
00004 import ost
00005 from PyQt4 import QtCore, QtGui
00006 from preset import Preset
00007
00008 class PresetEditorListModel(QtCore.QAbstractListModel):
00009 def __init__(self, preset, parent=None, *args):
00010 QtCore.QAbstractListModel.__init__(self, parent, *args)
00011
00012 self.preset_ = preset
00013
00014 def AddItem(self, op, row):
00015 self.insertRow(row, QtCore.QModelIndex(),op)
00016 model_index = self.createIndex(row,0)
00017 end_index = self.createIndex(self.rowCount(),0)
00018 self.emit(QtCore.SIGNAL("dataChanged"),model_index, end_index)
00019 return True
00020
00021 def RemoveItem(self, row):
00022 self.removeRow(row, QtCore.QModelIndex())
00023 model_index = self.createIndex(row,0)
00024 self.emit(QtCore.SIGNAL("dataChanged"),model_index, model_index)
00025 return True
00026
00027 def GetOp(self, model_index):
00028 if model_index.isValid():
00029 return self.preset_.GetOp(model_index.row())
00030
00031 def SetItem(self, model_index, op):
00032 self.preset_.SetOp(model_index.row(), op)
00033
00034 def GetLastRow(self):
00035 return self.rowCount()
00036
00037
00038 def rowCount(self, parent=QtCore.QModelIndex()):
00039 return self.preset_.GetOpCount()
00040
00041 def data(self, index, role):
00042 if index.isValid() and index.row()< self.rowCount():
00043 data = self.preset_.GetOp(index.row())
00044 if role == QtCore.Qt.DisplayRole:
00045 name=data.GetName()
00046 selection=str(data.GetSelection())
00047 if(len(selection)>0):
00048 return QtCore.QVariant(str("%s (%s)"%(name,selection.replace(os.linesep, " "))))
00049 else:
00050 return QtCore.QVariant(str("%s (all)"%name))
00051 return QtCore.QVariant()
00052
00053 def setData(self, index, value, role):
00054 if index.isValid():
00055 row = index.row()
00056 data = self.preset_.GetOp(row)
00057 if role == QtCore.Qt.EditRole:
00058 return True
00059 elif role == QtCore.Qt.DisplayRole:
00060 data
00061 elif role == QtCore.Qt.DecorationRole:
00062 data
00063 return False
00064
00065 def flags(self, index):
00066 if index.isValid():
00067 flags = QtCore.QAbstractItemModel.flags(self,index)
00068 return flags | QtCore.Qt.ItemIsEditable
00069 return QtCore.Qt.ItemIsEnabled
00070
00071 def insertRow(self, position, index, op):
00072 self.beginInsertRows(index, position, position)
00073 self.preset_.InsertOp(position, op)
00074 self.endInsertRows()
00075 return True
00076
00077 def removeRow(self, position, index):
00078 self.beginRemoveRows(index, position, position)
00079 self.preset_.RemoveOpAt(position)
00080 self.endRemoveRows()
00081 return True
00082