Added log error dialog

This commit is contained in:
parax0 2016-01-05 03:20:47 -07:00
parent b61f21f346
commit aa5453b84a
7 changed files with 183 additions and 32 deletions

View File

@ -5,6 +5,7 @@
namespace Log
{
TStringList ErrorLog;
static const TString gskLogFilename = "primeworldeditor.log";
#pragma warning(push)
@ -12,7 +13,7 @@ static const TString gskLogFilename = "primeworldeditor.log";
FILE *gpLogFile = fopen(*gskLogFilename, "w");
#pragma warning(pop)
void Write(const TString& message)
void Write(const TString& rkMessage)
{
if (gpLogFile)
{
@ -25,51 +26,65 @@ void Write(const TString& message)
char Buffer[80];
strftime(Buffer, 80, "[%H:%M:%S]", &pTimeInfo);
fprintf(gpLogFile, "%s %s\n", Buffer, *message);
fprintf(gpLogFile, "%s %s\n", Buffer, *rkMessage);
fflush(gpLogFile);
}
}
void Error(const TString& message)
void Error(const TString& rkMessage)
{
Write("ERROR: " + message);
std::cout << "ERROR: " << message << "\n";
TString FullMessage = "ERROR: " + rkMessage;
Write(FullMessage);
ErrorLog.push_back(FullMessage);
std::cout << FullMessage << "\n";
}
void Warning(const TString& message)
void Warning(const TString& rkMessage)
{
Write("Warning: " + message);
std::cout << "Warning: " << message << "\n";
TString FullMessage = "Warning: " + rkMessage;
Write(FullMessage);
ErrorLog.push_back(FullMessage);
std::cout << FullMessage << "\n";
}
void FileWrite(const TString& filename, const TString& message)
void FileWrite(const TString& rkFilename, const TString& rkMessage)
{
Write(filename + " : " + message);
Write(rkFilename + " : " + rkMessage);
}
void FileWrite(const TString& filename, unsigned long offset, const TString& message)
void FileWrite(const TString& rkFilename, u32 Offset, const TString& rkMessage)
{
Write(filename + " : " + TString::HexString(offset) + " - " + message);
Write(rkFilename + " : " + TString::HexString(Offset) + " - " + rkMessage);
}
void FileError(const TString& filename, const TString& message)
void FileError(const TString& rkFilename, const TString& rkMessage)
{
Error(filename + " : " + message);
Error(rkFilename + " : " + rkMessage);
}
void FileError(const TString& filename, unsigned long offset, const TString& message)
void FileError(const TString& rkFilename, u32 Offset, const TString& rkMessage)
{
Error(filename + " : " + TString::HexString(offset) + " - " + message);
Error(rkFilename + " : " + TString::HexString(Offset) + " - " + rkMessage);
}
void FileWarning(const TString& filename, const TString& message)
void FileWarning(const TString& rkFilename, const TString& rkMessage)
{
Warning(filename + " : " + message);
Warning(rkFilename + " : " + rkMessage);
}
void FileWarning(const TString& filename, unsigned long offset, const TString& message)
void FileWarning(const TString& rkFilename, u32 Offset, const TString& rkMessage)
{
Warning(filename + " : " + TString::HexString(offset) + " - " + message);
Warning(rkFilename + " : " + TString::HexString(Offset) + " - " + rkMessage);
}
const TStringList& GetErrorLog()
{
return ErrorLog;
}
void ClearErrorLog()
{
ErrorLog.clear();
}
}

View File

@ -6,15 +6,17 @@
namespace Log
{
void Write(const TString& message);
void Error(const TString& message);
void Warning(const TString& message);
void FileWrite(const TString& filename, const TString& message);
void FileWrite(const TString& filename, unsigned long offset, const TString& message);
void FileError(const TString& filename, const TString& message);
void FileError(const TString& filename, unsigned long offset, const TString& message);
void FileWarning(const TString& filename, const TString& message);
void FileWarning(const TString& filename, unsigned long offset, const TString& message);
void Write(const TString& rkMessage);
void Error(const TString& rkMessage);
void Warning(const TString& rkMessage);
void FileWrite(const TString& rkFilename, const TString& rkMessage);
void FileWrite(const TString& rkFilename, unsigned long Offset, const TString& rkMessage);
void FileError(const TString& rkFilename, const TString& rkMessage);
void FileError(const TString& rkFilename, unsigned long Offset, const TString& rkMessage);
void FileWarning(const TString& rkFilename, const TString& rkMessage);
void FileWarning(const TString& rkFilename, unsigned long Offset, const TString& rkMessage);
const TStringList& GetErrorLog();
void ClearErrorLog();
}

View File

@ -0,0 +1,51 @@
#include "CErrorLogDialog.h"
#include "ui_CErrorLogDialog.h"
#include "UICommon.h"
#include <Core/Log.h>
CErrorLogDialog::CErrorLogDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::CErrorLogDialog)
{
ui->setupUi(this);
connect(ui->CloseButton, SIGNAL(clicked()), this, SLOT(close()));
}
CErrorLogDialog::~CErrorLogDialog()
{
delete ui;
}
bool CErrorLogDialog::GatherErrors()
{
const TStringList& rkErrors = Log::GetErrorLog();
if (rkErrors.empty()) return false;
QString DialogString;
for (auto it = rkErrors.begin(); it != rkErrors.end(); it++)
{
QString Error = TO_QSTRING(*it);
QString LineColor;
if (Error.startsWith("ERROR: "))
LineColor = "#ff0000";
else if (Error.startsWith("Warning: "))
LineColor = "#ff8000";
QString FullLine = Error;
if (!LineColor.isEmpty())
{
FullLine.prepend(QString("<font color=\"%1\">").arg(LineColor));
FullLine.append("</font>");
}
FullLine.append("<br />");
DialogString += FullLine;
}
ui->ErrorLogTextEdit->setText(DialogString);
Log::ClearErrorLog();
return true;
}

View File

@ -0,0 +1,23 @@
#ifndef CERRORLOGDIALOG_H
#define CERRORLOGDIALOG_H
#include <QDialog>
namespace Ui {
class CErrorLogDialog;
}
class CErrorLogDialog : public QDialog
{
Q_OBJECT
public:
explicit CErrorLogDialog(QWidget *parent = 0);
~CErrorLogDialog();
bool GatherErrors();
private:
Ui::CErrorLogDialog *ui;
};
#endif // CERRORLOGDIALOG_H

View File

@ -0,0 +1,49 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>CErrorLogDialog</class>
<widget class="QDialog" name="CErrorLogDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>662</width>
<height>402</height>
</rect>
</property>
<property name="windowTitle">
<string>Errors</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>The following errors were encountered while loading the area:</string>
</property>
</widget>
</item>
<item>
<widget class="QTextEdit" name="ErrorLogTextEdit">
<property name="readOnly">
<bool>true</bool>
</property>
<property name="html">
<string>&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
p, li { white-space: pre-wrap; }
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'MS Shell Dlg 2'; font-size:8.25pt; font-weight:400; font-style:normal;&quot;&gt;
&lt;p style=&quot;-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="CloseButton">
<property name="text">
<string>Close</string>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>

View File

@ -1,5 +1,6 @@
#include "CStartWindow.h"
#include "ui_CStartWindow.h"
#include "CErrorLogDialog.h"
#include "UICommon.h"
#include "Editor/ModelEditor/CModelEditorWindow.h"
@ -169,6 +170,13 @@ void CStartWindow::on_LaunchWorldEditorButton_clicked()
mpWorldEditor->SetArea(mpWorld, pArea);
mpWorldEditor->setWindowModality(Qt::WindowModal);
mpWorldEditor->showMaximized();
// Display errors
CErrorLogDialog ErrorDialog(mpWorldEditor);
bool HasErrors = ErrorDialog.GatherErrors();
if (HasErrors)
ErrorDialog.exec();
}
gResCache.Clean();

View File

@ -124,7 +124,8 @@ HEADERS += \
CStartWindow.h \
INodeEditor.h \
TestDialog.h \
UICommon.h
UICommon.h \
CErrorLogDialog.h
# Source Files
SOURCES += \
@ -169,7 +170,8 @@ SOURCES += \
INodeEditor.cpp \
main.cpp \
TestDialog.cpp \
UICommon.cpp
UICommon.cpp \
CErrorLogDialog.cpp
# UI Files
FORMS += \
@ -183,4 +185,5 @@ FORMS += \
WorldEditor/CWorldEditor.ui \
WorldEditor/WCreateTab.ui \
WorldEditor/WInstancesTab.ui \
WorldEditor/WModifyTab.ui
WorldEditor/WModifyTab.ui \
CErrorLogDialog.ui