You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
203 lines
8.0 KiB
203 lines
8.0 KiB
#include "viewmodel/tree/util/Log2TreeItemConverter.h"
|
|
|
|
#include <QJsonArray>
|
|
|
|
/*************************************************************************************************/
|
|
std::unique_ptr<TreeItem> SimpleLog2TreeItemConverter::convert(const Log_ptr log,
|
|
const TMap& translatorMap) const
|
|
{
|
|
auto root = std::make_unique<TreeItem>(QVariantList{QString("Field"), QString("Value")});
|
|
|
|
if(log)
|
|
{
|
|
addIdItem(log, translatorMap, root.get());
|
|
addLevelItem(log, translatorMap, root.get());
|
|
addSrcItem(log, translatorMap, root.get());
|
|
addMsgItem(log, translatorMap, root.get());
|
|
addScopeItem(log, translatorMap, root.get());
|
|
addThreadId(log, translatorMap, root.get());
|
|
addTimestamp(log, translatorMap, root.get());
|
|
}
|
|
|
|
return root;
|
|
}
|
|
|
|
/*************************************************************************************************/
|
|
void SimpleLog2TreeItemConverter::addIdItem(const Log_ptr log,
|
|
const ILog2TreeItemConvertor::TMap& translatorMap,
|
|
TreeItem* parent) const
|
|
{
|
|
if(log->id.has_value())
|
|
{
|
|
parent->appendChild(std::make_unique<TreeItem>(
|
|
QVariantList{"Logger Id", translatorMap[id]->provideString(log)}));
|
|
}
|
|
}
|
|
|
|
/*************************************************************************************************/
|
|
void SimpleLog2TreeItemConverter::addLevelItem(const Log_ptr log,
|
|
const ILog2TreeItemConvertor::TMap& translatorMap,
|
|
TreeItem* parent) const
|
|
{
|
|
if(log->level.has_value())
|
|
{
|
|
parent->appendChild(std::make_unique<TreeItem>(
|
|
QVariantList{"Level", translatorMap[level]->provideString(log)}));
|
|
}
|
|
}
|
|
|
|
/*************************************************************************************************/
|
|
void SimpleLog2TreeItemConverter::addSrcItem(const Log_ptr log,
|
|
const ILog2TreeItemConvertor::TMap& translatorMap,
|
|
TreeItem* parent) const
|
|
{
|
|
if(log->src.has_value())
|
|
{
|
|
auto srcRoot = std::make_unique<TreeItem>(QVariantList{"Location", ""});
|
|
srcRoot->appendChild(std::make_unique<TreeItem>(QVariantList{
|
|
"Filename", translatorMap[file]->provideString(log)}));
|
|
|
|
srcRoot->appendChild(std::make_unique<TreeItem>(QVariantList{
|
|
"Line Number", translatorMap[lineno]->provideString(log)}));
|
|
|
|
srcRoot->appendChild(std::make_unique<TreeItem>(QVariantList{
|
|
"Function Name", translatorMap[func]->provideString(log)}));
|
|
|
|
parent->appendChild(std::move(srcRoot));
|
|
}
|
|
}
|
|
|
|
/*************************************************************************************************/
|
|
void SimpleLog2TreeItemConverter::addMsgItem(const Log_ptr log,
|
|
const ILog2TreeItemConvertor::TMap& translatorMap,
|
|
TreeItem* parent) const
|
|
{
|
|
Q_UNUSED(translatorMap)
|
|
|
|
if(log->msg.has_value())
|
|
{
|
|
auto msgRoot = std::make_unique<TreeItem>(QVariantList{"Message", ""});
|
|
addMsgParts(log->msg.value(), msgRoot.get());
|
|
parent->appendChild(std::move(msgRoot));
|
|
}
|
|
}
|
|
|
|
/*************************************************************************************************/
|
|
void SimpleLog2TreeItemConverter::addMsgParts(const QList<MessagePart>& parts,
|
|
TreeItem* parent) const
|
|
{
|
|
for(const auto& part : parts)
|
|
{
|
|
if(part.string.has_value())
|
|
{
|
|
addStringMessage(part.string.value(), parent);
|
|
}
|
|
|
|
if(part.loggedObject.has_value())
|
|
{
|
|
addObjectMessage(part.loggedObject.value(), parent);
|
|
}
|
|
}
|
|
}
|
|
|
|
/*************************************************************************************************/
|
|
void SimpleLog2TreeItemConverter::addStringMessage(const QString& message, TreeItem* parent) const
|
|
{
|
|
parent->appendChild(std::make_unique<TreeItem>(QVariantList{"[MSG]", message}));
|
|
}
|
|
|
|
/*************************************************************************************************/
|
|
void SimpleLog2TreeItemConverter::addObjectMessage(const LoggedObjectDto& obj,
|
|
TreeItem* parent) const
|
|
{
|
|
auto objRoot = std::make_unique<TreeItem>(QVariantList{"[" + obj.type + "]", obj.summary});
|
|
addJsonObject(obj.content, objRoot.get());
|
|
parent->appendChild(std::move(objRoot));
|
|
}
|
|
|
|
/*************************************************************************************************/
|
|
void SimpleLog2TreeItemConverter::addJsonObject(const QJsonObject& obj, TreeItem* parent) const
|
|
{
|
|
for(auto& key : obj.keys())
|
|
{
|
|
auto val = obj[key];
|
|
if(val.isObject())
|
|
{
|
|
auto objRoot = std::make_unique<TreeItem>(QVariantList{key, "[OBJ]"});
|
|
addJsonObject(val.toObject(), objRoot.get());
|
|
parent->appendChild(std::move(objRoot));
|
|
}
|
|
else if(val.isArray())
|
|
{
|
|
auto objRoot = std::make_unique<TreeItem>(QVariantList{key, "[ARRAY]"});
|
|
addJsonArray(val.toArray(), objRoot.get());
|
|
parent->appendChild(std::move(objRoot));
|
|
}
|
|
else
|
|
{
|
|
parent->appendChild(std::make_unique<TreeItem>(QVariantList{key, val.toVariant()}));
|
|
}
|
|
}
|
|
}
|
|
|
|
/*************************************************************************************************/
|
|
void SimpleLog2TreeItemConverter::addJsonArray(const QJsonArray& arr, TreeItem* parent) const
|
|
{
|
|
for(const auto& val : arr)
|
|
{
|
|
if(val.isObject())
|
|
{
|
|
auto objRoot = std::make_unique<TreeItem>(QVariantList{"[OBJ]", ""});
|
|
addJsonObject(val.toObject(), objRoot.get());
|
|
parent->appendChild(std::move(objRoot));
|
|
}
|
|
else if(val.isArray())
|
|
{
|
|
auto objRoot = std::make_unique<TreeItem>(QVariantList{"[ARRAY]", ""});
|
|
addJsonArray(val.toArray(), objRoot.get());
|
|
parent->appendChild(std::move(objRoot));
|
|
}
|
|
else
|
|
{
|
|
parent->appendChild(std::make_unique<TreeItem>(QVariantList{val.toVariant(), ""}));
|
|
}
|
|
}
|
|
}
|
|
|
|
/*************************************************************************************************/
|
|
void SimpleLog2TreeItemConverter::addScopeItem(const Log_ptr log,
|
|
const ILog2TreeItemConvertor::TMap& translatorMap,
|
|
TreeItem* parent) const
|
|
{
|
|
if(log->scope.has_value())
|
|
{
|
|
parent->appendChild(std::make_unique<TreeItem>(
|
|
QVariantList{"Scope", translatorMap[scope]->provideString(log)}));
|
|
}
|
|
}
|
|
|
|
/*************************************************************************************************/
|
|
void SimpleLog2TreeItemConverter::addThreadId(const Log_ptr log,
|
|
const ILog2TreeItemConvertor::TMap& translatorMap,
|
|
TreeItem* parent) const
|
|
{
|
|
if(log->threadId.has_value())
|
|
{
|
|
parent->appendChild(std::make_unique<TreeItem>(
|
|
QVariantList{"ThreadId",
|
|
translatorMap[threadId]->provideString(log)}));
|
|
}
|
|
}
|
|
|
|
/*************************************************************************************************/
|
|
void SimpleLog2TreeItemConverter::addTimestamp(const Log_ptr log,
|
|
const ILog2TreeItemConvertor::TMap& translatorMap,
|
|
TreeItem* parent) const
|
|
{
|
|
if(log->timestamp.has_value())
|
|
{
|
|
parent->appendChild(std::make_unique<TreeItem>(
|
|
QVariantList{"Time",
|
|
translatorMap[timestamp]->provideString(log)}));
|
|
}
|
|
}
|
|
|