OpenStructure
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
preset_editor_list_model.py
Go to the documentation of this file.
1 from ost import gui
2 from ost import gfx
3 import os
4 import ost
5 from PyQt5 import QtCore
6 from preset import Preset
7 
8 class PresetEditorListModel(QtCore.QAbstractListModel):
9  def __init__(self, preset, parent=None, *args):
10  QtCore.QAbstractListModel.__init__(self, parent, *args)
11 
12  self.preset_ = preset
13 
14  def AddItem(self, op, row):
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)
19  return True
20 
21  def RemoveItem(self, row):
22  self.removeRow(row, QtCore.QModelIndex())
23  model_index = self.createIndex(row,0)
24  self.emit(QtCore.SIGNAL("dataChanged"),model_index, model_index)
25  return True
26 
27  def GetOp(self, model_index):
28  if model_index.isValid():
29  return self.preset_.GetOp(model_index.row())
30 
31  def SetItem(self, model_index, op):
32  self.preset_.SetOp(model_index.row(), op)
33 
34  def GetLastRow(self):
35  return self.rowCount()
36 
37  #Overwritten Methods
38  def rowCount(self, parent=QtCore.QModelIndex()):
39  return self.preset_.GetOpCount()
40 
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:
45  name=data.GetName()
46  selection=str(data.GetSelection())
47  if(len(selection)>0):
48  return QtCore.QVariant(str("%s (%s)"%(name,selection.replace(os.linesep, " "))))
49  else:
50  return QtCore.QVariant(str("%s (all)"%name))
51  return QtCore.QVariant()
52 
53  def setData(self, index, value, role):
54  if index.isValid():
55  row = index.row()
56  data = self.preset_.GetOp(row)
57  if role == QtCore.Qt.EditRole:
58  return True
59  elif role == QtCore.Qt.DisplayRole:
60  data
61  elif role == QtCore.Qt.DecorationRole:
62  data
63  return False
64 
65  def flags(self, index):
66  if index.isValid():
67  flags = QtCore.QAbstractItemModel.flags(self,index)
68  return flags | QtCore.Qt.ItemIsEditable
69  return QtCore.Qt.ItemIsEnabled
70 
71  def insertRow(self, position, index, op):
72  self.beginInsertRows(index, position, position)
73  self.preset_.InsertOp(position, op)
74  self.endInsertRows()
75  return True
76 
77  def removeRow(self, position, index):
78  self.beginRemoveRows(index, position, position)
79  self.preset_.RemoveOpAt(position)
80  self.endRemoveRows()
81  return True
82