diff --git a/GUI/coregui/Models/IntensityDataItemUtils.cpp b/GUI/coregui/Models/IntensityDataItemUtils.cpp new file mode 100644 index 0000000000000000000000000000000000000000..75a4188f392850c1fb6e837ac97a4adc9251d8af --- /dev/null +++ b/GUI/coregui/Models/IntensityDataItemUtils.cpp @@ -0,0 +1,40 @@ +// ************************************************************************** // +// +// BornAgain: simulate and fit scattering at grazing incidence +// +//! @file GUI/coregui/Models/IntensityDataItemUtils.cpp +//! @brief Implements namespace IntensityDataItemUtils +//! +//! @homepage http://www.bornagainproject.org +//! @license GNU General Public License v3 or higher (see COPYING) +//! @copyright Forschungszentrum Jülich GmbH 2016 +//! @authors Scientific Computing Group at MLZ Garching +//! @authors Céline Durniak, Marina Ganeva, David Li, Gennady Pospelov +//! @authors Walter Van Herck, Joachim Wuttke +// +// ************************************************************************** // + +#include "IntensityDataItemUtils.h" +#include "GUIHelpers.h" +#include "JobItem.h" +#include "RealDataItem.h" +#include "IntensityDataItem.h" +#include "item_constants.h" + +IntensityDataItem* IntensityDataItemUtils::intensityDataItem(SessionItem* parent) +{ + if (!parent) + throw GUIHelpers::Error("IntensityDataItemUtils::intensityDataItem() -> Error. " + "Not initialized."); + + if (parent->modelType() == Constants::JobItemType) + return &parent->item<IntensityDataItem>(JobItem::T_OUTPUT); + else if(parent->modelType() == Constants::RealDataType) + return &parent->item<IntensityDataItem>(RealDataItem::T_INTENSITY_DATA); + else if(parent->modelType() == Constants::IntensityDataType) + return dynamic_cast<IntensityDataItem *>(parent); + else + throw GUIHelpers::Error("IntensityDataItemUtils::intensityDataItem() -> Error. " + "Unexpected item."); +} + diff --git a/GUI/coregui/Models/IntensityDataItemUtils.h b/GUI/coregui/Models/IntensityDataItemUtils.h new file mode 100644 index 0000000000000000000000000000000000000000..b3fae3318c5981d352ce91551853225a104369b9 --- /dev/null +++ b/GUI/coregui/Models/IntensityDataItemUtils.h @@ -0,0 +1,35 @@ +// ************************************************************************** // +// +// BornAgain: simulate and fit scattering at grazing incidence +// +//! @file GUI/coregui/Models/IntensityDataItemUtils.h +//! @brief Defines namespace IntensityDataItemUtils +//! +//! @homepage http://www.bornagainproject.org +//! @license GNU General Public License v3 or higher (see COPYING) +//! @copyright Forschungszentrum Jülich GmbH 2016 +//! @authors Scientific Computing Group at MLZ Garching +//! @authors Céline Durniak, Marina Ganeva, David Li, Gennady Pospelov +//! @authors Walter Van Herck, Joachim Wuttke +// +// ************************************************************************** // + +#ifndef INTENSITYDATAITEMUTILS_H +#define INTENSITYDATAITEMUTILS_H + +#include "WinDllMacros.h" + +class IntensityDataItem; +class SessionItem; + +//! Utility functions for IntensityDataItem + +namespace IntensityDataItemUtils +{ + +//! Returns IntensityDataItem contained as a child in givent parent. +BA_CORE_API_ IntensityDataItem* intensityDataItem(SessionItem* parent); + +} + +#endif // INTENSITYDATAITEMUTILS_H diff --git a/GUI/coregui/Views/IntensityDataWidgets/IntensityDataWidget.cpp b/GUI/coregui/Views/IntensityDataWidgets/IntensityDataWidget.cpp index 1f11b65885bab34975cdf0b36d13b13f80f6c1fe..2971fdba56bdf14d4b8c8d53ded9b52b616c52c6 100644 --- a/GUI/coregui/Views/IntensityDataWidgets/IntensityDataWidget.cpp +++ b/GUI/coregui/Views/IntensityDataWidgets/IntensityDataWidget.cpp @@ -19,8 +19,7 @@ #include "IntensityDataPropertyWidget.h" #include "IntensityDataCanvas.h" #include "JobItem.h" -#include "RealDataItem.h" -#include "GUIHelpers.h" +#include "IntensityDataItemUtils.h" #include <QBoxLayout> #include <QMenu> @@ -72,17 +71,5 @@ void IntensityDataWidget::onContextMenuRequest(const QPoint& point) IntensityDataItem* IntensityDataWidget::intensityDataItem() { - if (!currentItem()) - throw GUIHelpers::Error("IntensityDataWidget::intensityDataItem() -> Error. " - "Not initialized."); - - if (currentItem()->modelType() == Constants::JobItemType) - return ¤tItem()->item<IntensityDataItem>(JobItem::T_OUTPUT); - else if(currentItem()->modelType() == Constants::RealDataType) - return ¤tItem()->item<IntensityDataItem>(RealDataItem::T_INTENSITY_DATA); - else if(currentItem()->modelType() == Constants::IntensityDataType) - return dynamic_cast<IntensityDataItem *>(currentItem()); - else - throw GUIHelpers::Error("IntensityDataWidget::intensityDataItem() -> Error. " - "Unexpected item."); + return IntensityDataItemUtils::intensityDataItem(currentItem()); } diff --git a/GUI/coregui/Views/JobWidgets/JobProjectionsWidget.cpp b/GUI/coregui/Views/JobWidgets/JobProjectionsWidget.cpp index 4e5e1287eeb8530be9307aa47d2a30e0445eec91..fc6deeeb74752207f00d24b6b4bb4d1b9782bde7 100644 --- a/GUI/coregui/Views/JobWidgets/JobProjectionsWidget.cpp +++ b/GUI/coregui/Views/JobWidgets/JobProjectionsWidget.cpp @@ -20,8 +20,7 @@ #include "SessionModel.h" #include "JobItem.h" #include "ProjectionsEditor.h" -#include "RealDataItem.h" -#include "GUIHelpers.h" +#include "IntensityDataItemUtils.h" #include <QVBoxLayout> JobProjectionsWidget::JobProjectionsWidget(QWidget* parent) @@ -53,19 +52,7 @@ QList<QAction*> JobProjectionsWidget::actionList() IntensityDataItem* JobProjectionsWidget::intensityDataItem() { - if (!currentItem()) - throw GUIHelpers::Error("JobProjectionsWidget::intensityDataItem() -> Error. " - "Not initialized."); - - if (currentItem()->modelType() == Constants::JobItemType) - return ¤tItem()->item<IntensityDataItem>(JobItem::T_OUTPUT); - else if(currentItem()->modelType() == Constants::RealDataType) - return ¤tItem()->item<IntensityDataItem>(RealDataItem::T_INTENSITY_DATA); - else if(currentItem()->modelType() == Constants::IntensityDataType) - return dynamic_cast<IntensityDataItem *>(currentItem()); - else - throw GUIHelpers::Error("JobProjectionsWidget::intensityDataItem() -> Error. " - "Unexpected item."); + return IntensityDataItemUtils::intensityDataItem(currentItem()); } ProjectionContainerItem*