15 #ifndef BORNAGAIN_GUI_MODEL_DESCRIPTOR_SELECTIONPROPERTY_H
16 #define BORNAGAIN_GUI_MODEL_DESCRIPTOR_SELECTIONPROPERTY_H
61 template <
typename Catalog,
typename... ArgsForCreation>
63 ArgsForCreation... argsForCreation)
66 initDescriptor<Catalog>(label, tooltip, Catalog::types(), argsForCreation...);
81 template <
typename Catalog>
84 std::function<
void(T newItem,
const T oldItem)> initializer)
89 initDescriptor<Catalog>(label, tooltip, Catalog::types());
106 template <
typename Catalog>
109 const QVector<typename Catalog::Type>& types,
110 std::function<
void(T newItem,
const T oldItem)> initializer)
115 initDescriptor<Catalog>(label, tooltip, types);
132 void set(T t,
bool callInitializer =
false)
141 template <
typename S,
typename... ArgsForConstructor>
142 S*
set(ArgsForConstructor... argsForConstructor)
144 S* s =
new S(argsForConstructor...);
156 template <
typename Catalog,
typename... ArgsForCreation>
158 const QVector<typename Catalog::Type>& types,
159 ArgsForCreation... argsForCreation)
162 auto setCurrentIndex = [=](
int current) {
163 auto* p = Catalog::create(types[current], argsForCreation...);
171 for (
const auto type : types)
172 m_descriptor.options << Catalog::uiInfo(type).menuEntry;
174 m_descriptor.currentIndexGetter = [=]() {
return types.indexOf(Catalog::type(
m_p)); };
195 template <
typename Catalog,
typename... ArgsForCreation>
197 ArgsForCreation... argsForCreation);
205 template <
typename Catalog,
typename... ArgsForCreation>
207 ArgsForCreation... argsForCreation)
209 if (QXmlStreamWriter* w = s.
xmlWriter()) {
210 typename Catalog::CatalogedType* p = d.
get();
212 }
else if (QXmlStreamReader* r = s.
xmlReader()) {
213 typename Catalog::CatalogedType* p =
nullptr;
Defines class SelectionDescriptor.
Describes a selection (various possibilities and the current one).
Class for representing a selection, its attributes and its accessors.
S * set(ArgsForConstructor... argsForConstructor)
Directly set the new item.
QString m_persistentTag
Persistent tag for serializing.
void initDescriptor(const QString &label, const QString &tooltip, const QVector< typename Catalog::Type > &types, ArgsForCreation... argsForCreation)
SelectionDescriptor< T > m_descriptor
descriptor, holding attributes like label, tooltip
void initWithInitializer(const QString &label, const QString &tooltip, const QString &persistentTag, const QVector< typename Catalog::Type > &types, std::function< void(T newItem, const T oldItem)> initializer)
Initialize by means of a catalog class, a subsection of allowed types and an initializer function.
SelectionDescriptor< T > descriptor() const
Returns a descriptor working on this property.
void set(T t, bool callInitializer=false)
Directly set the new item.
T get() const
Direct access to the stored pointer.
QString persistentTag() const
Persistent tag for serializing.
void init(const QString &label, const QString &tooltip, const QString &persistentTag, ArgsForCreation... argsForCreation)
Initialize by means of a catalog class and optional creation arguments.
void initWithInitializer(const QString &label, const QString &tooltip, const QString &persistentTag, std::function< void(T newItem, const T oldItem)> initializer)
Initialize by means of a catalog class and an initializer function.
T operator->() const
Direct access to the stored pointer.
std::function< void(T newItem, const T oldItem)> m_initializer
initializer function. Can be empty. The first argument is the new item, the second is the old one if ...
Supports serialization to or deserialization from QXmlStream.
void write(const QString &tag, typename Catalog::CatalogedType *p)
QXmlStreamWriter * xmlWriter()
Returns stream writer or nullptr.
QXmlStreamReader * xmlReader()
Returns stream reader or nullptr.
void read(const QString &tag, typename Catalog::CatalogedType *&p, Args... argsForConstructor)
Functions to serialize various data types.
void rwSelected(Streamer &s, SelectionProperty< typename Catalog::CatalogedType * > &d, ArgsForCreation... argsForCreation)
Serializes an item from a catalog. Passes optional arguments to the constructor.