Change port’s Label to a CheckBox

For host, database name, and options i can leave them blank to use the
default value, but for the port i can’t with a SpinBox, since it _must_
have a value.

Qt’s driver uses -1 to mean “default port”, but i can not use the same
approach with the user interface, because there is no port -1, and makes
no sense to allow that value, specially since i then i have to allow 0
as well, which is a reserved port.

I also can not leave the SpinBox with PostgreSQL’s default port, 5432,
because that is slightly different than telling libpq to use the
“default”: if someone uses a ‘service=’ option, it would use the port in
the SpinBox rather than the one in ‘pg_service.conf’, if any.

My solution is to use a checkbox to tell the application “i wan to use a
port number”, and (will) only pass the port number if it is checked.  On
the other hand, now i do not have a keyboard shortcut to focus on the
port number field.
This commit is contained in:
jordi fita mas 2024-12-23 00:09:44 +01:00
parent 45c12ed2bb
commit dd2beba676
1 changed files with 14 additions and 4 deletions

View File

@ -67,17 +67,27 @@ Page {
onAccepted: loginAction.trigger() onAccepted: loginAction.trigger()
} }
MnemonicLabel { CheckBox {
id: port
Layout.alignment: Qt.AlignRight Layout.alignment: Qt.AlignRight
buddy: port Mnemonic.label: qsTr("Por&t:")
mnemonic: qsTr("Por&t:") text: Mnemonic.richTextLabel
Shortcut {
sequence: port.Mnemonic.sequence
onActivated: port.click()
}
} }
SpinBox { SpinBox {
id: port id: portNumber
Accessible.name: qsTr("Port number")
Layout.fillWidth: true Layout.fillWidth: true
editable: true editable: true
enabled: port.checked
from: 1 from: 1
to: 65535 to: 65535
} }