[Interest] implementing rows reordering in QSortFilterProxyModel

Александр Иваш elderorb at gmail.com
Mon Oct 12 23:28:26 CEST 2020


>> Just to make sure I understood, do you need a proxy model that allows to
reorder the rows of a given source model via DND?

No, what I need is a proxy model which can reorder its own rows via
DND without modifying the source model. In fact I want this:
ReorderingModel <=> FilteringModel <=> SourceModel

 >> QPersistentModelIndex. But it sounds like it's not _really_ needed, you
need a way to map integers (row numbers from the source model) into
other integers (row numbers after the proxy).

Any sample demonstrating how to do it?

Also, even without a proxy model I see some weird behaviour, like
'setItemData' gets called not for all the roles on drag-n-drop
completion. As the result row entry is moved only 'partially'. I feel
like either I'm missing something or this whole area (rows reordering
via drag-n-drop) is so rarely used that it has more bugs than it
should.

On Mon, Oct 12, 2020 at 11:09 PM Александр Иваш <elderorb at gmail.com> wrote:
>
> >> Just to make sure I understood, do you need a proxy model that allows to
> reorder the rows of a given source model via DND?
>
> No, what I need is a proxy model which can reorder its own rows via
> DND without modifying the source model. In fact I want this:
> ReorderingModel <=> FilteringModel <=> SourceModel
>
>  >> QPersistentModelIndex. But it sounds like it's not _really_ needed, you
> need a way to map integers (row numbers from the source model) into
> other integers (row numbers after the proxy).
>
> Any sample demonstrating how to do it?
>
>
> On Mon, Oct 12, 2020 at 9:46 PM Giuseppe D'Angelo via Interest
> <interest at qt-project.org> wrote:
> >
> > Il 12/10/20 15:31, Александр Иваш ha scritto:
> > > Is there any example for re-ordering of QTableView entries implemented
> > > in QSortFilterProxyModel (ideally drag-n-drop-driven)? If not, what is
> > > the best way to implement it? I'm thinking about implementing
> > > reordering as 'custom sorting' - but it will require me to collect all
> > > the QModelIndex-es in the separate list (which can be then reordered
> > > and used for custom sorting).
> >
> > Just to make sure I understood, do you need a proxy model that allows to
> > reorder the rows of a given source model via DND?
> >
> > > The issue with such approach is that
> > > QModelIndex-es are short-living and I need to track its lifetime
> > > somehow.... Any better ideas?
> >
> > QPersistentModelIndex. But it sounds like it's not _really_ needed, you
> > need a way to map integers (row numbers from the source model) into
> > other integers (row numbers after the proxy).
> >
> > HTH,
> >
> > --
> > Giuseppe D'Angelo | giuseppe.dangelo at kdab.com | Senior Software Engineer
> > KDAB (France) S.A.S., a KDAB Group company
> > Tel. France +33 (0)4 90 84 08 53, http://www.kdab.com
> > KDAB - The Qt, C++ and OpenGL Experts
> >
> > _______________________________________________
> > Interest mailing list
> > Interest at qt-project.org
> > https://lists.qt-project.org/listinfo/interest


More information about the Interest mailing list