Apply clang-format to Lts/Common and DTC/enum headers

- Formatted all CodeGen module files (9 files)
- Formatted LtsAppDescriptor module files
- Formatted LtsAppManager/AppChooser files
- Applied clang-format to all DTC and enum headers across modules
- Removed coordTransTests from CommonUnitTestsPlaceholder (moved to tests/)

Cosmetic changes only, no functional modifications.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
torstenandCopilot committed 2026-08-19 14:46:29 +02:00
1 parent 1881d68aef
commit d6b6ffce7c
848 files changed
+89305 -100020

No files matched your search

@@ -1,11 +1,9 @@
#include "AbstractTimelineModel.h"
#include <utility>
#include <NGLLogger/NGLLoggerBootstrap.h>
#include <utility>
namespace LtsTimelineClassic
{
@@ -17,267 +15,216 @@ AbstractTimelineModel::AbstractTimelineModel(QObject *parent) : QAbstractItemMod
, m_getEventListsRecursive(true)
, m_rootItem(new Item(QLatin1String("#mwille/r00t/")))
, m_markersItem(new Item(tr("Markers"), QStringLiteral("Markers"))),
m_logger(NGL::NGLLoggerBootstrap::getLogger()) {
m_logger(NGL::NGLLoggerBootstrap::getLogger())
{
m_rootItem->addItem(m_markersItem);
m_rootItem->addItem(m_markersItem);
}
AbstractTimelineModel::~AbstractTimelineModel()
{
delete m_rootItem;
delete m_rootItem;
}
void AbstractTimelineModel::retranslate()
{
m_markersItem->setName(tr("Markers"));
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();
}
}
Event *AbstractTimelineModel::getEvent(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::ItemList il = m_rootItem->getFullItemList(true);
for (auto i = il.constBegin(); i != il.constEnd(); ++i)
{
const LtsTimelineClassic::EventList el = item->getFullEventList(true, true);
LtsTimelineClassic::Item* item = *i;
for (LtsTimelineClassic::Event *event : el)
{
if (event->uniqueId() == uniqueId)
return event;
}
if (item != nullptr)
item->setEventListChanged();
}
}
return nullptr;
}
void AbstractTimelineModel::addEvent(Event *event)
Event* AbstractTimelineModel::getEvent(int uniqueId)
{
QStringList actuatorPath = event->getActuator();
Item *currentItem = m_rootItem;
QModelIndex currentIndex = QModelIndex();
for (const QString &curPath : std::as_const(actuatorPath))
{
Item *oldItem = currentItem;
const ItemList *itemList = currentItem->getChildren();
if (itemList != nullptr)
const LtsTimelineClassic::ItemList il = m_rootItem->getFullItemList(true);
for (auto i = il.constBegin(); i != il.constEnd(); ++i)
{
for (int row = 0; row < itemList->count(); row++)
{
Item *childItem = itemList->at(row);
if (childItem->getName() == curPath)
LtsTimelineClassic::Item* item = *i;
if (item != nullptr && item->getIdentifier() != QStringLiteral("Markers"))
{
currentIndex = index(row, 0, currentIndex);
currentItem = childItem;
break;
const LtsTimelineClassic::EventList el = item->getFullEventList(true, true);
for (LtsTimelineClassic::Event* event : el)
{
if (event->uniqueId() == uniqueId)
return event;
}
}
}
}
if (oldItem == currentItem)
return nullptr;
}
void AbstractTimelineModel::addEvent(Event* event)
{
QStringList actuatorPath = event->getActuator();
Item* currentItem = m_rootItem;
QModelIndex currentIndex = QModelIndex();
for (const QString& curPath : std::as_const(actuatorPath))
{
beginInsertRows(currentIndex, currentItem->childCount(), currentItem->childCount());
Item *newItem = new Item(curPath);
currentItem->addItem(newItem);
endInsertRows();
Item* oldItem = currentItem;
const ItemList* itemList = currentItem->getChildren();
currentIndex = index(currentItem->childCount() - 1, 0, currentIndex);
currentItem = newItem;
if (itemList != nullptr)
{
for (int row = 0; row < itemList->count(); row++)
{
Item* childItem = itemList->at(row);
if (childItem->getName() == curPath)
{
currentIndex = index(row, 0, currentIndex);
currentItem = childItem;
break;
}
}
}
if (oldItem == currentItem)
{
beginInsertRows(currentIndex, currentItem->childCount(), currentItem->childCount());
Item* newItem = new Item(curPath);
currentItem->addItem(newItem);
endInsertRows();
currentIndex = index(currentItem->childCount() - 1, 0, currentIndex);
currentItem = newItem;
}
}
}
currentItem->addEvent(event);
currentItem->addEvent(event);
}
Item *AbstractTimelineModel::getRootItem()
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
Item* AbstractTimelineModel::itemFromIndex(const QModelIndex& idx) const
{
if (role != Qt::DisplayRole || !index.isValid())
return QVariant();
Item *item = itemFromIndex(index);
if (!item)
return QVariant();
if (index.column() == 1)
{
PassiveEventContainer *pevcon = item->getPevcon();
return QVariant::fromValue(pevcon);
}
QString name(item->getName());
if (name.isEmpty())
name = tr("[unknown]");
return QVariant(name);
if (!idx.isValid())
return m_rootItem;
return static_cast<Item*>(idx.internalPointer());
}
Qt::ItemFlags AbstractTimelineModel::flags(const QModelIndex &index) const
QVariant AbstractTimelineModel::data(const QModelIndex& index, int role) const
{
if (!index.isValid())
return {};
if (role != Qt::DisplayRole || !index.isValid())
return QVariant();
return QAbstractItemModel::flags(index) | Qt::ItemIsEditable;
Item* item = itemFromIndex(index);
if (!item)
return QVariant();
if (index.column() == 1)
{
PassiveEventContainer* pevcon = item->getPevcon();
return QVariant::fromValue(pevcon);
}
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)
{
switch (section)
{
case 0: return QString(tr("Actuator") + QStringLiteral("\r\n"));
case 1: return QString(tr("Events") + QStringLiteral("\r\n"));
}
}
if (orientation == Qt::Horizontal && role == Qt::DisplayRole)
{
return QVariant();
switch (section)
{
case 0:
return QString(tr("Actuator") + QStringLiteral("\r\n"));
case 1:
return QString(tr("Events") + QStringLiteral("\r\n"));
}
}
return QVariant();
}
QModelIndex AbstractTimelineModel::index(int row, int column, const QModelIndex &parent) const
QModelIndex AbstractTimelineModel::index(int row, int column, const QModelIndex& parent) const
{
if (!hasIndex(row, column, parent))
if (!hasIndex(row, column, parent))
return QModelIndex();
Item* item = itemFromIndex(parent);
Item* child = item ? item->child(row) : nullptr;
if (child)
{
return createIndex(row, column, child);
}
return QModelIndex();
Item *item = itemFromIndex(parent);
Item *child = item ? item->child(row) : nullptr;
if (child)
{
return createIndex(row, column, child);
}
return QModelIndex();
}
QModelIndex AbstractTimelineModel::parent(const QModelIndex &index) const
QModelIndex AbstractTimelineModel::parent(const QModelIndex& index) const
{
if (!index.isValid())
return QModelIndex();
if (!index.isValid())
return QModelIndex();
Item *item = itemFromIndex(index);
Item *parent = item ? item->getParent() : nullptr;
Item* item = itemFromIndex(index);
Item* parent = item ? item->getParent() : nullptr;
if (parent == m_rootItem || parent == nullptr)
return QModelIndex();
if (parent == m_rootItem || parent == nullptr)
return QModelIndex();
int idx = parent->indexOfParent();
int idx = parent->indexOfParent();
if (idx == -1)
return QModelIndex();
if (idx == -1)
return QModelIndex();
return createIndex(idx, 0, parent);
return createIndex(idx, 0, parent);
}
int AbstractTimelineModel::rowCount(const QModelIndex &parent) const
int AbstractTimelineModel::rowCount(const QModelIndex& parent) const
{
if (!parent.isValid())
{
int r = m_rootItem->visibleChildCount();
return r;
}
if (!parent.isValid())
{
int r = m_rootItem->visibleChildCount();
Item *item = itemFromIndex(parent);
if (item)
{
int r = item->visibleChildCount();
return r;
}
return r;
}
return 0;
Item* item = itemFromIndex(parent);
if (item)
{
int r = item->visibleChildCount();
return r;
}
return 0;
}
int AbstractTimelineModel::columnCount(const QModelIndex &) const
int AbstractTimelineModel::columnCount(const QModelIndex&) const
{
return 2;
return 2;
}
}
} // namespace LtsTimelineClassic
@@ -1,113 +1,82 @@
#pragma once
#include <QObject>
#include "Event.h"
#include "Item.h"
#include "ltstimelineclassic_export.h"
#include <QAbstractItemModel>
#include <NGLLogger/INGLLogger.h>
#include <QAbstractItemModel>
#include <QObject>
namespace LtsTimelineClassic
{
class LTSTIMELINECLASSIC_EXPORT AbstractTimelineModel : public QAbstractItemModel
{
Q_OBJECT
Q_OBJECT
public:
explicit AbstractTimelineModel( QObject *parent = nullptr);
~AbstractTimelineModel();
public:
explicit AbstractTimelineModel(QObject* parent = nullptr);
~AbstractTimelineModel();
void retranslate();
void retranslate();
Item* getRootItem();
Item *getRootItem();
Event* getEvent(int uniqueId);
Event *getEvent(int uniqueId);
void invalidateTimeline();
void invalidateTimeline();
void refreshData();
qint64 highestPositionedItem() const
{
return m_highestPositionedItem;
}
void refreshData();
qint64 lowestPositionedItem() const
{
return m_lowestPositionedItem;
}
qint64 highestPositionedItem() const { return m_highestPositionedItem; }
qint64 lowestPositionedItem() const { return m_lowestPositionedItem; }
protected:
NGL::INGLLogger& m_logger;
protected:
void addEvent(Event* event);
protected:
QVariant data(const QModelIndex& index, int role) const;
Qt::ItemFlags flags(const QModelIndex& index) const;
NGL::INGLLogger &m_logger;
protected:
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
void addEvent(Event *event);
Item* itemFromIndex(const QModelIndex& idx) const;
QModelIndex index(int row, int column, const QModelIndex& parent = QModelIndex()) const;
QVariant data(const QModelIndex &index, int role) const;
QModelIndex parent(const QModelIndex& index) const;
int rowCount(const QModelIndex& parent = QModelIndex()) const;
Qt::ItemFlags flags(const QModelIndex &index) const;
int columnCount(const QModelIndex& parent = QModelIndex()) const;
virtual qint64 currentTime() const = 0;
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
qint64 m_highestPositionedItem;
qint64 m_lowestPositionedItem;
bool m_getEventListsRecursive;
Item* m_rootItem;
Item* m_markersItem;
signals:
Item *itemFromIndex(const QModelIndex &idx) const;
void signalContextMenu(const QPoint& position, Event* affectedEvent);
QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const;
QModelIndex parent(const QModelIndex &index) const;
int rowCount(const QModelIndex &parent = QModelIndex()) const;
int columnCount(const QModelIndex &parent = QModelIndex()) const;
virtual qint64 currentTime() const = 0;
qint64 m_highestPositionedItem;
qint64 m_lowestPositionedItem;
bool m_getEventListsRecursive;
Item *m_rootItem;
Item *m_markersItem;
signals:
void signalContextMenu(const QPoint &position, Event *affectedEvent);
void signalClicked(Event *affectedEvent);
void signalToolTip(const QPoint &p, Event *e);
void signalClicked(Event* affectedEvent);
void signalToolTip(const QPoint& p, Event* e);
};
}
} // namespace LtsTimelineClassic
+86 -141
View File
@@ -1,217 +1,162 @@
#include "Event.h"
#include <LtsSession/lts_session.h>
#include <QRect>
#include <QPainter>
#include <QPainterPath>
#include <QRect>
#include <time.h>
namespace LtsTimelineClassic
{
Event::Event(int uniqueId, int typeId, qint64 startTime,
qint64 endTime, int playerId, int partyId, int equipmentId, const QStringList &path,
const EventPaintFunc &paintFunc, const QColor &paintColor, const QJsonObject &detailData, int subEventId,
const LtsUtils::QPoint3D &pos, LtsSession::LtsSession *session) : m_path(path)
, m_detailData(detailData)
, m_position(pos)
, m_paintFunc(paintFunc)
, m_session(session)
, m_eventColor(paintColor)
, m_startTime(startTime)
, m_endTime(endTime)
, m_uniqueId(uniqueId)
, m_typeId(typeId)
, m_subEventId(subEventId)
, m_playerId(playerId)
, m_partyId(partyId)
, m_equipmentId(equipmentId)
, m_deleted(false)
, m_visible(true),
m_logger(NGL::NGLLoggerBootstrap::getLogger()) {
checkDuration();
Event::Event(int uniqueId, int typeId, qint64 startTime, qint64 endTime, int playerId, int partyId, int equipmentId,
const QStringList& path, const EventPaintFunc& paintFunc, const QColor& paintColor,
const QJsonObject& detailData, int subEventId, const LtsUtils::QPoint3D& pos,
LtsSession::LtsSession* session)
: m_path(path), m_detailData(detailData), m_position(pos), m_paintFunc(paintFunc), m_session(session),
m_eventColor(paintColor), m_startTime(startTime), m_endTime(endTime), m_uniqueId(uniqueId), m_typeId(typeId),
m_subEventId(subEventId), m_playerId(playerId), m_partyId(partyId), m_equipmentId(equipmentId), m_deleted(false),
m_visible(true), m_logger(NGL::NGLLoggerBootstrap::getLogger())
{
checkDuration();
}
void Event::setVisible(bool visibility)
{
if (visibility)
show();
else
hide();
if (visibility)
show();
else
hide();
}
void Event::hide()
{
this->m_visible = false;
this->m_visible = false;
}
void Event::show()
{
this->m_visible = true;
this->m_visible = true;
}
QString Event::getShortActuator() const
{
return m_path.isEmpty() ? QString() : m_path.last();
return m_path.isEmpty() ? QString() : m_path.last();
}
void Event::setEndT(qint64 newEnd)
{
m_endTime = newEnd;
m_endTime = newEnd;
checkDuration();
checkDuration();
}
bool Event::checkDuration()
{
return true;
return true;
}
qint64 Event::duration(bool ignoreLiveEvents) const
{
if (m_endTime > m_startTime)
{
if (m_duration == -1)
m_duration = m_endTime - m_startTime;
if (m_endTime > m_startTime)
{
if (m_duration == -1)
m_duration = m_endTime - m_startTime;
return m_duration;
}
return m_duration;
}
if (m_endTime < 0 && !ignoreLiveEvents)
{
qint64 currentTime = (m_session != nullptr) ? m_session->partitionTime() : time(nullptr) ;
qint64 duration = currentTime - m_startTime;
if (m_endTime < 0 && !ignoreLiveEvents)
{
qint64 currentTime = (m_session != nullptr) ? m_session->partitionTime() : time(nullptr);
qint64 duration = currentTime - m_startTime;
return duration;
}
return duration;
}
return 0;
return 0;
}
void Event::drawMultipleEventGraphic(QPainter *painter, const QRect &rect)
void Event::drawMultipleEventGraphic(QPainter* painter, const QRect& rect)
{
painter->save();
painter->setBrush(Qt::white);
painter->save();
painter->setBrush(Qt::white);
int x = rect.x();
int y = rect.y();
int h = rect.height();
int w = rect.width();
int x = rect.x();
int y = rect.y();
int h = rect.height();
int w = rect.width();
painter->drawRect(rect);
painter->drawRect(rect);
int s1 = y + h - (h * 0.4);
int s2 = y + h - (h * 0.2);
int s1 = y + h - (h * 0.4);
int s2 = y + h - (h * 0.2);
painter->drawLine(QPoint(x, s1),
QPoint(x + w, s1));
painter->drawLine(QPoint(x, s2),
QPoint(x + w, s2));
painter->drawLine(QPoint(x, s1), QPoint(x + w, s1));
painter->drawLine(QPoint(x, s2), QPoint(x + w, s2));
painter->restore();
painter->restore();
}
void Event::drawCustomEventGraphicTriangle(QPainter *painter, const QRect &rect)
void Event::drawCustomEventGraphicTriangle(QPainter* painter, const QRect& rect)
{
int x = rect.x();
int y = rect.y();
int h = rect.height();
int w = rect.width();
int x = rect.x();
int y = rect.y();
int h = rect.height();
int w = rect.width();
QPolygon pol;
pol.append(QPoint(x + 0, y + h));
pol.append(QPoint(x + (w / 2), y + 0));
pol.append(QPoint(x + w, y + h));
pol.append(QPoint(x + 0, y + h));
QPolygon pol;
pol.append(QPoint(x + 0, y + h));
pol.append(QPoint(x + (w / 2), y + 0));
pol.append(QPoint(x + w, y + h));
pol.append(QPoint(x + 0, y + h));
QPainterPath path;
path.moveTo(x, y);
path.addPolygon(pol);
QPainterPath path;
path.moveTo(x, y);
path.addPolygon(pol);
painter->drawPath(path);
painter->drawPath(path);
}
void Event::drawCustomEventGraphicInvertTriangle(QPainter *painter, const QRect &rect)
void Event::drawCustomEventGraphicInvertTriangle(QPainter* painter, const QRect& rect)
{
int x = rect.x();
int y = rect.y();
int h = rect.height();
int w = rect.width();
int x = rect.x();
int y = rect.y();
int h = rect.height();
int w = rect.width();
QPolygon pol;
pol.append(QPoint( x + 0 , y + 0));
pol.append(QPoint( x+ w , y + 0));
pol.append(QPoint(x + ( w / 2 ), y + h));
pol.append(QPoint( x + 0 , y + 0));
QPolygon pol;
pol.append(QPoint(x + 0, y + 0));
pol.append(QPoint(x + w, y + 0));
pol.append(QPoint(x + (w / 2), y + h));
pol.append(QPoint(x + 0, y + 0));
QPainterPath path;
path.moveTo(x, y);
path.addPolygon(pol);
QPainterPath path;
path.moveTo(x, y);
path.addPolygon(pol);
painter->drawPath(path);
painter->drawPath(path);
}
void Event::drawCustomEventGraphicEllipse(QPainter *painter, const QRect &rect)
void Event::drawCustomEventGraphicEllipse(QPainter* painter, const QRect& rect)
{
QPoint ellipsePos = rect.center();
ellipsePos.rx()++;
ellipsePos.ry()++;
QPoint ellipsePos = rect.center();
ellipsePos.rx()++;
ellipsePos.ry()++;
painter->drawEllipse(ellipsePos, rect.width() / 2, rect.height() / 2);
painter->drawEllipse(ellipsePos, rect.width() / 2, rect.height() / 2);
}
void Event::drawCustomEventGraphicRect(QPainter *painter, const QRect &rect)
void Event::drawCustomEventGraphicRect(QPainter* painter, const QRect& rect)
{
painter->drawRect(rect);
painter->drawRect(rect);
}
void Event::drawCustomEventGraphicRoundedRect(QPainter *painter, const QRect &rect)
void Event::drawCustomEventGraphicRoundedRect(QPainter* painter, const QRect& rect)
{
painter->drawRoundedRect(rect, 50, 50, Qt::RelativeSize);
painter->drawRoundedRect(rect, 50, 50, Qt::RelativeSize);
}
}
} // namespace LtsTimelineClassic
+136 -99
View File
@@ -1,14 +1,13 @@
#pragma once
#include "ltstimelineclassic_export.h"
#include <LtsUtilsCore/qpoint3d.h>
#include <QColor>
#include <QJsonObject>
#include <QStringList>
#include <LtsUtilsCore/qpoint3d.h>
class QPainter;
class QRect;
@@ -21,138 +20,176 @@ class LtsSession;
namespace LtsTimelineClassic
{
class LTSTIMELINECLASSIC_EXPORT Event
class LTSTIMELINECLASSIC_EXPORT Event
{
public:
enum ButtonType
{
ActiveEvent,
EventBlock,
};
public:
enum ButtonType {
ActiveEvent,
EventBlock,
};
typedef void (*EventPaintFunc)(QPainter*, const QRect&);
static void drawCustomEventGraphicTriangle(QPainter* painter, const QRect& rect);
static void drawCustomEventGraphicInvertTriangle(QPainter* painter, const QRect& rect);
static void drawCustomEventGraphicEllipse(QPainter* painter, const QRect& rect);
static void drawCustomEventGraphicRect(QPainter* painter, const QRect& rect);
static void drawCustomEventGraphicRoundedRect(QPainter* painter, const QRect& rect);
static void drawMultipleEventGraphic(QPainter* painter, const QRect& rect);
typedef void (*EventPaintFunc)(QPainter *, const QRect &);
static void drawCustomEventGraphicTriangle(QPainter *painter, const QRect &rect);
static void drawCustomEventGraphicInvertTriangle(QPainter *painter, const QRect &rect);
static void drawCustomEventGraphicEllipse(QPainter *painter, const QRect &rect);
static void drawCustomEventGraphicRect(QPainter *painter, const QRect &rect);
static void drawCustomEventGraphicRoundedRect(QPainter *painter, const QRect &rect);
static void drawMultipleEventGraphic(QPainter *painter, const QRect &rect);
Event() = default;
Event(int uniqueId, int typeId, qint64 startTime, qint64 endTime, int playerId, int partyId, int equipmentId,
const QStringList& path, const EventPaintFunc& paintFunc, const QColor& paintColor,
const QJsonObject& detailData, int subEventId = -1, const LtsUtils::QPoint3D& pos = LtsUtils::QPoint3D(),
LtsSession::LtsSession* session = nullptr);
QStringList getActuator() const
{
return m_path;
}
Event() = default;
Event(int uniqueId, int typeId, qint64 startTime, qint64 endTime,
int playerId, int partyId, int equipmentId, const QStringList &path,
const EventPaintFunc &paintFunc, const QColor &paintColor,
const QJsonObject &detailData, int subEventId = -1,
const LtsUtils::QPoint3D &pos = LtsUtils::QPoint3D(),
LtsSession::LtsSession *session = nullptr);
int typeId() const
{
return m_typeId;
}
int uniqueId() const
{
return m_uniqueId;
}
int getSubEventID() const;
QStringList getActuator() const { return m_path; }
QColor getColor() const
{
return m_eventColor;
}
int typeId() const { return m_typeId; }
int uniqueId() const { return m_uniqueId; }
EventPaintFunc getPaintFunc() const
{
return m_paintFunc;
}
int getSubEventID() const;
qint64 startTime() const
{
return m_startTime;
}
QColor getColor() const { return m_eventColor; }
qint64 endTime() const
{
return m_endTime;
}
EventPaintFunc getPaintFunc() const { return m_paintFunc; }
const QJsonObject& detailData() const
{
return m_detailData;
}
void setDetailData(const QJsonObject& detailData)
{
m_detailData = detailData;
}
qint64 startTime() const { return m_startTime; }
qint64 endTime() const { return m_endTime; }
void setEndT(qint64 newEnd);
qint64 duration(bool ignoreLiveEvents = false) const;
int playerId() const
{
return m_playerId;
}
void setPlayerId(int playerId)
{
m_playerId = playerId;
}
int partyId() const
{
return m_partyId;
}
const QJsonObject &detailData() const { return m_detailData; }
void setDetailData(const QJsonObject &detailData) { m_detailData = detailData; }
void setPartyId(int teamId)
{
m_partyId = teamId;
}
void setEndT(qint64 newEnd);
int equipmentId() const
{
return m_equipmentId;
}
void setEquipmentId(int eqId)
{
m_equipmentId = eqId;
}
qint64 duration(bool ignoreLiveEvents = false) const;
QString getShortActuator() const;
int playerId() const { return m_playerId; }
void setPlayerId(int playerId) { m_playerId = playerId; }
bool positionValid() const
{
return !std::isnan(m_position.x()) && !std::isnan(m_position.y());
}
int partyId() const { return m_partyId; }
void setPartyId(int teamId) { m_partyId = teamId; }
const LtsUtils::QPoint3D& position() const
{
return m_position;
}
int equipmentId() const { return m_equipmentId; }
void setEquipmentId(int eqId) { m_equipmentId = eqId; }
QPointF pos2d() const
{
return QPointF(m_position.x(), m_position.y());
}
QString getShortActuator() const;
void setPosition(const LtsUtils::QPoint3D& pos)
{
m_position = pos;
}
bool positionValid() const { return !std::isnan(m_position.x()) && !std::isnan(m_position.y()); }
const LtsUtils::QPoint3D &position() const { return m_position; }
QPointF pos2d() const { return QPointF(m_position.x(), m_position.y()); }
void setPosition(const LtsUtils::QPoint3D &pos) { m_position = pos; }
void hide();
void show();
bool isVisible() const
{
return m_visible;
}
void hide();
void setVisible(bool visibility = true);
void setDeleted()
{
m_deleted = true;
}
void show();
bool isDeleted() const
{
return m_deleted;
}
protected:
NGL::INGLLogger& m_logger;
QStringList m_path;
QJsonObject m_detailData;
bool isVisible() const { return m_visible; }
LtsUtils::QPoint3D m_position;
EventPaintFunc m_paintFunc = nullptr;
LtsSession::LtsSession* m_session = nullptr;
QColor m_eventColor;
qint64 m_startTime = -1;
qint64 m_endTime = -1;
mutable qint64 m_duration = -1;
int m_uniqueId = -1;
int m_typeId = -1;
int m_subEventId = -1;
int m_playerId = -1;
int m_partyId = -1;
int m_equipmentId = -1;
bool m_deleted = false;
bool m_visible = false;
void setVisible(bool visibility = true);
void setDeleted() { m_deleted = true; }
bool isDeleted() const { return m_deleted; }
protected:
NGL::INGLLogger &m_logger;
QStringList m_path;
QJsonObject m_detailData;
LtsUtils::QPoint3D m_position;
EventPaintFunc m_paintFunc = nullptr;
LtsSession::LtsSession *m_session = nullptr;
QColor m_eventColor;
qint64 m_startTime = -1;
qint64 m_endTime = -1;
mutable qint64 m_duration = -1;
int m_uniqueId = -1;
int m_typeId = -1;
int m_subEventId = -1;
int m_playerId = -1;
int m_partyId = -1;
int m_equipmentId = -1;
bool m_deleted = false;
bool m_visible = false;
private:
static bool checkDuration();
private:
static bool checkDuration();
};
}
} // namespace LtsTimelineClassic
+24 -31
View File
@@ -1,62 +1,55 @@
#include "EventDelegate.h"
#include "PassiveEventContainer.h"
#include <QModelIndex>
#include <QDebug>
#include <QModelIndex>
namespace LtsTimelineClassic
{
EventDelegate::EventDelegate(QWidget *parent)
: QStyledItemDelegate(parent)
, m_liveTime(0)
{
EventDelegate::EventDelegate(QWidget* parent) : QStyledItemDelegate(parent), m_liveTime(0) {}
QSize EventDelegate::sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const
{
(void)option;
(void)index;
return QSize(50, 20);
}
QSize EventDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
void EventDelegate::setKnownRanges(const QVector<Range>& knownRanges)
{
(void)option;
(void)index;
return QSize(50, 20);
}
void EventDelegate::setKnownRanges(const QVector<Range> &knownRanges)
{
m_knownRanges = knownRanges;
m_knownRanges = knownRanges;
}
void EventDelegate::setLiveTime(qint64 liveTime)
{
m_liveTime = liveTime;
m_liveTime = liveTime;
}
void EventDelegate::slotAddLine(int posX, qint64 time)
void EventDelegate::slotAddLine(int posX, qint64 time)
{
m_lineMap.insert(posX, time);
m_lineMap.insert(posX, time);
}
void EventDelegate::slotResetLineList()
{
m_lineMap.clear();
m_lineMap.clear();
}
void EventDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
void EventDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const
{
if (index.data().canConvert<PassiveEventContainer *>())
{
PassiveEventContainer *passiveEventContainer = qvariant_cast<PassiveEventContainer *>(index.data());
if (index.data().canConvert<PassiveEventContainer*>())
{
PassiveEventContainer* passiveEventContainer = qvariant_cast<PassiveEventContainer*>(index.data());
passiveEventContainer->paint(painter, option, m_lineMap, m_knownRanges);
}
else
QStyledItemDelegate::paint(painter, option, index);
passiveEventContainer->paint(painter, option, m_lineMap, m_knownRanges);
}
else
QStyledItemDelegate::paint(painter, option, index);
}
}
} // namespace LtsTimelineClassic
+18 -34
View File
@@ -1,56 +1,40 @@
#pragma once
#include <QObject>
#include "AbstractTimelineModel.h"
#include "Range.h"
#include <QObject>
#include <QStyledItemDelegate>
namespace LtsTimelineClassic
{
class EventDelegate : public QStyledItemDelegate
class EventDelegate : public QStyledItemDelegate
{
Q_OBJECT
Q_OBJECT
public:
public:
EventDelegate(QWidget* parent = nullptr);
void setKnownRanges(const QVector<Range>& knownRanges);
EventDelegate(QWidget *parent = nullptr);
void setKnownRanges(const QVector<Range> &knownRanges);
QSize sizeHint(const QStyleOptionViewItem& option = QStyleOptionViewItem(),
const QModelIndex& index = QModelIndex()) const;
void setLiveTime(qint64 liveTime);
QSize sizeHint(const QStyleOptionViewItem &option = QStyleOptionViewItem(), const QModelIndex &index = QModelIndex()) const;
private:
void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const;
void setLiveTime(qint64 liveTime);
private:
LineMap m_lineMap;
QVector<Range> m_knownRanges;
qint64 m_liveTime;
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const;
public slots:
void slotResetLineList();
LineMap m_lineMap;
QVector<Range> m_knownRanges;
qint64 m_liveTime;
public slots:
void slotResetLineList();
void slotAddLine(int posX, qint64 time);
void slotAddLine(int posX, qint64 time);
};
}
} // namespace LtsTimelineClassic
+101 -123
View File
@@ -1,176 +1,154 @@
#include "EventGraphic.h"
#include <utility>
#include <QPainter>
#include <QPen>
#include <QBrush>
#include <QGuiApplication>
#include <QPoint>
#include <QPalette>
#include <QDebug>
#include <QGuiApplication>
#include <QPainter>
#include <QPalette>
#include <QPen>
#include <QPoint>
#include <utility>
namespace LtsTimelineClassic
{
EventGraphic::EventGraphic(Event *event)
: m_lowest(0)
, m_duration(-1)
, m_isMultipleEvent(false)
EventGraphic::EventGraphic(Event* event) : m_lowest(0), m_duration(-1), m_isMultipleEvent(false)
{
m_eventList += event;
m_eventList += event;
}
void EventGraphic::addEvent(Event *event)
void EventGraphic::addEvent(Event* event)
{
if (event == nullptr)
return;
if (event == nullptr)
return;
m_eventList += event;
m_isMultipleEvent = true;
m_lowest = 0;
m_duration = -1;
m_eventList += event;
m_isMultipleEvent = true;
m_lowest = 0;
m_duration = -1;
}
void EventGraphic::addEventList(const QVector<Event *> &eventList)
void EventGraphic::addEventList(const QVector<Event*>& eventList)
{
if (eventList.isEmpty())
return;
if (eventList.isEmpty())
return;
m_eventList += eventList;
m_isMultipleEvent = true;
m_lowest = 0;
m_duration = -1;
m_eventList += eventList;
m_isMultipleEvent = true;
m_lowest = 0;
m_duration = -1;
}
qint64 EventGraphic::getDuration()
{
if (m_duration != -1)
if (m_duration != -1)
return m_duration;
qint64 highestDuration = 0;
qint64 lowest = lowestTime();
for (Event* event : std::as_const(m_eventList))
{
qint64 duration = (event->startTime() - lowest) + event->duration();
if (duration > highestDuration)
highestDuration = duration;
}
if (highestDuration < 0)
{
qWarning() << "duration < 0 !!" << highestDuration;
Q_ASSERT(false);
return 0;
}
m_duration = highestDuration;
return m_duration;
qint64 highestDuration = 0;
qint64 lowest = lowestTime();
for (Event *event : std::as_const(m_eventList))
{
qint64 duration = (event->startTime() - lowest) + event->duration();
if (duration > highestDuration)
highestDuration = duration;
}
if (highestDuration < 0)
{
qWarning() << "duration < 0 !!" << highestDuration;
Q_ASSERT(false);
return 0;
}
m_duration = highestDuration;
return m_duration;
}
qint64 EventGraphic::lowestTime() const
{
if (m_lowest != 0)
return m_lowest;
if (m_lowest != 0)
return m_lowest;
auto i = std::min_element(m_eventList.begin(), m_eventList.end(), [](const Event *a, const Event *b)
{
return a->startTime() < b->startTime();
});
auto i = std::min_element(m_eventList.begin(), m_eventList.end(),
[](const Event* a, const Event* b) { return a->startTime() < b->startTime(); });
if (i == m_eventList.end())
return 0;
if (i == m_eventList.end())
return 0;
m_lowest = (*i)->startTime();
return m_lowest;
m_lowest = (*i)->startTime();
return m_lowest;
}
bool EventGraphic::isMultipleEvent() const
{
return m_isMultipleEvent;
return m_isMultipleEvent;
}
void EventGraphic::drawEventGraphic(QPainter *painter, const QRect &rect) const
void EventGraphic::drawEventGraphic(QPainter* painter, const QRect& rect) const
{
painter->save();
painter->save();
painter->setPen(QPen(QBrush(QGuiApplication::palette().text()), 1.0));
painter->setPen(QPen(QBrush(QGuiApplication::palette().text()), 1.0));
if (isMultipleEvent())
Event::drawMultipleEventGraphic(painter, rect);
else
{
Event *e = m_eventList.first();
if (e == nullptr)
if (isMultipleEvent())
Event::drawMultipleEventGraphic(painter, rect);
else
{
painter->restore();
return;
Event* e = m_eventList.first();
if (e == nullptr)
{
painter->restore();
return;
}
painter->setBrush(QBrush(e->getColor()));
if (e->getPaintFunc() == nullptr)
{
painter->restore();
return;
}
e->getPaintFunc()(painter, rect);
}
painter->setBrush(QBrush(e->getColor()));
if (e->getPaintFunc() == nullptr)
{
painter->restore();
return;
}
e->getPaintFunc()(painter, rect);
}
painter->restore();
painter->restore();
}
void EventGraphic::drawDurationBackground(QPainter *painter, const QRect &rect) const
void EventGraphic::drawDurationBackground(QPainter* painter, const QRect& rect) const
{
painter->save();
if (!isMultipleEvent())
{
Event *e = m_eventList.first();
if (e == nullptr)
painter->save();
if (!isMultipleEvent())
{
painter->restore();
return;
Event* e = m_eventList.first();
if (e == nullptr)
{
painter->restore();
return;
}
painter->setBrush(QBrush(e->getColor()));
painter->setPen(QPen(QBrush(e->getColor()), 0));
}
else
{
painter->setBrush(QBrush(QColor("white")));
}
painter->setBrush(QBrush(e->getColor()));
painter->setPen(QPen(QBrush(e->getColor()), 0));
}
else
{
painter->setBrush(QBrush(QColor("white")));
}
painter->drawRect(rect.adjusted(0, 0, -2, 0));
painter->drawRect(rect.adjusted(0, 0, -2, 0));
painter->setPen(QPen(QBrush(QGuiApplication::palette().text()), 1.0));
painter->setPen(QPen(QBrush(QGuiApplication::palette().text()), 1.0));
painter->drawLine(rect.topLeft(), rect.topRight());
painter->drawLine(rect.bottomLeft() + QPoint(0, 1), rect.bottomRight() + QPoint(1, 1));
painter->restore();
painter->drawLine(rect.topLeft(), rect.topRight());
painter->drawLine(rect.bottomLeft() + QPoint(0, 1), rect.bottomRight() + QPoint(1, 1));
painter->restore();
}
}
} // namespace LtsTimelineClassic
+25 -27
View File
@@ -1,11 +1,9 @@
#pragma once
#include "EventList.h"
#include "Event.h"
#include "EventList.h"
#include "ltstimelineclassic_export.h"
namespace LtsTimelineClassic
@@ -13,36 +11,36 @@ namespace LtsTimelineClassic
class LTSTIMELINECLASSIC_EXPORT EventGraphic
{
public:
public:
enum Action {
ACTION_LEFT_CLICKED,
ACTION_RIGHT_CLICKED,
ACTION_TOOLTIP,
};
enum Action
{
ACTION_LEFT_CLICKED,
ACTION_RIGHT_CLICKED,
ACTION_TOOLTIP,
};
explicit EventGraphic(Event* event);
explicit EventGraphic(Event *event);
bool isMultipleEvent() const;
bool isMultipleEvent() const;
const QVector<Event*> eventList() const
{
return m_eventList;
}
const QVector<Event *> eventList() const { return m_eventList; }
void addEventList(const QVector<Event *> &eventList);
void addEvent(Event *event);
qint64 lowestTime() const;
qint64 getDuration();
void addEventList(const QVector<Event*>& eventList);
void addEvent(Event* event);
qint64 lowestTime() const;
qint64 getDuration();
void drawEventGraphic(QPainter *painter, const QRect &rect) const;
void drawDurationBackground(QPainter *painter, const QRect &rect) const;
void drawEventGraphic(QPainter* painter, const QRect& rect) const;
void drawDurationBackground(QPainter* painter, const QRect& rect) const;
private:
EventList m_eventList;
private:
EventList m_eventList;
mutable qint64 m_lowest;
mutable qint64 m_duration;
bool m_isMultipleEvent;
mutable qint64 m_lowest;
mutable qint64 m_duration;
bool m_isMultipleEvent;
};
}
} // namespace LtsTimelineClassic
+3 -4
View File
@@ -1,6 +1,5 @@
#pragma once
#include <QVector>
@@ -9,9 +8,9 @@ namespace LtsTimelineClassic
{
class Event;
using EventList = QVector<Event *>;
using EventList = QVector<Event*>;
class EventGraphic;
using EventGraphicList = QVector<EventGraphic *>;
using EventGraphicList = QVector<EventGraphic*>;
}
} // namespace LtsTimelineClassic
+270 -291
View File
@@ -1,27 +1,26 @@
#include "EventTools.h"
#include "EventGraphic.h"
#include "Event.h"
#include "EventGraphic.h"
#include <NGLLogger/NGLLoggerBootstrap.h>
#include <math.h>
#include <QPainter>
#include <QDebug>
#include <QPainter>
#include <math.h>
namespace LtsTimelineClassic
{
#define logger NGL::NGLLoggerBootstrap::getNGLRootLogger().getNGLLogger("Timeline.EventTools")
#define logger NGL::NGLLoggerBootstrap::getNGLRootLogger().getNGLLogger("Timeline.EventTools")
#ifdef LTS_DEBUG
#endif
#ifdef VERBOSE
#define dbg_print(x) qWarning() << #x << x
#define dbg_print(x) qWarning() << #x << x
#else
#define dbg_print(x) (void)x;
#define dbg_print(x) (void)x;
#endif
qint64 EventTools::s_minAdjusted = 0;
@@ -30,391 +29,371 @@ qint64 EventTools::s_minTimeline = 0;
qint64 EventTools::s_maxTimeline = 1;
qint64 EventTools::s_sbPos = 0;
qint64 EventTools::s_zoomFactor = 1;
int EventTools::s_paintMin = 0;
int EventTools::s_paintDiff = 0;
bool EventTools::s_isValid = false;
int EventTools::s_paintMin = 0;
int EventTools::s_paintDiff = 0;
bool EventTools::s_isValid = false;
qint64 EventTools::s_diff = 0;
int EventTools::s_sectionHeight = 0;
int EventTools::s_test = 0;
int EventTools::s_sectionHeight = 0;
int EventTools::s_test = 0;
qint64 EventTools::s_blockSizeTime = 0;
bool EventTools::s_inUse = false;
bool EventTools::s_inUse = false;
void EventTools::setValues(const qint64 min, const qint64 max, const qint64 sbPos, const qint64 zoomFactor)
{
if (s_minTimeline == min && s_maxTimeline == max && s_sbPos == sbPos && s_zoomFactor == zoomFactor)
return;
if (s_minTimeline == min && s_maxTimeline == max && s_sbPos == sbPos && s_zoomFactor == zoomFactor)
return;
s_sbPos = sbPos;
s_zoomFactor = zoomFactor;
s_sbPos = sbPos;
s_zoomFactor = zoomFactor;
s_isValid = false;
s_isValid = false;
s_minAdjusted = s_sbPos;
s_minAdjusted = s_sbPos;
double d_max = s_minAdjusted;
d_max += s_zoomFactor;
double d_max = s_minAdjusted;
d_max += s_zoomFactor;
s_maxAdjusted = d_max;
s_diff = s_maxAdjusted - s_minAdjusted;
s_maxAdjusted = d_max;
s_diff = s_maxAdjusted - s_minAdjusted;
s_minTimeline = min;
s_maxTimeline = max - EventTools::s_diff + (EventTools::getBlockSizeTime() * 2);
s_minTimeline = min;
s_maxTimeline = max - EventTools::s_diff + (EventTools::getBlockSizeTime() * 2);
recalcBlockSizeTime();
recalcBlockSizeTime();
if (min > 0 && max > 1)
{
s_isValid = true;
}
else
{
}
if (min > 0 && max > 1)
{
s_isValid = true;
}
else
{
}
#ifdef VERBOSE
qWarning() << "\r\n\r\nEventTools::setValues: " << "\r\n"
<< "s_sbPos" << s_sbPos << "\r\n"
<< "s_zoomFactor" << s_zoomFactor << "\r\n"
<< "s_minTimeline" << s_minTimeline << "\r\n"
<< "s_maxTimeline" << s_maxTimeline << "\r\n"
<< "s_isValid" << s_isValid << "\r\n"
<< "s_minAdjusted" << s_minAdjusted << "\r\n"
<< "s_maxAdjusted" << (long)s_maxAdjusted << "\r\n"
<< "s_diff" << s_diff << "\r\n"
;
qWarning() << "\r\n\r\nEventTools::setValues: "
<< "\r\n"
<< "s_sbPos" << s_sbPos << "\r\n"
<< "s_zoomFactor" << s_zoomFactor << "\r\n"
<< "s_minTimeline" << s_minTimeline << "\r\n"
<< "s_maxTimeline" << s_maxTimeline << "\r\n"
<< "s_isValid" << s_isValid << "\r\n"
<< "s_minAdjusted" << s_minAdjusted << "\r\n"
<< "s_maxAdjusted" << (long)s_maxAdjusted << "\r\n"
<< "s_diff" << s_diff << "\r\n";
#endif
}
void EventTools::setSection(const int x, const int length)
{
s_paintMin = x;
s_paintDiff = length;
s_paintMin = x;
s_paintDiff = length;
}
bool EventTools::isValid()
{
#ifdef VERBOSE
if (!s_isValid)
qWarning() << "<<<< INVALID EVENT TOOLS!!";
if (!s_isValid)
qWarning() << "<<<< INVALID EVENT TOOLS!!";
qWarning() << "\r\nEventTools::isValid: " << "\r\n"
<< "s_isValid" << s_isValid << "\r\n"
;
qWarning() << "\r\nEventTools::isValid: "
<< "\r\n"
<< "s_isValid" << s_isValid << "\r\n";
#endif
return s_isValid;
return s_isValid;
}
qint64 EventTools::getAdjustedMin()
{
if (!isValid())
return 0;
if (!isValid())
return 0;
return s_minAdjusted;
return s_minAdjusted;
}
qint64 EventTools::getAdjustedMax()
{
if (!isValid())
return 1;
if (!isValid())
return 1;
return s_maxAdjusted;
return s_maxAdjusted;
}
qint64 EventTools::getTimelineMin()
{
if (!isValid())
return 0;
if (!isValid())
return 0;
return s_minTimeline;
return s_minTimeline;
}
qint64 EventTools::getScrollbarPosition()
{
return s_sbPos;
return s_sbPos;
}
qint64 EventTools::getTimelineMax()
{
if (!isValid())
return 1;
if (!isValid())
return 1;
return s_maxTimeline;
return s_maxTimeline;
}
int EventTools::getEventPosition(qint64 eventTime)
int EventTools::getEventPosition(qint64 eventTime)
{
qint64 min = s_minAdjusted;
qint64 diff = s_diff;
qint64 min = s_minAdjusted;
qint64 diff = s_diff;
if (diff == 0)
{
if (diff == 0)
{
#ifdef VERBOSE
qWarning() << "\n\ngetEventPosition: diff == 0\n";
qWarning() << "\n\ngetEventPosition: diff == 0\n";
#endif
return 0;
}
return 0;
}
double pDiff = s_paintDiff;
double pMin = s_paintMin;
double pDiff = s_paintDiff;
double pMin = s_paintMin;
double x1 = eventTime;
x1 -= min;
x1 /= diff;
double x1 = eventTime;
x1 -= min;
x1 /= diff;
double x2 = x1;
x2 *= pDiff;
x2 += pMin;
double x2 = x1;
x2 *= pDiff;
x2 += pMin;
#ifdef VERBOSE
qWarning() << "\r\n\r\nEventTools::getEventPosition: " << "\r\n"
<< "min" << min << "\r\n"
<< "diff" << diff << "\r\n"
<< "pDiff" << pDiff << "\r\n"
<< "pMin" << pMin << "\r\n"
<< (long)x1 << "[x1]" << "= (" << eventTime << "[eventTime]" << "-" << min << "[min]" << ") /" << diff << "[diff]" << "\r\n"
<< (long)x2 << "[x2]" << "= (" << (long)x1 << "[x1]" << "*" << pDiff << "[pDiff]" << ") +" << pMin << "[pMin]" << "\r\n"
;
qWarning() << "\r\n\r\nEventTools::getEventPosition: "
<< "\r\n"
<< "min" << min << "\r\n"
<< "diff" << diff << "\r\n"
<< "pDiff" << pDiff << "\r\n"
<< "pMin" << pMin << "\r\n"
<< (long)x1 << "[x1]"
<< "= (" << eventTime << "[eventTime]"
<< "-" << min << "[min]"
<< ") /" << diff << "[diff]"
<< "\r\n"
<< (long)x2 << "[x2]"
<< "= (" << (long)x1 << "[x1]"
<< "*" << pDiff << "[pDiff]"
<< ") +" << pMin << "[pMin]"
<< "\r\n";
dbg_print(min);
dbg_print(min);
#endif
return qRound(x2);
return qRound(x2);
}
qint64 EventTools::getEventTime(double eventPosition)
qint64 EventTools::getEventTime(double eventPosition)
{
if (!isValid())
{
return 0;
}
if (!isValid())
{
if (eventPosition > 999999)
{
WARNING_LOG(logger) << "getEventTime: pos > 999999 => returning 0" ;
return 0;
}
return 0;
}
double min = s_minAdjusted;
double diff = s_diff;
double pDiff = s_paintDiff;
if (eventPosition > 999999)
{
if (pDiff < 1)
{
WARNING_LOG(logger) << "getEventTime: pDiff < 1" ;
return 0;
}
WARNING_LOG(logger) << "getEventTime: pos > 999999 => returning 0";
return 0;
}
double pMin = s_paintMin;
double min = s_minAdjusted;
double diff = s_diff;
double pDiff = s_paintDiff;
double x1 = eventPosition;
x1 -= pMin;
x1 /= pDiff;
if (pDiff < 1)
{
double x2 = x1;
x2 *= diff;
x2 += min;
WARNING_LOG(logger) << "getEventTime: pDiff < 1";
return 0;
}
return qRound64(x2);
double pMin = s_paintMin;
double x1 = eventPosition;
x1 -= pMin;
x1 /= pDiff;
double x2 = x1;
x2 *= diff;
x2 += min;
return qRound64(x2);
}
void EventTools::drawMarkLines(QPainter *painter, const EventList &eventList, int viewHeight)
void EventTools::drawMarkLines(QPainter* painter, const EventList& eventList, int viewHeight)
{
if (!isValid())
return;
if (!isValid())
return;
for (int k = 0; k < eventList.count(); k++)
{
Event* e = eventList.at(k);
int pos = getEventPosition(e->startTime());
for (int k = 0; k < eventList.count(); k++)
{
Event *e = eventList.at(k);
int pos = getEventPosition(e->startTime());
if (pos < (s_paintMin) || pos > (s_paintMin + s_paintDiff))
continue;
if (pos < (s_paintMin) || pos > (s_paintMin + s_paintDiff))
continue;
painter->drawLine(pos, 0, pos, viewHeight);
}
painter->drawLine(pos, 0, pos, viewHeight);
}
}
void EventTools::recalcBlockSizeTime()
{
s_blockSizeTime = _getBlockSizeTime();
s_blockSizeTime = _getBlockSizeTime();
}
qint64 EventTools::_getBlockSizeTime()
{
int startPos = getEventPosition(s_minAdjusted);
int endPos = getEventPosition(s_maxAdjusted);
int posDiff = endPos - startPos;
int startPos = getEventPosition(s_minAdjusted);
int endPos = getEventPosition(s_maxAdjusted);
if (posDiff < 1)
{
return 0;
}
int posDiff = endPos - startPos;
qint64 diff = s_maxAdjusted - s_minAdjusted;
if (posDiff < 1)
{
double pixelWidthInSeconds = diff;
pixelWidthInSeconds /= posDiff;
return 0;
}
int eventGraphicsWidth = eventWidth();
qint64 result = eventGraphicsWidth; result *= pixelWidthInSeconds;
qint64 diff = s_maxAdjusted - s_minAdjusted;
#ifdef VERBOSE
qWarning() << "\r\n\r\nEventTools::recalcBlockSizeTime: " << "\r\n"
<< "minAdj" << s_minAdjusted << "\r\n"
<< "maxAdj" << s_maxAdjusted << "\r\n"
<< "endPos" << endPos << "\r\n"
<< "diff" << diff << "\r\n"
<< "pixelWidthInSeconds" << pixelWidthInSeconds << "\r\n"
<< "eventGraphicsWidth" << eventGraphicsWidth << "\r\n"
<< "result" << result << "\r\n"
<< "(duration > result) ?" << (duration > result)
;
#endif
double pixelWidthInSeconds = diff;
pixelWidthInSeconds /= posDiff;
return result;
int eventGraphicsWidth = eventWidth();
qint64 result = eventGraphicsWidth;
result *= pixelWidthInSeconds;
#ifdef VERBOSE
qWarning() << "\r\n\r\nEventTools::recalcBlockSizeTime: "
<< "\r\n"
<< "minAdj" << s_minAdjusted << "\r\n"
<< "maxAdj" << s_maxAdjusted << "\r\n"
<< "endPos" << endPos << "\r\n"
<< "diff" << diff << "\r\n"
<< "pixelWidthInSeconds" << pixelWidthInSeconds << "\r\n"
<< "eventGraphicsWidth" << eventGraphicsWidth << "\r\n"
<< "result" << result << "\r\n"
<< "(duration > result) ?" << (duration > result);
#endif
return result;
}
qint64 EventTools::getBlockSizeTime(qint64 duration)
{
if (duration < s_blockSizeTime)
return s_blockSizeTime;
else
return duration;
}
void EventTools::drawEvents(QPainter *painter, const EventGraphicList &eventGraphicList, const int verticalPosition )
{
painter->save();
painter->setClipping(true);
painter->setClipRect(QRect(s_paintMin, verticalPosition, s_paintDiff, s_sectionHeight));
for (int i = 0; i < eventGraphicList.count(); i++)
{
EventGraphic *eg = eventGraphicList.at(i);
if (!eg)
{
continue;
}
qint64 eventStart = eg->lowestTime();
if (eventStart == 0)
continue;
#ifdef VERBOSE
qWarning() << "\r\n\r\nEventTools::drawEvents" << "\r\n"
<< "eventStart" << eventStart << "\r\n";
#endif
qint64 eventDuration = eg->getDuration();
int newEventPosition = getEventPosition(eventStart);
int newEventEndPosition = 0;
int finalEventEndPos = 0;
int eventGraphicsWidth = eventWidth();
if (eventDuration > 1)
{
qint64 eventPosition = eventStart;
eventPosition += eventDuration;
newEventEndPosition = getEventPosition(eventPosition);
finalEventEndPos = GetEndPos(newEventEndPosition, eventGraphicsWidth);
}
if (duration < s_blockSizeTime)
return s_blockSizeTime;
else
{
newEventEndPosition = newEventPosition;
}
if (newEventPosition + (newEventEndPosition - newEventPosition) < ((-eventGraphicsWidth) + s_paintMin) ||
newEventPosition > (s_paintMin + s_paintDiff))
{
#ifdef VERBOSE
qWarning() << "\n\ndrawEvents: boundary check result was negative\n" <<
" newEventPosition=" << newEventPosition << "\n" <<
" newEventEndPosition=" << newEventPosition << "\n" <<
" eventGraphicsWidth=" << eventGraphicsWidth << "\n" <<
" s_paintMin=" << s_paintMin << "\n" <<
" s_paintDiff=" << s_paintDiff << "\n";
#endif
continue;
}
int finalEventPos = newEventPosition;
QRect eventGraphicRect(finalEventPos, verticalPosition + 2, eventGraphicsWidth, s_sectionHeight - 6);
eg->drawEventGraphic(painter, eventGraphicRect);
#ifdef VERBOSE
qWarning() << "drawEvents > actually draw an event at "
"x=" << eventGraphicRect.x() << " "
"y=" << eventGraphicRect.y() << " "
"eventStart=" << eventStart ;
#endif
if (eventDuration > 1 &&
(finalEventEndPos - 1) > finalEventPos)
{
QRect eventGraphicEndRect(finalEventEndPos, verticalPosition + 2, eventGraphicsWidth, s_sectionHeight - 6);
eg->drawEventGraphic(painter, eventGraphicEndRect);
QRect eventWholeRect(newEventPosition + (eventGraphicsWidth / 2)
, verticalPosition + 2
, (newEventEndPosition - newEventPosition) - (eventGraphicsWidth)
, s_sectionHeight - 6);
eg->drawDurationBackground(painter, eventWholeRect);
}
}
painter->restore();
return duration;
}
}
void EventTools::drawEvents(QPainter* painter, const EventGraphicList& eventGraphicList, const int verticalPosition)
{
painter->save();
painter->setClipping(true);
painter->setClipRect(QRect(s_paintMin, verticalPosition, s_paintDiff, s_sectionHeight));
for (int i = 0; i < eventGraphicList.count(); i++)
{
EventGraphic* eg = eventGraphicList.at(i);
if (!eg)
{
continue;
}
qint64 eventStart = eg->lowestTime();
if (eventStart == 0)
continue;
#ifdef VERBOSE
qWarning() << "\r\n\r\nEventTools::drawEvents"
<< "\r\n"
<< "eventStart" << eventStart << "\r\n";
#endif
qint64 eventDuration = eg->getDuration();
int newEventPosition = getEventPosition(eventStart);
int newEventEndPosition = 0;
int finalEventEndPos = 0;
int eventGraphicsWidth = eventWidth();
if (eventDuration > 1)
{
qint64 eventPosition = eventStart;
eventPosition += eventDuration;
newEventEndPosition = getEventPosition(eventPosition);
finalEventEndPos = GetEndPos(newEventEndPosition, eventGraphicsWidth);
}
else
{
newEventEndPosition = newEventPosition;
}
if (newEventPosition + (newEventEndPosition - newEventPosition) < ((-eventGraphicsWidth) + s_paintMin) ||
newEventPosition > (s_paintMin + s_paintDiff))
{
#ifdef VERBOSE
qWarning() << "\n\ndrawEvents: boundary check result was negative\n"
<< " newEventPosition=" << newEventPosition << "\n"
<< " newEventEndPosition=" << newEventPosition << "\n"
<< " eventGraphicsWidth=" << eventGraphicsWidth << "\n"
<< " s_paintMin=" << s_paintMin << "\n"
<< " s_paintDiff=" << s_paintDiff << "\n";
#endif
continue;
}
int finalEventPos = newEventPosition;
QRect eventGraphicRect(finalEventPos, verticalPosition + 2, eventGraphicsWidth, s_sectionHeight - 6);
eg->drawEventGraphic(painter, eventGraphicRect);
#ifdef VERBOSE
qWarning() << "drawEvents > actually draw an event at "
"x="
<< eventGraphicRect.x()
<< " "
"y="
<< eventGraphicRect.y()
<< " "
"eventStart="
<< eventStart;
#endif
if (eventDuration > 1 && (finalEventEndPos - 1) > finalEventPos)
{
QRect eventGraphicEndRect(finalEventEndPos, verticalPosition + 2, eventGraphicsWidth, s_sectionHeight - 6);
eg->drawEventGraphic(painter, eventGraphicEndRect);
QRect eventWholeRect(newEventPosition + (eventGraphicsWidth / 2)
,
verticalPosition + 2, (newEventEndPosition - newEventPosition) - (eventGraphicsWidth),
s_sectionHeight - 6);
eg->drawDurationBackground(painter, eventWholeRect);
}
}
painter->restore();
}
} // namespace LtsTimelineClassic
+63 -107
View File
@@ -1,152 +1,108 @@
#pragma once
#include "EventList.h"
#include "ltstimelineclassic_export.h"
#include <QRect>
#include <QRect>
#include <time.h>
class QPainter;
namespace LtsTimelineClassic
{
class LTSTIMELINECLASSIC_EXPORT EventTools
{
static const int s_EventTopPadding = 2;
static const int s_EventHeightPadding = -6;
static const int s_ButtonTopPadding = s_EventTopPadding + 2;
static const int s_ButtonHeightPadding = s_EventHeightPadding + 7;
static const int s_EventTopPadding = 2;
static const int s_EventHeightPadding = -6;
static const int s_ButtonTopPadding = s_EventTopPadding + 2;
static const int s_ButtonHeightPadding = s_EventHeightPadding + 7;
public:
public:
static int s_test;
static int s_test;
static qint64 fromMsecsToSeconds(qint64 msecs)
{
return (msecs / 1000);
}
static qint64 fromSecondsToMsecs(qint64 minutes)
{
return (minutes * 1000);
}
static qint64 fromMsecsToSeconds(qint64 msecs)
{
return (msecs / 1000);
}
static qint64 getBlockSizeTime(qint64 duration = 0);
static qint64 fromSecondsToMsecs(qint64 minutes)
{
return (minutes * 1000);
}
static void setValues(const qint64 min, const qint64 max, const qint64 sbPos, const qint64 zoomFactor);
static void setSection(const int x, const int length);
static qint64 getBlockSizeTime(qint64 duration = 0);
static bool isValid();
static bool isRelative();
static void setValues(const qint64 min, const qint64 max, const qint64 sbPos, const qint64 zoomFactor);
static int getEventPosition(qint64 eventTime);
static qint64 getAdjustedMin();
static qint64 getAdjustedMax();
static qint64 getTimelineMin();
static void setSection(const int x, const int length);
static qint64 getTimelineMax();
static qint64 getScrollbarPosition();
static bool isValid();
static void recalcBlockSizeTime();
static qint64 getEventTime(double eventPosition);
static bool isRelative();
static void drawEvents(QPainter* painter, const EventGraphicList& eventGraphicList, const int verticalPosition);
static void drawMarkLines(QPainter* painter, const EventList& eventList, int viewHeight);
static int getEventPosition(qint64 eventTime);
static inline int eventWidth()
{
return s_sectionHeight / 2;
}
static inline int GetEndPos(int position, int graphicsWidth)
{
static qint64 getAdjustedMin();
return position - graphicsWidth - 1;
}
static inline float zoomFactor()
{
return s_zoomFactor;
}
static qint64 getAdjustedMax();
static inline void setSectionHeight(int sectionHeight)
{
s_sectionHeight = sectionHeight;
}
static bool s_inUse;
static qint64 getTimelineMin();
private:
static qint64 _getBlockSizeTime();
static qint64 s_minAdjusted;
static qint64 s_maxAdjusted;
static qint64 s_minTimeline;
static qint64 s_maxTimeline;
static qint64 s_sbPos;
static qint64 s_zoomFactor;
static int s_paintMin;
static int s_paintDiff;
static bool s_isValid;
static int s_sectionHeight;
static qint64 s_blockSizeTime;
static qint64 getTimelineMax();
static qint64 getScrollbarPosition();
static void recalcBlockSizeTime();
static qint64 getEventTime(double eventPosition);
static void drawEvents(QPainter *painter, const EventGraphicList &eventGraphicList, const int verticalPosition);
static void drawMarkLines(QPainter *painter, const EventList &eventList, int viewHeight);
static inline int eventWidth()
{
return s_sectionHeight / 2;
}
static inline int GetEndPos(int position, int graphicsWidth)
{
return position - graphicsWidth - 1;
}
static inline float zoomFactor() { return s_zoomFactor; }
static inline void setSectionHeight(int sectionHeight) { s_sectionHeight = sectionHeight; }
static bool s_inUse;
private:
static qint64 _getBlockSizeTime();
static qint64 s_minAdjusted;
static qint64 s_maxAdjusted;
static qint64 s_minTimeline;
static qint64 s_maxTimeline;
static qint64 s_sbPos;
static qint64 s_zoomFactor;
static int s_paintMin;
static int s_paintDiff;
static bool s_isValid;
static int s_sectionHeight;
static qint64 s_blockSizeTime;
public:
static qint64 s_diff;
public:
static qint64 s_diff;
};
}
} // namespace LtsTimelineClassic
+228 -280
View File
@@ -1,389 +1,337 @@
#include "Item.h"
#include "EventGraphic.h"
#include "EventTools.h"
#include <QDebug>
#include <utility>
#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(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;
delete m_pevcon;
if (m_children)
{
qDeleteAll(*m_children);
delete m_children;
}
if (m_children)
{
qDeleteAll(*m_children);
delete m_children;
}
qDeleteAll(m_eventList);
qDeleteAll(m_eventList);
}
PassiveEventContainer *Item::getPevcon()
PassiveEventContainer* Item::getPevcon()
{
if (!m_pevcon)
m_pevcon = new PassiveEventContainer(m_name == QStringLiteral("Markers"));
if (!m_pevcon)
m_pevcon = new PassiveEventContainer(m_name == QStringLiteral("Markers"));
if (m_eventListChanged)
{
m_eventListChanged = false;
m_pevcon->setEventList(getEventGraphics());
}
if (m_eventListChanged)
{
m_eventListChanged = false;
m_pevcon->setEventList(getEventGraphics());
}
return m_pevcon;
return m_pevcon;
}
const QString Item::path() const
{
if (m_parent == nullptr)
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;
return QStringLiteral("%1/%2").arg(m_parent->path(), m_name);
}
const QString &Item::getName() const
Item* Item::getParent() const
{
return m_name;
return m_parent;
}
Item *Item::getParent() const
{
return m_parent;
}
ItemList Item::getFullItemList(bool recursive) const
{
ItemList il;
ItemList il;
if (m_children == nullptr)
return il;
if (m_children == nullptr)
return il;
il += *m_children;
il += *m_children;
if (!recursive)
return il;
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)
auto end = m_children->constEnd();
for (auto i = m_children->constBegin(); i != end; ++i)
{
if (egChanged)
{
egEnd = egStart + eg->getDuration();
il += (*i)->getFullItemList(recursive);
}
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;
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;
EventList el;
if (getHiddenEvents)
{
el = m_eventList;
}
else
{
el.reserve(m_eventList.count());
for (Event *e : m_eventList)
if (getHiddenEvents)
{
if (e == nullptr || !e->isVisible())
continue;
el.append(e);
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);
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)
void Item::setParent(Item* parent)
{
m_parent = parent;
m_parent = parent;
}
void Item::addEvent(Event *event)
void Item::addEvent(Event* event)
{
m_eventList.append(event);
setEventListChanged();
m_eventList.append(event);
setEventListChanged();
}
void Item::setEventListChanged()
{
m_eventListChanged = true;
m_eventListChanged = true;
if (m_parent != nullptr)
{
m_parent->setEventListChanged();
}
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)
for (auto i = m_eventList.begin(); i != m_eventList.end(); ++i)
{
m_eventList.erase(i);
setEventListChanged();
Event* event = *i;
return true;
if (event->uniqueId() == eventId)
{
m_eventList.erase(i);
setEventListChanged();
return true;
}
}
}
return false;
return false;
}
void Item::addItem(Item *item)
void Item::addItem(Item* item)
{
if (!m_children)
m_children = new ItemList();
if (!m_children)
m_children = new ItemList();
item->setParent(this);
m_children->append(item);
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;
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())
for (auto i = m_children->constBegin(); i != m_children->constEnd(); ++i)
{
if (row == idx)
return item;
else
idx++;
}
}
Item* item = *i;
return nullptr;
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();
if (m_children)
return m_children->count();
return 0;
return 0;
}
int Item::visibleChildCount() const
{
if (m_children == nullptr)
return 0;
if (m_children == nullptr)
return 0;
int result = 0;
int result = 0;
for (auto i = m_children->constBegin(); i != m_children->constEnd(); ++i)
{
Item *item = *i;
for (auto i = m_children->constBegin(); i != m_children->constEnd(); ++i)
{
Item* item = *i;
if (item->hasVisibleEvents())
result++;
}
if (item->hasVisibleEvents())
result++;
}
return result;
return result;
}
ItemList *Item::getChildren()
ItemList* Item::getChildren()
{
return m_children;
return m_children;
}
int Item::indexOfParent() const
{
if (m_parent == nullptr || m_parent->getChildren() == nullptr)
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;
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
+44 -88
View File
@@ -1,128 +1,84 @@
#pragma once
#include "ltstimelineclassic_export.h"
#include "EventList.h"
#include "PassiveEventContainer.h"
#include "ltstimelineclassic_export.h"
namespace LtsTimelineClassic
{
class Item;
using ItemList = QList<Item *>;
class Item;
using ItemList = QList<Item*>;
class LTSTIMELINECLASSIC_EXPORT Item
{
public:
Item(const Item &) = delete;
Item &operator=(const Item &) = delete;
const EventGraphicList getEventGraphics() const;
public:
Item(const Item&) = delete;
Item& operator=(const Item&) = delete;
const EventGraphicList getEventGraphics() const;
explicit Item(const QString& name, const QString& identifier = QString());
explicit Item(const QString &name, const QString &identifier = QString());
~Item();
void addItem(Item* item);
~Item();
bool removeEvent(int eventId);
void setEventListChanged();
void addItem(Item *item);
const QString path() const;
bool removeEvent(int eventId);
PassiveEventContainer* getPevcon();
void setEventListChanged();
const EventGraphicList getCurrentEGLFromPevcon() const;
const QString path() const;
void setParent(Item* parent);
const QString& getName() const;
void setName(const QString& name)
{
m_name = name;
}
const QString& getIdentifier() const
{
return m_identifier;
}
PassiveEventContainer *getPevcon();
ItemList* getChildren();
const EventGraphicList getCurrentEGLFromPevcon() const;
Item* getParent() const;
void addEvent(Event* event);
EventList getFullEventList(bool recursive = true, bool getHiddenEvents = false) const;
ItemList getFullItemList(bool recursive = true) const;
void setParent(Item *parent);
Item* child(int row) const;
int indexOfParent() const;
const QString &getName() const;
int childCount() const;
void setName(const QString &name) { m_name = name; }
int visibleChildCount() const;
const QString &getIdentifier() const { return m_identifier; }
bool hasVisibleEvents() const;
private:
QString m_name;
QString m_identifier;
ItemList* m_children;
Item* m_parent;
PassiveEventContainer* m_pevcon;
EventList m_eventList;
ItemList *getChildren();
Item *getParent() const;
void addEvent(Event *event);
EventList getFullEventList(bool recursive = true, bool getHiddenEvents = false) const;
ItemList getFullItemList(bool recursive = true) const;
Item *child(int row) const;
int indexOfParent() const;
int childCount() const;
int visibleChildCount() const;
bool hasVisibleEvents() const;
private:
QString m_name;
QString m_identifier;
ItemList *m_children;
Item *m_parent;
PassiveEventContainer *m_pevcon;
EventList m_eventList;
bool m_eventListChanged;
bool m_eventListChanged;
};
}
} // namespace LtsTimelineClassic
-1
View File
@@ -1,6 +1,5 @@
#pragma once
#include <QMap>
@@ -1,133 +1,99 @@
#include "PassiveEventContainer.h"
#include "EventGraphic.h"
#include "EventTools.h"
#include <QBrush>
#include <QDebug>
#include <QGuiApplication>
#include <QPainter>
#include <QPen>
#include <QStyleOptionViewItem>
#include <QBrush>
#include <math.h>
#include <time.h>
#include <QDebug>
namespace LtsTimelineClassic
{
PassiveEventContainer::PassiveEventContainer(bool ignoreKnownRanges, QObject *parent)
: QObject(parent)
, m_ignoreKnownRanges(ignoreKnownRanges)
PassiveEventContainer::PassiveEventContainer(bool ignoreKnownRanges, QObject* parent)
: QObject(parent), m_ignoreKnownRanges(ignoreKnownRanges)
{
}
PassiveEventContainer::~PassiveEventContainer()
{
qDeleteAll(m_eventGraphicList);
qDeleteAll(m_eventGraphicList);
}
EventGraphicList PassiveEventContainer::getEventGraphicList() const
{
return m_eventGraphicList;
return m_eventGraphicList;
}
void PassiveEventContainer::setEventList(const EventGraphicList &eventGraphicList)
void PassiveEventContainer::setEventList(const EventGraphicList& eventGraphicList)
{
qDeleteAll(m_eventGraphicList);
qDeleteAll(m_eventGraphicList);
m_eventGraphicList = eventGraphicList;
m_eventGraphicList = eventGraphicList;
}
void PassiveEventContainer::paint(QPainter *painter, const QStyleOptionViewItem &option, const LineMap &lineMap,
const QVector<Range> &knownRanges) const
void PassiveEventContainer::paint(QPainter* painter, const QStyleOptionViewItem& option, const LineMap& lineMap,
const QVector<Range>& knownRanges) const
{
EventTools::s_test++;
EventTools::s_test++;
bool alternate = option.features.testFlag(QStyleOptionViewItem::ViewItemFeature::Alternate);
const QColor bg = QColor(alternate ? QRgb(0xF6D8CE) : QRgb(0xFBF2EF));
bool alternate = option.features.testFlag(QStyleOptionViewItem::ViewItemFeature::Alternate);
const QColor bg = QColor(alternate ? QRgb(0xF6D8CE) : QRgb(0xFBF2EF));
QColor cachedBg(Qt::white);
if (alternate)
cachedBg = cachedBg.darker(110);
QColor cachedBg(Qt::white);
if (alternate)
cachedBg = cachedBg.darker(110);
painter->fillRect(option.rect, QBrush(bg));
painter->fillRect(option.rect, QBrush(bg));
int posX1 = option.rect.x();
int posX2 = option.rect.right();
int posY1 = option.rect.y();
int posY2 = option.rect.bottom();
int h = posY2 - posY1 + 1;
int posX1 = option.rect.x();
int posX2 = option.rect.right();
int posY1 = option.rect.y();
int posY2 = option.rect.bottom();
int h = posY2 - posY1 + 1;
painter->save();
painter->setClipping(true);
painter->setClipRect(option.rect.adjusted(0, 0, 1, 1));
painter->save();
painter->setClipping(true);
painter->setClipRect(option.rect.adjusted(0, 0, 1, 1));
int eventWidth = EventTools::eventWidth();
int eventWidth = EventTools::eventWidth();
if (m_ignoreKnownRanges)
{
painter->fillRect(QRect(posX1, posY1, posX2 - posX1, h), cachedBg);
}
else
{
for (const auto &range : knownRanges)
if (m_ignoreKnownRanges)
{
int rangeStart = EventTools::getEventPosition(range.start);
int rangeEnd = EventTools::getEventPosition(range.end);
if (rangeEnd >= posX1 && rangeStart <= posX2)
painter->fillRect(QRect(rangeStart, posY1, rangeEnd - rangeStart + eventWidth + 1, h), cachedBg);
painter->fillRect(QRect(posX1, posY1, posX2 - posX1, h), cachedBg);
}
}
else
{
for (const auto& range : knownRanges)
{
int rangeStart = EventTools::getEventPosition(range.start);
int rangeEnd = EventTools::getEventPosition(range.end);
if (rangeEnd >= posX1 && rangeStart <= posX2)
painter->fillRect(QRect(rangeStart, posY1, rangeEnd - rangeStart + eventWidth + 1, h), cachedBg);
}
}
painter->restore();
for (auto i = lineMap.constBegin(); i != lineMap.constEnd(); ++i)
{
int posX = i.key();
painter->setPen(QPen(QBrush(QGuiApplication::palette().shadow()), 1.0));
if (posX > option.rect.x() && posX < (option.rect.x() + option.rect.width()))
painter->drawLine(posX, posY1, posX, posY2);
}
painter->restore();
for (auto i = lineMap.constBegin(); i != lineMap.constEnd(); ++i)
{
int posX = i.key();
painter->setPen(QPen(QBrush(QGuiApplication::palette().shadow()), 1.0));
if (posX > option.rect.x() &&
posX < (option.rect.x() + option.rect.width()))
painter->drawLine(posX, posY1, posX, posY2);
}
EventTools::drawEvents(painter, m_eventGraphicList, option.rect.y());
EventTools::drawEvents(painter, m_eventGraphicList, option.rect.y());
}
}
} // namespace LtsTimelineClassic
@@ -1,6 +1,5 @@
#pragma once
#include "EventList.h"
@@ -9,45 +8,33 @@
#include <QObject>
class QPainter;
class QStyleOptionViewItem;
namespace LtsTimelineClassic
{
class PassiveEventContainer: public QObject
class PassiveEventContainer : public QObject
{
Q_OBJECT
Q_OBJECT
public:
public:
explicit PassiveEventContainer(bool ignoreKnownRanges, QObject* parent = nullptr);
explicit PassiveEventContainer(bool ignoreKnownRanges, QObject *parent = nullptr);
~PassiveEventContainer();
~PassiveEventContainer();
void paint(QPainter* painter, const QStyleOptionViewItem& option, const LineMap& lineMap,
const QVector<Range>& knownRanges) const;
EventGraphicList getEventGraphicList() const;
void paint(QPainter *painter, const QStyleOptionViewItem &option, const LineMap &lineMap, const QVector<Range> &knownRanges) const;
EventGraphicList getEventGraphicList() const;
void setEventList(const EventGraphicList &eventGraphicList);
private:
EventGraphicList m_eventGraphicList;
bool m_ignoreKnownRanges;
void setEventList(const EventGraphicList& eventGraphicList);
private:
EventGraphicList m_eventGraphicList;
bool m_ignoreKnownRanges;
};
}
} // namespace LtsTimelineClassic
Q_DECLARE_METATYPE(LtsTimelineClassic::PassiveEventContainer *)
Q_DECLARE_METATYPE(LtsTimelineClassic::PassiveEventContainer*)
+6 -6
View File
@@ -1,6 +1,5 @@
#pragma once
#include <qglobal.h>
@@ -9,10 +8,11 @@ namespace LtsTimelineClassic
{
struct Range
{
qint64 start = 0;
qint64 end = 0;
Range() = default;
Range(qint64 s, qint64 e) : start(s), end(e) {}
qint64 start = 0;
qint64 end = 0;
Range() = default;
Range(qint64 s, qint64 e) : start(s), end(e) {}
};
}
} // namespace LtsTimelineClassic
+16 -23
View File
@@ -1,40 +1,33 @@
#include "TestTimelineModel.h"
#include "EventGraphic.h"
#include <QToolTip>
#include <QDebug>
#include <QToolTip>
namespace LtsTimelineClassic
{
TestTimelineModel::TestTimelineModel()
: AbstractTimelineModel()
TestTimelineModel::TestTimelineModel() : AbstractTimelineModel() {}
void TestTimelineModel::addTestEvent(Event* event)
{
AbstractTimelineModel::addEvent(event);
}
void TestTimelineModel::addTestEvent(Event *event)
void TestTimelineModel::slotEventAction(EventGraphic* eg, int actionType)
{
AbstractTimelineModel::addEvent(event);
(void)actionType;
QString content = tr("Event count: %1").arg(QString::number(eg->eventList().count()));
for (int i = 0; i < eg->eventList().count(); i++)
{
content += QLatin1String("\r\nTime: ");
content += QString::number(eg->eventList().at(i)->startTime());
}
}
void TestTimelineModel::slotEventAction(EventGraphic *eg, int actionType)
{
(void)actionType;
QString content = tr("Event count: %1").arg(QString::number(eg->eventList().count()));
for (int i = 0; i < eg->eventList().count(); i++)
{
content += QLatin1String("\r\nTime: ");
content += QString::number(eg->eventList().at(i)->startTime());
}
}
}
} // namespace LtsTimelineClassic
+8 -11
View File
@@ -1,26 +1,23 @@
#pragma once
#include <QObject>
#include "AbstractTimelineModel.h"
#include <QObject>
namespace LtsTimelineClassic
{
class LTSTIMELINECLASSIC_EXPORT TestTimelineModel : public AbstractTimelineModel
{
Q_OBJECT
Q_OBJECT
public:
TestTimelineModel();
void addTestEvent(Event *event);
public:
TestTimelineModel();
void addTestEvent(Event* event);
private slots:
void slotEventAction(EventGraphic *, int);
private slots:
void slotEventAction(EventGraphic*, int);
};
}
} // namespace LtsTimelineClassic
+90 -101
View File
@@ -1,149 +1,138 @@
#include "TimelineWidget.h"
#include "TimelineHeaderView.h"
#include "TimelineWidget.h"
#include <QGuiApplication>
#include <QPainter>
#include <QPainterPath>
#include <QPen>
#include <QPoint>
#include <QRect>
#include <QGuiApplication>
namespace LtsTimelineClassic
{
TimelineHeaderView::TimelineHeaderView(QWidget *parent)
: QHeaderView(Qt::Horizontal, parent)
, m_posMarkTime(0)
, m_paintingRange(rect())
, m_liveTime(0)
TimelineHeaderView::TimelineHeaderView(QWidget* parent)
: QHeaderView(Qt::Horizontal, parent), m_posMarkTime(0), m_paintingRange(rect()), m_liveTime(0)
{
setSectionsClickable(true);
setSectionsClickable(true);
setStretchLastSection(true);
setStretchLastSection(true);
connect(this, &TimelineHeaderView::sectionResized,
this, &TimelineHeaderView::slotSectionResized);
connect(this, &TimelineHeaderView::sectionResized, this, &TimelineHeaderView::slotSectionResized);
}
#define GET_LOGGER NGL::NGLLoggerBootstrap::getNGLRootLogger().getNGLLogger("Timeline.HeaderView")
void TimelineHeaderView::setPosMarkTime(qint64 time)
{
m_posMarkTime = time;
refreshData();
m_posMarkTime = time;
refreshData();
}
void TimelineHeaderView::setLiveTime(qint64 time)
{
m_liveTime = time;
refreshData();
m_liveTime = time;
refreshData();
}
void TimelineHeaderView::setPosMarkPos()
{
if (m_posMarkTime > 0)
{
int posMarkPos = EventTools::getEventPosition(m_posMarkTime);
emit signalSetPosMarkPos(posMarkPos);
refreshData();
}
if (m_posMarkTime > 0)
{
int posMarkPos = EventTools::getEventPosition(m_posMarkTime);
emit signalSetPosMarkPos(posMarkPos);
refreshData();
}
}
void TimelineHeaderView::refreshData()
{
if (EventTools::getTimelineMin() > 0 && EventTools::getTimelineMax() > 1)
{
updateSection(1);
updateSection(0);
}
if (EventTools::getTimelineMin() > 0 && EventTools::getTimelineMax() > 1)
{
updateSection(1);
updateSection(0);
}
}
void TimelineHeaderView::slotSectionResized(int logicalIndex, int oldSize, int newSize)
{
(void)oldSize;
(void)oldSize;
if (logicalIndex == 1)
m_paintingRange = QRect(0, 0, newSize, height());
if (logicalIndex == 1)
m_paintingRange = QRect(0, 0, newSize, height());
refreshData();
refreshData();
}
void TimelineHeaderView::paintSection(QPainter *painter, const QRect &rect, int logicalIndex) const
void TimelineHeaderView::paintSection(QPainter* painter, const QRect& rect, int logicalIndex) const
{
painter->save();
QHeaderView::paintSection(painter, rect, logicalIndex);
painter->restore();
if (logicalIndex == 1)
{
int h = (rect.height() / 3);
int y = rect.height() - h;
int w = h;
painter->save();
painter->setClipping(true);
if (m_posMarkTime != 0)
{
double posMark = EventTools::getEventPosition(m_posMarkTime);
int x = + posMark;
if (x >= sectionPosition(1))
{
painter->setPen(QPen(QGuiApplication::palette().color(QPalette::Inactive, QPalette::Highlight)));
painter->setBrush(QGuiApplication::palette().highlight());
QPolygon pol;
pol.append(QPoint(x + (-w / 2), y + 0));
pol.append(QPoint(x + 0, y + h));
pol.append(QPoint(x + (w / 2), y + 0));
pol.append(QPoint(x + (-w / 2), y + 0));
QPainterPath path;
path.moveTo(x, y);
path.addPolygon(pol);
painter->drawPath(path);
}
}
if (m_liveTime != 0)
{
int posLive = EventTools::getEventPosition(m_liveTime);
int x = posLive;
if (x >= sectionPosition(1))
{
painter->setPen(QPen(QColor("green")));
painter->setBrush(QBrush(QColor("green")));
QPolygon pol;
pol.append(QPoint(x + (-w / 2), y + 0));
pol.append(QPoint(x + 0, y + h));
pol.append(QPoint(x + (w / 2), y + 0));
pol.append(QPoint(x + (-w / 2), y + 0));
QPainterPath path;
path.moveTo(x, y);
path.addPolygon(pol);
painter->drawPath(path);
}
}
QHeaderView::paintSection(painter, rect, logicalIndex);
painter->restore();
}
if (logicalIndex == 1)
{
int h = (rect.height() / 3);
int y = rect.height() - h;
int w = h;
painter->save();
painter->setClipping(true);
if (m_posMarkTime != 0)
{
double posMark = EventTools::getEventPosition(m_posMarkTime);
int x = +posMark;
if (x >= sectionPosition(1))
{
painter->setPen(QPen(QGuiApplication::palette().color(QPalette::Inactive, QPalette::Highlight)));
painter->setBrush(QGuiApplication::palette().highlight());
QPolygon pol;
pol.append(QPoint(x + (-w / 2), y + 0));
pol.append(QPoint(x + 0, y + h));
pol.append(QPoint(x + (w / 2), y + 0));
pol.append(QPoint(x + (-w / 2), y + 0));
QPainterPath path;
path.moveTo(x, y);
path.addPolygon(pol);
painter->drawPath(path);
}
}
if (m_liveTime != 0)
{
int posLive = EventTools::getEventPosition(m_liveTime);
int x = posLive;
if (x >= sectionPosition(1))
{
painter->setPen(QPen(QColor("green")));
painter->setBrush(QBrush(QColor("green")));
QPolygon pol;
pol.append(QPoint(x + (-w / 2), y + 0));
pol.append(QPoint(x + 0, y + h));
pol.append(QPoint(x + (w / 2), y + 0));
pol.append(QPoint(x + (-w / 2), y + 0));
QPainterPath path;
path.moveTo(x, y);
path.addPolygon(pol);
painter->drawPath(path);
}
}
painter->restore();
}
}
}
} // namespace LtsTimelineClassic
+20 -37
View File
@@ -1,64 +1,47 @@
#pragma once
#include <QObject>
#include "EventTools.h"
#include <QHeaderView>
#include <QObject>
class QPainter;
namespace LtsTimelineClassic
{
class TimelineHeaderView : public QHeaderView
{
Q_OBJECT
Q_OBJECT
public:
explicit TimelineHeaderView(QWidget *parent = nullptr);
public:
explicit TimelineHeaderView(QWidget* parent = nullptr);
void refreshData();
void setLiveTime(qint64 time);
void refreshData();
void setLiveTime(qint64 time);
private:
qint64 m_posMarkTime;
QRect m_paintingRange;
private:
qint64 m_posMarkTime;
QRect m_paintingRange;
qint64 m_liveTime;
qint64 m_liveTime;
protected:
protected:
void paintSection(QPainter* painter, const QRect& rect, int logicalIndex) const;
void paintSection(QPainter *painter, const QRect &rect, int logicalIndex) const;
signals:
signals:
void signalSetPosMarkPos(int pos);
void signalSetPosMarkPos(int pos);
public slots:
public slots:
void slotSectionResized(int logicalIndex, int oldSize, int newSize);
void setPosMarkTime(qint64 time);
void slotSectionResized(int logicalIndex, int oldSize, int newSize);
void setPosMarkTime(qint64 time);
private:
void setPosMarkPos();
private:
void setPosMarkPos();
};
}
} // namespace LtsTimelineClassic
+279 -344
View File
@@ -1,39 +1,34 @@
#include "TimelineWidget.h"
#include "TimelineIndicator.h"
#include "EventTools.h"
#include "TimelineWidget.h"
#include <NGLLogger/NGLLoggerBootstrap.h>
#include <ngltools/ngltools_dtg.h>
#include <QGuiApplication>
#include <QHeaderView>
#include <QApplication>
#include <QComboBox>
#include <QDateTime>
#include <QDebug>
#include <QFont>
#include <QFontMetrics>
#include <QGuiApplication>
#include <QHBoxLayout>
#include <QHeaderView>
#include <QLabel>
#include <QPainter>
#include <QPalette>
#include <QPushButton>
#include <QApplication>
#include <QHBoxLayout>
#include <QDateTime>
#include <QPoint>
#include <QLabel>
#include <QComboBox>
#include <QDebug>
#include <QPushButton>
#include <ngltools/ngltools_dtg.h>
#ifdef LTS_DEBUG
#endif
#ifdef VERBOSE
#define dbg_print(x) qWarning() << #x << x
#define dbg_print(x) qWarning() << #x << x
#else
#define dbg_print(x) (void)x;
#define dbg_print(x) (void)x;
#endif
namespace LtsTimelineClassic
@@ -49,470 +44,410 @@ TimelineIndicator::TimelineIndicator(QWidget *parent) : QWidget(parent)
, m_sectionPos(0)
, m_sectionSize(0)
.getNGLLogger("Timeline.Indicator")),
m_logger(NGL::NGLLoggerBootstrap::getLogger()) {
m_timeArray.reserve(11 + 11 + 7 + 10);
m_logger(NGL::NGLLoggerBootstrap::getLogger())
{
m_timeArray.reserve(11 + 11 + 7 + 10);
m_timeArray <<
1 << 2 << 3 << 4 << 5 << 6 << 12 << 15 << 20 << 30 << 60 <<
m_timeArray <<
1 * 60 << 2 * 60 << 3 * 60 << 4 * 60 << 5 * 60 << 6 * 60 << 12 * 60 << 15 * 60 << 20 * 60 << 30 * 60 << 60 * 60 <<
1 << 2 << 3 << 4 << 5 << 6 << 12 << 15 << 20 << 30 << 60 <<
1 * 60 * 60 << 2 * 60 * 60 << 4 * 60 * 60 << 6 * 60 * 60 << 8 * 60 * 60 << 12 * 60 * 60 << 24 * 60 * 60 <<
1 * 60 << 2 * 60 << 3 * 60 << 4 * 60 << 5 * 60 << 6 * 60 << 12 * 60 << 15 * 60 << 20 * 60 << 30 * 60 << 60 * 60
<<
1 * 60 * 60 << 2 * 60 * 60 << 4 * 60 * 60 << 6 * 60 * 60 << 8 * 60 * 60 << 10 * 60 * 60 << 14 * 60 * 60 << 18 * 60 * 60 << 22 * 60 * 60 << 26 * 60 * 60 << 30 * 60 * 60;
1 * 60 * 60 << 2 * 60 * 60 << 4 * 60 * 60 << 6 * 60 * 60 << 8 * 60 * 60 << 12 * 60 * 60 << 24 * 60 * 60 <<
QHBoxLayout *centralLayout = new QHBoxLayout();
centralLayout->setSpacing(0);
1 * 60 * 60 << 2 * 60 * 60 << 4 * 60 * 60 << 6 * 60 * 60 << 8 * 60 * 60 << 10 * 60 * 60 << 14 * 60 * 60
<< 18 * 60 * 60 << 22 * 60 * 60 << 26 * 60 * 60 << 30 * 60 * 60;
setLayout(centralLayout);
QHBoxLayout* centralLayout = new QHBoxLayout();
centralLayout->setSpacing(0);
m_pbZoom->setText(QLatin1String("+"));
m_pbZoom->setFixedSize(s_pbSize, s_pbSize);
setLayout(centralLayout);
m_pbUnzoom->setText(QLatin1String("-"));
m_pbUnzoom->setFixedSize(s_pbSize, s_pbSize);
m_pbZoom->setText(QLatin1String("+"));
m_pbZoom->setFixedSize(s_pbSize, s_pbSize);
m_cbZoomLevel->addItem(tr("10 min"), 600);
m_cbZoomLevel->addItem(tr("30 min"), 1800);
m_cbZoomLevel->addItem(tr("1 h"), 3600);
m_cbZoomLevel->addItem(tr("2 h"), 7200);
m_cbZoomLevel->addItem(tr("4 h"), 14400);
m_cbZoomLevel->addItem(tr("8 h"), 28800);
m_pbUnzoom->setText(QLatin1String("-"));
m_pbUnzoom->setFixedSize(s_pbSize, s_pbSize);
m_cbZoomLevel->setCurrentIndex(0);
m_cbZoomLevel->setFixedHeight(s_pbSize);
m_zoomFactorPoints = m_cbZoomLevel->currentData().toLongLong();
m_cbZoomLevel->addItem(tr("10 min"), 600);
m_cbZoomLevel->addItem(tr("30 min"), 1800);
m_cbZoomLevel->addItem(tr("1 h"), 3600);
m_cbZoomLevel->addItem(tr("2 h"), 7200);
m_cbZoomLevel->addItem(tr("4 h"), 14400);
m_cbZoomLevel->addItem(tr("8 h"), 28800);
connect(m_cbZoomLevel, &QComboBox::currentTextChanged,
this, &TimelineIndicator::afterZoom);
connect(m_pbZoom, &QPushButton::clicked,
this, &TimelineIndicator::slotZoom);
connect(m_pbUnzoom, &QPushButton::clicked,
this, &TimelineIndicator::slotUnzoom);
connect(this, &TimelineIndicator::signalAddLine,
this, &TimelineIndicator::slotAddLine);
connect(this, &TimelineIndicator::signalResetLineList,
this, &TimelineIndicator::slotResetLineList);
m_cbZoomLevel->setCurrentIndex(0);
centralLayout->addWidget(m_pbZoom, 0, Qt::AlignLeft | Qt::AlignTop);
centralLayout->addWidget(m_pbUnzoom, 0, Qt::AlignLeft | Qt::AlignTop);
centralLayout->addWidget(m_cbZoomLevel, 1, Qt::AlignLeft | Qt::AlignTop);
m_cbZoomLevel->setFixedHeight(s_pbSize);
m_zoomFactorPoints = m_cbZoomLevel->currentData().toLongLong();
connect(m_cbZoomLevel, &QComboBox::currentTextChanged, this, &TimelineIndicator::afterZoom);
connect(m_pbZoom, &QPushButton::clicked, this, &TimelineIndicator::slotZoom);
connect(m_pbUnzoom, &QPushButton::clicked, this, &TimelineIndicator::slotUnzoom);
connect(this, &TimelineIndicator::signalAddLine, this, &TimelineIndicator::slotAddLine);
connect(this, &TimelineIndicator::signalResetLineList, this, &TimelineIndicator::slotResetLineList);
centralLayout->addWidget(m_pbZoom, 0, Qt::AlignLeft | Qt::AlignTop);
centralLayout->addWidget(m_pbUnzoom, 0, Qt::AlignLeft | Qt::AlignTop);
centralLayout->addWidget(m_cbZoomLevel, 1, Qt::AlignLeft | Qt::AlignTop);
QFontMetrics fm(QApplication::font());
m_currentTextHeight = fm.height();
QFontMetrics fm(QApplication::font());
m_currentTextHeight = fm.height();
#if QT_VERSION < QT_VERSION_CHECK(5, 11, 0)
m_currentTextWidth = fm.width(DTG::toString(QDateTime::currentDateTimeUtc(), DTG::Short));
m_currentTextWidth = fm.width(DTG::toString(QDateTime::currentDateTimeUtc(), DTG::Short));
#else
m_currentTextWidth = fm.horizontalAdvance(DTG::toString(QDateTime::currentDateTimeUtc(), DTG::Short));
m_currentTextWidth = fm.horizontalAdvance(DTG::toString(QDateTime::currentDateTimeUtc(), DTG::Short));
#endif
dbg_print(m_currentTextWidth);
dbg_print(m_currentTextWidth);
}
TimelineIndicator::~TimelineIndicator()
TimelineIndicator::~TimelineIndicator() {}
void TimelineIndicator::afterZoom()
{
m_zoomFactorPoints = m_cbZoomLevel->currentData().toLongLong() * 1000;
emit signalSetZoomFactor(m_zoomFactorPoints);
update();
}
void TimelineIndicator::afterZoom()
{
m_zoomFactorPoints = m_cbZoomLevel->currentData().toLongLong() * 1000;
emit signalSetZoomFactor(m_zoomFactorPoints);
update();
}
void TimelineIndicator::slotZoom()
{
int pos = m_cbZoomLevel->currentIndex();
int pos = m_cbZoomLevel->currentIndex();
if (pos == 0)
return;
if (pos == 0)
return;
m_cbZoomLevel->setCurrentIndex(pos - 1);
emit signalZoomChanged();
m_cbZoomLevel->setCurrentIndex(pos - 1);
emit signalZoomChanged();
}
void TimelineIndicator::slotUnzoom()
{
int count = m_cbZoomLevel->count();
int pos = m_cbZoomLevel->currentIndex();
int count = m_cbZoomLevel->count();
int pos = m_cbZoomLevel->currentIndex();
if (pos >= count - 1)
return;
if (pos >= count - 1)
return;
m_cbZoomLevel->setCurrentIndex(pos + 1);
emit signalZoomChanged();
m_cbZoomLevel->setCurrentIndex(pos + 1);
emit signalZoomChanged();
}
enum highestUnit
{
HU_INVALID,
HU_DAYS,
HU_HOURS,
HU_MINUTES,
HU_SECONDS
enum highestUnit {
HU_INVALID,
HU_DAYS,
HU_HOURS,
HU_MINUTES,
HU_SECONDS
};
void TimelineIndicator::refreshData()
{
#ifdef VERBOSE
qWarning() << "<refreshData>";
qWarning() << "<refreshData>";
#endif
emit signalResetLineList();
emit signalResetLineList();
#ifdef VERBOSE
qWarning() << "section x" << m_sectionPos << "length" << m_sectionSize;
qWarning() << "section x" << m_sectionPos << "length" << m_sectionSize;
#endif
double abstand = m_sectionPos + m_currentTextWidth + s_TimeTextDistanceTolerancePixels;
dbg_print(abstand);
qint64 eventTimeOfAbstand = EventTools::getEventTime(abstand);
dbg_print(eventTimeOfAbstand);
qint64 adjustedMin = EventTools::getAdjustedMin();
dbg_print(adjustedMin);
qint64 textWidthTime = (eventTimeOfAbstand - adjustedMin);
if (textWidthTime < 0)
{
qWarning() << "TimelineIndicator: paintEvent: textWidthTime invalid! (" << textWidthTime << ")";
return;
}
double abstand = m_sectionPos + m_currentTextWidth + s_TimeTextDistanceTolerancePixels;
dbg_print(abstand);
qint64 eventTime = EventTools::getEventTime(abstand);
dbg_print(eventTime);
QDateTime textWidthDt = QDateTime::fromMSecsSinceEpoch(textWidthTime);
qint64 eventTimeOfAbstand = EventTools::getEventTime(abstand);
dbg_print(eventTimeOfAbstand);
qint64 adjustedMin = EventTools::getAdjustedMin();
dbg_print(adjustedMin);
qint64 textWidthTime = (eventTimeOfAbstand - adjustedMin);
int days = textWidthDt.date().day() - 1;
int hours = textWidthDt.time().hour() - 1;
int minutes = textWidthDt.time().minute();
int seconds = textWidthDt.time().second() - 1;
if (textWidthTime < 0)
{
qWarning() << "TimelineIndicator: paintEvent: textWidthTime invalid! (" << textWidthTime << ")";
return;
}
highestUnit unit = HU_INVALID;
qint64 eventTime = EventTools::getEventTime(abstand);
dbg_print(eventTime);
if (days == 0)
if (hours == 0)
if (minutes == 0)
if (seconds == 0)
{
#ifdef VERBOSE
qWarning() << "refreshData: no lower time unit available";
#endif
return;
}
else
{
QDateTime textWidthDt = QDateTime::fromMSecsSinceEpoch(textWidthTime);
unit = HU_SECONDS;
}
else
{
int days = textWidthDt.date().day() - 1;
int hours = textWidthDt.time().hour() - 1;
int minutes = textWidthDt.time().minute();
int seconds = textWidthDt.time().second() - 1;
highestUnit unit = HU_INVALID;
if (days == 0)
if (hours == 0)
if (minutes == 0)
if (seconds == 0)
unit = HU_MINUTES;
}
else
{
#ifdef VERBOSE
qWarning() << "refreshData: no lower time unit available" ;
#endif
return;
unit = HU_HOURS;
}
else
{
unit = HU_DAYS;
}
if (unit == HU_INVALID)
{
#ifdef VERBOSE
qWarning() << "unit == HU_INVALID";
#endif
return;
}
int higherValue = 0;
for (int i = 0; i < m_timeArray.size(); i++)
{
qint64 time = (m_timeArray[i] * 1000);
if (time >= textWidthTime)
{
higherValue = time;
break;
}
else
{
unit = HU_SECONDS;
continue;
}
else
{
unit = HU_MINUTES;
}
else
{
unit = HU_HOURS;
}
else
{
unit = HU_DAYS;
}
if (unit == HU_INVALID)
{
#ifdef VERBOSE
qWarning() << "unit == HU_INVALID";
qWarning() << "refreshData: no fitting highest unit found !";
#endif
return;
}
int higherValue = 0;
for (int i = 0; i < m_timeArray.size(); i++)
{
qint64 time = (m_timeArray[i] * 1000);
if (time >= textWidthTime)
{
higherValue = time;
break;
}
else
{
continue;
return;
}
#ifdef VERBOSE
qWarning() << "refreshData: no fitting highest unit found !" ;
#endif
return;
}
if (higherValue < 1)
{
return;
}
QDateTime minDt = QDateTime::fromMSecsSinceEpoch(adjustedMin);
dbg_print(minDt);
dbg_print(unit);
switch (unit)
{
case HU_SECONDS:
if (higherValue < 1)
{
minDt = minDt.addSecs(-(minDt.time().second()));
return;
}
QDateTime minDt = QDateTime::fromMSecsSinceEpoch(adjustedMin);
dbg_print(minDt);
dbg_print(unit);
switch (unit)
{
case HU_SECONDS: {
minDt = minDt.addSecs(-(minDt.time().second()));
#ifdef VERBOSE
qCritical() << "HU_SECONDS";
qCritical() << "HU_SECONDS";
#endif
break;
}
break;
}
case HU_MINUTES:
{
minDt = minDt.addSecs(-(minDt.time().second()));
minDt = minDt.addSecs(-(minDt.time().minute() * 60));
case HU_MINUTES: {
minDt = minDt.addSecs(-(minDt.time().second()));
minDt = minDt.addSecs(-(minDt.time().minute() * 60));
#ifdef VERBOSE
qCritical() << "HU_MINUTES";
qCritical() << "HU_MINUTES";
#endif
break;
}
break;
}
case HU_HOURS:
{
minDt = minDt.addSecs(-(minDt.time().second()));
minDt = minDt.addSecs(-(minDt.time().minute() * 60));
minDt = minDt.addSecs(-(minDt.time().hour() * 60 * 60));
case HU_HOURS: {
minDt = minDt.addSecs(-(minDt.time().second()));
minDt = minDt.addSecs(-(minDt.time().minute() * 60));
minDt = minDt.addSecs(-(minDt.time().hour() * 60 * 60));
#ifdef VERBOSE
qCritical() << "HU_HOURS";
qCritical() << "HU_HOURS";
#endif
break;
}
break;
}
case HU_DAYS:
{
minDt = minDt.addSecs(-(minDt.time().second()));
minDt = minDt.addSecs(-(minDt.time().minute() * 60));
minDt = minDt.addSecs(-(minDt.time().hour() * 60 * 60));
minDt = minDt.addDays(-(minDt.date().day()));
case HU_DAYS: {
minDt = minDt.addSecs(-(minDt.time().second()));
minDt = minDt.addSecs(-(minDt.time().minute() * 60));
minDt = minDt.addSecs(-(minDt.time().hour() * 60 * 60));
minDt = minDt.addDays(-(minDt.date().day()));
#ifdef VERBOSE
qCritical() << "HU_DAYS";
qCritical() << "HU_DAYS";
#endif
break;
}
break;
}
default:
{
default: {
#ifdef VERBOSE
qWarning() << "unit / scaling is off da charz !";
qWarning() << "unit / scaling is off da charz !";
#endif
return;
return;
}
}
}
dbg_print(minDt);
dbg_print(minDt);
minDt = minDt.addMSecs(-higherValue);
minDt = minDt.addMSecs(-higherValue);
dbg_print(minDt);
dbg_print(minDt);
qint64 maxTimelineView = EventTools::getAdjustedMax() + (higherValue );
qint64 additional = textWidthTime / 2;
maxTimelineView += additional;
qint64 maxTimelineView = EventTools::getAdjustedMax() + (higherValue);
qint64 additional = textWidthTime / 2;
maxTimelineView += additional;
qint64 minTimeline = minDt.toMSecsSinceEpoch();
qint64 minTimeline = minDt.toMSecsSinceEpoch();
dbg_print(minTimeline);
dbg_print(maxTimelineView);
dbg_print(higherValue);
dbg_print(minTimeline);
dbg_print(maxTimelineView);
dbg_print(higherValue);
qint64 steps = (maxTimelineView - minTimeline) / higherValue;
if (steps < 0)
steps = steps * (-1);
qint64 steps = (maxTimelineView - minTimeline) / higherValue;
if (steps < 0)
steps = steps * (-1);
if (steps > 60000 || steps < 1)
{
ERROR_LOG(m_logger) << "More than 60000 ("<<steps<<") or less than 1 lines to draw. Loop will exit after 60000 lines.";
}
if (steps < 1)
steps = 2;
uint16_t currentStep = 0;
dbg_print(steps);
for (qint64 indicatorTime = minTimeline;
indicatorTime < maxTimelineView + 1 ;
indicatorTime += higherValue)
{
if (currentStep > 60000)
break;
currentStep++;
int pos = EventTools::getEventPosition(indicatorTime);
dbg_print(indicatorTime);
if (pos + (m_currentTextWidth / 4) + 1 < m_sectionPos)
if (steps > 60000 || steps < 1)
{
#ifdef VERBOSE
qCritical() << "Indicator: pos" << pos << "invisible #1";
#endif
continue;
ERROR_LOG(m_logger) << "More than 60000 (" << steps
<< ") or less than 1 lines to draw. Loop will exit after 60000 lines.";
}
else
if (pos - (m_currentTextWidth ) > (m_sectionPos + m_sectionSize))
if (steps < 1)
steps = 2;
uint16_t currentStep = 0;
dbg_print(steps);
for (qint64 indicatorTime = minTimeline; indicatorTime < maxTimelineView + 1; indicatorTime += higherValue)
{
if (currentStep > 60000)
break;
currentStep++;
int pos = EventTools::getEventPosition(indicatorTime);
dbg_print(indicatorTime);
if (pos + (m_currentTextWidth / 4) + 1 < m_sectionPos)
{
#ifdef VERBOSE
qCritical() << "Indicator: pos" << pos << "invisible #2";
qCritical() << "Indicator: pos" << pos << "invisible #1";
#endif
continue;
}
else
{
continue;
}
else if (pos - (m_currentTextWidth) > (m_sectionPos + m_sectionSize))
{
#ifdef VERBOSE
qCritical() << "Indicator: OKAY!! pos" << pos << "visible";
qCritical() << "Indicator: pos" << pos << "invisible #2";
#endif
continue;
}
else
{
#ifdef VERBOSE
qCritical() << "Indicator: OKAY!! pos" << pos << "visible";
#endif
}
emit signalAddLine(pos, indicatorTime);
}
dbg_print(currentStep);
emit signalAddLine(pos, indicatorTime);
}
QFontMetrics fm(QApplication::font());
m_currentTextHeight = fm.height();
dbg_print(currentStep);
QFontMetrics fm(QApplication::font());
m_currentTextHeight = fm.height();
update();
update();
}
void TimelineIndicator::paintEvent(QPaintEvent *)
void TimelineIndicator::paintEvent(QPaintEvent*)
{
QPainter painter(this);
painter.save();
painter.setClipping(true);
painter.setClipRect(QRect(x() - 8 + m_sectionPos, 0, m_sectionSize, height()));
QPainter painter(this);
painter.save();
painter.setClipping(true);
painter.setClipRect(QRect(x() - 8 + m_sectionPos, 0, m_sectionSize, height()));
#ifdef VERBOSE
int textY = (height() - m_currentTextHeight - 5);
int textY = (height() - m_currentTextHeight - 5);
#endif
int h = height();
int h = height();
for (auto i = m_lineMap.constBegin(); i != m_lineMap.constEnd(); ++i)
{
for (auto i = m_lineMap.constBegin(); i != m_lineMap.constEnd(); ++i)
{
int pos = i.key();
int pos = i.key();
painter.setPen(QPen(QColor("black"), 1.0));
painter.drawLine(pos, m_currentTextHeight, pos, h);
painter.setPen(QPen(QColor("black"), 1.0));
painter.drawLine(pos, m_currentTextHeight, pos, h);
int centeredPos = pos - (m_currentTextWidth / 2);
qint64 time = (*i);
int centeredPos = pos - (m_currentTextWidth / 2);
qint64 time = (*i);
painter.drawText(centeredPos, (m_currentTextHeight / 2) + 4,
DTG::toStringMSec(time, DTG::Short));
painter.drawText(centeredPos, (m_currentTextHeight / 2) + 4, DTG::toStringMSec(time, DTG::Short));
#ifdef VERBOSE
WARNING_LOG(m_logger) << "paintEvent: actual drawing position: x=" << centeredPos << " y=" << textY;
WARNING_LOG(m_logger) << "paintEvent: actual drawing position: x=" << centeredPos << " y=" << textY;
#endif
}
}
painter.restore();
painter.restore();
}
void TimelineIndicator::slotSectionResized(int logicalIndex, int oldSize, int newSize)
{
(void)oldSize;
(void)oldSize;
QHeaderView *header = qobject_cast<QHeaderView *>(QObject::sender());
QHeaderView* header = qobject_cast<QHeaderView*>(QObject::sender());
if (!header)
return;
if (!header)
return;
if (logicalIndex == 1)
{
m_sectionPos = header->sectionPosition(1);
m_sectionSize = newSize;
}
if (logicalIndex == 1)
{
m_sectionPos = header->sectionPosition(1);
m_sectionSize = newSize;
}
update();
update();
}
void TimelineIndicator::slotAddLine(double posX, qint64 time)
void TimelineIndicator::slotAddLine(double posX, qint64 time)
{
#ifdef VERBOSE
qCritical() << "slotAddLine: posX" << posX << "time" << time;
qCritical() << "slotAddLine: posX" << posX << "time" << time;
#endif
m_lineMap.insert(posX, time);
m_lineMap.insert(posX, time);
}
void TimelineIndicator::slotResetLineList()
{
m_lineMap.clear();
m_lineMap.clear();
}
}
} // namespace LtsTimelineClassic
+44 -69
View File
@@ -1,15 +1,13 @@
#pragma once
#include <QObject>
#include "EventTools.h"
#include "LineMap.h"
#include <QWidget>
#include <QPoint>
#include <QPair>
#include <QObject>
#include <QPair>
#include <QPoint>
#include <QWidget>
namespace NGL
{
@@ -20,92 +18,69 @@ class QPushButton;
class QLabel;
class QComboBox;
namespace LtsTimelineClassic
{
class TimelineIndicator : public QWidget
{
Q_OBJECT
Q_OBJECT
static const int s_TimeTextDistanceTolerancePixels = 10;
static const int s_pbSize = 18;
static const int s_TimeTextDistanceTolerancePixels = 10;
static const int s_pbSize = 18;
public:
explicit TimelineIndicator(QWidget *parent);
~TimelineIndicator();
qint64 zoomFactorPoints() const { return m_zoomFactorPoints * 1000; }
public:
explicit TimelineIndicator(QWidget* parent);
~TimelineIndicator();
qint64 zoomFactorPoints() const
{
return m_zoomFactorPoints * 1000;
}
void refreshData();
void refreshData();
private:
QVector<qint64> m_timeArray;
qint64 m_zoomFactorPoints;
QPushButton *m_pbZoom;
QPushButton *m_pbUnzoom;
QComboBox *m_cbZoomLevel;
int m_currentTextHeight;
int m_currentTextWidth;
LineMap m_lineMap;
int m_sectionPos;
int m_sectionSize;
protected:
private:
QVector<qint64> m_timeArray;
qint64 m_zoomFactorPoints;
QPushButton* m_pbZoom;
QPushButton* m_pbUnzoom;
QComboBox* m_cbZoomLevel;
int m_currentTextHeight;
int m_currentTextWidth;
LineMap m_lineMap;
int m_sectionPos;
int m_sectionSize;
NGL::INGLLogger &m_logger;
void paintEvent(QPaintEvent *);
protected:
NGL::INGLLogger& m_logger;
void paintEvent(QPaintEvent*);
signals:
signals:
void signalSetTimelineRange(qint64 min, qint64 max);
void signalSetTimelineRange(qint64 min, qint64 max);
void signalSetZoomFactor(qint64 zoomFactor);
void signalSetZoomFactor(qint64 zoomFactor);
void signalResetLineList();
void signalAddLine(int posX, qint64 time);
void signalResetLineList();
void signalZoomChanged();
private slots:
void afterZoom();
void signalAddLine(int posX, qint64 time);
public slots:
void signalZoomChanged();
void slotSectionResized(int logicalIndex, int oldSize, int newSize);
void slotZoom();
private slots:
void afterZoom();
void slotUnzoom();
void slotResetLineList();
public slots:
void slotSectionResized(int logicalIndex, int oldSize, int newSize);
void slotZoom();
void slotUnzoom();
void slotResetLineList();
void slotAddLine(double posX, qint64 time);
void slotAddLine(double posX, qint64 time);
};
}
} // namespace LtsTimelineClassic
+244 -316
View File
@@ -1,393 +1,321 @@
#include "TimelineView.h"
#include <utility>
#include "TimelineHeaderView.h"
#include "TimelineWidget.h"
#include "EventDelegate.h"
#include "EventGraphic.h"
#include "TimelineHeaderView.h"
#include "TimelineWidget.h"
#include <QPainter>
#include <QPen>
#include <QBrush>
#include <QDebug>
#include <QGuiApplication>
#include <QHeaderView>
#include <QHelpEvent>
#include <QModelIndex>
#include <QPainter>
#include <QPen>
#include <QRect>
#include <QDebug>
#include <utility>
namespace LtsTimelineClassic
{
TimelineView::TimelineView(QWidget* parent)
: QTreeView(parent)
TimelineView::TimelineView(QWidget *parent)
: QTreeView(parent)
, m_model(nullptr)
, m_drawCache(false)
,
m_model(nullptr), m_drawCache(false)
{
m_posMarkTime = 0;
m_posMarkTime = 0;
setAlternatingRowColors(true);
setEditTriggers(QAbstractItemView::NoEditTriggers);
setSelectionBehavior(QAbstractItemView::SelectItems);
setSelectionMode(QAbstractItemView::NoSelection);
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
setAlternatingRowColors(true);
setEditTriggers(QAbstractItemView::NoEditTriggers);
setSelectionBehavior(QAbstractItemView::SelectItems);
setSelectionMode(QAbstractItemView::NoSelection);
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
}
void TimelineView::setHeader(QHeaderView *header)
void TimelineView::setHeader(QHeaderView* header)
{
if (header)
{
QTreeView::setHeader(header);
header->setMinimumSectionSize(150);
}
else
{
}
}
AbstractTimelineModel *TimelineView::timelineModel()
{
return m_model;
}
void TimelineView::setTimelineModel(AbstractTimelineModel *model)
{
m_model = model;
setMouseTracking(true);
setModel(m_model);
EventDelegate *ed = new EventDelegate(this);
EventTools::setSectionHeight(ed->sizeHint().height());
setItemDelegate(ed);
}
EventGraphic *TimelineView::getEventOnPosition(QPoint position)
{
position = viewport()->mapFromGlobal(position);
QModelIndex index = indexAt(position);
if (index.isValid() && position.x() > header()->sectionSize(0))
{
Item *item = static_cast<Item *>(index.internalPointer());
if (!item)
return nullptr;
qint64 curTime = EventTools::getEventTime(position.x());
EventGraphicList egl = item->getCurrentEGLFromPevcon();
qint64 blockSizeTime = EventTools::getBlockSizeTime();
for (int i = 0; i < egl.count(); i++)
if (header)
{
QTreeView::setHeader(header);
header->setMinimumSectionSize(150);
}
else
{
EventGraphic *eg = egl.at(i);
if (!eg)
continue;
qint64 eventStartTime = eg->lowestTime();
if (eventStartTime == 0)
continue;
qint64 eventEndTime = eventStartTime;
qint64 eglDuration = eg->getDuration();
if (eglDuration > blockSizeTime)
eventEndTime += eglDuration;
else
eventEndTime += blockSizeTime;
if (curTime >= eventStartTime && curTime <= eventEndTime)
return eg;
}
}
return nullptr;
}
bool TimelineView::event(QEvent *event)
AbstractTimelineModel* TimelineView::timelineModel()
{
switch (event->type())
{
case QEvent::ToolTip:
{
return m_model;
}
QHelpEvent *helpEvent = static_cast<QHelpEvent *>(event);
void TimelineView::setTimelineModel(AbstractTimelineModel* model)
{
m_model = model;
setMouseTracking(true);
setModel(m_model);
if (!helpEvent)
return true;
EventDelegate* ed = new EventDelegate(this);
EventGraphic *eg = getEventOnPosition(helpEvent->globalPos());
EventTools::setSectionHeight(ed->sizeHint().height());
setItemDelegate(ed);
}
EventGraphic* TimelineView::getEventOnPosition(QPoint position)
{
position = viewport()->mapFromGlobal(position);
QModelIndex index = indexAt(position);
if (index.isValid() && position.x() > header()->sectionSize(0))
{
Item* item = static_cast<Item*>(index.internalPointer());
if (!item)
return nullptr;
qint64 curTime = EventTools::getEventTime(position.x());
EventGraphicList egl = item->getCurrentEGLFromPevcon();
qint64 blockSizeTime = EventTools::getBlockSizeTime();
for (int i = 0; i < egl.count(); i++)
{
EventGraphic* eg = egl.at(i);
if (!eg)
continue;
qint64 eventStartTime = eg->lowestTime();
if (eventStartTime == 0)
continue;
qint64 eventEndTime = eventStartTime;
qint64 eglDuration = eg->getDuration();
if (eglDuration > blockSizeTime)
eventEndTime += eglDuration;
else
eventEndTime += blockSizeTime;
if (curTime >= eventStartTime && curTime <= eventEndTime)
return eg;
}
}
return nullptr;
}
bool TimelineView::event(QEvent* event)
{
switch (event->type())
{
case QEvent::ToolTip: {
QHelpEvent* helpEvent = static_cast<QHelpEvent*>(event);
if (!helpEvent)
return true;
EventGraphic* eg = getEventOnPosition(helpEvent->globalPos());
if (!eg)
return true;
emit signalEventAction(eg, EventGraphic::ACTION_TOOLTIP);
return true;
}
default: {
break;
}
}
return QTreeView::event(event);
}
void TimelineView::wheelEvent(QWheelEvent* event)
{
QTreeView::wheelEvent(event);
if (QGuiApplication::queryKeyboardModifiers() != Qt::ControlModifier)
return;
int scrolls = event->delta() / 120;
if (scrolls > 0)
{
for (int i = 0; i < scrolls; i++)
emit signalZoom();
}
if (scrolls < 0)
{
for (int i = 0; i > scrolls; i--)
emit signalUnzoom();
}
}
void TimelineView::mouseReleaseEvent(QMouseEvent* event)
{
QTreeView::mouseReleaseEvent(event);
QPoint position = event->globalPos();
EventGraphic* eg = getEventOnPosition(position);
if (!eg)
return true;
return;
emit signalEventAction(eg, EventGraphic::ACTION_TOOLTIP);
switch (event->button())
{
case Qt::LeftButton: {
emit signalEventAction(eg, EventGraphic::ACTION_LEFT_CLICKED);
break;
}
return true;
}
case Qt::RightButton: {
emit signalEventAction(eg, EventGraphic::ACTION_RIGHT_CLICKED);
break;
}
default:
{
break;
}
}
return QTreeView::event(event);
default: {
break;
}
}
}
void TimelineView::wheelEvent(QWheelEvent *event)
void TimelineView::slotAddLine(int posX, qint64 time)
{
QTreeView::wheelEvent(event);
if (QGuiApplication::queryKeyboardModifiers() != Qt::ControlModifier)
return;
int scrolls = event->delta() / 120;
if (scrolls > 0)
{
for (int i = 0; i < scrolls; i++)
emit signalZoom();
}
if (scrolls < 0)
{
for (int i = 0; i > scrolls; i--)
emit signalUnzoom();
}
m_lineMap.insert(posX, time);
}
void TimelineView::mouseReleaseEvent(QMouseEvent *event)
{
QTreeView::mouseReleaseEvent(event);
QPoint position = event->globalPos();
EventGraphic *eg = getEventOnPosition(position);
if (!eg)
return;
switch (event->button())
{
case Qt::LeftButton:
{
emit signalEventAction(eg, EventGraphic::ACTION_LEFT_CLICKED);
break;
}
case Qt::RightButton:
{
emit signalEventAction(eg, EventGraphic::ACTION_RIGHT_CLICKED);
break;
}
default:
{
break;
}
}
}
void TimelineView::slotAddLine(int posX, qint64 time)
{
m_lineMap.insert(posX, time);
}
void TimelineView::slotResetLineList()
{
m_lineMap.clear();
m_lineMap.clear();
}
void TimelineView::slotSetPosMarkTime(qint64 posMarkTime)
void TimelineView::slotSetPosMarkTime(qint64 posMarkTime)
{
m_posMarkTime = posMarkTime;
m_posMarkTime = posMarkTime;
TimelineHeaderView *headerView = qobject_cast<TimelineHeaderView *>(header());
if (headerView)
headerView->setPosMarkTime(posMarkTime);
TimelineHeaderView* headerView = qobject_cast<TimelineHeaderView*>(header());
if (headerView)
headerView->setPosMarkTime(posMarkTime);
refreshData();
refreshData();
}
void TimelineView::refreshData()
{
update();
viewport()->update();
update();
viewport()->update();
}
void TimelineView::paintEvent(QPaintEvent *event)
void TimelineView::paintEvent(QPaintEvent* event)
{
if (!m_model)
return;
if (!m_model)
return;
QWidget *viewp0rt = viewport();
QWidget* viewp0rt = viewport();
QPainter painter(viewp0rt);
QPainter painter(viewp0rt);
if (!painter.isActive())
{
}
painter.save();
int viewPortHeight = viewp0rt->height();
QHeaderView *head0r = header();
int sectionPos = head0r->sectionPosition(1);
int sectionSize = head0r->sectionSize(1);
int minSection = sectionPos;
int maxSection = minSection + sectionSize;
QRect paintRect(minSection, 0,
maxSection - minSection, height());
painter.setClipping(true);
painter.setClipRect(paintRect);
for (auto i = m_lineMap.constBegin(); i != m_lineMap.constEnd(); ++i)
{
int pos = i.key();
painter.setPen(QPen(QBrush(QGuiApplication::palette().shadow()), 1.0));
if (pos > minSection &&
pos < maxSection)
painter.drawLine(pos, 0, pos, viewPortHeight);
else
if (!painter.isActive())
{
}
painter.save();
int viewPortHeight = viewp0rt->height();
QHeaderView* head0r = header();
int sectionPos = head0r->sectionPosition(1);
int sectionSize = head0r->sectionSize(1);
int minSection = sectionPos;
int maxSection = minSection + sectionSize;
QRect paintRect(minSection, 0, maxSection - minSection, height());
painter.setClipping(true);
painter.setClipRect(paintRect);
for (auto i = m_lineMap.constBegin(); i != m_lineMap.constEnd(); ++i)
{
int pos = i.key();
painter.setPen(QPen(QBrush(QGuiApplication::palette().shadow()), 1.0));
if (pos > minSection && pos < maxSection)
painter.drawLine(pos, 0, pos, viewPortHeight);
else
{
#ifdef VERBOSE
qCritical() << "out of view => pos" << pos << "min" << minSection << "max" << maxSection;
qCritical() << "out of view => pos" << pos << "min" << minSection << "max" << maxSection;
#endif
}
}
}
painter.restore();
QTreeView::paintEvent(event);
painter.save();
painter.restore();
QTreeView::paintEvent(event);
painter.save();
if (m_drawCache)
{
painter.setPen(QPen(QBrush("gray"), 1));
painter.setBrush(QBrush("gray"));
painter.drawRect(minSection, 0, maxSection, height());
painter.setPen(QPen(QBrush("white"), 1));
painter.setBrush(QBrush("white"));
int h = height();
for (const auto &range : std::as_const(m_knownRanges))
if (m_drawCache)
{
int start = EventTools::getEventPosition(range.start);
if (start < minSection)
start = minSection;
painter.setPen(QPen(QBrush("gray"), 1));
painter.setBrush(QBrush("gray"));
painter.drawRect(minSection, 0, maxSection, height());
int end = EventTools::getEventPosition(range.end);
painter.setPen(QPen(QBrush("white"), 1));
painter.setBrush(QBrush("white"));
int h = height();
if (end > maxSection)
end = maxSection;
for (const auto& range : std::as_const(m_knownRanges))
{
int start = EventTools::getEventPosition(range.start);
painter.drawRect(start, 0, end - start, h);
if (start < minSection)
start = minSection;
int end = EventTools::getEventPosition(range.end);
if (end > maxSection)
end = maxSection;
painter.drawRect(start, 0, end - start, h);
}
}
}
ItemList il = m_model->getRootItem()->getFullItemList(true);
for (int i = 0; i < il.count(); i++)
{
if (il.at(i)->getName() == tr("Markers"))
EventTools::drawMarkLines(&painter, il.at(i)->getFullEventList(true), height());
}
if (m_posMarkTime > 0)
{
int posMarkPosition = EventTools::getEventPosition(m_posMarkTime);
if (posMarkPosition > sectionPos &&
posMarkPosition < sectionSize + sectionPos)
ItemList il = m_model->getRootItem()->getFullItemList(true);
for (int i = 0; i < il.count(); i++)
{
painter.setPen(QPen(QGuiApplication::palette().highlight(), 1.0));
int xpos = posMarkPosition;
painter.drawLine(xpos, 0, xpos, height());
if (il.at(i)->getName() == tr("Markers"))
EventTools::drawMarkLines(&painter, il.at(i)->getFullEventList(true), height());
}
}
painter.restore();
if (m_posMarkTime > 0)
{
int posMarkPosition = EventTools::getEventPosition(m_posMarkTime);
if (posMarkPosition > sectionPos && posMarkPosition < sectionSize + sectionPos)
{
painter.setPen(QPen(QGuiApplication::palette().highlight(), 1.0));
int xpos = posMarkPosition;
painter.drawLine(xpos, 0, xpos, height());
}
}
painter.restore();
}
}
} // namespace LtsTimelineClassic
+39 -75
View File
@@ -1,108 +1,72 @@
#pragma once
#include <QObject>
#include "AbstractTimelineModel.h"
#include "TimelineIndicator.h"
#include "TimelineHeaderView.h"
#include "LineMap.h"
#include "Range.h"
#include "TimelineHeaderView.h"
#include "TimelineIndicator.h"
#include <QObject>
#include <QTreeView>
namespace LtsTimelineClassic
{
class TimelineView : public QTreeView
{
Q_OBJECT
Q_OBJECT
public:
public:
explicit TimelineView(QWidget* parent);
explicit TimelineView(QWidget *parent);
EventGraphic* getEventOnPosition(QPoint position);
EventGraphic *getEventOnPosition(QPoint position);
void setTimelineModel(AbstractTimelineModel* model);
AbstractTimelineModel* timelineModel();
void setTimelineModel(AbstractTimelineModel *model);
void refreshData();
void setHeader(QHeaderView* header);
AbstractTimelineModel *timelineModel();
void setKnownRanges(const QVector<Range>& newRanges)
{
m_knownRanges = newRanges;
}
void setDrawCache(bool show)
{
m_drawCache = show;
}
void refreshData();
private:
qint64 m_posMarkTime;
AbstractTimelineModel* m_model;
LineMap m_lineMap;
QVector<Range> m_knownRanges;
bool m_drawCache;
protected:
bool event(QEvent* event) override;
void mouseReleaseEvent(QMouseEvent*) override;
void wheelEvent(QWheelEvent* event) override;
void setHeader(QHeaderView *header);
virtual void paintEvent(QPaintEvent* event) override;
public slots:
void setKnownRanges(const QVector<Range> &newRanges)
{
m_knownRanges = newRanges;
}
void slotResetLineList();
void setDrawCache(bool show)
{
m_drawCache = show;
}
void slotAddLine(int posX, qint64 time);
void slotSetPosMarkTime(qint64 posMarkTime);
private:
qint64 m_posMarkTime;
AbstractTimelineModel *m_model;
LineMap m_lineMap;
QVector<Range> m_knownRanges;
bool m_drawCache;
protected:
bool event(QEvent *event) override;
void mouseReleaseEvent(QMouseEvent *) override;
void wheelEvent(QWheelEvent *event) override;
virtual void paintEvent(QPaintEvent *event) override;
public slots:
void slotResetLineList();
void slotAddLine(int posX, qint64 time);
void slotSetPosMarkTime(qint64 posMarkTime);
signals:
void signalEventAction(EventGraphic *eg, int);
void signalZoom();
void signalUnzoom();
signals:
void signalEventAction(EventGraphic* eg, int);
void signalZoom();
void signalUnzoom();
};
}
} // namespace LtsTimelineClassic
+150 -197
View File
@@ -1,21 +1,18 @@
#include "TimelineWidget.h"
#include "EventDelegate.h"
#include "ui_TimelineWidgetUi.h"
#include "AbstractTimelineModel.h"
#include "EventDelegate.h"
#include "EventGraphic.h"
#include "ui_TimelineWidgetUi.h"
#include <NGLLogger/NGLLoggerBootstrap.h>
#include <QSize>
#include <QDateTime>
#include <QDebug>
#include <QPoint>
#include <QRect>
#include <QDateTime>
#include <QDebug>
#include <QSize>
namespace LtsTimelineClassic
{
@@ -29,295 +26,251 @@ TimelineWidget::TimelineWidget(QWidget *parent) : QWidget(parent)
, m_zoomFactor(1)
, m_headerView(new TimelineHeaderView)
, m_model(nullptr),
m_logger(NGL::NGLLoggerBootstrap::getLogger()) {
m_timelineUi->setupUi(this);
m_timelineUi->view->setHeader(m_headerView);
m_headerView->setMinimumSectionSize(150);
m_logger(NGL::NGLLoggerBootstrap::getLogger())
{
m_timelineUi->setupUi(this);
m_timelineUi->view->setHeader(m_headerView);
m_headerView->setMinimumSectionSize(150);
m_timelineUi->scrollbar->setMouseTracking(true);
connect(m_timelineUi->scrollbar, &QScrollBar::sliderReleased, this, &TimelineWidget::scrollBarFilter2);
connect(m_timelineUi->scrollbar, &QScrollBar::actionTriggered, this, &TimelineWidget::scrollBarFilter1);
m_timelineUi->scrollbar->setMouseTracking(true);
connect(m_timelineUi->scrollbar, &QScrollBar::sliderReleased, this, &TimelineWidget::scrollBarFilter2);
connect(m_timelineUi->scrollbar, &QScrollBar::actionTriggered, this, &TimelineWidget::scrollBarFilter1);
connect(m_headerView, &QHeaderView::sectionResized, m_timelineUi->indicator, &TimelineIndicator::slotSectionResized);
connect(m_headerView, &QHeaderView::sectionResized, this, &TimelineWidget::slotSectionResized);
connect(m_timelineUi->view, &TimelineView::signalZoom, m_timelineUi->indicator, &TimelineIndicator::slotZoom);
connect(m_timelineUi->view, &TimelineView::signalUnzoom, m_timelineUi->indicator, &TimelineIndicator::slotUnzoom);
connect(m_headerView, &QHeaderView::sectionResized, m_timelineUi->indicator,
&TimelineIndicator::slotSectionResized);
connect(m_headerView, &QHeaderView::sectionResized, this, &TimelineWidget::slotSectionResized);
connect(m_timelineUi->view, &TimelineView::signalZoom, m_timelineUi->indicator, &TimelineIndicator::slotZoom);
connect(m_timelineUi->view, &TimelineView::signalUnzoom, m_timelineUi->indicator, &TimelineIndicator::slotUnzoom);
connect(m_timelineUi->view, &TimelineView::signalZoom, this, &TimelineWidget::signalZoomChanged);
connect(m_timelineUi->view, &TimelineView::signalUnzoom, this, &TimelineWidget::signalZoomChanged);
connect(m_timelineUi->view, &TimelineView::signalZoom, this, &TimelineWidget::signalZoomChanged);
connect(m_timelineUi->view, &TimelineView::signalUnzoom, this, &TimelineWidget::signalZoomChanged);
connect(m_timelineUi->indicator, &TimelineIndicator::signalZoomChanged, this, &TimelineWidget::signalZoomChanged);
connect(m_timelineUi->indicator, &TimelineIndicator::signalSetZoomFactor, this, &TimelineWidget::slotSetZoomFactor);
connect(m_timelineUi->indicator, &TimelineIndicator::signalZoomChanged, this, &TimelineWidget::signalZoomChanged);
connect(m_timelineUi->indicator, &TimelineIndicator::signalSetZoomFactor, this, &TimelineWidget::slotSetZoomFactor);
connect(m_timelineUi->view, &TimelineView::signalEventAction,
this, &TimelineWidget::signalEventAction);
connect(m_timelineUi->view, &TimelineView::signalEventAction, this, &TimelineWidget::signalEventAction);
connect(m_timelineUi->cbDrawCache, &QCheckBox::toggled,
this, [this](bool toggled)
{
m_timelineUi->view->setDrawCache(toggled);
update();
});
connect(m_timelineUi->cbDrawCache, &QCheckBox::toggled, this, [this](bool toggled) {
m_timelineUi->view->setDrawCache(toggled);
update();
});
connect(m_timelineUi->cbArm, &QCheckBox::toggled,
this, &TimelineWidget::signalArm);
connect(m_timelineUi->updateTimeline, &QPushButton::clicked,
this, &TimelineWidget::slotUpdateTimeline);
connect(m_timelineUi->cbArm, &QCheckBox::toggled, this, &TimelineWidget::signalArm);
connect(m_timelineUi->updateTimeline, &QPushButton::clicked, this, &TimelineWidget::slotUpdateTimeline);
}
TimelineWidget::~TimelineWidget()
{
delete m_timelineUi;
delete m_timelineUi;
}
void TimelineWidget::setLiveTime(qint64 time)
{
m_headerView->setLiveTime(time);
m_headerView->setLiveTime(time);
EventDelegate *ed = qobject_cast<EventDelegate *>(m_timelineUi->view->itemDelegate());
if (ed == nullptr)
{
qWarning() << "TimelineWidget::setLiveTime: ed == nullptr";
return;
}
EventDelegate* ed = qobject_cast<EventDelegate*>(m_timelineUi->view->itemDelegate());
if (ed == nullptr)
{
qWarning() << "TimelineWidget::setLiveTime: ed == nullptr";
return;
}
ed->setLiveTime(time);
ed->setLiveTime(time);
}
void TimelineWidget::hideDebugWidget()
{
m_timelineUi->debugWidget->hide();
m_timelineUi->lbMinMax->hide();
m_timelineUi->debugWidget->hide();
m_timelineUi->lbMinMax->hide();
}
void TimelineWidget::knownRangesChanged(const QVector<Range> &newRanges)
void TimelineWidget::knownRangesChanged(const QVector<Range>& newRanges)
{
EventDelegate *ed = qobject_cast<EventDelegate *>(m_timelineUi->view->itemDelegate());
if (ed == nullptr)
{
WARNING_LOG(m_logger) << "ed == nullptr";
return;
}
EventDelegate* ed = qobject_cast<EventDelegate*>(m_timelineUi->view->itemDelegate());
if (ed == nullptr)
{
WARNING_LOG(m_logger) << "ed == nullptr";
return;
}
m_timelineUi->view->setKnownRanges(newRanges);
ed->setKnownRanges(newRanges);
m_timelineUi->view->refreshData();
m_timelineUi->view->setKnownRanges(newRanges);
ed->setKnownRanges(newRanges);
m_timelineUi->view->refreshData();
}
void TimelineWidget::setMaxPos()
{
m_timelineUi->scrollbar->setValue(m_timelineUi->scrollbar->maximum());
m_timelineUi->scrollbar->setValue(m_timelineUi->scrollbar->maximum());
}
int TimelineWidget::getMaxPos() const
{
return m_timelineUi->scrollbar->maximum();
return m_timelineUi->scrollbar->maximum();
}
int TimelineWidget::getPos() const
{
return m_timelineUi->scrollbar->value();
return m_timelineUi->scrollbar->value();
}
void TimelineWidget::setPos(qint64 pos)
{
m_timelineUi->scrollbar->setValue(pos / 1000);
m_timelineUi->scrollbar->setValue(pos / 1000);
}
void TimelineWidget::setPositionMarkerTime(const qint64 time)
{
m_timelineUi->view->slotSetPosMarkTime(time);
m_timelineUi->view->slotSetPosMarkTime(time);
}
void TimelineWidget::slotUpdateTimeline()
void TimelineWidget::slotUpdateTimeline()
{
qint64 min = m_model->lowestPositionedItem();
qint64 max = m_model->highestPositionedItem();
qint64 min = m_model->lowestPositionedItem();
qint64 max = m_model->highestPositionedItem();
if (m_timelineUi->cbMinMax->isChecked())
{
QString minmax(QStringLiteral("%1 (%2) - %3 (%4)")
.arg(QDateTime::fromMSecsSinceEpoch(min).toString())
.arg(min)
.arg(QDateTime::fromMSecsSinceEpoch(max).toString())
.arg(max));
m_timelineUi->lbMinMax->setText(minmax);
}
if (m_timelineUi->cbMinMax->isChecked())
{
QString minmax(QStringLiteral("%1 (%2) - %3 (%4)")
.arg(QDateTime::fromMSecsSinceEpoch(min).toString())
.arg(min)
.arg(QDateTime::fromMSecsSinceEpoch(max).toString())
.arg(max));
m_timelineUi->lbMinMax->setText(minmax);
}
setTimelineRange(min, max);
emit signalRangeChanged();
setTimelineRange(min, max);
emit signalRangeChanged();
}
void TimelineWidget::setTimelineModel(AbstractTimelineModel *model)
void TimelineWidget::setTimelineModel(AbstractTimelineModel* model)
{
m_model = model;
m_model = model;
connect(m_model, &AbstractTimelineModel::dataChanged,
this, &TimelineWidget::slotRefreshData );
connect(m_model, &AbstractTimelineModel::dataChanged, this, &TimelineWidget::slotRefreshData);
m_timelineUi->view->setTimelineModel(m_model);
m_timelineUi->view->setTimelineModel(m_model);
connect(m_timelineUi->indicator, &TimelineIndicator::signalAddLine, m_timelineUi->view, &TimelineView::slotAddLine);
connect(m_timelineUi->indicator, &TimelineIndicator::signalResetLineList, m_timelineUi->view,
&TimelineView::slotResetLineList);
connect(m_timelineUi->indicator, &TimelineIndicator::signalAddLine,
m_timelineUi->view, &TimelineView::slotAddLine);
connect(m_timelineUi->indicator, &TimelineIndicator::signalResetLineList,
m_timelineUi->view, &TimelineView::slotResetLineList);
EventDelegate* ed = qobject_cast<EventDelegate*>(m_timelineUi->view->itemDelegate());
if (ed != nullptr)
{
connect(m_timelineUi->indicator, &TimelineIndicator::signalAddLine, ed, &EventDelegate::slotAddLine);
connect(m_timelineUi->indicator, &TimelineIndicator::signalResetLineList, ed,
&EventDelegate::slotResetLineList);
}
EventDelegate *ed = qobject_cast<EventDelegate *>(m_timelineUi->view->itemDelegate());
if (ed != nullptr)
{
connect(m_timelineUi->indicator, &TimelineIndicator::signalAddLine,
ed, &EventDelegate::slotAddLine);
connect(m_timelineUi->indicator, &TimelineIndicator::signalResetLineList,
ed, &EventDelegate::slotResetLineList);
}
m_timelineUi->view->expandToDepth(1);
m_timelineUi->view->expandToDepth(1);
m_headerView->resizeSection(0, m_headerView->minimumSectionSize());
m_headerView->resizeSection(1, m_headerView->minimumSectionSize());
m_headerView->resizeSection(0, m_headerView->minimumSectionSize());
m_headerView->resizeSection(1, m_headerView->minimumSectionSize());
slotSetZoomFactor(m_timelineUi->indicator->zoomFactorPoints());
slotSetZoomFactor(m_timelineUi->indicator->zoomFactorPoints());
}
qint64 TimelineWidget::getRangeMinimum() const
{
return EventTools::getAdjustedMin();
return EventTools::getAdjustedMin();
}
qint64 TimelineWidget::getRangeMaximum() const
{
return EventTools::getAdjustedMax();
return EventTools::getAdjustedMax();
}
void TimelineWidget::setTimelineRange(qint64 min, qint64 max)
void TimelineWidget::setTimelineRange(qint64 min, qint64 max)
{
m_min = min;
m_max = max;
m_min = min;
m_max = max;
if (m_min > 0 && m_max > 2)
{
m_sbPos = EventTools::fromSecondsToMsecs(m_timelineUi->scrollbar->sliderPosition());
if (m_min > 0 && m_max > 2)
{
m_sbPos = EventTools::fromSecondsToMsecs(m_timelineUi->scrollbar->sliderPosition());
if (m_max <= m_min)
{
if (m_min > (10 * 60))
m_min -= (10 * 60);
}
else
{
qint64 diff = m_max - m_min;
if (diff < (10 * 60))
if (m_min > (10 * 60))
m_min -= (10 * 60);
if (m_max <= m_min)
{
if (m_min > (10 * 60))
m_min -= (10 * 60);
}
else
{
qint64 diff = m_max - m_min;
if (diff < (10 * 60))
if (m_min > (10 * 60))
m_min -= (10 * 60);
}
EventTools::setValues(m_min, m_max, m_sbPos, m_zoomFactor);
m_timelineUi->scrollbar->setRange(EventTools::fromMsecsToSeconds(EventTools::getTimelineMin()),
EventTools::fromMsecsToSeconds(EventTools::getTimelineMax()));
if (m_sbPos < m_min)
{
m_sbPos = m_min;
m_timelineUi->scrollbar->setSliderPosition(EventTools::fromMsecsToSeconds(m_sbPos));
}
int pagestep = EventTools::fromMsecsToSeconds(EventTools::s_diff);
if (pagestep < 0)
pagestep = 1;
m_timelineUi->scrollbar->setPageStep(pagestep);
m_timelineUi->bsz->setText(QString::number(EventTools::getBlockSizeTime()));
}
EventTools::setValues(m_min, m_max, m_sbPos, m_zoomFactor);
m_timelineUi->scrollbar->setRange(EventTools::fromMsecsToSeconds(EventTools::getTimelineMin()), EventTools::fromMsecsToSeconds(EventTools::getTimelineMax()));
if (m_sbPos < m_min)
{
m_sbPos = m_min;
m_timelineUi->scrollbar->setSliderPosition(EventTools::fromMsecsToSeconds(m_sbPos));
}
int pagestep = EventTools::fromMsecsToSeconds(EventTools::s_diff);
if (pagestep < 0)
pagestep = 1;
m_timelineUi->scrollbar->setPageStep(pagestep);
m_timelineUi->bsz->setText(QString::number(EventTools::getBlockSizeTime()));
}
refreshData();
refreshData();
}
void TimelineWidget::slotRefreshData()
{
refreshData();
refreshData();
}
void TimelineWidget::refreshData()
{
m_headerView->refreshData();
m_timelineUi->indicator->refreshData();
m_timelineUi->view->refreshData();
m_headerView->refreshData();
m_timelineUi->indicator->refreshData();
m_timelineUi->view->refreshData();
}
void TimelineWidget::slotSetZoomFactor(qint64 zoomFactor)
{
m_zoomFactor = zoomFactor;
slotUpdateTimeline();
m_zoomFactor = zoomFactor;
slotUpdateTimeline();
}
void TimelineWidget::scrollBarFilter1(int )
void TimelineWidget::scrollBarFilter1(int)
{
scrollBarFilter2();
scrollBarFilter2();
}
void TimelineWidget::scrollBarFilter2()
{
slotUpdateTimeline();
slotUpdateTimeline();
}
void TimelineWidget::slotSectionResized(int logicalIndex, int oldSize, int newSize)
{
(void)oldSize;
(void)oldSize;
if (logicalIndex == 1)
{
int viewScrollbarWidth = m_timelineUi->view->verticalScrollBar()->width();
m_timelineUi->scrollbar->setMinimumHeight(viewScrollbarWidth);
m_timelineUi->scrollbar->setMaximumHeight(viewScrollbarWidth);
if (logicalIndex == 1)
{
int viewScrollbarWidth = m_timelineUi->view->verticalScrollBar()->width();
m_timelineUi->scrollbar->setMinimumHeight(viewScrollbarWidth);
m_timelineUi->scrollbar->setMaximumHeight(viewScrollbarWidth);
m_timelineUi->scrollbar->setMaximumWidth(newSize);
m_timelineUi->scrollbar->setMinimumWidth(newSize);
m_timelineUi->scrollbar->setMaximumWidth(newSize);
m_timelineUi->scrollbar->setMinimumWidth(newSize);
EventTools::setSection(m_headerView->sectionPosition(1),
newSize );
}
EventTools::setSection(m_headerView->sectionPosition(1), newSize);
}
slotUpdateTimeline();
slotUpdateTimeline();
}
}
} // namespace LtsTimelineClassic
+42 -79
View File
@@ -1,123 +1,86 @@
#pragma once
#include <QObject>
#include "Range.h"
#include "ltstimelineclassic_export.h"
#include "Range.h"
#include <NGLLogger/INGLLogger.h>
#include <QObject>
#include <QWidget>
namespace Ui
{
class Timeline;
}
namespace LtsTimelineClassic
{
class AbstractTimelineModel;
class EventGraphic;
class TimelineHeaderView;
class LTSTIMELINECLASSIC_EXPORT TimelineWidget : public QWidget
{
Q_OBJECT
Q_OBJECT
public:
public:
explicit TimelineWidget(QWidget* parent = nullptr);
explicit TimelineWidget(QWidget *parent = nullptr);
~TimelineWidget();
~TimelineWidget();
void setPositionMarkerTime(const qint64 time);
qint64 getRangeMinimum() const;
qint64 getRangeMaximum() const;
void setPositionMarkerTime(const qint64 time);
void setPos(qint64 pos);
void setMaxPos();
int getPos() const;
int getMaxPos() const;
qint64 getRangeMinimum() const;
qint64 getRangeMaximum() const;
void knownRangesChanged(const QVector<Range>& newRanges);
void hideDebugWidget();
void setLiveTime(qint64 time);
void setPos(qint64 pos);
void setMaxPos();
int getPos() const;
int getMaxPos() const;
private:
NGL::INGLLogger& m_logger;
void setTimelineRange(qint64 min, qint64 max);
void knownRangesChanged(const QVector<Range> &newRanges);
void hideDebugWidget();
void setLiveTime(qint64 time);
void refreshData();
Ui::Timeline* m_timelineUi;
qint64 m_min;
qint64 m_max;
qint64 m_sbPos;
qint64 m_zoomFactor;
private:
TimelineHeaderView* m_headerView;
AbstractTimelineModel* m_model;
NGL::INGLLogger &m_logger;
void setTimelineRange(qint64 min, qint64 max);
signals:
void refreshData();
Ui::Timeline *m_timelineUi;
void signalLoadNewEvents(qint64 from, qint64 to);
qint64 m_min;
qint64 m_max;
qint64 m_sbPos;
qint64 m_zoomFactor;
void signalEventAction(EventGraphic* eg, int);
void signalRangeChanged();
void signalArm(bool arm);
void signalZoomChanged();
TimelineHeaderView *m_headerView;
AbstractTimelineModel *m_model;
public slots:
void scrollBarFilter1(int x);
signals:
void scrollBarFilter2();
void signalLoadNewEvents(qint64 from, qint64 to);
void slotSetZoomFactor(qint64 zoomFactor);
void slotSectionResized(int logicalIndex, int oldSize, int newSize);
void setTimelineModel(AbstractTimelineModel* model);
void signalEventAction(EventGraphic *eg, int);
void signalRangeChanged();
void signalArm(bool arm);
void signalZoomChanged();
public slots:
void scrollBarFilter1(int x);
void scrollBarFilter2();
void slotSetZoomFactor(qint64 zoomFactor);
void slotSectionResized(int logicalIndex, int oldSize, int newSize);
void setTimelineModel(AbstractTimelineModel *model);
void slotUpdateTimeline();
void slotRefreshData();
void slotUpdateTimeline();
void slotRefreshData();
};
}
} // namespace LtsTimelineClassic
+40 -51
View File
@@ -1,82 +1,71 @@
#include "TimelineWidget.h"
#include "TestTimelineModel.h"
#include "TimelineWidget.h"
#include <NGLLogger/NGLLoggerBootstrap.h>
#include <nglapplication/nglapplication.h>
#include <QDebug>
#include <QPushButton>
#include <QVBoxLayout>
#include <Services/ProjectDataManagement/pdm_enums.hpp>
#include <Services/ProjectDataManagement/pdm_translation.h>
#include <nglapplication/nglapplication.h>
#include <time.h>
#include <QVBoxLayout>
#include <QPushButton>
#include <QDebug>
LtsTimelineClassic::TestTimelineModel *ttm;
LtsTimelineClassic::TestTimelineModel* ttm;
void add(qint64 time_offset)
{
qint64 time = 1505292189000;
time += time_offset;
qint64 time = 1505292189000;
time += time_offset;
ttm->addTestEvent(new LtsTimelineClassic::Event(0, (int)ProjectDataManagement::EventType_def::Hit, time, 0, 0, 0, 0,
QStringList() << QStringLiteral("Test"),
LtsTimelineClassic::Event::drawCustomEventGraphicEllipse, QColor("green"), QString()));
ttm->addTestEvent(new LtsTimelineClassic::Event(
0, (int)ProjectDataManagement::EventType_def::Hit, time, 0, 0, 0, 0, QStringList() << QStringLiteral("Test"),
LtsTimelineClassic::Event::drawCustomEventGraphicEllipse, QColor("green"), QString()));
}
int main(int argc, char *argv[])
int main(int argc, char* argv[])
{
qputenv("TDS_DEVEL", "yes, of course");
qWarning() << "LtsTimelineClassicTest";
NGLApplication app(argc, argv);
app.createLogger("Timeline", "log4cxx_timeline.props");
qputenv("TDS_DEVEL", "yes, of course");
qWarning() << "LtsTimelineClassicTest";
NGLApplication app(argc, argv);
app.createLogger("Timeline", "log4cxx_timeline.props");
STARTUP_LOG(app.baseLogger());
STARTUP_LOG(app.baseLogger());
int ret = 0;
int ret = 0;
#if 1
QWidget *widget = new QWidget();
widget->setMinimumWidth(500);
QWidget* widget = new QWidget();
widget->setMinimumWidth(500);
QVBoxLayout *layout = new QVBoxLayout();
widget->setLayout(layout);
QVBoxLayout* layout = new QVBoxLayout();
widget->setLayout(layout);
LtsTimelineClassic::TimelineWidget *timelineWidget = new LtsTimelineClassic::TimelineWidget();
layout->addWidget(timelineWidget);
LtsTimelineClassic::TimelineWidget* timelineWidget = new LtsTimelineClassic::TimelineWidget();
layout->addWidget(timelineWidget);
QHBoxLayout *btnLayout = new QHBoxLayout();
QWidget *btnLayoutWidget = new QWidget();
btnLayoutWidget->setLayout(btnLayout);
layout->addWidget(btnLayoutWidget);
QHBoxLayout* btnLayout = new QHBoxLayout();
QWidget* btnLayoutWidget = new QWidget();
btnLayoutWidget->setLayout(btnLayout);
layout->addWidget(btnLayoutWidget);
btnLayout->addWidget(new QPushButton(QStringLiteral("Filter")));
btnLayout->addWidget(new QPushButton(QStringLiteral("CSV Export")));
btnLayout->addStretch(1);
btnLayout->addWidget(new QPushButton(QStringLiteral("Filter")));
btnLayout->addWidget(new QPushButton(QStringLiteral("CSV Export")));
btnLayout->addStretch(1);
widget->show();
widget->show();
ttm = new LtsTimelineClassic::TestTimelineModel();
timelineWidget->setTimelineModel(ttm);
ttm = new LtsTimelineClassic::TestTimelineModel();
timelineWidget->setTimelineModel(ttm);
add(0);
add(100 * 60 * 1000);
add(3000 * 60 * 1000);
add(0);
add(100 * 60 * 1000);
add(3000 * 60 * 1000);
ret = app.exec();
SHUTDOWN_LOG(app.baseLogger());
ret = app.exec();
SHUTDOWN_LOG(app.baseLogger());
#endif
return ret;
return ret;
}