From 324531e5212e8e59237eda30c86436374b29c2a3 Mon Sep 17 00:00:00 2001 From: Matthias <github@mpuchner.de> Date: Tue, 23 Feb 2021 08:55:10 +0100 Subject: [PATCH] improve encapsulation of native output data in realDataItem --- GUI/coregui/Models/InstrumentItems.cpp | 4 ++-- GUI/coregui/Models/JobModelFunctions.cpp | 3 +-- GUI/coregui/Models/RealDataItem.cpp | 12 ++++++++++++ GUI/coregui/Models/RealDataItem.h | 4 +++- 4 files changed, 18 insertions(+), 5 deletions(-) diff --git a/GUI/coregui/Models/InstrumentItems.cpp b/GUI/coregui/Models/InstrumentItems.cpp index 86969bac2cd..9ddb8428c39 100644 --- a/GUI/coregui/Models/InstrumentItems.cpp +++ b/GUI/coregui/Models/InstrumentItems.cpp @@ -151,7 +151,7 @@ void SpecularInstrumentItem::updateToRealData(const RealDataItem* item) throw GUIHelpers::Error("Error in SpecularInstrumentItem::updateToRealData: The type " "of instrument is incompatible with passed data shape."); - const auto& data = item->nativeData()->getOutputData()->axis(0); + const auto& data = item->nativeOutputData()->axis(0); beamItem()->updateToData(data, item->nativeDataUnits()); } @@ -172,7 +172,7 @@ bool SpecularInstrumentItem::alignedWith(const RealDataItem* item) const if (!instrument_axis) return false; - const auto& native_axis = item->nativeData()->getOutputData()->axis(0); + const auto& native_axis = item->nativeOutputData()->axis(0); return *instrument_axis == native_axis; ; } diff --git a/GUI/coregui/Models/JobModelFunctions.cpp b/GUI/coregui/Models/JobModelFunctions.cpp index 26be014f4ce..ddc1ad314db 100644 --- a/GUI/coregui/Models/JobModelFunctions.cpp +++ b/GUI/coregui/Models/JobModelFunctions.cpp @@ -207,8 +207,7 @@ void JobModelFunctions::copyRealDataItem(JobItem* jobItem, const RealDataItem* r if (!realDataItem->nativeData()) return; - realDataItemCopy->nativeData()->setOutputData( - realDataItem->nativeData()->getOutputData()->clone()); + realDataItemCopy->setNativeOutputData(realDataItem->nativeOutputData()->clone()); realDataItemCopy->nativeData()->setFileName(ItemFileNameUtils::jobNativeDataFileName(*jobItem)); } diff --git a/GUI/coregui/Models/RealDataItem.cpp b/GUI/coregui/Models/RealDataItem.cpp index ac6a9daddf5..f01e6b3fe68 100644 --- a/GUI/coregui/Models/RealDataItem.cpp +++ b/GUI/coregui/Models/RealDataItem.cpp @@ -150,6 +150,18 @@ bool RealDataItem::hasNativeData() const return (nativeData() != nullptr) && (nativeData()->getOutputData() != nullptr); } +const OutputData<double>* RealDataItem::nativeOutputData() const +{ + return hasNativeData() ? nativeData()->getOutputData() : nullptr; +} + +//! takes ownership of data + +void RealDataItem::setNativeOutputData(OutputData<double>* data) +{ + nativeData()->setOutputData(data); // takes ownership of odata +} + //! Creates data item if not existing so far. Checks for rank compatibility if already existing. No //! further initialization like clearing the data etc. diff --git a/GUI/coregui/Models/RealDataItem.h b/GUI/coregui/Models/RealDataItem.h index 09e1f2086c0..f02739059bb 100644 --- a/GUI/coregui/Models/RealDataItem.h +++ b/GUI/coregui/Models/RealDataItem.h @@ -67,7 +67,9 @@ public: void initNativeData(); QString nativeDataUnits() const; void setNativeDataUnits(const QString& units); - bool hasNativeData() const; + bool hasNativeData() const; + const OutputData<double>* nativeOutputData() const; + void setNativeOutputData(OutputData<double>* data); void setOutputData(OutputData<double>* data); void setImportData(ImportDataInfo data); -- GitLab