Skip to content
Snippets Groups Projects
Commit 79f102ba authored by Matthias Puchner's avatar Matthias Puchner
Browse files

add abstract base class for SelectionDescriptors to ease referencing

parent 95885831
No related branches found
No related tags found
1 merge request!415Unit handling in layer oriented sample editor
......@@ -23,6 +23,18 @@
using std::function;
//! 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.
......@@ -38,7 +50,7 @@ using std::function;
//! By using this class, the underlying data scheme is hidden from the user of the data. This e.g.
//! eases SessionItem migration. The underlying implementation can be a GroupItem, a simple pointer
//! member, a std::variant or any other construction to define a selection.
template <typename T> class SelectionDescriptor {
template <typename T> class SelectionDescriptor : public AbstractSelectionDescriptor {
public:
SelectionDescriptor() = default;
......@@ -51,7 +63,7 @@ public:
{
label = item->displayName();
options = item->value().value<ComboProperty>().getValues();
setCurrentIndex = [=](int index) {
currentIndexSetter = [=](int index) {
ComboProperty comboProperty = item->value().value<ComboProperty>();
if (comboProperty.currentIndex() != index) {
......@@ -59,18 +71,22 @@ public:
item->setValue(QVariant::fromValue<ComboProperty>(comboProperty));
}
};
currentIndex = [=] { return item->value().value<ComboProperty>().currentIndex(); };
currentIndexGetter = [=] { return item->value().value<ComboProperty>().currentIndex(); };
if constexpr (std::is_pointer<T>::value)
currentItem = [=] { return dynamic_cast<T>(item->currentItem()); };
}
QString label; //!< A label text (short, no trailing colon)
QString tooltip; //!< Tooltip text
QStringList options; //!< List of options, usually presented as combo entries
function<void(int)> setCurrentIndex; //!< Function to set currently selected option
function<int()> currentIndex; //!< Function to get currently selected option
function<T()> currentItem; //!< Function to get currently selected item
virtual void setCurrentIndex(int newIndex) const override { currentIndexSetter(newIndex); }
virtual 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
function<void(int)> currentIndexSetter; //!< Function to set currently selected option
function<int()> currentIndexGetter; //!< Function to get currently selected option
function<T()> currentItem; //!< Function to get currently selected item
};
#endif // BORNAGAIN_GUI_MODELS_SELECTIONDESCRIPTOR_H
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment