[Qt-jambi-interest] QAbstractTableModel problems
Thomas Coopman
thomas.coopman at gmail.com
Wed Aug 6 12:10:05 CEST 2008
Hi,
I'm trying to write a custom QAbstractTableModel but I have some
problems with inserting data into the model.
My model will have a fixed number of columns and data items can be
added one at a time.
All the items that are present before I start the model get added
correctly. New items that get added in the current row are also shown
correctly but at the moment I have to insert a new row, no more new
items are shown.
I've tried before with both beginInsertColumns and beginInsertRows but
that didn't work.
I've also tried it with calling reset() but even then, items that come
in a new row are not shown.
Does anyone what's wrong?
Thanks!
This is my model code, it is written in scala. (I call updateData
every time an item gets added to auction)
class AuctionModel(auction:Auction) extends QAbstractTableModel {
override def rowCount(parent:QModelIndex):Int = myRowCount
private def myRowCount() = (auction.currentItems.length / 4.0).ceil.toInt
override def columnCount(parent:QModelIndex):Int = myColumnCount
private def myColumnCount() = 4
override def flags(index:QModelIndex):Qt.ItemFlags = {
val flags = new Array[Qt.ItemFlag](1)
flags(0) = Qt.ItemFlag.NoItemFlags
new Qt.ItemFlags(flags)
}
override def data(index:QModelIndex, role:Int):Object = {
try {
println("role = " + role)
println("displayrole = " + Qt.ItemDataRole.DisplayRole)
if (role == Qt.ItemDataRole.DisplayRole) {
println("data")
println(index.column() + (index.row()*myColumnCount))
println(auction.currentItems.length)
auction.currentItems.apply(index.column() + (index.row()*myColumnCount))
} else {
new QVariant()
}
} catch {
case _ => {
new QVariant()
}
}
}
override def headerData(section:Int, orientation:Qt.Orientation,
role:Int):java.lang.Object = {
//TODO
return "Header"
}
def updateData() = {
if (((auction.currentItems.length - 1) % 4) + 1 == 1) {
beginInsertRows(null,myRowCount,myRowCount)
endInsertRows()
}
}
}
--
Thomas Coopman
Thomas.coopman at gmail.com
More information about the Qt-jambi-interest
mailing list