Results 1 to 9 of 9

Thread: how to setRootPath(...) on a QSortFilterProxyModel of a QFileSystemModel

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jul 2013
    Posts
    15
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: how to setRootPath(...) on a QSortFilterProxyModel of a QFileSystemModel

    You mean like this ...
    Qt Code:
    1. QFSMfilenameView = new QFileSystemModel(this);
    To copy to clipboard, switch view to plain text mode 
    and
    Qt Code:
    1. QModelIndex index = QFSMfilenameView->setRootPath(qsPath);
    To copy to clipboard, switch view to plain text mode 

    -Enjoy
    fh : )_~

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: how to setRootPath(...) on a QSortFilterProxyModel of a QFileSystemModel

    Qt Code:
    1. QModelIndex sourceIndex = QFSMfilenameView->setRootPath(qsPath); // gives a model index on the original model
    2. QModelIndex proxyIndex = filenameSortFilterModel->mapFromSource(sourceIndex); // converts that to an index on the proxy
    3. // do something with the view(s) using the proxy index
    4. ui->filenameListView->setRootIndex(proxyIindex);
    To copy to clipboard, switch view to plain text mode 
    You need the index on the proxy because those are the indexes the view(s) you have attached to the proxy will see and use.

  3. #3
    Join Date
    Jul 2013
    Posts
    15
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: how to setRootPath(...) on a QSortFilterProxyModel of a QFileSystemModel

    I have done exactly that excluding the proxyIndex (had it at one time), no point in having it because the code
    Qt Code:
    1. QFSMfilenameView->setRootPath(qsPath);
    To copy to clipboard, switch view to plain text mode 
    Returns an invalid index after the QSortFilterProxyModel has been attached.

    And yes, qsPath is valid.

    EDIT:
    Off topic, but ... What tags are used to get the Qt objects to link to the docs like you do in your posts?

    -Enjoy
    fh : )_~

  4. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: how to setRootPath(...) on a QSortFilterProxyModel of a QFileSystemModel

    The base model is unaware of the proxy which interacts with it no differently than a view would. I guess the question is, what are you trying to achieve?

    Many Qclasses are linked automatically when they are inside [code][/code] tags. Outside of code use can use [qtclass][/qtclass] or [docs=somesuch.html#anchor][/docs]

  5. #5
    Join Date
    Jul 2013
    Posts
    15
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: how to setRootPath(...) on a QSortFilterProxyModel of a QFileSystemModel

    Hate to be a dink ... But!

    Did you even read the OP?

    Everything that has been discussed so far (other then the Markup tags) is in the unedited OP.
    Including the goal!

    Thanks for the [qtclass] markup tags.

    -Enjoy
    fh : )_~

  6. #6
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: how to setRootPath(...) on a QSortFilterProxyModel of a QFileSystemModel

    Yes I read the OP. At your kind invitation I have re-read it. Your variable naming had me mildly confused (e.g. models and views with names ending View) and I was assuming that both views sat on the same model. There's no mention of mapFromSource() in your OP, so you've learned something new there.

    You are retrieving a path from the directory view. You have a correct path to a directory.

    You want that path to be the root of the file view. You need the index of that path in the model underlying the file view and QFileSystemModel::index() does that.
    Qt Code:
    1. QModelIndex index = QFSMfilenameView->index(qsPath);
    2. // your view is sitting on the top of a proxy you need to map the index to a proxy index:
    3. QModelIndex proxyIndex = filenameSortFilterModel->mapFromSource(index);
    4. // before you can use that to set the root of the file view:
    5. ui->filenameListView->setRootIndex(proxyIndex);
    To copy to clipboard, switch view to plain text mode 
    Unfortunately this doesn't work because QFSMfilenameView is filtered to exclude directories, and the path you are supplying is a directory, so there is no index in the source model for that path. As a result, both indexes are invalid and the file view does not behave as expected. If you remove the filter on the QFSMfilenameView the indexes are good but the file view displays directories you don't want.

    I cannot see a straightforward way to make this work with the models as is. You may be able to use the file proxy to filter on QFileSystemModel::type() to exclude "Directory" or "Folder".

  7. #7
    Join Date
    Jul 2013
    Posts
    15
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: how to setRootPath(...) on a QSortFilterProxyModel of a QFileSystemModel

    Beautiful ... I understand!

    As already stated I removed the proxyIndex (mapToSource) for the post, it wasn't working, not needed for the question.

    Yup, I agree about the "View" variable names on the data models... I already changed them to be more inline with the others. Hey, It's where I started!

    Working on trying to come up with a different design, ain't visioned one yet ...

    Thank you

    -Enjoy
    fh : )_~

Similar Threads

  1. Replies: 7
    Last Post: 13th February 2014, 06:23
  2. Replies: 2
    Last Post: 9th July 2013, 10:13
  3. Replies: 3
    Last Post: 22nd August 2012, 03:32
  4. Replies: 0
    Last Post: 9th March 2011, 00:08

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
  •  
Qt is a trademark of The Qt Company.