QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
HorizontalFactValueGrid.qml
Go to the documentation of this file.
1import QtQuick
2import QtQuick.Layouts
3import QtQuick.Controls
4import QtQml
5
6import QGroundControl.Controls
7import QGroundControl.FlightMap
8import QGroundControl
9
10HorizontalFactValueGridTemplate {
11 id: _root
12 Layout.preferredWidth: topLayout.width
13 Layout.preferredHeight: topLayout.height
14
15 property bool settingsUnlocked: false
16
17 property real _margins: ScreenTools.defaultFontPixelWidth / 2
18 property int _rowMax: 2
19 property real _rowButtonWidth: ScreenTools.minTouchPixels
20 property real _rowButtonHeight: ScreenTools.minTouchPixels / 2
21 property real _editButtonSpacing: 2
22
23 QGCPalette { id: qgcPal; colorGroupEnabled: enabled }
24
25 ColumnLayout {
26 id: topLayout
27 spacing: ScreenTools.defaultFontPixelWidth
28
29 RowLayout {
30 spacing: parent.spacing
31 RowLayout {
32 id: labelValueColumnLayout
33 spacing: ScreenTools.defaultFontPixelWidth * 1.25
34
35 Repeater {
36 model: _root.columns
37
38 GridLayout {
39 rows: object.count
40 columns: 2
41 rowSpacing: 0
42 columnSpacing: ScreenTools.defaultFontPixelWidth / 4
43 flow: GridLayout.TopToBottom
44
45 Repeater {
46 id: labelRepeater
47 model: object
48
49 InstrumentValueLabel {
50 Layout.fillHeight: true
51 Layout.alignment: Qt.AlignRight
52 instrumentValueData: object
53 }
54 }
55
56 Repeater {
57 id: valueRepeater
58 model: object
59
60 property real _index: index
61 property real maxWidth: 0
62 property var lastCheck: new Date().getTime()
63
64 function recalcWidth() {
65 var newMaxWidth = 0
66 for (var i=0; i<valueRepeater.count; i++) {
67 newMaxWidth = Math.max(newMaxWidth, valueRepeater.itemAt(i).contentWidth)
68 }
69 maxWidth = Math.min(maxWidth, newMaxWidth)
70 }
71
72 InstrumentValueValue {
73 Layout.fillHeight: true
74 Layout.alignment: Qt.AlignLeft
75 Layout.preferredWidth: valueRepeater.maxWidth
76 instrumentValueData: object
77
78 property real lastContentWidth
79
80 Component.onCompleted: {
81 valueRepeater.maxWidth = Math.max(valueRepeater.maxWidth, contentWidth)
82 lastContentWidth = contentWidth
83 }
84
85 onContentWidthChanged: {
86 valueRepeater.maxWidth = Math.max(valueRepeater.maxWidth, contentWidth)
87 lastContentWidth = contentWidth
88 var currentTime = new Date().getTime()
89 if (currentTime - valueRepeater.lastCheck > 30 * 1000) {
90 valueRepeater.lastCheck = currentTime
91 valueRepeater.recalcWidth()
92 }
93 }
94 }
95 }
96 }
97 }
98 }
99
100 ColumnLayout {
101 spacing: 1
102 visible: settingsUnlocked
103
104 QGCButton {
105 Layout.preferredWidth: ScreenTools.minTouchPixels
106 Layout.fillHeight: true
107 topPadding: 0
108 bottomPadding: 0
109 leftPadding: 0
110 rightPadding: 0
111 text: qsTr("+")
112 enabled: (_root.width + (2 * (_rowButtonWidth + _margins))) < screen.width
113 onClicked: appendColumn()
114 }
115
116 QGCButton {
117 Layout.preferredWidth: ScreenTools.minTouchPixels
118 Layout.fillHeight: true
119 topPadding: 0
120 bottomPadding: 0
121 leftPadding: 0
122 rightPadding: 0
123 text: qsTr("-")
124 enabled: _root.columns.count > 1
125 onClicked: deleteLastColumn()
126 }
127 }
128 }
129
130 RowLayout {
131 Layout.fillWidth: true
132 spacing: 1
133 visible: settingsUnlocked
134
135 QGCButton {
136 Layout.fillWidth: true
137 Layout.preferredHeight: ScreenTools.minTouchPixels
138 topPadding: 0
139 bottomPadding: 0
140 leftPadding: 0
141 rightPadding: 0
142 text: qsTr("+")
143 enabled: (_root.height + (2 * (_rowButtonHeight + _margins))) < (screen.height - ScreenTools.toolbarHeight)
144 onClicked: appendRow()
145 }
146
147 QGCButton {
148 Layout.fillWidth: true
149 Layout.preferredHeight: parent.height
150 topPadding: 0
151 bottomPadding: 0
152 leftPadding: 0
153 rightPadding: 0
154 text: qsTr("-")
155 enabled: _root.rowCount > 1
156 onClicked: deleteLastRow()
157 }
158 }
159 }
160
161 QGCMouseArea {
162 x: labelValueColumnLayout.x
163 y: labelValueColumnLayout.y
164 width: labelValueColumnLayout.width
165 height: labelValueColumnLayout.height
166 visible: settingsUnlocked
167 cursorShape:Qt.PointingHandCursor
168
169 property var mappedLabelValueColumnLayoutPosition: _root.mapFromItem(labelValueColumnLayout, labelValueColumnLayout.x, labelValueColumnLayout.y)
170
171 onClicked: (mouse) => {
172 var columnGridLayoutItem = labelValueColumnLayout.childAt(mouse.x, mouse.y)
173 //console.log(mouse.x, mouse.y, columnGridLayoutItem)
174 var mappedMouse = labelValueColumnLayout.mapToItem(columnGridLayoutItem, mouse.x, mouse.y)
175 var labelOrDataItem = columnGridLayoutItem.childAt(mappedMouse.x, mappedMouse.y)
176 //console.log(mappedMouse.x, mappedMouse.y, labelOrDataItem, labelOrDataItem ? labelOrDataItem.instrumentValueData : "null", labelOrDataItem && labelOrDataItem.parent ? labelOrDataItem.parent.instrumentValueData : "null")
177 if (labelOrDataItem && labelOrDataItem.instrumentValueData !== undefined) {
178 valueEditDialogFactory.open({ instrumentValueData: labelOrDataItem.instrumentValueData })
179 }
180 }
181 }
182
183 QGCPopupDialogFactory {
184 id: valueEditDialogFactory
185
186 dialogComponent: valueEditDialog
187 }
188
189 Component {
190 id: valueEditDialog
191
192 InstrumentValueEditDialog { }
193 }
194}