15 #ifndef BORNAGAIN_GUI_MODEL_MODEL_SESSIONMODEL_H
16 #define BORNAGAIN_GUI_MODEL_MODEL_SESSIONMODEL_H
19 #include <QStringList>
21 #include <QXmlStreamWriter>
22 #include <heinz/Complex.h>
23 #include <heinz/Vectors3D.h>
52 Qt::ItemFlags
flags(
const QModelIndex&
index)
const override;
53 QVariant
data(
const QModelIndex&
index,
int role)
const override;
54 QVariant
headerData(
int section, Qt::Orientation orientation,
int role)
const override;
57 QModelIndex
index(
int row,
int column,
const QModelIndex&
parent)
const override;
58 QModelIndex
parent(
const QModelIndex& child)
const override;
66 QMimeData*
mimeData(
const QModelIndexList& indices)
const override;
68 const QModelIndex&
parent)
const override;
69 bool dropMimeData(
const QMimeData*
data, Qt::DropAction action,
int row,
int column,
70 const QModelIndex&
parent)
override;
103 virtual void writeTo(QXmlStreamWriter* writer);
106 const QString& tag =
"");
108 template <
typename T>
109 T*
copyItem(
const T* item_to_copy,
SessionItem* new_parent =
nullptr,
const QString& tag =
"");
112 const QString& tag =
"");
115 template <
typename T = SessionItem>
117 template <
typename T = SessionItem>
119 template <
typename T = SessionItem>
120 QVector<T*>
topItems(std::function<
bool(
const T&)> accept)
const;
136 template <
typename T>
142 template <
typename T>
148 template <
typename T>
151 return static_cast<T*
>(
copy(item_to_copy, new_parent, tag));
154 template <
typename T>
157 auto items = topItems<T>();
158 return items.isEmpty() ? nullptr :
items.front();
161 template <
typename T>
166 QModelIndex parentIndex;
167 for (
int i_row = 0; i_row <
rowCount(parentIndex); ++i_row) {
168 QModelIndex itemIndex =
index(i_row, 0, parentIndex);
170 result.push_back(
item);
176 template <
typename T>
181 QModelIndex parentIndex;
182 for (
int i_row = 0; i_row <
rowCount(parentIndex); ++i_row) {
183 QModelIndex itemIndex =
index(i_row, 0, parentIndex);
186 result.push_back(
item);
194 return Qt::MoveAction;
199 return Qt::MoveAction;
Defines class SessionItem.
The service to collect messages from different senders.
Base class for a GUI data item.
QVariant value() const
Get value.
SessionModel * model() const
Returns model of this item.
T * item(const QString &tag) const
QVector< T * > items(const QString &tag="") const
QString modelType() const
Get model type.
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
T * topItem() const
Returns first item in list of topItems.
bool setData(const QModelIndex &index, const QVariant &value, int role) override
SessionItem * moveItem(SessionItem *item, SessionItem *new_parent=nullptr, int row=-1, const QString &tag="")
Move given parameterized item to the new_parent at given row. If new_parent is not defined,...
SessionModel(QString model_tag, QObject *parent=nullptr)
QMimeData * mimeData(const QModelIndexList &indices) const override
SessionItem * itemForIndex(const QModelIndex &index) const
void setDraggedItemType(const QString &type)
T * insertItem(SessionItem *parent=nullptr, int row=-1, QString tag="")
Qt::ItemFlags flags(const QModelIndex &index) const override
virtual QVector< SessionItem * > nonXMLItems() const
QString m_dragged_item_type
QModelIndex index(int row, int column, const QModelIndex &parent) const override
QVector< T * > topItems() const
QStringList mimeTypes() const override
int columnCount(const QModelIndex &parent) const override
QString getModelTag() const
virtual void readFrom(QXmlStreamReader *reader, MessageService *messageService=nullptr)
Qt::DropActions supportedDragActions() const override
void removeItem(SessionItem *item)
virtual void writeTo(QXmlStreamWriter *writer)
SessionItem * insertNewItem(QString model_type, SessionItem *parent_item=nullptr, int row=-1, QString tag="")
bool canDropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) const override
virtual void initFrom(SessionModel *model, SessionItem *parent)
SessionItem * rootItem() const
QVector< QString > acceptableDefaultItemTypes(const QModelIndex &parent) const
bool removeRows(int row, int count, const QModelIndex &parent) override
bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) override
T * copyItem(const T *item_to_copy, SessionItem *new_parent=nullptr, const QString &tag="")
Qt::DropActions supportedDropActions() const override
QVariant headerData(int section, Qt::Orientation orientation, int role) const override
int rowCount(const QModelIndex &parent) const override
void setRootItem(SessionItem *root)
SessionItem * m_root_item
QModelIndex indexOfItem(SessionItem *item) const
SessionItem * copy(const SessionItem *item_to_copy, SessionItem *new_parent=nullptr, const QString &tag="")
Copy given item to the new_parent at given row. Item intended for copying can belong to another model...