From: Michal MalĂ˝ Date: Fri, 17 Apr 2015 13:54:10 +0000 (+0200) Subject: Do not duplicate code in data exporting. X-Git-Tag: 0.5c~12 X-Git-Url: https://gitweb.devoid-pointer.net/?a=commitdiff_plain;h=41bce63803e9832751e70bfb916be9648abfa05a;p=anyanka.git Do not duplicate code in data exporting. --- diff --git a/datafileexporter.cpp b/datafileexporter.cpp index ab97907..d1b3294 100644 --- a/datafileexporter.cpp +++ b/datafileexporter.cpp @@ -87,32 +87,18 @@ exportData(const WriteList& list, const QString& path, const int formatIdx) return ReturnCode::E_INVAL_FORMAT; } - if (list.size() > 1) - file.setFileName(backend->filename(plainName, list.cbegin()->first.c_str())); - else - file.setFileName(backend->filename(plainName)); - - /* Export first signal to file */ - if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) { - QMessageBox::critical(nullptr, "Data export error", "Cannot open output file for writing."); - delete backend; - return ReturnCode::E_FAILED; - } - - ret = writeToFile(file, backend, list.cbegin()->second); - if (ret != ReturnCode::SUCCESS) { - file.close(); - delete backend; - return ret; - } - WriteList::const_iterator cit = list.cbegin(); - std::advance(cit, 1); for (; cit != list.cend(); cit++) { - file.setFileName(backend->filename(plainName, cit->first.c_str())); + /* Append a signal name to file name if more that one signal is to be exported */ + if (list.size() > 1) + file.setFileName(backend->filename(plainName, cit->first.c_str())); + else + file.setFileName(backend->filename(plainName)); + if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) { QMessageBox::critical(nullptr, "Data export error", "Cannot open output file '" + file.fileName() + "' for writing."); - return ReturnCode::E_FAILED; + ret = ReturnCode::E_FAILED; + break; } ret = writeToFile(file, backend, cit->second); file.close();