Results 1 to 1 of 1

Thread: Proxy for the QFileSystemModel

  1. #1
    Join Date
    Jan 2011
    Posts
    127
    Thanks
    42
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Proxy for the QFileSystemModel

    Qt Code:
    1. #include <QtCore>
    2. #include <QtGui>
    3.  
    4. class busyProxy : public QSortFilterProxyModel
    5. {
    6. Q_OBJECT
    7. public:
    8. explicit busyProxy(QObject *parent = 0) : QSortFilterProxyModel(parent) {}
    9.  
    10. bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const
    11. {
    12. QModelIndex index = sourceModel()->index(source_row, 0, source_parent);
    13. QString const &text = sourceModel()->data(index).toString();
    14. //the folder "very big" contains a lot of jpg, and I only want
    15. //to show one of it which name "kkk0.jpg"
    16. if(text == "kkk0.jpg" || text == "kkk1000.jpg" || text == "kkk10.jpg") return true;
    17.  
    18. if(text == "very big") return true;
    19.  
    20. return false;
    21. }
    22.  
    23. bool lessThan(const QModelIndex &left, const QModelIndex &right) const
    24. {
    25. QString const leftString = sourceModel()->data(left).toString();
    26. QString const rightString = sourceModel()->data(right).toString();
    27.  
    28. qDebug() << leftString << ", " << rightString;
    29.  
    30. return leftString > rightString;
    31. }
    32. };
    33.  
    34. //Do nothing, only want to compare with the busyProxy
    35. class lazyProxy : public QSortFilterProxyModel
    36. {
    37. Q_OBJECT
    38. public:
    39. explicit lazyProxy(QObject *parent = 0) : QSortFilterProxyModel(parent) {}
    40. };
    41.  
    42. class testProxyFiles : public QWidget
    43. {
    44. public:
    45. testProxyFiles()
    46. {
    47. QFileSystemModel *model = new QFileSystemModel(this);
    48.  
    49. lazyProxy *lazyPro = new lazyProxy(this);
    50. lazyPro->setSourceModel(model);
    51.  
    52. QTableView *sourceView = new QTableView(this);
    53. sourceView->setModel(lazyPro);
    54. QString const rootPath = "E:/file_test/very big";
    55. sourceView->setRootIndex(lazyPro->mapFromSource(model->setRootPath(rootPath)));
    56.  
    57. QTableView *proxyView = new QTableView(this);
    58. busyProxy *busyPro = new busyProxy(this);
    59. busyPro->setSourceModel(model);
    60. proxyView->setModel(busyPro);
    61. proxyView->setRootIndex(busyPro->mapFromSource(model->setRootPath(rootPath)));
    62.  
    63. QHBoxLayout *layout = new QHBoxLayout(this);
    64. layout->addWidget(sourceView);
    65. layout->addWidget(proxyView);
    66.  
    67. setLayout(layout);
    68. }
    69. };
    70.  
    71.  
    72. inline int proxyFiles(QApplication &app)
    73. {
    74. testProxyFiles proxy;
    75. proxy.show();
    76.  
    77. return app.exec();
    78. }
    79.  
    80. int main( int argc, char **argv )
    81. {
    82. QApplication app( argc, argv );
    83.  
    84. proxyFiles(app);
    85.  
    86. return 0;
    87. }
    To copy to clipboard, switch view to plain text mode 

    I have several questions :
    1 : On line 16~18, do I have other solution to filter out the item of the QFileSystemModel?
    The QFileSystemModel would navigate the root first, if I don't return true when the text
    equal to "very big", the proxy wouldn't navigate the files inside "very big"

    2 : when I show the item by busyProxy or lazyProxy, the indexes on the leftside are weird, how could
    I edit them?When I set the QFileSystemModel as the model of QtableView, the indexes looks fine.

    3 : the lessThan function never print anything, but why?

    4 : Do you have any easy examples for the proxy of QFileSystemModel? I can't find a topic
    talk about how to design a proxy for QFileSystemModel

    Thanks a lot


    Added after 14 minutes:


    Besides, how could I ask the view to display all of the drives(win7)?
    Qt Code:
    1. sourceView->setRootIndex(lazyPro->mapFromSource(model->setRootPath(rootPath)));
    To copy to clipboard, switch view to plain text mode 

    What kind of path should I set at the "setRootPath" function?Thanks
    Last edited by stereoMatching; 26th July 2012 at 12:26.

Similar Threads

  1. QFileSystemModel with checkboxes...
    By been_1990 in forum Qt Programming
    Replies: 14
    Last Post: 11th March 2011, 15:01
  2. how use QFileSystemModel with QListView ?
    By lwifi in forum Qt Programming
    Replies: 4
    Last Post: 26th April 2010, 03:41
  3. Help with QFileSystemModel
    By TheShow in forum Qt Programming
    Replies: 4
    Last Post: 5th January 2010, 20:11
  4. Notifying QFileSystemModel about changes
    By squidge in forum Qt Programming
    Replies: 3
    Last Post: 23rd November 2009, 23:24
  5. QDirModel or QFileSystemModel?
    By ricardo in forum Qt Programming
    Replies: 1
    Last Post: 21st June 2009, 17:10

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.