Results 1 to 4 of 4

Thread: QStandardItemModel + Undo

  1. #1
    Join Date
    Dec 2014
    Posts
    49
    Thanks
    6
    Thanked 3 Times in 3 Posts
    Qt products
    Qt5 PyQt3 PyQt4
    Platforms
    Windows

    Default QStandardItemModel + Undo

    Currently i am displaying a tree using a QStandardItemModel. I wanted to implement Undo/Redo for editing the branch names. I connect to itemChanged(QStandardItem*) and i have created my undo and redo methods. However, when i call undo, i setText on the item, at which point a new itemChanged(QStandardItem*) fires, creating a new QUndoCommand and then things get lost.

    I implemented a "hack" where i set a flag in Qt::UserRole+1 when the undoCommand is issued, and i check before issuing the command. This works fine.

    My question is, is there a more elegant route to using Undo with the QStandardItemModel, without having to subclass the QStandardItemModel.

  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: QStandardItemModel + Undo

    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. The following user says thank you to wysota for this useful post:

    NIteLordz (29th January 2015)

  4. #3
    Join Date
    Dec 2014
    Posts
    49
    Thanks
    6
    Thanked 3 Times in 3 Posts
    Qt products
    Qt5 PyQt3 PyQt4
    Platforms
    Windows

    Default Re: QStandardItemModel + Undo

    Thank you, i wish i would've found that article before i had started down this path.

  5. #4
    Join Date
    Jun 2014
    Posts
    98
    Thanks
    43
    Thanked 4 Times in 4 Posts
    Platforms
    Windows

    Default Re: QStandardItemModel + Undo

    Wow just about to embark on this, so glad you asked this recently and our resident Ninja has an article!!!

Similar Threads

  1. Replies: 0
    Last Post: 21st January 2014, 06:05
  2. Undo the this->setupId(this)
    By valerianst in forum Qt Programming
    Replies: 11
    Last Post: 2nd July 2013, 14:30
  3. qt undo/redo
    By giugio in forum Qt Programming
    Replies: 1
    Last Post: 12th November 2012, 16:31
  4. Syncing QTextDocument's undo stack with custom undo stack
    By Dini Selimović in forum Newbie
    Replies: 0
    Last Post: 24th June 2012, 13:11
  5. buggy undo example
    By Gopala Krishna in forum Qt Programming
    Replies: 2
    Last Post: 21st August 2007, 19:33

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.