15 #ifndef BORNAGAIN_GUI_MODEL_BASEITEM_SESSIONITEM_H
16 #define BORNAGAIN_GUI_MODEL_BASEITEM_SESSIONITEM_H
18 #include "Base/Util/Assert.h"
19 #include "Fit/Param/RealLimits.h"
22 #include "Wrap/WinDllMacros.h"
23 #include <QStringList>
26 Q_DECLARE_METATYPE(RealLimits)
30 class QXmlStreamWriter;
31 class QXmlStreamReader;
208 static constexpr
auto P_NAME{
"Name"};
217 QModelIndex
index()
const;
218 bool hasChildren()
const;
219 int numberOfChildren()
const;
220 QVector<SessionItem*> children()
const;
223 SessionItem* getChildOfType(
const QString& type)
const;
224 QVector<SessionItem*> childrenOfType(
const QString& model_type)
const;
225 template <
typename T>
226 QVector<T*> childrenOfType()
const;
227 template <
typename T>
228 T* firstChildOfType()
const;
233 bool registerTag(
const QString&
name,
int min = 0,
int max = -1, QStringList modelTypes = {});
234 bool isTag(
const QString&
name)
const;
236 QString tagFromItem(
const SessionItem* item)
const;
237 bool acceptsAsDefaultItem(
const QString& item_name)
const;
241 SessionItem* getItem(
const QString& tag =
"",
int row = 0)
const;
242 template <
typename T>
243 T* item(
const QString& tag)
const;
244 QVector<SessionItem*> getItems(
const QString& tag =
"")
const;
245 template <
typename T>
246 QVector<T*> items(
const QString& tag =
"")
const;
247 void insertChild(
int row,
SessionItem* item,
const QString& tag =
"");
248 SessionItem* takeItem(
int row,
const QString& tag);
254 SessionItem* addProperty(
const QString&
name,
const QVariant& variant);
257 template <
typename T>
258 T* addProperty(
const QString&
name);
260 QVariant getItemValue(
const QString& tag)
const;
261 void setItemValue(
const QString& tag,
const QVariant& variant)
const;
265 SessionItem* setGroupProperty(
const QString& groupTag,
const QString& modelType)
const;
266 template <
typename T>
267 T* setGroupPropertyType(
const QString& groupTag);
268 SessionItem* getGroupItem(
const QString& groupName)
const;
269 template <
typename T>
270 T& groupItem(
const QString& groupName)
const;
273 QVariant roleProperty(
int role)
const;
277 bool setRoleProperty(
int role,
const QVariant& value);
278 QVector<int> getRoles()
const;
279 void emitDataChanged(
int role = Qt::DisplayRole);
282 QString modelType()
const;
283 template <
typename T>
284 bool hasModelType()
const;
286 QVariant value()
const;
287 bool setValue(QVariant value);
289 QString defaultTag()
const;
290 void setDefaultTag(
const QString& tag);
292 QString displayName()
const;
293 void setDisplayName(
const QString& display_name);
295 QString itemName()
const;
296 void setItemName(
const QString&
name);
297 static bool isItemNamePropertyName(
const QString&
name);
299 void setEnabled(
bool enabled);
300 void setEditable(
bool enabled);
301 bool isEnabled()
const;
302 bool isEditable()
const;
304 RealLimits limits()
const;
307 int decimals()
const;
310 QString toolTip()
const;
315 virtual QByteArray serializeBinaryData()
const;
316 virtual void deserializeBinaryData(
const QByteArray&
data);
318 virtual void writeNonSessionItems(QXmlStreamWriter* writer)
const;
319 virtual void readNonSessionItems(QXmlStreamReader* reader);
320 virtual bool allowWritingChildToXml(
SessionItem* child)
const;
327 void changeFlags(
bool enabled,
int flag);
328 int getCopyNumberOfChild(
const SessionItem* item)
const;
343 template <
typename type>
352 template <
typename T>
355 auto* t =
dynamic_cast<T*
>(
getItem(tag));
360 template <
typename T>
366 if (
auto* titem =
dynamic_cast<T*
>(
item))
367 result.push_back(titem);
371 template <
typename T>
376 if (child->modelType() == T::M_TYPE)
377 result.append(
dynamic_cast<T*
>(child));
383 template <
typename T>
387 if (child->modelType() == T::M_TYPE)
388 return dynamic_cast<T*
>(child);
393 template <
typename T>
396 auto property =
new T;
398 registerTag(tagname, 1, 1, QStringList() << property->modelType());
403 template <
typename T>
407 if (!
item->hasModelType<T>())
409 return dynamic_cast<T*
>(
item);
412 template <
typename T>
420 template <
typename T>
427 template <
typename type>
430 if (QXmlStreamWriter* w = s.
xmlWriter()) {
431 auto v =
property->value().value<type>();
433 }
else if (QXmlStreamReader* r = s.
xmlReader()) {
436 property->setValue(v);
Defines class ModelMapper.
Defines info for GroupProperty, i.e. collection of model types, their labels and the name of default ...
Handles all data roles for SessionItem.
Base class for a GUI data item.
T & groupItem(const QString &groupName) const
SessionItem * addProperty(const QString &name, const QVariant &variant)
Add new property item and register new tag. name is the tag name and the display name....
SessionItem * getGroupItem(const QString &groupName) const
Access subitem of group item.
bool registerTag(const QString &name, int min=0, int max=-1, QStringList modelTypes={})
Add new tag to this item with given name, min, max and types. max = -1 -> unlimited,...
QVector< SessionItem * > getItems(const QString &tag="") const
Returns vector of all items of given tag.
std::unique_ptr< SessionItemData > m_properties
void insertChild(int row, SessionItem *item, const QString &tag="")
Insert item into given tag into given row.
bool hasModelType() const
QVector< SessionItem * > m_children
void setDisplayName(const QString &display_name)
Set display name.
T * firstChildOfType() const
T * item(const QString &tag) const
QVector< T * > items(const QString &tag="") const
SessionItem * setGroupProperty(const QString &groupTag, const QString &modelType) const
Set the current type of group item.
std::unique_ptr< SessionItemTags > m_tags
QVector< T * > childrenOfType() const
QString modelType() const
Get model type.
std::unique_ptr< ModelMapper > m_mapper
T * setGroupPropertyType(const QString &groupTag)
SessionItem * getItem(const QString &tag="", int row=0) const
Returns item in given row of given tag.
Base class for a GUI data collection. A collection is e.g. all real data (RealDataModel)....
QVariant data(const QModelIndex &index, int role) const override
QModelIndex parent(const QModelIndex &child) const override
Qt::ItemFlags flags(const QModelIndex &index) const override
QModelIndex index(int row, int column, const QModelIndex &parent) const override
QVector< QString > acceptableDefaultItemTypes(const QModelIndex &parent) const
Supports serialization to or deserialization from QXmlStream.
QXmlStreamWriter * xmlWriter()
Returns stream writer or nullptr.
QXmlStreamReader * xmlReader()
Returns stream reader or nullptr.
QString const & name(EShape k)
Functions to serialize various data types.
void rwSessionItem(Streamer &s, const QString &tag, SessionItem *property)
Only for migration.
void rwValue(Streamer &s, const QString &tag, bool &val)