Results 1 to 2 of 2

Thread: beginMoveRows working down to up but not up to down... Any insignt would be great.

  1. #1
    Join Date
    Dec 2006
    Posts
    160
    Thanks
    33
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default beginMoveRows working down to up but not up to down... Any insignt would be great.

    Here are two methods from my model. The first one (Moving a row up) is working, while the 2nd to do the opposite and only slightly different doesn't. What could be wrong with my code here?
    Qt Code:
    1. bool REA::ZoneRecognizersModel::moveUp (quint32 row, QModelIndex const &parent) {
    2. TreeItem *pItm = (TreeItem*)parent.internalPointer();
    3. if (!pItm) pItm = _root;
    4. if (row<=0 || row>=pItm->children.size())
    5. return false;
    6. quint32 dstRow = row-1;
    7. beginMoveRows (parent, row, row, parent, dstRow);
    8. pItm->children.swap (row, dstRow);
    9. endMoveRows ();
    10. return true;
    11. }
    12. bool REA::ZoneRecognizersModel::moveDown (quint32 row, QModelIndex const &parent) {
    13. TreeItem *pItm = (TreeItem*)parent.internalPointer();
    14. if (!pItm) pItm = _root;
    15. if (row<0 || row>=pItm->children.size()-1)
    16. return false;
    17. quint32 dstRow = row+1;
    18. beginMoveRows (parent, row, row, parent, dstRow);
    19. pItm->children.swap (dstRow, row);
    20. endMoveRows ();
    21. return true;
    22. }
    To copy to clipboard, switch view to plain text mode 

    The error i get is a debugging assert in QStack: !this->empty. If i ignore it, i end up with an invalid allocation size in the QList::detach holding my internal proxy data tree to the model... The error is happening in the endMoveRow method.

    It is likely that i'm coding for way too long now, and it could be a very small and silly mistake...

    Thanks,
    Pierre.
    Last edited by hickscorp; 3rd August 2011 at 20:30.

  2. #2
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: beginMoveRows working down to up but not up to down... Any insignt would be great

    When moving rows down in the same parent (sourceParent and destinationParent are equal), the rows will be placed before the destinationChild index
    Qt Code:
    1. bool REA::ZoneRecognizersModel::moveUp (quint32 row, QModelIndex const &parent) {
    2. ...
    3. beginMoveRows (parent, row, row, parent, row);
    4. ...
    5. }
    6. bool REA::ZoneRecognizersModel::moveDown (quint32 row, QModelIndex const &parent) {
    7. ...
    8. beginMoveRows (parent, row, row, parent, (row >= pItm->children.size()) ? pItm->children.size() : (row + 2));
    9. ...
    10. }
    To copy to clipboard, switch view to plain text mode 

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

    oberlus (17th August 2011)

Similar Threads

  1. beginMoveRows corrupting persistent model indexes
    By Jmgr in forum Qt Programming
    Replies: 12
    Last Post: 7th July 2011, 11:01
  2. beginMoveRows
    By StefanLatsch in forum Qt Programming
    Replies: 6
    Last Post: 7th December 2010, 09:49
  3. PyQt what a great work!!
    By arkero24 in forum Qt Programming
    Replies: 0
    Last Post: 1st June 2010, 19:28
  4. Great QT book
    By wererabit in forum Newbie
    Replies: 2
    Last Post: 6th April 2010, 23:57
  5. Replies: 0
    Last Post: 20th December 2009, 20:54

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.