incremental data fetching logic distorted when resetting the model
-
i have implemented incremental data fetching for my tree view class.
at some point in time i need to clear the tree view content:void TreeModel::resetModel() { beginResetModel(); getRootNode()->clear(); endResetModel(); }
where:
void TreeNode::clear() { qDeleteAll(m_children); m_children.clear(); }
however, my tree view is not cleared because after removing the children the root node still exists, and my
canFetchMore()
returns true and tree view is filled again.i'm thinking of keeping a
bool
to determine whether or not to returntrue
orfalse
fromcanFetchMore()
but i don't think that's a good solution. what else can i do?by the way:
bool TreeModel::canFetchMore(const QModelIndex &parent) const { if (!parent.isValid()) return m_pRootNode->childCount() < m_pRootNode->actualChildCount(); // get the node pointer auto node = static_cast<TreeNode *>(parent.internalPointer()); return node->childCount() < node->actualChildCount(); }
-
@user4592357 said in incremental data fetching logic distorted when resetting the model:
and my canFetchMore() returns true
This is the problem, nothing to do with the view.
I assume
getRootNode()
returnsm_pRootNode
? if so can you show the code forchildCount
andactualChildCount
? -
@user4592357 said in incremental data fetching logic distorted when resetting the model:
and m_nActualChildCount is calculated once
This needs to be recalculated if you reset the model