[SailfishDevel] One ListModel for multiple SilicaGridViews

Tomek discuss at tdress.de
Sun Mar 16 16:56:14 UTC 2014


Andrey, makes sense.
It is an model which is not related to the file system. 
Instead, it contains strings like caption and url and few booleans such as isFavourite and isActive.
I would like to use the mentioned booleans, to filter out elements is a SilicaGridView.

/Tomek

Am 16.03.2014 um 10:03 schrieb Andrey Kozhevnikov <coderusinbox at gmail.com>:

> what kind of model you implementing? files model and abstract data model solutions can be differ
> 
> On 16.03.2014 11:37, Tomek wrote:
>> I am wondering how I could display a single ListModel in multiple SilicaGridViews (filtered)?
>> Simply making an item invisible in a specific view does not work, because it still consumes (cellWidth x  cellHeight) the space.
>> I know, I could also implement my own model in c++. Probably something like this was done my someone already? 
>> 
>> 
>> Currently, I am experimenting with multiple models which I need to keep in sync (implementation is far from ready ;)).
>> [FilteredListModel.qml]
>> import QtQuick 2.0
>> import Sailfish.Silica 1.0
>> 
>> Item {
>>     property ListModel filteredModel: _filteredModel
>>     property ListModel model: _model
>>     property string filterRoleName
>>     property var filterValue
>>     ListModel {
>>         id: _filteredModel
>>     }
>>     ListModel {
>>         id: _model
>>         onRowsInserted: {
>>             for (var i = first; i <= last; i++) {
>>                 var entry = model.get(i);
>>                 if (entry[filterRoleName] === filterValue)
>>                 {
>>                   _filteredModel.append(entry);
>>                 }
>>             }
>>         }
>>         onRowsRemoved: {
>>              for (var i = first; i <= last; i++) {
>>                 _filteredModel.remove(i);
>>              }
>>         }
>>     }
>>     function append(sobject)
>>     {
>>         model.append(sobject);
>>     }
>>     function setProperty(index, key, value )
>>     {
>>         model.setProperty(index, key, value);
>>         var entry = model.get(index);
>>         if (entry[filterRoleName] === filterValue)
>>         {
>>             _filteredModel.set(index, model.get(index))
>>         }
>>         else
>>         {
>>             _filteredModel.remove(index);
>>         }
>>     }
>>     function remove(index)
>>     {
>>         model.remove(index);
>>     }
>>     Component.onCompleted: {
>>         model.append({"name": "Apple","cost": 0.25,active: false});
>>         model.append({"name": "Orange","cost": 0.90,active: true});
>>         model.append({"name": "Bannana","cost": 0.30,active: true});
>>         model.append({"name": "Ananas","cost": 3.10,active: true});
>>     }
>> }
>> 
>> 
>> 
>> _______________________________________________
>> SailfishOS.org Devel mailing list
> 
> _______________________________________________
> SailfishOS.org Devel mailing list

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.sailfishos.org/pipermail/devel/attachments/20140316/ebf54ab6/attachment.html>


More information about the Devel mailing list