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. QFileSystemModel - iterating through current index children
Forum Updated to NodeBB v4.3 + New Features

QFileSystemModel - iterating through current index children

Scheduled Pinned Locked Moved General and Desktop
68 Posts 7 Posters 48.7k 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.
  • A Offline
    A Offline
    andre
    wrote on last edited by
    #21

    It is still on my radar, but time is flying and to be honest, I'm also a bit bussy enjoying the excellent weather out here for a bit ;-) Thanks for the reminder though!

    1 Reply Last reply
    0
    • P Offline
      P Offline
      phamtv
      wrote on last edited by
      #22

      Hi Andre... Any progress?

      1 Reply Last reply
      0
      • A Offline
        A Offline
        andre
        wrote on last edited by
        #23

        I am making good progress. I am just trying to find some last issues, but the basics are working just fine. I guess I also need to bolt some kind of API onto it for modifying and querying the checked items from code, but that is for later.

        1 Reply Last reply
        0
        • A Offline
          A Offline
          andre
          wrote on last edited by
          #24

          The snippets you requested have turned into a complete class. The principle works, -but there is still an issue to iron out that sometimes, an infinate recursion is triggered and the application crashes. That, of course, is not acceptable.-

          Still, working with a QFileSystemModel as the base model, the proxy nicely manages to add checkboxes to each node, and make branch nodes work as expected (checking or unchecking them will do the same for the whole subtree, while having both checked and unchecked nodes in the subtree results in the Partially Checked checkbox state). That works with a minimum number of items that are actually tracked. In a realistic scenario on a pretty big file system, I still only had a few dozen items in the internal data store that tracks the check state of each node. The proxy model automatically reduces the number of size of the internal data store to a minimum. Obviously, all that works without recursing into the base model more deeply than the user already has, let alone trying to iterate over all children and trying to make the model fetch all of them. :-)

          Now that I have a complete class, the question arises under what licence to publish it. Do you need it for an open source project, or do you need something compatible with a closed source application? It turned out to be quite a bit of work to get working, even though the principles are actually the same as I described on the previous page of this topic. That makes me a bit reluctant to just dump it into the public domain...

          Edit:
          I have managed to resolve the issue, I think. At least the class now seems to work reliably under my tests. See screenshot below for how it looks:
          !http://dl.dropbox.com/u/16442531/CheckableProxyModelDemo.png(Screenshot of CheckableProxyModel class applied to a QFileSystemModel)!

          What kind of additional API would be needed, you think? I am thinking along these lines:

          An API to set the default state of all the nodes to either checked or unchecked (done)

          An API to list the checked subtrees (QModelIndexList with the top nodes that have everything under them checked) (done)

          An API to list the checked branch nodes (also a QModelIndexList) (done)

          Signals to indicate when 1 or 2 changes (done, though only one change signal for now)

          ... ?

          Will we need convenience API to set the check-state programatically? I mean, you can already do that of course by using QAbstractItemModel::setData() just like the view does, but perhaps that could be made easier. What might be handy is to be able to specify the check state based on the source models QModelIndex-es. That way, it would be easy to set for instance the check state based on the file path when using a QFileSystemModel as the source model.

          1 Reply Last reply
          0
          • A Offline
            A Offline
            andre
            wrote on last edited by
            #25

            OK, I guess the class is pretty much done. All the ideas in my previous post have been implemented, and the class seems to behave nicely even when you also use the sort capabilities of the QSortFilterProxyModel it is based on.

            1 Reply Last reply
            0
            • G Offline
              G Offline
              giesbert
              wrote on last edited by
              #26

              Hi Andre,

              did you think of making this class a contribution to Qt? Or a QtSolution or something. It sounds really interesting.

              Nokia Certified Qt Specialist.
              Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

              1 Reply Last reply
              0
              • A Offline
                A Offline
                andre
                wrote on last edited by
                #27

                I am thinking of the best way to do this, yes. I'm not sure if it should be a Qt contribution, or some other third party component, nor I am sure if I could perhaps make some kind of dual licence for it.

                Edit: a suggestion at #qt-labs was to make it into a Qt example. That might work.

                1 Reply Last reply
                0
                • P Offline
                  P Offline
                  phamtv
                  wrote on last edited by
                  #28

                  Hi Andre, it looks great and I can´t wait to see its implementation!!! I do not need it to be closed source, thus, any license you see fit should work.

                  1 Reply Last reply
                  0
                  • A Offline
                    A Offline
                    andre
                    wrote on last edited by
                    #29

                    OK. I guess I will start by tagging the files as GPL for now, and then put the whole project into a git repository somewhere, and I'll put the link here.

                    phamtv: do you think you will be needing other API than what's already available?

                    1 Reply Last reply
                    0
                    • P Offline
                      P Offline
                      phamtv
                      wrote on last edited by
                      #30

                      How hard will it be to get a list of unchecked files from the root directory filtered by a certain extention.

                      For instance, you´ve filter the model to show all .txt file in the tree. I see that you have all of the checked .txt file listed in the snapshot shown above. How hard will it to be to get all the .txt file that is NOT checked from your model?

                      edit: The goal is to get a list of all UNCHECKED filtered files from -partially checked/checked- all directory.

                      1 Reply Last reply
                      0
                      • A Offline
                        A Offline
                        andre
                        wrote on last edited by
                        #31

                        Hmmm... That is actually not trivial. I guess you can do the filtering on .txt files using the QFileSystemModel itself, by using the setNameFilter.

                        In principle, getting the unchecked items from the tree is about the same complexity as getting the checked ones: doable. That is: you would get a list of unchecked files, and of unchecked branches.
                        However, it is not really feasable to get all the unchecked .txt files inside the unchecked branches. That would bring you back to having to populate the entire tree and potentially recurse through the whole file system to find them all. That would be outside the scope of this class, and should be done using QDirIterator, I think (if you really can't avoid this) or using system dependent methods if your system supports more efficient search of files than just scanning the complete file system. You can still use the results of the selection to limit the search scope though.

                        1 Reply Last reply
                        0
                        • P Offline
                          P Offline
                          phamtv
                          wrote on last edited by
                          #32

                          You read my mind. It is very specific to my project. I have been researching and I think that QDirIterator along with your class will be the solution to my problem. I will basically use QDirIterator to get all my filtered files and compare it to your model/class result and determine if it is unchecked.. Thanks!

                          1 Reply Last reply
                          0
                          • P Offline
                            P Offline
                            phamtv
                            wrote on last edited by
                            #33

                            Just crossed my mind, will the class you´ve implemented support multiple selection check/uncheck propagation?

                            1 Reply Last reply
                            0
                            • A Offline
                              A Offline
                              andre
                              wrote on last edited by
                              #34

                              [quote author="phamtv" date="1304006640"]You read my mind. It is very specific to my project. I have been researching and I think that QDirIterator along with your class will be the solution to my problem. I will basically use QDirIterator to get all my filtered files and compare it to your model/class result and determine if it is unchecked.. Thanks![/quote]

                              I could add methods to get the unchecked files and branches like you can get the checked ones now. That would mean that you would only need to iterate over the branches returned by this method. That might be much quicker than iterating over the whole FS, and then comparing.

                              [quote author="phamtv" date="1304006828"]Just crossed my mind, will the class you´ve implemented support multiple selection check/uncheck propagation?[/quote]

                              I am not sure what you mean by that. Checking/unchecking all the selected files in one go?
                              Such a thing is not possible to support directly, as the selection is not part of the model. The model doesn't know about which items are selected. It could be done by simply setting the check state on all indexes in a selection though.

                              1 Reply Last reply
                              0
                              • P Offline
                                P Offline
                                phamtv
                                wrote on last edited by
                                #35

                                bq. I could add methods to get the unchecked files and branches like you can get the checked ones now. That would mean that you would only need to iterate over the branches returned by this method. That might be much quicker than iterating over the whole FS, and then comparing.

                                That would be greatly appreciated! However, like you´ve said, wouldn´t that mean that if my initial state for all the dir and files were unchecked,

                                bq. That would bring you back to having to populate the entire tree and potentially recurse through the whole file system to find them all

                                1 Reply Last reply
                                0
                                • A Offline
                                  A Offline
                                  andre
                                  wrote on last edited by
                                  #36

                                  [quote author="phamtv" date="1304007289"]bq. I could add methods to get the unchecked files and branches like you can get the checked ones now. That would mean that you would only need to iterate over the branches returned by this method. That might be much quicker than iterating over the whole FS, and then comparing.

                                  That would be greatly appreciated! However, like you´ve said, wouldn´t that mean that if my initial state for all the dir and files were unchecked,

                                  bq. That would bring you back to having to populate the entire tree and potentially recurse through the whole file system to find them all[/quote]

                                  Yes, it would. But if you are interested in unchecked items, then it would probably make sense to make checked the default for all the nodes at the start. I don't think there is a way around to recursing through at least part of the file system in your case, and a worst-case scenario for that would be recursing through the whole file system.

                                  1 Reply Last reply
                                  0
                                  • P Offline
                                    P Offline
                                    phamtv
                                    wrote on last edited by
                                    #37

                                    Correct! The default state would have to be checked. Can you add the methods to get unchecked files? Thanks!

                                    1 Reply Last reply
                                    0
                                    • A Offline
                                      A Offline
                                      andre
                                      wrote on last edited by
                                      #38

                                      [quote author="phamtv" date="1304007771"]Correct! The default state would have to be checked. Can you add the methods to get unchecked files? Thanks![/quote]

                                      Done. :-)

                                      1 Reply Last reply
                                      0
                                      • A Offline
                                        A Offline
                                        andre
                                        wrote on last edited by
                                        #39

                                        I have created a "repository":https://gitorious.org/checkableproxymodel on gitorious for this project. The licence for this project is GPL-3. Note that CheckableProxyModel makes use of my "DelayedExecutionTimer class":http://developer.qt.nokia.com/wiki/Delay_action_to_wait_for_user_interaction that I published earlier on this site (BSD).

                                        I have also made a separate "announcement":http://developer.qt.nokia.com/forums/viewthread/5531/ in the showcase section.

                                        1 Reply Last reply
                                        0
                                        • P Offline
                                          P Offline
                                          phamtv
                                          wrote on last edited by
                                          #40

                                          I sincerely appreciate your time and effort of support! This is a major piece of the puzzle for the application I am currently working on. Thank You!!!!

                                          1 Reply Last reply
                                          0

                                          • Login

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