改进部分代码
parent
8beba8758b
commit
8978488e66
|
@ -144,8 +144,6 @@ DbPage *DbPage::Instance()
|
||||||
DbPage::DbPage(QObject *parent) : QObject(parent)
|
DbPage::DbPage(QObject *parent) : QObject(parent)
|
||||||
{
|
{
|
||||||
startIndex = 0;
|
startIndex = 0;
|
||||||
tempSql = "";
|
|
||||||
sql = "";
|
|
||||||
queryModel = new SqlQueryModel;
|
queryModel = new SqlQueryModel;
|
||||||
|
|
||||||
pageCurrent = 1;
|
pageCurrent = 1;
|
||||||
|
@ -260,6 +258,24 @@ void DbPage::bindData(const QString &sql)
|
||||||
emit receivePage(pageCurrent, pageCount, resultCount, resultCurrent);
|
emit receivePage(pageCurrent, pageCount, resultCount, resultCurrent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString DbPage::getPageSql()
|
||||||
|
{
|
||||||
|
//组织分页SQL语句,不同的数据库分页语句不一样
|
||||||
|
QString sql = QString("select %1 from %2 %3 order by %4").arg(selectColumn).arg(tableName).arg(whereSql).arg(orderSql);
|
||||||
|
if (dbType == DbType_PostgreSQL || dbType == DbType_KingBase) {
|
||||||
|
sql = QString("%1 limit %3 offset %2;").arg(sql).arg(startIndex).arg(resultCurrent);
|
||||||
|
} else if (dbType == DbType_SqlServer) {
|
||||||
|
//取第m条到第n条记录:select top (n-m+1) id from tablename where id not in (select top m-1 id from tablename)
|
||||||
|
//sql = QString("select %1 from %2 %3 order by %4").arg(selectColumn).arg(tableName).arg(whereSql).arg(orderSql);
|
||||||
|
} else if (dbType == DbType_Oracle) {
|
||||||
|
//暂时没有找到好办法
|
||||||
|
} else {
|
||||||
|
sql = QString("%1 limit %2,%3;").arg(sql).arg(startIndex).arg(resultCurrent);
|
||||||
|
}
|
||||||
|
|
||||||
|
return sql;
|
||||||
|
}
|
||||||
|
|
||||||
void DbPage::slot_receiveCount(quint32 count, double msec)
|
void DbPage::slot_receiveCount(quint32 count, double msec)
|
||||||
{
|
{
|
||||||
if (labResult != 0) {
|
if (labResult != 0) {
|
||||||
|
@ -294,10 +310,7 @@ void DbPage::slot_receiveCount(quint32 count, double msec)
|
||||||
btnPre->setEnabled(true);
|
btnPre->setEnabled(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
tempSql = QString("select %1 from %2 %3 order by %4").arg(selectColumn).arg(tableName).arg(whereSql).arg(orderSql);
|
bindData(getPageSql());
|
||||||
sql = QString("%1 limit %2,%3;").arg(tempSql).arg(startIndex).arg(resultCurrent); //组织分页SQL语句
|
|
||||||
|
|
||||||
bindData(sql);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void DbPage::first()
|
void DbPage::first()
|
||||||
|
@ -305,8 +318,7 @@ void DbPage::first()
|
||||||
if (pageCount > 1) {
|
if (pageCount > 1) {
|
||||||
startIndex = 0;
|
startIndex = 0;
|
||||||
pageCurrent = 1;
|
pageCurrent = 1;
|
||||||
sql = QString("%1 limit %2,%3;").arg(tempSql).arg(startIndex).arg(resultCurrent);
|
bindData(getPageSql());
|
||||||
bindData(sql);
|
|
||||||
btnLast->setEnabled(true);
|
btnLast->setEnabled(true);
|
||||||
btnNext->setEnabled(true);
|
btnNext->setEnabled(true);
|
||||||
}
|
}
|
||||||
|
@ -320,8 +332,7 @@ void DbPage::previous()
|
||||||
if (pageCurrent > 1) {
|
if (pageCurrent > 1) {
|
||||||
pageCurrent--;
|
pageCurrent--;
|
||||||
startIndex -= resultCurrent;
|
startIndex -= resultCurrent;
|
||||||
sql = QString("%1 limit %2,%3;").arg(tempSql).arg(startIndex).arg(resultCurrent);
|
bindData(getPageSql());
|
||||||
bindData(sql);
|
|
||||||
btnLast->setEnabled(true);
|
btnLast->setEnabled(true);
|
||||||
btnNext->setEnabled(true);
|
btnNext->setEnabled(true);
|
||||||
}
|
}
|
||||||
|
@ -337,8 +348,7 @@ void DbPage::next()
|
||||||
if (pageCurrent < pageCount) {
|
if (pageCurrent < pageCount) {
|
||||||
pageCurrent++;
|
pageCurrent++;
|
||||||
startIndex += resultCurrent;
|
startIndex += resultCurrent;
|
||||||
sql = QString("%1 limit %2,%3;").arg(tempSql).arg(startIndex).arg(resultCurrent);
|
bindData(getPageSql());
|
||||||
bindData(sql);
|
|
||||||
btnFirst->setEnabled(true);
|
btnFirst->setEnabled(true);
|
||||||
btnPre->setEnabled(true);
|
btnPre->setEnabled(true);
|
||||||
}
|
}
|
||||||
|
@ -354,8 +364,7 @@ void DbPage::last()
|
||||||
if (pageCount > 0) {
|
if (pageCount > 0) {
|
||||||
startIndex = (pageCount - 1) * resultCurrent;
|
startIndex = (pageCount - 1) * resultCurrent;
|
||||||
pageCurrent = pageCount;
|
pageCurrent = pageCount;
|
||||||
sql = QString("%1 limit %2,%3;").arg(tempSql).arg(startIndex).arg(resultCurrent);
|
bindData(getPageSql());
|
||||||
bindData(sql);
|
|
||||||
btnFirst->setEnabled(true);
|
btnFirst->setEnabled(true);
|
||||||
btnPre->setEnabled(true);
|
btnPre->setEnabled(true);
|
||||||
}
|
}
|
||||||
|
@ -514,7 +523,7 @@ void DbPage::select()
|
||||||
}
|
}
|
||||||
|
|
||||||
//开始分页绑定数据前,计算好总数据量以及行数
|
//开始分页绑定数据前,计算好总数据量以及行数
|
||||||
tempSql = QString("select count(%1) from %2 %3").arg(countName).arg(tableName).arg(whereSql);
|
QString sql = QString("select count(%1) from %2 %3").arg(countName).arg(tableName).arg(whereSql);
|
||||||
|
|
||||||
//采用线程执行查询复合条件的记录行数
|
//采用线程执行查询复合条件的记录行数
|
||||||
DbCountThread *dbCountThread = new DbCountThread(this);
|
DbCountThread *dbCountThread = new DbCountThread(this);
|
||||||
|
@ -524,7 +533,7 @@ void DbPage::select()
|
||||||
|
|
||||||
//设置数据库连接名称和查询语句,并启动线程
|
//设置数据库连接名称和查询语句,并启动线程
|
||||||
dbCountThread->setConnName(connName);
|
dbCountThread->setConnName(connName);
|
||||||
dbCountThread->setSql(tempSql);
|
dbCountThread->setSql(sql);
|
||||||
//从5.10开始不支持数据库在线程中执行
|
//从5.10开始不支持数据库在线程中执行
|
||||||
#if (QT_VERSION <= QT_VERSION_CHECK(5,10,0))
|
#if (QT_VERSION <= QT_VERSION_CHECK(5,10,0))
|
||||||
dbCountThread->start();
|
dbCountThread->start();
|
||||||
|
|
|
@ -77,11 +77,14 @@ class DbPage : public QObject
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
enum DbType {
|
enum DbType {
|
||||||
DbType_Sqlite = 0, //sqlite数据库
|
DbType_ODBC = 0, //odbc数据源
|
||||||
DbType_MySql = 1, //mysql数据库
|
DbType_Sqlite = 1, //sqlite数据库
|
||||||
DbType_SqlServer = 3, //sqlserver数据库
|
DbType_MySql = 2, //mysql数据库
|
||||||
DbType_Access = 4, //access数据库
|
DbType_PostgreSQL = 3, //postgresql数据库
|
||||||
DbType_PostgreSQL = 5 //postgresql数据库
|
DbType_SqlServer = 4, //sqlserver数据库
|
||||||
|
DbType_Oracle = 5, //oracle数据库
|
||||||
|
DbType_KingBase = 6, //人大金仓数据库
|
||||||
|
DbType_Other = 255 //其他数据库
|
||||||
};
|
};
|
||||||
|
|
||||||
static DbPage *Instance();
|
static DbPage *Instance();
|
||||||
|
@ -97,8 +100,6 @@ private:
|
||||||
static QScopedPointer<DbPage> self;
|
static QScopedPointer<DbPage> self;
|
||||||
|
|
||||||
int startIndex; //分页开始索引,每次翻页都变动
|
int startIndex; //分页开始索引,每次翻页都变动
|
||||||
QString tempSql; //临时SQL语句
|
|
||||||
QString sql; //sql语句
|
|
||||||
SqlQueryModel *queryModel; //查询模型
|
SqlQueryModel *queryModel; //查询模型
|
||||||
|
|
||||||
QLabel *labPageCount; //总页数标签
|
QLabel *labPageCount; //总页数标签
|
||||||
|
@ -143,6 +144,8 @@ private slots:
|
||||||
private slots:
|
private slots:
|
||||||
//绑定sql语句到表格
|
//绑定sql语句到表格
|
||||||
void bindData(const QString &sql);
|
void bindData(const QString &sql);
|
||||||
|
//生成分页sql语句
|
||||||
|
QString getPageSql();
|
||||||
|
|
||||||
//收到记录行数
|
//收到记录行数
|
||||||
void slot_receiveCount(quint32 count, double msec);
|
void slot_receiveCount(quint32 count, double msec);
|
||||||
|
|
|
@ -568,6 +568,16 @@ QList<QRect> VideoWidget::getFaceRects() const
|
||||||
return this->faceRects;
|
return this->faceRects;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QSize VideoWidget::sizeHint() const
|
||||||
|
{
|
||||||
|
return QSize(400, 300);
|
||||||
|
}
|
||||||
|
|
||||||
|
QSize VideoWidget::minimumSizeHint() const
|
||||||
|
{
|
||||||
|
return QSize(40, 30);
|
||||||
|
}
|
||||||
|
|
||||||
void VideoWidget::updateImage(const QImage &image)
|
void VideoWidget::updateImage(const QImage &image)
|
||||||
{
|
{
|
||||||
//拷贝图片有个好处,当处理器比较差的时候,图片不会产生断层,缺点是占用时间
|
//拷贝图片有个好处,当处理器比较差的时候,图片不会产生断层,缺点是占用时间
|
||||||
|
|
|
@ -204,6 +204,9 @@ public:
|
||||||
QColor getFaceColor() const;
|
QColor getFaceColor() const;
|
||||||
QList<QRect> getFaceRects() const;
|
QList<QRect> getFaceRects() const;
|
||||||
|
|
||||||
|
QSize sizeHint() const;
|
||||||
|
QSize minimumSizeHint() const;
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
//接收图像并绘制
|
//接收图像并绘制
|
||||||
void updateImage(const QImage &image);
|
void updateImage(const QImage &image);
|
||||||
|
|
Loading…
Reference in New Issue