Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. incremental data fetching logic distorted when resetting the model
Forum Updated to NodeBB v4.3 + New Features

incremental data fetching logic distorted when resetting the model

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 2 Posters 313 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • U Offline
    U Offline
    user4592357
    wrote on last edited by
    #1

    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 return true or false from canFetchMore() 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();
    }
    
    VRoninV 1 Reply Last reply
    0
    • U user4592357

      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 return true or false from canFetchMore() 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();
      }
      
      VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by
      #2

      @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() returns m_pRootNode? if so can you show the code for childCount and actualChildCount?

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      U 1 Reply Last reply
      1
      • VRoninV VRonin

        @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() returns m_pRootNode? if so can you show the code for childCount and actualChildCount?

        U Offline
        U Offline
        user4592357
        wrote on last edited by
        #3

        @VRonin
        yes that's right.

        int TreeNode::childCount() const
        {
        	return m_children.size();
        }
        
        int TreeNode::actualChildCount() const
        {
        	return m_nActualChildCount;
        }
        

        and m_nActualChildCount is calculated once

        VRoninV 1 Reply Last reply
        0
        • U user4592357

          @VRonin
          yes that's right.

          int TreeNode::childCount() const
          {
          	return m_children.size();
          }
          
          int TreeNode::actualChildCount() const
          {
          	return m_nActualChildCount;
          }
          

          and m_nActualChildCount is calculated once

          VRoninV Offline
          VRoninV Offline
          VRonin
          wrote on last edited by
          #4

          @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

          "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
          ~Napoleon Bonaparte

          On a crusade to banish setIndexWidget() from the holy land of Qt

          1 Reply Last reply
          3

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved