def __init__(self, xmlData=None, numPasses=1):
super(PyTableModel, self).__init__()
self.alternateColor_Header = True
self.alternateColor_Data = True
self.lstPassItems = [...left out to save space...]
self.chkPassItems = [1]*len(self.lstPassItems)
self.numPasses = numPasses*3
self.lstPasses = range(numPasses)
self.passData = [[[float('%.3F' % (random.randint(0.00, 1000.00)*random.random())),
float('%.3F' % (random.randint(0.00, 1000.00)*random.random())),
float('%.3F' % (random.randint(0.00, 1000.00)*random.random()))]]]
self.initPassData()
print len(self.passData)
print len(self.passData[0])
print len(self.passData[0][0])
def initPassData(self):
for x in range(self.numPasses/3):
for y in range(len(self.lstPassItems)):
self.passData[x].append([float('%.3F' % (random.randint(0.00, 1000.00)*random.random())),
float('%.3F' % (random.randint(0.00, 1000.00)*random.random())),
float('%.3F' % (random.randint(0.00, 1000.00)*random.random()))])
self.passData.append([])
return len(self.lstPassItems)+2
return self.numPasses+1
def data(self, index, role=Qt.DisplayRole):
if 0 == index.row() and 0 == index.column():
if role == Qt.DisplayRole:
if role == Qt.TextAlignmentRole:
if role == Qt.BackgroundColorRole:
if role == Qt.FontRole:
if role == Qt.ForegroundRole:
if 0 == index.row() and index.column() > 0:
if index.column() % 3 == 1:
self.alternateColor_Header = not self.alternateColor_Header
if role == Qt.DisplayRole:
if 1 == (index.column()%3):
return QVariant(self.
lstPasses[index.
column()/3]+1) else:
if role == Qt.TextAlignmentRole:
if role == Qt.BackgroundColorRole:
if self.alternateColor_Header:
else:
if role == Qt.FontRole:
if role == Qt.TextColorRole:
if 1 == index.row() and (index.column() != 0 and 0 == (index.column()%3)):
if role == Qt.DisplayRole:
if role == Qt.TextAlignmentRole:
if role == Qt.BackgroundColorRole:
if role == Qt.FontRole:
elif 1 == index.row() and (index.column() != 0 and 1 == (index.column()%3)):
if role == Qt.DisplayRole:
if role == Qt.TextAlignmentRole:
if role == Qt.BackgroundColorRole:
if role == Qt.FontRole:
elif 1 == index.row() and (index.column() != 0 and 2 == (index.column()%3)):
if role == Qt.DisplayRole:
if role == Qt.TextAlignmentRole:
if role == Qt.BackgroundColorRole:
if role == Qt.FontRole:
if 1 <= index.column() < self.numPasses+1 and 2 <= index.row():
if (index.column()-1) % 3 == 0:
self.alternateColor_Data = not self.alternateColor_Data
if role == Qt.DisplayRole:
return QVariant(self.
passData[(index.
column()-1)/3][index.
row()-2][(index.
column()-1)%3
]) if role == Qt.BackgroundColorRole:
if self.alternateColor_Data:
else:
item = self.lstPassItems[index.row()-2]
if 0 == index.column() and 2 <= index.row():
if role == Qt.DisplayRole:
if role == Qt.TextAlignmentRole:
if role == Qt.BackgroundColorRole:
if role == Qt.FontRole:
if role == Qt.ToolTipRole:
if role == Qt.CheckStateRole:
if self.chkPassItems[index.row()-2] == 1:
else:
def setData
(self, index, value
=QVariant(), role
=Qt.
EditRole): if index.isValid() and (index.column() == 0 and index.row() >= 2):
if role == Qt.CheckStateRole:
if self.chkPassItems[index.row()-2] == 0:
self.chkPassItems[index.row()-2] = 1
else:
self.chkPassItems[index.row()-2] = 0
if role == Qt.EditRole:
try:
if value.toString() != '':
self.passData[(index.column()-1)/3][index.row()-2][(index.column()-1)%3] = float('%.3F' % float(value.toString()))
print 'Pass Data:', self.passData[(index.column()-1)/3][index.row()-2][(index.column()-1)%3]
print 'Value:', float('%.3F' % float(value.toString()))
except ValueError, ve:
pass
return True
def flags(self, index):
if 0 == index.column() and 2 <= index.row():
return Qt.ItemIsUserCheckable|Qt.ItemIsSelectable|Qt.ItemIsEnabled
if 1 <= index.column() < self.numPasses+1:
if 0 <= index.row() < 2:
return Qt.ItemIsSelectable|Qt.ItemIsEnabled
return Qt.ItemIsEditable|Qt.ItemIsEnabled|Qt.ItemIsSelectable
else:
if index.row() <= 1 >= index.column():
return Qt.ItemIsEnabled
return Qt.ItemIsSelectable|Qt.ItemIsEnabled
def headerData(self, section, orientation, role=Qt.DisplayRole):