Continues migration with DDS, Common
This commit is contained in:
1 parent
9b15cee841
commit
fa48db111e
668 files changed
+111841
-2
No files matched your search
Executable
+388
@@ -0,0 +1,388 @@
|
||||
|
||||
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
#include "Item.h"
|
||||
#include "EventTools.h"
|
||||
#include "EventGraphic.h"
|
||||
|
||||
|
||||
#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 : qAsConst(*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;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user