Log Viewer
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.
 
 

114 lines
4.8 KiB

#include "viewmodel/tree/util/Log2TreeItemConverter.h"
/*************************************************************************************************/
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
{
if(log->msg.has_value())
{
}
}
/*************************************************************************************************/
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)}));
}
}