|
|
|
#include "viewmodel/table/LogTableModel.h"
|
|
|
|
|
|
|
|
#include "viewmodel/displayString/util/DisplayStringProviderMapGenerator.h"
|
|
|
|
|
|
|
|
/*************************************************************************************************/
|
|
|
|
LogTableModel::LogTableModel()
|
|
|
|
{
|
|
|
|
initColumnMap();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************************************/
|
|
|
|
LogTableModel::~LogTableModel()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************************************/
|
|
|
|
int LogTableModel::rowCount(const QModelIndex& parent) const {
|
|
|
|
Q_UNUSED(parent)
|
|
|
|
|
|
|
|
auto size = _logs.size();
|
|
|
|
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************************************/
|
|
|
|
int LogTableModel::columnCount(const QModelIndex& parent) const {
|
|
|
|
Q_UNUSED(parent)
|
|
|
|
|
|
|
|
return _columnMap.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************************************/
|
|
|
|
QVariant LogTableModel::data(const QModelIndex& index, int role) const {
|
|
|
|
if(!index.isValid() || (role != Qt::DisplayRole and role != Qt::UserRole))
|
|
|
|
{
|
|
|
|
return QVariant();
|
|
|
|
}
|
|
|
|
|
|
|
|
if(role == Qt::DisplayRole)
|
|
|
|
{
|
|
|
|
return providerDisplayRepresentation(_logs[index.row()],
|
|
|
|
static_cast<ELogColumn>(index.column()));
|
|
|
|
}
|
|
|
|
|
|
|
|
if(role == Qt::UserRole)
|
|
|
|
{
|
|
|
|
return QVariant::fromValue(_logs[index.row()]);
|
|
|
|
}
|
|
|
|
|
|
|
|
return QVariant();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************************************/
|
|
|
|
QVariant LogTableModel::headerData(int section, Qt::Orientation orientation, int role) const {
|
|
|
|
if(role == Qt::DisplayRole)
|
|
|
|
{
|
|
|
|
if(orientation == Qt::Horizontal)
|
|
|
|
{
|
|
|
|
return _columnMap[section];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return QVariant();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************************************/
|
|
|
|
void LogTableModel::setDisplayProviderCreator(DisplayProviderCreator_ptr creator)
|
|
|
|
{
|
|
|
|
_textProviders = DisplayStringProviderMapGenerator::generate(creator);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************************************/
|
|
|
|
void LogTableModel::onLogAdded(Log_ptr log)
|
|
|
|
{
|
|
|
|
beginInsertRows(QModelIndex(), _logs.size(), _logs.size());
|
|
|
|
_logs.append(log);
|
|
|
|
endInsertRows();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************************************/
|
|
|
|
void LogTableModel::onLogsChanged(QList<Log_ptr> logs)
|
|
|
|
{
|
|
|
|
beginResetModel();
|
|
|
|
_logs = logs;
|
|
|
|
endResetModel();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************************************/
|
|
|
|
QVariant LogTableModel::providerDisplayRepresentation(const Log_ptr& log, ELogColumn column) const
|
|
|
|
{
|
|
|
|
auto provider = _textProviders.value(column, nullptr);
|
|
|
|
if(provider)
|
|
|
|
{
|
|
|
|
return provider->provideString(log);
|
|
|
|
}
|
|
|
|
|
|
|
|
return QVariant();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************************************/
|
|
|
|
void LogTableModel::initColumnMap()
|
|
|
|
{
|
|
|
|
_columnMap[id] = "Logger Id";
|
|
|
|
_columnMap[level] = "Level";
|
|
|
|
_columnMap[timestamp] = "Time";
|
|
|
|
_columnMap[file] = "File Address";
|
|
|
|
_columnMap[func] = "Function";
|
|
|
|
_columnMap[lineno] = "Line Number";
|
|
|
|
_columnMap[msg] = "Message";
|
|
|
|
_columnMap[scope] = "Scope";
|
|
|
|
_columnMap[threadId] = "Thread";
|
|
|
|
}
|