目录
MVC设计模式-界面数据分开处理
数据库查看:设置信息 视频信息 图片信息
8.SetControl.h .cpp
9.SetModel.h .cpp
10.VideoControl.h .cpp
11.VideoModel.h .cpp
12.ImageControl.h .cpp
13.ImageModel.h .cpp
#ifndef SETCONTROL_H
#define SETCONTROL_H
#include
#include "setmodel.h"//设置模型层
class SetControl
{
public:
static SetControl *getInstance();//外部公共接口--获取control对象
int doSet(QString Video_path,QString Image_path,int framecount,QString cameraName);//第一次设置参数存储到数据库
QString getSetting_videopath();//获取设置信息视频保存路径
QString getSetting_imagepath();//获取设置信息图片保存路径
int getSetting_interval();//获取设置信息视频间隔
int getSetting();//获取设置信息,用于判断是否有设置过
int updateSetting(QString Video_path, QString Image_path, int framecount, QString cameraName);//更新设置信息
private:
SetControl();//构造私有化
static SetControl *contorl;//静态私成员变量
};
#endif // SETCONTROL_H
#include "setcontrol.h"
SetControl *SetControl::contorl=nullptr;
SetControl::SetControl(){}
//外部公共接口 获取control对象
SetControl *SetControl::getInstance()
{
if(SetControl::contorl=nullptr)
{
SetControl::contorl=new SetControl();
}
return SetControl::contorl;
}
//第一次设置参数存储到数据库
int SetControl::doSet(QString Video_path,QString Image_path,int framecount,QString cameraName)
{
return SetModel::getInstance()->addSetting(Video_path,Image_path,framecount,cameraName);
}
//获取视频路径
QString SetControl::getSetting_videopath()
{
QString videopath;
SetModel::getInstance()->getSetting_videopath(videopath);
return videopath;
}
//获取设置信息图片路径
QString SetControl::getSetting_imagepath()
{
QString imagepath;
SetModel::getInstance()->getSetting_imagepath(imagepath);
return imagepath;
}
//获取视频录制时长
int SetControl::getSetting_interval()
{
return SetModel::getInstance()->getSetting_interval();
}
//获取设置信息,用于判断是否有设置过
int SetControl::getSetting()
{
return SetModel::getInstance()->getSetting();
}
//更新设置信息
int SetControl::updateSetting(QString Video_path, QString Image_path, int framecount, QString cameraName)
{
return SetModel::getInstance()->updateSetting(Video_path,Image_path,framecount,cameraName);
}
#ifndef SETMODEL_H
#define SETMODEL_H
#include "singeldb.h"//数据库
#include
#include //字符串
#include //测试
class SetModel
{
public:
static SetModel *getInstance();//外部公共接口 获取model对象
int addSetting(QString Video_path,QString Image_path,int framecount,QString cameraName);//添加设置信息
int updateSetting(QString Video_path,QString Image_path,int framecount,QString cameraName);//更新设置信息
int getSetting();//获取设置信息
void getSetting_videopath(QString &videopath);//获取设置信息视频保存路径
void getSetting_imagepath(QString &imagpath);//获取设置信息图片保存路径
int getSetting_interval();//获取设置信息视频间隔
private:
SetModel();//构造私有化
static SetModel *moder;//静态私成员变量
sqlite3 *sqldb;//数据库
char *errmsg;//用来存储错误信息字符串
};
#endif // SETMODEL_H
#include "setmodel.h"
SetModel *SetModel::moder =nullptr;
SetModel::SetModel(){}
//外部公共接口 获取model对象
SetModel *SetModel::getInstance()
{
if(SetModel::moder==nullptr)
{
SetModel::moder=new SetModel;
}
return SetModel::moder;
}
//添加设置信息
int SetModel::addSetting(QString Video_path, QString Image_path, int framecount, QString cameraName)
{
char sql[256];
sprintf(sql,"insert into setting(video_path,image_path,interval,camera_name)values('%s','%s','%d','%s');",
Video_path.toStdString().c_str(),Image_path.toStdString().c_str(),
framecount,cameraName.toStdString().c_str());
char **qres;
int row,col;
return SingelDB::getInstance()->dosql(sql,qres,row,col);
}
//更新设置信息
//返回值0代表更新成功,1代表失败
int SetModel::updateSetting(QString Video_path, QString Image_path, int framecount, QString cameraName)
{
char sql[256];
char **qres;
int row,col;
sprintf(sql,"update setting set video_path='%s',image_path='%s',interval='%d',camera_name='%s' where set_id=1;",
Video_path.toStdString().c_str(),Image_path.toStdString().c_str(),framecount,cameraName.toStdString().c_str());
return SingelDB::getInstance()->dosql(sql,qres,row,col);
}
//获取设置信息
//0表示dosql没有数据,大于0 表示有数据,-1执行失败
int SetModel::getSetting()
{
char sql[256] = "select * from setting";
char **qres;
int col,row;
int res = SingelDB::getInstance()->dosql(sql,qres,row,col);
if(res == 0)
{
return row;
}
return -1;
}
//获取设置信息视频保存路径
void SetModel::getSetting_videopath(QString &videopath)
{
char sql[256] = "select video_path from setting where set_id=1;";
char **qres;
int col,row;
//将sql语句换成sqlite3可以识别的语句,返回指针到stmt
int res = SingelDB::getInstance()->dosql(sql,qres,row,col);
if(res == SQLITE_OK)
{
if(row==0)
{
return;//没有数据
}
videopath = QString(QLatin1String(qres[1]));
}
}
//获取设置信息图片保存路径
void SetModel::getSetting_imagepath(QString &imagepath)
{
char sql[256] = "select image_path from setting where set_id=1;";
char **qres;
int col,row;
int res = SingelDB::getInstance()->dosql(sql,qres,row,col);
if(res == SQLITE_OK)
{
if(row==0)
{
return;//没有数据
}
imagepath = QString(QLatin1String(qres[1]));
}
}
//获取设置信息视频间隔
int SetModel::getSetting_interval()
{
char sql[256] = "select interval from setting where set_id=1;";
char **qres;
int col,row;
int res = SingelDB::getInstance()->dosql(sql,qres,row,col);
if(res == SQLITE_OK)
{
if(row==0)
{
return 1;//没有数据
}
return atoi(qres[1]);
}
return -1;
}
#ifndef VIDEOCONTROL_H
#define VIDEOCONTROL_H
#include
#include "videomodel.h"//视频控制层
class VideoControl
{
public:
static VideoControl *getInstance();//外部公共接口--获取control对象
int addVideoPath(QString video_name, QString cover_path, QString video_path);//从model层添加图片信息
char **getVideoPath();//从model层获取多个视频路径和视频名称---视频列表显示
char **getVideo(QString name);//从model层获取指定视频路径---视频播放
char **calendar_query(QString date);//从model层日历查询视频信息
char **getLastvideo();//从model层获取最后一个视频路径
private:
VideoControl();//构造私有化
static VideoControl *contorl;//静态私成员变量
};
#endif // VIDEOCONTROL_H
#include "videocontrol.h"
VideoControl *VideoControl::contorl=nullptr;
VideoControl::VideoControl(){}
//外部公共接口 获取control对象
VideoControl *VideoControl::getInstance()
{
if(VideoControl::contorl=nullptr)
{
VideoControl::contorl=new VideoControl();
}
return VideoControl::contorl;
}
//从model层添加视频信息
int VideoControl::addVideoPath(QString video_name, QString cover_path, QString video_path)
{
return VideoModel::getInstance()->addVideoPath(video_name,cover_path,video_path);
}
//从model层获取多个视频路径和视频名称---视频列表显示
char **VideoControl::getVideoPath()
{
return VideoModel::getInstance()->getVideoPath();
}
//从model层获取指定视频路径---视频播放
char **VideoControl::getVideo(QString name)
{
return VideoModel::getInstance()->getVideo(name);
}
//从model层日历查询视频信息
char **VideoControl::calendar_query(QString date)
{
return VideoModel::getInstance()->calendar_query(date);
}
//从model层获取最后一个视频路径
char **VideoControl::getLastvideo()
{
return VideoModel::getInstance()->getLastvideo();
}
#ifndef VIDEOMODEL_H
#define VIDEOMODEL_H
#include "singeldb.h"//数据库
#include
#include //字符串
class VideoModel
{
public:
static VideoModel *getInstance();//外部公共接口---获取model对象
int addVideoPath(QString video_name, QString cover_path, QString video_path);//添加图片信息
char **getVideoPath();//获取多个视频路径和视频名称---视频列表显示
char **getVideo(QString name);//获取指定视频路径---视频播放
char **calendar_query(QString date);//日历查询视频信息
char **getLastvideo();//获取最后一个视频路径
static int row,col;
private:
VideoModel();//构造私有化
static VideoModel *moder;//静态私成员变量
sqlite3 *sqldb;//数据库
char *errmsg;//用来存储错误信息字符串
};
#endif // VIDEOMODEL_H
#include "videomodel.h"
VideoModel *VideoModel::moder =nullptr;
int VideoModel::row=0;
int VideoModel::col=0;
VideoModel::VideoModel(){}
//外部公共接口 获取model对象
VideoModel *VideoModel::getInstance()
{
if(VideoModel::moder==nullptr)
{
VideoModel::moder=new VideoModel;
}
return VideoModel::moder;
}
//添加视频信息
int VideoModel::addVideoPath(QString video_name, QString cover_path, QString video_path)
{
char sql[256];
sprintf(sql,"insert into video(video_name,cover_path,video_path)values('%s','%s','%s');",
video_name.toStdString().c_str(),cover_path.toStdString().c_str(),video_path.toStdString().c_str());
char **qres;
int row,col;
return SingelDB::getInstance()->dosql(sql,qres,row,col);
}
//获取多个视频路径和视频名称---视频列表显示
char **VideoModel::getVideoPath()
{
char sql[256];
sprintf(sql,"select video_name,cover_path from video;");
char **qres;
SingelDB::getInstance()->dosql(sql,qres,row,col);
return qres;
}
//获取指定视频路径---视频播放
char **VideoModel::getVideo(QString name)
{
char sql[256];
sprintf(sql,"select video_path from video where video_name = '%s' ;",name.toStdString().c_str());
char **qres;
int row,col;
SingelDB::getInstance()->dosql(sql,qres,row,col);
return qres;
}
//日历查询视频信息
char **VideoModel::calendar_query(QString date)
{
char sql[256];
sprintf(sql,"select video_name,cover_path from video where video_name like '%s%';",date.toStdString().c_str());
char **qres;
SingelDB::getInstance()->dosql(sql,qres,row,col);
return qres;
}
//获取最后一个视频路径
char **VideoModel::getLastvideo()
{
char sql[256];
sprintf(sql,"select video_path from video order by video_id desc limit 1;");
char **qres;
int row,col;
SingelDB::getInstance()->dosql(sql,qres,row,col);
return qres;
}
#ifndef IMAGECONTROL_H
#define IMAGECONTROL_H
#include //字符串
#include "imagemodel.h"//图像模型层
class ImageControl
{
public:
// ImageControl();
static ImageControl *getInstance();//外部公共接口----获取control对象
int addImagePath(QString video_name, QString cover_path);//从control层添加图片路径到数据库----截图
char **getImagePath(int num);//从control层获取数据库中的图片路径----照片列表设置
char **getimage(QString name);//从control层获取数据库中的图片路径----照片放大相关操作
private:
ImageControl();//构造函数私有化
static ImageControl *contorl;//静态私有的成员变量
};
#endif // IMAGECONTROL_H
#include "imagecontrol.h"
ImageControl *ImageControl::contorl=nullptr;
ImageControl::ImageControl()
{
}
//外部公共接口 获取control对象
ImageControl *ImageControl::getInstance()
{
if(ImageControl::contorl=nullptr)
{
ImageControl::contorl=new ImageControl();
}
return ImageControl::contorl;
}
//从control层添加图片路径到数据库----截图
int ImageControl::addImagePath(QString video_name, QString cover_path)
{
return ImageModel::getInstance()->addImagePath(video_name,cover_path);
}
//从control层获取数据库中的图片路径----照片列表设置
char **ImageControl::getImagePath(int num)
{
return ImageModel::getInstance()->getImagePath(num);
}
//从control层获取数据库中的图片路径----照片放大相关操作
char **ImageControl::getimage(QString name)
{
return ImageModel::getInstance()->getimage(name);
}
#ifndef IMAGEMODEL_H
#define IMAGEMODEL_H
#include "singeldb.h"//数据库
#include
#include //字符串
class ImageModel
{
public:
// ImageModel();
static ImageModel *getInstance();//外部公共接口 获取model对象
int addImagePath(QString video_name, QString cover_path);//添加设置信息----截图
char **getImagePath(int num);//获取多个图片路径----要求9个为一组
char **getimage(QString name);//获取图片路径
static int row,col;
private:
ImageModel();//构造私有化
static ImageModel *moder;//静态私成员变量
sqlite3 *sqldb;//数据库
char *errmsg;//用来存储错误信息字符串
};
#endif // IMAGEMODEL_H
#include "imagemodel.h"
//ImageModel::ImageModel()
//{
//}
ImageModel *ImageModel::moder =nullptr;
int ImageModel::row=0;
int ImageModel::col=0;
ImageModel::ImageModel()
{
}
//外部公共接口 获取model对象
ImageModel *ImageModel::getInstance()
{
if(ImageModel::moder==nullptr)
{
ImageModel::moder=new ImageModel;
}
return ImageModel::moder;
}
//添加设置信息--截图
int ImageModel::addImagePath(QString video_name, QString cover_path)
{
char sql[256];
sprintf(sql,"insert into image(image_name,image_path)values('%s','%s');",
video_name.toStdString().c_str(),cover_path.toStdString().c_str());
char **qres;
int row,col;
return SingelDB::getInstance()->dosql(sql,qres,row,col);
}
//获取多个图片路径 要求9个为一组
char **ImageModel::getImagePath(int num)
{
char sql[256];
sprintf(sql,"select image_path,image_name from image limit 9 offset (%d-1)*9;",num);
char **qres;
//int row,col;
SingelDB::getInstance()->dosql(sql,qres,row,col);//执行sql语句
return qres;
}
//获取图片路径
char **ImageModel::getimage(QString name)
{
char sql[256];
sprintf(sql,"select image_path from image where image_name = '%s';",name.toStdString().c_str());
char **qres;
int row,col;
SingelDB::getInstance()->dosql(sql,qres,row,col);//执行sql语句
return qres;
}