Results 1 to 5 of 5

Thread: how to use QIdentityProxyModel?

  1. #1
    Join Date
    Oct 2009
    Location
    Mexico
    Posts
    81
    Thanks
    6
    Thanked 10 Times in 10 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default how to use QIdentityProxyModel?

    What is the correct way to subclass or use the QIdentityProxyModel?

    the next are the minimal example who represent my problem. MyIdentityModel can modify the DisplayRole value (change de capitalitation for upper) but the value in ListView are from the listModel not IdentModel

    Qt Code:
    1. #include <QtGui>
    2.  
    3. #include <QDebug>
    4.  
    5. class MyIdentityModel : public QIdentityProxyModel
    6. {
    7. public:
    8. MyIdentityModel(QObject* parent = 0): QIdentityProxyModel(parent)
    9. { qDebug() << "constructor"; }
    10.  
    11. QVariant data(const QModelIndex &index, int role) {
    12. QVariant var = QIdentityProxyModel::data(index,role);
    13. if (role == Qt::DisplayRole)
    14. return var.toString().toUpper();
    15.  
    16. return var;
    17. }
    18. };
    19.  
    20.  
    21. int main(int argc, char *argv[])
    22. {
    23. QApplication a(argc, argv);
    24.  
    25. list << "uno" << "dos" << "tres" << "cuatro"
    26. << "cinco" << "seis" << "siete";
    27.  
    28. listModel->setStringList(list);
    29.  
    30. MyIdentityModel * identModel = new MyIdentityModel;
    31. identModel->setSourceModel(listModel); //setSource model works?
    32.  
    33. //The ident proxy works fine. convert Display role to Upper
    34. //but value display in QListView are from listModel
    35. qDebug() << "data" << identModel->data(
    36. identModel->index(3,0),
    37. Qt::DisplayRole);
    38.  
    39. QListView *w = new QListView;
    40. w->setModel(identModel);
    41. w->show();
    42.  
    43. return a.exec();
    44. }
    To copy to clipboard, switch view to plain text mode 

  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 use QIdentityProxyModel?

    The prototype of your data() function does not match the prototype of the data() function you are trying to override: you are missing a const qualifier.

  3. The following user says thank you to ChrisW67 for this useful post:

    ecanela (3rd August 2012)

  4. #3
    Join Date
    Oct 2009
    Location
    Mexico
    Posts
    81
    Thanks
    6
    Thanked 10 Times in 10 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: how to use QIdentityProxyModel?

    almost four hours of trial and error and the error was a missing type in the doc of QIdentityProxyModel... but, I feel like a fool for not having noticed before.

    let me report the missing typo in the doc to trolltech.


    thanks for the help.

  5. #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 use QIdentityProxyModel?

    I see no error in the documentation of the data() function in QAbstractProxyModel, from which it is inherited by QIdentityProxyModel. There is an error in the snippet in the QIdentityProxyModel detailed description section. Attach a patch to your bug.
    Qt Code:
    1. diff -u a/doc/src/snippets/code/src_gui_itemviews_qidentityproxymodel.cpp b/doc/src/snippets/code/src_gui_itemviews_qidentityproxymodel.cpp
    2. --- a/doc/src/snippets/code/src_gui_itemviews_qidentityproxymodel.cpp 2012-03-15 00:01:52.000000000 +1000
    3. +++ b/doc/src/snippets/code/src_gui_itemviews_qidentityproxymodel.cpp 2012-08-03 16:03:09.000000000 +1000
    4. @@ -48,7 +48,7 @@
    5. m_formatString = formatString;
    6. }
    7.  
    8. - QVariant data(const QModelIndex &index, int role)
    9. + QVariant data(const QModelIndex &index, int role) const
    10. {
    11. if (role != Qt::DisplayRole)
    12. return QIdentityProxyModel::data(index, role);
    To copy to clipboard, switch view to plain text mode 

    BTW: Trolltech have not existed for quite a while.

  6. The following user says thank you to ChrisW67 for this useful post:

    ecanela (3rd August 2012)

  7. #5
    Join Date
    Oct 2009
    Location
    Mexico
    Posts
    81
    Thanks
    6
    Thanked 10 Times in 10 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: how to use QIdentityProxyModel?

    patch submitted. thanks for the diff file.

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.