-
Notifications
You must be signed in to change notification settings - Fork 0
/
ComponentsSearch.qml
151 lines (131 loc) · 4.54 KB
/
ComponentsSearch.qml
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
import QtQuick 2.7
import QtQuick.Controls 2.0
import QtQuick.Layouts 1.0
Item {
property bool sorting: false
property string column
property string name
property string search
property string unite
property real rdi
objectName: "componentsSearch"
function interpret(number, factor, unit) {
if (number == 0) {
return "";
}
factor = typeof factor !== 'undefined' ? factor : 1;
if (isNaN(number)) {
if (number[0] == '<') {
number = number[0] + " " + (parseFloat(number.slice(1, number.length)) * factor).toLocaleString(Qt.locale()) + " " + unit;
}
return number;
}
else {
return (parseFloat(number) * factor).toLocaleString(Qt.locale()) + " " + unit;
}
}
function sizeBg(number, factor, rdi) {
if (rdi == 0) {
return 0;
}
factor = typeof factor !== 'undefined' ? factor : 1;
if (isNaN(number)) {
if (number[0] == '<') {
number = (parseFloat(number.slice(1, number.length)) * factor) / rdi;
return number;
}
return 0;
}
else {
return (parseFloat(number) * factor) / rdi;
}
}
function refresh() {
componentSearchModel.setParameter(":column", column);
componentSearchModel.setParameter(":searchString", "'%" + search + "%'");
componentSearchModel.setParameter(":sorting", sorting ? "ASC" : "DESC");
componentSearchModel.refresh();
}
Component {
id: resultsDelegate
Item {
anchors {
right: parent.right
left: parent.left
}
height: 60
Rectangle {
anchors {
top: parent.top
bottom: parent.bottom
left: parent.left
}
color: Qt.hsla(index >= 20 ? (1/20) * (18 - (index % 20)) : (1 / 20) * (index % 20), 0.4, 0.82)
width: sizeBg(value, 1, rdi) * parent.width
}
GridLayout {
anchors.fill: parent
Text {
text: origfdnm
Layout.alignment: Qt.AlignBottom | Qt.AlignLeft
Layout.leftMargin: 16
opacity: 1
elide: Text.ElideRight
Layout.maximumWidth: parent.width * 0.7
font.pixelSize: 13
Layout.row: 0
Layout.column: 0
}
Text {
text: qsTr(interpret(value, 1, unite))
Layout.alignment: Qt.AlignBottom | Qt.AlignRight
Layout.rightMargin: 16
opacity: 1
font.pixelSize: 13
Layout.row: 0
Layout.column: 1
}
Text {
text: origgpfr
Layout.alignment: Qt.AlignTop | Qt.AlignLeft
Layout.leftMargin: 16
opacity: 0.535
font.pixelSize: 13
Layout.row: 1
Layout.column: 0
}
Text {
text: sizeBg(value, 1, rdi) ? (Math.round((sizeBg(value, 1, rdi) * 100) * 10) / 10) + " %" : ""
Layout.alignment: Qt.AlignTop | Qt.AlignRight
Layout.rightMargin: 16
opacity: 0.535
font.pixelSize: 13
Layout.row: 1
Layout.column: 1
}
}
MouseArea {
anchors.fill: parent
onClicked: {
createProductPage(false, origfdcd, null);
// var productComponent = Qt.createComponent("ProductTable.qml");
// var productTable = productComponent.createObject(null, JSON.parse(productData.getData(origfdcd)));
// // Hide search field and search results before loading the new page
// searchField.focus = false;
// stack.push(productTable);
}
}
}
}
ListView {
id: resultsView
anchors.fill: parent
model: componentSearchModel
delegate: resultsDelegate
clip: true
onMovementStarted: {
searchField.focus = false;
}
ScrollBar.vertical: ScrollBar {}
}
}