Beispiel #1
0
void LogWindow::addLogEntry(const LogEntry &entry)
{
    QString entryType;
    QTextCharFormat *entryFormat;
    switch (entry.entryType()) {
    case LogEntry::DebugMessage:
        entryType = tr("Debug");
        entryFormat = m_debugMessageFormat;
        break;
    case LogEntry::Notification:
        entryType = tr("Notification");
        entryFormat = m_notificationFormat;
        break;
    case LogEntry::Warning:
        entryType = tr("Warning");
        entryFormat = m_warningFormat;
        break;
    case LogEntry::Error:
        entryType = tr("Error");
        entryFormat = m_errorFormat;
        break;
    default:
        entryType = tr("LogEntry");
        entryFormat = m_debugMessageFormat;
    }

    QTextDocument *doc = m_log->document();
    QTextCursor cur(doc);
    cur.beginEditBlock();
    cur.movePosition(QTextCursor::Start);
    cur.insertBlock(*m_logEntryBlockFormat);
    cur.insertText(entry.timeStamp().toString("[yyyy-MM-dd hh:mm:ss]"),
                   *m_timeStampFormat);
    cur.insertText(" ");
    cur.insertText(QString("%1").arg(entryType, -12), *entryFormat);
    cur.insertText(" ");
    if (entry.moleQueueId() == InvalidId) {
        cur.insertText(tr("Job %1").arg("N/A", -6), *m_moleQueueIdFormat);
    }
    else {
        cur.insertText(tr("Job %1").arg(entry.moleQueueId(), -6),
                       *m_moleQueueIdFormat);
    }
    cur.insertText(" ");
    // Modify newlines to align with the hanging indent.
    cur.insertText(entry.message().replace(QRegExp("\\n+"), "\n  "),
                   *m_messageFormat);
    cur.endEditBlock();
}