From 41bce63803e9832751e70bfb916be9648abfa05a Mon Sep 17 00:00:00 2001 From: =?utf8?q?Michal=20Mal=C3=BD?= Date: Fri, 17 Apr 2015 15:54:10 +0200 Subject: [PATCH] Do not duplicate code in data exporting. --- datafileexporter.cpp | 30 ++++++++---------------------- 1 file changed, 8 insertions(+), 22 deletions(-) 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(); -- 2.43.5