Gui: implement temporary blocker for console observer
This commit is contained in:
@@ -70,6 +70,44 @@ private:
|
||||
void Log (const char *sErr);
|
||||
};
|
||||
|
||||
/** The ILoggerBlocker class
|
||||
* This class allows to temporary block then automatically restore arbitrary message types
|
||||
* on a particular console observer.
|
||||
*/
|
||||
class BaseExport ILoggerBlocker
|
||||
{
|
||||
public:
|
||||
// Constructor that will block message types passed as parameter. By default, all types are blocked.
|
||||
inline explicit ILoggerBlocker(const char* co, ConsoleMsgFlags msgTypes =
|
||||
ConsoleSingleton::MsgType_Txt | ConsoleSingleton::MsgType_Log | ConsoleSingleton::MsgType_Wrn | ConsoleSingleton::MsgType_Err);
|
||||
// Disable copy & move constructors
|
||||
ILoggerBlocker(ILoggerBlocker const&) = delete;
|
||||
ILoggerBlocker(ILoggerBlocker const &&) = delete;
|
||||
// Disable assignment & move-assignment operator
|
||||
ILoggerBlocker& operator=(ILoggerBlocker const&) = delete;
|
||||
ILoggerBlocker& operator=(ILoggerBlocker const&&) = delete;
|
||||
// Destructor that will restore message type settings.
|
||||
inline ~ILoggerBlocker();
|
||||
private:
|
||||
ConsoleMsgFlags msgTypesBlocked = 0; // Stores message types blocked by the blocker
|
||||
const char* conObs; // Stores console observer name that blocker acts on
|
||||
};
|
||||
|
||||
ILoggerBlocker::ILoggerBlocker(const char* co, ConsoleMsgFlags msgTypes):
|
||||
conObs(co)
|
||||
{
|
||||
msgTypesBlocked = Console().SetEnabledMsgType(conObs, msgTypes, false);
|
||||
}
|
||||
|
||||
ILoggerBlocker::~ILoggerBlocker()
|
||||
{
|
||||
auto debug = Console().SetEnabledMsgType(conObs, msgTypesBlocked, true);
|
||||
#ifdef FC_DEBUG
|
||||
if (debug != msgTypesBlocked)
|
||||
Console().Warning("Enabled message types have been changed while ILoggerBlocker was set\n");
|
||||
#endif
|
||||
}
|
||||
|
||||
class BaseExport RedirectStdOutput : public std::streambuf
|
||||
{
|
||||
public:
|
||||
|
||||
@@ -42,6 +42,7 @@
|
||||
|
||||
#include <App/Application.h>
|
||||
#include <Base/Console.h>
|
||||
#include <Base/ConsoleObserver.h>
|
||||
|
||||
#include "BitmapFactory.h"
|
||||
|
||||
@@ -337,11 +338,12 @@ QPixmap BitmapFactoryInst::pixmapFromSvg(const QByteArray& originalContents, con
|
||||
image.fill(0x00000000);
|
||||
|
||||
QPainter p(&image);
|
||||
// tmp. disable the report window to suppress some bothering warnings
|
||||
auto tmp = Base::Console().IsMsgTypeEnabled("ReportOutput", Base::ConsoleSingleton::MsgType_Wrn);
|
||||
Base::Console().SetEnabledMsgType("ReportOutput", Base::ConsoleSingleton::MsgType_Wrn, false);
|
||||
QSvgRenderer svg(contents);
|
||||
Base::Console().SetEnabledMsgType("ReportOutput", Base::ConsoleSingleton::MsgType_Wrn, tmp);
|
||||
QSvgRenderer svg;
|
||||
{
|
||||
// tmp. disable the report window to suppress some bothering warnings
|
||||
const Base::ILoggerBlocker blocker("ReportOutput", Base::ConsoleSingleton::MsgType_Wrn);
|
||||
svg.load(contents);
|
||||
}
|
||||
svg.render(&p);
|
||||
p.end();
|
||||
|
||||
|
||||
@@ -55,6 +55,7 @@
|
||||
#include <App/Document.h>
|
||||
#include <App/DocumentObject.h>
|
||||
#include <App/DocumentObjectGroup.h>
|
||||
#include <Base/ConsoleObserver.h>
|
||||
#include <Base/Parameter.h>
|
||||
#include <Base/Exception.h>
|
||||
#include <Base/FileInfo.h>
|
||||
@@ -1412,14 +1413,12 @@ void MainWindow::loadWindowSettings()
|
||||
pos.setX(qMin(qMax(pos.x(),x1-this->width()+30),x2-30));
|
||||
pos.setY(qMin(qMax(pos.y(),y1-10),y2-10));
|
||||
this->move(pos);
|
||||
|
||||
// tmp. disable the report window to suppress some bothering warnings
|
||||
auto tmp = Base::Console().IsMsgTypeEnabled("ReportOutput", Base::ConsoleSingleton::MsgType_Wrn);
|
||||
Base::Console().SetEnabledMsgType("ReportOutput", Base::ConsoleSingleton::MsgType_Wrn, false);
|
||||
this->restoreState(config.value(QString::fromLatin1("MainWindowState")).toByteArray());
|
||||
{
|
||||
// tmp. disable the report window to suppress some bothering warnings
|
||||
const Base::ILoggerBlocker blocker("ReportOutput", Base::ConsoleSingleton::MsgType_Wrn);
|
||||
this->restoreState(config.value(QString::fromLatin1("MainWindowState")).toByteArray());
|
||||
}
|
||||
std::clog << "Main window restored" << std::endl;
|
||||
Base::Console().SetEnabledMsgType("ReportOutput", Base::ConsoleSingleton::MsgType_Wrn, tmp);
|
||||
|
||||
bool max = config.value(QString::fromLatin1("Maximized"), false).toBool();
|
||||
max ? showMaximized() : show();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user