Files
qt6-migration-pipeline/TetraIF/LogView/LogViewField.cpp
T

276 lines
5.6 KiB
C++

#include "LogViewField.hpp"
#include <QtCore/QDateTime>
#include "LogViewXdrElement.hpp"
#include "LogViewXdrStandardType.hpp"
namespace N_LogView
{
LogViewField::LogViewField(const QString& a_name, const E_FieldKind a_kind, const LogViewXdrElement* a_xdrElement)
: m_Name(a_name),
m_IsRightAligned(false),
m_Offset(0),
m_Size(0),
m_MaxArraySize(0),
m_IsDynamicArray(false),
m_HasContent(true),
m_bDeleteXdr(false),
m_Kind(a_kind),
m_XdrElement(a_xdrElement),
m_logger(getLogger("LogViewField"))
{
}
LogViewField::~LogViewField()
{
for (LogViewField *f : std::as_const(m_Child))
delete f;
if (m_bDeleteXdr)
delete m_XdrElement;
}
LogViewField *LogViewField::clone(int arrayIdx) const
{
LogViewField *f = new LogViewField(*this);
f->m_Child.clear();
f->m_bDeleteXdr = false;
for (auto * c : m_Child)
{
auto *clonedChild = c->clone(-1);
if (arrayIdx >= 0)
{
QStringList sl = clonedChild->jsonPath();
if (sl.size() > 1 && sl.at(sl.size() - 2).startsWith(QStringLiteral("index: ")))
{
sl[sl.size() - 2] = QStringLiteral("index: %1").arg(arrayIdx);
clonedChild->setJsonPath(sl);
}
}
f->addChild(clonedChild);
}
for (auto &val : f->m_ValueList)
val.clear();
return f;
}
void LogViewField::addChild(LogViewField* a_child)
{
if (a_child)
m_Child.push_back(a_child);
}
void LogViewField::removeLastChild()
{
if (m_Child.empty())
return;
delete m_Child.takeLast();
}
LogViewField* LogViewField::child(int arrayIdx)
{
if (m_Child.size() > arrayIdx)
return m_Child.at(arrayIdx);
return nullptr;
}
void LogViewField::addValue(const QString &value)
{
m_ValueList.append(value);
}
void LogViewField::addValueBinaryHex(const QString &value)
{
const QByteArray ba = QByteArray::fromHex(value.toLatin1());
for (const char c : ba)
m_ValueList.append(QString::number(static_cast<unsigned char>(c)));
}
QString LogViewField::value(int arrayIdx, const bool a_doNotMakeSpecialConversions) const
{
if (m_ValueList.size() > arrayIdx)
{
const QString &ret = m_ValueList.at(arrayIdx);
if (!a_doNotMakeSpecialConversions)
{
if (isDateTimeField())
return QDateTime::fromMSecsSinceEpoch(ret.toLongLong() * 1000).toString(QStringLiteral("dd.mm.yy hh:mm:ss.zzz"));
if (isMSecsField())
return QDateTime::fromMSecsSinceEpoch(ret.toLongLong()).toString(QStringLiteral("dd.mm.yy hh:mm:ss.zzz"));
}
return ret;
}
return QString();
}
int64_t LogViewField::getHighestValue() const
{
switch (m_XdrElement->getKind())
{
case LogViewXdrElement::e_KindStandardType:
{
int64_t highest = 1;
uint16_t bitSize = 8*static_cast<const LogViewXdrStandardType*>(m_XdrElement)->getEditSize();
if ((0 == m_Name.compare(QLatin1String("utm nordwert"), Qt::CaseInsensitive)) ||
(0 == m_Name.compare(QLatin1String("utm ostwert"), Qt::CaseInsensitive)))
bitSize -= 8;
switch (static_cast<const LogViewXdrStandardType*>(m_XdrElement)->getValueKind()) {
case LogViewXdrStandardType::e_Boolean:
return 1;
case LogViewXdrStandardType::e_Signed:
bitSize--;
Q_FALLTHROUGH();
case LogViewXdrStandardType::e_Unsigned:
case LogViewXdrStandardType::e_Data:
highest = highest << bitSize;
highest--;
break;
default:
highest = 0;
break;
}
return highest;
}
default:
ERROR_LOG(m_logger) << "Case not implemented";
}
return 0;
}
int64_t LogViewField::getLowestValue() const
{
switch (m_XdrElement->getKind())
{
case LogViewXdrElement::e_KindStandardType:
{
int64_t lowest = 0;
switch (static_cast<const LogViewXdrStandardType*>(m_XdrElement)->getValueKind()) {
case LogViewXdrStandardType::e_Boolean:
return 0;
case LogViewXdrStandardType::e_Signed:
lowest = getHighestValue() + 1;
lowest = -lowest;
break;
default:
break;
}
return lowest;
}
default:
ERROR_LOG(m_logger) << "Case not implemented";
break;
}
return 0;
}
void LogViewField::dump(const QString &a_indent) const
{
INFO_LOG(m_logger) << a_indent << "[";
INFO_LOG(m_logger) << a_indent << "Field[" << m_Name << "]: m_Kind=" << m_Kind << " m_Offset=" << m_Offset << " m_Size=" << m_Size << " m_MaxArraySize=" << m_MaxArraySize << " m_IsRightAligned=" << m_IsRightAligned << " m_IsDynamicArray=" << m_IsDynamicArray << " m_ToolTipText=" << m_ToolTipText;
for (int i=0; i<m_ValueList.size(); i++)
INFO_LOG(m_logger) << a_indent << "m_Value[" << i << "]=" << m_ValueList[i];
for (auto *c : m_Child)
c->dump(a_indent + QLatin1Char(' '));
INFO_LOG(m_logger) << a_indent << "]";
}
QString LogViewField::makeClean(const QString &text)
{
QString a_uncleanText = text;
if (a_uncleanText.endsWith(QLatin1String("_rt")))
a_uncleanText = a_uncleanText.left(a_uncleanText.length() - 3);
a_uncleanText = a_uncleanText.replace(QLatin1Char('_'), QLatin1Char(' '));
int pos = 0;
while (a_uncleanText.length() > pos)
{
a_uncleanText[pos] = a_uncleanText[pos].toUpper();
pos = a_uncleanText.indexOf(QLatin1Char(' '), pos + 1);
if (-1 == pos)
break;
pos++;
}
return a_uncleanText;
}
bool LogViewField::isDateTimeField() const
{
QString name = m_Name.toLower();
return name == QLatin1String("gps_zeit");
}
bool LogViewField::isMSecsField() const
{
QString name = m_Name.toLower();
return (name == QLatin1String("timestamp")) || (name == QLatin1String("effectstart"));
}
void LogViewField::setMaxArraySize(uint16_t newVal, const bool a_isDynamic)
{
m_MaxArraySize = newVal;
m_IsDynamicArray = a_isDynamic;
}
}