From 094b8aa2bbb8b90dff9da199873cbc6b36549eb6 Mon Sep 17 00:00:00 2001 From: Thomas Vanbesien Date: Wed, 11 Mar 2026 15:25:11 +0100 Subject: Refactor: three XPL2 ports, EchoServer class, dark debug console, qmllint clean - Xpl2Client: replace single port with commandPort/imagingPort/statusPort (9110/9111/9112) - Mock server: extract EchoServer class from lambda-based listenOn() - Demo: dark debug console matching BobinkQtOpcUa style, 2-column connection layout - Fix qmlls module resolution via IMPORT_PATH in qt_add_qml_module() - Add pragma ComponentBehavior: Bound, fix all qmllint warnings --- demo/Main.qml | 292 +++++++++++++++++++++++++++++++++++----------------------- 1 file changed, 178 insertions(+), 114 deletions(-) (limited to 'demo/Main.qml') diff --git a/demo/Main.qml b/demo/Main.qml index 82b2573..fe9f885 100644 --- a/demo/Main.qml +++ b/demo/Main.qml @@ -1,3 +1,5 @@ +pragma ComponentBehavior: Bound + import QtQuick import QtQuick.Controls import QtQuick.Layouts @@ -6,170 +8,232 @@ import Xpl2 ApplicationWindow { id: root - width: 800 height: 600 - visible: true title: "XPL2 Demo" + visible: true + width: 800 Connections { - target: Xpl2Client - function onConnectedChanged() { - log(Xpl2Client.connected ? "Connected" : "Disconnected"); + debugConsole.appendLog(Xpl2Client.connected ? "Connected" : + "Disconnected"); } - function onResponseReceived(response: string) { - log("← " + response); - responseModel.append({ - text: response - }); + function onErrorOccurred(error: string) { + debugConsole.appendLog("ERROR: " + error); } - function onErrorOccurred(error: string) { - log("ERROR: " + error); + function onResponseReceived(response: string) { + debugConsole.appendLog("Received: " + response); + responseModel.append({ + text: response + }); } function onStatusMessage(message: string) { - log(message); + debugConsole.appendLog(message); } - } - function log(msg: string) { - let ts = new Date().toLocaleTimeString(Qt.locale(), "HH:mm:ss.zzz"); - logModel.append({ - text: "[" + ts + "] " + msg - }); - logView.positionViewAtEnd(); + target: Xpl2Client } ColumnLayout { anchors.fill: parent - anchors.margins: 16 - spacing: 12 + spacing: 0 - // --- Connection --- - GroupBox { - title: "Connection" + ColumnLayout { + Layout.fillHeight: true Layout.fillWidth: true + Layout.margins: 16 + spacing: 12 - GridLayout { - columns: 4 - anchors.fill: parent + // --- Connection --- + GroupBox { + Layout.fillWidth: true + title: "Connection" - Label { - text: "Host:" - } - TextField { - id: hostField - text: Xpl2Client.host - Layout.fillWidth: true - onEditingFinished: Xpl2Client.host = text - } + GridLayout { + anchors.fill: parent + columns: 2 - Label { - text: "Port:" - } - TextField { - id: portField - text: Xpl2Client.port - implicitWidth: 80 - validator: IntValidator { - bottom: 1 - top: 65535 + Label { + text: "Host:" } - onEditingFinished: Xpl2Client.port = parseInt(text) - } - Button { - text: Xpl2Client.connected ? "Disconnect" : "Connect" - Layout.columnSpan: 4 - Layout.alignment: Qt.AlignRight - onClicked: { - if (Xpl2Client.connected) + TextField { + id: hostField + + Layout.fillWidth: true + text: Xpl2Client.host + + onEditingFinished: Xpl2Client.host = text + } + + Label { + text: "Command port:" + } + + TextField { + id: commandPortField + + Layout.fillWidth: true + text: Xpl2Client.commandPort + + validator: IntValidator { + bottom: 1 + top: 65535 + } + + onEditingFinished: Xpl2Client.commandPort = parseInt( + text) + } + + Label { + text: "Imaging port:" + } + + TextField { + id: imagingPortField + + Layout.fillWidth: true + text: Xpl2Client.imagingPort + + validator: IntValidator { + bottom: 1 + top: 65535 + } + + onEditingFinished: Xpl2Client.imagingPort = parseInt( + text) + } + + Label { + text: "Status port:" + } + + TextField { + id: statusPortField + + Layout.fillWidth: true + text: Xpl2Client.statusPort + + validator: IntValidator { + bottom: 1 + top: 65535 + } + + onEditingFinished: Xpl2Client.statusPort = parseInt( + text) + } + + Button { + Layout.alignment: Qt.AlignRight + Layout.columnSpan: 2 + text: Xpl2Client.connected ? "Disconnect" : "Connect" + + onClicked: { + if (Xpl2Client.connected) Xpl2Client.disconnectFromServer(); - else + else Xpl2Client.connectToServer(); + } } } } - } - // --- Send Command --- - GroupBox { - title: "Command" - Layout.fillWidth: true - enabled: Xpl2Client.connected + // --- Send Command --- + GroupBox { + Layout.fillWidth: true + enabled: Xpl2Client.connected + title: "Command" - RowLayout { - anchors.fill: parent + RowLayout { + anchors.fill: parent - TextField { - id: cmdField - placeholderText: "Enter command…" - Layout.fillWidth: true - onAccepted: sendBtn.clicked() - } + TextField { + id: cmdField + + Layout.fillWidth: true + placeholderText: "Enter command…" + + onAccepted: sendBtn.clicked() + } - Button { - id: sendBtn - text: "Send" - onClicked: { - if (cmdField.text.length > 0) { - Xpl2Client.sendCommand(cmdField.text); - cmdField.text = ""; + Button { + id: sendBtn + + text: "Send" + + onClicked: { + if (cmdField.text.length > 0) { + Xpl2Client.sendCommand(cmdField.text); + cmdField.text = ""; + } } } } } - } - // --- Responses --- - GroupBox { - title: "Responses" - Layout.fillWidth: true - Layout.fillHeight: true + // --- Responses --- + GroupBox { + Layout.fillHeight: true + Layout.fillWidth: true + title: "Responses" - ListView { - id: responseView - anchors.fill: parent - clip: true - model: ListModel { - id: responseModel - } + ListView { + id: responseView - delegate: Text { - required property string text - width: responseView.width - wrapMode: Text.Wrap - font.family: "monospace" - font.pixelSize: 13 - text: model.text + anchors.fill: parent + clip: true + + delegate: Text { + id: responseDelegate + + required property string text + + font.family: "monospace" + font.pixelSize: 13 + text: responseDelegate.text + width: responseView.width + wrapMode: Text.Wrap + } + model: ListModel { + id: responseModel + + } } } } - // --- Debug Log --- - GroupBox { - title: "Log" + // --- Debug Console --- + Rectangle { + id: debugConsole + + function appendLog(msg) { + let ts = new Date().toLocaleTimeString(Qt.locale(), "HH:mm:ss"); + debugLog.text += "[" + ts + "] " + msg + "\n"; + debugLog.cursorPosition = debugLog.text.length; + } + Layout.fillWidth: true - Layout.preferredHeight: 160 + Layout.preferredHeight: 120 + border.color: "#444" + color: "#1e1e1e" + radius: 4 - ListView { - id: logView + ScrollView { anchors.fill: parent - clip: true - model: ListModel { - id: logModel - } + anchors.margins: 4 + + TextArea { + id: debugLog - delegate: Text { - required property string text - width: logView.width - wrapMode: Text.Wrap + background: null + color: "#cccccc" font.family: "monospace" - font.pixelSize: 12 - color: "#555" - text: model.text + font.pointSize: 9 + readOnly: true + wrapMode: TextEdit.Wrap } } } -- cgit v1.2.3