5 from PyQt5
import QtCore, QtWidgets, QtGui
6 from .immutable_gradient_info_handler
import ImmutableGradientInfoHandler
7 from .gradient_info_handler
import GradientInfoHandler
13 MUTABLE_GRADIENTS_PATH =
"user_gradients.xml"
15 dataChanged = QtCore.pyqtSignal(int, int, name=
"dataChanged")
18 QtCore.QAbstractListModel.__init__(self, parent, *args)
27 def AddItem(self, name, gradient, row, editable, save):
29 icon = self.
GetIconGetIcon(gradient)
30 self.
insertRowinsertRow(row, QtCore.QModelIndex())
31 self.
data_data_[row] = [name, gradient, icon, editable]
32 model_index = self.createIndex(row,0)
33 index = self.index(row)
34 end_index = self.createIndex(self.
rowCountrowCount(),0)
37 self.
dataChangeddataChanged.emit(model_index, end_index)
42 return self.
data_data_[row][3]
46 name = self.
data_data_[row][0]
47 self.
removeRowremoveRow(row, QtCore.QModelIndex())
48 model_index = self.createIndex(row,0)
49 self.
infoh_infoh_.RemoveGradient(name)
50 self.
dataChangeddataChanged.emit(model_index, model_index)
55 self.
infoh_infoh_.StoreQGradient(gradient,str(name))
60 for k, v
in qgradients.items():
63 qgradients = self.
infoh_infoh_.GetQGradients()
64 for k, v
in qgradients.items():
68 if model_index.isValid():
69 return self.
data_data_[model_index.row()][1]
76 pixmap = QtGui.QPixmap(64, 64)
77 pixmap.fill(QtCore.Qt.transparent)
78 painter = QtGui.QPainter()
79 if painter.begin(pixmap):
80 gradient.setStart(QtCore.QPointF(0, 0))
81 gradient.setFinalStop(QtCore.QPointF(64, 0))
82 brush = QtGui.QBrush(gradient)
83 painter.setBrush(brush)
84 painter.drawRect(0, 0, 64, 64)
87 return QtGui.QIcon(pixmap)
92 for values
in self.
data_data_:
93 if string == values[0]:
98 def rowCount(self, parent=QtCore.QModelIndex()):
99 return len(self.
data_data_)
102 if index.isValid()
and index.row()< self.
rowCountrowCount():
103 data = self.
data_data_[index.row()]
104 if role == QtCore.Qt.DisplayRole:
105 return QtCore.QVariant(data[0])
106 elif role == QtCore.Qt.DecorationRole:
107 return QtCore.QVariant(data[2])
108 return QtCore.QVariant()
113 if not self.
data_data_[row]:
114 self.
data_data_[row] = list()
115 if role == QtCore.Qt.EditRole
and self.
NameIsValidNameIsValid(value.toString()):
116 old_name = str(self.
data_data_[row][0])
117 new_name = value.toString()
118 self.
data_data_[row][0] = new_name
119 self.
infoh_infoh_.RenameGradient(old_name,str(new_name))
122 elif role == QtCore.Qt.DisplayRole:
123 self.
data_data_[row][0] = value.toString()
124 elif role == QtCore.Qt.DecorationRole:
125 self.
data_data_[row][2] = value.toPyObject()
130 flags = QtCore.QAbstractItemModel.flags(self,index)
132 return flags | QtCore.Qt.ItemIsEditable
135 return QtCore.Qt.ItemIsEnabled
138 self.beginInsertRows(index, position, position)
139 self.
data_data_.insert(position,list())
144 self.beginRemoveRows(index, position, position)
145 del self.
data_data_[position]
def RemoveItem(self, row)
def IsEditable(self, row)
def AddItem(self, name, gradient, row, editable, save)
def data(self, index, role)
def insertRow(self, position, index)
def __init__(self, parent=None, *args)
def LoadGradientFromInfo(self)
def GetIcon(self, gradient)
def GetGradient(self, model_index)
def setData(self, index, value, role)
def removeRow(self, position, index)
def NameIsValid(self, string)
def rowCount(self, parent=QtCore.QModelIndex())
def AddGradientToInfo(self, gradient, name)
String DLLEXPORT_OST_BASE GetSharedDataPath()