From baaa2a60c1bbd1662c81586e581980b1582fdafb Mon Sep 17 00:00:00 2001
From: liukunlin123 <2358524838@qq.com>
Date: Thu, 8 Jul 2021 12:10:16 +0800
Subject: [PATCH] =?UTF-8?q?=E5=AE=9A=E5=88=B6=E8=B7=AF=E7=BA=BF=E7=95=8C?=
=?UTF-8?q?=E9=9D=A2=EF=BC=8C=E4=BB=A5=E5=8F=8A=E9=80=89=E6=8B=A9=E4=BA=A4?=
=?UTF-8?q?=E9=80=9A=E8=B7=AF=E7=BA=BF=E7=95=8C=E9=9D=A2=EF=BC=8C=E6=98=BE?=
=?UTF-8?q?=E7=A4=BA=E8=B7=AF=E7=BA=BF=E8=AF=A6=E6=83=85=EF=BC=8C=E5=8A=A0?=
=?UTF-8?q?=E5=85=A5=E5=9C=BA=E6=89=80=E6=94=B6=E8=97=8F=E5=A4=B9=E5=92=8C?=
=?UTF-8?q?=E8=A1=8C=E7=A8=8B=E6=95=B0=E6=8D=AE=E5=BA=93?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/ChangShaTour/ChangShaTour.pro.user | 636 ++++++++++++-----------
src/ChangShaTour/confirmwidget.cpp | 151 +++++-
src/ChangShaTour/confirmwidget.h | 42 +-
src/ChangShaTour/planwidget.cpp | 255 +++++++--
src/ChangShaTour/planwidget.h | 9 +-
src/ChangShaTour/route.cpp | 13 +-
src/ChangShaTour/route.h | 1 +
src/ChangShaTour/routeplanning.cpp | 6 +
src/ChangShaTour/showrouteinfowidget.cpp | 82 +++
src/ChangShaTour/showrouteinfowidget.h | 30 ++
10 files changed, 859 insertions(+), 366 deletions(-)
diff --git a/src/ChangShaTour/ChangShaTour.pro.user b/src/ChangShaTour/ChangShaTour.pro.user
index fe67737..c85a543 100644
--- a/src/ChangShaTour/ChangShaTour.pro.user
+++ b/src/ChangShaTour/ChangShaTour.pro.user
@@ -1,317 +1,319 @@
-
-
-
-
-
- EnvironmentId
- {5009ac75-b61d-4c91-8540-bc9e10b6e582}
-
-
- ProjectExplorer.Project.ActiveTarget
- 0
-
-
- ProjectExplorer.Project.EditorSettings
-
- true
- false
- true
-
- Cpp
-
- CppGlobal
-
-
-
- QmlJS
-
- QmlJSGlobal
-
-
- 2
- UTF-8
- false
- 4
- false
- 80
- true
- true
- 1
- true
- false
- 0
- true
- true
- 0
- 8
- true
- 1
- true
- true
- true
- false
-
-
-
- ProjectExplorer.Project.PluginSettings
-
-
- 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
- 0
- 0
- 0
-
- /home/extra/Program/Qt5.14.2/Trip-in-Chang-sha/build-ChangShaTour-Desktop_Qt_5_14_2_GCC_64bit-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
-
-
- /home/extra/Program/Qt5.14.2/Trip-in-Chang-sha/build-ChangShaTour-Desktop_Qt_5_14_2_GCC_64bit-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
-
-
- /home/extra/Program/Qt5.14.2/Trip-in-Chang-sha/build-ChangShaTour-Desktop_Qt_5_14_2_GCC_64bit-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
-
- Qt4ProjectManager.Qt4RunConfiguration:/home/extra/Program/Qt5.14.2/Trip-in-Chang-sha/ChangShaTour/ChangShaTour.pro
- /home/extra/Program/Qt5.14.2/Trip-in-Chang-sha/ChangShaTour/ChangShaTour.pro
-
- false
-
- false
- true
- true
- false
- false
- true
-
- /home/extra/Program/Qt5.14.2/Trip-in-Chang-sha/build-ChangShaTour-Desktop_Qt_5_14_2_GCC_64bit-Debug
-
- 1
-
-
-
- ProjectExplorer.Project.TargetCount
- 1
-
-
- ProjectExplorer.Project.Updater.FileVersion
- 22
-
-
- Version
- 22
-
-
+
+
+
+
+
+ EnvironmentId
+ {0c4c8ccc-c524-4850-ba23-7e124d5915df}
+
+
+ ProjectExplorer.Project.ActiveTarget
+ 0
+
+
+ ProjectExplorer.Project.EditorSettings
+
+ true
+ false
+ true
+
+ Cpp
+
+ CppGlobal
+
+
+
+ QmlJS
+
+ QmlJSGlobal
+
+
+ 2
+ UTF-8
+ false
+ 4
+ false
+ 80
+ true
+ true
+ 1
+ true
+ false
+ 0
+ true
+ true
+ 0
+ 8
+ true
+ 1
+ true
+ true
+ true
+ false
+
+
+
+ ProjectExplorer.Project.PluginSettings
+
+
+ -fno-delayed-template-parsing
+
+ true
+
+
+
+ ProjectExplorer.Project.Target.0
+
+ Desktop Qt 5.14.2 MSVC2017 64bit
+ Desktop Qt 5.14.2 MSVC2017 64bit
+ qt.qt5.5142.win64_msvc2017_64_kit
+ 1
+ 0
+ 0
+
+ F:/QtDemo/build-ChangShaTour-Desktop_Qt_5_14_2_MSVC2017_64bit-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
+
+
+ F:/QtDemo/build-ChangShaTour-Desktop_Qt_5_14_2_MSVC2017_64bit-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
+
+
+ F:/QtDemo/build-ChangShaTour-Desktop_Qt_5_14_2_MSVC2017_64bit-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
+
+ Qt4ProjectManager.Qt4RunConfiguration:F:/QtDemo/ChangShaTour/ChangShaTour.pro
+ F:/QtDemo/ChangShaTour/ChangShaTour.pro
+
+ false
+
+ false
+ true
+ true
+ false
+ false
+ true
+
+ F:/QtDemo/build-ChangShaTour-Desktop_Qt_5_14_2_MSVC2017_64bit-Release
+
+ 1
+
+
+
+ ProjectExplorer.Project.TargetCount
+ 1
+
+
+ ProjectExplorer.Project.Updater.FileVersion
+ 22
+
+
+ Version
+ 22
+
+
diff --git a/src/ChangShaTour/confirmwidget.cpp b/src/ChangShaTour/confirmwidget.cpp
index 8104cfc..cb2bb45 100644
--- a/src/ChangShaTour/confirmwidget.cpp
+++ b/src/ChangShaTour/confirmwidget.cpp
@@ -1,21 +1,160 @@
#include "confirmwidget.h"
#include "ui_confirmwidget.h"
-#include
-#include
+
ConfirmWidget::ConfirmWidget(QWidget *parent) :
QWidget(parent),
ui(new Ui::ConfirmWidget)
{
ui->setupUi(this);
-
verLayout = new QVBoxLayout();
+ setLayout(verLayout);
- QLabel *label = new QLabel("ConfirmWidget");
+ routeToConfirm = new Route();
+ routePlan = new RoutePlanning();
- setLayout(verLayout);
- verLayout->addWidget(label);
+}
+void ConfirmWidget::initWidget()
+{
+
+ initInfoWidget();
+ qDebug()<<"generate ConfirmWidget";
+
+ //并不能像定制界面那样能对齐,因此取消
+ //format = new QHBoxLayout();
+ //format->addWidget(new QLabel("序号"),1);
+ //format->addWidget(new QLabel("场所"),12);
+ //format->addWidget(new QLabel("起始时间"),3);
+ //format->addWidget(new QLabel("结束时间"),3);
+ //format->addWidget(new QLabel(""),2);
+ //format->addWidget(new QLabel(""),2);
+ //verLayout->addLayout(format);
+ int i;
+ for (i = 0;i < size;i++) {
+ lineList[2*i]= new QHBoxLayout();
+ lineList[2*i]->addWidget(placeLabelList[i]);
+ lineList[2*i]->addWidget(startTimeLabelList[i]);
+ lineList[2*i]->addWidget(endTimeLabelList[i]);
+ verLayout->addLayout(lineList[2*i]);
+ qDebug()<<"generate verlayout";
+ if(i != size - 1)
+ {
+ lineList[2*i+1]= new QHBoxLayout();
+ lineList[2*i+1]->addWidget(trafficCBoxList[i]);
+ lineList[2*i+1]->addWidget(distanceLabelList[i]);
+ lineList[2*i+1]->addWidget(descriptionLabelList[i]);
+ lineList[2*i+1]->addWidget(timeCostLabelList[i]);
+ verLayout->addLayout(lineList[2*i+1]);
+ }
+
+ }
+}
+void ConfirmWidget::initInfoWidget()
+{
+ initInfo();
+ RouteItem * routeItems = routeToConfirm->getAllItems();
+ int i = 0;
+ routeNameLabel = new QLabel("路线名称:");
+ routeNameLineEdit->setText(routeToConfirm->getRouteName());
+ nameLine = new QHBoxLayout();
+ nameLine->addWidget(routeNameLabel);
+ nameLine->addWidget(routeNameLineEdit);
+ verLayout->addLayout(nameLine);
+ while(routeItems->next != NULL)
+ {
+ routeItems=routeItems->next;
+ qDebug()<placeName<startTime<endTime;
+ placeLabelList[i] = new QLabel(routeItems->placeName);
+ startTimeLabelList[i] = new QLabel(routeItems->startTime.toString());
+ endTimeLabelList[i] = new QLabel(routeItems->endTime.toString());
+
+ double * tt =getLatAndLng(routeItems->placeName,routeItems->cateId);
+ lats[i] = tt[0];
+ lngs[i] = tt[1];
+ i++;
+ }
+ //需要根据接口返回的数据调整顺序
+ trafficLabels<<"步行"<<"公交地铁"<<"驾车"<<"骑行";
+ qDebug()<addItems(trafficLabels);
+ QString location1 = QString::number(lngs[i]) + "," + QString::number(lats[i]);
+ qDebug()<getAllInfo(location1,location2);
+ int k = trafficCBoxList[i]->currentIndex();
+
+ descriptionLabelList[i]=new QLabel(allInfo[k][2]);
+ distanceLabelList[i]=new QLabel("距离:"+allInfo[k][0]);
+ timeCostLabelList[i]=new QLabel("时间:"+allInfo[k][1]);
+ void(QComboBox::*fp)(int)=&QComboBox:: currentIndexChanged;
+ connect(trafficCBoxList[i],fp,this,[=](){descriptionLabelList[i]->setText(allInfo[trafficCBoxList[i]->currentIndex()][2]);distanceLabelList[i]->setText("距离:"+allInfo[trafficCBoxList[i]->currentIndex()][0]);timeCostLabelList[i]->setText("时间:"+allInfo[trafficCBoxList[i]->currentIndex()][1]);});
+ }
+
+}
+void ConfirmWidget::initInfo()
+{
+ size = routeToConfirm->getLength();
+ routeNameLineEdit = new QLineEdit();
+ placeLabelList = (QLabel **)malloc(sizeof(QLabel *) * size);
+ startTimeLabelList = (QLabel **)malloc(sizeof(QLabel *) * size);
+ endTimeLabelList = (QLabel **)malloc(sizeof(QLabel *) * size);
+ trafficCBoxList = (QComboBox **)malloc(sizeof(QComboBox *) * (size - 1));
+ descriptionLabelList = (QLabel **)malloc(sizeof(QLabel *) * (size - 1));
+ distanceLabelList = (QLabel **)malloc(sizeof(QLabel *) * (size - 1));
+ timeCostLabelList = (QLabel **)malloc(sizeof(QLabel *) * (size - 1));
+ lineList = (QHBoxLayout **)malloc(sizeof(QHBoxLayout *) * (2 * size - 1));
+ lats = (double *)malloc(sizeof(double) * size);
+ lngs = (double *)malloc(sizeof(double) * size);
+
+}
+
+double * ConfirmWidget::getLatAndLng(QString title,QString cateId)
+{
+ double *tuple = (double *)malloc(sizeof(double *) * 2);
+ QString sql = "select * from "+labelToDb[cateId] + " where title = ?";
+ qDebug()<text()=="")
+ {
+ QMessageBox::warning(this,"警告","请填入路线名称!",QMessageBox::Yes);
+ return NULL;
+ }
+ routeToConfirm->setRouteName(routeNameLineEdit->text());
+ RouteItem * routeItems = routeToConfirm->getAllItems();
+ for(i = 0;inext;
+ routeItems->traffic = trafficCBoxList[i]->currentText();
+ routeItems->description = descriptionLabelList[i]->text();
+ routeItems->distance = distanceLabelList[i]->text().split(":")[1].toDouble();
+ routeItems->timeCost = timeCostLabelList[i]->text().split(":")[1].toDouble();
+ if((routeItems->next->startTime.toTime_t()) - (routeItems->next->endTime.toTime_t()) < routeItems->timeCost)
+ {
+ QMessageBox::warning(this,"警告","当前交通方式无法按时到达目的地!",QMessageBox::Yes);
+ }
+ }
+ return routeToConfirm;
+
+}
+//路线用指针
+void ConfirmWidget::setRouteToConfirm(Route *route)
+{
+ this->routeToConfirm = route;
}
ConfirmWidget::~ConfirmWidget()
diff --git a/src/ChangShaTour/confirmwidget.h b/src/ChangShaTour/confirmwidget.h
index 436630f..ecefe2f 100644
--- a/src/ChangShaTour/confirmwidget.h
+++ b/src/ChangShaTour/confirmwidget.h
@@ -2,8 +2,21 @@
#define CONFIRMWIDGET_H
#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
#include
+#include
#include
+#include
#if _MSC_VER >= 1600
@@ -21,11 +34,36 @@ class ConfirmWidget : public QWidget
public:
explicit ConfirmWidget(QWidget *parent = nullptr);
~ConfirmWidget();
+ void initInfoWidget();
+ void initInfo();
+ void setRouteToConfirm(Route * route);
+ double * getLatAndLng(QString title,QString cateId);
+ void initWidget();
+ void trafficInfoChanged(const QString &);
+ Route * genRoute();
private:
+ int size;
+ QLineEdit * routeNameLineEdit;
+ QHBoxLayout * nameLine;
+ QLabel * routeNameLabel;
+ Route * routeToConfirm;
+ RoutePlanning * routePlan;
+ QStringList trafficLabels;
+ QLabel ** placeLabelList;
+ QHBoxLayout ** lineList;
+ QVBoxLayout * verLayout;
+ QHBoxLayout * format;
+ QLabel ** startTimeLabelList;
+ QLabel ** descriptionLabelList;
+ QLabel ** distanceLabelList;
+ QLabel ** timeCostLabelList;
+ QLabel ** endTimeLabelList;
+ QLabel ** labelList;//显示序号
+ double *lats;//考虑用km,保留一位有效数字,*10即可
+ double *lngs;
+ QComboBox ** trafficCBoxList;
Ui::ConfirmWidget *ui;
-
- QVBoxLayout *verLayout;
};
#endif // CONFIRMWIDGET_H
diff --git a/src/ChangShaTour/planwidget.cpp b/src/ChangShaTour/planwidget.cpp
index 4cee0fa..5e8db25 100644
--- a/src/ChangShaTour/planwidget.cpp
+++ b/src/ChangShaTour/planwidget.cpp
@@ -23,6 +23,33 @@ void PlanWidget::switchToPlanChoice()
customizeWidget->deleteLater();
customizeWidget = new CustomizeWidget();
verLayout->addWidget(customizeWidget);
+ }
+ if (pageIndex == 6)
+ {
+ addRoute();
+ //删除界面定制相关界面
+ QMessageBox::information(NULL, "success", "已成功添加至行程\n可进入\"个人->行程\"查看");
+ showRouteInfoWidget->deleteLater();
+ showRouteInfoWidget = new ShowRouteInfoWidget();
+ verLayout->addWidget(showRouteInfoWidget);
+ confirmWidget->deleteLater();
+ confirmWidget = new ConfirmWidget();
+ verLayout->addWidget(confirmWidget);
+ customizeWidget->deleteLater();
+ customizeWidget = new CustomizeWidget();
+ verLayout->addWidget(customizeWidget);
+ //删除推荐路线相关界面
+ conditionWidget->deleteLater();
+ conditionWidget = new ConditionWidget();
+ verLayout->addWidget(conditionWidget);
+ preferenceWidget->deleteLater();
+ preferenceWidget = new PreferenceWidget();
+ verLayout->addWidget(preferenceWidget);
+ routeChoiceWidget->deleteLater();
+ routeChoiceWidget = new RouteChoiceWidget();
+ verLayout->addWidget(routeChoiceWidget);
+
+
}
pageIndex = 0;
@@ -36,6 +63,7 @@ void PlanWidget::switchToPlanChoice()
routeChoiceWidget->setVisible(false);
customizeWidget->setVisible(false);
confirmWidget->setVisible(false);
+ showRouteInfoWidget->setVisible(false);
}
void PlanWidget::switchToConditionWidget()
@@ -64,6 +92,7 @@ void PlanWidget::switchToConditionWidget()
routeChoiceWidget->setVisible(false);
customizeWidget->setVisible(false);
confirmWidget->setVisible(false);
+ showRouteInfoWidget->setVisible(false);
disconnect(returnBtn, 0, 0, 0);
disconnect(confirmBtn, 0, 0, 0);
@@ -119,6 +148,7 @@ void PlanWidget::switchToPreferenceWidget()
routeChoiceWidget->setVisible(false);
customizeWidget->setVisible(false);
confirmWidget->setVisible(false);
+ showRouteInfoWidget->setVisible(false);
disconnect(returnBtn, 0, 0, 0);
disconnect(confirmBtn, 0, 0, 0);
@@ -130,10 +160,10 @@ void PlanWidget::switchToPreferenceWidget()
void PlanWidget::switchToRouteChoiceWidget()
{
- if (pageIndex == 5)
+ if (pageIndex == 6)
{
- confirmWidget->deleteLater();
- confirmWidget = new ConfirmWidget();
+ showRouteInfoWidget->deleteLater();
+ showRouteInfoWidget = new ShowRouteInfoWidget();//显示详情界面index为6
verLayout->addWidget(confirmWidget);
}
@@ -161,6 +191,7 @@ void PlanWidget::switchToRouteChoiceWidget()
routeChoiceWidget->setVisible(true);
customizeWidget->setVisible(false);
confirmWidget->setVisible(false);
+ showRouteInfoWidget->setVisible(false);
routeChoiceWidget->setBtns(recRouteManager->getRecRoutes(), recRouteManager->getNumOfRecRoutes());
@@ -168,9 +199,82 @@ void PlanWidget::switchToRouteChoiceWidget()
disconnect(confirmBtn, 0, 0, 0);
connect(returnBtn, &QPushButton::clicked, this, &PlanWidget::switchToPreferenceWidget);
- connect(confirmBtn, &QPushButton::clicked, this, &PlanWidget::switchToConfirmWidget);
+ connect(confirmBtn, &QPushButton::clicked, this, &PlanWidget::switchToShowRouteInfo);
}
+void PlanWidget::switchToShowRouteInfo()
+{
+ int originalIndex = pageIndex;
+
+ if (originalIndex == 3)
+ {
+ pageIndex = 6;
+ tag = 0;//推荐路线
+ functionWidget->setVisible(true);
+ returnBtn->setVisible(true);
+ favoriteBtn->setVisible(true);
+ confirmBtn->setVisible(true);
+ //rcmdPlanBtn->setVisible(false);
+ //cstmPlanBtn->setVisible(false);
+ conditionWidget->setVisible(false);
+ preferenceWidget->setVisible(false);
+ routeChoiceWidget->setVisible(false);
+ customizeWidget->setVisible(false);
+ confirmWidget->setVisible(false);
+ showRouteInfoWidget->setVisible(true);
+ showRouteInfoWidget->setRouteToShow(recRoute);//《在这添加》,一点button,就把recRoute赋值
+ showRouteInfoWidget->initWidget();
+
+ disconnect(returnBtn, 0, 0, 0);
+ disconnect(confirmBtn, 0, 0, 0);
+ connect(returnBtn, &QPushButton::clicked, this, &PlanWidget::switchToRouteChoiceWidget);
+ connect(confirmBtn, &QPushButton::clicked, this, &PlanWidget::switchToPlanChoice);
+ connect(favoriteBtn,&QPushButton::clicked, this, &PlanWidget::addFavRoute);
+ }
+ if (originalIndex == 5)
+ {
+ Route *route = confirmWidget->genRoute();
+ if(route == NULL)
+ {
+ return ;
+ }
+ else
+ {
+ pageIndex = 6;
+ tag = 1;//来自定制路线
+ functionWidget->setVisible(true);
+ returnBtn->setVisible(true);
+ favoriteBtn->setVisible(true);
+ confirmBtn->setVisible(true);
+ //rcmdPlanBtn->setVisible(false);
+ //cstmPlanBtn->setVisible(false);
+ conditionWidget->setVisible(false);
+ preferenceWidget->setVisible(false);
+ routeChoiceWidget->setVisible(false);
+ customizeWidget->setVisible(false);
+ confirmWidget->setVisible(false);
+ showRouteInfoWidget->setVisible(true);
+ disconnect(returnBtn, 0, 0, 0);
+ disconnect(confirmBtn, 0, 0, 0);
+ connect(returnBtn, &QPushButton::clicked, this, &PlanWidget::switchToConfirmWidget);
+ connect(confirmBtn, &QPushButton::clicked, this, &PlanWidget::switchToPlanChoice);
+ connect(favoriteBtn,&QPushButton::clicked, this, &PlanWidget::addFavRoute);
+
+
+
+ showRouteInfoWidget->setRouteToShow(route);
+ showRouteInfoWidget->initWidget();
+ struct routeItem * p= route->getAllItems()->next;
+ while (p)
+ {
+ qDebug() << p->traffic;
+ p = p->next;
+ }
+ }
+
+
+ }
+}
void PlanWidget::switchToCustomizeWidget()
{
@@ -193,6 +297,7 @@ void PlanWidget::switchToCustomizeWidget()
routeChoiceWidget->setVisible(false);
customizeWidget->setVisible(true);
confirmWidget->setVisible(false);
+ showRouteInfoWidget->setVisible(false);
disconnect(returnBtn, 0, 0, 0);
disconnect(confirmBtn, 0, 0, 0);
@@ -206,57 +311,68 @@ void PlanWidget::switchToConfirmWidget()
{
int originalIndex = pageIndex;
-
- if (originalIndex == 3)
+ if (originalIndex == 6)
{
+ showRouteInfoWidget->deleteLater();
+ showRouteInfoWidget = new ShowRouteInfoWidget();
+ verLayout->addWidget(showRouteInfoWidget);
pageIndex = 5;
-
functionWidget->setVisible(true);
returnBtn->setVisible(true);
- favoriteBtn->setVisible(true);
+ favoriteBtn->setVisible(false);
confirmBtn->setVisible(true);
- choiceWidget->setVisible(false);
+ //rcmdPlanBtn->setVisible(false);
+ //cstmPlanBtn->setVisible(false);
conditionWidget->setVisible(false);
preferenceWidget->setVisible(false);
routeChoiceWidget->setVisible(false);
customizeWidget->setVisible(false);
confirmWidget->setVisible(true);
-
+ showRouteInfoWidget->setVisible(false);
disconnect(returnBtn, 0, 0, 0);
disconnect(confirmBtn, 0, 0, 0);
- connect(returnBtn, &QPushButton::clicked, this, &PlanWidget::switchToRouteChoiceWidget);
+ connect(returnBtn, &QPushButton::clicked, this, &PlanWidget::switchToCustomizeWidget);
+ connect(confirmBtn, &QPushButton::clicked, this, &PlanWidget::switchToShowRouteInfo);
}
- if (originalIndex == 4)
+ if(originalIndex == 4)
{
- if (customizeWidget->genRoute())
+
+ if(customizeWidget->genRoute())
{
+ Route *route = customizeWidget->getRoute();
+ confirmWidget->setRouteToConfirm(route);
+ confirmWidget->initWidget();
+ qDebug() << "generate customize route:";
+ struct routeItem * p= route->getAllItems()->next;
+ while (p)
+ {
+ qDebug() << p->placeName;
+ p = p->next;
+ }
pageIndex = 5;
functionWidget->setVisible(true);
returnBtn->setVisible(true);
- favoriteBtn->setVisible(true);
+ favoriteBtn->setVisible(false);
confirmBtn->setVisible(true);
- choiceWidget->setVisible(false);
+ //rcmdPlanBtn->setVisible(false);
+ //cstmPlanBtn->setVisible(false);
conditionWidget->setVisible(false);
preferenceWidget->setVisible(false);
routeChoiceWidget->setVisible(false);
customizeWidget->setVisible(false);
confirmWidget->setVisible(true);
+ showRouteInfoWidget->setVisible(false);
disconnect(returnBtn, 0, 0, 0);
disconnect(confirmBtn, 0, 0, 0);
connect(returnBtn, &QPushButton::clicked, this, &PlanWidget::switchToCustomizeWidget);
+ connect(confirmBtn, &QPushButton::clicked, this, &PlanWidget::switchToShowRouteInfo);
+ }
+
- Route *route = customizeWidget->getRoute();
- qDebug() << "generate customize route:";
- struct routeItem * p= route->getAllItems()->next;
- while (p)
- {
- qDebug() << p->placeName;
- p = p->next;
- }
- }
}
-// connect(confirmBtn, &QPushButton::clicked, this, &PlanWidget::switchToPreferenceWidget);
+
+
}
@@ -285,7 +401,6 @@ void PlanWidget::InitPlanWidget()
functionWidget = new QWidget();
InitFunctionWidget();
- functionWidget->setFixedSize(1380, 50);
verLayout->addWidget(functionWidget);
functionWidget->setVisible(false);
returnBtn->setVisible(false);
@@ -302,26 +417,30 @@ void PlanWidget::InitPlanWidget()
routeChoiceWidget = new RouteChoiceWidget();
customizeWidget = new CustomizeWidget();
confirmWidget = new ConfirmWidget();
+ showRouteInfoWidget = new ShowRouteInfoWidget();
+
conditionWidget->setVisible(false);
preferenceWidget->setVisible(false);
routeChoiceWidget->setVisible(false);
customizeWidget->setVisible(false);
confirmWidget->setVisible(false);
+ showRouteInfoWidget->setVisible(false);
verLayout->addWidget(conditionWidget);
verLayout->addWidget(preferenceWidget);
verLayout->addWidget(routeChoiceWidget);
verLayout->addWidget(customizeWidget);
verLayout->addWidget(confirmWidget);
+ verLayout->addWidget(showRouteInfoWidget);
}
void PlanWidget::InitChoiceWidget()
{
- QVBoxLayout * verLayout = new QVBoxLayout();
- choiceWidget->setLayout(verLayout);
+ QVBoxLayout * choiceverLayout = new QVBoxLayout();
+ choiceWidget->setLayout(choiceverLayout);
QWidget * firstSubWidget = new QWidget();
- verLayout->addWidget(firstSubWidget);
+ choiceverLayout->addWidget(firstSubWidget);
QHBoxLayout * firstHoriLayout = new QHBoxLayout();
firstSubWidget->setLayout(firstHoriLayout);
@@ -336,7 +455,7 @@ void PlanWidget::InitChoiceWidget()
firstHoriLayout->addWidget(cstmPlanBtn);
QWidget * secondSubWidget = new QWidget();
- verLayout->addWidget(secondSubWidget);
+ choiceverLayout->addWidget(secondSubWidget);
QHBoxLayout * secondHoriLayout = new QHBoxLayout();
secondSubWidget->setLayout(secondHoriLayout);
@@ -382,7 +501,82 @@ void PlanWidget::InitLabel(QLabel * label)
label->setStyleSheet("color:#FFFFFF");
label->setAlignment(Qt::AlignCenter);
}
+void PlanWidget::addFavRoute()
+{
+ Route * routeFav = showRouteInfoWidget->getRouteToShow();
+ RouteItem * routeItemsFav = routeFav->getAllItems();
+ QSqlQuery query(userDb);
+ QString sql = "insert into favRoutes (userId,routeId,routeName,placeNo,startTime,endTime,placeName,url,cateId,traffic,distance,timeCost,description) values(?,?,?,?,?,?,?,?,?,?,?,?,?);";
+ int i = 1;
+ QString sql_query="select max(routeId) from favRoutes";
+ query.exec(sql_query);
+ query.next();
+ int routeId = query.value(0).toInt();
+ routeId = routeId+1;
+ //int size = routeFav->getPlaceSize();
+ while(routeItemsFav->next != NULL)
+ {
+ routeItemsFav = routeItemsFav->next;
+ query.prepare(sql);
+ query.addBindValue(Id);
+ query.addBindValue(routeId);
+ //query.addBindValue(routeFav->getRouteId());
+ query.addBindValue(routeFav->getRouteName());
+ //query.addBindValue(routeFav->getRouteName());
+ query.addBindValue(i);
+ query.addBindValue(routeItemsFav->startTime.toString("yyyy-MM-dd HH:mm:ss"));
+ query.addBindValue(routeItemsFav->endTime.toString("yyyy-MM-dd HH:mm:ss"));
+ query.addBindValue(routeItemsFav->placeName);
+ query.addBindValue(routeItemsFav->url);
+ query.addBindValue(routeItemsFav->cateId);
+ query.addBindValue(routeItemsFav->traffic);
+ query.addBindValue(routeItemsFav->distance);
+ query.addBindValue(routeItemsFav->timeCost);
+ query.addBindValue(routeItemsFav->description);
+ //query.addBindValue(tag);
+ query.exec();
+ i++;
+ }
+}
+void PlanWidget::addRoute()
+{
+ Route * routeFav = showRouteInfoWidget->getRouteToShow();
+ RouteItem * routeItemsFav = routeFav->getAllItems();
+ QSqlQuery query(userDb);
+ QString sql = "insert into journey (userId,routeId,routeName,placeNo,startTime,endTime,placeName,url,cateId,traffic,distance,timeCost,description,tag) values(?,?,?,?,?,?,?,?,?,?,?,?,?,?);";
+ int i = 1;
+ QString sql_query="select max(routeId) from journey";
+ query.exec(sql_query);
+ query.next();
+ int routeId = query.value(0).toInt();
+ routeId = routeId+1;
+ //int size = routeFav->getPlaceSize();
+ while(routeItemsFav->next != NULL)
+ {
+ routeItemsFav = routeItemsFav->next;
+ query.prepare(sql);
+ query.addBindValue(Id);
+ query.addBindValue(routeId);
+ //query.addBindValue(routeFav->getRouteId());
+ query.addBindValue(routeFav->getRouteName());
+ //query.addBindValue(routeFav->getRouteName());
+ query.addBindValue(i);
+ query.addBindValue(routeItemsFav->startTime.toString("yyyy-MM-dd HH:mm:ss"));
+ query.addBindValue(routeItemsFav->endTime.toString("yyyy-MM-dd HH:mm:ss"));
+ query.addBindValue(routeItemsFav->placeName);
+ query.addBindValue(routeItemsFav->url);
+ query.addBindValue(routeItemsFav->cateId);
+ query.addBindValue(routeItemsFav->traffic);
+ query.addBindValue(routeItemsFav->distance);
+ query.addBindValue(routeItemsFav->timeCost);
+ query.addBindValue(routeItemsFav->description);
+ query.addBindValue(tag);
+ query.exec();
+ i++;
+ }
+
+}
void PlanWidget::InitButton(QPushButton * button)
{
button->setStyleSheet("QPushButton {"
@@ -448,6 +642,7 @@ void PlanWidget::InitPlanButton(QPushButton * button, QString url)
button->setFixedSize(500, 300);
}
+
void PlanWidget::resizeEvent(QResizeEvent *event)
{
background->resize(this->size());
diff --git a/src/ChangShaTour/planwidget.h b/src/ChangShaTour/planwidget.h
index eda72e3..f083a23 100644
--- a/src/ChangShaTour/planwidget.h
+++ b/src/ChangShaTour/planwidget.h
@@ -12,6 +12,7 @@
#include "customizewidget.h"
#include "confirmwidget.h"
#include "route.h"
+#include "showrouteinfowidget.h"
#include "recroutemanager.h"
#if _MSC_VER >= 1600
@@ -48,6 +49,7 @@ private:
QLabel * background;
int pageIndex;
+ int tag = 1;
QVBoxLayout *verLayout;
@@ -56,6 +58,7 @@ private:
QPushButton *confirmBtn;
QPushButton *rcmdPlanBtn;
QPushButton *cstmPlanBtn;
+ Route * recRoute;
QWidget * choiceWidget;
QWidget * functionWidget;
@@ -63,13 +66,17 @@ private:
PreferenceWidget *preferenceWidget;
RouteChoiceWidget *routeChoiceWidget;
CustomizeWidget *customizeWidget;
- ConfirmWidget *confirmWidget;
+ ConfirmWidget *confirmWidget;//选择交通路线界面
+ ShowRouteInfoWidget * showRouteInfoWidget;//显示详情界面
RecRouteManager * recRouteManager;
public slots:
void switchToPlanChoice();
void switchToConditionWidget();
+ void addFavRoute();
+ void addRoute();
+ void switchToShowRouteInfo();
void switchToPreferenceWidget();
void switchToRouteChoiceWidget();
void switchToCustomizeWidget();
diff --git a/src/ChangShaTour/route.cpp b/src/ChangShaTour/route.cpp
index f8f6365..6eefed0 100644
--- a/src/ChangShaTour/route.cpp
+++ b/src/ChangShaTour/route.cpp
@@ -46,9 +46,9 @@ void Route::setAllItems(QStringList titleList,QStringList urlList,QStringList ca
{
RouteItem * head= routeItems;
RouteItem * p;
- int totalSize=titleList.size();
+ placeSize=titleList.size();
int i;
- for(i=0;iplaceName = titleList[i];
@@ -98,12 +98,5 @@ RouteItem * Route::deleteItem(int locate)
int Route::getLength()
{
- RouteItem * p = routeItems->next;
- int i = 0;
- while(p != NULL)
- {
- p = p->next;
- i++;
- }
- return i;
+ return this->placeSize;
}
diff --git a/src/ChangShaTour/route.h b/src/ChangShaTour/route.h
index 17c358e..937665e 100644
--- a/src/ChangShaTour/route.h
+++ b/src/ChangShaTour/route.h
@@ -21,6 +21,7 @@ public:
int getLength();
private:
QString routeName;
+ int placeSize = 0;
int userId=0;//路线没有用户时默认为0
int routeId=0;//路线编号默认为0
struct routeItem *routeItems;
diff --git a/src/ChangShaTour/routeplanning.cpp b/src/ChangShaTour/routeplanning.cpp
index 515bfe8..5bb6576 100644
--- a/src/ChangShaTour/routeplanning.cpp
+++ b/src/ChangShaTour/routeplanning.cpp
@@ -48,6 +48,7 @@ QStringList RoutePlanning::getWalkingRoute(QString origin, QString destination)
QString duration = pathsJson.value("duration").toString();
walkingInfo.append(distance);
walkingInfo.append(duration);
+ walkingInfo.append("");
return walkingInfo;
}
else
@@ -61,6 +62,7 @@ QStringList RoutePlanning::getWalkingRoute(QString origin, QString destination)
netManager = nullptr;
}
+ walkingInfo.append("Error");
walkingInfo.append("Error");
walkingInfo.append("Error");
return walkingInfo;
@@ -189,6 +191,7 @@ QStringList RoutePlanning::getDrivingRoute(QString origin, QString destination)
QString duration = pathsJson.value("duration").toString();
drivingInfo.append(distance);
drivingInfo.append(duration);
+ drivingInfo.append("");
return drivingInfo;
}
else
@@ -202,6 +205,7 @@ QStringList RoutePlanning::getDrivingRoute(QString origin, QString destination)
netManager = nullptr;
}
+ drivingInfo.append("Error");
drivingInfo.append("Error");
drivingInfo.append("Error");
return drivingInfo;
@@ -249,6 +253,7 @@ QStringList RoutePlanning::getBicyclingRoute(QString origin, QString destination
QString duration = QString::number(pathsJson.value("duration").toInt());
bicyclingInfo.append(distance);
bicyclingInfo.append(duration);
+ bicyclingInfo.append("");
return bicyclingInfo;
}
else
@@ -262,6 +267,7 @@ QStringList RoutePlanning::getBicyclingRoute(QString origin, QString destination
netManager = nullptr;
}
+ bicyclingInfo.append("Error");
bicyclingInfo.append("Error");
bicyclingInfo.append("Error");
return bicyclingInfo;
diff --git a/src/ChangShaTour/showrouteinfowidget.cpp b/src/ChangShaTour/showrouteinfowidget.cpp
index 53155e2..3111c1b 100644
--- a/src/ChangShaTour/showrouteinfowidget.cpp
+++ b/src/ChangShaTour/showrouteinfowidget.cpp
@@ -6,7 +6,89 @@ ShowRouteInfoWidget::ShowRouteInfoWidget(QWidget *parent) :
ui(new Ui::ShowRouteInfoWidget)
{
ui->setupUi(this);
+ verLayout = new QVBoxLayout();
+
+
+ setLayout(verLayout);
+ routeToShow = new Route();
+
+}
+
+void ShowRouteInfoWidget::initWidget()
+{
+ initInfoWidget();
+ int i;
+ routeNameLabel = new QLabel("路线名称:");
+ nameLabel = new QLabel(routeToShow->getRouteName());
+ nameLine = new QHBoxLayout();
+ nameLine->addWidget(routeNameLabel);
+ nameLine->addWidget(nameLabel);
+ verLayout->addLayout(nameLine);
+ for (i = 0;i < size;i++) {
+ lineList[2*i] = new QHBoxLayout();
+ lineList[2*i]->addWidget(placeLabelList[i]);
+ lineList[2*i]->addWidget(startTimeLabelList[i]);
+ lineList[2*i]->addWidget(endTimeLabelList[i]);
+ verLayout->addLayout(lineList[2*i]);
+
+ if(i != size - 1)
+ {
+ lineList[2*i+1] = new QHBoxLayout();
+ lineList[2*i+1]->addWidget(trafficLabelList[i]);
+ lineList[2*i+1]->addWidget(descriptionLabelList[i]);
+ lineList[2*i+1]->addWidget(distanceLabelList[i]);
+ lineList[2*i+1]->addWidget(timeCostLabelList[i]);
+ verLayout->addLayout(lineList[2*i+1]);
+ }
+
+ }
+}
+
+void ShowRouteInfoWidget::initInfoWidget()
+{
+ initInfo();
+ routeItems = routeToShow->getAllItems();
+ int i = 0;
+ while(routeItems->next != NULL)
+ {
+ routeItems=routeItems->next;
+
+ placeLabelList[i] = new QLabel(routeItems->placeName);
+ startTimeLabelList[i] = new QLabel(routeItems->startTime.toString());
+ endTimeLabelList[i] = new QLabel(routeItems->endTime.toString());
+ if(i != size-1)
+ {
+ trafficLabelList[i] = new QLabel(routeItems->traffic);
+ descriptionLabelList[i] = new QLabel(routeItems->description);
+ distanceLabelList[i] = new QLabel("距离:"+QString::number(routeItems->distance));
+ timeCostLabelList[i] = new QLabel("时间:"+QString::number(routeItems->timeCost));
+ }
+ i++;
+ }
+}
+void ShowRouteInfoWidget::initInfo()
+{
+ size = routeToShow->getLength();
+
+ placeLabelList = (QLabel ** )malloc(sizeof (QLabel *) * size);
+ startTimeLabelList = (QLabel ** )malloc(sizeof (QLabel *) * size);
+ endTimeLabelList = (QLabel **)malloc(sizeof (QLabel *) * size);
+ trafficLabelList = (QLabel **)malloc(sizeof (QLabel *) * (size - 1));
+ descriptionLabelList = (QLabel **)malloc(sizeof (QLabel *) * (size - 1));
+ distanceLabelList = (QLabel **)malloc(sizeof (QLabel *) * (size - 1));
+ timeCostLabelList = (QLabel **)malloc(sizeof (QLabel *) * (size - 1));
+ lineList = (QHBoxLayout **)malloc(sizeof (QHBoxLayout *) * (2 * size - 1));
}
+//路线用指针
+void ShowRouteInfoWidget::setRouteToShow(Route *route)
+{
+ this->routeToShow = route;
+}
+Route * ShowRouteInfoWidget::getRouteToShow()
+{
+ return this->routeToShow;
+}
+
ShowRouteInfoWidget::~ShowRouteInfoWidget()
{
diff --git a/src/ChangShaTour/showrouteinfowidget.h b/src/ChangShaTour/showrouteinfowidget.h
index 1caaf0c..7da131a 100644
--- a/src/ChangShaTour/showrouteinfowidget.h
+++ b/src/ChangShaTour/showrouteinfowidget.h
@@ -2,6 +2,15 @@
#define SHOWROUTEINFOWIDGET_H
#include
+#include "route.h"
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
#if _MSC_VER >= 1600
#pragma execution_character_set("utf-8")
@@ -18,9 +27,30 @@ class ShowRouteInfoWidget : public QWidget
public:
explicit ShowRouteInfoWidget(QWidget *parent = nullptr);
~ShowRouteInfoWidget();
+ void initInfo();
+ void initWidget();
+ void initInfoWidget();
+ void setRouteToShow(Route * route);
+ Route * getRouteToShow();
private:
Ui::ShowRouteInfoWidget *ui;
+ Route * routeToShow;
+ int size;
+ QLabel * routeNameLabel;
+ QLabel * nameLabel;
+ QHBoxLayout * nameLine;
+ RouteItem * routeItems;
+ QLabel ** placeLabelList;
+ QLabel ** startTimeLabelList;
+ QLabel ** descriptionLabelList;
+ QLabel ** distanceLabelList;
+ QLabel ** timeCostLabelList;
+ QLabel ** endTimeLabelList;
+ QLabel ** labelList;//显示序号
+ QHBoxLayout ** lineList;
+ QVBoxLayout * verLayout;
+ QLabel ** trafficLabelList;
};
#endif // SHOWROUTEINFOWIDGET_H