Re: [Interest] [External] Proxied view not updating live when source model does

2021-09-22 Thread Friedemann Kleint

Hi,

have you runĀ  QAbstractItemModelTester 
https://doc.qt.io/qt-6/qabstractitemmodeltester.html on the source model 
and the proxy model?


It usually quickly reveals issues in the overridden methods.

Regards, Friedemann
--

Friedemann Kleint
The Qt Company GmbH

___
Interest mailing list
Interest@qt-project.org
https://lists.qt-project.org/listinfo/interest


Re: [Interest] [External] Proxied view not updating live when source model does

2021-09-21 Thread Elvis Stansvik
Den tis 21 sep. 2021 16:00Murphy, Sean  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
> > ) 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
> ) 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@qt-project.org
> https://lists.qt-project.org/listinfo/interest
>
___
Interest mailing list
Interest@qt-project.org
https://lists.qt-project.org/listinfo/interest


Re: [Interest] [External] Proxied view not updating live when source model does

2021-09-21 Thread Murphy, Sean
> 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
> ) 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 ) 
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...

Sean

___
Interest mailing list
Interest@qt-project.org
https://lists.qt-project.org/listinfo/interest