Commit 0e726278 authored by Tao Zhong's avatar Tao Zhong

#137 Open file fails

parent cd1cf903
Pipeline #21067 passed with stages
in 25 seconds
...@@ -385,133 +385,157 @@ void MWindow::openFileXML() ...@@ -385,133 +385,157 @@ void MWindow::openFileXML()
QString fileName=QFileDialog::getOpenFileName(this,tr("Open XML"),"",tr("XML-Files (*.xml)")); QString fileName=QFileDialog::getOpenFileName(this,tr("Open XML"),"",tr("XML-Files (*.xml)"));
openGeometry(fileName); QString error_geometry = openGeometry(fileName);
openRouting(fileName); // if load geometry file failed, stop read others files
if(!error_geometry.isEmpty())
{
QMessageBox::critical(this,
"Open XML",
error_geometry,
QMessageBox::Ok);
return;
}
openGoal(fileName); QString error_routing = openRouting(fileName);
openSource(fileName); QString error_goal = openGoal(fileName);
openTraffic(fileName); QString error_source = openSource(fileName);
QString error_traffic = openTraffic(fileName);
if(!error_goal.isEmpty() or !error_routing.isEmpty() or !error_source.isEmpty() or !error_traffic.isEmpty())
{
QString error = "";
QMessageBox msgBox;
msgBox.setText("Geometry is loaded, but some files aren't loaded.");
if(!error_routing.isEmpty())
error += error_routing + "\n";
if(!error_goal.isEmpty())
error += error_goal + "\n";
if(!error_source.isEmpty())
error += error_source + "\n";
if(!error_traffic.isEmpty())
error += error_traffic + "\n";
msgBox.setDetailedText(error);
msgBox.setStandardButtons(QMessageBox::Ok);
msgBox.exec();
return;
} else
{
statusBar()->showMessage(tr("Files successfully loaded!"),10000);
//AutoZoom to drawing
mview->AutoZoom();
}
//AutoZoom to drawing
mview->AutoZoom();
} }
void MWindow::openGeometry(QString fileName) QString MWindow::openGeometry(QString fileName)
{ {
QFile file(fileName); QFile file(fileName);
if(fileName.isEmpty()) if(fileName.isEmpty())
return; {
QString error = "Geometry file isn't found!";
return error;
}
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
{ {
QMessageBox::warning(this, tr("Read Geometry XML"), QString error = "Format error, open geometry file failed!";
tr("Cannot read file %1:\n%2.") return error;
.arg(QDir::toNativeSeparators(fileName),
file.errorString()));
return;
} }
if (!dmanager->readXML(file)) if (!dmanager->readXML(file))
{ {
QMessageBox::critical(this, QString error = "Content error, read geometry file failed";
"Prase geometry XML", return error;
"Cannot prase XML-file",
QMessageBox::Ok);
statusBar()->showMessage("XML-File could not be loaded!",10000);
} }
else else
{ {
statusBar()->showMessage("XML file loaded!", 10000); QString error = ""; // file is loaded successful!
return error;
} }
} }
void MWindow::openRouting(QString fileName) QString MWindow::openRouting(QString fileName)
{ {
QString fileNameRouting= fileName.split(".").first()+"_routing.xml"; QString fileNameRouting= fileName.split(".").first()+"_routing.xml";
QFile fileRouting(fileNameRouting); QFile fileRouting(fileNameRouting);
if(fileNameRouting.isEmpty())
return;
if (!fileRouting.open(QIODevice::ReadOnly | QIODevice::Text)) if (!fileRouting.open(QIODevice::ReadOnly | QIODevice::Text))
{ {
QMessageBox::warning(this, tr("Read Routing XML"), QString error = "Routing file isn't found!";
tr("Cannot read file %1:\n%2.") return error;
.arg(QDir::toNativeSeparators(fileName),
fileRouting.errorString()));
return;
} }
//Start to read routing //Start to read routing
if (!dmanager->readRoutingXML(fileRouting)) if (!dmanager->readRoutingXML(fileRouting))
{ {
QMessageBox::critical(this, QString error = "Content error, read routing file failed!";
"Prase routing XML", return error;
"Cannot prase XML-file",
QMessageBox::Ok);
} }
else else
{ {
QString error = ""; // file is loaded successful!
return error;
} }
} }
void MWindow::openSource(QString fileName) QString MWindow::openSource(QString fileName)
{ {
QString fileNameSource= fileName.split(".").first()+"_sources.xml"; QString fileNameSource= fileName.split(".").first()+"_sources.xml";
QFile fileSource(fileNameSource); QFile fileSource(fileNameSource);
if(fileNameSource.isEmpty())
return;
if(!fileSource.open(QIODevice::ReadOnly | QIODevice::Text)) if(!fileSource.open(QIODevice::ReadOnly | QIODevice::Text))
{ {
QMessageBox::warning(this, tr("Read source XML"), QString error = "Source file isn't found!";
tr("Cannot read file %1:\n%2.") return error;
.arg(QDir::toNativeSeparators(fileNameSource),
fileSource.errorString()));
return;
} }
SourceReader sourceReader(mview); SourceReader sourceReader(mview);
if(!sourceReader.read(&fileSource)) if(!sourceReader.read(&fileSource))
{ {
QMessageBox::warning(this, tr("Prasse source XML"), QString error = "Content error, read source file failed";
tr("Cannot prase file %1:\n%2.") return error;
.arg(QDir::toNativeSeparators(fileNameSource), } else
fileSource.errorString())); {
QString error = ""; // file is loaded successful!
return error;
} }
} }
void MWindow::openGoal(QString fileName) QString MWindow::openGoal(QString fileName)
{ {
QString fileNameGoal= fileName.split(".").first()+"_goals.xml"; QString fileNameGoal= fileName.split(".").first()+"_goals.xml";
QFile fileGoal(fileNameGoal); QFile fileGoal(fileNameGoal);
if(fileNameGoal.isEmpty())
return;
if(!fileGoal.open(QIODevice::ReadOnly | QIODevice::Text)) if(!fileGoal.open(QIODevice::ReadOnly | QIODevice::Text))
{ {
QMessageBox::warning(this, tr("Read Goal XML"), QString error = "Goal file isn't found!";
tr("Cannot read file %1:\n%2.") return error;
.arg(QDir::toNativeSeparators(fileNameGoal),
fileGoal.errorString()));
return;
} }
GoalReader goalReader(mview); GoalReader goalReader(mview);
if(!goalReader.read(&fileGoal)) if(!goalReader.read(&fileGoal))
{ {
QMessageBox::warning(this, tr("Prasse goal XML"), QString error = "Content error, read source file failed";
tr("Cannot prase file %1:\n%2.") return error;
.arg(QDir::toNativeSeparators(fileNameGoal), } else
fileGoal.errorString())); {
QString error = ""; // file is loaded successful!
return error;
} }
} }
...@@ -519,6 +543,7 @@ void MWindow::openFileCogMap() ...@@ -519,6 +543,7 @@ void MWindow::openFileCogMap()
{ {
QString fileName=QFileDialog::getOpenFileName(this,tr("Open XML"),"",tr("XML-Files (*.xml)")); QString fileName=QFileDialog::getOpenFileName(this,tr("Open XML"),"",tr("XML-Files (*.xml)"));
QFile file(fileName); QFile file(fileName);
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
{ {
QMessageBox::critical(this, QMessageBox::critical(this,
...@@ -672,8 +697,8 @@ void MWindow::info() ...@@ -672,8 +697,8 @@ void MWindow::info()
"<h1><p style=\"line-height:0.7\">JPSeditor</p></h1><p style=\"line-height:1.4\" style=\"color:Gray;" "<h1><p style=\"line-height:0.7\">JPSeditor</p></h1><p style=\"line-height:1.4\" style=\"color:Gray;"
"\"><small><i>Version %1</i></small></p>" "\"><small><i>Version %1</i></small></p>"
"<p style=\"line-height:0.4\" style=\"color:Gray;\"><i>Commit Hash</i> %2</p>" "<p style=\"line-height:0.4\" style=\"color:Gray;\"><i>Commit Hash</i> %2</p>"
"<p style=\"line-height:0.4\" style=\"color:Gray;\"><i>Commmit Date</i> %3</p>" "<p style=\"line-height:0.4\" style=\"color:Gray;\"><i>Commmit Date</i> %3</p>"
"<p style=\"line-height:0.4\" style=\"color:Gray;\"><i>Branch</i> %4</p><hr>" "<p style=\"line-height:0.4\" style=\"color:Gray;\"><i>Branch</i> %4</p><hr>"
).arg(JPSEDITOR_VERSION).arg(GIT_COMMIT_HASH).arg(GIT_COMMIT_DATE); ).arg(JPSEDITOR_VERSION).arg(GIT_COMMIT_HASH).arg(GIT_COMMIT_DATE);
QString text = QMessageBox::tr( QString text = QMessageBox::tr(
...@@ -1146,31 +1171,25 @@ void MWindow::goalButtionClicked() ...@@ -1146,31 +1171,25 @@ void MWindow::goalButtionClicked()
Open traffic file Open traffic file
*/ */
void MWindow::openTraffic(QString fileName) QString MWindow::openTraffic(QString fileName)
{ {
QString fileNameTraffic = fileName.split(".").first() + "_traffic.xml"; QString fileNameTraffic = fileName.split(".").first() + "_traffic.xml";
QFile fileTraffic(fileNameTraffic); QFile fileTraffic(fileNameTraffic);
if(fileNameTraffic.isEmpty())
return;
if (!fileTraffic.open(QIODevice::ReadOnly | QIODevice::Text)) if (!fileTraffic.open(QIODevice::ReadOnly | QIODevice::Text))
{ {
QMessageBox::warning(this, tr("Read traffic XML"), QString error = "Traffic file isn't found!";
tr("Cannot read file %1:\n%2.") return error;
.arg(QDir::toNativeSeparators(fileName),
fileTraffic.errorString()));
return;
} }
if(!dmanager->readTrafficXML(fileTraffic)) if(!dmanager->readTrafficXML(fileTraffic))
{ {
QMessageBox::critical(this, QString error = "Content error, read traffic file failed";
"Prase traffic XML", return error;
"Cannot prase XML-file",
QMessageBox::Ok);
} else } else
{ {
QString error = ""; // file is loaded successful!
return error;
} }
} }
......
...@@ -102,11 +102,11 @@ protected slots: ...@@ -102,11 +102,11 @@ protected slots:
//For "Load XML" menu button //For "Load XML" menu button
void openFileXML(); void openFileXML();
void openGeometry(QString fileName); QString openGeometry(QString fileName);
void openRouting(QString fileName); QString openRouting(QString fileName);
void openSource(QString fileName); QString openSource(QString fileName);
void openGoal(QString fileName); QString openGoal(QString fileName);
void openTraffic(QString fileName); QString openTraffic(QString fileName);
void openFileCogMap(); void openFileCogMap();
void OpenLineFile(); void OpenLineFile();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment