同意合并数据库相关代码

pull/11/head
ple93m5su 7 months ago
commit 7850da49de

@ -0,0 +1,34 @@
#include "CommunicationUI.h"
#include "ui_CommunicationUI.h"
#include <QMediaPlayer>
#include <QVideoWidget>
CommunicationUI::CommunicationUI(QWidget* parent):
QWidget(parent),
ui(new Ui::CommunicationUI)
{
ui->setupUi(this);
setWindowTitle("远程交互救助服务");
resize(600,400);
// 创建视频播放器
QMediaPlayer* player = new QMediaPlayer(this);
// 创建视频播放窗口
QVideoWidget* videoWidget = new QVideoWidget(this);
videoWidget->setGeometry(50, 50, 500, 300); // 设置视频播放窗口的位置和大小
// 设置视频播放器的输出窗口
player->setVideoOutput(videoWidget);
// 加载视频文件
player->setSource(QUrl::fromLocalFile("C:\\Users\\86185\\Desktop\\WeChat_20240428194941.mp4"));
// 播放视频
player->play();
}
CommunicationUI::~CommunicationUI()
{
delete ui;
}

@ -0,0 +1,30 @@
#ifndef COMMUNICATIONUI_H
#define COMMUNICATIONUI_H
#include <QWidget>
QT_BEGIN_NAMESPACE //qt的命名空间
namespace Ui {
class CommunicationUI; //声明ui命名空间下的类
}
QT_END_NAMESPACE
class CommunicationUI : public QWidget
{
// Q_OBJECT宏用于提供Qt信号槽和元对象系统服务
// 它必须限定为私有访问权限
Q_OBJECT
public:
CommunicationUI(QWidget *parent = nullptr);
~CommunicationUI();
private slots:
private:
// 创建Ui::CommunicationUI类型的指针用于操作ui界面及其控件
Ui::CommunicationUI *ui;
};
#endif // COMMUNICATIONUI_H

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>CommunicationUI</class>
<widget class="QWidget" name="CommunicationUI">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
</widget>
<resources/>
<connections/>
</ui>

@ -0,0 +1,34 @@
#include "DogControlUI.h"
#include "ui_DogControlUI.h"
#include <QMediaPlayer>
#include <QVideoWidget>
DogControlUI::DogControlUI(QWidget* parent):
QWidget(parent),
ui(new Ui::DogControlUI)
{
ui->setupUi(this);
setWindowTitle("控制机器狗");
resize(600,400);
// 创建视频播放器
QMediaPlayer* player = new QMediaPlayer(this);
// 创建视频播放窗口
QVideoWidget* videoWidget = new QVideoWidget(this);
videoWidget->setGeometry(50, 50, 500, 300); // 设置视频播放窗口的位置和大小
// 设置视频播放器的输出窗口
player->setVideoOutput(videoWidget);
// 加载视频文件
player->setSource(QUrl::fromLocalFile("C:\\Users\\86185\\Desktop\\WeChat_20240428194941.mp4"));
// 播放视频
player->play();
}
DogControlUI::~DogControlUI()
{
delete ui;
}

@ -0,0 +1,32 @@
#ifndef DOGCONTROLUI_H
#define DOGCONTROLUI_H
#include <QWidget>
QT_BEGIN_NAMESPACE //qt的命名空间
namespace Ui {
class DogControlUI; //声明ui命名空间下的类
}
QT_END_NAMESPACE
class DogControlUI : public QWidget
{
// Q_OBJECT宏用于提供Qt信号槽和元对象系统服务
// 它必须限定为私有访问权限
Q_OBJECT
public:
DogControlUI(QWidget *parent = nullptr);
~DogControlUI();
private slots:
private:
// 创建Ui::DogControlUI类型的指针用于操作ui界面及其控件
Ui::DogControlUI *ui;
};
#endif // DOGCONTROLUI_H

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>DogControlUI</class>
<widget class="QWidget" name="DogControlUI">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
</widget>
<resources/>
<connections/>
</ui>

@ -0,0 +1,56 @@
#include "GuidingUI.h"
#include "ui_GuidingUI.h"
#include <DogControlUI.h>
#include <UAVControlUI.h>
#include <CommunicationUI.h>
#include <InjuryDisplayUI.h>
#include <QMessageBox>
GuidingUI::GuidingUI(QWidget *parent)
: QWidget(parent)
, ui(new Ui::GuidingUI)
{
ui->setupUi(this);
setWindowTitle("空地协同伤情态势感知分析系统");
resize(600,400);
}
GuidingUI::~GuidingUI()
{
delete ui;
}
void GuidingUI::on_Communication_clicked()
{
//QMessageBox::information(this,"远程交互界面","视频 语音");
CommunicationUI* communication = new CommunicationUI;
communication->show();
}
void GuidingUI::on_ControlDog_clicked()
{
//QMessageBox::information(this,"控制机器狗","输入正确的指令");
DogControlUI* dogUI = new DogControlUI;
dogUI->show();
}
void GuidingUI::on_ControlUAV_clicked()
{
//QMessageBox::information(this,"控制无人机","输入正确的指令");
UAVControlUI* uavUI = new UAVControlUI;
uavUI->show();
}
void GuidingUI::on_InjuryDisplay_clicked()
{
//QMessageBox::information(this,"伤情总览","呈现伤情");
InjuryDisplayUI* injuryDisplay = new InjuryDisplayUI;
injuryDisplay->show();
}

@ -0,0 +1,34 @@
#ifndef GUIDINGUI_H
#define GUIDINGUI_H
#include <QWidget>
QT_BEGIN_NAMESPACE //qt的命名空间
namespace Ui {
class GuidingUI; //声明ui命名空间下的类
}
QT_END_NAMESPACE
class GuidingUI : public QWidget
{
// Q_OBJECT宏用于提供Qt信号槽和元对象系统服务
// 它必须限定为私有访问权限
Q_OBJECT
public:
GuidingUI(QWidget *parent = nullptr);
~GuidingUI();
private slots:
void on_Communication_clicked();
void on_ControlDog_clicked();
void on_ControlUAV_clicked();
void on_InjuryDisplay_clicked();
private:
// 创建Ui::GuidingUI类型的指针用于操作ui界面及其控件
Ui::GuidingUI *ui;
};
#endif // GUIDINGUI_H

@ -0,0 +1,92 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>GuidingUI</class>
<widget class="QWidget" name="GuidingUI">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>609</width>
<height>450</height>
</rect>
</property>
<property name="windowTitle">
<string>Widget</string>
</property>
<widget class="QWidget" name="layoutWidget">
<property name="geometry">
<rect>
<x>150</x>
<y>30</y>
<width>301</width>
<height>361</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<property name="rightMargin">
<number>0</number>
</property>
<item>
<widget class="QPushButton" name="Communication">
<property name="text">
<string>远程交互救助</string>
</property>
<property name="iconSize">
<size>
<width>12</width>
<height>30</height>
</size>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="ControlUAV">
<property name="text">
<string>控制无人机</string>
</property>
<property name="iconSize">
<size>
<width>12</width>
<height>30</height>
</size>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="ControlDog">
<property name="text">
<string>控制机器狗</string>
</property>
<property name="iconSize">
<size>
<width>12</width>
<height>30</height>
</size>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="InjuryDisplay">
<property name="minimumSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="text">
<string>伤情态势显示</string>
</property>
<property name="iconSize">
<size>
<width>12</width>
<height>40</height>
</size>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
<resources/>
<connections/>
</ui>

@ -0,0 +1,16 @@
#include "InjuryAnalysisUI.h"
#include "ui_InjuryAnalysisUI.h"
InjuryAnalysisUI::InjuryAnalysisUI(QWidget* parent):
QWidget(parent),
ui(new Ui::InjuryAnalysisUI)
{
ui->setupUi(this);
setWindowTitle("伤情态势分析界面");
resize(600,400);
}
InjuryAnalysisUI::~InjuryAnalysisUI()
{
delete ui;
}

@ -0,0 +1,32 @@
#ifndef INJURYANALYSISUI_H
#define INJURYANALYSISUI_H
#include <QWidget>
QT_BEGIN_NAMESPACE
namespace Ui {
class InjuryAnalysisUI; //声明ui命名空间下的类
}
QT_END_NAMESPACE
class InjuryAnalysisUI : public QWidget
{
// Q_OBJECT宏用于提供Qt信号槽和元对象系统服务
// 它必须限定为私有访问权限
Q_OBJECT
public:
InjuryAnalysisUI(QWidget *parent = nullptr);
~InjuryAnalysisUI();
private slots:
private:
// 创建Ui::InjuryAnalysisUI类型的指针用于操作ui界面及其控件
Ui::InjuryAnalysisUI *ui;
};
#endif // INJURYANALYSISUI_H

@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>InjuryAnalysisUI</class>
<widget class="QWidget" name="InjuryAnalysisUI">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<widget class="QLabel" name="label">
<property name="geometry">
<rect>
<x>140</x>
<y>50</y>
<width>91</width>
<height>51</height>
</rect>
</property>
<property name="text">
<string>目前伤亡情况:</string>
</property>
</widget>
</widget>
<resources/>
<connections/>
</ui>

@ -0,0 +1,158 @@
#include "InjuryDatabase.h"
InjuryDatabase *InjuryDatabase::getInstance()
{
static InjuryDatabase db;
return &db;
}
InjuryDatabase::~InjuryDatabase()
{
close();
}
//建立连接
bool InjuryDatabase::open(const QString &dbName,const QString &userName,const QString &passwd)
{
m_sqlDb.setHostName("localhost"); // 本地数据库 远程DB是ipaddress
m_sqlDb.setPort(3306); // 设置端口号
m_sqlDb.setDatabaseName(dbName);
m_sqlDb.setUserName(userName);
m_sqlDb.setPassword(passwd);
if(!m_sqlDb.open())
{
qDebug()<<"连接失败!";
return false;
}
else
{
qDebug()<<"连接成功!";
return true;
}
}
//添加记录
bool InjuryDatabase::add(const QString &tableName, const Injury &data)
{
beginAddFiled(tableName);
addFiled("id");
addFiled("injuryrank");
addFiled("position");
addFiled("flag");
endAddFiled();
beginAddRow();
addValue(data.id);
addValue(data.rank);
addValue(data.position);
addValue(data.flag);
endAddRow();
m_valueSql = m_valueSql.left(m_valueSql.length()-1);
QString sql;
sql = m_headerSql + m_valueSql;
return exec(sql);
}
//查询所有记录
bool InjuryDatabase::select(const QString &tableName, QList<Injury> &result)
{
QSqlQuery query(m_sqlDb);
QString strQuery;
strQuery = "SELECT * FROM ";
strQuery += tableName;
query.prepare(strQuery);
bool isSuccess = query.exec();
if(isSuccess)
{
while(query.next())
{
QString id = query.value(0).toString();
int rank = query.value(1).toInt();
QString position = query.value(2).toString();
int flag = query.value(3).toInt();
Injury data;
data.id = id;
data.rank = rank;
data.position = position;
data.flag = flag;
result.append(data);
}
}
return isSuccess;
}
void InjuryDatabase::close()
{
m_sqlDb.close();
}
void InjuryDatabase::beginAddFiled(const QString &tableName)
{
m_tableName = tableName;
m_fieldName.clear();
m_headerSql.clear();
m_valueSql.clear();
m_fieldAdd = 0;
}
void InjuryDatabase::addFiled(const QString &filedName)
{
m_fieldName.append(filedName);
}
void InjuryDatabase::endAddFiled()
{
m_headerSql = QString("INSERT INTO %0 (%1) values").arg(m_tableName).arg(m_fieldName.join(","));
}
void InjuryDatabase::beginAddRow()
{
m_valueSql += "(";
}
void InjuryDatabase::addValue(const QVariant &value)
{
m_valueSql += QString("\'%0\',").arg(value.toString());
m_fieldAdd++;
}
void InjuryDatabase::endAddRow()
{
m_valueSql = m_valueSql.left(m_valueSql.length() - 1);
m_valueSql += "),";
}
bool InjuryDatabase::exec(const QString &sql)
{
bool isSuccess = false;
QSqlQuery query(m_sqlDb);
query.prepare(sql);
qDebug()<<sql;
isSuccess = query.exec();
if(!isSuccess)
qDebug() << "Error inserting data:" << query.lastError().text();
return isSuccess;
}
InjuryDatabase::InjuryDatabase()
{
m_sqlDb = QSqlDatabase::addDatabase("QMYSQL");
}

@ -0,0 +1,96 @@
#ifndef INJURYDATABASE_H
#define INJURYDATABASE_H
#include <QtSql>
#include <QWidget>
#include <QSqlQuery>
#include <QSqlDatabase>
#include <QString>
#include <QSqlRecord>
#include <QDebug>
using namespace std;
struct Injury
{
QString id;
int rank;
QString position;
int flag;
};
class InjuryDatabase
{
// Q_OBJECT宏用于提供Qt信号槽和元对象系统服务
// 它必须限定为私有访问权限
//Q_OBJECT
public:
static InjuryDatabase *getInstance();
InjuryDatabase();
~InjuryDatabase();
//打开
bool open(const QString &dbName,const QString &userName = QString(),const QString &passwd = QString());
//添加数据记录
bool add(const QString &tableName,const Injury &data);
//查询所有数据
bool select(const QString &tableName,QList<Injury> &result);
//关闭
void close();
public:
Injury data;
void ReturnInfo(Injury data);
private:
//开始添加字段
void beginAddFiled(const QString &tableName);
//添加字段
void addFiled(const QString &filedName);
//结束添加字段
void endAddFiled();
//开始添加行
void beginAddRow();
//添加字段值
void addValue(const QVariant &value);
//结束添加行
void endAddRow();
//执行
bool exec(const QString &sql);
private:
//数据库
QSqlDatabase m_sqlDb;
//表名
QString m_tableName;
//字段名
QStringList m_fieldName;
//头sql
QString m_headerSql;
//值sql
QString m_valueSql;
//已添加row数
int m_fieldAdd = 0;
};
#endif // INJURYDATABASE_H

@ -0,0 +1,35 @@
#include "InjuryDisplayUI.h"
#include "ui_InjuryDisplayUI.h"
#include "InjuryAnalysisUI.h"
#include <QQuickItem>
InjuryDisplayUI::InjuryDisplayUI(QWidget* parent):
QWidget(parent),
ui(new Ui::InjuryDisplayUI)
{
ui->setupUi(this);
setWindowTitle("伤情态势展示界面");
}
InjuryDisplayUI::~InjuryDisplayUI()
{
delete ui;
}
void InjuryDisplayUI::on_InjuryAnaysis_clicked()
{
InjuryAnalysisUI* injuryAnalysis = new InjuryAnalysisUI;
injuryAnalysis->show();
}
void InjuryDisplayUI::on_MapButton_clicked()
{
QQuickItem *root = ui->quickWidget->rootObject();//拿到所有对象的列表
auto labelqml = root->findChild<QObject*>("labelcpp");//名字要与main.qml中的 objectName: 'labelcpp' 相同
QVariant ret;
QMetaObject::invokeMethod(labelqml, "setCoordinate", Q_ARG(QVariant, 22.65599), Q_ARG(QVariant, 113.92576));
qDebug() << ret.toString();
}

@ -0,0 +1,34 @@
#ifndef INJURYDISPLAYUI_H
#define INJURYDISPLAYUI_H
#include <QWidget>
QT_BEGIN_NAMESPACE //qt的命名空间
namespace Ui {
class InjuryDisplayUI; //声明ui命名空间下的类
}
QT_END_NAMESPACE
class InjuryDisplayUI : public QWidget
{
// Q_OBJECT宏用于提供Qt信号槽和元对象系统服务
// 它必须限定为私有访问权限
Q_OBJECT
public:
InjuryDisplayUI(QWidget *parent = nullptr);
~InjuryDisplayUI();
private slots:
void on_InjuryAnaysis_clicked();
void on_MapButton_clicked();
private:
// 创建Ui::DogControlUI类型的指针用于操作ui界面及其控件
Ui::InjuryDisplayUI *ui;
};
#endif // INJURYDISPLAYUI_H

@ -0,0 +1,80 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>InjuryDisplayUI</class>
<widget class="QWidget" name="InjuryDisplayUI">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>600</width>
<height>370</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<widget class="QPushButton" name="InjuryAnaysis">
<property name="geometry">
<rect>
<x>510</x>
<y>10</y>
<width>81</width>
<height>31</height>
</rect>
</property>
<property name="text">
<string>分析当前伤情</string>
</property>
</widget>
<widget class="QPushButton" name="MapButton">
<property name="geometry">
<rect>
<x>210</x>
<y>330</y>
<width>161</width>
<height>31</height>
</rect>
</property>
<property name="text">
<string>打印经纬度</string>
</property>
</widget>
<widget class="QWidget" name="Widget" native="true">
<property name="geometry">
<rect>
<x>10</x>
<y>50</y>
<width>581</width>
<height>271</height>
</rect>
</property>
</widget>
<widget class="QQuickWidget" name="quickWidget">
<property name="geometry">
<rect>
<x>10</x>
<y>60</y>
<width>571</width>
<height>251</height>
</rect>
</property>
<property name="resizeMode">
<enum>QQuickWidget::SizeRootObjectToView</enum>
</property>
<property name="source">
<url>
<string>qrc:/map.qml</string>
</url>
</property>
</widget>
</widget>
<customwidgets>
<customwidget>
<class>QQuickWidget</class>
<extends>QWidget</extends>
<header location="global">QtQuickWidgets/QQuickWidget</header>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>

@ -0,0 +1,5 @@
<RCC>
<qresource prefix="/">
<file>map.qml</file>
</qresource>
</RCC>

@ -0,0 +1,35 @@
#include "UAVControlUI.h"
#include "ui_UAVControlUI.h"
#include <QMediaPlayer>
#include <QVideoWidget>
UAVControlUI::UAVControlUI(QWidget* parent):
QWidget(parent),
ui(new Ui::UAVControlUI)
{
ui->setupUi(this);
setWindowTitle("控制无人机");
resize(600,400);
// 创建视频播放器
QMediaPlayer* player = new QMediaPlayer(this);
// 创建视频播放窗口
QVideoWidget* videoWidget = new QVideoWidget(this);
videoWidget->setGeometry(50, 50, 500, 300); // 设置视频播放窗口的位置和大小
// 设置视频播放器的输出窗口
player->setVideoOutput(videoWidget);
// 加载视频文件
player->setSource(QUrl::fromLocalFile("C:\\Users\\86185\\Desktop\\WeChat_20240428194941.mp4"));
// 播放视频
player->play();
}
UAVControlUI::~UAVControlUI()
{
delete ui;
}

@ -0,0 +1,33 @@
#ifndef UAVCONTROLUI_H
#define UAVCONTROLUI_H
#include <QWidget>
QT_BEGIN_NAMESPACE //qt的命名空间
namespace Ui {
class UAVControlUI; //声明ui命名空间下的类
}
QT_END_NAMESPACE
class UAVControlUI : public QWidget
{
// Q_OBJECT宏用于提供Qt信号槽和元对象系统服务
// 它必须限定为私有访问权限
Q_OBJECT
public:
UAVControlUI(QWidget *parent = nullptr);
~UAVControlUI();
private slots:
private:
// 创建Ui::DogControlUI类型的指针用于操作ui界面及其控件
Ui::UAVControlUI *ui;
};
#endif // UAVCONTROLUI_H

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>UAVControlUI</class>
<widget class="QWidget" name="UAVControlUI">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
</widget>
<resources/>
<connections/>
</ui>

@ -0,0 +1,21 @@
QMAKE_CXX.QT_COMPILER_STDCXX = 201703L
QMAKE_CXX.QMAKE_GCC_MAJOR_VERSION = 11
QMAKE_CXX.QMAKE_GCC_MINOR_VERSION = 2
QMAKE_CXX.QMAKE_GCC_PATCH_VERSION = 0
QMAKE_CXX.COMPILER_MACROS = \
QT_COMPILER_STDCXX \
QMAKE_GCC_MAJOR_VERSION \
QMAKE_GCC_MINOR_VERSION \
QMAKE_GCC_PATCH_VERSION
QMAKE_CXX.INCDIRS = \
D:/Qt/Tools/mingw1120_64/lib/gcc/x86_64-w64-mingw32/11.2.0/include/c++ \
D:/Qt/Tools/mingw1120_64/lib/gcc/x86_64-w64-mingw32/11.2.0/include/c++/x86_64-w64-mingw32 \
D:/Qt/Tools/mingw1120_64/lib/gcc/x86_64-w64-mingw32/11.2.0/include/c++/backward \
D:/Qt/Tools/mingw1120_64/lib/gcc/x86_64-w64-mingw32/11.2.0/include \
D:/Qt/Tools/mingw1120_64/lib/gcc/x86_64-w64-mingw32/11.2.0/include-fixed \
D:/Qt/Tools/mingw1120_64/x86_64-w64-mingw32/include
QMAKE_CXX.LIBDIRS = \
D:/Qt/Tools/mingw1120_64/lib/gcc/x86_64-w64-mingw32/11.2.0 \
D:/Qt/Tools/mingw1120_64/lib/gcc \
D:/Qt/Tools/mingw1120_64/x86_64-w64-mingw32/lib \
D:/Qt/Tools/mingw1120_64/lib

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save