Results 1 to 4 of 4

Thread: Opening persistent delegate editors with proxy model

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    May 2014
    Posts
    5
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Opening persistent delegate editors with proxy model

    Hi all.

    I have a QTreeView hooked up with an implementation of QAbstractItemModel, and the view has a custom delegate set up for one of the columns. I've set it up to open these delegate editors persistently in the following way:

    1. Model is populated with data. When it encounters a row that needs a delegate, it notifies the owner and passes on the index in question.
    2. The owner stores a QPersistentModelIndex with the given index for later use.
    3. Once the model is fully populated, it notifies the owner of this. The owner then goes through each stored index and calls openPersistentEditor() on the view for each one.
    4. (If the model data is cleared or re-populated from this point, it will call closePersistentEditor() on each index beforehand and clear them.)

    This worked seemingly perfectly, until I installed an implementation of QSortFilterProxyModel for filtering purposes. I tried to change the calls to openPersistentEditor() and closePersistentEditor() to first map the index from source, since the view now uses the proxy model instead, but nothing seems to happen. I can still get the editors to open by double-clicking in the cells, but I cannot make them persistent anymore. I've stepped through as much as I can of the Qt function calls to see if anything is obviously wrong without much luck.

    Am I missing something here? Or maybe my way of thinking is entirely wrong?

    Any help would be greatly appreciated.

    Regards,

    skauert

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Opening persistent delegate editors with proxy model

    Have you tried mapping the indexes into proxy model indexes before storing them in persistant model indexes?

    Cheers,
    _

  3. #3
    Join Date
    May 2014
    Posts
    5
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: Opening persistent delegate editors with proxy model

    Hi anda, thanks for your response.

    I have indeed tried that. Going down that route causes an assert to fire in QSortFilterProxyModelPrivate::index_to_iterator. The following code sample highlights it.
    Qt Code:
    1. inline QHash<QModelIndex, Mapping *>::const_iterator index_to_iterator(
    2. const QModelIndex &proxy_index) const
    3. {
    4. Q_ASSERT(proxy_index.isValid());
    5. Q_ASSERT(proxy_index.model() == q_func());
    6. const void *p = proxy_index.internalPointer();
    7. Q_ASSERT(p);
    8. QHash<QModelIndex, Mapping *>::const_iterator it =
    9. static_cast<const Mapping*>(p)->map_iter;
    10. Q_ASSERT(it != source_index_mapping.constEnd()); // <<-- Asserts here.
    11. Q_ASSERT(it.value());
    12. return it;
    13. }
    To copy to clipboard, switch view to plain text mode 
    If it is of any help, I've also included the callstack.
    Qt Code:
    1. > QtGuid4.dll!QSortFilterProxyModelPrivate::index_to_iterator(const QModelIndex & proxy_index) Line 174 + 0x8 bytes C++
    2. QtGuid4.dll!QSortFilterProxyModel::parent(const QModelIndex & child) Line 1639 C++
    3. QtCored4.dll!QModelIndex::parent() Line 374 + 0x55 bytes C++
    4. QtGuid4.dll!QTreeView::isIndexHidden(const QModelIndex & index) Line 2854 + 0x26 bytes C++
    5. QtGuid4.dll!QTreeView::visualRect(const QModelIndex & index) Line 1026 + 0x27 bytes C++
    6. QtGuid4.dll!QAbstractItemView::updateEditorGeometries() Line 2597 + 0x24 bytes C++
    7. QtGuid4.dll!QAbstractItemView::updateGeometries() Line 2632 C++
    8. QtGuid4.dll!QTreeView::updateGeometries() Line 2706 C++
    9. QtGuid4.dll!QAbstractItemView::doItemsLayout() Line 1146 C++
    10. QtGuid4.dll!QTreeView::doItemsLayout() Line 2046 C++
    11. QtGuid4.dll!QAbstractItemView::timerEvent(QTimerEvent * event) Line 2424 C++
    12. QtGuid4.dll!QTreeView::timerEvent(QTimerEvent * event) Line 1192 C++
    13. QtCored4.dll!QObject::event(QEvent * e) Line 1139 C++
    14. QtGuid4.dll!QWidget::event(QEvent * event) Line 8802 + 0x10 bytes C++
    15. QtGuid4.dll!QFrame::event(QEvent * e) Line 538 + 0xc bytes C++
    16. QtGuid4.dll!QAbstractScrollArea::event(QEvent * e) Line 977 + 0xc bytes C++
    17. QtGuid4.dll!QAbstractItemView::event(QEvent * event) Line 1562 C++
    18. QtGuid4.dll!QApplicationPrivate::notify_helper(QObject * receiver, QEvent * e) Line 4538 + 0x11 bytes C++
    19. QtGuid4.dll!QApplication::notify(QObject * receiver, QEvent * e) Line 4503 + 0x10 bytes C++
    20. QtCored4.dll!QCoreApplication::notifyInternal(QObject * receiver, QEvent * event) Line 857 + 0x15 bytes C++
    21. QtCored4.dll!QCoreApplication::sendEvent(QObject * receiver, QEvent * event) Line 212 + 0x39 bytes C++
    22. QtCored4.dll!QEventDispatcherWin32::event(QEvent * e) Line 1117 + 0x10 bytes C++
    23. QtGuid4.dll!QApplicationPrivate::notify_helper(QObject * receiver, QEvent * e) Line 4538 + 0x11 bytes C++
    24. QtGuid4.dll!QApplication::notify(QObject * receiver, QEvent * e) Line 3920 + 0x10 bytes C++
    25. QtCored4.dll!QCoreApplication::notifyInternal(QObject * receiver, QEvent * event) Line 857 + 0x15 bytes C++
    26. QtCored4.dll!QCoreApplication::sendEvent(QObject * receiver, QEvent * event) Line 212 + 0x39 bytes C++
    27. QtCored4.dll!QCoreApplicationPrivate::sendPostedEvents(QObject * receiver, int event_type, QThreadData * data) Line 1481 + 0xd bytes C++
    28. QtCored4.dll!qt_internal_proc(HWND__ * hwnd, unsigned int message, unsigned int wp, long lp) Line 477 + 0x10 bytes C++
    29. user32.dll!_InternalCallWinProc@20() + 0x23 bytes
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    May 2014
    Posts
    5
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: Opening persistent delegate editors with proxy model

    Hi all.

    I've now figured out what I was doing wrong, and I'd like to share with anyone who might've done the same mistake.

    It seems that requesting persistent editors from the view between emitting layoutAboutToBeChanged() and layoutChanged() was the cause for this issue. I'm not 100% sure of the details, but I assume there is some sort of index invalidation going on. Moving the openPersistentEditor() call to after emitting layoutChanged() appears to have fixed it.

    (Apologies for necro if this sort of delayed follow-up is frowned upon)

    Regards,

    skauert

Similar Threads

  1. Opening persistent editors without text cursor
    By kossmoboleat in forum Qt Programming
    Replies: 0
    Last Post: 13th February 2012, 19:22
  2. Model/Delegate/Proxy
    By skyline2000 in forum Qt Programming
    Replies: 1
    Last Post: 9th March 2011, 17:13
  3. Replies: 7
    Last Post: 4th November 2010, 00:18
  4. Persistent (changing) model and delegate deletion
    By mclark in forum Qt Programming
    Replies: 0
    Last Post: 23rd September 2010, 16:51
  5. Replies: 0
    Last Post: 28th August 2009, 10:49

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.