GUI: Use early return

This commit is contained in:
Daniel Marjamäki 2017-11-11 21:52:36 +01:00
parent 526d8b76a6
commit 63feebc34f
1 changed files with 27 additions and 26 deletions

View File

@ -86,33 +86,34 @@ void LibraryDialog::openCfg()
filter,
&selectedFilter);
if (!selectedFile.isEmpty()) {
QFile file(selectedFile);
if (file.open(QIODevice::ReadOnly | QIODevice::Text)) {
ignoreChanges = true;
data.open(file);
mFileName = selectedFile;
ui->buttonSave->setEnabled(false);
ui->buttonSaveAs->setEnabled(true);
ui->filter->clear();
ui->functions->clear();
for (CppcheckLibraryData::Function &function : data.functions) {
ui->functions->addItem(new FunctionListItem(ui->functions,
&function,
false));
}
ui->sortFunctions->setEnabled(!data.functions.empty());
ui->filter->setEnabled(!data.functions.empty());
ui->addFunction->setEnabled(true);
ignoreChanges = false;
} else {
QMessageBox msg(QMessageBox::Critical,
tr("Cppcheck"),
tr("Can not open file %1.").arg(selectedFile),
QMessageBox::Ok,
this);
msg.exec();
if (selectedFile.isEmpty())
return;
QFile file(selectedFile);
if (file.open(QIODevice::ReadOnly | QIODevice::Text)) {
ignoreChanges = true;
data.open(file);
mFileName = selectedFile;
ui->buttonSave->setEnabled(false);
ui->buttonSaveAs->setEnabled(true);
ui->filter->clear();
ui->functions->clear();
for (CppcheckLibraryData::Function &function : data.functions) {
ui->functions->addItem(new FunctionListItem(ui->functions,
&function,
false));
}
ui->sortFunctions->setEnabled(!data.functions.empty());
ui->filter->setEnabled(!data.functions.empty());
ui->addFunction->setEnabled(true);
ignoreChanges = false;
} else {
QMessageBox msg(QMessageBox::Critical,
tr("Cppcheck"),
tr("Can not open file %1.").arg(selectedFile),
QMessageBox::Ok,
this);
msg.exec();
}
}