-
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.
-
Re: beginMoveRows
Did you actually remove the content in the model?
-
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();
}
}
-
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.
-
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.
-
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) :
- Call moveRows() on the QSqlQueryModel()
- If you are sorting on some key, do the sorting in your sql query
- Make a lower level implementation:
- If the move has to be permanent, you'll need to implement your own sql query handling model
- If the move is only for the display, implement a proxy model that sorts in your desired order.
-
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.