modify client2

pull/10/head
eazzy 9 months ago
parent 080537a240
commit 0ea74f76ee

@ -0,0 +1,196 @@
#include "DogDatabase.h"
DogDatabase *DogDatabase::getInstance()
{
static DogDatabase db;
return &db;
}
DogDatabase::~DogDatabase()
{
close();
}
DogDatabase::DogDatabase()
{
m_sqlDb = QSqlDatabase::addDatabase("QMYSQL");
}
//添加记录
bool DogDatabase::add(const Dog &data)
{
if(open("fly_land_database","root","684542"))
{
beginAddFiled("dogdatabase");
addFiled("id");
addFiled("state");
addFiled("ip");
addFiled("port");
addFiled("lon");
addFiled("lat");
endAddFiled();
beginAddRow();
addValue(data.id);
addValue(data.state);
addValue(data.ip);
addValue(data.port);
addValue(data.lon);
addValue(data.lat);
endAddRow();
m_valueSql = m_valueSql.left(m_valueSql.length()-1);
QString sql;
sql = m_headerSql + m_valueSql;
return exec(sql);
}
close();
}
//查询位置信息的记录
Point DogDatabase::ReturnUAVPosition(QString id)
{
if(open("fly_land_database","root","684542"))
{
QSqlQuery query(m_sqlDb);
QString strQuery;
strQuery = "SELECT lon, lat FROM ";
strQuery += "dogdatabase";
strQuery += " WHERE id = ";
strQuery += id;
qDebug()<<strQuery;
query.prepare(strQuery);
Point position;
bool isSuccess = query.exec();
if(isSuccess)
{
while(query.next())
{
double lon = query.value(0).toDouble();
double lat = query.value(1).toDouble();
position.lon = lon;
position.lat = lat;
}
}
return position;
}
close();
}
//返回状态信息
int DogDatabase::giveInfo(QString id)
{
if(open("fly_land_database","root","684542"))
{
QSqlQuery query(m_sqlDb);
QString strQuery;
strQuery = "SELECT state FROM ";
strQuery += "dogdatabase";
strQuery += " WHERE id = ";
strQuery += id;
qDebug()<<strQuery;
query.prepare(strQuery);
int state = -1;
bool isSuccess = query.exec();
if(isSuccess)
{
while(query.next())
{
state = query.value(0).toInt();
}
}
return state;
}
close();
}
//——————————————————私有方法————————————————————
//建立连接
bool DogDatabase::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;
}
}
void DogDatabase::close()
{
m_sqlDb.close();
}
void DogDatabase::beginAddFiled(const QString &tableName)
{
m_tableName = tableName;
m_fieldName.clear();
m_headerSql.clear();
m_valueSql.clear();
m_fieldAdd = 0;
}
void DogDatabase::addFiled(const QString &filedName)
{
m_fieldName.append(filedName);
}
void DogDatabase::endAddFiled()
{
m_headerSql = QString("INSERT INTO %0 (%1) values").arg(m_tableName).arg(m_fieldName.join(","));
}
void DogDatabase::beginAddRow()
{
m_valueSql += "(";
}
void DogDatabase::addValue(const QVariant &value)
{
m_valueSql += QString("\'%0\',").arg(value.toString());
m_fieldAdd++;
}
void DogDatabase::endAddRow()
{
m_valueSql = m_valueSql.left(m_valueSql.length() - 1);
m_valueSql += "),";
}
bool DogDatabase::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;
}

@ -0,0 +1,98 @@
#ifndef DOGDATABASE_H
#define DOGDATABASE_H
#include <QtSql>
#include <QWidget>
#include <QSqlQuery>
#include <QSqlDatabase>
#include <QString>
#include <QSqlRecord>
#include <QDebug>
#include "UAVDatabase.h"
using namespace std;
struct Dog
{
QString id;
int state;
QString ip;
int port;
double lon;
double lat;
};
class DogDatabase
{
// Q_OBJECT宏用于提供Qt信号槽和元对象系统服务
// 它必须限定为私有访问权限
//Q_OBJECT
public:
static DogDatabase *getInstance();
DogDatabase();
~DogDatabase();
Dog data;
//返回状态信息
int giveInfo(QString id);
//添加数据记录
bool add(const Dog &data);
//查询位置信息数据
Point ReturnUAVPosition( QString id);
private:
//打开
bool open(const QString &dbName,const QString &userName = QString(),const QString &passwd = QString());
//关闭
void close();
//开始添加字段
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 // DOGDATABASE_H

@ -1,5 +1,8 @@
#include "InjuryAnalysisUI.h"
#include "InjuryDatabase.h"
#include "ui_InjuryAnalysisUI.h"
#include <QMessageBox>
#include <QWidget>
InjuryAnalysisUI::InjuryAnalysisUI(QWidget* parent):
QWidget(parent),
@ -8,9 +11,106 @@ InjuryAnalysisUI::InjuryAnalysisUI(QWidget* parent):
ui->setupUi(this);
setWindowTitle("伤情态势分析界面");
resize(600,400);
InjuryDatabase injurydatabase;
QList<Injury> resultNow;
injurydatabase.select_all(resultNow);//获取所有伤员数据
result = resultNow;
//添加一个scrollArea来将信息显示出来
ui->scrollArea->setWidgetResizable(false);//可以拖动滚动条
//竖滚动条和横滚动条都可以一直显示
ui->scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
ui->scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
//设置主界面的实际界面
ui->scrollArea->setWidget(ui->scrollAreaWidgetContents);
ui->scrollAreaWidgetContents->setGeometry(0, 0, 381, result.length()*20);//实际界面参数
QLabel *label0=new QLabel(ui->scrollAreaWidgetContents);
label0->setText("伤员编号");
label0->move(0,0);
QLabel *label1=new QLabel(ui->scrollAreaWidgetContents);
label1->setText("伤情等级");
label1->move(100,0);
QLabel *label2=new QLabel(ui->scrollAreaWidgetContents);
label2->setText("位置精度");
label2->move(200,0);
QLabel *label3=new QLabel(ui->scrollAreaWidgetContents);
label3->setText("位置维度");
label3->move(300,0);
for(int i = 0; i<result.length(); i++)
{
QLabel *labelID=new QLabel(ui->scrollAreaWidgetContents);
labelID->setText(result[i].id);
labelID->move(0,15*(i+2));
QLabel *labelRank=new QLabel(ui->scrollAreaWidgetContents);
labelRank->setText(QString::number(result[i].rank));
labelRank->move(100,15*(i+2));
QLabel *labelLon=new QLabel(ui->scrollAreaWidgetContents);
labelLon->setText(QString::number(result[i].lon));
labelLon->move(200,15*(i+2));
QLabel *labelLat=new QLabel(ui->scrollAreaWidgetContents);
labelLat->setText(QString::number(result[i].lat));
labelLat->move(300,15*(i+2));
}
//对信息进行分类统计分析
int sum = result.length();
ui->sumLabel->setText(QString::number(sum));
int rank0Sum = 0;
int rank1Sum = 0;
int rank2Sum = 0;
for(int i = 0; i<sum; i++)
{
if(result[i].rank==0)
rank0Sum++;
else if(result[i].rank==1)
rank1Sum++;
else if(result[i].rank==2)
rank2Sum++;
}
ui->rank0Label->setText(QString::number(rank0Sum));
ui->rank1Label->setText(QString::number(rank1Sum));
ui->rank2Label->setText(QString::number(rank2Sum));
}
InjuryAnalysisUI::~InjuryAnalysisUI()
{
delete ui;
}
void InjuryAnalysisUI::on_searchButton_clicked()
{
QString userInput = ui->searchInput->text();
int searchIndex = -1;
if(!userInput.isEmpty())
{
for(int i = 0; i<result.length(); i++)
{
if(QString::compare(userInput,result[i].id)==0)
{
searchIndex = i;
break;
}
}
}
QString rank = QString::number(result[searchIndex].rank);
QString lon = QString::number(result[searchIndex].lon);
QString lat = QString::number(result[searchIndex].lat);
if(searchIndex==-1)
{
QMessageBox::warning(this, tr("查找"), tr("找不到id为 %1 的伤员!").arg(userInput));
}
else
{
QMessageBox::warning(this, tr("查找"), tr("伤员id%1 伤情等级:%2 位置经纬度:%3 %4 ").arg(userInput,rank,lon,lat));
}
}

@ -1,7 +1,7 @@
#ifndef INJURYANALYSISUI_H
#define INJURYANALYSISUI_H
#include "InjuryDatabase.h"
#include <QWidget>
QT_BEGIN_NAMESPACE
@ -19,11 +19,15 @@ class InjuryAnalysisUI : public QWidget
public:
InjuryAnalysisUI(QWidget *parent = nullptr);
~InjuryAnalysisUI();
QList<Injury> result;
private slots:
void on_searchButton_clicked();
private:
// 创建Ui::InjuryAnalysisUI类型的指针用于操作ui界面及其控件
Ui::InjuryAnalysisUI *ui;

@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
<width>600</width>
<height>400</height>
</rect>
</property>
<property name="windowTitle">
@ -16,14 +16,180 @@
<widget class="QLabel" name="label">
<property name="geometry">
<rect>
<x>140</x>
<y>50</y>
<x>10</x>
<y>10</y>
<width>91</width>
<height>51</height>
</rect>
</property>
<property name="text">
<string>目前伤亡情况:</string>
<string>伤情结果统计:</string>
</property>
</widget>
<widget class="QScrollArea" name="scrollArea">
<property name="geometry">
<rect>
<x>10</x>
<y>50</y>
<width>381</width>
<height>211</height>
</rect>
</property>
<property name="widgetResizable">
<bool>true</bool>
</property>
<widget class="QWidget" name="scrollAreaWidgetContents">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>379</width>
<height>209</height>
</rect>
</property>
</widget>
</widget>
<widget class="QLabel" name="label_2">
<property name="geometry">
<rect>
<x>410</x>
<y>50</y>
<width>101</width>
<height>21</height>
</rect>
</property>
<property name="text">
<string>伤员总数:</string>
</property>
</widget>
<widget class="QLabel" name="label_3">
<property name="geometry">
<rect>
<x>410</x>
<y>80</y>
<width>101</width>
<height>20</height>
</rect>
</property>
<property name="text">
<string>伤情轻微的伤员数:</string>
</property>
</widget>
<widget class="QLabel" name="label_4">
<property name="geometry">
<rect>
<x>410</x>
<y>110</y>
<width>101</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string>伤情一般的伤员数:</string>
</property>
</widget>
<widget class="QLabel" name="label_5">
<property name="geometry">
<rect>
<x>410</x>
<y>140</y>
<width>101</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string>伤情严重的伤员数:</string>
</property>
</widget>
<widget class="QLabel" name="label_6">
<property name="geometry">
<rect>
<x>20</x>
<y>280</y>
<width>131</width>
<height>21</height>
</rect>
</property>
<property name="text">
<string>输入伤员编号查询伤员信息</string>
</property>
</widget>
<widget class="QLineEdit" name="searchInput">
<property name="geometry">
<rect>
<x>160</x>
<y>280</y>
<width>71</width>
<height>21</height>
</rect>
</property>
<property name="text">
<string/>
</property>
</widget>
<widget class="QPushButton" name="searchButton">
<property name="geometry">
<rect>
<x>250</x>
<y>280</y>
<width>51</width>
<height>21</height>
</rect>
</property>
<property name="text">
<string>查询</string>
</property>
</widget>
<widget class="QLabel" name="sumLabel">
<property name="geometry">
<rect>
<x>520</x>
<y>55</y>
<width>41</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string>TextLabel</string>
</property>
</widget>
<widget class="QLabel" name="rank0Label">
<property name="geometry">
<rect>
<x>520</x>
<y>85</y>
<width>40</width>
<height>12</height>
</rect>
</property>
<property name="text">
<string>TextLabel</string>
</property>
</widget>
<widget class="QLabel" name="rank1Label">
<property name="geometry">
<rect>
<x>520</x>
<y>115</y>
<width>40</width>
<height>12</height>
</rect>
</property>
<property name="text">
<string>TextLabel</string>
</property>
</widget>
<widget class="QLabel" name="rank2Label">
<property name="geometry">
<rect>
<x>520</x>
<y>145</y>
<width>40</width>
<height>12</height>
</rect>
</property>
<property name="text">
<string>TextLabel</string>
</property>
</widget>
</widget>

@ -11,41 +11,29 @@ InjuryDatabase::~InjuryDatabase()
close();
}
//建立连接
bool InjuryDatabase::open(const QString &dbName,const QString &userName,const QString &passwd)
InjuryDatabase::InjuryDatabase()
{
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;
}
m_sqlDb = QSqlDatabase::addDatabase("QMYSQL");
}
//添加记录
bool InjuryDatabase::add(const QString &tableName, const Injury &data)
bool InjuryDatabase::add(const Injury &data)
{
beginAddFiled(tableName);
if(open("fly_land_database","root","684542"))
{
beginAddFiled("injurydatabase");
addFiled("id");
addFiled("injuryrank");
addFiled("position");
addFiled("lon");
addFiled("lat");
addFiled("flag");
endAddFiled();
beginAddRow();
addValue(data.id);
addValue(data.rank);
addValue(data.position);
addValue(data.lon);
addValue(data.lat);
addValue(data.flag);
endAddRow();
@ -53,18 +41,22 @@ bool InjuryDatabase::add(const QString &tableName, const Injury &data)
QString sql;
sql = m_headerSql + m_valueSql;
return exec(sql);
}
close();
}
//查询所有记录
bool InjuryDatabase::select(const QString &tableName, QList<Injury> &result)
bool InjuryDatabase::select_all(QList<Injury> &result)
{
if(open("fly_land_database","root","684542"))
{
QSqlQuery query(m_sqlDb);
QString strQuery;
strQuery = "SELECT * FROM ";
strQuery += tableName;
strQuery += "injurydatabase";
query.prepare(strQuery);
@ -75,22 +67,97 @@ bool InjuryDatabase::select(const QString &tableName, QList<Injury> &result)
{
QString id = query.value(0).toString();
int rank = query.value(1).toInt();
QString position = query.value(2).toString();
int flag = query.value(3).toInt();
double lon = query.value(2).toDouble();
double lat = query.value(3).toDouble();
int flag = query.value(4).toInt();
Injury data;
data.id = id;
data.rank = rank;
data.position = position;
data.lon = lon;
data.lat = lat;
data.flag = flag;
result.append(data);
}
}
return isSuccess;
}
close();
}
//返回有效伤员的信息
void InjuryDatabase::ReturnInfo(QList<Injury> result)
{
if(open("fly_land_database","root","684542"))
{
select_valid("injurydatabase", result);
for(int i = 0; i<result.length(); i++)
{
qDebug()<<result[i].id<<" "<<result[i].lon<< " "<<result[i].lat<<" "<<result[i].rank;
}
}
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::select_valid(const QString &tableName, QList<Injury> &result)
{
QSqlQuery query(m_sqlDb);
QString strQuery;
strQuery = "SELECT id, injuryrank, lon, lat FROM ";
strQuery += tableName;
strQuery += " WHERE flag = 1";
//qDebug()<<strQuery;//打印SQL语句检查错误
query.prepare(strQuery);
bool isSuccess = query.exec();
if(isSuccess)
{
while(query.next())
{
QString id = query.value(0).toString();
int rank = query.value(1).toInt();
double lon = query.value(2).toDouble();
double lat = query.value(3).toDouble();
Injury data;
data.id = id;
data.rank = rank;
data.lon = lon;
data.lat = lat;
result.append(data);
}
}
return isSuccess;
}
void InjuryDatabase::close()
{
@ -151,8 +218,3 @@ bool InjuryDatabase::exec(const QString &sql)
return isSuccess;
}
InjuryDatabase::InjuryDatabase()
{
m_sqlDb = QSqlDatabase::addDatabase("QMYSQL");
}

@ -17,7 +17,8 @@ struct Injury
{
QString id;
int rank;
QString position;
double lon;
double lat;
int flag;
};
@ -35,19 +36,20 @@ public:
//打开
bool open(const QString &dbName,const QString &userName = QString(),const QString &passwd = QString());
//添加数据记录
bool add(const QString &tableName,const Injury &data);
bool add(const Injury &data);
//查询所有数据
bool select(const QString &tableName,QList<Injury> &result);
//关闭
void close();
bool select_all(QList<Injury> &result);
public:
Injury data;
void ReturnInfo(Injury data);
//返回有效信息
void ReturnInfo(QList<Injury> data);
private:
//查询有效数据
bool select_valid(const QString &tableName,QList<Injury> &result);
//关闭
void close();
//开始添加字段
void beginAddFiled(const QString &tableName);

@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>600</width>
<height>370</height>
<height>400</height>
</rect>
</property>
<property name="windowTitle">

@ -0,0 +1,196 @@
#include "UAVDatabase.h"
UAVDatabase *UAVDatabase::getInstance()
{
static UAVDatabase db;
return &db;
}
UAVDatabase::~UAVDatabase()
{
close();
}
UAVDatabase::UAVDatabase()
{
m_sqlDb = QSqlDatabase::addDatabase("QMYSQL");
}
//添加记录
bool UAVDatabase::add(const UAV &data)
{
if(open("fly_land_database","root","684542"))
{
beginAddFiled("uavdatabase");
addFiled("id");
addFiled("state");
addFiled("ip");
addFiled("port");
addFiled("lon");
addFiled("lat");
endAddFiled();
beginAddRow();
addValue(data.id);
addValue(data.state);
addValue(data.ip);
addValue(data.port);
addValue(data.lon);
addValue(data.lat);
endAddRow();
m_valueSql = m_valueSql.left(m_valueSql.length()-1);
QString sql;
sql = m_headerSql + m_valueSql;
return exec(sql);
}
close();
}
//查询位置信息的记录
Point UAVDatabase::ReturnUAVPosition(QString id)
{
if(open("fly_land_database","root","684542"))
{
QSqlQuery query(m_sqlDb);
QString strQuery;
strQuery = "SELECT lon, lat FROM ";
strQuery += "uavdatabase";
strQuery += " WHERE id = ";
strQuery += id;
qDebug()<<strQuery;
query.prepare(strQuery);
Point position;
bool isSuccess = query.exec();
if(isSuccess)
{
while(query.next())
{
double lon = query.value(0).toDouble();
double lat = query.value(1).toDouble();
position.lon = lon;
position.lat = lat;
}
}
return position;
}
close();
}
//返回状态信息
int UAVDatabase::giveInfo(QString id)
{
if(open("fly_land_database","root","684542"))
{
QSqlQuery query(m_sqlDb);
QString strQuery;
strQuery = "SELECT state FROM ";
strQuery += "uavdatabase";
strQuery += " WHERE id = ";
strQuery += id;
qDebug()<<strQuery;
query.prepare(strQuery);
int state = -1;
bool isSuccess = query.exec();
if(isSuccess)
{
while(query.next())
{
state = query.value(0).toInt();
}
}
return state;
}
close();
}
//——————————————————私有方法————————————————————
//建立连接
bool UAVDatabase::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;
}
}
void UAVDatabase::close()
{
m_sqlDb.close();
}
void UAVDatabase::beginAddFiled(const QString &tableName)
{
m_tableName = tableName;
m_fieldName.clear();
m_headerSql.clear();
m_valueSql.clear();
m_fieldAdd = 0;
}
void UAVDatabase::addFiled(const QString &filedName)
{
m_fieldName.append(filedName);
}
void UAVDatabase::endAddFiled()
{
m_headerSql = QString("INSERT INTO %0 (%1) values").arg(m_tableName).arg(m_fieldName.join(","));
}
void UAVDatabase::beginAddRow()
{
m_valueSql += "(";
}
void UAVDatabase::addValue(const QVariant &value)
{
m_valueSql += QString("\'%0\',").arg(value.toString());
m_fieldAdd++;
}
void UAVDatabase::endAddRow()
{
m_valueSql = m_valueSql.left(m_valueSql.length() - 1);
m_valueSql += "),";
}
bool UAVDatabase::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;
}

@ -0,0 +1,104 @@
#ifndef UAVDATABASE_H
#define UAVDATABASE_H
#include <QtSql>
#include <QWidget>
#include <QSqlQuery>
#include <QSqlDatabase>
#include <QString>
#include <QSqlRecord>
#include <QDebug>
using namespace std;
struct UAV
{
QString id;
int state;
QString ip;
int port;
double lon;
double lat;
};
//存储经纬度信息
struct Point
{
double lon;
double lat;
};
class UAVDatabase
{
// Q_OBJECT宏用于提供Qt信号槽和元对象系统服务
// 它必须限定为私有访问权限
//Q_OBJECT
public:
static UAVDatabase *getInstance();
UAVDatabase();
~UAVDatabase();
UAV data;
//返回状态信息
int giveInfo(QString id);
//添加数据记录
bool add(const UAV &data);
//查询位置信息数据
Point ReturnUAVPosition( QString id);
private:
//打开
bool open(const QString &dbName,const QString &userName = QString(),const QString &passwd = QString());
//关闭
void close();
//开始添加字段
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 // UAVDATABASE_H

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

@ -35,7 +35,9 @@ namespace {
#ifdef QT_MOC_HAS_STRINGDATA
struct qt_meta_stringdata_CLASSInjuryAnalysisUIENDCLASS_t {};
constexpr auto qt_meta_stringdata_CLASSInjuryAnalysisUIENDCLASS = QtMocHelpers::stringData(
"InjuryAnalysisUI"
"InjuryAnalysisUI",
"on_searchButton_clicked",
""
);
#else // !QT_MOC_HAS_STRINGDATA
#error "qtmochelpers.h not found or too old."
@ -48,13 +50,19 @@ Q_CONSTINIT static const uint qt_meta_data_CLASSInjuryAnalysisUIENDCLASS[] = {
12, // revision
0, // classname
0, 0, // classinfo
0, 0, // methods
1, 14, // methods
0, 0, // properties
0, 0, // enums/sets
0, 0, // constructors
0, // flags
0, // signalCount
// slots: name, argc, parameters, tag, flags, initial metatype offsets
1, 0, 20, 2, 0x08, 1 /* Private */,
// slots: parameters
QMetaType::Void,
0 // eod
};
@ -66,16 +74,23 @@ Q_CONSTINIT const QMetaObject InjuryAnalysisUI::staticMetaObject = { {
nullptr,
qt_incomplete_metaTypeArray<qt_meta_stringdata_CLASSInjuryAnalysisUIENDCLASS_t,
// Q_OBJECT / Q_GADGET
QtPrivate::TypeAndForceComplete<InjuryAnalysisUI, std::true_type>
QtPrivate::TypeAndForceComplete<InjuryAnalysisUI, std::true_type>,
// method 'on_searchButton_clicked'
QtPrivate::TypeAndForceComplete<void, std::false_type>
>,
nullptr
} };
void InjuryAnalysisUI::qt_static_metacall(QObject *_o, QMetaObject::Call _c, int _id, void **_a)
{
(void)_o;
(void)_id;
(void)_c;
if (_c == QMetaObject::InvokeMetaMethod) {
auto *_t = static_cast<InjuryAnalysisUI *>(_o);
(void)_t;
switch (_id) {
case 0: _t->on_searchButton_clicked(); break;
default: ;
}
}
(void)_a;
}
@ -95,6 +110,17 @@ void *InjuryAnalysisUI::qt_metacast(const char *_clname)
int InjuryAnalysisUI::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
_id = QWidget::qt_metacall(_c, _id, _a);
if (_id < 0)
return _id;
if (_c == QMetaObject::InvokeMetaMethod) {
if (_id < 1)
qt_static_metacall(this, _c, _id, _a);
_id -= 1;
} else if (_c == QMetaObject::RegisterMethodArgumentMetaType) {
if (_id < 1)
*reinterpret_cast<QMetaType *>(_a[0]) = QMetaType();
_id -= 1;
}
return _id;
}
QT_WARNING_POP

@ -1,10 +1,12 @@
debug/CommunicationUI.o
debug/DogControlUI.o
debug/DogDatabase.o
debug/GuidingUI.o
debug/InjuryAnalysisUI.o
debug/InjuryDatabase.o
debug/InjuryDisplayUI.o
debug/UAVControlUI.o
debug/UAVDatabase.o
debug/main.o
debug/qrc_Resource.o
debug/moc_CommunicationUI.o

@ -1,10 +1,12 @@
release/CommunicationUI.o
release/DogControlUI.o
release/DogDatabase.o
release/GuidingUI.o
release/InjuryAnalysisUI.o
release/InjuryDatabase.o
release/InjuryDisplayUI.o
release/UAVControlUI.o
release/UAVDatabase.o
release/main.o
release/qrc_Resource.o
release/moc_CommunicationUI.o

@ -12,6 +12,9 @@
#include <QtCore/QVariant>
#include <QtWidgets/QApplication>
#include <QtWidgets/QLabel>
#include <QtWidgets/QLineEdit>
#include <QtWidgets/QPushButton>
#include <QtWidgets/QScrollArea>
#include <QtWidgets/QWidget>
QT_BEGIN_NAMESPACE
@ -20,15 +23,69 @@ class Ui_InjuryAnalysisUI
{
public:
QLabel *label;
QScrollArea *scrollArea;
QWidget *scrollAreaWidgetContents;
QLabel *label_2;
QLabel *label_3;
QLabel *label_4;
QLabel *label_5;
QLabel *label_6;
QLineEdit *searchInput;
QPushButton *searchButton;
QLabel *sumLabel;
QLabel *rank0Label;
QLabel *rank1Label;
QLabel *rank2Label;
void setupUi(QWidget *InjuryAnalysisUI)
{
if (InjuryAnalysisUI->objectName().isEmpty())
InjuryAnalysisUI->setObjectName("InjuryAnalysisUI");
InjuryAnalysisUI->resize(400, 300);
InjuryAnalysisUI->resize(600, 400);
label = new QLabel(InjuryAnalysisUI);
label->setObjectName("label");
label->setGeometry(QRect(140, 50, 91, 51));
label->setGeometry(QRect(10, 10, 91, 51));
scrollArea = new QScrollArea(InjuryAnalysisUI);
scrollArea->setObjectName("scrollArea");
scrollArea->setGeometry(QRect(10, 50, 381, 211));
scrollArea->setWidgetResizable(true);
scrollAreaWidgetContents = new QWidget();
scrollAreaWidgetContents->setObjectName("scrollAreaWidgetContents");
scrollAreaWidgetContents->setGeometry(QRect(0, 0, 379, 209));
scrollArea->setWidget(scrollAreaWidgetContents);
label_2 = new QLabel(InjuryAnalysisUI);
label_2->setObjectName("label_2");
label_2->setGeometry(QRect(410, 50, 101, 21));
label_3 = new QLabel(InjuryAnalysisUI);
label_3->setObjectName("label_3");
label_3->setGeometry(QRect(410, 80, 101, 20));
label_4 = new QLabel(InjuryAnalysisUI);
label_4->setObjectName("label_4");
label_4->setGeometry(QRect(410, 110, 101, 16));
label_5 = new QLabel(InjuryAnalysisUI);
label_5->setObjectName("label_5");
label_5->setGeometry(QRect(410, 140, 101, 16));
label_6 = new QLabel(InjuryAnalysisUI);
label_6->setObjectName("label_6");
label_6->setGeometry(QRect(20, 280, 131, 21));
searchInput = new QLineEdit(InjuryAnalysisUI);
searchInput->setObjectName("searchInput");
searchInput->setGeometry(QRect(160, 280, 71, 21));
searchButton = new QPushButton(InjuryAnalysisUI);
searchButton->setObjectName("searchButton");
searchButton->setGeometry(QRect(250, 280, 51, 21));
sumLabel = new QLabel(InjuryAnalysisUI);
sumLabel->setObjectName("sumLabel");
sumLabel->setGeometry(QRect(520, 55, 41, 16));
rank0Label = new QLabel(InjuryAnalysisUI);
rank0Label->setObjectName("rank0Label");
rank0Label->setGeometry(QRect(520, 85, 40, 12));
rank1Label = new QLabel(InjuryAnalysisUI);
rank1Label->setObjectName("rank1Label");
rank1Label->setGeometry(QRect(520, 115, 40, 12));
rank2Label = new QLabel(InjuryAnalysisUI);
rank2Label->setObjectName("rank2Label");
rank2Label->setGeometry(QRect(520, 145, 40, 12));
retranslateUi(InjuryAnalysisUI);
@ -38,7 +95,18 @@ public:
void retranslateUi(QWidget *InjuryAnalysisUI)
{
InjuryAnalysisUI->setWindowTitle(QCoreApplication::translate("InjuryAnalysisUI", "Form", nullptr));
label->setText(QCoreApplication::translate("InjuryAnalysisUI", "\347\233\256\345\211\215\344\274\244\344\272\241\346\203\205\345\206\265\357\274\232", nullptr));
label->setText(QCoreApplication::translate("InjuryAnalysisUI", "\344\274\244\346\203\205\347\273\223\346\236\234\347\273\237\350\256\241\357\274\232", nullptr));
label_2->setText(QCoreApplication::translate("InjuryAnalysisUI", "\344\274\244\345\221\230\346\200\273\346\225\260\357\274\232", nullptr));
label_3->setText(QCoreApplication::translate("InjuryAnalysisUI", "\344\274\244\346\203\205\350\275\273\345\276\256\347\232\204\344\274\244\345\221\230\346\225\260\357\274\232", nullptr));
label_4->setText(QCoreApplication::translate("InjuryAnalysisUI", "\344\274\244\346\203\205\344\270\200\350\210\254\347\232\204\344\274\244\345\221\230\346\225\260\357\274\232", nullptr));
label_5->setText(QCoreApplication::translate("InjuryAnalysisUI", "\344\274\244\346\203\205\344\270\245\351\207\215\347\232\204\344\274\244\345\221\230\346\225\260\357\274\232", nullptr));
label_6->setText(QCoreApplication::translate("InjuryAnalysisUI", "\350\276\223\345\205\245\344\274\244\345\221\230\347\274\226\345\217\267\346\237\245\350\257\242\344\274\244\345\221\230\344\277\241\346\201\257", nullptr));
searchInput->setText(QString());
searchButton->setText(QCoreApplication::translate("InjuryAnalysisUI", "\346\237\245\350\257\242", nullptr));
sumLabel->setText(QCoreApplication::translate("InjuryAnalysisUI", "TextLabel", nullptr));
rank0Label->setText(QCoreApplication::translate("InjuryAnalysisUI", "TextLabel", nullptr));
rank1Label->setText(QCoreApplication::translate("InjuryAnalysisUI", "TextLabel", nullptr));
rank2Label->setText(QCoreApplication::translate("InjuryAnalysisUI", "TextLabel", nullptr));
} // retranslateUi
};

@ -29,7 +29,7 @@ public:
{
if (InjuryDisplayUI->objectName().isEmpty())
InjuryDisplayUI->setObjectName("InjuryDisplayUI");
InjuryDisplayUI->resize(600, 370);
InjuryDisplayUI->resize(600, 400);
InjuryAnaysis = new QPushButton(InjuryDisplayUI);
InjuryAnaysis->setObjectName("InjuryAnaysis");
InjuryAnaysis->setGeometry(QRect(510, 10, 81, 31));

@ -4,6 +4,7 @@ QT += multimedia
QT += multimediawidgets
QT += sql
win32: LIBS += -lAdvAPI32
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
@ -17,21 +18,25 @@ CONFIG += c++17
SOURCES += \
CommunicationUI.cpp \
DogControlUI.cpp \
DogDatabase.cpp \
GuidingUI.cpp \
InjuryAnalysisUI.cpp \
InjuryDatabase.cpp \
InjuryDisplayUI.cpp \
UAVControlUI.cpp \
UAVDatabase.cpp \
main.cpp
HEADERS += \
CommunicationUI.h \
DogControlUI.h \
DogDatabase.h \
GuidingUI.h \
InjuryAnalysisUI.h \
InjuryDatabase.h \
InjuryDisplayUI.h \
UAVControlUI.h
UAVControlUI.h \
UAVDatabase.h
FORMS += \
CommunicationUI.ui \

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 13.0.0, 2024-05-10T09:33:09. -->
<!-- Written by QtCreator 13.0.0, 2024-05-17T08:47:56. -->
<qtcreator>
<data>
<variable>EnvironmentId</variable>

@ -1,5 +1,7 @@
#include "GuidingUI.h"
#include "InjuryDatabase.h"
#include "UAVDatabase.h"
#include "DogDatabase.h"
#include <QLabel>
#include <QApplication>
#include <QLineEdit>
@ -9,9 +11,10 @@
#include <QWidget>
#include <QDebug>
#include <QPluginLoader>
#include <QSql>
#include <QtSql>
#include <QSqlDatabase>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
@ -19,44 +22,40 @@ int main(int argc, char *argv[])
w.setWindowTitle("GuidingUI");
w.show();
// QSqlDatabase db=QSqlDatabase::addDatabase("QMYSQL");
// db.setHostName("localhost"); // 本地数据库 远程DB是ipaddress
// db.setPort(3306); // 设置端口号
// db.setDatabaseName("fly_land_database"); // 使用的数据库 sql = use '数据库名'
// db.setUserName("root");
// db.setPassword("684542");
// if(db.open()){
// qDebug()<<"成功";
// }else{
// qDebug()<<"失败";
// qDebug()<<"InjuryDatabase";
// InjuryDatabase injuryDatabase;
// QList<Injury> result;
// injuryDatabase.ReturnInfo(result);
// for(int i = 0; i<result.length(); i++)
// {
// qDebug()<<result[i].lon<<" " << result[i].lat << " " << result[i].id;
// }
InjuryDatabase injuryDatabase;
if(injuryDatabase.open("fly_land_database","root","684542"))
{
QList<Injury> result;
injuryDatabase.select("injurydatabase", result);
for(int i = 0; i<result.length(); i++)
{
qDebug()<<result[i].id<<" "<<result[i].position<<" "<<result[i].rank;
}
injuryDatabase.data.id = "0005";
injuryDatabase.data.position = "23,55";
injuryDatabase.data.flag = 1;
injuryDatabase.data.rank = 2;
if(injuryDatabase.add("injurydatabase",injuryDatabase.data))
{
result.clear();
injuryDatabase.select("injurydatabase", result);
qDebug()<<"添加成功!:\n";
for(int i = 0; i<result.length(); i++)
{
qDebug()<<result[i].id<<" "<<result[i].position<<" "<<result[i].rank;
}
}
}
injuryDatabase.close();
// qDebug()<<"UAVDatabase";
// UAVDatabase uavdatabase;
// Point uavposition = uavdatabase.ReturnUAVPosition("5");
// int uavstate = uavdatabase.giveInfo("5");
// qDebug()<<uavposition.lon << " " << uavposition.lat << ' ' << uavstate;
// qDebug()<<"DogDatabase";
// DogDatabase dogdatabase;
// Point dogposition = dogdatabase.ReturnUAVPosition("5");
// int dogstate = dogdatabase.giveInfo("5");
// qDebug()<<dogposition.lon << " " << dogposition.lat << ' ' << dogstate;
// Dog dog;
// dog.id = "11";
// dog.ip = "1.1.1.1";
// dog.port = 8080;
// dog.state = 55;
// dog.lon = 113.54;
// dog.lat = 30.33;
// dogdatabase.add(dog);
// Point dogposition1 = dogdatabase.ReturnUAVPosition("11");
// qDebug()<<dogposition1.lon << " " << dogposition1.lat;
return a.exec();

Loading…
Cancel
Save