Initial commit

This commit is contained in:
torsten committed 2026-08-13 18:33:10 +02:00
commit b7d90b9afe
16245 files changed
+3396666

No files matched your search

+292
View File
@@ -0,0 +1,292 @@
/**
* @RDE_HEADER@
* MVC model
* $Id$
* $HeadURL$
* $Author$
* Created by Mike Wille, SLSE, 2014-10-01
*/
#include "AbstractTimelineModel.h"
#include <NGLLogger/NGLLoggerBootstrap.h>
namespace LtsTimelineClassic
{
AbstractTimelineModel::AbstractTimelineModel(QObject *parent)
: QAbstractItemModel(parent)
, m_logger(NGL::NGLLoggerBootstrap::getNGLRootLogger().getNGLLogger("Timeline.AbstractTimelineModel"))
, m_highestPositionedItem(0)
, m_lowestPositionedItem(0)
, m_getEventListsRecursive(true) // get events from actuators and all their children
, m_rootItem(new Item(QLatin1String("#mwille/r00t/")))
, m_markersItem(new Item(tr("Markers"), QStringLiteral("Markers")))
{
/*/
*
* Filter Text syntax see zwmstl_exconFilter.cpp
*
/*/
m_rootItem->addItem(m_markersItem); // reparented
}
AbstractTimelineModel::~AbstractTimelineModel()
{
delete m_rootItem;
}
void AbstractTimelineModel::retranslate()
{
m_markersItem->setName(tr("Markers"));
}
void AbstractTimelineModel::invalidateTimeline()
{
const LtsTimelineClassic::ItemList il = m_rootItem->getFullItemList(true);
for (auto i = il.constBegin(); i != il.constEnd(); ++i)
{
LtsTimelineClassic::Item *item = *i;
if (item != nullptr)
item->setEventListChanged();
}
}
//void AbstractTimelineModel::invalidateItemForEvent(int uniqueId)
//{
// const LtsTimelineClassic::ItemList il = m_rootItem->getFullItemList(true);
// for (auto i = il.constBegin(); i != il.constEnd(); ++i)
// {
// LtsTimelineClassic::Item *item = *i;
// if (item != nullptr && item->getIdentifier() != QStringLiteral("Markers"))
// {
// const LtsTimelineClassic::EventList el = item->getFullEventList(true, true);
// for (LtsTimelineClassic::Event *event : el)
// {
// if (event->uniqueId() == uniqueId)
// {
// item->setEventListChanged();
// return;
// }
// }
// }
// }
// ERROR_LOG(m_logger) << "unable to invalidate an item - event not found!";
//}
Event *AbstractTimelineModel::getEvent(int uniqueId) // NOTE: ignores markers
{
const LtsTimelineClassic::ItemList il = m_rootItem->getFullItemList(true);
for (auto i = il.constBegin(); i != il.constEnd(); ++i)
{
LtsTimelineClassic::Item *item = *i;
if (item != nullptr && item->getIdentifier() != QStringLiteral("Markers"))
{
const LtsTimelineClassic::EventList el = item->getFullEventList(true, true);
for (LtsTimelineClassic::Event *event : el)
{
if (event->uniqueId() == uniqueId)
return event;
}
}
}
return nullptr;
}
void AbstractTimelineModel::addEvent(Event *event) // FIXME: to const ref ! give ownership...
{
QStringList actuatorPath = event->getActuator();
// actuatorPath => path/to/event ==> event
Item *currentItem = m_rootItem; // set first item to the root item
QModelIndex currentIndex = QModelIndex();
for (const QString &curPath : qAsConst(actuatorPath)) // look for paths in actuatorPath
{
Item *oldItem = currentItem; // to see wether an item has been found or has to be created!!!
const ItemList *itemList = currentItem->getChildren();
if (itemList != nullptr)
{
for (int row = 0; row < itemList->count(); row++) // look for items with the name equal to the path name
{
Item *childItem = itemList->at(row);
if (childItem->getName() == curPath)
{
currentIndex = index(row, 0, currentIndex);
currentItem = childItem;
break;
}
}
}
if (oldItem == currentItem) // path not found, it (item) has to be created - DO NOT FILL WITH EVENT YET, it is possible that there are paths left!
{
beginInsertRows(currentIndex, currentItem->childCount(), currentItem->childCount());
Item *newItem = new Item(curPath);
currentItem->addItem(newItem);
endInsertRows();
currentIndex = index(currentItem->childCount() - 1, 0, currentIndex); // TODO: not needed?
currentItem = newItem; // we are now on the new item to work with it
}
}
currentItem->addEvent(event);
}
Item *AbstractTimelineModel::getRootItem()
{
return m_rootItem;
}
Item *AbstractTimelineModel::itemFromIndex(const QModelIndex &idx) const
{
if (!idx.isValid())
return m_rootItem;
return static_cast<Item *>(idx.internalPointer());
}
QVariant AbstractTimelineModel::data(const QModelIndex &index, int role) const
{
if (role != Qt::DisplayRole || !index.isValid())
return QVariant();
Item *item = itemFromIndex(index);
if (!item)
return QVariant();
// if (m_listMode)
// getFullEventList
// ....
// else
if (index.column() == 1) // event row = delegate row
{
PassiveEventContainer *pevcon = item->getPevcon(); // set new event list for pevcon in case that new events were appended
return QVariant::fromValue(pevcon);
}
// actuators column (0)
QString name(item->getName());
if (name.isEmpty())
name = tr("[unknown]");
return QVariant(name);
}
Qt::ItemFlags AbstractTimelineModel::flags(const QModelIndex &index) const
{
if (!index.isValid())
return {};
return QAbstractItemModel::flags(index) | Qt::ItemIsEditable;
}
QVariant AbstractTimelineModel::headerData(int section, Qt::Orientation orientation, int role) const
{
if (orientation == Qt::Horizontal && role == Qt::DisplayRole)
{
// if (m_listMode)
switch (section)
{
case 0: return QString(tr("Actuator") + QStringLiteral("\r\n"));
case 1: return QString(tr("Events") + QStringLiteral("\r\n"));
}
// else switch (section)
// {
// case 1: return QString(tr("Event Type") + QStringLiteral("\r\n"));
// case 2: return QString(tr("Start time") + QStringLiteral("\r\n"));
// case 3: return QString(tr("End time") + QStringLiteral("\r\n"));
// }
}
return QVariant();
}
QModelIndex AbstractTimelineModel::index(int row, int column, const QModelIndex &parent) const
{
if (!hasIndex(row, column, parent))
return QModelIndex();
Item *item = itemFromIndex(parent);
Item *child = item ? item->child(row) : nullptr;
if (child)
{
//qWarning() << "new Index: row = " << row << "column = " << column << "parent = " << &parent;
return createIndex(row, column, child);
}
return QModelIndex();
}
QModelIndex AbstractTimelineModel::parent(const QModelIndex &index) const
{
if (!index.isValid())
return QModelIndex();
Item *item = itemFromIndex(index);
Item *parent = item ? item->getParent() : nullptr;
if (parent == m_rootItem || parent == nullptr)
return QModelIndex();
int idx = parent->indexOfParent();
if (idx == -1)
return QModelIndex();
return createIndex(idx, 0, parent);
}
int AbstractTimelineModel::rowCount(const QModelIndex &parent) const
{
if (!parent.isValid())
{
int r = m_rootItem->visibleChildCount();
//qWarning() << m_rootItem->getName() << "rowCount" << r;
return r;
}
Item *item = itemFromIndex(parent);
if (item)
{
int r = item->visibleChildCount();
//qWarning() << item->getName() << "rowCount" << r;
return r;
}
return 0;
}
int AbstractTimelineModel::columnCount(const QModelIndex &) const
{
return 2; // Actuator + Events
}
} // namespace LtsTimelineClassic