Results 1 to 14 of 14

Thread: fetchMore() not working on the top-level index in a QFileSystemModel

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Feb 2013
    Location
    San Diego
    Posts
    37
    Thanks
    14
    Thanked 7 Times in 7 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: fetchMore() not working on the top-level index in a QFileSystemModel

    I have implemented the proxi model in the view itself, because only that view needs that trick with an artificial index to display the rootindex.
    I create the proxi model when I call setModel(). SetModel() is called with the source model.

    Qt Code:
    1. void FileSysSelectView::setModel(QAbstractItemModel * model)
    2. {
    3.  
    4. m_sourceModel = static_cast<FileSysSelectModel *> (model);
    5. m_proxiModel = new QSortFilterProxyModel();
    6. m_proxiModel->setSourceModel(m_sourceModel);
    7.  
    8. QTreeView::setModel(m_proxiModel);
    9.  
    10. // Limit the view to the File name Column (1st Column)
    11. for (int i(1); i < m_proxiModel->columnCount(QModelIndex::QModelIndex()); i++) this->setColumnHidden(i,true);
    12. }
    To copy to clipboard, switch view to plain text mode 
    At that point everything works well, my proxi model sits bettween my view and the source model, and it acts transparently.
    I try to insert the artificial index when I call setRootIndex().

    For exemple, if I want to show what is under C:/, I have to do the folowing:

    before:
    - root
    --C:\
    ---Program Files
    ---Windows
    ---Users
    --D:\
    --X:\

    after:
    - root
    -- artififical index
    ---C:\
    ----Program Files
    ----Windows
    ---Users
    --D:\
    --X:\
    Qt Code:
    1. void FileSysSelectView::setRootIndex(const QModelIndex & index)
    2. {
    3.  
    4. // insert a new index under the specified root index.
    5. QModelIndex idxParent = m_proxiModel->mapFromSource(index.parent());
    6. m_proxiModel->insertRow(0, idxParent);
    7.  
    8. // move the the root index under the new index
    9. QModelIndex idxNew = m_proxiModel->index(0,0, idxParent);
    10. QModelIndex idx = m_proxiModel->mapFromSource(index);
    11. int idxPosition = idx.row();
    12. m_proxiModel->moveRow(idxParent, idxPosition, idxNew, 0);
    13. QTreeView::setRootIndex(idx);
    14. }
    To copy to clipboard, switch view to plain text mode 
    Actually int idxPosition = idx.row() at line 11 doesn't work for the reasons I mentioned earlier in the thread. The underlying QFileSystemModel needs to be populated before idx.row() is called. That means I have to call fetchMore() and check for directroyLoaded() signal in that situation too...

  2. #2
    Join Date
    Feb 2013
    Location
    San Diego
    Posts
    37
    Thanks
    14
    Thanked 7 Times in 7 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: fetchMore() not working on the top-level index in a QFileSystemModel

    Also, I have found another old thread from a different forum that said:

    "Regarding folder sorting on Windows: I think I got it. The damn model only sorts items below its "root path()" as the statrting point which is "/" on Linux /UNIX / Mac Os X, but on windows it's the system driver's root directory. Effectively, only "c:/" and it's sub-folders were sorted...
    Now I'm using "QFileSystemModel::myComputer" as the model's root and as a result everything is sorted as expected."

    http://forums.bannister.org/ubbthrea...68709&page=289

    That might be related to my issue. I don't know how that person managed to use "QFileSystemModel::myComputer" as the model's root, though... it does not retrun a QModelIndex.

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

    Default Re: fetchMore() not working on the top-level index in a QFileSystemModel

    A sort-filter proxy model can't do what you require. You have to implement your own proxy model derived either from QAbstractProxyModel or from QIdentityProxyModel.
    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.


  4. #4
    Join Date
    Feb 2013
    Location
    San Diego
    Posts
    37
    Thanks
    14
    Thanked 7 Times in 7 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: fetchMore() not working on the top-level index in a QFileSystemModel

    QIdentityProxyModel is what I tried in the first place. It didn't work either. I'm not familiar whith proxi models. why do I need my own proxi? Could you give my some guidance or some useful links...
    I search the internet without any success for that...

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

    Default Re: fetchMore() not working on the top-level index in a QFileSystemModel

    Quote Originally Posted by Guett_31 View Post
    QIdentityProxyModel is what I tried in the first place. It didn't work either.
    It won't "work" because it is a transparent proxy. You need to subclass it and implement the functionality you need.

    I'm not familiar whith proxi models. why do I need my own proxi?
    Because you want to add an artificial item to an existing model without changing the original model itself.
    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. Replies: 3
    Last Post: 26th September 2012, 20:21
  2. QComboBox::insertSeparator(int index) is not working
    By osiris81 in forum Qt Programming
    Replies: 2
    Last Post: 14th July 2011, 18:43
  3. QFileSystemModel::remove not removing index from model
    By revorgm in forum Qt Programming
    Replies: 1
    Last Post: 27th February 2011, 09:24
  4. Beginner level program not working
    By Nishant in forum Newbie
    Replies: 9
    Last Post: 11th June 2010, 14:46
  5. Crash while checking the index is of particular level of a tree
    By kapil sharma in forum Qt Programming
    Replies: 1
    Last Post: 27th November 2008, 07:21

Tags for this Thread

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.