Files
qt5-legatus-legacy/Lts/Plugins/Evaluations/Gui/SchemaEdit/evl_edit_treemodel_general.cpp
T
2026-08-13 18:33:10 +02:00

93 lines
2.0 KiB
C++
Executable File

/**
* @RDE_HEADER@
* $Id$
* $HeadURL$
* $Author$
*
* Created by Philipp Last, NLSE, 05.01.2018
*/
#include "evl_edit_treemodel_general.h"
namespace Evaluations
{
TreeModelGeneral::TreeModelGeneral(QObject *parent, NGL::INGLLogger &logger)
: NGLTreeModel(parent, new NGLTreeItem(QVariant()), {QString()}), m_logger(logger)
{
}
void TreeModelGeneral::iterateModel(const QModelIndex &parent, const std::function<void(const QModelIndex &, const QVariant &)> &fCallback, bool recursive) const
{
for (int r = 0; r < rowCount(parent); ++r)
{
QModelIndex idx = index(r, 0, parent);
QVariant v = TreeModelGeneral::data(idx);
fCallback(idx, v);
if (recursive && hasChildren(idx))
iterateModel(idx, fCallback);
}
}
QVariant TreeModelGeneral::dataAsVariant(const QModelIndex &index) const
{
if (!index.isValid())
return QVariant();
NGLTreeItem *item = privateData(index);
return item->data();
}
QVariant TreeModelGeneral::data(const QModelIndex &index, int role) const
{
if (!index.isValid())
return NGLTreeModel::data(index, role);
if (role != Qt::DisplayRole)
return NGLTreeModel::data(index, role);
NGLTreeItem *item = privateData(index);
return item->data();
}
QModelIndex TreeModelGeneral::insertRow(const QModelIndex &parent, const QVariant &data, const QIcon &icon)
{
int row = rowCount(parent);
NGLTreeItem *item = static_cast<NGLTreeItem *>(createItem(data, icon));
item->setModified(true);
if (!NGLTreeModel::insertRow(row, parent, item))
return {};
QModelIndex newIdx = index(row, 0, parent);
return newIdx;
}
bool TreeModelGeneral::updateRow(const QModelIndex &index, const QVariant &data, const QIcon &icon)
{
if (!index.isValid())
return false;
return setItemData(index, data, icon);
}
/*
* All sub elements are also removed.
*/
void TreeModelGeneral::removeRow(const QModelIndex &idx, bool deleteRootAllowed)
{
if (!idx.parent().isValid() && !deleteRootAllowed)
return;
removeRows(idx.row(), 1, idx.parent());
}
} // namespace Evaluations