Files
qt-migration-legatus/qt6-after/qt6-migrated-legatus/Lts/Common/LtsTimelineClassic/Item.cpp
T
torstenandCopilot 7a6be7474e Qt6 migration: Fix BUILD_RTI=OFF build errors in TrainingAreaBase
- training_area_telegrams.cpp: Fixed QJsonObject initializer syntax (Qt6 requires {{}} not ({}))
- training_area_telegrams.cpp: Fixed fromJson() methods to access m_* members directly
- training_area_telegrams.cpp: Fixed brace mismatches in multiple toJson() methods
- training_area_telegrams.h: Changed Header struct to public members for consistency
- tx_mixin.cpp: Fixed getEquipmentNumber() template for direct member access
- lts_coordinate.cpp: Added missing #include <iomanip>
- MIGRATION_STATUS.md: Added migration progress tracking document

C++17 constraint enforced due to RTI Connext DDS 7.7.0 incompatibility with C++20+

Build status: BUILD_RTI=OFF successful (0 errors, warnings only)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-08-23 20:49:23 +02:00

338 lines
6.2 KiB
C++

#include "Item.h"
#include "EventGraphic.h"
#include "EventTools.h"
#include <QtCore/QDebug>
#include <utility>
#ifdef LTS_DEBUG
#endif
namespace LtsTimelineClassic
{
Item::Item(const QString& name, const QString& identifier)
: m_name(name), m_identifier(identifier), m_children(nullptr), m_parent(nullptr), m_pevcon(nullptr),
m_eventListChanged(true)
{
}
Item::~Item()
{
delete m_pevcon;
if (m_children)
{
qDeleteAll(*m_children);
delete m_children;
}
qDeleteAll(m_eventList);
}
PassiveEventContainer* Item::getPevcon()
{
if (!m_pevcon)
m_pevcon = new PassiveEventContainer(m_name == QStringLiteral("Markers"));
if (m_eventListChanged)
{
m_eventListChanged = false;
m_pevcon->setEventList(getEventGraphics());
}
return m_pevcon;
}
const QString Item::path() const
{
if (m_parent == nullptr)
return m_name;
return QStringLiteral("%1/%2").arg(m_parent->path(), m_name);
}
const QString& Item::getName() const
{
return m_name;
}
Item* Item::getParent() const
{
return m_parent;
}
ItemList Item::getFullItemList(bool recursive) const
{
ItemList il;
if (m_children == nullptr)
return il;
il += *m_children;
if (!recursive)
return il;
auto end = m_children->constEnd();
for (auto i = m_children->constBegin(); i != end; ++i)
{
il += (*i)->getFullItemList(recursive);
}
return il;
}
const EventGraphicList Item::getCurrentEGLFromPevcon() const
{
if (m_pevcon == nullptr)
return EventGraphicList();
return m_pevcon->getEventGraphicList();
}
const EventGraphicList Item::getEventGraphics() const
{
EventGraphicList egl;
EventList el = getFullEventList(true, false);
std::sort(el.begin(), el.end(), [](const Event* a, const Event* b) { return a->startTime() < b->startTime(); });
for (auto i1 = el.begin(); i1 != el.end(); ++i1)
{
Event* e1 = (*i1);
if (e1->isDeleted())
continue;
qint64 egStart = e1->startTime();
qint64 egEnd = egStart + EventTools::getBlockSizeTime(e1->duration());
qint64 blockSizeTime = EventTools::getBlockSizeTime();
bool egChanged = false;
EventGraphic* eg = new EventGraphic(e1);
egl += eg;
auto i2 = i1 + 1;
for (; i2 != el.end(); ++i2)
{
if (egChanged)
{
egEnd = egStart + eg->getDuration();
if (egEnd - egStart < blockSizeTime)
egEnd = egStart + blockSizeTime;
egChanged = false;
}
Event* e2 = (*i2);
if (e2->isDeleted())
continue;
qint64 start2 = e2->startTime();
if (start2 >= egStart && egEnd >= start2)
{
eg->addEvent(e2);
egChanged = true;
}
else
{
--i2;
break;
}
}
if (i2 == el.end())
break;
i1 = i2;
}
return egl;
}
EventList Item::getFullEventList(bool recursive, bool getHiddenEvents) const
{
EventList el;
if (getHiddenEvents)
{
el = m_eventList;
}
else
{
el.reserve(m_eventList.count());
for (Event* e : m_eventList)
{
if (e == nullptr || !e->isVisible())
continue;
el.append(e);
}
}
if (!m_children || !recursive)
return el;
for (const Item* item : std::as_const(*m_children))
el += item->getFullEventList(recursive, getHiddenEvents);
return el;
}
void Item::setParent(Item* parent)
{
m_parent = parent;
}
void Item::addEvent(Event* event)
{
m_eventList.append(event);
setEventListChanged();
}
void Item::setEventListChanged()
{
m_eventListChanged = true;
if (m_parent != nullptr)
{
m_parent->setEventListChanged();
}
}
bool Item::removeEvent(int eventId)
{
for (auto i = m_eventList.begin(); i != m_eventList.end(); ++i)
{
Event* event = *i;
if (event->uniqueId() == eventId)
{
m_eventList.erase(i);
setEventListChanged();
return true;
}
}
return false;
}
void Item::addItem(Item* item)
{
if (!m_children)
m_children = new ItemList();
item->setParent(this);
m_children->append(item);
}
bool Item::hasVisibleEvents() const
{
if (!m_eventList.isEmpty() && std::find_if(m_eventList.constBegin(), m_eventList.constEnd(),
[](Event* e) { return e->isVisible(); }) != m_eventList.constEnd())
return true;
if (m_children == nullptr)
return false;
for (auto i = m_children->constBegin(); i != m_children->constEnd(); ++i)
{
Item* item = *i;
if (item->hasVisibleEvents())
return true;
}
return false;
}
Item* Item::child(int row) const
{
if (m_children == nullptr)
return nullptr;
int idx = 0;
for (auto i = m_children->constBegin(); i != m_children->constEnd(); ++i)
{
Item* item = *i;
if (item->hasVisibleEvents())
{
if (row == idx)
return item;
else
idx++;
}
}
return nullptr;
}
int Item::childCount() const
{
if (m_children)
return m_children->count();
return 0;
}
int Item::visibleChildCount() const
{
if (m_children == nullptr)
return 0;
int result = 0;
for (auto i = m_children->constBegin(); i != m_children->constEnd(); ++i)
{
Item* item = *i;
if (item->hasVisibleEvents())
result++;
}
return result;
}
ItemList* Item::getChildren()
{
return m_children;
}
int Item::indexOfParent() const
{
if (m_parent == nullptr || m_parent->getChildren() == nullptr)
return -1;
int idx = 0;
ItemList* parentItemList = m_parent->getChildren();
for (auto i = parentItemList->constBegin(); i != parentItemList->constEnd(); ++i)
{
Item* item = *i;
if (item == this)
return idx;
idx++;
}
Q_ASSERT(false);
return -1;
}
} // namespace LtsTimelineClassic