|
|
|
@ -11,6 +11,7 @@
|
|
|
|
|
#include "ui/dialogs/DeviceDialog.h"
|
|
|
|
|
#include "utils/SystemLogger.h"
|
|
|
|
|
#include "core/database/DatabaseHelper.h"
|
|
|
|
|
#include "core/database/EnemyDatabase.h"
|
|
|
|
|
#include "styles/ModernStyleManager.h"
|
|
|
|
|
|
|
|
|
|
// Qt GUI头文件
|
|
|
|
@ -56,6 +57,7 @@ MainWindow::MainWindow(QWidget *parent)
|
|
|
|
|
, m_leftPanelSplitter(nullptr)
|
|
|
|
|
, m_intelligenceUI(nullptr)
|
|
|
|
|
, m_faceLightControl(nullptr)
|
|
|
|
|
, m_enemyDisplayVisible(false)
|
|
|
|
|
, m_enemyStatsDialog(nullptr)
|
|
|
|
|
, m_visionProcess(nullptr)
|
|
|
|
|
// , m_droneControlDialog(nullptr)
|
|
|
|
@ -1219,51 +1221,113 @@ void MainWindow::onEnemyStatsRequested()
|
|
|
|
|
|
|
|
|
|
void MainWindow::onEnemyDisplayRequested()
|
|
|
|
|
{
|
|
|
|
|
qDebug() << "Displaying enemies on map...";
|
|
|
|
|
SystemLogger::getInstance()->logInfo("在地图上显示敌情");
|
|
|
|
|
|
|
|
|
|
// 获取所有敌情数据并在地图上显示
|
|
|
|
|
// 这里可以从EnemyDatabase获取数据
|
|
|
|
|
qDebug() << "Enemy display toggle requested, current state:" << m_enemyDisplayVisible;
|
|
|
|
|
|
|
|
|
|
if (m_enemyDisplayVisible) {
|
|
|
|
|
// 当前显示敌情,需要隐藏
|
|
|
|
|
qDebug() << "Hiding enemies on map...";
|
|
|
|
|
SystemLogger::getInstance()->logInfo("隐藏地图上的敌情");
|
|
|
|
|
|
|
|
|
|
QString jsCode = R"(
|
|
|
|
|
// 清除所有敌人标记
|
|
|
|
|
if (typeof clearEnemyMarkers === 'function') {
|
|
|
|
|
clearEnemyMarkers();
|
|
|
|
|
console.log('All enemy markers cleared from map');
|
|
|
|
|
}
|
|
|
|
|
)";
|
|
|
|
|
|
|
|
|
|
// 查找地图WebEngineView并执行JavaScript
|
|
|
|
|
QList<QWebEngineView*> webViews = this->findChildren<QWebEngineView*>();
|
|
|
|
|
for (auto webView : webViews) {
|
|
|
|
|
if (webView->isVisible()) {
|
|
|
|
|
webView->page()->runJavaScript(jsCode, [this](const QVariant &result) {
|
|
|
|
|
SystemLogger::getInstance()->logInfo("敌情标记已从地图上清除");
|
|
|
|
|
});
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m_enemyDisplayVisible = false;
|
|
|
|
|
} else {
|
|
|
|
|
// 当前隐藏敌情,需要显示
|
|
|
|
|
qDebug() << "Displaying enemies on map...";
|
|
|
|
|
SystemLogger::getInstance()->logInfo("在地图上显示敌情");
|
|
|
|
|
|
|
|
|
|
// 从数据库获取所有敌情数据
|
|
|
|
|
EnemyDatabase* enemyDB = EnemyDatabase::getInstance();
|
|
|
|
|
if (!enemyDB->initializeDatabase()) {
|
|
|
|
|
SystemLogger::getInstance()->logError("敌情数据库连接失败");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 模拟在地图上显示敌人位置的JavaScript代码
|
|
|
|
|
QString jsCode = R"(
|
|
|
|
|
// 清除现有的敌人标记
|
|
|
|
|
if (typeof clearEnemyMarkers === 'function') {
|
|
|
|
|
clearEnemyMarkers();
|
|
|
|
|
QList<EnemyRecord> enemyRecords = enemyDB->getAllEnemyRecords();
|
|
|
|
|
|
|
|
|
|
if (enemyRecords.isEmpty()) {
|
|
|
|
|
SystemLogger::getInstance()->logInfo("数据库中没有敌情数据");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 添加敌人标记
|
|
|
|
|
var enemies = [
|
|
|
|
|
{id: 'ENEMY001', lat: 39.9042, lng: 116.4074, threat: '高', type: '装甲车'},
|
|
|
|
|
{id: 'ENEMY002', lat: 39.9139, lng: 116.3912, threat: '中', type: '步兵'},
|
|
|
|
|
{id: 'ENEMY003', lat: 39.8876, lng: 116.4231, threat: '低', type: '侦察兵'},
|
|
|
|
|
{id: 'ENEMY004', lat: 39.9254, lng: 116.3845, threat: '高', type: '坦克'}
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
enemies.forEach(function(enemy) {
|
|
|
|
|
var color = enemy.threat === '高' ? 'red' :
|
|
|
|
|
enemy.threat === '中' ? 'orange' : 'yellow';
|
|
|
|
|
if (typeof addEnemyMarker === 'function') {
|
|
|
|
|
addEnemyMarker(enemy.id, enemy.lat, enemy.lng, color, enemy.type, enemy.threat);
|
|
|
|
|
// 构建JavaScript代码来显示敌人位置
|
|
|
|
|
QString jsCode = R"(
|
|
|
|
|
// 清除现有的敌人标记
|
|
|
|
|
if (typeof clearEnemyMarkers === 'function') {
|
|
|
|
|
clearEnemyMarkers();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
console.log('Enemy markers displayed on map');
|
|
|
|
|
)";
|
|
|
|
|
|
|
|
|
|
// 查找地图WebEngineView并执行JavaScript
|
|
|
|
|
QList<QWebEngineView*> webViews = this->findChildren<QWebEngineView*>();
|
|
|
|
|
for (auto webView : webViews) {
|
|
|
|
|
if (webView->isVisible()) {
|
|
|
|
|
webView->page()->runJavaScript(jsCode, [this](const QVariant &result) {
|
|
|
|
|
SystemLogger::getInstance()->logInfo("敌情标记已在地图上显示");
|
|
|
|
|
QMessageBox::information(this, "敌情显示",
|
|
|
|
|
"敌情位置已在地图上标记显示!\n\n"
|
|
|
|
|
"🔴 红色:高威胁目标\n"
|
|
|
|
|
"🟠 橙色:中威胁目标\n"
|
|
|
|
|
"🟡 黄色:低威胁目标");
|
|
|
|
|
// 添加敌人标记
|
|
|
|
|
var enemies = [)";
|
|
|
|
|
|
|
|
|
|
// 将数据库中的敌情数据转换为JavaScript数组
|
|
|
|
|
QStringList enemyJsObjects;
|
|
|
|
|
qDebug() << "Converting enemy records to JavaScript (Final center: 113.045134, 28.264012):";
|
|
|
|
|
for (const EnemyRecord& record : enemyRecords) {
|
|
|
|
|
qDebug() << "Enemy:" << record.id << "Lat:" << record.latitude << "Lng:" << record.longitude << "Threat:" << record.threatLevel;
|
|
|
|
|
|
|
|
|
|
QString enemyJs = QString(
|
|
|
|
|
"{id: '%1', lat: %2, lng: %3, threat: '%4', status: '%5'}")
|
|
|
|
|
.arg(record.id)
|
|
|
|
|
.arg(record.latitude, 0, 'f', 6)
|
|
|
|
|
.arg(record.longitude, 0, 'f', 6)
|
|
|
|
|
.arg(record.threatLevel)
|
|
|
|
|
.arg(record.status);
|
|
|
|
|
enemyJsObjects.append(enemyJs);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
jsCode += enemyJsObjects.join(",\n ");
|
|
|
|
|
jsCode += R"(
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
enemies.forEach(function(enemy) {
|
|
|
|
|
var color = enemy.threat === '高' ? '#ff3838' :
|
|
|
|
|
enemy.threat === '中' ? '#ffa502' : '#00a8ff';
|
|
|
|
|
if (typeof addEnemyMarker === 'function') {
|
|
|
|
|
addEnemyMarker(enemy.id, enemy.lat, enemy.lng, color, enemy.status, enemy.threat);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
console.log('从数据库加载了 ' + enemies.length + ' 个敌人标记');
|
|
|
|
|
)";
|
|
|
|
|
|
|
|
|
|
qDebug() << "Generated JavaScript code for" << enemyRecords.size() << "enemies";
|
|
|
|
|
|
|
|
|
|
// 查找地图WebEngineView并执行JavaScript
|
|
|
|
|
QList<QWebEngineView*> webViews = this->findChildren<QWebEngineView*>();
|
|
|
|
|
bool mapFound = false;
|
|
|
|
|
|
|
|
|
|
for (auto webView : webViews) {
|
|
|
|
|
if (webView->isVisible()) {
|
|
|
|
|
mapFound = true;
|
|
|
|
|
webView->page()->runJavaScript(jsCode, [this, enemyRecords](const QVariant &result) {
|
|
|
|
|
SystemLogger::getInstance()->logInfo(QString("敌情标记已在地图上显示:%1个目标").arg(enemyRecords.size()));
|
|
|
|
|
});
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!mapFound) {
|
|
|
|
|
SystemLogger::getInstance()->logError("未找到地图显示组件");
|
|
|
|
|
} else {
|
|
|
|
|
m_enemyDisplayVisible = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|