|
|
|
@ -1,322 +1,322 @@
|
|
|
|
|
#include "searchwidget.h"
|
|
|
|
|
#include "ui_searchwidget.h"
|
|
|
|
|
|
|
|
|
|
SearchWidget::SearchWidget(QWidget *parent) :
|
|
|
|
|
QWidget(parent),
|
|
|
|
|
ui(new Ui::SearchWidget)
|
|
|
|
|
{
|
|
|
|
|
ui->setupUi(this);
|
|
|
|
|
|
|
|
|
|
showLimit = 15;
|
|
|
|
|
cateList.append("food");
|
|
|
|
|
cateList.append("entertainment");
|
|
|
|
|
cateList.append("hotel");
|
|
|
|
|
cateList.append("attractions");
|
|
|
|
|
cateList.append("sport");
|
|
|
|
|
lengthList = (int *)malloc(sizeof(int) * cateList.length());
|
|
|
|
|
idList = (int *)malloc(sizeof(int) * showLimit);
|
|
|
|
|
|
|
|
|
|
mainLayout = new QVBoxLayout();
|
|
|
|
|
|
|
|
|
|
subWidget = new QWidget();
|
|
|
|
|
web = new WebWidget();
|
|
|
|
|
nullWidget = new QLabel("抱歉,未找到您要的结果。");
|
|
|
|
|
|
|
|
|
|
subLayout = new QVBoxLayout();
|
|
|
|
|
|
|
|
|
|
rtn = new QPushButton("返回");
|
|
|
|
|
scroll = new QScrollArea();
|
|
|
|
|
|
|
|
|
|
scrollWidget = new QWidget();
|
|
|
|
|
scrollLayout = new QVBoxLayout();
|
|
|
|
|
|
|
|
|
|
btnList = (QToolButton **)malloc(sizeof(QToolButton *) * showLimit);
|
|
|
|
|
|
|
|
|
|
switchLine = new QHBoxLayout();
|
|
|
|
|
up = new QPushButton("上一页");
|
|
|
|
|
down = new QPushButton("下一页");
|
|
|
|
|
|
|
|
|
|
//设置布局
|
|
|
|
|
this->setLayout(mainLayout);
|
|
|
|
|
|
|
|
|
|
mainLayout->addWidget(subWidget);
|
|
|
|
|
mainLayout->addWidget(web);
|
|
|
|
|
mainLayout->addWidget(nullWidget);
|
|
|
|
|
web->setVisible(false);
|
|
|
|
|
nullWidget->setVisible(false);
|
|
|
|
|
|
|
|
|
|
subWidget->setLayout(subLayout);
|
|
|
|
|
|
|
|
|
|
subLayout->addWidget(rtn);
|
|
|
|
|
subLayout->addWidget(scroll);
|
|
|
|
|
subLayout->addLayout(switchLine);
|
|
|
|
|
|
|
|
|
|
switchLine->addWidget(up);
|
|
|
|
|
switchLine->addWidget(down);
|
|
|
|
|
|
|
|
|
|
connect(web->getReturnBtn(), &QPushButton::clicked, this, &SearchWidget::returnWeb);
|
|
|
|
|
connect(up, &QPushButton::clicked, this, &SearchWidget::pageUp);
|
|
|
|
|
connect(down, &QPushButton::clicked, this, &SearchWidget::pageDown);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SearchWidget::~SearchWidget()
|
|
|
|
|
{
|
|
|
|
|
delete ui;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QPushButton *SearchWidget::getReturnBtn()
|
|
|
|
|
{
|
|
|
|
|
return rtn;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SearchWidget::sendInput(QString input)
|
|
|
|
|
{
|
|
|
|
|
this->segment = input;
|
|
|
|
|
qDebug() << "segment:" <<segment;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SearchWidget::getTotalNum()
|
|
|
|
|
{
|
|
|
|
|
//查询条目数
|
|
|
|
|
QSqlQuery query(meituanDb);
|
|
|
|
|
|
|
|
|
|
int length = cateList.length();
|
|
|
|
|
for (int i = 0; i < length; i++)
|
|
|
|
|
{
|
|
|
|
|
query.prepare("select count(*) as num from " + cateList[i] + " where title like :segment");
|
|
|
|
|
query.bindValue(":segment", "%" + segment + "%");
|
|
|
|
|
query.exec();
|
|
|
|
|
query.next();
|
|
|
|
|
qDebug() << cateList[i] + " totalNum:" << query.value("num");
|
|
|
|
|
lengthList[i] = query.value("num").value<qlonglong>();
|
|
|
|
|
totalNum += query.value("num").value<qlonglong>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pageNum = (totalNum + showLimit - 1)/showLimit;
|
|
|
|
|
page2cate = (int *)malloc(sizeof(int) * pageNum);
|
|
|
|
|
page2offset = (int *)malloc(sizeof(int) * pageNum);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SearchWidget::queryDatabase(QSqlQuery query)
|
|
|
|
|
{
|
|
|
|
|
query.exec();
|
|
|
|
|
int i = currentHead;
|
|
|
|
|
while(query.next()==true && i < showLimit)
|
|
|
|
|
{
|
|
|
|
|
QVariant id = query.value("id");
|
|
|
|
|
|
|
|
|
|
QVariant detail = query.value("detail");
|
|
|
|
|
|
|
|
|
|
QVariant frontimg = query.value("frontimg");
|
|
|
|
|
|
|
|
|
|
QVariant title = query.value("title");
|
|
|
|
|
QVariant avgscore = query.value("avgscore");
|
|
|
|
|
QVariant comments = query.value("comments");
|
|
|
|
|
QVariant address = query.value("address");
|
|
|
|
|
QVariant cateId = query.value("cateId");
|
|
|
|
|
// QVariant avgprice = query.value("avgprice");
|
|
|
|
|
|
|
|
|
|
QString name = title.value<QString>();
|
|
|
|
|
QString score = QString::number(avgscore.value<double>());
|
|
|
|
|
QString commentNum = QString::number(comments.value<qlonglong>());
|
|
|
|
|
QString addr = address.value<QString>();
|
|
|
|
|
// QString price = QString::number(avgprice.value<qlonglong>());
|
|
|
|
|
QString text = name + "\n" + score + "分 " + commentNum + "条评论\n" + addr + "\n";// + "人均" + price + "元";
|
|
|
|
|
QString cateid = cateId.value<QString>();
|
|
|
|
|
|
|
|
|
|
idList[i] = id.value<qlonglong>();
|
|
|
|
|
nameList.append(name);
|
|
|
|
|
urlList.append(detail.value<QString>());
|
|
|
|
|
imgList.append(frontimg.value<QString>());
|
|
|
|
|
textList.append(text);
|
|
|
|
|
cateIdList.append(cateid);
|
|
|
|
|
i++;
|
|
|
|
|
}
|
|
|
|
|
currentQueryLength = i - currentHead;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QToolButton *SearchWidget::setBtn(QToolButton *btn, const QString iconPath, const QString text)
|
|
|
|
|
{
|
|
|
|
|
if(iconPath != "")
|
|
|
|
|
btn->setIcon(QIcon(iconPath));
|
|
|
|
|
btn->setText(text);
|
|
|
|
|
btn->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
|
|
|
|
|
btn->setIconSize(QSize(100,200));
|
|
|
|
|
btn->setFixedSize(1230,200);
|
|
|
|
|
|
|
|
|
|
return btn;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SearchWidget::setBtns()
|
|
|
|
|
{
|
|
|
|
|
int i = currentHead;
|
|
|
|
|
// qDebug() << "currentHead:" << currentHead;
|
|
|
|
|
// qDebug() << "currentQueryLength:" << currentQueryLength;
|
|
|
|
|
for (i; i < currentHead + currentQueryLength; i++)
|
|
|
|
|
{
|
|
|
|
|
int index = i;
|
|
|
|
|
//下载图片到本地
|
|
|
|
|
QString imgPath = "./images/" + cateList[currentCate] + QString::number(idList[index]) + ".png";
|
|
|
|
|
imgDownloader *download = new imgDownloader();
|
|
|
|
|
download->downloadFileFromUrl(imgList[index], imgPath);
|
|
|
|
|
btnList[index] = setBtn(btnList[index], imgPath, textList[index]);
|
|
|
|
|
qDebug() << "info:" << cateList[currentCate] << idList[index] << urlList[index] << imgList[index];
|
|
|
|
|
// btnList[index]->setVisible(true);
|
|
|
|
|
disconnect(btnList[index], 0, 0, 0);
|
|
|
|
|
connect(btnList[index], &QToolButton::clicked, this, [=](){web->loadPage(nameList[index], imgList[index], urlList[index], cateIdList[index]); subWidget->setVisible(false); web->setVisible(true); nullWidget->setVisible(false);});
|
|
|
|
|
}
|
|
|
|
|
for (i; i < showLimit; i++)
|
|
|
|
|
{
|
|
|
|
|
int index = i;
|
|
|
|
|
btnList[index] = setBtn(btnList[index], "./images/transparent.png", "");
|
|
|
|
|
// btnList[index]->setVisible(false);
|
|
|
|
|
disconnect(btnList[index], 0, 0, 0);
|
|
|
|
|
}
|
|
|
|
|
// offset += currentQueryLength;
|
|
|
|
|
// currentHead += currentQueryLength;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SearchWidget::querySet()
|
|
|
|
|
{
|
|
|
|
|
rollTop();
|
|
|
|
|
|
|
|
|
|
//重置存储查询信息的列表
|
|
|
|
|
nameList.clear();
|
|
|
|
|
urlList.clear();
|
|
|
|
|
imgList.clear();
|
|
|
|
|
textList.clear();
|
|
|
|
|
cateIdList.clear();
|
|
|
|
|
currentHead = 0;
|
|
|
|
|
currentQueryLength = 0;
|
|
|
|
|
currentCate = page2cate[currentPage - 1];
|
|
|
|
|
currentOffset = page2offset[currentPage - 1];
|
|
|
|
|
for (int i = 0; i <showLimit; i++)
|
|
|
|
|
{
|
|
|
|
|
int index = i;
|
|
|
|
|
btnList[index] = new QToolButton();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// subLayout->removeWidget(scroll);
|
|
|
|
|
scroll->takeWidget();
|
|
|
|
|
scrollWidget->deleteLater();
|
|
|
|
|
scrollWidget = new QWidget();
|
|
|
|
|
scrollLayout->deleteLater();
|
|
|
|
|
scrollLayout = new QVBoxLayout();
|
|
|
|
|
scrollWidget->setLayout(scrollLayout);
|
|
|
|
|
|
|
|
|
|
qDebug() << "currentPage:" << currentPage;
|
|
|
|
|
|
|
|
|
|
QSqlQuery query(meituanDb);
|
|
|
|
|
|
|
|
|
|
while (currentHead < showLimit)
|
|
|
|
|
{
|
|
|
|
|
//判断是否换表
|
|
|
|
|
if (currentOffset >= lengthList[currentCate])
|
|
|
|
|
{
|
|
|
|
|
currentCate += 1;
|
|
|
|
|
currentOffset = 0;
|
|
|
|
|
if (currentCate >= cateList.length())
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
//查询数据
|
|
|
|
|
query.prepare("select * from " + cateList[currentCate] + " where title like :segment limit :offset , :showLimit");
|
|
|
|
|
query.bindValue(":segment", "%" + segment + "%");
|
|
|
|
|
query.bindValue(":offset", currentOffset);
|
|
|
|
|
qDebug() << "currentCate:" << currentCate;
|
|
|
|
|
// qDebug() << "offset:" << offset;
|
|
|
|
|
query.bindValue(":showLimit", showLimit);
|
|
|
|
|
queryDatabase(query);
|
|
|
|
|
// qDebug() << "query success";
|
|
|
|
|
//设置按钮
|
|
|
|
|
setBtns();
|
|
|
|
|
// qDebug() << "set buttons success";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//设置滚动界面布局
|
|
|
|
|
for (int i = currentHead; i < currentHead + currentQueryLength; i++)
|
|
|
|
|
{
|
|
|
|
|
scrollLayout->addWidget(btnList[i]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
currentOffset += currentQueryLength;
|
|
|
|
|
currentHead += currentQueryLength;
|
|
|
|
|
}
|
|
|
|
|
page2cate[currentPage] = currentCate;
|
|
|
|
|
page2offset[currentPage] = currentOffset;
|
|
|
|
|
|
|
|
|
|
scroll->setWidget(scrollWidget);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SearchWidget::showResult()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
totalNum = 0;
|
|
|
|
|
pageNum = 0;
|
|
|
|
|
getTotalNum();
|
|
|
|
|
qDebug() << "totalNum:" << totalNum;
|
|
|
|
|
qDebug() << "pageNum:" << pageNum;
|
|
|
|
|
currentPage = 1;
|
|
|
|
|
currentCate = 0;
|
|
|
|
|
currentOffset = 0;
|
|
|
|
|
page2cate[0] = currentCate;
|
|
|
|
|
page2offset[0] = currentOffset;
|
|
|
|
|
if (totalNum)
|
|
|
|
|
{
|
|
|
|
|
querySet();
|
|
|
|
|
subWidget->setVisible(true);
|
|
|
|
|
nullWidget->setVisible(false);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
subWidget->setVisible(false);
|
|
|
|
|
nullWidget->setVisible(true);
|
|
|
|
|
}
|
|
|
|
|
web->setVisible(false);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SearchWidget::returnWeb()
|
|
|
|
|
{
|
|
|
|
|
subWidget->setVisible(true);
|
|
|
|
|
web->setVisible(false);
|
|
|
|
|
nullWidget->setVisible(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SearchWidget::pageUp()
|
|
|
|
|
{
|
|
|
|
|
currentPage--;
|
|
|
|
|
if (currentPage < 1)
|
|
|
|
|
{
|
|
|
|
|
currentPage = 1;
|
|
|
|
|
qDebug("这是第一页");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
rollTop();
|
|
|
|
|
querySet();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SearchWidget::pageDown()
|
|
|
|
|
{
|
|
|
|
|
currentPage++;
|
|
|
|
|
if (currentPage > pageNum)
|
|
|
|
|
{
|
|
|
|
|
currentPage = pageNum;
|
|
|
|
|
qDebug("已经是最后一页了!");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
rollTop();
|
|
|
|
|
querySet();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SearchWidget::rollTop()
|
|
|
|
|
{
|
|
|
|
|
QScrollBar *scrollBar = scroll->verticalScrollBar();
|
|
|
|
|
scrollBar->setValue(scrollBar->minimum());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#include "searchwidget.h"
|
|
|
|
|
#include "ui_searchwidget.h"
|
|
|
|
|
|
|
|
|
|
SearchWidget::SearchWidget(QWidget *parent) :
|
|
|
|
|
QWidget(parent),
|
|
|
|
|
ui(new Ui::SearchWidget)
|
|
|
|
|
{
|
|
|
|
|
ui->setupUi(this);
|
|
|
|
|
|
|
|
|
|
showLimit = 15;
|
|
|
|
|
cateList.append("food");
|
|
|
|
|
cateList.append("entertainment");
|
|
|
|
|
cateList.append("hotel");
|
|
|
|
|
cateList.append("attractions");
|
|
|
|
|
cateList.append("sport");
|
|
|
|
|
lengthList = (int *)malloc(sizeof(int) * cateList.length());
|
|
|
|
|
idList = (int *)malloc(sizeof(int) * showLimit);
|
|
|
|
|
|
|
|
|
|
mainLayout = new QVBoxLayout();
|
|
|
|
|
|
|
|
|
|
subWidget = new QWidget();
|
|
|
|
|
web = new WebWidget();
|
|
|
|
|
nullWidget = new QLabel("抱歉,未找到您要的结果。");
|
|
|
|
|
|
|
|
|
|
subLayout = new QVBoxLayout();
|
|
|
|
|
|
|
|
|
|
rtn = new QPushButton("返回");
|
|
|
|
|
scroll = new QScrollArea();
|
|
|
|
|
|
|
|
|
|
scrollWidget = new QWidget();
|
|
|
|
|
scrollLayout = new QVBoxLayout();
|
|
|
|
|
|
|
|
|
|
btnList = (QToolButton **)malloc(sizeof(QToolButton *) * showLimit);
|
|
|
|
|
|
|
|
|
|
switchLine = new QHBoxLayout();
|
|
|
|
|
up = new QPushButton("上一页");
|
|
|
|
|
down = new QPushButton("下一页");
|
|
|
|
|
|
|
|
|
|
//设置布局
|
|
|
|
|
this->setLayout(mainLayout);
|
|
|
|
|
|
|
|
|
|
mainLayout->addWidget(subWidget);
|
|
|
|
|
mainLayout->addWidget(web);
|
|
|
|
|
mainLayout->addWidget(nullWidget);
|
|
|
|
|
web->setVisible(false);
|
|
|
|
|
nullWidget->setVisible(false);
|
|
|
|
|
|
|
|
|
|
subWidget->setLayout(subLayout);
|
|
|
|
|
|
|
|
|
|
subLayout->addWidget(rtn);
|
|
|
|
|
subLayout->addWidget(scroll);
|
|
|
|
|
subLayout->addLayout(switchLine);
|
|
|
|
|
|
|
|
|
|
switchLine->addWidget(up);
|
|
|
|
|
switchLine->addWidget(down);
|
|
|
|
|
|
|
|
|
|
connect(web->getReturnBtn(), &QPushButton::clicked, this, &SearchWidget::returnWeb);
|
|
|
|
|
connect(up, &QPushButton::clicked, this, &SearchWidget::pageUp);
|
|
|
|
|
connect(down, &QPushButton::clicked, this, &SearchWidget::pageDown);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SearchWidget::~SearchWidget()
|
|
|
|
|
{
|
|
|
|
|
delete ui;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QPushButton *SearchWidget::getReturnBtn()
|
|
|
|
|
{
|
|
|
|
|
return rtn;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SearchWidget::sendInput(QString input)
|
|
|
|
|
{
|
|
|
|
|
this->segment = input;
|
|
|
|
|
qDebug() << "segment:" <<segment;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SearchWidget::getTotalNum()
|
|
|
|
|
{
|
|
|
|
|
//查询条目数
|
|
|
|
|
QSqlQuery query(meituanDb);
|
|
|
|
|
|
|
|
|
|
int length = cateList.length();
|
|
|
|
|
for (int i = 0; i < length; i++)
|
|
|
|
|
{
|
|
|
|
|
query.prepare("select count(*) as num from " + cateList[i] + " where title like :segment");
|
|
|
|
|
query.bindValue(":segment", "%" + segment + "%");
|
|
|
|
|
query.exec();
|
|
|
|
|
query.next();
|
|
|
|
|
qDebug() << cateList[i] + " totalNum:" << query.value("num");
|
|
|
|
|
lengthList[i] = query.value("num").value<qlonglong>();
|
|
|
|
|
totalNum += query.value("num").value<qlonglong>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pageNum = (totalNum + showLimit - 1)/showLimit;
|
|
|
|
|
page2cate = (int *)malloc(sizeof(int) * pageNum);
|
|
|
|
|
page2offset = (int *)malloc(sizeof(int) * pageNum);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SearchWidget::queryDatabase(QSqlQuery query)
|
|
|
|
|
{
|
|
|
|
|
query.exec();
|
|
|
|
|
int i = currentHead;
|
|
|
|
|
while(query.next()==true && i < showLimit)
|
|
|
|
|
{
|
|
|
|
|
QVariant id = query.value("id");
|
|
|
|
|
|
|
|
|
|
QVariant detail = query.value("detail");
|
|
|
|
|
|
|
|
|
|
QVariant frontimg = query.value("frontimg");
|
|
|
|
|
|
|
|
|
|
QVariant title = query.value("title");
|
|
|
|
|
QVariant avgscore = query.value("avgscore");
|
|
|
|
|
QVariant comments = query.value("comments");
|
|
|
|
|
QVariant address = query.value("address");
|
|
|
|
|
QVariant cateId = query.value("cateId");
|
|
|
|
|
// QVariant avgprice = query.value("avgprice");
|
|
|
|
|
|
|
|
|
|
QString name = title.value<QString>();
|
|
|
|
|
QString score = QString::number(avgscore.value<double>());
|
|
|
|
|
QString commentNum = QString::number(comments.value<qlonglong>());
|
|
|
|
|
QString addr = address.value<QString>();
|
|
|
|
|
// QString price = QString::number(avgprice.value<qlonglong>());
|
|
|
|
|
QString text = name + "\n" + score + "分 " + commentNum + "条评论\n" + addr + "\n";// + "人均" + price + "元";
|
|
|
|
|
QString cateid = cateId.value<QString>();
|
|
|
|
|
|
|
|
|
|
idList[i] = id.value<qlonglong>();
|
|
|
|
|
nameList.append(name);
|
|
|
|
|
urlList.append(detail.value<QString>());
|
|
|
|
|
imgList.append(frontimg.value<QString>());
|
|
|
|
|
textList.append(text);
|
|
|
|
|
cateIdList.append(cateid);
|
|
|
|
|
i++;
|
|
|
|
|
}
|
|
|
|
|
currentQueryLength = i - currentHead;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QToolButton *SearchWidget::setBtn(QToolButton *btn, const QString iconPath, const QString text)
|
|
|
|
|
{
|
|
|
|
|
if(iconPath != "")
|
|
|
|
|
btn->setIcon(QIcon(iconPath));
|
|
|
|
|
btn->setText(text);
|
|
|
|
|
btn->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
|
|
|
|
|
btn->setIconSize(QSize(100,200));
|
|
|
|
|
btn->setFixedSize(1230,200);
|
|
|
|
|
|
|
|
|
|
return btn;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SearchWidget::setBtns()
|
|
|
|
|
{
|
|
|
|
|
int i = currentHead;
|
|
|
|
|
// qDebug() << "currentHead:" << currentHead;
|
|
|
|
|
// qDebug() << "currentQueryLength:" << currentQueryLength;
|
|
|
|
|
for (i; i < currentHead + currentQueryLength; i++)
|
|
|
|
|
{
|
|
|
|
|
int index = i;
|
|
|
|
|
//下载图片到本地
|
|
|
|
|
QString imgPath = "./images/" + cateList[currentCate] + QString::number(idList[index]) + ".png";
|
|
|
|
|
imgDownloader *download = new imgDownloader();
|
|
|
|
|
download->downloadFileFromUrl(imgList[index], imgPath);
|
|
|
|
|
btnList[index] = setBtn(btnList[index], imgPath, textList[index]);
|
|
|
|
|
qDebug() << "info:" << cateList[currentCate] << idList[index] << urlList[index] << imgList[index];
|
|
|
|
|
// btnList[index]->setVisible(true);
|
|
|
|
|
disconnect(btnList[index], 0, 0, 0);
|
|
|
|
|
connect(btnList[index], &QToolButton::clicked, this, [=](){web->loadPage(nameList[index], imgList[index], urlList[index], cateIdList[index]); subWidget->setVisible(false); web->setVisible(true); nullWidget->setVisible(false);});
|
|
|
|
|
}
|
|
|
|
|
for (i; i < showLimit; i++)
|
|
|
|
|
{
|
|
|
|
|
int index = i;
|
|
|
|
|
btnList[index] = setBtn(btnList[index], "./images/transparent.png", "");
|
|
|
|
|
// btnList[index]->setVisible(false);
|
|
|
|
|
disconnect(btnList[index], 0, 0, 0);
|
|
|
|
|
}
|
|
|
|
|
// offset += currentQueryLength;
|
|
|
|
|
// currentHead += currentQueryLength;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SearchWidget::querySet()
|
|
|
|
|
{
|
|
|
|
|
rollTop();
|
|
|
|
|
|
|
|
|
|
//重置存储查询信息的列表
|
|
|
|
|
nameList.clear();
|
|
|
|
|
urlList.clear();
|
|
|
|
|
imgList.clear();
|
|
|
|
|
textList.clear();
|
|
|
|
|
cateIdList.clear();
|
|
|
|
|
currentHead = 0;
|
|
|
|
|
currentQueryLength = 0;
|
|
|
|
|
currentCate = page2cate[currentPage - 1];
|
|
|
|
|
currentOffset = page2offset[currentPage - 1];
|
|
|
|
|
for (int i = 0; i <showLimit; i++)
|
|
|
|
|
{
|
|
|
|
|
int index = i;
|
|
|
|
|
btnList[index] = new QToolButton();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// subLayout->removeWidget(scroll);
|
|
|
|
|
scroll->takeWidget();
|
|
|
|
|
scrollWidget->deleteLater();
|
|
|
|
|
scrollWidget = new QWidget();
|
|
|
|
|
scrollLayout->deleteLater();
|
|
|
|
|
scrollLayout = new QVBoxLayout();
|
|
|
|
|
scrollWidget->setLayout(scrollLayout);
|
|
|
|
|
|
|
|
|
|
qDebug() << "currentPage:" << currentPage;
|
|
|
|
|
|
|
|
|
|
QSqlQuery query(meituanDb);
|
|
|
|
|
|
|
|
|
|
while (currentHead < showLimit)
|
|
|
|
|
{
|
|
|
|
|
//判断是否换表
|
|
|
|
|
if (currentOffset >= lengthList[currentCate])
|
|
|
|
|
{
|
|
|
|
|
currentCate += 1;
|
|
|
|
|
currentOffset = 0;
|
|
|
|
|
if (currentCate >= cateList.length())
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
//查询数据
|
|
|
|
|
query.prepare("select * from " + cateList[currentCate] + " where title like :segment limit :offset , :showLimit");
|
|
|
|
|
query.bindValue(":segment", "%" + segment + "%");
|
|
|
|
|
query.bindValue(":offset", currentOffset);
|
|
|
|
|
qDebug() << "currentCate:" << currentCate;
|
|
|
|
|
// qDebug() << "offset:" << offset;
|
|
|
|
|
query.bindValue(":showLimit", showLimit);
|
|
|
|
|
queryDatabase(query);
|
|
|
|
|
// qDebug() << "query success";
|
|
|
|
|
//设置按钮
|
|
|
|
|
setBtns();
|
|
|
|
|
// qDebug() << "set buttons success";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//设置滚动界面布局
|
|
|
|
|
for (int i = currentHead; i < currentHead + currentQueryLength; i++)
|
|
|
|
|
{
|
|
|
|
|
scrollLayout->addWidget(btnList[i]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
currentOffset += currentQueryLength;
|
|
|
|
|
currentHead += currentQueryLength;
|
|
|
|
|
}
|
|
|
|
|
page2cate[currentPage] = currentCate;
|
|
|
|
|
page2offset[currentPage] = currentOffset;
|
|
|
|
|
|
|
|
|
|
scroll->setWidget(scrollWidget);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SearchWidget::showResult()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
totalNum = 0;
|
|
|
|
|
pageNum = 0;
|
|
|
|
|
getTotalNum();
|
|
|
|
|
qDebug() << "totalNum:" << totalNum;
|
|
|
|
|
qDebug() << "pageNum:" << pageNum;
|
|
|
|
|
currentPage = 1;
|
|
|
|
|
currentCate = 0;
|
|
|
|
|
currentOffset = 0;
|
|
|
|
|
page2cate[0] = currentCate;
|
|
|
|
|
page2offset[0] = currentOffset;
|
|
|
|
|
if (totalNum)
|
|
|
|
|
{
|
|
|
|
|
querySet();
|
|
|
|
|
subWidget->setVisible(true);
|
|
|
|
|
nullWidget->setVisible(false);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
subWidget->setVisible(false);
|
|
|
|
|
nullWidget->setVisible(true);
|
|
|
|
|
}
|
|
|
|
|
web->setVisible(false);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SearchWidget::returnWeb()
|
|
|
|
|
{
|
|
|
|
|
subWidget->setVisible(true);
|
|
|
|
|
web->setVisible(false);
|
|
|
|
|
nullWidget->setVisible(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SearchWidget::pageUp()
|
|
|
|
|
{
|
|
|
|
|
currentPage--;
|
|
|
|
|
if (currentPage < 1)
|
|
|
|
|
{
|
|
|
|
|
currentPage = 1;
|
|
|
|
|
qDebug("这是第一页");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
rollTop();
|
|
|
|
|
querySet();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SearchWidget::pageDown()
|
|
|
|
|
{
|
|
|
|
|
currentPage++;
|
|
|
|
|
if (currentPage > pageNum)
|
|
|
|
|
{
|
|
|
|
|
currentPage = pageNum;
|
|
|
|
|
qDebug("已经是最后一页了!");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
rollTop();
|
|
|
|
|
querySet();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SearchWidget::rollTop()
|
|
|
|
|
{
|
|
|
|
|
QScrollBar *scrollBar = scroll->verticalScrollBar();
|
|
|
|
|
scrollBar->setValue(scrollBar->minimum());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|