]> Devoid-pointer.net GitWeb - anyanka.git/commitdiff
Do not duplicate code in data exporting.
authorMichal Malý <madcatxster@devoid-pointer.net>
Fri, 17 Apr 2015 13:54:10 +0000 (15:54 +0200)
committerMichal Malý <madcatxster@devoid-pointer.net>
Fri, 17 Apr 2015 13:54:10 +0000 (15:54 +0200)
datafileexporter.cpp

index ab979076a64cbf0ead3ccd43132d4437b2b68ba9..d1b32947de844a358c813e89f15908198c082b76 100644 (file)
@@ -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();