def __init__(self):
self.bricks = []
def addBrick(self, brick):
self.
beginInsertRows(QModelIndex(), len
(self.
bricks), len
(self.
bricks)) self.bricks.append(brick)
self.endInsertRows()
def removeBrick(self, index):
del self.bricks[index]
self.endRemoveRows()
def clearBricks(self):
if len(self.bricks) != 0:
self.
beginRemoveRows(QModelIndex(),
0, len
(self.
bricks) - 1) self.bricks = []
self.endRemoveRows()
def getAllBricks(self):
return self.bricks
def index(self, row, column, parent):
if not parent.isValid():
if column < 2:
if row > len(self.bricks):
return createIndex(row, column)
def rowCount(self, parent):
return len(self.bricks)
def columnCount(self, parent):
return 2
def data(self, index, role):
if index.column == 0:
return self.bricks[index.row()]['id']
elif index.column == 1:
return self.bricks[index.row()]['comment']
def parent(self, index):
def headerData(self, section, orientation, role):
if section == 0:
return "Brick"
if section == 1:
return "Comment"
class BrickListModel(QAbstractItemModel):
def __init__(self):
QAbstractItemModel.__init__(self)
self.bricks = []
def addBrick(self, brick):
self.beginInsertRows(QModelIndex(), len(self.bricks), len(self.bricks))
self.bricks.append(brick)
self.endInsertRows()
def removeBrick(self, index):
self.beginRemoveRows(QModelIndex(), index, index)
del self.bricks[index]
self.endRemoveRows()
def clearBricks(self):
if len(self.bricks) != 0:
self.beginRemoveRows(QModelIndex(), 0, len(self.bricks) - 1)
self.bricks = []
self.endRemoveRows()
def getAllBricks(self):
return self.bricks
def index(self, row, column, parent):
if not parent.isValid():
if column < 2:
if row > len(self.bricks):
return createIndex(row, column)
return QModelIndex()
def rowCount(self, parent):
return len(self.bricks)
def columnCount(self, parent):
return 2
def data(self, index, role):
if index.column == 0:
return self.bricks[index.row()]['id']
elif index.column == 1:
return self.bricks[index.row()]['comment']
return QVariant()
def parent(self, index):
return QModelIndex()
def headerData(self, section, orientation, role):
if section == 0:
return "Brick"
if section == 1:
return "Comment"
return QVariant()
To copy to clipboard, switch view to plain text mode
Bookmarks