01-07-2013 09:30 AM
I load data from a JSON file into a QVariantList which is then appended to an ArrayDataModel which is used to show the data in a ListView. This all works fine. I now want to update some values from a ListViewItem and want to propagate those changes back to the ArrayDataModel -> QVariantList -> JSON file. How would i handle that? Should i update the ListView or the DataModel or even the QVariantList? Loading and showing data in a ListView is very well documented but i can find litle information on the other way arround?
Any help will be greatly appreciated!
Solved! Go to Solution.
01-07-2013 09:36 AM - edited 01-07-2013 09:38 AM
You can access the dataModel from ListView items so it's possible to manipulate it directly.
Outside of ListView subscribe to dataModel's signals such as
void itemAdded (QVariantList indexPath) void itemUpdated (QVariantList indexPath) void itemRemoved (QVariantList indexPath) void itemsChanged (bb::cascades::DataModelChangeType::Type eChangeType=bb::cascades::DataModelChangeType::Ini
t, QSharedPointer< bb::cascades::DataModel::IndexMapper > indexMapper=QSharedPointer< bb::cascades::DataModel::IndexMapper >(0))
You'll probably won't have to subscribe to all of them as you know which changes you're making to the dataModel. For example, if you're only updating the items subscribe to itemUpdated etc.
In signal handler fetch the changes from dataModel and save them to disk.
p.s. Be sure to subscribe to changes only after the dataModel is initially populated.
01-08-2013 01:36 PM
OK thank you for those pointers. I now have a working solution where i save the currentIndex of the selected list item. If it needs to be changed i call the following code:
QVariantMap item = modelItems->value(index).toMap();
That triggers the datamodel signals which i use to save the data to the filesystem.