目的、要求:
A.選區XX大學平面圖作爲底圖,選擇圖中的9個點做爲爲導航點
B.上面的9個點要有點的介紹和圖片信息
C.隨便點擊任意兩點,會出現2點之間的最短路徑和語言播報(播報內容有方向、距離。怎麼走到這個點,其中點1到點2和點2到點1播放的內容不同)
D.顯示系統主界面模塊設計在我的系統中,首先實現的整個系統的主界面,並不會直接進入到導航界面。系統主界面要有學生名字、老師名字和學校名字。背景爲本校圖片。主界面上應該有一個進入導航系統界面的按鈕
簡介:
1.實現系統主界面模塊
2.實現導航界面(點擊地圖上的點,在導航頁面的顯示該點信息和圖片。選擇要導航的2個點,通過迪杰特斯拉算法得到最短路徑,然後播放對應的音頻信息)
3.實現地點信息管理模塊(修改地點介紹和地點圖片)
4.導航語音下載檢測模塊(使用迪杰特斯拉算法獲取選擇點的最短路徑信息,編輯成文字,然後與百度語音api進行交互,下載全部的語音信息)
效果:
下載語音gif圖超過大小,這裏就貼圖吧
代碼:
/////導航按鈕槽函數
void MainForm::on_navigationBtn_clicked()
{
if(ui->startSiteComboBox->currentText() == ui->endSiteComboBox->currentText())
{
QMessageBox::information(NULL,QStringLiteral("警告"),QStringLiteral("請不要選擇2個相同的點"));
return;
}
//獲取當前定位的點,然後直接播放語音
QString startStr = ui->startSiteComboBox->currentText();
QString endStr = ui->endSiteComboBox->currentText();
QString videoName = startStr + "到" + endStr;
ui->infoShowTextEdit_2->clear();
//求輸入2點的最短路徑
m_approachSiteList.clear();
m_approachSiteLengthList.clear();
int startInt = ui->startSiteComboBox->currentIndex() + 1;
int endInt = ui->endSiteComboBox->currentIndex() + 1;
qDebug() << "startInt:" << startInt << "endInt:" << endInt;
ShortestPath_DIJ(amg, startInt - 1);
int temp = endInt - 1;
int temp1, temp2;
int flag[MAX_], m = 0;
qDebug() << "從" << QString::fromStdString(amg.vexs[startInt - 1]) << "到" << QString::fromStdString(amg.vexs[endInt - 1]) << "最短路徑爲:" ;
while (temp!= -1)
{
flag[m++] = temp;
temp1 = temp ;
temp2 = Path[temp1];
temp = temp2;
}
for (int i = m - 1; i >= 0; i--)
{
//cout << amg.vexs[flag[i]] << "->";
QString infos = QString::fromStdString(amg.vexs[flag[i]]);
//QString pointPath2 = "途徑" + infos;
//qDebug() << "->" << pointPath2;
//ui->infoShowTextEdit->append(pointPath);
m_approachSiteList.append(infos);
if(i + 1 < m)
{
QString pathLenth1 = QString::number(amg.arcs[flag[i]][flag[i + 1]]);
//ui->infoShowTextEdit->append(pathLenth1);
// qDebug() << "分路程" << pathLenth1;
m_approachSiteLengthList.append(pathLenth1);
}
}
//cout << endl;
//cout << "最短路徑值爲:" << D[end - 1] <<"米"<< endl;
//ui->infoShowTextEdit->append("路徑長度是:");
QString pathLenth = QString::number(D[endInt - 1]);
//ui->infoShowTextEdit->append(pathLenth);
qDebug() << "總路程" << pathLenth;
// for(int www = 0;www < m_approachSiteLengthList.count();www++)
// {
// qDebug() << "m_approachSiteLengthList.count()::" << m_approachSiteLengthList.count() << m_approachSiteLengthList[www];
// }
qDebug() << "m_approachSiteList.count()::" << m_approachSiteList.count() << " m_approachSiteLengthList";
////對路徑導航語音字符串進行編寫
QString str = "您從" + startStr + "開始出發,";
qDebug() << "str::" << str;
QString str1;
int allLength = D[endInt - 1];
for(int iii = 1;iii < m_approachSiteList.count();iii++)
{
//如果m_approachSiteList.count()等於2,也就是隻有2個點
if(m_approachSiteList.count() == 2)
{
str1 += "朝着" + m_approachSiteList[iii] + "的方向前行" + QString::number(allLength) + "米," + "最終您將到達目的地" + m_approachSiteList[iii] + ",總路程" + QString::number(allLength) + "米";;
}
else if(iii == 1 && m_approachSiteList.count() != 2)
{
str1 += "朝着" + m_approachSiteList[iii] + "的方向前行" + m_approachSiteLengthList[iii - 1] + "米,";
}
else if(iii == (m_approachSiteList.count() - 1))
{
//如果到最後一條
str1 += "隨後朝着" + m_approachSiteList[iii] + "的方向前行" + m_approachSiteLengthList[iii - 1] + "米," + "最終您將到達目的地" + m_approachSiteList[iii] + ",總路程" + QString::number(allLength) + "米";
}
else
{
str1 += "隨後朝着" + m_approachSiteList[iii] + "的方向前行" + m_approachSiteLengthList[iii - 1] + "米,";
}
qDebug() << "str1:" << str1;
}
//總字符串拼接
QString videoStr = str + str1;
//語音字符串請看下面的debug的輸出
//qDebug() << "videoStr:" << videoStr;
//ui->infoShowTextEdit->append(videoStr);
ui->infoShowTextEdit_2->append(videoStr);
//對語音進行播放
QString voiceFilePath = QString("%1/%2.ogg").arg(currentExeFilePath).arg(videoName);
mediaPlayer->setMedia(QUrl::fromLocalFile(voiceFilePath));
mediaPlayer->play();
}
//下載語音按鈕槽函數
void MainForm::on_downloadVideoBtn_clicked()
{
QStringList strList,strList1;
strList << "小足球場" << "博識樓" << "圖書館" << "體育館" << "科技大樓" << "宿舍博寧寓一號樓" << "博味廳" << "宿舍博夢寓二號樓" << "二號實驗室";
strList1 << "小足球場" << "博識樓" << "圖書館" << "體育館" << "科技大樓" << "宿舍博寧寓一號樓" << "博味廳" << "宿舍博夢寓二號樓" << "二號實驗室";
QStringList fileNameList;
QString fileName;
QStringList fileContentList;
//對文件名進行命名
for(int i = 0;i < strList.count();i++)
{
for(int j = 0;j < strList.count();j++)
{
if(strList[i] != strList1[j])
{
fileName = strList[i] + "到" + strList1[j];
fileNameList.append(fileName);
//求輸入2點的最短路徑
m_approachSiteList.clear();
m_approachSiteLengthList.clear();
int startInt = i + 1;
int endInt = j + 1;
qDebug() << "startInt:" << startInt << "endInt:" << endInt;
ShortestPath_DIJ(amg, startInt - 1);
int temp = endInt - 1;
int temp1, temp2;
int flag[MAX_], m = 0;
qDebug() << "從" << QString::fromStdString(amg.vexs[startInt - 1]) << "到" << QString::fromStdString(amg.vexs[endInt - 1]) << "最短路徑爲:" ;
while (temp!= -1)
{
flag[m++] = temp;
temp1 = temp ;
temp2 = Path[temp1];
temp = temp2;
}
for (int i = m - 1; i >= 0; i--)
{
//cout << amg.vexs[flag[i]] << "->";
QString infos = QString::fromStdString(amg.vexs[flag[i]]);
//QString pointPath2 = "途徑" + infos;
//qDebug() << "->" << pointPath2;
//ui->infoShowTextEdit->append(pointPath);
m_approachSiteList.append(infos);
if(i + 1 < m)
{
QString pathLenth1 = QString::number(amg.arcs[flag[i]][flag[i + 1]]);
//ui->infoShowTextEdit->append(pathLenth1);
// qDebug() << "分路程" << pathLenth1;
m_approachSiteLengthList.append(pathLenth1);
}
}
//cout << endl;
//cout << "最短路徑值爲:" << D[end - 1] <<"米"<< endl;
//ui->infoShowTextEdit->append("路徑長度是:");
QString pathLenth = QString::number(D[endInt - 1]);
//ui->infoShowTextEdit->append(pathLenth);
qDebug() << "總路程" << pathLenth;
for(int www = 0;www < m_approachSiteLengthList.count();www++)
{
qDebug() << "m_approachSiteLengthList.count()::" << m_approachSiteLengthList.count() << m_approachSiteLengthList[www];
}
qDebug() << "m_approachSiteList.count()::" << m_approachSiteList.count() << " m_approachSiteLengthList";
////對路徑導航語音字符串進行編寫
QString str = "您從" + strList[i] + "開始出發,";
qDebug() << "str::" << str;
QString str1;
int allLength = D[endInt - 1];
for(int iii = 1;iii < m_approachSiteList.count();iii++)
{
// QString str2 = m_approachSiteLengthList[iii];
// allLength += str2.toInt();
//如果m_approachSiteList.count()等於2,也就是隻有2個點
if(m_approachSiteList.count() == 2)
{
str1 += "朝着" + m_approachSiteList[iii] + "的方向前行" + QString::number(allLength) + "米," + "最終您將到達目的地" + m_approachSiteList[iii] + ",總路程" + QString::number(allLength) + "米";;
}
else if(iii == 1 && m_approachSiteList.count() != 2)
{
str1 += "朝着" + m_approachSiteList[iii] + "的方向前行" + m_approachSiteLengthList[iii - 1] + "米,";
}
else if(iii == (m_approachSiteList.count() - 1))
{
//如果到最後一條
str1 += "隨後朝着" + m_approachSiteList[iii] + "的方向前行" + m_approachSiteLengthList[iii - 1] + "米," + "最終您將到達目的地" + m_approachSiteList[iii] + ",總路程" + QString::number(allLength) + "米";
}
else
{
str1 += "隨後朝着" + m_approachSiteList[iii] + "的方向前行" + m_approachSiteLengthList[iii - 1] + "米,";
}
qDebug() << "str1:" << str1;
}
//總字符串拼接
QString videoStr = str + str1;
//語音字符串請看下面的debug的輸出
qDebug() << "videoStr:" << videoStr;
//ui->infoShowTextEdit->append(videoStr);
fileContentList.append(videoStr);
}
}
}
for(int i = 0;i < fileNameList.count();i++)
{
QString str = "第 " + QString::number(i) + "個文件,文件名爲:" + fileNameList[i] + " 內容是:" + fileContentList[i];
//qDebug() << i << " " <<fileNameList[i] << " 內容是:" << fileContentList[i];
ui->infoShowTextEdit->append(str);
}
//得到文件名和文件內容後,開始進行語音下載
//通過獲取要點名的名字信息,然後與存在的音頻文件名對比,得到重複的文件,然後刪除相應的數據信息,不再對已有的音頻文件下載
//只下載沒有的即可
m_currentNeedDownloadVideoList = fileContentList;
m_currentNeedDownloadVideoNameList = fileNameList;
if(m_currentNeedDownloadVideoList.count() > 0)
{
getFileFormUrl(QUrl(QString("http://tts.baidu.com/text2audio?lan=zh&ie=UTF-8&text=" + m_currentNeedDownloadVideoList.at(0))),
QString("%1/%2.ogg").arg(currentExeFilePath).arg(m_currentNeedDownloadVideoNameList.at(0)));
}
else
{
ui->infoShowTextEdit->append(QString("需要下載的音頻文件已經存在,不需要再次下載..."));
ui->downloadVideoBtn->setEnabled(true);
}
}
//檢驗按鈕槽函數
void MainForm::on_checkoutBtn_clicked()
{
QStringList nameQStrList = m_currentNeedDownloadVideoNameList;
for(int i = 0;i < nameQStrList.count();i++)
{
QFile files(QString("%1/%2.ogg").arg(currentExeFilePath).arg(nameQStrList.at(i)));
if(files.exists())
{
//判斷文件大小是否爲0,如果爲0肯定是不能用的
if(files.size() != 0)
{
ui->infoShowTextEdit->append(QString("%1.ogg 存在...").arg(nameQStrList.at(i)));
}
else
{
ui->infoShowTextEdit->append(QString("%1.ogg 存在,但是下載時出錯,請重新下載...").arg(nameQStrList.at(i)));
}
}
else
{
ui->infoShowTextEdit->append(QString("%1.ogg 不存在,請重新下載...").arg(nameQStrList.at(i)));
}
}
}