diff --git a/GUI/DataLoaders/QREDataLoader.cpp b/GUI/DataLoaders/QREDataLoader.cpp index 53ae8cfb6c3f637f99a7365d27359c378c413ab4..1e36e016a65f6bd2c7de5d71c6be8e84c14287ff 100644 --- a/GUI/DataLoaders/QREDataLoader.cpp +++ b/GUI/DataLoaders/QREDataLoader.cpp @@ -208,6 +208,17 @@ void QREDataLoader::deserialize(const QByteArray& data) if (s.status() != QDataStream::Ok) throw DeserializationException::streamError(); + + // If calculationErrors contains the outdated "WrongQOrder": Throw "too old". + // Recalculation seems to be an option, but is difficult to realize since the item's + // data loading takes place at another spot in the loading process (to keep compatibility). + // Taking the little likelihood of such a file in an old project into account, it seems to + // be not worth the effort to implement compatibility for such a project. + // #baProjectCompatibility If it is decided to break project compatibility, these lines can be + // removed, as well as the type WrongQOrder itself. + for (const auto& error : m_importResult.calculationErrors.values()) + if (error.type == ErrorDefinition::wrongQOrder) + throw DeserializationException::tooOld(); } AbstractDataLoader* QREDataLoader::clone() const @@ -461,7 +472,6 @@ void QREDataLoader::calculateFromParseResult() const const int eCol = c[DataType::dR].column; QSet<double> foundQValues; - double lastFoundQ = std::numeric_limits<double>::quiet_NaN(); for (int lineNr = 0; lineNr < m_importResult.lines.size(); lineNr++) { const bool skipLine = m_importResult.lines[lineNr].first; @@ -504,11 +514,6 @@ void QREDataLoader::calculateFromParseResult() const continue; } - if (!std::isnan(lastFoundQ) && q <= lastFoundQ) { - m_importResult.addError(lineNr, ErrorDefinition::wrongQOrder); - continue; - } - if (r > 1.0) { m_importResult.addError(lineNr, ErrorDefinition::RGreaterOne, r); continue; @@ -524,22 +529,31 @@ void QREDataLoader::calculateFromParseResult() const m_importResult.eValues[lineNr] = e; m_importResult.validCalculatedLines++; foundQValues << q; - lastFoundQ = q; } } void QREDataLoader::createOutputDataFromParsingResult(RealDataItem* item) const { - // -- create OutputData - std::vector<double> qVec; - std::vector<double> rVec; - + // create data sorted by ascending Q values. + // For this, the line numbers are sorted by Q + QVector<int> lineNumbers; for (int lineNr = 0; lineNr < m_importResult.lines.size(); lineNr++) { const bool skipLine = m_importResult.lines[lineNr].first; const bool lineHasError = m_importResult.calculationErrors.contains(lineNr); if (skipLine || lineHasError) continue; + lineNumbers.push_back(lineNr); + } + + std::sort(lineNumbers.begin(), lineNumbers.end(), + [&](int a, int b) { return m_importResult.qValues[a] < m_importResult.qValues[b]; }); + + // -- create OutputData + std::vector<double> qVec; + std::vector<double> rVec; + + for (auto lineNr : lineNumbers) { qVec.push_back(m_importResult.qValues[lineNr]); rVec.push_back(m_importResult.rValues[lineNr]); } diff --git a/GUI/DataLoaders/QREDataLoader.h b/GUI/DataLoaders/QREDataLoader.h index 6bda64a2f06022caf1129b216934c1450b049695..588e89affb20ea5f917bf91ff834926e1e258a29 100644 --- a/GUI/DataLoaders/QREDataLoader.h +++ b/GUI/DataLoaders/QREDataLoader.h @@ -85,7 +85,7 @@ private: none = 0, columnDoesNotContainValidNumber = 1, duplicateQ = 2, - wrongQOrder = 3, + wrongQOrder = 3, // outdated, but kept for backwards compatibility (deserialize!) RGreaterOne = 4, RLessZero = 5 };