diff --git a/src/ChangShaTour/ChangShaTour.pro b/src/ChangShaTour/ChangShaTour.pro index 6fcd0e1..535bfde 100644 --- a/src/ChangShaTour/ChangShaTour.pro +++ b/src/ChangShaTour/ChangShaTour.pro @@ -33,12 +33,13 @@ SOURCES += \ mainwidget.cpp \ mainwindow.cpp \ planwidget.cpp \ + popwidget.cpp \ preferencewidget.cpp \ recommendwidget.cpp \ registermanager.cpp \ registerwidget.cpp \ routechoicewidget.cpp \ - searchresultwidget.cpp \ + searchwidget.cpp \ showplaceinfowidget.cpp \ showrouteinfowidget.cpp \ smtp.cpp \ @@ -64,12 +65,13 @@ HEADERS += \ mainwidget.h \ mainwindow.h \ planwidget.h \ + popwidget.h \ preferencewidget.h \ recommendwidget.h \ registermanager.h \ registerwidget.h \ routechoicewidget.h \ - searchresultwidget.h \ + searchwidget.h \ showplaceinfowidget.h \ showrouteinfowidget.h \ smtp.h \ @@ -92,15 +94,18 @@ FORMS += \ mainwidget.ui \ mainwindow.ui \ planwidget.ui \ + popwidget.ui \ preferencewidget.ui \ recommendwidget.ui \ registerwidget.ui \ routechoicewidget.ui \ + searchwidget.ui \ showplaceinfowidget.ui \ showrouteinfowidget.ui \ sortwidget.ui \ userinfowidget.ui \ userwidget.ui \ + waitwidget.ui \ webwidget.ui # Default rules for deployment. diff --git a/src/ChangShaTour/ChangShaTour.pro.user b/src/ChangShaTour/ChangShaTour.pro.user index 4f9bd9d..ff40fb2 100644 --- a/src/ChangShaTour/ChangShaTour.pro.user +++ b/src/ChangShaTour/ChangShaTour.pro.user @@ -1,10 +1,10 @@ - + EnvironmentId - {5009ac75-b61d-4c91-8540-bc9e10b6e582} + {61ba832e-6c30-4ab6-b0b8-ace44f46ca0c} ProjectExplorer.Project.ActiveTarget @@ -44,8 +44,8 @@ true 0 8 - true - 1 + false + 0 true true true @@ -55,21 +55,23 @@ ProjectExplorer.Project.PluginSettings - + + -fno-delayed-template-parsing + true ProjectExplorer.Project.Target.0 - Desktop Qt 5.14.2 GCC 64bit - Desktop Qt 5.14.2 GCC 64bit - qt.qt5.5142.gcc_64_kit + Desktop Qt 5.14.2 MSVC2017 64bit + Desktop Qt 5.14.2 MSVC2017 64bit + qt.qt5.5142.win64_msvc2017_64_kit 0 0 0 - /home/extra/Study/2021SpringTerm/Architecture/TourInChangSha/src/build-ChangShaTour-Desktop_Qt_5_14_2_GCC_64bit-Debug + D:/Study/SE/project/code/Trip-in-Chang-sha-main-4/Trip-in-Chang-sha-main/build-ChangShaTour-Desktop_Qt_5_14_2_MSVC2017_64bit-Debug true @@ -117,7 +119,7 @@ 2 - /home/extra/Study/2021SpringTerm/Architecture/TourInChangSha/src/build-ChangShaTour-Desktop_Qt_5_14_2_GCC_64bit-Release + D:/Study/SE/project/code/Trip-in-Chang-sha-main-4/Trip-in-Chang-sha-main/build-ChangShaTour-Desktop_Qt_5_14_2_MSVC2017_64bit-Release true @@ -165,7 +167,7 @@ 0 - /home/extra/Study/2021SpringTerm/Architecture/TourInChangSha/src/build-ChangShaTour-Desktop_Qt_5_14_2_GCC_64bit-Profile + D:/Study/SE/project/code/Trip-in-Chang-sha-main-4/Trip-in-Chang-sha-main/build-ChangShaTour-Desktop_Qt_5_14_2_MSVC2017_64bit-Profile true @@ -285,8 +287,9 @@ 2 - Qt4ProjectManager.Qt4RunConfiguration:/home/extra/Study/2021SpringTerm/Architecture/TourInChangSha/src/ChangShaTour/ChangShaTour.pro - /home/extra/Study/2021SpringTerm/Architecture/TourInChangSha/src/ChangShaTour/ChangShaTour.pro + ChangShaTour2 + Qt4ProjectManager.Qt4RunConfiguration:D:/ChangShaTour/ChangShaTour.pro + D:/ChangShaTour/ChangShaTour.pro false @@ -297,14 +300,500 @@ false true - /home/extra/Study/2021SpringTerm/Architecture/TourInChangSha/src/build-ChangShaTour-Desktop_Qt_5_14_2_GCC_64bit-Debug + D:/Study/SE/project/code/Trip-in-Chang-sha-main-4/Trip-in-Chang-sha-main/build-ChangShaTour-Desktop_Qt_5_14_2_MSVC2017_64bit-Debug + + 1 + + + + ProjectExplorer.Project.Target.1 + + Desktop Qt 5.14.2 MinGW 32-bit + Desktop Qt 5.14.2 MinGW 32-bit + qt.qt5.5142.win32_mingw73_kit + 0 + 0 + 0 + + D:/Study/SE/project/code/Trip-in-Chang-sha-main-4/Trip-in-Chang-sha-main/build-ChangShaTour-Desktop_Qt_5_14_2_MinGW_32_bit-Debug + + + true + QtProjectManager.QMakeBuildStep + true + + false + false + false + + + true + Qt4ProjectManager.MakeStep + + false + + + false + + 2 + Build + Build + ProjectExplorer.BuildSteps.Build + + + + true + Qt4ProjectManager.MakeStep + + true + clean + + false + + 1 + Clean + Clean + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Debug + Qt4ProjectManager.Qt4BuildConfiguration + 2 + + + D:/Study/SE/project/code/Trip-in-Chang-sha-main-4/Trip-in-Chang-sha-main/build-ChangShaTour-Desktop_Qt_5_14_2_MinGW_32_bit-Release + + + true + QtProjectManager.QMakeBuildStep + false + + false + false + true + + + true + Qt4ProjectManager.MakeStep + + false + + + false + + 2 + Build + Build + ProjectExplorer.BuildSteps.Build + + + + true + Qt4ProjectManager.MakeStep + + true + clean + + false + + 1 + Clean + Clean + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Release + Qt4ProjectManager.Qt4BuildConfiguration + 0 + + + D:/Study/SE/project/code/Trip-in-Chang-sha-main-4/Trip-in-Chang-sha-main/build-ChangShaTour-Desktop_Qt_5_14_2_MinGW_32_bit-Profile + + + true + QtProjectManager.QMakeBuildStep + true + + false + true + true + + + true + Qt4ProjectManager.MakeStep + + false + + + false + + 2 + Build + Build + ProjectExplorer.BuildSteps.Build + + + + true + Qt4ProjectManager.MakeStep + + true + clean + + false + + 1 + Clean + Clean + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Profile + Qt4ProjectManager.Qt4BuildConfiguration + 0 + + 3 + + + 0 + Deploy + Deploy + ProjectExplorer.BuildSteps.Deploy + + 1 + ProjectExplorer.DefaultDeployConfiguration + + 1 + + + dwarf + + cpu-cycles + + + 250 + + -e + cpu-cycles + --call-graph + dwarf,4096 + -F + 250 + + -F + true + 4096 + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + kcachegrind + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + 2 + + + ProjectExplorer.CustomExecutableRunConfiguration + + + false + + false + true + false + false + true + + + + 1 + + + + ProjectExplorer.Project.Target.2 + + Desktop Qt 5.14.2 MinGW 64-bit + Desktop Qt 5.14.2 MinGW 64-bit + qt.qt5.5142.win64_mingw73_kit + 0 + 0 + 0 + + D:/Study/SE/project/code/Trip-in-Chang-sha-main-4/Trip-in-Chang-sha-main/build-ChangShaTour-Desktop_Qt_5_14_2_MinGW_64_bit-Debug + + + true + QtProjectManager.QMakeBuildStep + true + + false + false + false + + + true + Qt4ProjectManager.MakeStep + + false + + + false + + 2 + Build + Build + ProjectExplorer.BuildSteps.Build + + + + true + Qt4ProjectManager.MakeStep + + true + clean + + false + + 1 + Clean + Clean + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Debug + Qt4ProjectManager.Qt4BuildConfiguration + 2 + + + D:/Study/SE/project/code/Trip-in-Chang-sha-main-4/Trip-in-Chang-sha-main/build-ChangShaTour-Desktop_Qt_5_14_2_MinGW_64_bit-Release + + + true + QtProjectManager.QMakeBuildStep + false + + false + false + true + + + true + Qt4ProjectManager.MakeStep + + false + + + false + + 2 + Build + Build + ProjectExplorer.BuildSteps.Build + + + + true + Qt4ProjectManager.MakeStep + + true + clean + + false + + 1 + Clean + Clean + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Release + Qt4ProjectManager.Qt4BuildConfiguration + 0 + + + D:/Study/SE/project/code/Trip-in-Chang-sha-main-4/Trip-in-Chang-sha-main/build-ChangShaTour-Desktop_Qt_5_14_2_MinGW_64_bit-Profile + + + true + QtProjectManager.QMakeBuildStep + true + + false + true + true + + + true + Qt4ProjectManager.MakeStep + + false + + + false + + 2 + Build + Build + ProjectExplorer.BuildSteps.Build + + + + true + Qt4ProjectManager.MakeStep + + true + clean + + false + + 1 + Clean + Clean + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Profile + Qt4ProjectManager.Qt4BuildConfiguration + 0 + + 3 + + + 0 + Deploy + Deploy + ProjectExplorer.BuildSteps.Deploy + + 1 + ProjectExplorer.DefaultDeployConfiguration + + 1 + + + dwarf + + cpu-cycles + + + 250 + + -e + cpu-cycles + --call-graph + dwarf,4096 + -F + 250 + + -F + true + 4096 + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + kcachegrind + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + 2 + + + ProjectExplorer.CustomExecutableRunConfiguration + + + false + + false + true + false + false + true + + 1 ProjectExplorer.Project.TargetCount - 1 + 3 ProjectExplorer.Project.Updater.FileVersion diff --git a/src/ChangShaTour/RouteItem.h b/src/ChangShaTour/RouteItem.h new file mode 100644 index 0000000..cd30a99 --- /dev/null +++ b/src/ChangShaTour/RouteItem.h @@ -0,0 +1,21 @@ +#include +#include +#ifndef ROUTEITEM_H +#define ROUTEITEM_H +struct routeItem{ + QString placeName; + QString url; + QString cateId; + QString startTime; + QString endTime; + QString traffic; + int distance; + int timeCost; + QString description; + struct routeItem * next; +}; +typedef struct routeItem RouteItem; + + + +#endif // ROUTEITEM_H diff --git a/src/ChangShaTour/customizewidget.cpp b/src/ChangShaTour/customizewidget.cpp index 9128839..9b4905a 100644 --- a/src/ChangShaTour/customizewidget.cpp +++ b/src/ChangShaTour/customizewidget.cpp @@ -6,9 +6,126 @@ CustomizeWidget::CustomizeWidget(QWidget *parent) : ui(new Ui::CustomizeWidget) { ui->setupUi(this); + + num = 1; + limit = 15; + + mainLayout = new QVBoxLayout(); + + lineList = (QHBoxLayout **)malloc(sizeof(QHBoxLayout *) * limit); + labelList = (QLabel **)malloc(sizeof(QLabel *) * limit); + placeBtnList = (QPushButton **)malloc(sizeof(QPushButton *) * limit); + addBtnList = (QPushButton **)malloc(sizeof(QPushButton *) * limit); + delBtnList = (QPushButton **)malloc(sizeof(QPushButton *) * limit); + for(int i = 0; i < limit; i++) + { + nameList.append(""); + urlList.append(""); + cateIdList.append(""); + } + + spaceList = (QHBoxLayout **)malloc(sizeof(QHBoxLayout *) * (limit - 1)); + spacers = (QLabel **)malloc(sizeof(QLabel *) * (limit - 1)); + + this->setLayout(mainLayout); + + for (int i = 0; i < limit; i++) + { + lineList[i] = new QHBoxLayout(); + labelList[i] = new QLabel(QString::number(i+1)); + labelList[i]->setAlignment(Qt::AlignCenter); + placeBtnList[i] = new QPushButton(""); + addBtnList[i] = new QPushButton("add"); + delBtnList[i] = new QPushButton("del"); + + mainLayout->addLayout(lineList[i]); + + lineList[i]->setAlignment(Qt::AlignTop); + + lineList[i]->addWidget(labelList[i],1); + lineList[i]->addWidget(placeBtnList[i],12); + lineList[i]->addWidget(addBtnList[i],2); + lineList[i]->addWidget(delBtnList[i],2); + + connect(placeBtnList[i], &QPushButton::clicked, this, [=](){setBtn(i);}); + connect(addBtnList[i], &QPushButton::clicked, this, [=](){addAt(i);}); + connect(delBtnList[i], &QPushButton::clicked, this, [=](){delAt(i);}); + + if (i > 0) + { + visibleAt(i, false); + } + } + + for (int i = 0; i < (limit - 1); i++) + { + spaceList[i] = new QHBoxLayout(); + spacers[i] = new QLabel(); + spaceList[i]->addWidget(spacers[i]); + mainLayout->addLayout(spaceList[i]); + } } CustomizeWidget::~CustomizeWidget() { delete ui; } + +void CustomizeWidget::visibleAt(int index, bool flag) +{ + labelList[index]->setVisible(flag); + placeBtnList[index]->setVisible(flag); + addBtnList[index]->setVisible(flag); + delBtnList[index]->setVisible(flag); +// if (flag) +// placeBtnList[index]->setText("Choose Place"); +// else +// placeBtnList[index]->setText(""); +} + +void CustomizeWidget::addAt(int index) +{ + if (num < limit) + { + num++; + visibleAt(num - 1, true); + spacers[limit - num]->setVisible(false); + qDebug() << "Add at " << QString::number(index); + + for (int i = num - 1; i > index + 1; i--) + { + nameList[i] = nameList[i - 1]; + placeBtnList[i]->setText(nameList[i]); + } + nameList[index + 1] = ""; + placeBtnList[index + 1]->setText(nameList[index + 1]); + } +} + +void CustomizeWidget::delAt(int index) +{ + if (num > 1) + { + num--; + visibleAt(num, false); + spacers[limit - num - 1]->setVisible(true); + qDebug() << "Del at " << QString::number(index); + + for (int i = index; i < num ; i++) + { + nameList[i] = nameList[i + 1]; + placeBtnList[i]->setText(nameList[i]); + } + nameList[num] = ""; + placeBtnList[num]->setText(nameList[index + 1]); + } +} + +void CustomizeWidget::setBtn(int index) +{ + PopWidget * w = new PopWidget(); + w->show(); + connect(w->getConfirmBtn(), &QPushButton::clicked, this, [=](){w->close();}); + connect(w->getCancelBtn(), &QPushButton::clicked, this, [=](){w->close();}); + qDebug() << "Set Btn" << QString::number(index); +} diff --git a/src/ChangShaTour/customizewidget.h b/src/ChangShaTour/customizewidget.h index 9ac9a89..17ed5f1 100644 --- a/src/ChangShaTour/customizewidget.h +++ b/src/ChangShaTour/customizewidget.h @@ -2,6 +2,15 @@ #define CUSTOMIZEWIDGET_H #include +#include +#include +#include +#include +#include +#include +#include +#include +#include "popwidget.h" #if _MSC_VER >= 1600 #pragma execution_character_set("utf-8") @@ -19,8 +28,31 @@ public: explicit CustomizeWidget(QWidget *parent = nullptr); ~CustomizeWidget(); + void visibleAt(int index, bool flag); + void addAt(int index); + void delAt(int index); + void setBtn(int index); + QString getBtn(int index); + private: Ui::CustomizeWidget *ui; + + int num; + int limit; + QStringList nameList; + QStringList urlList; + QStringList cateIdList; + + QHBoxLayout **lineList; + QLabel **labelList; + QPushButton **placeBtnList; + QPushButton **addBtnList; + QPushButton ** delBtnList; + + QHBoxLayout ** spaceList; + QLabel **spacers; + + QVBoxLayout *mainLayout; }; #endif // CUSTOMIZEWIDGET_H diff --git a/src/ChangShaTour/listwidget.cpp b/src/ChangShaTour/listwidget.cpp index 7fbb7d6..301f587 100644 --- a/src/ChangShaTour/listwidget.cpp +++ b/src/ChangShaTour/listwidget.cpp @@ -170,7 +170,7 @@ void ListWidget::setHotList() queryMeituan.bindValue(":url", url); QStringList list = queryMeituanDatabase(queryMeituan);//获得图片链接和店铺名和id imgDownloader *imgDownload = new imgDownloader(); - QString imgPath = "D:/Study/SE/project/images/" + labelToDb[cate] + list[2] + ".png"; + QString imgPath = "./images/" + labelToDb[cate] + list[2] + ".png"; imgDownload->downloadFileFromUrl(list[0], imgPath); btn = setBtn(btn, imgPath, list[1]); connect(btn, &QToolButton::clicked, this, [=](){web->loadPage(url, cate); subWidget->setVisible(false); web->setVisible(true);}); diff --git a/src/ChangShaTour/mainwidget.cpp b/src/ChangShaTour/mainwidget.cpp index b1a9231..8eeda87 100644 --- a/src/ChangShaTour/mainwidget.cpp +++ b/src/ChangShaTour/mainwidget.cpp @@ -21,7 +21,7 @@ MainWidget::MainWidget(QWidget *parent) : homeWidget = new HomeWidget(this); userWidget = new UserWidget(this); - searchWidget = new SearchResultWidget(this); + searchWidget = new SearchWidget(this); userWidget->setVisible(false); searchWidget->setVisible(false); diff --git a/src/ChangShaTour/mainwidget.h b/src/ChangShaTour/mainwidget.h index bdf7aa1..9f3eb56 100644 --- a/src/ChangShaTour/mainwidget.h +++ b/src/ChangShaTour/mainwidget.h @@ -9,7 +9,7 @@ #include #include "homewidget.h" #include "userwidget.h" -#include "searchresultwidget.h" +#include "searchwidget.h" #if _MSC_VER >= 1600 #pragma execution_character_set("utf-8") @@ -42,7 +42,7 @@ private: HomeWidget *homeWidget; UserWidget *userWidget; - SearchResultWidget *searchWidget; + SearchWidget *searchWidget; public slots: void switchToHome(); diff --git a/src/ChangShaTour/mainwindow.cpp b/src/ChangShaTour/mainwindow.cpp index 39cd93a..fbec060 100644 --- a/src/ChangShaTour/mainwindow.cpp +++ b/src/ChangShaTour/mainwindow.cpp @@ -37,10 +37,13 @@ void MainWindow::switchToMain() { //setMaximumSize(QSize(1330,1000)); // showMaximized(); + WaitStart(); loginWidget->deleteLater(); - mainWidget = new MainWidget(); + mainWidget = new MainWidget(this); + WaitEnd(); resize(1600, 900); setCentralWidget(mainWidget); + move ((QApplication::desktop()->width() - this->width())/2,(QApplication::desktop()->height() - this->height())/2); } else { @@ -91,6 +94,18 @@ void MainWindow::switchToLogin() setCentralWidget(loginWidget); } +void MainWindow::WaitStart() +{ + waitProcess = new QProcess(this); + QStringList arguments; + waitProcess->start("./Wait/Wait.exe"); +} + +void MainWindow::WaitEnd() +{ + waitProcess->kill(); +} + MainWindow::~MainWindow() { delete ui; diff --git a/src/ChangShaTour/mainwindow.h b/src/ChangShaTour/mainwindow.h index dbad5c0..cc0e34f 100644 --- a/src/ChangShaTour/mainwindow.h +++ b/src/ChangShaTour/mainwindow.h @@ -2,6 +2,8 @@ #define MAINWINDOW_H #include +#include +#include #include "loginwidget.h" #include "mainwidget.h" #include "loginmanager.h" @@ -32,6 +34,7 @@ private: RegisterWidget *registerWidget; RegisterManager * registerManager; + QProcess * waitProcess; public slots: void switchToMain(); @@ -39,5 +42,7 @@ public slots: void switchToLogin(); void registerConfirmSwitch(); void clickGetVerificationCodeButton(); + void WaitStart(); + void WaitEnd(); }; #endif // MAINWINDOW_H diff --git a/src/ChangShaTour/popwidget.cpp b/src/ChangShaTour/popwidget.cpp new file mode 100644 index 0000000..1c00b8c --- /dev/null +++ b/src/ChangShaTour/popwidget.cpp @@ -0,0 +1,242 @@ +#include "popwidget.h" +#include "ui_popwidget.h" + +PopWidget::PopWidget(QWidget *parent) : + QWidget(parent), + ui(new Ui::PopWidget) +{ + ui->setupUi(this); + + this->setWindowModality(Qt::ApplicationModal); + this->setFixedSize(QSize(400,1000)); + + chosen.append(""); + chosen.append(""); + chosen.append(""); + showLimit = 15; + currentPage = 1; + offset = 0; + btnList = (QToolButton **)malloc(sizeof(QToolButton *) * showLimit); + + mainLayout = new QVBoxLayout(); + + notify = new QLabel("请从您的收藏夹中选择场所添加到路线中"); + notify->setAlignment(Qt::AlignCenter); + + searchLine = new QHBoxLayout(); + searchBar = new QLineEdit(); + searchBtn = new QPushButton("搜索"); + returnSearchBtn = new QPushButton("退出搜索"); + + scroll = new QScrollArea(); + scrollWidget = new QWidget; + scrollLayout = new QVBoxLayout(); + + pageLine = new QHBoxLayout(); + up = new QPushButton("上一页"); + down = new QPushButton("下一页"); + + chosenLabel = new QLabel("您还未选择场所..."); + chosenLabel->setAlignment(Qt::AlignLeft); + + closeLine = new QHBoxLayout(); + confirm = new QPushButton("确认"); + cancel = new QPushButton("取消"); + + this->setLayout(mainLayout); + + mainLayout->addWidget(notify); + mainLayout->addLayout(searchLine); + mainLayout->addWidget(scroll); + mainLayout->addLayout(pageLine); + mainLayout->addWidget(chosenLabel); + mainLayout->addLayout(closeLine); + + searchLine->addWidget(searchBar, 6); + searchLine->addWidget(searchBtn, 1); + +// scrollWidget->setLayout(scrollLayout); +// //查询数据库,进行按钮布局 +// scroll->setWidget(scrollWidget); + getTotalNum(); + setScreen(); + + pageLine->addWidget(up); + pageLine->addWidget(down); + + closeLine->addWidget(confirm); + closeLine->addWidget(cancel); + + connect(up, &QPushButton::clicked, this, &PopWidget::pageUp); + connect(down, &QPushButton::clicked, this, &PopWidget::pageDown); +} + +PopWidget::~PopWidget() +{ + delete ui; +} + +QPushButton * PopWidget::getConfirmBtn() +{ + return confirm; +} + +QPushButton * PopWidget::getCancelBtn() +{ + return cancel; +} + +//从店铺收藏夹获取店铺 +void PopWidget::getTotalNum() +{ + //查询条目数 + QSqlQuery query(userDb); + + query.prepare("select count(*) as num from favPlaces where userId = :id"); + query.bindValue(":id", Id); + query.exec(); + query.next(); + qDebug() << " popWidget totalNum:" << query.value("num"); + totalNum = query.value("num").value(); + + pageNum = (totalNum + showLimit - 1)/showLimit; + +} + +void PopWidget::queryDatabase() +{ + QSqlQuery query(userDb); + + query.prepare("select * from favPlaces where userId = :id limit :offset, :limit"); + query.bindValue(":id", Id); + query.bindValue(":offset", offset); + query.bindValue(":limit", showLimit); + query.exec(); + int i = 0; + while(query.next()==true) + { + QVariant detail = query.value("url"); + + urlList.append(detail.value()); + i++; + } + currentNum = i; + qDebug() << "popWidget currentNum:" << currentNum; + +} + +QToolButton * PopWidget::setBtn(QToolButton *btn, QString text, QString img) +{ + if(img != "") + btn->setIcon(QIcon(img)); + btn->setText(text); + btn->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); + btn->setIconSize(QSize(100,200)); + btn->setFixedSize(300,100); + + return btn; +} + +void PopWidget::setBtns() +{ + int i = 0; + for (i; i < currentNum; i++) + { + int index = i; + //下载图片到本地 +// QString imgPath = "D:/Study/SE/project/images/" + cateList[currentCate] + QString::number(idList[index]) + ".png"; +// imgDownloader *download = new imgDownloader(); +// download->downloadFileFromUrl(imgList[index], imgPath); + btnList[index] = setBtn(btnList[index], urlList[index], "D:/Study/SE/project/images/transparent.png"); + disconnect(btnList[index], 0, 0, 0); + connect(btnList[index], &QToolButton::clicked, this, [=](){setChosen(index);}); + } +} + +void PopWidget::setChosen(int index) +{ + if (urlList[index] != chosen[1]) + { +// chosen[0] = nameList[index]; + chosen[1] = urlList[index]; +// chosen[2] = imgList[index]; + qDebug() << "popWidget chosen:" + chosen[0] + chosen[1] + chosen[2]; + chosenLabel->setText("您选择了" + chosen[1]); + } + else + { + chosen[0] = ""; + chosen[1] = ""; + chosen[2] = ""; + chosenLabel->setText("您还未选择场所..."); + } +} + +void PopWidget::setScreen() +{ + qDebug() << "popWidget currentPage:" << currentPage; + qDebug() << "popWidget offset:" << offset; + urlList.clear(); + imgList.clear(); + nameList.clear(); + for (int i = 0; i < showLimit; i++) + btnList[i] = new QToolButton(); + + queryDatabase(); + qDebug("query success"); + setBtns(); + qDebug("setBtns success"); + + scroll->takeWidget(); + scrollWidget->deleteLater(); + scrollWidget = new QWidget(); + scrollLayout->deleteLater(); + scrollLayout = new QVBoxLayout(); + scrollWidget->setLayout(scrollLayout); + + for (int i = 0; i < currentNum; i++) + { + scrollLayout->addWidget(btnList[i]); + } + + scroll->setWidget(scrollWidget); + +} + +void PopWidget::pageUp() +{ + currentPage--; + if (currentPage < 1) + { + currentPage = 1; + qDebug("这是第一页"); + } + else + { + offset -= showLimit; + rollTop(); + setScreen(); + } +} + +void PopWidget::pageDown() +{ + currentPage++; + if (currentPage > pageNum) + { + currentPage = pageNum; + qDebug("已经是最后一页了!"); + } + else + { + offset += showLimit; + rollTop(); + setScreen(); + } +} + +void PopWidget::rollTop() +{ + QScrollBar *scrollBar = scroll->verticalScrollBar(); + scrollBar->setValue(scrollBar->minimum()); +} diff --git a/src/ChangShaTour/popwidget.h b/src/ChangShaTour/popwidget.h new file mode 100644 index 0000000..78a9aa1 --- /dev/null +++ b/src/ChangShaTour/popwidget.h @@ -0,0 +1,86 @@ +#ifndef POPWIDGET_H +#define POPWIDGET_H + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "cglobal.h" + +#if _MSC_VER >= 1600 +#pragma execution_character_set("utf-8") +#endif + +namespace Ui { +class PopWidget; +} + +class PopWidget : public QWidget +{ + Q_OBJECT + +public: + explicit PopWidget(QWidget *parent = nullptr); + ~PopWidget(); + + QPushButton * getConfirmBtn(); + QPushButton * getCancelBtn(); + void getTotalNum(); + void queryDatabase(); + void pageUp(); + void pageDown(); + void setScreen(); + void setBtns(); + QToolButton * setBtn(QToolButton *btn, QString text, QString img); + void setChosen(int index); + void rollTop(); + +private: + Ui::PopWidget *ui; + + bool inSearch; + QStringList chosen;//被选中的场所在当,有三个值name,url,img + int totalNum;//收藏夹总共有多少条 + int showLimit;//一页中最多显示条数 + int pageNum;//总页数 + int currentPage;//当前所在页数 + int currentNum;//当前页中条目数量 + int offset;//query语句中的偏移量 + QStringList nameList; + QStringList urlList; + QStringList imgList; + QToolButton **btnList; + + QVBoxLayout *mainLayout; + + QLabel *notify; + + QHBoxLayout *searchLine; + QLineEdit *searchBar; + QPushButton *searchBtn; + QPushButton *returnSearchBtn; + + QScrollArea *scroll; + QWidget *scrollWidget; + QVBoxLayout *scrollLayout; + + QHBoxLayout *pageLine; + QPushButton *up; + QPushButton *down; + + QLabel *chosenLabel; + + QHBoxLayout *closeLine; + QPushButton *confirm; + QPushButton *cancel; +}; + +#endif // POPWIDGET_H diff --git a/src/ChangShaTour/popwidget.ui b/src/ChangShaTour/popwidget.ui new file mode 100644 index 0000000..c79c892 --- /dev/null +++ b/src/ChangShaTour/popwidget.ui @@ -0,0 +1,21 @@ + + + + + PopWidget + + + + 0 + 0 + 400 + 300 + + + + Form + + + + + diff --git a/src/ChangShaTour/recommendwidget.cpp b/src/ChangShaTour/recommendwidget.cpp index 0623c95..49c4d9a 100644 --- a/src/ChangShaTour/recommendwidget.cpp +++ b/src/ChangShaTour/recommendwidget.cpp @@ -151,10 +151,7 @@ void RecommendWidget::setBtns() { int index = i * column + j; //下载图片到本地 -// QString imgPath = ":/images" + idList[index] + ".jpg"; - QString imgPath = "C:/Users/13648/Desktop/Trip-in-Chang-sha/ChangShaTour/images/"+labelToDb[cateIdList[index]] + QString::number(idList[index]) + ".png"; -// qDebug() << QDir::currentPath(); -// QString imgPath = "D:/Study/SE/project/images/" + labelToDb[cateIdList[index]] + QString::number(idList[index]) + ".png"; + QString imgPath = "./images/" + labelToDb[cateIdList[index]] + QString::number(idList[index]) + ".png"; imgDownloader *download = new imgDownloader(); download->downloadFileFromUrl(imgList[index], imgPath); qDebug()<next=NULL; +} +//route结构体使用方式和query类似 +//Route * oneRoute = getAllItems(); +//while (oneRoute->next!=NULL) +//{ +// oneRoute=oneRoute->next; +// url=oneRoute->url; +//} +RouteItem * Route::getAllItems() +{ + return this->routeItems; +} +int Route::getRouteId() +{ + return this->routeId; +} +QString Route::getRouteName() +{ + return this->routeName; +} +int Route::getUserId() +{ + return this->userId; +} +void Route::setRouteName(QString name) +{ + this->routeName = name; +} +void Route::setUserId(int id) +{ + this->userId=id; +} +void Route::setRouteId(int id) +{ + this->routeId=id; +} +void Route::setAllItems(QStringList titleList,QStringList urlList,QStringList cateIdList,QStringList startTimeList,QStringList endTimeList,QStringList trafficList,int * distanceList,int * timeCostList,QStringList descriptionList) +{ + RouteItem * head= routeItems; + RouteItem * p; + int totalSize=titleList.size(); + int i; + for(i=0;iplaceName = titleList[i]; + p->url = urlList[i]; + p->cateId = cateIdList[i]; + p->startTime = startTimeList[i]; + p->endTime = endTimeList[i]; + p->traffic = trafficList[i]; + p->distance = distanceList[i]; + p->timeCost = timeCostList[i]; + p->description = descriptionList[i]; + p->next = NULL; + head->next = p; + head=head->next; + } +} +//删除和添加都是根据位置,位置从1开始计数 +RouteItem * Route::addItem(RouteItem * oneItem,int locate) +{ + RouteItem * p = routeItems; + int i = 0; + while(p->next != NULL&&inext; + i++; + } + oneItem->next = p->next; + p->next=oneItem; + return routeItems; +} +RouteItem * Route::deleteItem(int locate) +{ + RouteItem * p = routeItems; + RouteItem * pre = routeItems; + int i = 0; + while(p->next != NULL&&inext; + i++; + } + pre->next = p->next; + free(p); + return routeItems; + +} diff --git a/src/ChangShaTour/route.h b/src/ChangShaTour/route.h new file mode 100644 index 0000000..a790053 --- /dev/null +++ b/src/ChangShaTour/route.h @@ -0,0 +1,28 @@ +#ifndef ROUTE_H +#define ROUTE_H +#include +#include + +class Route +{ +public: + Route(); + struct routeItem * getAllItems(); + //距离和时间都用int表示,单位m/km,时间s/min,统一一下 + void setAllItems(QStringList titleList,QStringList urlList,QStringList cateIdList,QStringList startTimeList,QStringList endTimeList,QStringList trafficList,int *distanceList,int *timeCostList,QStringList descriptionList); + int getRouteId(); + int getUserId(); + QString getRouteName(); + void setRouteName(QString name); + void setRouteId(int id); + void setUserId(int id); + RouteItem * addItem(RouteItem * oneItem,int locate); + RouteItem * deleteItem(int locate); +private: + QString name; + int userId=0;//路线没有用户时默认为0 + int routeId=0;//路线编号默认为0 + struct routeItem *routeItems; +}; + +#endif // ROUTE_H diff --git a/src/ChangShaTour/searchresultwidget.cpp b/src/ChangShaTour/searchresultwidget.cpp deleted file mode 100644 index cecfdab..0000000 --- a/src/ChangShaTour/searchresultwidget.cpp +++ /dev/null @@ -1,311 +0,0 @@ -#include "searchresultwidget.h" - -SearchResultWidget::SearchResultWidget(QWidget *parent) : QWidget(parent) -{ - 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); - for (int i = 0; i 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, &SearchResultWidget::returnWeb); - connect(up, &QPushButton::clicked, this, &SearchResultWidget::pageUp); - connect(down, &QPushButton::clicked, this, &SearchResultWidget::pageDown); - -} - -QPushButton *SearchResultWidget::getReturnBtn() -{ - return rtn; -} - -void SearchResultWidget::sendInput(QString input) -{ - this->segment = input; - qDebug() << "segment:" <(); - totalNum += query.value("num").value(); - } - - pageNum = (totalNum + showLimit - 1)/showLimit; - page2cate = (int *)malloc(sizeof(int) * pageNum); - page2offset = (int *)malloc(sizeof(int) * pageNum); - -} - -void SearchResultWidget::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 score = QString::number(avgscore.value()); - QString commentNum = QString::number(comments.value()); - QString addr = address.value(); -// QString price = QString::number(avgprice.value()); - QString text = name + "\n" + score + "分 " + commentNum + "条评论\n" + addr + "\n";// + "人均" + price + "元"; - QString cateid = cateId.value(); - - idList[i] = id.value(); - urlList.append(detail.value()); - imgList.append(frontimg.value()); - textList.append(text); - cateIdList.append(cateid); - i++; - } - currentQueryLength = i - currentHead; -} - -QToolButton *SearchResultWidget::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 SearchResultWidget::setBtns() -{ - int i = currentHead; -// qDebug() << "currentHead:" << currentHead; -// qDebug() << "currentQueryLength:" << currentQueryLength; - for (i; i < currentHead + currentQueryLength; i++) - { - int index = i; - //下载图片到本地 - QString imgPath = "D:/Study/SE/project/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(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], "D:/Study/SE/project/images/transparent.png", ""); -// btnList[index]->setVisible(false); - disconnect(btnList[index], 0, 0, 0); - } -// offset += currentQueryLength; -// currentHead += currentQueryLength; -} - -void SearchResultWidget::querySet() -{ - rollTop(); - - //重置存储查询信息的列表 - urlList.clear(); - imgList.clear(); - textList.clear(); - cateIdList.clear(); - currentHead = 0; - currentQueryLength = 0; - currentCate = page2cate[currentPage - 1]; - currentOffset = page2offset[currentPage - 1]; -// 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 SearchResultWidget::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 SearchResultWidget::returnWeb() -{ - subWidget->setVisible(true); - web->setVisible(false); - nullWidget->setVisible(false); -} - -void SearchResultWidget::pageUp() -{ - currentPage--; - if (currentPage < 1) - { - currentPage = 1; - qDebug("这是第一页"); - } - else - { - rollTop(); - querySet(); - } -} - -void SearchResultWidget::pageDown() -{ - currentPage++; - if (currentPage > pageNum) - { - currentPage = pageNum; - qDebug("已经是最后一页了!"); - } - else - { - rollTop(); - querySet(); - } -} - -void SearchResultWidget::rollTop() -{ - QScrollBar *scrollBar = scroll->verticalScrollBar(); - scrollBar->setValue(scrollBar->minimum()); -} - - diff --git a/src/ChangShaTour/searchresultwidget.h b/src/ChangShaTour/searchresultwidget.h deleted file mode 100644 index 32a8273..0000000 --- a/src/ChangShaTour/searchresultwidget.h +++ /dev/null @@ -1,87 +0,0 @@ -#ifndef SEARCHRESULTWIDGET_H -#define SEARCHRESULTWIDGET_H - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "databaseconnector.h" -#include "webwidget.h" -#include "imgdownloader.h" - - - - -class SearchResultWidget : public QWidget -{ - Q_OBJECT -public: - explicit SearchResultWidget(QWidget *parent = nullptr); - - void sendInput(QString input); - void queryDatabase(QSqlQuery query); - void getTotalNum(); - void showResult(); - QPushButton *getReturnBtn(); - QToolButton *setBtn(QToolButton *btn, const QString iconPath, const QString text); - void querySet(); - void setBtns(); - void pageUp(); - void pageDown(); - void returnWeb(); - void rollTop(); - -signals: - -private: - QString segment; - - QStringList urlList; - QStringList imgList; - QStringList textList; - int *idList; - QStringList cateIdList; - QStringList cateList; - - int totalNum; - int *lengthList; - int pageNum; - int showLimit; - int currentPage; - int currentHead; - int currentQueryLength; - int currentCate; - int currentOffset; - int *page2cate; - int *page2offset; - - - QVBoxLayout *mainLayout; - - QWidget *subWidget; - WebWidget *web; - QLabel *nullWidget; - - QVBoxLayout *subLayout; - QPushButton *rtn; - QScrollArea *scroll; - - QWidget *scrollWidget; - QVBoxLayout *scrollLayout; - - QToolButton **btnList; - - QHBoxLayout *switchLine; - QPushButton *up; - QPushButton *down; - -}; - -#endif // SEARCHRESULTWIDGET_H diff --git a/src/ChangShaTour/searchwidget.cpp b/src/ChangShaTour/searchwidget.cpp index 2c639e4..a59c33f 100644 --- a/src/ChangShaTour/searchwidget.cpp +++ b/src/ChangShaTour/searchwidget.cpp @@ -1,4 +1,4 @@ -#include "searchwidget.h" +#include "searchwidget.h" #include "ui_searchwidget.h" SearchWidget::SearchWidget(QWidget *parent) : @@ -6,9 +6,315 @@ SearchWidget::SearchWidget(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:" <(); + totalNum += query.value("num").value(); + } + + 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 score = QString::number(avgscore.value()); + QString commentNum = QString::number(comments.value()); + QString addr = address.value(); +// QString price = QString::number(avgprice.value()); + QString text = name + "\n" + score + "分 " + commentNum + "条评论\n" + addr + "\n";// + "人均" + price + "元"; + QString cateid = cateId.value(); + + idList[i] = id.value(); + urlList.append(detail.value()); + imgList.append(frontimg.value()); + 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(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(); + + //重置存储查询信息的列表 + 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 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()); +} + diff --git a/src/ChangShaTour/searchwidget.h b/src/ChangShaTour/searchwidget.h index d2119ef..3e2a52a 100644 --- a/src/ChangShaTour/searchwidget.h +++ b/src/ChangShaTour/searchwidget.h @@ -1,7 +1,24 @@ -#ifndef SEARCHWIDGET_H +#ifndef SEARCHWIDGET_H #define SEARCHWIDGET_H #include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "databaseconnector.h" +#include "webwidget.h" +#include "imgdownloader.h" + +#if _MSC_VER >= 1600 +#pragma execution_character_set("utf-8") +#endif namespace Ui { class SearchWidget; @@ -15,8 +32,63 @@ public: explicit SearchWidget(QWidget *parent = nullptr); ~SearchWidget(); + void sendInput(QString input); + void queryDatabase(QSqlQuery query); + void getTotalNum(); + void showResult(); + QPushButton *getReturnBtn(); + QToolButton *setBtn(QToolButton *btn, const QString iconPath, const QString text); + void querySet(); + void setBtns(); + void pageUp(); + void pageDown(); + void returnWeb(); + void rollTop(); + private: Ui::SearchWidget *ui; + + QString segment; + + QStringList urlList; + QStringList imgList; + QStringList textList; + int *idList; + QStringList cateIdList; + QStringList cateList; + + int totalNum; + int *lengthList; + int pageNum; + int showLimit; + int currentPage; + int currentHead; + int currentQueryLength; + int currentCate; + int currentOffset; + int *page2cate; + int *page2offset; + + + QVBoxLayout *mainLayout; + + QWidget *subWidget; + WebWidget *web; + QLabel *nullWidget; + + QVBoxLayout *subLayout; + QPushButton *rtn; + QScrollArea *scroll; + + QWidget *scrollWidget; + QVBoxLayout *scrollLayout; + + QToolButton **btnList; + + QHBoxLayout *switchLine; + QPushButton *up; + QPushButton *down; + }; #endif // SEARCHWIDGET_H diff --git a/src/ChangShaTour/sortwidget.cpp b/src/ChangShaTour/sortwidget.cpp index 6d36c02..d3c33e8 100644 --- a/src/ChangShaTour/sortwidget.cpp +++ b/src/ChangShaTour/sortwidget.cpp @@ -261,7 +261,7 @@ void SortWidget::Screen(QString str) queryDatabase(query, "select * from " + screenCode + " limit " + QString::number(row)); else queryDatabase(query, "select * from " + screenCode + " where cateId=\"" + str + "\" limit " + QString::number(row)); - size = size < row? size: row; + size = fmin(size, row); scroll->takeWidget(); subWidget->deleteLater(); @@ -320,7 +320,7 @@ void SortWidget::nextPage() queryDatabase(query, "select * from " + screenCode + " limit " + QString::number(row * (pageNumber + 1)) + "," + QString::number(row)); else queryDatabase(query, "select * from " + screenCode + " where cateId=\"" + screenStr + "\" limit " + QString::number(row * (pageNumber + 1)) + "," + QString::number(row)); - size = size < row? size: row; + size = fmin(size, row); scroll->takeWidget(); subWidget->deleteLater(); @@ -354,7 +354,7 @@ void SortWidget::backPage() queryDatabase(query, "select * from " + screenCode + " limit " + QString::number(row * (pageNumber - 1)) + "," + QString::number(row)); else queryDatabase(query, "select * from " + screenCode + " where cateId=\"" + screenStr + "\" limit " + QString::number(row * (pageNumber - 1)) + "," + QString::number(row)); - size = size < row? size: row; + size = fmin(size, row); scroll->takeWidget(); subWidget->deleteLater(); diff --git a/src/ChangShaTour/waitwidget.cpp b/src/ChangShaTour/waitwidget.cpp new file mode 100644 index 0000000..bcb08d0 --- /dev/null +++ b/src/ChangShaTour/waitwidget.cpp @@ -0,0 +1,38 @@ +#include "waitwidget.h" +#include "ui_waitwidget.h" + +WaitWidget::WaitWidget(QWidget *parent) : + QWidget(parent), + ui(new Ui::WaitWidget) +{ + ui->setupUi(this); + + background = new QLabel(this); + + this->setWindowOpacity(0.8); + setWindowFlags(Qt::Dialog | Qt::FramelessWindowHint);//设置为对话框风格,并且去掉边框 + setWindowModality(Qt::WindowModal);//设置为模式对话框,同时在构造该对话框时要设置父窗口 + SetBackground("./softImages/waitGirl.gif"); +} + +WaitWidget::~WaitWidget() +{ + delete ui; +} + +void WaitWidget::SetBackground(QString url) +{ + background->setStyleSheet("background-color: transparent;"); + //新建QMovie对象并用资源文件初始化 + QMovie * mov = new QMovie(url); + //setMoive + background->setMovie(mov); + background->setScaledContents(true); + //播放动画 + mov->start(); +} + +void WaitWidget::resizeEvent(QResizeEvent *event) +{ + background->resize(this->size()); +} diff --git a/src/ChangShaTour/waitwidget.h b/src/ChangShaTour/waitwidget.h new file mode 100644 index 0000000..a6c6f0e --- /dev/null +++ b/src/ChangShaTour/waitwidget.h @@ -0,0 +1,29 @@ +#ifndef WAITWIDGET_H +#define WAITWIDGET_H + +#include +#include +#include + +namespace Ui { +class WaitWidget; +} + +class WaitWidget : public QWidget +{ + Q_OBJECT + +public: + explicit WaitWidget(QWidget *parent = nullptr); + ~WaitWidget(); + + void SetBackground(QString); + void resizeEvent(QResizeEvent *event); + +private: + Ui::WaitWidget *ui; + + QLabel * background; +}; + +#endif // WAITWIDGET_H diff --git a/src/ChangShaTour/waitwidget.ui b/src/ChangShaTour/waitwidget.ui new file mode 100644 index 0000000..30e5791 --- /dev/null +++ b/src/ChangShaTour/waitwidget.ui @@ -0,0 +1,21 @@ + + + + + WaitWidget + + + + 0 + 0 + 400 + 300 + + + + Form + + + + + diff --git a/src/Wait.rar b/src/Wait.rar new file mode 100644 index 0000000..7cbb528 Binary files /dev/null and b/src/Wait.rar differ