Restore the tree state in Details View if a top-level folder is collapsed and then expanded again

Review Request #113293 - Created Oct. 16, 2013 and submitted

Information
Frank Reininghaus
kde-baseapps
master
304363
Reviewers
dolphin
This patch actually does two things when collapsing an expanded folder with expanded children:

(a) It removes all expanded children (which are removed from the model) from m_expandedDirs. This fixes some very subtle issues (to reproduce, e.g., expand a/ and a/a/, collapse and re-expand a/, note that a/a/ is not expanded, go to another folder and then go back, and see that a/a/ is now expanded, i.e., that the view state is actually not restored correctly).

(b) It remembers the expanded children and restores them if the top-level folder is re-expanded.

Storing the information in the "values" hash is sort of a hack, because this is information that is, unlike the other data stored in this hash, not supposed to be shown in the view. However, I still think that this approach is probably cleaner than all alternatives because it requires changes only in one function. If we stored this information in a new member in KFileItemModel (like a QHash<KUrl, QSet<KUrl> >, where the key is the previously expanded folder, and the value the set of expanded children), we would have to update this member whenever the parent folder is removed from the model (because it is deleted, its own parent gets collapsed, the model is cleared, etc.), so we would need new code in many different places, and remember to update it whenever there is a change in the affected functions.
If I expand a top-level folder and then some of its children, then collapse the top-level folder and re-expand it, the previous state is restored correctly.
Emmanuel Pescosta
Commit Hook
Frank Reininghaus
Review request changed

Status: Closed (submitted)

Loading...