Skip to content

Commit c096339

Browse files
committed
feat(Serial): Add custom baud rate entry for serial links
Add a 'Custom' option to the baud rate combo box in both SerialSettings and NmeaGpsSettings. When selected, a text field appears allowing entry of any baud rate value. - Append 'Custom' entry to baud rate combo in SerialSettings - Show QGCTextField with IntValidator when Custom is selected - Persist custom baud via saveSettings() on dialog accept - If saved baud not in standard list, auto-select Custom on load - Apply same pattern to NmeaGpsSettings for NMEA serial ports Fixes #13021
1 parent adbd787 commit c096339

File tree

2 files changed

+77
-15
lines changed

2 files changed

+77
-15
lines changed

src/UI/AppSettings/NmeaGpsSettings.qml

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,24 +43,58 @@ SettingsGroupLayout {
4343

4444
LabelledComboBox {
4545
id: nmeaBaudCombo
46-
visible: (nmeaPortCombo.currentText !== "UDP Port") && (nmeaPortCombo.currentText !== "Disabled")
46+
visible: nmeaPortCombo.currentIndex > 1
4747
label: qsTr("Baudrate")
48-
model: QGroundControl.linkManager.serialBaudRates
48+
49+
readonly property string _customLabel: qsTr("Custom")
50+
readonly property bool isCustomBaud: currentText === _customLabel
4951

5052
onActivated: (index) => {
51-
if (index !== -1) {
53+
if (index !== -1 && !isCustomBaud) {
5254
QGroundControl.settingsManager.autoConnectSettings.autoConnectNmeaBaud.value = parseInt(comboBox.textAt(index));
5355
}
5456
}
5557

5658
Component.onCompleted: {
57-
const index = nmeaBaudCombo.comboBox.find(QGroundControl.settingsManager.autoConnectSettings.autoConnectNmeaBaud.valueString);
58-
nmeaBaudCombo.currentIndex = index;
59+
var rates = QGroundControl.linkManager.serialBaudRates.slice()
60+
rates.push(_customLabel)
61+
nmeaBaudCombo.model = rates
62+
63+
var baud = QGroundControl.settingsManager.autoConnectSettings.autoConnectNmeaBaud.valueString
64+
const index = nmeaBaudCombo.comboBox.find(baud);
65+
if (index === -1) {
66+
nmeaBaudCombo.currentIndex = nmeaBaudCombo.comboBox.count - 1
67+
customNmeaBaudField.text = baud
68+
} else {
69+
nmeaBaudCombo.currentIndex = index;
70+
}
71+
}
72+
}
73+
74+
RowLayout {
75+
visible: nmeaBaudCombo.visible && nmeaBaudCombo.isCustomBaud
76+
spacing: ScreenTools.defaultFontPixelWidth
77+
78+
QGCLabel {
79+
text: qsTr("Custom Baud Rate")
80+
Layout.fillWidth: true
81+
}
82+
QGCTextField {
83+
id: customNmeaBaudField
84+
numericValuesOnly: true
85+
validator: IntValidator { bottom: 1 }
86+
onEditingFinished: {
87+
if (!nmeaBaudCombo.isCustomBaud) return
88+
var baud = parseInt(text)
89+
if (baud > 0) {
90+
QGroundControl.settingsManager.autoConnectSettings.autoConnectNmeaBaud.value = baud
91+
}
92+
}
5993
}
6094
}
6195

6296
LabelledFactTextField {
63-
visible: nmeaPortCombo.currentText === "UDP Port"
97+
visible: nmeaPortCombo.currentIndex === 1
6498
label: qsTr("NMEA stream UDP port")
6599
fact: QGroundControl.settingsManager.autoConnectSettings.nmeaUdpPort
66100
}

src/UI/AppSettings/SerialSettings.qml

Lines changed: 37 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,12 @@ ColumnLayout {
99
spacing: _rowSpacing
1010

1111
function saveSettings() {
12-
// No Need
12+
if (baudCombo.isCustomBaud) {
13+
var baud = parseInt(customBaudField.text)
14+
if (baud > 0) {
15+
subEditConfig.baud = baud
16+
}
17+
}
1318
}
1419

1520
GridLayout {
@@ -63,27 +68,50 @@ ColumnLayout {
6368
QGCComboBox {
6469
id: baudCombo
6570
Layout.preferredWidth: _secondColumnWidth
66-
model: QGroundControl.linkManager.serialBaudRates
71+
72+
readonly property string _customLabel: qsTr("Custom")
73+
readonly property bool isCustomBaud: currentText === _customLabel
6774

6875
onActivated: (index) => {
69-
if (index != -1) {
70-
subEditConfig.baud = parseInt(QGroundControl.linkManager.serialBaudRates[index])
76+
if (index !== -1 && !isCustomBaud) {
77+
subEditConfig.baud = parseInt(currentText)
7178
}
7279
}
7380

7481
Component.onCompleted: {
75-
var baud = "57600"
76-
if(subEditConfig != null) {
77-
baud = subEditConfig.baud.toString()
78-
}
82+
var rates = QGroundControl.linkManager.serialBaudRates.slice()
83+
rates.push(_customLabel)
84+
model = rates
85+
86+
var baud = subEditConfig ? subEditConfig.baud.toString() : "57600"
7987
var index = baudCombo.find(baud)
8088
if (index === -1) {
81-
console.warn(qsTr("Baud rate name not in combo box"), baud)
89+
baudCombo.currentIndex = baudCombo.count - 1
90+
customBaudField.text = baud
8291
} else {
8392
baudCombo.currentIndex = index
8493
}
8594
}
8695
}
96+
97+
QGCLabel {
98+
text: qsTr("Custom Baud Rate")
99+
visible: baudCombo.isCustomBaud
100+
}
101+
QGCTextField {
102+
id: customBaudField
103+
Layout.preferredWidth: _secondColumnWidth
104+
visible: baudCombo.isCustomBaud
105+
numericValuesOnly: true
106+
validator: IntValidator { bottom: 1 }
107+
onEditingFinished: {
108+
if (!baudCombo.isCustomBaud) return
109+
var baud = parseInt(text)
110+
if (baud > 0) {
111+
subEditConfig.baud = baud
112+
}
113+
}
114+
}
87115
}
88116

89117
QGCCheckBox {

0 commit comments

Comments
 (0)