Project

General

Profile

How to use neginRemoveRows / endRemoveRows with WTreeView

Added by adam s about 8 years ago

Hi,

I just find some free time and try to continue with my first Wt application where i try to create dynamic WTreeView/Model which will allows adding and removing nodes (There is Add and remove buttons in the column). I use vector of small structures to store information about each node (parent/child) and some internal data for querying db. Index from the vector is used as internalId of WModelIndex. My vector is encapsulated in small Tree structure which is used by model (derived from WAbstractItemModel) to create child/parent indexes and to query database. All this works except of removing node.

In 'remove' button handler i do something like:

beginRemoveRows(parent, row, row);

m_tree.removeNode(parent, row); // this removes child from parent child list

endRemoveRows();

But this seems to be not working if we remove something in the middle. The best way to reproduce this is to remove 2nd node from the end and try to expand last node. In my case WTreeView is querying removed node.

For me it looks like that something is wrong in WTreeViewNode::shiftModelIndexes which is called from modelRowsAboutToBeRemoved, where we reindex the nodes:

if (n && n->modelIndex().row() >= start) {

view_->removeRenderedNode(n);

n~~index_ = view_>model()index(n~~>modelIndex().row() + offset,

n->modelIndex().column(), index_);

if we remove single node, offset=1, so we replace n>index_ with index of previous node, which will be removed.

I just started with Wt, so could someone check if and what I'm doing wrong or if there is a bug in WTreeView?