diff --git a/GUI/Model/Beam/SourceItems.h b/GUI/Model/Beam/SourceItems.h index 6135a0e96b2a855341b84feb159f612a896f6c6f..3ac015a02d0d4de7254bf839b6386fc84d52fdad 100644 --- a/GUI/Model/Beam/SourceItems.h +++ b/GUI/Model/Beam/SourceItems.h @@ -17,7 +17,7 @@ #include "GUI/Model/Beam/FootprintCatalog.h" #include "GUI/Model/Descriptor/DoubleProperty.h" -#include "GUI/Model/Descriptor/PolyItem.h" +#include "GUI/Model/Descriptor/PolyPtr.h" #include <functional> #include <heinz/Vectors3D.h> @@ -43,7 +43,7 @@ public: BeamDistributionItem* azimuthalAngleItem() const; void setAzimuthalAngle(double value); - PolyItem<FootprintCatalog>& footprintSelection() { return m_footprint; } + PolyPtr<FootprintItem, FootprintCatalog>& footprintSelection() { return m_footprint; } void setFootprintItem(const IFootprint* footprint); void setGaussianFootprint(double value); void setSquareFootprint(double value); @@ -60,7 +60,7 @@ protected: DoubleProperty m_intensity; std::unique_ptr<BeamDistributionItem> m_wavelength_item; std::unique_ptr<BeamDistributionItem> m_azimuthal_angle_item; - PolyItem<FootprintCatalog> m_footprint; + PolyPtr<FootprintItem, FootprintCatalog> m_footprint; }; class BeamItem : public SourceItem { diff --git a/GUI/View/Device/FootprintForm.cpp b/GUI/View/Device/FootprintForm.cpp index d999090321bb44d299e8399736f4123434f3521b..c1b6e24892f122e4d69752832d3f4c3a8bd5b387 100644 --- a/GUI/View/Device/FootprintForm.cpp +++ b/GUI/View/Device/FootprintForm.cpp @@ -28,7 +28,7 @@ FootprintForm::FootprintForm(QWidget* parent, SourceItem* item) { m_form_layout->setFieldGrowthPolicy(QFormLayout::FieldsStayAtSizeHint); ASSERT(item->footprintSelection().certainItem()); - auto* typeCombo = GUI::Util::createComboBoxFromPolyitem( + auto* typeCombo = GUI::Util::createComboBoxFromPolyPtr( item->footprintSelection(), [this](int) { updateFootprintWidgets(); diff --git a/GUI/View/Numeric/ComboUtil.h b/GUI/View/Numeric/ComboUtil.h index 5fd0e833c74ef2c0ff084df9c3c3acb05e71469f..23d4a58094970da1fd097ff2faa46f73f3092d96 100644 --- a/GUI/View/Numeric/ComboUtil.h +++ b/GUI/View/Numeric/ComboUtil.h @@ -16,6 +16,7 @@ #define BORNAGAIN_GUI_VIEW_NUMERIC_COMBOUTIL_H #include "GUI/Model/Descriptor/PolyItem.h" +#include "GUI/Model/Descriptor/PolyPtr.h" #include "GUI/View/Base/CustomEventFilters.h" #include <QComboBox> @@ -46,8 +47,8 @@ QComboBox* createComboBox(std::function<ComboProperty()> comboFunction, //! //! Changes in the combobox will be notified to the PolyItem already. The additional (and //! optional) slot can be used to be notified about an already executed change. -template <typename T> -QComboBox* createComboBoxFromPolyitem(PolyItem<T>& d, std::function<void(int)> slot, +template <typename C> +QComboBox* createComboBoxFromPolyitem(PolyItem<C>& d, std::function<void(int)> slot, bool inScrollArea) { auto* combo = new QComboBox; @@ -68,6 +69,28 @@ QComboBox* createComboBoxFromPolyitem(PolyItem<T>& d, std::function<void(int)> s return combo; } +template <typename B, typename C> +QComboBox* createComboBoxFromPolyPtr(PolyPtr<B, C>& d, std::function<void(int)> slot, + bool inScrollArea) +{ + auto* combo = new QComboBox; + combo->addItems(d.menuEntries()); + combo->setMaxCount(d.menuEntries().size()); + combo->setToolTip(d.piTooltip()); + combo->setCurrentIndex(d.currentIndex()); + + if (inScrollArea) + WheelEventEater::install(combo); + + QObject::connect(combo, &QComboBox::currentIndexChanged, [&d, slot](int index) { + d.setCurrentIndex(index); + if (slot) + slot(index); + }); + + return combo; +} + } // namespace GUI::Util #endif // BORNAGAIN_GUI_VIEW_NUMERIC_COMBOUTIL_H