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):
class PyTableModel(QAbstractTableModel):
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.palette = QPalette()
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([])
def rowCount(self, index=QModelIndex()):
return len(self.lstPassItems)+2
def columnCount(self, index=QModelIndex()):
return self.numPasses+1
def data(self, index, role=Qt.DisplayRole):
if 0 == index.row() and 0 == index.column():
if role == Qt.DisplayRole:
return QVariant('Pass')
if role == Qt.TextAlignmentRole:
return QVariant(Qt.AlignTop)
if role == Qt.BackgroundColorRole:
return QVariant(QColor(0,0,0))
if role == Qt.FontRole:
return QVariant(QFont('', 16, QFont.Bold))
if role == Qt.ForegroundRole:
return QVariant(QColor(255,255,255))
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:
return QVariant()
if role == Qt.TextAlignmentRole:
return QVariant(Qt.AlignCenter)
if role == Qt.BackgroundColorRole:
if self.alternateColor_Header:
return QVariant(QColor(0,0,0))
else:
return QVariant(QColor(50,50,50))
if role == Qt.FontRole:
return QVariant(QFont('', 8, QFont.Bold))
if role == Qt.TextColorRole:
return QVariant(QColor(255,255,255))
if 1 == index.row() and (index.column() != 0 and 0 == (index.column()%3)):
if role == Qt.DisplayRole:
return QVariant('Tolerance')
if role == Qt.TextAlignmentRole:
return QVariant(Qt.AlignCenter)
if role == Qt.BackgroundColorRole:
return QVariant(self.palette.color(QPalette.Background).darker(200))
if role == Qt.FontRole:
return QVariant(QFont('', 8, QFont.Normal))
elif 1 == index.row() and (index.column() != 0 and 1 == (index.column()%3)):
if role == Qt.DisplayRole:
return QVariant('Value')
if role == Qt.TextAlignmentRole:
return QVariant(Qt.AlignCenter)
if role == Qt.BackgroundColorRole:
return QVariant(self.palette.color(QPalette.Background).darker(200))
if role == Qt.FontRole:
return QVariant(QFont('', 8, QFont.Normal))
elif 1 == index.row() and (index.column() != 0 and 2 == (index.column()%3)):
if role == Qt.DisplayRole:
return QVariant('Display')
if role == Qt.TextAlignmentRole:
return QVariant(Qt.AlignCenter)
if role == Qt.BackgroundColorRole:
return QVariant(self.palette.color(QPalette.Background).darker(200))
if role == Qt.FontRole:
return QVariant(QFont('', 8, QFont.Normal))
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:
return QVariant(self.palette.color(QPalette.Background).darker(25))
else:
return QVariant(self.palette.color(QPalette.Background).darker(105))
return QVariant()
item = self.lstPassItems[index.row()-2]
if 0 == index.column() and 2 <= index.row():
if role == Qt.DisplayRole:
return QVariant(item[0])
if role == Qt.TextAlignmentRole:
return QVariant(Qt.AlignLeft)
if role == Qt.BackgroundColorRole:
return QVariant(self.palette.color(QPalette.Background).darker(125))
if role == Qt.FontRole:
return QVariant(QFont('', 8, QFont.Normal))
if role == Qt.ToolTipRole:
return QVariant(item[1])
if role == Qt.CheckStateRole:
if self.chkPassItems[index.row()-2] == 1:
return QVariant(Qt.Checked)
else:
return QVariant(Qt.Unchecked)
return QVariant()
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):
return QVariant()
To copy to clipboard, switch view to plain text mode
Bookmarks