parent
080537a240
commit
0ea74f76ee
@ -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
|
@ -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
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in new issue