forked from papyros/qml-material
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathutils.js
More file actions
99 lines (82 loc) · 2.22 KB
/
Copy pathutils.js
File metadata and controls
99 lines (82 loc) · 2.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/*
* QML Material - An application framework implementing Material Design.
*
* Copyright (C) 2014-2016 Michael Spencer <sonrisesoftware@gmail.com>
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
function findRoot(obj) {
while (obj.parent) {
obj = obj.parent;
}
return obj;
}
function findRootChild(obj, objectName) {
obj = findRoot(obj);
var childs = new Array(0);
childs.push(obj);
while (childs.length > 0) {
if (childs[0].objectName == objectName) {
return childs[0];
}
for (var i in childs[0].data) {
childs.push(childs[0].data[i]);
}
childs.splice(0, 1);
}
return null;
}
function findChild(obj,objectName) {
var childs = new Array(0);
childs.push(obj);
while (childs.length > 0) {
if (childs[0].objectName == objectName) {
return childs[0];
}
for (var i in childs[0].data) {
childs.push(childs[0].data[i]);
}
childs.splice(0, 1);
}
return null;
}
function newObject(path, args, parent) {
if (!args)
args = {};
args.parent = parent;
var component = Qt.createComponent(path);
if (component.status === QtQuick.Component.Error) {
// Error Handling
print("Unable to load object: " + path + "\n" + component.errorString());
return null;
}
return component.createObject(parent, args);
}
function filter(list, filter) {
var filtered = [];
forEach(list, function(item) {
if (filter(item))
filtered.push(item)
})
return filtered;
}
function forEach(list, callback) {
for (var i = 0; i < length(list); i++) {
var item = getItem(list, i)
callback(item)
}
}
function getItem(model, index) {
var item = model.get ? model.get(index) : model[index]
if (model.get && item.modelData)
item = item.modelData
return item
}
function length(model) {
if (model === undefined || model === null)
return 0
else
return model.count ? model.count : model.length
}