Skip to content

Commit 87e4376

Browse files
author
etet100
committed
Remove exception handling from file save operations
Remove try/catch blocks from fileSave, fileSaveAs, and fileSaveTransformedAs; switch HeightmapExporter to instance-based calls. Simplify saveHeightmap to always prompt for a save location. Remove unused saveClicked signal connection from heightmap panel.
1 parent 0ce8142 commit 87e4376

1 file changed

Lines changed: 15 additions & 45 deletions

File tree

src/gpilot/ui/forms/frmmain.cpp

Lines changed: 15 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,6 @@ void FrmMain::initializeHeightmapPanel()
518518
});
519519
connect(ui->heightmap, &PartMainHeightmap::newClicked, this, &FrmMain::newHeightmap);
520520
connect(ui->heightmap, &PartMainHeightmap::openClicked, this, &FrmMain::openHeightmap);
521-
connect(ui->heightmap, &PartMainHeightmap::saveClicked, this, &FrmMain::saveHeightmap);
522521
connect(ui->heightmap, &PartMainHeightmap::useHeightmapToggled, this, &FrmMain::useHeightmapToggled);
523522
connect(ui->heightmap, &PartMainHeightmap::heightmapModeToggled, this, &FrmMain::heightmapModeToggled);
524523
connect(ui->heightmap, &PartMainHeightmap::showVisualizationChanged, this, [this](PartMainHeightmap::VisualizationDrawers drawers) {
@@ -955,22 +954,15 @@ void FrmMain::fileSave()
955954
if (!m_heightmapMode) {
956955
// G-code saving
957956
if (fm.gcodeOpened()) fileSaveAs(); else {
958-
try {
959-
GCodeExporter exporter;
960-
exporter.exportToFile(program(), fm.gcodeFilePath());
961-
fm.setGcodeModified(false);
962-
} catch (std::runtime_error &err) {
963-
QMessageBox::critical(this, tr("Error"), tr("Failed to save file: %1").arg(err.what()));
964-
}
957+
GCodeExporter exporter;
958+
exporter.exportToFile(program(), fm.gcodeFilePath());
959+
fm.setGcodeModified(false);
965960
}
966961
} else {
967962
// Height map saving
968963
if (fm.heightmapOpened()) fileSaveAs(); else {
969-
try {
970-
HeightmapExporter::exportToFile(heightmap(), fm.heightmapFilePath());
971-
} catch (std::runtime_error &err) {
972-
QMessageBox::critical(this, tr("Error"), tr("Failed to save heightmap: %1").arg(err.what()));
973-
}
964+
HeightmapExporter exporter;
965+
exporter.exportToFile(heightmap(), fm.heightmapFilePath());
974966
}
975967
}
976968
}
@@ -983,13 +975,8 @@ void FrmMain::fileSaveAs()
983975
QString fileName = QFileDialog::getSaveFileName(this, tr("Save file as"), lastUsedDirectory(), tr(FILE_FILTER_TEXT));
984976

985977
if (!fileName.isEmpty()) {
986-
try {
987-
GCodeExporter exporter;
988-
exporter.exportToFile(program(), fileName);
989-
} catch (std::runtime_error &err) {
990-
QMessageBox::critical(this, tr("Error"), tr("Failed to save file: %1").arg(err.what()));
991-
return;
992-
}
978+
GCodeExporter exporter;
979+
exporter.exportToFile(program(), fm.gcodeFilePath());
993980

994981
fm.setGcodeFilePath(fileName);
995982
fm.setGcodeModified(false);
@@ -1002,12 +989,8 @@ void FrmMain::fileSaveAs()
1002989
QString fileName = (QFileDialog::getSaveFileName(this, tr("Save file as"), lastUsedDirectory(), tr("Heightmap files (*.map)")));
1003990

1004991
if (!fileName.isEmpty()) {
1005-
try {
1006-
HeightmapExporter::exportToFile(heightmap(), fileName);
1007-
} catch (std::runtime_error &err) {
1008-
QMessageBox::critical(this, tr("Error"), tr("Failed to save heightmap: %1").arg(err.what()));
1009-
return;
1010-
}
992+
HeightmapExporter exporter;
993+
exporter.exportToFile(heightmap(), fm.heightmapFilePath());
1011994

1012995
fm.setHeightmapFilePath(fileName);
1013996
fm.setHeightmapModified(false);
@@ -1026,12 +1009,8 @@ void FrmMain::fileSaveTransformedAs()
10261009
QString fileName = (QFileDialog::getSaveFileName(this, tr("Save file as"), lastUsedDirectory(), tr(FILE_FILTER_TEXT)));
10271010

10281011
if (!fileName.isEmpty()) {
1029-
try {
1030-
GCodeExporter exporter;
1031-
exporter.exportToFile(program(), fileName);
1032-
} catch (std::runtime_error &err) {
1033-
QMessageBox::critical(this, tr("Error"), tr("Failed to save file: %1").arg(err.what()));
1034-
}
1012+
GCodeExporter exporter;
1013+
exporter.exportToFile(program(), fileName);
10351014
}
10361015
}
10371016

@@ -1058,22 +1037,13 @@ void FrmMain::openHeightmap()
10581037

10591038
void FrmMain::saveHeightmap()
10601039
{
1061-
FilesManager& fm = FilesManager::instance();
1062-
QString fileName = fm.heightmapFilePath();
1063-
1064-
if (fm.heightmapOpened()) {
1065-
fileName = QFileDialog::getSaveFileName(this, tr("Save heightmap as"), lastUsedDirectory(), tr("Heightmap files (*.map)"));
1066-
if (fileName.isEmpty()) {
1067-
return;
1068-
}
1040+
QString fileName = (QFileDialog::getSaveFileName(this, tr("Save heightmap as"), lastUsedDirectory(), tr("Heightmap files (*.map)")));
1041+
if (fileName.isEmpty()) {
1042+
return;
10691043
}
10701044

10711045
try {
10721046
HeightmapExporter::exportToFile(heightmap(), fileName);
1073-
fm.setHeightmapFilePath(fileName);
1074-
fm.setHeightmapModified(false);
1075-
heightmap.markAsNotModified();
1076-
ui->heightmap->setOpenFile(fileName.mid(fileName.lastIndexOf("/") + 1));
10771047
} catch (std::runtime_error &err) {
10781048
QMessageBox::critical(this, tr("Error"), tr("Failed to save heightmap: %1").arg(err.what()));
10791049
return;
@@ -1255,7 +1225,7 @@ void FrmMain::onFileSend()
12551225

12561226
void FrmMain::onFilePause(bool checked)
12571227
{
1258-
// static SenderState s;
1228+
// static SenderState s;
12591229

12601230
// if (checked) {
12611231
// //PAUSE

0 commit comments

Comments
 (0)