Skip to content
Snippets Groups Projects

GUI: delete SelectionDescriptors class

Merged Mikhail Svechnikov requested to merge from_SelectionDescriptors_4 into main
All threads resolved!
49 files
+ 263
449
Compare changes
  • Side-by-side
  • Inline
Files
49
// ************************************************************************************************
//
// BornAgain: simulate and fit reflection and scattering
//
//! @file GUI/Model/Descriptor/SelectionDescriptor.h
//! @brief Defines class SelectionDescriptor
//!
//! @homepage http://www.bornagainproject.org
//! @license GNU General Public License v3 or higher (see COPYING)
//! @copyright Forschungszentrum Jülich GmbH 2021
//! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS)
//
// ************************************************************************************************
#ifndef BORNAGAIN_GUI_MODEL_DESCRIPTOR_SELECTIONDESCRIPTOR_H
#define BORNAGAIN_GUI_MODEL_DESCRIPTOR_SELECTIONDESCRIPTOR_H
#include "GUI/Util/ComboProperty.h"
#include <QString>
#include <QStringList>
#include <functional>
//! Abstract base class for SelectionDescriptor to ease referencing.
class AbstractSelectionDescriptor {
public:
virtual ~AbstractSelectionDescriptor() = default;
//! Set currently selected option
virtual void setCurrentIndex(int newIndex) const = 0;
//! Get currently selected option
virtual int currentIndex() const = 0;
};
//! Describes a selection (various possibilities and the current one).
//!
//! Usually a selection is presented as a combo box.
//!
//! SelectionDescriptor operate on a SelectionProperty. Please refer to this class for more
//! information.
//!
//! The template parameter defines the type of the current item. This can be a pointer to a common
//! base class (like RotationItem*), but it also can be a std::variant<...>, which is useful if
//! no dedicated common base class exists (like for the roughness items LayerZeroRoughnessItem and
//! LayerBasicRoughnessItem).
//! If used with a ComboProperty holder, the template parameter can be a QString, so currentItem()
//! returns the currently selected string.
//!
//! Note that this class does not provide (*implement*) a selection, but *provide
//! information* about a selection. For implementing a selection, please see SelectionProperty.
//!
//! For easy UI creation, there are functions like GUI:Util::createSelectionCombo() which take a
//! descriptor and fully initialize the created combo box.
//!
//! \sa SelectionProperty
//!
template <typename T>
class SelectionDescriptor : public AbstractSelectionDescriptor {
public:
SelectionDescriptor() = default;
operator T() const { return currentItem(); }
void setCurrentIndex(int newIndex) const override { currentIndexSetter(newIndex); }
int currentIndex() const override { return currentIndexGetter(); }
QString label; //!< A label text (short, no trailing colon)
QString tooltip; //!< Tooltip text
QStringList options; //!< List of options, usually presented as combo entries
std::function<void(int)> currentIndexSetter; //!< Function to set currently selected option
std::function<int()> currentIndexGetter; //!< Function to get currently selected option
std::function<T()> currentItem; //!< Function to get currently selected item
};
#endif // BORNAGAIN_GUI_MODEL_DESCRIPTOR_SELECTIONDESCRIPTOR_H
Loading