Results 1 to 2 of 2

Thread: What is the right time to refresh tree view of underlying data structure

  1. #1
    Join Date
    Aug 2008
    Posts
    132
    Thanks
    23
    Thanked 3 Times in 3 Posts

    Default Re: What is the right time to refresh tree view of underlying data structure

    Hi

    I've been using a custom tree view model for a long time which shows data contained in an external data structure. Whenever the data structure itself changes I update the model's representation of the tree and call reset. When only data in the data structure changes I emit dataChanged().

    This works well, but its not as fast as it possibly can be. I am trying to optimize this and the main performance issue is that whenever the data structure changes I rebuild the internal representation of the tree. This happens even if the view in which the model is used is not visible. Thus, its a waste. I'm now looking for a way to only rebuild the internal tree representation when the view is visible. Thus, if an update is required when the view is not visible, I delay it until the view becomes visible.

    My question is, what is the right place to know that the view becomes visible. I thought of the following ways:
    - Do it the first time the model receives a request from the view (seems to be in rowCount()).
    - Subclass the view class and do it in the paint() function.
    - Install an event filter on the view and do it when an appropriate event happens (focusIn perhaps).

    Any ideas on what is the optimal way to do this will be appreciated.

    Thanks,
    Jaco


    Added after 20 minutes:


    Quote Originally Posted by JPNaude View Post
    - Do it the first time the model receives a request from the view (seems to be in rowCount()).
    I realize now that rowCount() is const, thus it is probably not the place to do this.


    Added after 47 minutes:


    Ok, rowCount() implementation does the job for me.
    Thanks,
    Jaco
    Last edited by JPNaude; 3rd October 2011 at 10:23.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,363
    Thanks
    3
    Thanked 5,012 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: What is the right time to refresh tree view of underlying data structure

    The ideal approach would be to use the underlying data structure directly without any need to rebuild anything.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. How to map tree model data to list view
    By msopanen in forum Qt Programming
    Replies: 0
    Last Post: 10th November 2009, 19:56
  2. Data structure reference in Model/View Framework
    By jimc1200 in forum Qt Programming
    Replies: 4
    Last Post: 14th September 2009, 20:23
  3. How to constantly refresh time on a view
    By salmanmanekia in forum Qt Programming
    Replies: 5
    Last Post: 23rd June 2008, 12:44
  4. data, model and tree view
    By larry104 in forum Qt Programming
    Replies: 17
    Last Post: 3rd July 2006, 14:43
  5. Replies: 1
    Last Post: 1st March 2006, 11:43

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.