我正在基于 QAbstractItemModel 实现我的模型,并将它与 QTreeView 一起使用来显示分层数据。数据存储在 sqlite 表中。
我的问题是添加子节点时应该如何调用 beginInsertRows。假设我有一些父节点,它包含 10 个子节点。我想添加新的子节点(最后)。
我这样做是这样的:
beginInsertRows(parentIndex, currentNodesCount, currentNodesCount);
// actual inserting
endInsertRows()
currentNodesCount 包含值 10,这是该子节点中的行数。新节点将放置在第 11 个位置(从 0 开始计数的第 10 个)。
这个逻辑正确吗?
感谢帮助。
我也想知道使用 beginRemoveRows。
它是否正确:
beginRemoveRows(parentIndex, currentRow, currentRow);
// delete record
endRemoveRows();
currentRow 包含从 0 开始计数的已移除节点列表中的位置。