OP-1900 have path_progress updated correctly for leg_remaining and error_below end...
[librepilot.git] / ground / openpilotgcs / src / plugins / flightlog / FlightLogDialog.qml
bloba24a28551f721e056de8d6eb460f205b3840395b
1 import QtQuick 2.1
2 import QtQuick.Controls 1.0
3 import QtQuick.Layouts 1.0
5 import org.openpilot 1.0
7 import "functions.js" as Functions
9 Rectangle {
10     width: 700
11     height: 400
12     id: root
13     ColumnLayout {
14         anchors.fill: parent
15         anchors.margins: 10
16         spacing: 10
17         Rectangle {
18             Layout.fillWidth: true
19             Layout.fillHeight: true
20             border.width: 1
21             radius: 4
22             ColumnLayout {
23                 id: exportTab
24                 anchors.margins: 10
25                 anchors.fill: parent
26                 visible: true
27                 Text {
28                     Layout.fillWidth: true
29                     text: "<b>" + qsTr("Log entries") + "</b>"
30                 }
31                 TableView {
32                     Layout.fillWidth: true
33                     Layout.fillHeight: true
34                     Layout.preferredHeight: 1000;
35                     model: logManager.logEntries
36                     enabled: !logManager.disableControls && logManager.boardConnected
38                     rowDelegate: Rectangle {
39                         height: 22
40                         color: styleData.selected ? "#ccc" : (styleData.alternate ? "#fff" : "#eee")
41                     }
43                     itemDelegate: Text {
44                         verticalAlignment: Text.AlignVCenter
45                         text: styleData.value
46                     }
48                     TableViewColumn {
49                         role: "Flight"; title: qsTr("Flight"); width: 50;
50                         delegate:
51                             Text {
52                                 verticalAlignment: Text.AlignVCenter
53                                 text: styleData.value + 1
54                             }
56                     }
57                     TableViewColumn {
58                         role: "FlightTime"; title: qsTr("Time"); width: 100;
59                         delegate:
60                             Text {
61                                 verticalAlignment: Text.AlignVCenter
62                                 text: Functions.microsToTime(styleData.value)
63                             }
64                     }
65                     TableViewColumn {
66                         role: "Type"; title: "Type"; width: 50;
67                         delegate:
68                             Text {
69                                 verticalAlignment: Text.AlignVCenter
70                                 text: {
71                                     switch(styleData.value) {
72                                     case 0 : text: qsTr("Empty"); break;
73                                     case 1 : text: qsTr("Text"); break;
74                                     case 2 : text: qsTr("UAVO"); break;
75                                     case 3 : text: qsTr("UAVO(P)"); break;
76                                     default: text: qsTr("Unknown"); break;
77                                     }
78                                 }
79                             }
81                     }
82                     TableViewColumn {
83                         role: "LogString";
84                         title: qsTr("Data");
85                         width: 280
86                     }
87                 }
89                 RowLayout {
90                     anchors.margins: 10
91                     spacing: 10
93                     ColumnLayout {
94                         spacing: 10
95                         Text {
96                             id: totalFlights
97                             text: "<b>" + qsTr("Flights recorded:") + "</b> " + (logStatus.Flight + 1)
98                         }
99                         Text {
100                             id: totalSlots
101                             text: "<b>" + qsTr("Slots used/free:") + "</b> " +
102                                   logStatus.UsedSlots + "/" + logStatus.FreeSlots
103                         }
104                         Text {
105                             id: totalEntries
106                             text: "<b>" + qsTr("Entries downloaded:") + "</b> " + logManager.logEntriesCount
107                         }
108                         Rectangle {
109                             Layout.fillHeight: true
110                         }
111                         CheckBox {
112                             id: exportRelativeTimeCB
113                             enabled: !logManager.disableControls && !logManager.disableExport && logManager.boardConnected
114                             text: qsTr("Adjust timestamps")
115                             activeFocusOnPress: true
116                             checked: logManager.adjustExportedTimestamps
117                             onCheckedChanged: logManager.setAdjustExportedTimestamps(checked)
118                         }
119                     }
120                     Rectangle {
121                         Layout.fillWidth: true
122                     }
123                     ColumnLayout {
124                         spacing: 10
125                         RowLayout {
126                             Rectangle {
127                                 Layout.fillWidth: true
128                             }
129                             Text {
130                                 text: "<b>" + qsTr("Flight to download:") + "</b>"
131                             }
133                             ComboBox {
134                                 id: flightCombo
135                                 enabled: !logManager.disableControls && logManager.boardConnected
136                                 model: logManager.flightEntries
137                             }
138                         }
139                         RowLayout {
140                             spacing: 10
141                             Rectangle {
142                                 Layout.fillWidth: true
143                             }
144                             Button {
145                                 text: qsTr("Download logs")
146                                 enabled: !logManager.disableControls && logManager.boardConnected
147                                 activeFocusOnPress: true
148                                 onClicked: logManager.retrieveLogs(flightCombo.currentIndex - 1)
149                             }
150                         }
151                         Rectangle {
152                             Layout.fillHeight: true
153                         }
154                         RowLayout {
155                             Rectangle {
156                                 Layout.fillWidth: true
157                             }
158                             Button {
159                                 id: clearButton
160                                 enabled: !logManager.disableControls && logManager.boardConnected
161                                 text: qsTr("Clear all logs")
162                                 activeFocusOnPress: true
163                                 onClicked: logManager.clearAllLogs()
164                             }
165                             Button {
166                                 id: exportButton
167                                 enabled: !logManager.disableControls && !logManager.disableExport && logManager.boardConnected
168                                 text: qsTr("Export logs...")
169                                 activeFocusOnPress: true
170                                 onClicked: logManager.exportLogs()
171                             }
172                         }
173                     }
174                 }
175             }
176             ColumnLayout {
177                 id: settingsTab
178                 visible: false
179                 anchors.margins: 10
180                 anchors.fill: parent
181                 Text {
182                     Layout.fillWidth: true
183                     text: "<b>" + qsTr("Settings") + "</b>"
184                 }
186                 RowLayout {
187                     Layout.fillWidth: true
188                     Layout.fillHeight: true
189                     Text {
190                         text: qsTr("When to log: ")
191                     }
192                     ComboBox {
193                         enabled: !logManager.disableControls && logManager.boardConnected
194                         model: logManager.logStatuses
195                         Layout.preferredWidth: 200
196                         currentIndex: logManager.loggingEnabled
197                         onCurrentIndexChanged: {
198                             logManager.setLoggingEnabled(currentIndex);
199                         }
200                     }
202                 }
204                 Component {
205                     id: comboEditableDelegate
206                     Item {
208                         Text {
209                             width: parent.width
210                             anchors.left: parent.left
211                             anchors.verticalCenter: parent.verticalCenter
212                             elide: styleData.elideMode
213                             text: styleData.value !== undefined ? logManager.logSettings[styleData.value] : ""
214                             color: logManager.uavoEntries[styleData.row].dirty ? "#f00" : styleData.textColor
215                             visible: !styleData.selected
216                         }
217                         Loader {
218                             id: loaderEditor
219                             anchors.fill: parent
220                             Connections {
221                                 target: loaderEditor.item
222                                 onCurrentIndexChanged: {
223                                     logManager.uavoEntries[styleData.row].setting = loaderEditor.item.currentIndex
224                                 }
225                             }
226                             sourceComponent: styleData.selected ? editor : null
227                             Component {
228                                 id: editor
229                                 ComboBox {
230                                     id: combo
231                                     model: logManager.logSettings
232                                     currentIndex: styleData.value
233                                 }
234                             }
235                         }
236                     }
237                 }
239                 Component {
240                     id: spinnerEditableDelegate
241                     Item {
243                         Text {
244                             width: parent.width
245                             anchors.left: parent.left
246                             anchors.verticalCenter: parent.verticalCenter
247                             elide: styleData.elideMode
248                             text: styleData.value !== undefined &&
249                                   (logManager.uavoEntries[styleData.row].setting === 1 || logManager.uavoEntries[styleData.row].setting === 3) ?
250                                   parseInt(logManager.uavoEntries[styleData.row].period) + " ms" : "-"
251                             color: logManager.uavoEntries[styleData.row].dirty ? "#f00" : styleData.textColor
252                             //visible: !styleData.selected && (logManager.uavoEntries[styleData.row].setting <= 1)
253                             enabled: (logManager.uavoEntries[styleData.row].setting > 1)
254                         }
255                         Loader {
256                             id: loaderEditor
257                             anchors.fill: parent
258                             Connections {
259                                 target: loaderEditor.item
260                                 onValueChanged: {
261                                     logManager.uavoEntries[styleData.row].period = loaderEditor.item.value
262                                 }
263                             }
264                             sourceComponent: styleData.selected &&
265                                              (logManager.uavoEntries[styleData.row].setting === 1 || logManager.uavoEntries[styleData.row].setting === 3) ? editor : null
266                             Component {
267                                 id: editor
268                                 SpinBox {
269                                     id: spinner
270                                     decimals: 0
271                                     minimumValue: 0
272                                     maximumValue: 1000 * 60 * 60 //1h
273                                     suffix: "ms"
274                                     stepSize: 10
275                                     value: styleData.value
276                                 }
277                             }
278                         }
279                     }
280                 }
282                 TableView {
283                     id: settingsTable
284                     Layout.fillWidth: true
285                     Layout.fillHeight: true
286                     Layout.preferredHeight: 1000;
287                     model: logManager.uavoEntries
288                     enabled: !logManager.disableControls && logManager.boardConnected
290                     rowDelegate: Rectangle {
291                         height: 22
292                         color: styleData.selected ? "#ccc" : (styleData.alternate ? "#fff" : "#eee")
293                     }
295                     TableViewColumn {
296                         role: "name";
297                         title: qsTr("UAVObject");
298                         width: 250;
299                         delegate:
300                             Text {
301                                 verticalAlignment: Text.AlignVCenter
302                                 anchors.leftMargin: 5
303                                 color: logManager.uavoEntries[styleData.row].dirty ? "#f00" : styleData.textColor
304                                 text: styleData.value
305                             }
307                     }
309                     TableViewColumn {
310                         role: "setting";
311                         title: qsTr("Settings");
312                         width: 160;
313                         delegate: comboEditableDelegate
314                     }
316                     TableViewColumn {
317                         role: "period";
318                         title: qsTr("Period");
319                         width: 120;
320                         delegate: spinnerEditableDelegate
321                     }
322                 }
323                 RowLayout {
324                     Layout.fillWidth: true
325                     Layout.fillHeight: true
327                     Button {
328                         enabled: !logManager.disableControls && logManager.boardConnected
329                         text: qsTr("Load...")
330                         tooltip: qsTr("Loads settings for all objects from a file.")
331                         activeFocusOnPress: true
332                         onClicked: logManager.loadSettings()
333                     }
334                     Button {
335                         enabled: !logManager.disableControls && logManager.boardConnected
336                         text: qsTr("Save...")
337                         tooltip: qsTr("Saves settings for all objects in a file.")
338                         activeFocusOnPress: true
339                         onClicked: logManager.saveSettings()
340                     }
341                     Button {
342                         enabled: !logManager.disableControls && logManager.boardConnected
343                         text: qsTr("Reset")
344                         tooltip: qsTr("Resets all settings to the values currently set on the board.")
345                         activeFocusOnPress: true
346                         onClicked: logManager.resetSettings(false)
347                     }
348                     Button {
349                         enabled: !logManager.disableControls && logManager.boardConnected
350                         text: qsTr("Clear")
351                         tooltip: qsTr("Clears all settings to default values.")
352                         activeFocusOnPress: true
353                         onClicked: logManager.resetSettings(true)
354                     }
355                     Rectangle {
356                         Layout.fillWidth: true
357                     }
358                     Button {
359                         enabled: !logManager.disableControls && logManager.boardConnected
360                         text: qsTr("Save to board")
361                         tooltip: qsTr("Saves the logging configurations to the boards flash memory.")
362                         activeFocusOnPress: true
363                         onClicked: logManager.saveSettingsToBoard()
364                     }
365                 }
366             }
367         }
369         RowLayout {
370             Layout.fillWidth: true
371             height: 40
372             Button {
373                 id: settingsButton
374                 enabled: !logManager.disableControls
375                 text: qsTr("Settings...")
376                 activeFocusOnPress: true
377                 property bool showSettings: false
378                 onClicked: {
379                     showSettings = !showSettings;
380                     settingsTab.visible = showSettings;
381                     exportTab.visible = !showSettings;
382                     text = (showSettings ? qsTr("Logs...") : qsTr("Settings..."));
383                 }
384             }
385             Rectangle {
386                 Layout.fillWidth: true
387             }
388             Button {
389                 id: cancelButton
390                 enabled: logManager.disableControls
391                 text: qsTr("Cancel")
392                 activeFocusOnPress: true
393                 onClicked: logManager.cancelExportLogs()
394             }
395             Button {
396                 id: okButton
397                 enabled: !logManager.disableControls
398                 text: qsTr("OK")
399                 isDefault: true
400                 activeFocusOnPress: true
401                 onClicked: logDialog.close()
402             }
403         }
404     }