Results 1 to 9 of 9

Thread: QAbstractItemModel reset Persistent Index

  1. #1
    Join Date
    Apr 2010
    Posts
    6
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default QAbstractItemModel reset Persistent Index

    Hi,

    How do I reset a persistent Index List?

    Let's say I signal "layoutAboutToBeChanged()" then I update my data and check if the current persistent index is still there. If it's not there, I would like to clear the persistent index. Is there a way to do this?

    Thank you

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

    Default Re: QAbstractItemModel reset Persistent Index

    You can probably assign an invalid (null) model index to it. Although layoutAboutToBeChanged() shouldn't invalidate any indexes as no data gets added or removed, only its position may change.
    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.


  3. #3
    Join Date
    Apr 2010
    Posts
    6
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QAbstractItemModel reset Persistent Index

    I'm almost sure that I'm using the layoutToBeChanged() in a wrong way. To clarify a bit what I want to do is: I have a table view that shows files on a server, which the client can assign to a certain item or folder. Once the file gets assigned, it gets removed from the table view (hence, the persistent index would be set back to a non selection).

    Changing the persistent index to an empty model index list crashes the Application.

    Thank you.

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

    Default Re: QAbstractItemModel reset Persistent Index

    Why are you using persistent indexes in the first place? In 99% of the cases you shouldn't need them at all.
    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.


  5. #5
    Join Date
    Apr 2010
    Posts
    6
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QAbstractItemModel reset Persistent Index

    But how do I keep a view from changing it's selection after updating it's data? I'm aware that the selection on a view doesn't move from it's row or column, but sometimes after updating data the order on the view gets resorted.

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

    Default Re: QAbstractItemModel reset Persistent Index

    Quote Originally Posted by larcho View Post
    But how do I keep a view from changing it's selection after updating it's data?
    The view will take care of that if you emit proper signals from the model (i.e. dataChanged(), rowsInserted(), rowsRemoved(), etc.). It takes a bit of effort to do it but you just have to do it.
    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.


  7. #7
    Join Date
    Apr 2010
    Posts
    6
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QAbstractItemModel reset Persistent Index

    I'll give a look into that. Thank you.

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

    Default Re: QAbstractItemModel reset Persistent Index

    One more thing... what you might try is to connect a slot to the layoutAboutToBeChanged() signal and use QAbstractItemModel::changePersistentIndex() to update persistent indexes manually if you are able to determine new positions of each of the persistent indexes kept by the model.
    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.


  9. #9
    Join Date
    Apr 2010
    Posts
    6
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QAbstractItemModel reset Persistent Index

    I did your first approach and it worked fine. Working with dataChanged(), insertRow() and removeRow() did the trick. As you said, it´s a bit more work, but the end result is great.

    Thank you.

Similar Threads

  1. Replies: 1
    Last Post: 9th February 2010, 12:11
  2. Replies: 0
    Last Post: 10th September 2009, 09:43
  3. Replies: 3
    Last Post: 31st March 2008, 21:23
  4. Bug in Qt4.3.3 QXmlSimpleReader::reset() ?
    By Shawn in forum Qt Programming
    Replies: 9
    Last Post: 3rd March 2008, 09:14
  5. reset QwtPlot
    By sarefo in forum Qwt
    Replies: 1
    Last Post: 24th January 2008, 08:00

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.