Results 1 to 7 of 7

Thread: beginMoveRows

  1. #1
    Join Date
    Dec 2010
    Location
    Luxembourg
    Posts
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default beginMoveRows

    I have a QSqlQueryModel based Tableview and I want the user sort the resultset in the the tableview manually. So I try to use

    beginMoveRows(index, r, r, index, r-1);
    endMoveRows();

    but it work only partially. The selection in the tableview is moving to the new position, where the row shall be moved. but the content is not moving.

  2. #2
    Join Date
    Jul 2009
    Location
    Enschede, Netherlands
    Posts
    462
    Thanked 69 Times in 67 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: beginMoveRows

    Did you actually remove the content in the model?
    Horse sense is the thing that keeps horses from betting on people. --W.C. Fields

    Ask Smart Questions

  3. #3
    Join Date
    Dec 2010
    Location
    Luxembourg
    Posts
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: beginMoveRows

    No I didn't
    CODE WHILE INIT THE DIALOG:

    model = new AuslagerQueryModel(this);
    ui.Liste->setModel(model);
    ui.Liste->setSelectionBehavior(QAbstractItemView::SelectRow s);

    The Testfunction to move a row 1 up

    void Auslagerung::OnF6(void)
    {
    if(model->rowCount() <= 0)
    return;
    QModelIndex idx = ui.Liste->currentIndex();
    model->moveRow(QModelIndex(), idx.row(), -1);

    }


    void AuslagerQueryModel::moveRow(const QModelIndex &index, const int &r, const int &p)
    {
    if(r > 0 && p == -1)
    {
    beginMoveRows(index, r, r, index, r-1);
    endMoveRows();
    }
    }

  4. #4
    Join Date
    Jul 2009
    Location
    Enschede, Netherlands
    Posts
    462
    Thanked 69 Times in 67 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: beginMoveRows

    You only tell the outside world you are moving your data around, while your current implementation doesn't actually do that. You need to actually move your data to the new position in your internal data structure as well.

    Also, please use the code tags when posting code.
    Horse sense is the thing that keeps horses from betting on people. --W.C. Fields

    Ask Smart Questions

  5. #5
    Join Date
    Dec 2010
    Location
    Luxembourg
    Posts
    5
    Qt products
    Qt4
    Platforms
    Windows

    Question Re: beginMoveRows

    looks like.. but I cant see where I have to move my data. I thought, that beginMove and endmove is doing it and forwarding the changes to the subclasses. may you can give me a hint.

  6. #6
    Join Date
    Jul 2009
    Location
    Enschede, Netherlands
    Posts
    462
    Thanked 69 Times in 67 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: beginMoveRows

    beginMoveRows() and endMoveRows() is just a signaling to the outside world that the model is going to move around data. I am not familiar enough with QSqlQueryModel to give you pointers on how to handle the data. There's a few things you should try (in order) :
    1. Call moveRows() on the QSqlQueryModel()
    2. If you are sorting on some key, do the sorting in your sql query
    3. Make a lower level implementation:
      1. If the move has to be permanent, you'll need to implement your own sql query handling model
      2. If the move is only for the display, implement a proxy model that sorts in your desired order.
    Last edited by franz; 6th December 2010 at 15:26. Reason: reformatted to look better
    Horse sense is the thing that keeps horses from betting on people. --W.C. Fields

    Ask Smart Questions

  7. #7
    Join Date
    Dec 2010
    Location
    Luxembourg
    Posts
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: beginMoveRows

    Thanks,
    I extended my sql query model class to keep the data herein. now it works fine...no need to implement another proxy class.

Similar Threads

  1. beginMoveRows corrupting persistent model indexes
    By Jmgr in forum Qt Programming
    Replies: 12
    Last Post: 7th July 2011, 11:01
  2. 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.