-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathLineDiagram.qml
318 lines (265 loc) · 9.33 KB
/
LineDiagram.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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
import QtQuick 2.5
import QtGraphicalEffects 1.0
import Sailfish.Silica 1.0
import test_module.test_cppmodule 0.1
/*** Пример использования диаграммы
LineDiagram{
id: laborCostsDiag
spacing: 10 // расстояние между элементами
itemSpacing: 5 // расстояние между столбцами элемента
textFontSize: 17 // размер текста подписи под элементом
valueFontSize: 16 // размер текста значения над столбцами графика
legendFontSize: 17 // размер текста легенды
chartHeight: 200 // высота графика с столбцами, подписью и легендой (пересчитывается, зависит от параметров ниже)
textHeight: 100 // высота подписи под графиком
legendHeight: 70 // высота легенды
itemWidth: 85 // ширина столбца
legendTextHeight:50 // высота текста элемента легенды
legendTextWidth:200 // ширина текста элемента легенды
anchors{
left: parent.left
leftMargin: 10
right: parent.right
rightMargin: 10
}
legends: [ //Пример добавления легенд на график (статическое добавление)
LegendDiagram{
color: "black"
text: "Плановые трудозатраты"
},
LegendDiagram{
color: "red"
text: "Фактические трудозатраты"
}
]
Component.onCompleted: {
if(woCommonInfo.countAll > 0){ // Динамическое добавление значений
var list = woCommonInfo.workingHoursOfTypes;
for(var type in list){
var listValue = [Number(list[type]["sum_plan"]), Number(list[type]["sum_labor"])];
laborCostsDiag.addValue(list[type]["text"],
listValue);
}
laborCostsDiag.update(); // после добавления обязательно нужно обновить элемент
}
}
*/
BackgroundItem {
id: linerDiagram
width: parent.width
height: chartHeight + textHeight + legendHeight
clip: false
property bool debugBorderVisible: false //Используется для отображения границ элементов для тестирования
property alias chartHeight: valuesListView.height
property alias textHeight: valueTextListView.height
property alias legendHeight: rectLegend.height
onChartHeightChanged: linerDiagram.height=chartHeight + textHeight + legendHeight
onTextHeightChanged: linerDiagram.height=chartHeight + textHeight + legendHeight
onLegendHeightChanged: linerDiagram.height=chartHeight + textHeight + legendHeight
property real spacing: 20
///Размер 1 элемента данных
property real itemWidth: 20
property real itemSpacing: 10
property int nestedValuesCount: 1
property int textFontSize: 11
property int valueFontSize: 11
property int legendFontSize: 11
property int borderSize: 3
property alias legendTextHeight: legendView.cellHeight
property alias legendTextWidth: legendView.cellWidth
function addValue(text, value){
diagramModel.addValue(text,value);
diagramModel.diagramValuesChanged();
}
function clearValue(){
diagramModel.clearValue();
}
function update(){
diagramModel.updateMaxValue();
}
Rectangle{
color: "white"
anchors.fill: parent
}
function removeInd(index){
diagram.remove(index);
}
property alias legends: diagramModel.legends
property alias values: diagramModel.diagramValues
LineDiagramModel{
id: diagramModel
}
Component.onCompleted: {
diagramModel.updateMaxValue();
}
SilicaListView{
id: valuesListView
property real maxVal: 100.0
height: parent.height / 3 * 2
anchors{
left: parent.left
right: parent.right
top: parent.top
leftMargin: 10
rightMargin: 10
}
clip: true
spacing: linerDiagram.spacing
HorizontalScrollDecorator{}
orientation: ListView.Horizontal
flickableDirection: Flickable.HorizontalFlick
model: diagramModel.diagramValues
onContentXChanged: {
valueTextListView.contentX = contentX;
imageRightArrow.visible = contentX+linerDiagram.width < contentWidth;
imageLeftArrow.visible = contentX > itemWidth + 30;
}
delegate: LineDiagramItem{
id: lineItem
debugBorder: debugBorderVisible
legends: diagramModel.legends
fontSize: valueFontSize
valueDiagram: modelData
itemSpacing: linerDiagram.itemSpacing
widthValue: linerDiagram.itemWidth
height: valuesListView.height
maxValueDiagram: diagramModel.diagramMaxValue
}
}
Rectangle{
height: 2
border.width: 2
anchors.leftMargin: 0
anchors.rightMargin: 0
anchors{
top:valuesListView.bottom
left: parent.left
right: parent.right
}
border.color: "black"
}
SilicaListView {
id: valueTextListView
enabled: false
HorizontalScrollDecorator{}
height: parent.height / 3 * 0.5
anchors{
top:valuesListView.bottom
topMargin: 2
left: valuesListView.left
right: valuesListView.right
}
clip: true
spacing: linerDiagram.spacing
orientation: ListView.Horizontal
model: diagramModel.diagramValues
delegate: Item {
id: valueTextItem
width: modelData.count * (itemWidth + itemSpacing)
height: parent.height
Rectangle{
visible: debugBorderVisible
border.width: 1
anchors.fill: parent
border.color: "green"
}
Text {
id: valueText
width: parent.width
text: modelData.text
font.bold: true
font.pointSize: textFontSize
wrapMode: Text.WordWrap
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
onHeightChanged: {
if(height > textHeight){
textHeight = height;
}
}
}
}
}
Image {
id: imageRightArrow
visible: valuesListView.contentX+linerDiagram.width < valuesListView.contentWidth
source: "image://theme/icon-m-arrow-right-green?red"
width: 40
height: 40
anchors.verticalCenter: valuesListView.verticalCenter
anchors.right: parent.right
anchors.rightMargin: -15
fillMode: Image.PreserveAspectFit
}
Image {
id: imageLeftArrow
visible: valuesListView.contentX > itemWidth + 30
source: "image://theme/icon-m-arrow-left-green?red"
width: 40
height: 40
anchors.verticalCenter: valuesListView.verticalCenter
anchors.left: parent.left
anchors.leftMargin: -15
fillMode: Image.PreserveAspectFit
}
Rectangle{
id: rectLegend
border{
width: debugBorderVisible ? 1 : 0
color: "red"
}
anchors{
topMargin: 5
top:valueTextListView.bottom
left: parent.left
leftMargin: 20
right: parent.right
rightMargin: 20
}
SilicaGridView{
id: legendView
anchors.fill: parent
model: diagramModel.legends;
cellHeight: 30
cellWidth: 120
clip: true
delegate: BackgroundItem {
Rectangle{
anchors.fill: parent
border{
width: debugBorderVisible ? 1 : 0
color: "red"
}
}
height: legendText.height
width: legendColorRect.width + legendText.width
Rectangle{
id: legendColorRect
anchors{
verticalCenter: parent.verticalCenter
left: parent.left
}
height: 20
width: 20
color: modelData.color
}
Text{
id: legendText
anchors{
left: legendColorRect.right
leftMargin: 10
}
text: modelData.text
font.pointSize: legendFontSize
width: legendView.cellWidth - legendColorRect.width
wrapMode: Text.WordWrap
}
}
}
}
}
/*##^##
Designer {
D{i:0;formeditorZoom:1.33;height:300;width:300}
}
##^##*/