Skip to content

Commit

Permalink
Add egm file save functionality (#229)
Browse files Browse the repository at this point in the history
* Add egm file save functionality

* Add logic to handle file save using selected filter extension

* Simplify extension map and selected filter append op

* Fix fileName empty check location
  • Loading branch information
KartikShrivastava authored Jun 11, 2022
1 parent 31dbcb7 commit 3e69593
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
24 changes: 24 additions & 0 deletions MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,30 @@ void MainWindow::on_actionOpen_triggered() {
if (!fileName.isEmpty()) openFile(fileName);
}

void MainWindow::on_actionSave_triggered() {
// map useful to quickly fetch extension from the selected filter in QDialog (because Qt doesn't give a better way)
QHash<QString, QString> extensionMap;
extensionMap["EGM (*.egm)"] = ".egm";

QString selectedFilter;
QString fileName = QFileDialog::getSaveFileName(this, tr("Save Project"), "",
extensionMap.keys().join(QStringLiteral(";;")),
&selectedFilter);

if(fileName.isEmpty()) {
return;
}

if(!fileName.endsWith(extensionMap[selectedFilter], Qt::CaseInsensitive)) {
// removes any trailing periods(.) from the file path
while(fileName.endsWith(QLatin1Char('.')))
fileName.chop(1);
fileName.append(extensionMap[selectedFilter]);
}

egm::WriteProject(_project.get(), fileName.toStdString());
}

void MainWindow::on_actionPreferences_triggered() {
PreferencesDialog preferencesDialog(this);
preferencesDialog.exec();
Expand Down
1 change: 1 addition & 0 deletions MainWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ class MainWindow : public QMainWindow {
void on_actionNew_triggered();
void on_actionOpen_triggered();
void on_actionClearRecentMenu_triggered();
void on_actionSave_triggered();
void on_actionPreferences_triggered();
void on_actionExit_triggered();

Expand Down

0 comments on commit 3e69593

Please sign in to comment.