/ tests / tst_filtercontainerattached.qml
tst_filtercontainerattached.qml
 1  import QtQuick 2.0
 2  import SortFilterProxyModel 0.2
 3  import QtQml.Models 2.2
 4  import QtQml 2.2
 5  import QtTest 1.1
 6  
 7  Item {
 8  
 9      ListModel {
10          id: dataModel
11          ListElement { a: 0; b: 0; c: 0 }
12          ListElement { a: 0; b: 0; c: 1 }
13          ListElement { a: 0; b: 1; c: 0 }
14          ListElement { a: 0; b: 1; c: 1 }
15          ListElement { a: 1; b: 0; c: 0 }
16          ListElement { a: 1; b: 0; c: 1 }
17          ListElement { a: 1; b: 1; c: 0 }
18          ListElement { a: 1; b: 1; c: 1 }
19      }
20  
21      SortFilterProxyModel {
22          id: testModel
23          sourceModel: dataModel
24      }
25  
26      Instantiator {
27          id: filterInstantiator
28          model: ["a", "b", "c"]
29          delegate: ValueFilter {
30              FilterContainer.container: testModel
31              roleName: modelData
32              value: 1
33          }
34      }
35  
36      TestCase {
37          name: "FilterContainerAttached"
38  
39          function modelValues() {
40              var modelValues = [];
41  
42              for (var i = 0; i < testModel.count; i++)
43                  modelValues.push(testModel.get(i));
44  
45              return modelValues;
46          }
47  
48          function test_filterContainers() {
49              compare(filterInstantiator.count, 3);
50              compare(modelValues(), [ { a: 1, b: 1, c: 1 }]);
51              filterInstantiator.model = ["a", "b"];
52              wait(0);
53              compare(filterInstantiator.count, 2)
54              compare(modelValues(), [ { a: 1, b: 1, c: 0 }, { a: 1, b: 1, c: 1 }]);
55          }
56      }
57  }