Serial-Studio/assets/qml/JsonEditor/JsonDatasetDelegate.qml

292 lines
8.8 KiB
QML
Raw Normal View History

2021-09-17 01:41:50 -05:00
/*
* Copyright (c) 2020-2021 Alex Spataru <https://github.com/alex-spataru>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
2021-09-30 19:07:39 -05:00
import QtQuick
import QtQuick.Layouts
import QtQuick.Controls
2021-09-17 01:41:50 -05:00
import "../Widgets" as Widgets
Widgets.Window {
id: root
2021-09-17 19:44:59 -05:00
//
// Window properties
//
2021-09-17 17:45:05 -05:00
headerDoubleClickEnabled: false
2021-09-17 01:41:50 -05:00
icon.source: "qrc:/icons/dataset.svg"
2021-10-06 16:58:35 -05:00
borderColor: Cpp_ThemeManager.widgetWindowBorder
palette.window: Cpp_ThemeManager.widgetWindowBackground
2021-09-17 17:45:05 -05:00
title: qsTr("Dataset %1 - %2").arg(dataset + 1).arg(Cpp_JSON_Editor.datasetTitle(group, dataset))
2021-09-17 19:44:59 -05:00
//
// Delete dataset button
//
2021-10-13 03:47:19 -05:00
altButtonEnabled: !showGroupWidget
2021-09-17 19:44:59 -05:00
altButtonIcon.source: "qrc:/icons/close.svg"
onAltButtonClicked: Cpp_JSON_Editor.deleteDataset(group, dataset)
2021-09-17 17:45:05 -05:00
//
// Custom properties
//
property int group
property int dataset
property bool showGroupWidget
//
// Convenience variables
//
2021-10-09 16:26:19 -05:00
readonly property bool fftSamplesVisible: fftCheck.checked
readonly property bool alarmVisible: widget.currentIndex === 2
readonly property bool minMaxVisible: widget.currentIndex === 1 || widget.currentIndex === 2 || logPlot.checked || linearPlot.checked
2021-09-17 17:45:05 -05:00
//
// User interface
//
2021-09-17 01:41:50 -05:00
GridLayout {
2021-09-17 17:45:05 -05:00
x: 0
2021-09-17 01:41:50 -05:00
columns: 2
2021-09-17 17:45:05 -05:00
anchors.fill: parent
2021-09-17 01:41:50 -05:00
rowSpacing: app.spacing
columnSpacing: app.spacing
2021-09-17 17:45:05 -05:00
anchors.margins: app.spacing * 2
2021-09-17 01:41:50 -05:00
2021-09-17 17:45:05 -05:00
//
// Dataset title
//
2021-09-17 01:41:50 -05:00
Label {
text: qsTr("Title:")
2021-09-17 17:45:05 -05:00
} TextField {
2021-09-17 01:41:50 -05:00
Layout.fillWidth: true
2021-09-17 17:45:05 -05:00
text: Cpp_JSON_Editor.datasetTitle(group, dataset)
2021-09-17 01:41:50 -05:00
placeholderText: qsTr("Sensor reading, uptime, etc...")
2021-09-17 17:45:05 -05:00
onTextChanged: {
Cpp_JSON_Editor.setDatasetTitle(group, dataset, text)
root.title = qsTr("Dataset %1 - %2").arg(dataset + 1).arg(Cpp_JSON_Editor.datasetTitle(group, dataset))
}
2021-09-17 01:41:50 -05:00
}
2021-09-17 17:45:05 -05:00
//
// Dataset units
//
2021-09-17 01:41:50 -05:00
Label {
text: qsTr("Units:")
2021-09-17 17:45:05 -05:00
} TextField {
2021-09-17 01:41:50 -05:00
Layout.fillWidth: true
2021-09-17 17:45:05 -05:00
text: Cpp_JSON_Editor.datasetUnits(group, dataset)
2021-09-17 01:41:50 -05:00
placeholderText: qsTr("Volts, meters, seconds, etc...")
2021-09-17 17:45:05 -05:00
onTextChanged: Cpp_JSON_Editor.setDatasetUnits(group, dataset, text)
2021-09-17 01:41:50 -05:00
}
2021-09-17 17:45:05 -05:00
//
// Frame index
//
2021-09-17 01:41:50 -05:00
Label {
text: qsTr("Frame index:")
2021-09-17 19:44:59 -05:00
} TextField {
2021-09-17 01:41:50 -05:00
Layout.fillWidth: true
2021-09-17 19:44:59 -05:00
text: Cpp_JSON_Editor.datasetIndex(group, dataset)
onTextChanged: Cpp_JSON_Editor.setDatasetIndex(group, dataset, text)
validator: IntValidator {
bottom: 1
top: 100
}
2021-09-17 01:41:50 -05:00
}
2021-09-17 17:45:05 -05:00
//
// Dataset graph
//
2021-09-17 01:41:50 -05:00
Label {
2021-10-07 19:02:02 -05:00
text: qsTr("Generate plot:")
2021-09-17 17:45:05 -05:00
} Switch {
id: linearPlot
2021-09-17 17:45:05 -05:00
Layout.leftMargin: -app.spacing
checked: Cpp_JSON_Editor.datasetGraph(group, dataset)
2021-10-07 19:02:02 -05:00
onCheckedChanged: {
if (!checked)
logPlot.checked = false
Cpp_JSON_Editor.setDatasetGraph(group, dataset, checked)
}
2021-09-17 01:41:50 -05:00
}
2021-10-06 23:50:17 -05:00
//
2021-10-07 19:02:02 -05:00
// Log plot
2021-10-06 23:50:17 -05:00
//
Label {
2021-10-07 19:02:02 -05:00
text: qsTr("Logarithmic plot:")
visible: linearPlot.checked
} CheckBox {
id: logPlot
visible: linearPlot.checked
2021-10-06 23:50:17 -05:00
Layout.leftMargin: -app.spacing
2021-10-07 19:02:02 -05:00
checked: Cpp_JSON_Editor.datasetLogPlot(group, dataset)
onCheckedChanged: Cpp_JSON_Editor.setDatasetLogPlot(group, dataset, checked)
2021-10-06 23:50:17 -05:00
}
//
// FFT plot
//
Label {
2021-10-07 19:02:02 -05:00
text: qsTr("FFT plot:")
} Switch {
2021-10-09 16:26:19 -05:00
id: fftCheck
Layout.leftMargin: -app.spacing
2021-10-07 19:02:02 -05:00
checked: Cpp_JSON_Editor.datasetFftPlot(group, dataset)
onCheckedChanged: Cpp_JSON_Editor.setDatasetFftPlot(group, dataset, checked)
}
2021-09-17 17:45:05 -05:00
//
// Dataset widget (user selectable or group-level constant)
//
Label {
text: qsTr("Widget:")
} ComboBox {
2021-09-17 01:41:50 -05:00
id: widget
2021-09-17 17:45:05 -05:00
Layout.fillWidth: true
visible: !showGroupWidget
enabled: !showGroupWidget
2021-09-17 17:45:05 -05:00
model: Cpp_JSON_Editor.availableDatasetLevelWidgets()
currentIndex: Cpp_JSON_Editor.datasetWidgetIndex(group, dataset)
onCurrentIndexChanged: {
if (visible && currentIndex !== Cpp_JSON_Editor.datasetWidgetIndex(group, dataset))
2021-09-17 17:45:05 -05:00
Cpp_JSON_Editor.setDatasetWidget(group, dataset, currentIndex)
}
} TextField {
readOnly: true
2021-09-17 01:41:50 -05:00
Layout.fillWidth: true
2021-09-17 17:45:05 -05:00
visible: showGroupWidget
enabled: showGroupWidget
2021-09-17 17:45:05 -05:00
text: Cpp_JSON_Editor.datasetWidget(group, dataset)
2021-09-17 01:41:50 -05:00
}
2021-10-09 16:26:19 -05:00
//
// FFT max frequency
//
Label {
text: qsTr("FFT Samples:")
visible: root.fftSamplesVisible
} TextField {
id: fftSamples
Layout.fillWidth: true
visible: root.fftSamplesVisible
text: Cpp_JSON_Editor.datasetFFTSamples(group, dataset)
onTextChanged: Cpp_JSON_Editor.setDatasetFFTSamples(group, dataset, parseInt(text))
validator: IntValidator {
2021-10-19 01:24:19 -05:00
bottom: 8
2021-10-09 16:26:19 -05:00
top: 40 * 1000
}
}
2021-09-17 17:45:05 -05:00
//
// Widget minimum value
//
2021-09-17 01:41:50 -05:00
Label {
text: qsTr("Min value:")
visible: root.minMaxVisible
2021-09-17 17:45:05 -05:00
} TextField {
2021-09-17 01:41:50 -05:00
id: min
Layout.fillWidth: true
visible: root.minMaxVisible
2021-09-17 17:45:05 -05:00
text: Cpp_JSON_Editor.datasetWidgetMin(group, dataset)
onTextChanged: Cpp_JSON_Editor.setDatasetWidgetMin(group, dataset, text)
validator: DoubleValidator {
top: parseFloat(max.text)
}
2021-09-17 01:41:50 -05:00
}
2021-09-17 17:45:05 -05:00
//
// Widget maximum value
//
2021-09-17 01:41:50 -05:00
Label {
text: qsTr("Max value:")
visible: root.minMaxVisible
2021-09-17 17:45:05 -05:00
} TextField {
2021-09-17 01:41:50 -05:00
id: max
Layout.fillWidth: true
visible: root.minMaxVisible
2021-09-17 17:45:05 -05:00
text: Cpp_JSON_Editor.datasetWidgetMax(group, dataset)
onTextChanged: Cpp_JSON_Editor.setDatasetWidgetMax(group, dataset, text)
validator: DoubleValidator {
bottom: parseFloat(min.text)
}
}
2021-09-26 05:42:22 -05:00
//
2021-10-13 03:47:19 -05:00
// Bar alarm level
2021-09-26 05:42:22 -05:00
//
Label {
2021-10-13 03:47:19 -05:00
text: qsTr("Alarm level:")
visible: root.alarmVisible
2021-09-26 05:42:22 -05:00
} TextField {
id: alarm
Layout.fillWidth: true
visible: root.alarmVisible
2021-09-26 05:42:22 -05:00
text: Cpp_JSON_Editor.datasetWidgetAlarm(group, dataset)
onTextChanged: Cpp_JSON_Editor.setDatasetWidgetAlarm(group, dataset, text)
validator: DoubleValidator {
top: parseFloat(max.text)
bottom: parseFloat(min.text)
}
}
2021-09-17 17:45:05 -05:00
//
// Vertical spacer
//
Item {
Layout.fillHeight: true
} Item {
Layout.fillHeight: true
2021-09-17 01:41:50 -05:00
}
2021-10-07 20:51:47 -05:00
//
// Compass note label
//
Widgets.Icon {
width: 32
height: 32
color: palette.text
source: "qrc:/icons/compass.svg"
Layout.alignment: Qt.AlignHCenter
visible: widget.currentIndex === 3
} Label {
font.pixelSize: 16
Layout.fillWidth: true
wrapMode: Label.WordWrap
visible: widget.currentIndex === 3
text: "<b>" + qsTr("Note:") + "</b> " + qsTr("The compass widget expects values from 0° to 360°.")
}
//
// Vertical spacer
//
Item {
Layout.fillHeight: true
} Item {
Layout.fillHeight: true
}
2021-09-17 01:41:50 -05:00
}
}