11-09-2012 08:47 AM
I'm loading all my images aynchronously in an single cache for my listview. My problem is that when the imageview first loads, it loads the default image, but once it completes populating the cache I can't send a signal to the update item for it to refresh its image. it doesn't trigger an item refresh until the item is recycled - and only then does it grab the image.
How do I send a signal to a specific item in a listview to trigger an image change or how do I access a specific item's image from the listview to change it?
11-09-2012 10:32 AM
11-09-2012 10:43 PM
I implemented my cache like this in my datamodel emitting the update
void NewGalleryModel::cacheImage(int num){
bb::ImageData imageData = mimageScaling->resultAt(num);
Image im = Image(imageData);
mImageGalleryCache.insert(num,im);
QVariantMap itemMap = mImageGalleryData.at(num).toMap();
QString Url=itemMap.value("thumbURL").toString();
mImageGalleryHash[Url]=num;
qDebug() << "Num"<< num;
QVariantList indexPath;
indexPath << QVariant::fromValue(num);
qDebug()<< "CacheImage" <<indexPath;
emit itemUpdated(indexPath);
}
and here is where I update the image in the Listview
ImageView {
id: imageviewID
image:rootcontainer.ListItem.view.dataModel.getIma ge(ListItemData.thumbURL)
}
I assumed as you indicated that updateItem would refresh the visual item. I have confirmed that the datamodel receives the onUpdateItem but no update occurs to the visual items in the list. I have also confirmed that the indexPath is correct:
Debug: CacheImage (QVariant(int, 0) )
The list does eventually update after it recycles. I just can't get the listitem to update. onUpdateItem doesn't seem to update the listview by default. Am I doing something wrong?
02-01-2013 09:07 PM - edited 02-01-2013 09:12 PM
I solved this problem by adding an extra item type, and overriding the itemType() method in QML. I've implemented my own DataModel. I initially populate my list with a bunch of empty dummy items, once the data comes back from the network (or attached QNetworkDiskCache), I emit the itemsChanged() signal from my model, which causes the itemType() QML function to be called again, at which point I switch the ListItem to use the final ThumbItem components. This ThumbItem contains a WebImageView which loads the image (see
https://github.com/RileyGB/BlackBerry10-Samples/tr
ListView {
id: mainListView
dataModel: mainListDataModel
listItemComponents: [
ListItemComponent {
type: "item"
ThumbItem {
}
},
ListItemComponent {
type: "loading"
ThumbItemLoading {
}
}
]
// itemsChanged() signal in DataModel does cause this to be called again.
function itemType(data, indexPath) {
if (data.ContentId == "") // If dummy item, use loading ListItemComponent.
return "loading";
else
return "item";
}
}