From cebce2b1d8b632981b491e9b6851289f2d25111d Mon Sep 17 00:00:00 2001 From: Dmitry Yurov <d.yurov@fz-juelich.de> Date: Wed, 7 Feb 2018 11:11:49 +0100 Subject: [PATCH] SpecularDataItem is now created through session model in test view --- GUI/coregui/Models/ItemCatalogue.cpp | 2 ++ GUI/coregui/Models/SpecularDataItem.cpp | 21 --------------- GUI/coregui/Views/TestView.cpp | 34 ++++++++++++++++++++++++- 3 files changed, 35 insertions(+), 22 deletions(-) diff --git a/GUI/coregui/Models/ItemCatalogue.cpp b/GUI/coregui/Models/ItemCatalogue.cpp index bb6192b1424..efcaef3c912 100644 --- a/GUI/coregui/Models/ItemCatalogue.cpp +++ b/GUI/coregui/Models/ItemCatalogue.cpp @@ -53,6 +53,7 @@ #include "ResolutionFunctionItems.h" #include "RotationItems.h" #include "SimulationOptionsItem.h" +#include "SpecularDataItem.h" #include "SphericalDetectorItem.h" #include "TransformationItem.h" #include "VectorItem.h" @@ -164,6 +165,7 @@ ItemCatalogue::ItemCatalogue() add(Constants::JobItemType, create_new<JobItem>); add(Constants::IntensityDataType, create_new<IntensityDataItem>); + add(Constants::SpecularDataType, create_new<SpecularDataItem>); add(Constants::BasicAxisType, create_new<BasicAxisItem>); add(Constants::AmplitudeAxisType, create_new<AmplitudeAxisItem>); diff --git a/GUI/coregui/Models/SpecularDataItem.cpp b/GUI/coregui/Models/SpecularDataItem.cpp index 4ef9d5dcb5a..dc13a2a943c 100644 --- a/GUI/coregui/Models/SpecularDataItem.cpp +++ b/GUI/coregui/Models/SpecularDataItem.cpp @@ -293,24 +293,3 @@ void SpecularDataItem::setLastModified(const QDateTime &dtime) { m_last_modified = dtime; } - -namespace { -double getTestValue(size_t bin) -{ - const double factor = M_PI / (180.0 * 100.0); - const double angle = bin * factor; - return (std::cos(angle * 1000.0) + 1.5) * std::exp(-(bin / 100.0)); -} -} - -SpecularDataItem* SpecularDataItem::createTestItem() -{ - auto outputData = std::make_unique<OutputData<double>>(); - outputData->addAxis(FixedBinAxis("Angle [deg]", 1000, 0.0, 10.0)); - for (size_t i = 0; i < 1000; ++i) - outputData->operator[](i) = getTestValue(i); - - auto result = new SpecularDataItem(); - result->setOutputData(outputData.release()); - return result; -} diff --git a/GUI/coregui/Views/TestView.cpp b/GUI/coregui/Views/TestView.cpp index 5098d9b73ca..69f62308b9d 100644 --- a/GUI/coregui/Views/TestView.cpp +++ b/GUI/coregui/Views/TestView.cpp @@ -34,6 +34,14 @@ #include <QCheckBox> #include <QLineEdit> +namespace { +// These functions are required for testing purposes only +// They must be removed after completion of +// SpecularDataWidget +double getTestValue(size_t bin); +SpecularDataItem* fillTestItem(SessionItem* item); +} + TestView::TestView(MainWindow *mainWindow) : QWidget(mainWindow) , m_mainWindow(mainWindow) @@ -175,12 +183,36 @@ void TestView::test_ba3d() void TestView::test_specular_data_widget() { + SessionModel* tempModel = new SessionModel("Test", this); + auto data = fillTestItem(tempModel->insertNewItem(Constants::SpecularDataType)); + QVBoxLayout *layout = new QVBoxLayout; layout->setMargin(0); layout->setSpacing(0); - auto data = SpecularDataItem::createTestItem(); auto widget = new SpecularDataWidget(this); widget->setItem(data); layout->addWidget(widget); setLayout(layout); } + +namespace { +double getTestValue(size_t bin) +{ + const double factor = M_PI / (180.0 * 100.0); + const double angle = bin * factor; + return (std::cos(angle * 1000.0) + 1.5) * std::exp(-(bin / 100.0)); +} + +SpecularDataItem* fillTestItem(SessionItem* item) +{ + SpecularDataItem* result = dynamic_cast<SpecularDataItem*>(item); + Q_ASSERT(result); + auto outputData = std::make_unique<OutputData<double>>(); + outputData->addAxis(FixedBinAxis("Angle [deg]", 1000, 0.0, 10.0)); + for (size_t i = 0; i < 1000; ++i) + outputData->operator[](i) = getTestValue(i); + + result->setOutputData(outputData.release()); + return result; +} +} -- GitLab