[Interest] [External] Proxied view not updating live when source model does
Elvis Stansvik
elvstone at gmail.com
Tue Sep 21 18:01:45 CEST 2021
Den tis 21 sep. 2021 16:00Murphy, Sean <Sean.Murphy at centauricorp.com> skrev:
> > I'm having an issue where my proxy model and its associated view aren't
> > updating live when changes are made in the source model.
> >
> > My proxy model simply is attempting to invert the rows of the source
> model. So
> > it inherits from a QSortFilterProxyModel and implements mapFromSource()
> and
> > mapToSource() as follows:
> >
> > QModelIndex invertRowsModel::mapFromSource(const QModelIndex
> > &sourceIndex) const
> > {
> > if(sourceIndex.isValid() && rowCount() > 0)
> > {
> > return this->index(rowCount() - sourceIndex.row() - 1,
> > sourceIndex.column());
> > }
> >
> > return QModelIndex();
> > }
> >
>
> Small update here, but I'm not sure what it actually means... I added a
> debug
> statement at the top of my mapFromSource() function, so now that function
> reads like so:
>
> QModelIndex invertRowsModel::mapFromSource(const QModelIndex
> &sourceIndex) const
> {
> if(sourceIndex.isValid() && rowCount() > 0)
> {
> qDebug() << __FUNCTION__ << "valid index" << sourceIndex;
> return this->index(rowCount() - sourceIndex.row() - 1,
> sourceIndex.column());
> } else {
> qDebug() << __FUNCTION__ << "invalid index" << sourceIndex;
> }
>
> return QModelIndex();
> }
>
> With this in place, while modifying the data in the source view, I NEVER
> see the
> mapFromSource() "valid index" debug message from the proxy model. Right
> after
> setData() is called in the source model, I see a couple of these messages
> come out
> and that's it:
>
> invertRowsModel::mapFromSource invalid index
> QModelIndex(-1,-1,0x0,QObject(0x0))
>
> I'm not sure exactly what that means or how to address it, but it is a new
> data point...
>
I added the same kind of printout and concluded the same yesterday, when I
thought I'd help you debug as a challenge.. (then ran out of time).
Curious to see how this progresses..
Code in QSFPM for handling source model dataChanged is a bit hard to
follow..
Elvis
> Sean
>
> _______________________________________________
> Interest mailing list
> Interest at qt-project.org
> https://lists.qt-project.org/listinfo/interest
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20210921/8e41f218/attachment.html>
More information about the Interest
mailing list