Skip to content

Commit a0196b4

Browse files
committed
Fix crash when creating a new profile with no opened file
Signed-off-by: Maxime Gervais <gervais.maxime@gmail.com>
1 parent 6b00ea3 commit a0196b4

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

Source/GUI/mainwindow_Ui.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,8 +229,18 @@ void MainWindow::Ui_Init()
229229
connect(&manageDialog, &ManageBarchartConditions::newProfile, this, [&](const QString& profileFilePath) {
230230
auto currentProfileFilePath = m_profileSelectorCombobox->currentData(BarchartProfilesModel::Data).toString();
231231

232-
Plots fakePlots(0, Files[getFilesCurrentPos()]);
233-
QJsonDocument profilesJson = QJsonDocument(fakePlots.saveBarchartsProfile());
232+
233+
QJsonDocument profilesJson;
234+
if (Files.size() > getFilesCurrentPos()) {
235+
Plots fakePlots(0, Files[getFilesCurrentPos()]);
236+
profilesJson = QJsonDocument(fakePlots.saveBarchartsProfile());
237+
}
238+
else {
239+
QFile defaultProfileFile(":/barchart_profiles/default.json");
240+
if (defaultProfileFile.open(QIODevice::ReadOnly)) {
241+
profilesJson = QJsonDocument::fromJson(defaultProfileFile.readAll());
242+
}
243+
}
234244

235245
QFile file(profileFilePath);
236246
if(file.open(QFile::WriteOnly)) {

0 commit comments

Comments
 (0)