[SailfishDevel] One ListModel for multiple SilicaGridViews

Andrey Kozhevnikov coderusinbox at gmail.com
Sun Mar 16 16:59:20 UTC 2014


well, its not trivial with GridView. You might need to use model to 
filteredmodel sorting manually, or implement  model in C++ with methods 
you need

On 16.03.2014 22:56, Tomek wrote:
> 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 <mailto: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  <http://SailfishOS.org>  Devel mailing list
>>
>> _______________________________________________
>> SailfishOS.org <http://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/f69df7ea/attachment.html>


More information about the Devel mailing list