You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
303 lines
7.9 KiB
303 lines
7.9 KiB
#include "targetdata.h"
|
|
#include <QDebug>
|
|
#include <QDateTime>
|
|
|
|
/**
|
|
* 目标数据模型实现
|
|
* 负责管理单个目标的所有状态信息和操作
|
|
*/
|
|
|
|
TargetData::TargetData(const QString& id, TargetType type, QObject* parent)
|
|
: QObject(parent)
|
|
, id_(id)
|
|
, type_(type)
|
|
, status_(TargetStatus::Identified)
|
|
, priority_(5) // 默认中等优先级
|
|
, strikeMethod_(StrikeMethod::Surveillance) // 默认监视
|
|
, identifiedTime_(QDateTime::currentDateTime())
|
|
{
|
|
}
|
|
|
|
void TargetData::setType(TargetType type) {
|
|
if (type_ != type) {
|
|
type_ = type;
|
|
}
|
|
}
|
|
|
|
void TargetData::setStatus(TargetStatus status) {
|
|
if (status_ != status) {
|
|
status_ = status;
|
|
emit statusChanged(status_);
|
|
|
|
if (status == TargetStatus::Engaged) {
|
|
engagedTime_ = QDateTime::currentDateTime();
|
|
emit targetEngaged();
|
|
} else if (status == TargetStatus::Destroyed) {
|
|
emit targetDestroyed();
|
|
}
|
|
}
|
|
}
|
|
|
|
void TargetData::setDescription(const QString& description) {
|
|
description_ = description;
|
|
}
|
|
|
|
void TargetData::setName(const QString& name) {
|
|
name_ = name;
|
|
}
|
|
|
|
void TargetData::setPriority(int priority) {
|
|
if (priority_ != priority && priority >= 1 && priority <= 10) {
|
|
priority_ = priority;
|
|
emit priorityChanged(priority_);
|
|
}
|
|
}
|
|
|
|
void TargetData::setStrikeMethod(StrikeMethod method) {
|
|
if (strikeMethod_ != method) {
|
|
strikeMethod_ = method;
|
|
emit strikeMethodChanged(strikeMethod_);
|
|
}
|
|
}
|
|
|
|
void TargetData::setPosition(const QVector3D& position) {
|
|
position_ = position;
|
|
}
|
|
|
|
void TargetData::setLocation(const QString& location) {
|
|
location_ = location;
|
|
}
|
|
|
|
void TargetData::confirmTarget() {
|
|
setStatus(TargetStatus::Confirmed);
|
|
}
|
|
|
|
void TargetData::engageTarget() {
|
|
setStatus(TargetStatus::Engaged);
|
|
}
|
|
|
|
void TargetData::destroyTarget() {
|
|
setStatus(TargetStatus::Destroyed);
|
|
}
|
|
|
|
void TargetData::escapeTarget() {
|
|
setStatus(TargetStatus::Escaped);
|
|
}
|
|
|
|
void TargetData::cancelTarget() {
|
|
setStatus(TargetStatus::Cancelled);
|
|
}
|
|
|
|
QString TargetData::getTypeString() const {
|
|
switch (type_) {
|
|
case TargetType::Personnel: return "人员";
|
|
case TargetType::Vehicle: return "车辆";
|
|
case TargetType::Building: return "建筑";
|
|
case TargetType::Equipment: return "设备";
|
|
case TargetType::Infrastructure: return "基础设施";
|
|
case TargetType::Other: return "其他";
|
|
default: return "未知类型";
|
|
}
|
|
}
|
|
|
|
QString TargetData::getStatusString() const {
|
|
switch (status_) {
|
|
case TargetStatus::Identified: return "已识别";
|
|
case TargetStatus::Confirmed: return "已确认";
|
|
case TargetStatus::Engaged: return "已交战";
|
|
case TargetStatus::Destroyed: return "已摧毁";
|
|
case TargetStatus::Escaped: return "已逃脱";
|
|
case TargetStatus::Cancelled: return "已取消";
|
|
default: return "未知状态";
|
|
}
|
|
}
|
|
|
|
QString TargetData::getStrikeMethodString() const {
|
|
switch (strikeMethod_) {
|
|
case StrikeMethod::Missile: return "导弹";
|
|
case StrikeMethod::LaserGuided: return "激光引导";
|
|
case StrikeMethod::Surveillance: return "监视";
|
|
case StrikeMethod::Precision: return "精确打击";
|
|
case StrikeMethod::Area: return "区域打击";
|
|
case StrikeMethod::NonLethal: return "非致命打击";
|
|
default: return "未知方式";
|
|
}
|
|
}
|
|
|
|
QString TargetData::getPriorityString() const {
|
|
if (priority_ <= 3) return "高优先级";
|
|
if (priority_ <= 6) return "中优先级";
|
|
return "低优先级";
|
|
}
|
|
|
|
/**
|
|
* 目标管理器实现
|
|
* 负责管理多个目标的生命周期和状态
|
|
*/
|
|
|
|
TargetManager::TargetManager(QObject* parent)
|
|
: QObject(parent)
|
|
{
|
|
}
|
|
|
|
TargetManager::~TargetManager() {
|
|
qDeleteAll(targets_);
|
|
}
|
|
|
|
QString TargetManager::generateTargetId() {
|
|
return QString("TARGET_%1").arg(QDateTime::currentDateTime().toString("yyyyMMdd_hhmmss_zzz"));
|
|
}
|
|
|
|
TargetData* TargetManager::createTarget(TargetType type, const QString& name, const QString& description) {
|
|
QString targetId = generateTargetId();
|
|
|
|
auto* target = new TargetData(targetId, type, this);
|
|
target->setName(name);
|
|
target->setDescription(description);
|
|
|
|
targets_.append(target);
|
|
|
|
// 连接信号
|
|
connect(target, &TargetData::statusChanged, this, [this, targetId](TargetStatus status) {
|
|
emit targetStatusChanged(targetId, status);
|
|
});
|
|
|
|
connect(target, &TargetData::priorityChanged, this, [this, targetId](int priority) {
|
|
emit targetPriorityChanged(targetId, priority);
|
|
});
|
|
|
|
connect(target, &TargetData::strikeMethodChanged, this, [this, targetId](StrikeMethod method) {
|
|
emit targetStrikeMethodChanged(targetId, method);
|
|
});
|
|
|
|
emit targetCreated(targetId);
|
|
return target;
|
|
}
|
|
|
|
void TargetManager::removeTarget(const QString& targetId) {
|
|
for (int i = 0; i < targets_.size(); ++i) {
|
|
if (targets_[i]->getId() == targetId) {
|
|
targets_[i]->deleteLater();
|
|
targets_.removeAt(i);
|
|
emit targetRemoved(targetId);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
TargetData* TargetManager::getTarget(const QString& targetId) const {
|
|
for (auto* target : targets_) {
|
|
if (target->getId() == targetId) {
|
|
return target;
|
|
}
|
|
}
|
|
return nullptr;
|
|
}
|
|
|
|
QVector<TargetData*> TargetManager::getAllTargets() const {
|
|
return targets_;
|
|
}
|
|
|
|
QVector<TargetData*> TargetManager::getTargetsByType(TargetType type) const {
|
|
QVector<TargetData*> result;
|
|
for (auto* target : targets_) {
|
|
if (target->getType() == type) {
|
|
result.append(target);
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
|
|
QVector<TargetData*> TargetManager::getTargetsByStatus(TargetStatus status) const {
|
|
QVector<TargetData*> result;
|
|
for (auto* target : targets_) {
|
|
if (target->getStatus() == status) {
|
|
result.append(target);
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
|
|
QVector<TargetData*> TargetManager::getTargetsByPriority(int priority) const {
|
|
QVector<TargetData*> result;
|
|
for (auto* target : targets_) {
|
|
if (target->getPriority() == priority) {
|
|
result.append(target);
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
|
|
QVector<TargetData*> TargetManager::getTargetsSortedByPriority() const {
|
|
QVector<TargetData*> result = targets_;
|
|
std::sort(result.begin(), result.end(), [](TargetData* a, TargetData* b) {
|
|
return a->getPriority() < b->getPriority(); // 数字小的优先级高
|
|
});
|
|
return result;
|
|
}
|
|
|
|
QVector<TargetData*> TargetManager::getHighPriorityTargets(int threshold) const {
|
|
QVector<TargetData*> result;
|
|
for (auto* target : targets_) {
|
|
if (target->getPriority() <= threshold) {
|
|
result.append(target);
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
|
|
int TargetManager::getTargetCount() const {
|
|
return targets_.size();
|
|
}
|
|
|
|
int TargetManager::getTargetCountByType(TargetType type) const {
|
|
int count = 0;
|
|
for (auto* target : targets_) {
|
|
if (target->getType() == type) {
|
|
count++;
|
|
}
|
|
}
|
|
return count;
|
|
}
|
|
|
|
int TargetManager::getTargetCountByStatus(TargetStatus status) const {
|
|
int count = 0;
|
|
for (auto* target : targets_) {
|
|
if (target->getStatus() == status) {
|
|
count++;
|
|
}
|
|
}
|
|
return count;
|
|
}
|
|
|
|
int TargetManager::getTargetCountByPriority(int priority) const {
|
|
int count = 0;
|
|
for (auto* target : targets_) {
|
|
if (target->getPriority() == priority) {
|
|
count++;
|
|
}
|
|
}
|
|
return count;
|
|
}
|
|
|
|
void TargetManager::updateAllTargetsPriority(int newPriority) {
|
|
for (auto* target : targets_) {
|
|
target->setPriority(newPriority);
|
|
}
|
|
}
|
|
|
|
void TargetManager::updateTargetsByType(TargetType type, StrikeMethod method) {
|
|
for (auto* target : targets_) {
|
|
if (target->getType() == type) {
|
|
target->setStrikeMethod(method);
|
|
}
|
|
}
|
|
}
|
|
|
|
void TargetManager::clearAllTargets() {
|
|
qDeleteAll(targets_);
|
|
targets_.clear();
|
|
}
|
|
|
|
|