Refactor and rename ConsoleObserver...

...Renamed to "ILogger", to designate that this is an Interface for a
Logger. This "Interface" is pure virtual, so that it cannot be
instantiated directly. This makes it clear that it is intended to be
derived.

Finally, got rid of all the individual log-style methods and replaced
with SendLog. The idea here is that day-to-day users will only interact
with ILogger through ConsoleSingleton (or, likely, LoggerSingleton in
the future). This singleton will manage an arbirtary collection of
ILogger, and call SendLog with the appropriate parameters based on what
the user requests.

Therefore, the singleton itself will have the individual Log, Message,
Error, etc... methods, while stil allowing us to simplify the code base
of ILogger and its derived classes.
This commit is contained in:
ezzieyguywuf
2019-09-10 00:27:36 -04:00
committed by wmayer
parent bf7e50d803
commit f27e4590a6
12 changed files with 392 additions and 417 deletions

View File

@@ -1350,10 +1350,10 @@ void MainWindow::loadWindowSettings()
this->move(pos);
// tmp. disable the report window to suppress some bothering warnings
Base::Console().SetEnabledMsgType("ReportOutput", ConsoleMsgType::MsgType_Wrn, false);
Base::Console().SetEnabledMsgType("ReportOutput", Base::ConsoleSingleton::MsgType_Wrn, false);
this->restoreState(config.value(QString::fromLatin1("MainWindowState")).toByteArray());
std::clog << "Main window restored" << std::endl;
Base::Console().SetEnabledMsgType("ReportOutput", ConsoleMsgType::MsgType_Wrn, true);
Base::Console().SetEnabledMsgType("ReportOutput", Base::ConsoleSingleton::MsgType_Wrn, true);
bool max = config.value(QString::fromLatin1("Maximized"), false).toBool();
max ? showMaximized() : show();
@@ -1969,43 +1969,26 @@ void StatusBarObserver::OnChange(Base::Subject<const char*> &rCaller, const char
}
}
/** Get called when a message is issued.
* The message is displayed on the ststus bar.
*/
void StatusBarObserver::Message(const char * m)
void StatusBarObserver::SendLog(const std::string& msg, Base::LogStyle level)
{
// Send the event to the main window to allow thread-safety. Qt will delete it when done.
CustomMessageEvent* ev = new CustomMessageEvent(MainWindow::Msg, QString::fromUtf8(m));
QApplication::postEvent(getMainWindow(), ev);
}
int messageType = -1;
switch(level){
case Base::LogStyle::Warning:
messageType = MainWindow::Wrn;
break;
case Base::LogStyle::Message:
messageType = MainWindow::Msg;
break;
case Base::LogStyle::Error:
messageType = MainWindow::Err;
break;
case Base::LogStyle::Log:
messageType = MainWindow::Log;
break;
}
/** Get called when a warning is issued.
* The message is displayed on the ststus bar.
*/
void StatusBarObserver::Warning(const char *m)
{
// Send the event to the main window to allow thread-safety. Qt will delete it when done.
CustomMessageEvent* ev = new CustomMessageEvent(MainWindow::Wrn, QString::fromUtf8(m));
QApplication::postEvent(getMainWindow(), ev);
}
/** Get called when an error is issued.
* The message is displayed on the ststus bar.
*/
void StatusBarObserver::Error (const char *m)
{
// Send the event to the main window to allow thread-safety. Qt will delete it when done.
CustomMessageEvent* ev = new CustomMessageEvent(MainWindow::Err, QString::fromUtf8(m));
QApplication::postEvent(getMainWindow(), ev);
}
/** Get called when a log message is issued.
* The message is used to create an Inventor node for debug purposes.
*/
void StatusBarObserver::Log(const char *m)
{
// Send the event to the main window to allow thread-safety. Qt will delete it when done.
CustomMessageEvent* ev = new CustomMessageEvent(MainWindow::Log, QString::fromUtf8(m));
CustomMessageEvent* ev = new CustomMessageEvent(messageType, QString::fromUtf8(msg.c_str()));
QApplication::postEvent(getMainWindow(), ev);
}