Added LogDialog and LogModel

This commit is contained in:
0xFEEDC0DE64
2017-12-22 11:43:59 +01:00
parent 2b1cdc2bd0
commit d301a9bd71
7 changed files with 250 additions and 5 deletions
+70
View File
@@ -0,0 +1,70 @@
#include "logmodel.h"
LogModel::LogModel(QObject *parent) :
QAbstractListModel(parent)
{
}
void LogModel::log(QtMsgType type, const char *fileName, int lineNumber, const char *functionName, const char *categoryName, const QString &message)
{
beginInsertRows(QModelIndex(), m_entries.count(), m_entries.count());
m_entries.append(Entry { QDateTime::currentDateTime(), type, fileName, lineNumber, functionName, categoryName, message });
endInsertRows();
}
int LogModel::rowCount(const QModelIndex &parent) const
{
Q_UNUSED(parent)
return m_entries.count();
}
int LogModel::columnCount(const QModelIndex &parent) const
{
Q_UNUSED(parent)
return 4;
}
QVariant LogModel::data(const QModelIndex &index, int role) const
{
Q_ASSERT(index.row() < m_entries.count());
const auto &entry = m_entries.at(index.row());
switch(role)
{
case Qt::DisplayRole:
case Qt::EditRole:
switch(index.column())
{
case 0: return entry.type;
case 1: return entry.dateTime.toString(QStringLiteral("dd.MM.yyyy HH:mm:ss.zzz"));
case 2: return entry.functionName;
case 3: return entry.message;
}
}
return QVariant();
}
QVariant LogModel::headerData(int section, Qt::Orientation orientation, int role) const
{
switch(orientation)
{
case Qt::Horizontal:
switch(role)
{
case Qt::DisplayRole:
case Qt::EditRole:
switch(section)
{
case 0: return tr("Type");
case 1: return tr("Timestamp");
case 2: return tr("Function");
case 3: return tr("Message");
}
}
default:
qt_noop();
}
return QVariant();
}