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, filter,
&selectedFilter); &selectedFilter);
if (!selectedFile.isEmpty()) { if (selectedFile.isEmpty())
QFile file(selectedFile); return;
if (file.open(QIODevice::ReadOnly | QIODevice::Text)) {
ignoreChanges = true; QFile file(selectedFile);
data.open(file); if (file.open(QIODevice::ReadOnly | QIODevice::Text)) {
mFileName = selectedFile; ignoreChanges = true;
ui->buttonSave->setEnabled(false); data.open(file);
ui->buttonSaveAs->setEnabled(true); mFileName = selectedFile;
ui->filter->clear(); ui->buttonSave->setEnabled(false);
ui->functions->clear(); ui->buttonSaveAs->setEnabled(true);
for (CppcheckLibraryData::Function &function : data.functions) { ui->filter->clear();
ui->functions->addItem(new FunctionListItem(ui->functions, ui->functions->clear();
&function, for (CppcheckLibraryData::Function &function : data.functions) {
false)); ui->functions->addItem(new FunctionListItem(ui->functions,
} &function,
ui->sortFunctions->setEnabled(!data.functions.empty()); false));
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();
} }
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();
} }
} }