I'm not sure which signals you mean...layoutAboutToBeChanged() or rowsAboutToBeInserted() perhaps?
I think beginInsertRows() will take care of those things
Anyway, this is how my insert mechanism looks like
Is this what you have in mind?
bool DomModel::insertRows(int position, int rows, const QModelIndex& parent)
{
DomItem *parentItem;
if (!parent.isValid())
parentItem = rootItem;
else
parentItem = static_cast<DomItem*>(parent.internalPointer());
//only need to append one child
beginInsertRows(parent, position, position);
if(!parentItem->insertChild())
return false;
endInsertRows();
return true;
}
bool DomItem::insertChild()
{
int rows = childItems.count();
DomItem *item = new DomItem(node, rows+1, this);
domNode.appendChild(node);
childItems.insert(rows+1, item);
return true;
}
bool DomModel::insertRows(int position, int rows, const QModelIndex& parent)
{
DomItem *parentItem;
if (!parent.isValid())
parentItem = rootItem;
else
parentItem = static_cast<DomItem*>(parent.internalPointer());
//only need to append one child
beginInsertRows(parent, position, position);
if(!parentItem->insertChild())
return false;
endInsertRows();
return true;
}
bool DomItem::insertChild()
{
int rows = childItems.count();
QDomNode node;
DomItem *item = new DomItem(node, rows+1, this);
domNode.appendChild(node);
childItems.insert(rows+1, item);
return true;
}
To copy to clipboard, switch view to plain text mode
I keep getting the same message(which was written wrong in my last post)
QTreeView::rowsInserted internal representation of the model has been corrupted, resetting.
It looks like bad indexing occurs...but I'm not sure why that happens.
Bookmarks