Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Regular Contributor
Posts: 60
Registered: ‎12-19-2012
My Device: BB10 Alpha B
My Carrier: SFR
Accepted Solution

Notify ListView that data from the model has changed

Hi !

 

I know that this question has been asked several times but I haven't found anything satisfactory yet.

 

I have a ListView, populated with a QListDataModel. 

 

After a while I update one element of the model. So far, the only way I have found for the ListView to reflect this change is to clear the model and then reappend all the items. But the problem with this approach is that the ListView will blink and scroll to top. Is there anything better to just tell the ListView that it should update the visible elements ?

 

Thanks

Developer
Posts: 1,524
Registered: ‎12-18-2012
My Device: Z30, Z10 LE, DevAlpha C, PlayBook

Re: Notify ListView that data from the model has changed

Emit itemUpdatesNeeded() from ListItemProvider. This will update all visible items.

 

I've created a test project and it works:

 

	listView_ = new ListView;
	listView_->setDataModel(&model_);
	listView_->setListItemProvider(listItemProvider_ = new SettingsListItemProvider);
	QTimer::singleShot(5000, this, SLOT(zzz()));
-------
void SettingsPage::zzz()
{
	qDebug() << "zzz";
	listItemProvider_->emit itemUpdatesNeeded();
}

 

Had to mark ListItemProvider as friend class to SettingPage for this test because itemUpdatesNeeded() signal is protected.

 

But anyway it's better to emit this signal from ListItemProvider's subclass.

 

Also changing individual model entries should trigger updateItem for these entries only.

 


Andrey Fidrya, @zmeyc on twitter
Developer
Posts: 526
Registered: ‎05-17-2009
My Device: 9900
My Carrier: ATT

Re: Notify ListView that data from the model has changed

If you have properties on the object you are updating it should reflect it automatically. Are you sure you are updating the same instance that the data model has?
Like all of my posts
Regular Contributor
Posts: 60
Registered: ‎12-19-2012
My Device: BB10 Alpha B
My Carrier: SFR

Re: Notify ListView that data from the model has changed

Unfortunately, I don't use ListItemProvider but LitsItemComponent, so I don't kno if this trick can work for me.

Regular Contributor
Posts: 60
Registered: ‎12-19-2012
My Device: BB10 Alpha B
My Carrier: SFR

Re: Notify ListView that data from the model has changed

In fact I have a QListDataModel that is populated with a QList<QObject*>, so yes I have some properties. At a moment, I want to remove an item from this list. The only way to have it reflected on the ListView is to clear my model and reappend the QList of the items, which triggers a blink and a scroll to top

Developer
Posts: 1,524
Registered: ‎12-18-2012
My Device: Z30, Z10 LE, DevAlpha C, PlayBook

Re: Notify ListView that data from the model has changed

You're mixing two different approaches. I suggest using ListItemProvider+DataModel (more flexible approach) or ListItemComponents (QML only).

Andrey Fidrya, @zmeyc on twitter
Regular Contributor
Posts: 60
Registered: ‎12-19-2012
My Device: BB10 Alpha B
My Carrier: SFR

Re: Notify ListView that data from the model has changed

Yes, I agree. But using ListItemComponent is much more convenient to create the interface, although I do need to handle my model from C++

Regular Contributor
Posts: 60
Registered: ‎12-19-2012
My Device: BB10 Alpha B
My Carrier: SFR

Re: Notify ListView that data from the model has changed

[ Edited ]

I figured out that my properties where missing the NOTIFY method. I added them and now, instead of clearing and then appending my elements to the model, I just update the properties. 

 

It still not works completly as expected. Some elemnts are not updated visually although I have put some qDebug in the READ method associated and I can see in log that the correct information is requested and returned. Some items weems to be correctly updated after a while of scrolling

 

EDIT :

 

I have a property of my model that decides whether an ActivityIndicator is visible or not in a cell. I have put a console.log() in the onVisibleChanged slot of the ActivityIndicator. And it seems that the signal is not always triggered whereas it should. Anyone noticed somthing similar ?

Regular Contributor
Posts: 60
Registered: ‎12-19-2012
My Device: BB10 Alpha B
My Carrier: SFR

Re: Notify ListView that data from the model has changed

Well, I just emit the signal myself in the WRITE method and it works.