From f4c6a048f5b4de6db67b566111004778a84f0a6b Mon Sep 17 00:00:00 2001 From: luocai Date: Mon, 26 Aug 2024 14:55:15 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E9=83=A8=E5=88=86BUG?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Application.cpp | 10 ++++-- CMakeLists.txt | 9 ++--- DataCollection.cpp | 2 +- DeviceConnection.cpp | 1 + DeviceListModel.cpp | 8 +++++ DeviceListModel.h | 1 + qml/DeviceView.qml | 2 +- qml/IpTextField.qml | 4 +-- qml/Main.qml | 66 +++++++++++++++++++++++++++---------- qml/NetworkSettingPopup.qml | 6 ++++ 10 files changed, 80 insertions(+), 29 deletions(-) diff --git a/Application.cpp b/Application.cpp index 69b5414..3242a01 100644 --- a/Application.cpp +++ b/Application.cpp @@ -17,7 +17,7 @@ Application::Application(int &argc, char **argv) font.setPointSize(16); m_app->setFont(font); m_app->setApplicationName(APPLICATION_NAME); - m_app->setApplicationVersion(QString("v%1_%2 build: %3 %4").arg(APP_VERSION, GIT_COMMIT_ID, __DATE__, __TIME__)); + m_app->setApplicationVersion(QString("v%1").arg(APP_VERSION)); m_player->open(); } @@ -145,8 +145,12 @@ void Application::updateNetworkInfomation(bool dhcp, const QString &ip, const QS const QString &dns) { if (!m_device.expired()) { auto device = m_device.lock(); - device->updateNetworkInfomation(dhcp, ip, netmask, gateway, dns); - emit newMessage(1, "网络设置", "设置成功,请等待设备重新上线!"); + if (device->isConnected()) { + device->updateNetworkInfomation(dhcp, ip, netmask, gateway, dns); + emit newMessage(1, "网络设置", "设置成功,请等待设备重新上线!"); + } else { + emit newMessage(2, "网络设置", "设备已离线!"); + } } } diff --git a/CMakeLists.txt b/CMakeLists.txt index a6e04c9..6e7ee2e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,7 @@ cmake_minimum_required(VERSION 3.16) -project(AntiClipSettings VERSION 0.1 LANGUAGES C CXX) -set(APPLICATION_NAME "T009") +project(AntiClipSettings VERSION 1.1 LANGUAGES C CXX) +set(APPLICATION_NAME "T009上位机工具") set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) @@ -9,6 +9,9 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON) set(Projects_ROOT E:/Projects) set(Libraries_ROOT ${Projects_ROOT}/Libraries) +find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Qml Quick Network QuickControls2) +find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Qml Quick Network QuickControls2) + if (Qt6_FOUND) qt_standard_project_setup(REQUIRES 6.5) set(BOOST_ROOT ${Libraries_ROOT}/boost_1_86_0_msvc2022_64bit) @@ -29,8 +32,6 @@ set(FFmpeg_INCLUDE_DIR ${FFmpeg_ROOT}/include) set(FFmpeg_LIB_DIR ${FFmpeg_ROOT}/lib) find_package(Boost REQUIRED COMPONENTS json) -find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Qml Quick Network QuickControls2) -find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Qml Quick Network QuickControls2) execute_process( COMMAND D:/msys64/usr/bin/git rev-parse --short HEAD diff --git a/DataCollection.cpp b/DataCollection.cpp index cac490e..d59727b 100644 --- a/DataCollection.cpp +++ b/DataCollection.cpp @@ -37,7 +37,7 @@ void DataCollection::setPath(const QString &path) { if (m_path != p) { m_path = p; emit pathChanged(); - LOG(info) << "set data path: " << m_path.toStdWString(); + LOG(info) << "set data path: " << m_path.toStdString(); } } diff --git a/DeviceConnection.cpp b/DeviceConnection.cpp index 85ef5ff..26aa92a 100644 --- a/DeviceConnection.cpp +++ b/DeviceConnection.cpp @@ -600,6 +600,7 @@ void DeviceConnection::onDisconnected() { m_otaProgress = -1; emit otaProgressChanged(false, m_otaProgress, "网络断开,设备升级失败!"); } + m_h264Socket->close(); } } diff --git a/DeviceListModel.cpp b/DeviceListModel.cpp index 38ad141..9a6b29c 100644 --- a/DeviceListModel.cpp +++ b/DeviceListModel.cpp @@ -99,6 +99,14 @@ std::shared_ptr DeviceListModel::device(int index) { return ret; } +bool DeviceListModel::deviceConnected(int index) { + bool ret = false; + if (index >= 0 && index < m_devices.size()) { + ret = m_devices.at(index)->isConnected(); + } + return ret; +} + void DeviceListModel::startSearchDevice() { if (m_timerId >= 0) { LOG(error) << "app is searching device."; diff --git a/DeviceListModel.h b/DeviceListModel.h index 7bf6cbf..997924e 100644 --- a/DeviceListModel.h +++ b/DeviceListModel.h @@ -31,6 +31,7 @@ public: QHash roleNames() const final; Q_INVOKABLE QVariantMap get(int index) const; std::shared_ptr device(int index); + Q_INVOKABLE bool deviceConnected(int index); void startSearchDevice(); bool isSearching() const; float searchProgress() const; diff --git a/qml/DeviceView.qml b/qml/DeviceView.qml index 787e73a..0341566 100644 --- a/qml/DeviceView.qml +++ b/qml/DeviceView.qml @@ -7,7 +7,7 @@ Item { id: root property alias enabled: shieldedRow.enabled property int dargWidth: 12 - property color openDoorAreaColor: "green" + property color openDoorAreaColor: "#0FF40D" // 绿色 property var openDoorAreaPoints: [] property int openDoorAreaWay: 0 property color shieldedAreaColor: "yellow" diff --git a/qml/IpTextField.qml b/qml/IpTextField.qml index 4299925..6b48a5b 100644 --- a/qml/IpTextField.qml +++ b/qml/IpTextField.qml @@ -7,6 +7,7 @@ Column { property alias text: input.text property bool valid: false property bool canEmpty: false + property var regularExpression : /^(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])\.(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])\.(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])\.(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])$/ TextField { height: 36 width: 350 @@ -30,8 +31,7 @@ Column { root.valid = root.canEmpty return root.valid } - var regex = /^(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])\.(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])\.(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])\.(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])$/ - root.valid = regex.test(input.text) + root.valid = root.regularExpression.test(input.text) if (!root.valid) { hint.text = "参数配置无效" } else { diff --git a/qml/Main.qml b/qml/Main.qml index cd4cc94..c08aad2 100644 --- a/qml/Main.qml +++ b/qml/Main.qml @@ -1,22 +1,20 @@ import QtQuick 2.15 import QtQuick.Controls 2.15 import QtQuick.Layouts 1.15 -import QtQuick.Dialogs import AntiClipSettings 1.0 -import Qt.labs.platform 1.1 as Labs - ApplicationWindow { id: window width: 1000 height: 640 visible: true - title: qsTr("T009上位机工具") + title: qsTr(Qt.application.name + " " + Qt.application.version) header: ToolBar { RowLayout { anchors.fill: parent - ToolButton { + Button { + Material.background: Material.Blue text: "搜索设备" onClicked: { deviceList.currentIndex = -1 @@ -42,6 +40,12 @@ ApplicationWindow { width: 420 clip: true model: App.devices + Label { + id: emptyHint + visible: false + anchors.centerIn: parent + text: qsTr("未搜索到设备") + } delegate: Rectangle { width: deviceList.width height: 40 @@ -72,7 +76,11 @@ ApplicationWindow { deviceList.currentIndex = index } onDoubleClicked: { - networkPopup.open() + if(App.devices.deviceConnected(index)){ + networkPopup.open() + } else { + showMessageDialog(2, "网络设置", "设备已离线!") + } } } } @@ -97,7 +105,7 @@ ApplicationWindow { anchors.bottom: parent.bottom anchors.left: deviceList.right anchors.right: parent.right - enabled: App.currentDeviceConnected&&(deviceList.currentIndex >= 0) + enabled: App.currentDeviceConnected && (deviceList.currentIndex >= 0) openDoorAreaWay: App.currentOpenDoorAreaWay openDoorAreaPoints: App.currentOpenDoorAreaPoints shieldedAreaEnabled: App.currentShieldedAreaEnabled @@ -116,14 +124,6 @@ ApplicationWindow { id: otaPopup } - Labs.FolderDialog { - id: folderDialog - onAccepted: { - App.collector.path = folderDialog.selectedFolder - App.collector.start(App.devices.get(deviceList.currentIndex).ip) - } - } - footer: RowLayout { width: parent.width Item {} @@ -136,12 +136,15 @@ ApplicationWindow { if (deviceList.currentIndex < 0) { showMessageDialog(2, "数据采集", "请先选择设备") return - } else if(!App.currentDeviceConnected){ + } else if (!App.currentDeviceConnected) { showMessageDialog(2, "数据采集", "设备已离线,请重新连接设备!") return } if (App.collector.path.length <= 0) { - folderDialog.open() + showFolderDialog((folder)=>{ + App.collector.path = folder + App.collector.start(App.devices.get(deviceList.currentIndex).ip) + }) } else { App.collector.start(App.devices.get( deviceList.currentIndex).ip) @@ -156,7 +159,7 @@ ApplicationWindow { if (deviceList.currentIndex < 0) { showMessageDialog(2, "OTA升级", "请先选择设备!") return - }else if(!App.currentDeviceConnected){ + } else if (!App.currentDeviceConnected) { showMessageDialog(2, "OTA升级", "设备已离线,请重新连接设备!") return } @@ -179,10 +182,37 @@ ApplicationWindow { dialog.open() } } + + function showFolderDialog(onSelected){ + var dialog = Qt.createQmlObject("import QtQuick.Dialogs; FolderDialog {}",window,"myDynamicSnippet"); + if (dialog) { + dialog.visible = true; + dialog.accepted.connect(function() { + onSelected(dialog.selectedFolder) + dialog.destroy(); + }); + dialog.rejected.connect(function() { + dialog.destroy(); + }); + } else { + console.error("Failed to create FolderDialog object"); + } + } + Connections { target: App function onNewMessage(type, title, message) { showMessageDialog(type, title, message) } } + Connections { + target: App.devices + function onIsSearchingChanged() { + if (App.devices.isSearching) { + emptyHint.visible = false + } else if (!App.devices.isSearching && (App.devices.rowCount() <= 0)) { + emptyHint.visible = true + } + } + } } diff --git a/qml/NetworkSettingPopup.qml b/qml/NetworkSettingPopup.qml index 73a12b0..97df378 100644 --- a/qml/NetworkSettingPopup.qml +++ b/qml/NetworkSettingPopup.qml @@ -15,6 +15,10 @@ Popup { } contentItem: ColumnLayout { anchors.centerIn: parent + Label { + Layout.alignment: Qt.AlignCenter + text: "有线网络设置" + } Row { spacing: 10 @@ -59,6 +63,7 @@ Popup { height: inputHeight width: 350 text: App.currentNetworkInfomation.ip + regularExpression: /^(22[0-3]|2[01][0-9]|1[0-9]{2}|[1-9][0-9]?|1[0-9]{2})\.(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])\.(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])\.(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])$/; } } @@ -101,6 +106,7 @@ Popup { width: 350 height: inputHeight text: App.currentNetworkInfomation.gateway + regularExpression: /^(22[0-3]|2[01][0-9]|1[0-9]{2}|[1-9][0-9]?|1[0-9]{2})\.(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])\.(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])\.(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])$/; canEmpty: true } }