[Interest] Quick2 - animate sorting of listview, sorted with QSortFilerProxyModel

Mark markg85 at gmail.com
Wed Aug 14 17:47:16 CEST 2013


On Wed, Aug 14, 2013 at 5:30 PM, Nils Jeisecke <njeisecke at saltation.de> wrote:
> On Wed, Aug 14, 2013 at 4:59 PM, Mark <markg85 at gmail.com> wrote:
>> But does resorting the model call those functions internally? Or does it
>> simply notify that "the model changed" which would cause the entire view to
>> be updated...
>
> AFAIK QSortFilterProxyModel does not emit the rowsMoved signal, only
> rowsRemoved/rowsInserted. So this won't be properly animated.
>
> You must implement the sorting directly in your model and then use
> beginMoveRows/endMoveRows. This shouldn't be so difficult for a score
> model.
>
> Here's some code:
>
> ---
>
> class ScoreModel
> {
> // ...
>   QList<ScoreEntry> m_entries;
> // ...
> };
>
> void ScoreModel::move(int from, int to)
> {
>   if (to == from)
>     return;
>
>   // beginMoveRows "to" means => before "to"
>   int modelTo = to;
>   if (to > from)
>     modelTo++;
>
>   // register move for views
>   if (!beginMoveRows(QModelIndex(), from, from, QModelIndex(), modelTo)) {
>     qFatal() << "MOVING FAILED";
>     return;
>   }
>
>   // actually move item in container
>   m_entries.move(from, to);
>
>   // now the qml view should animate a move
>   endMoveRows();
> }
>
> ---
>
> Nils

That "could" work and most likely will for small models. But that
means you need to completely re-implement sorting stuff (the
algorithms itself even) to get everything sorted in an animated
manner.

So, if you're just animation the movement of one item to another place
then your above approach will probably work just fine.
If you want to animate the sorting (which was the initial question of
the topic starter) then this approach is probably not going to work.



More information about the Interest mailing list