diff --git a/src/Base/Console.h b/src/Base/Console.h index 6e698fe690..93c8148767 100644 --- a/src/Base/Console.h +++ b/src/Base/Console.h @@ -458,7 +458,7 @@ class BaseExport ConsoleObserver { public: ConsoleObserver() - :bErr(true),bMsg(true),bLog(true),bWrn(true),bShow(true) {} + :bErr(true),bMsg(true),bLog(true),bWrn(true){} virtual ~ConsoleObserver() {} /// get calls when a Warning is issued virtual void Warning(const char *){} @@ -470,7 +470,7 @@ public: virtual void Log (const char *){} virtual const char *Name(void){return 0L;} - bool bErr,bMsg,bLog,bWrn,bShow; + bool bErr,bMsg,bLog,bWrn; }; diff --git a/src/Gui/MainWindow.cpp b/src/Gui/MainWindow.cpp index 2ecc6d539a..fd46be7e44 100644 --- a/src/Gui/MainWindow.cpp +++ b/src/Gui/MainWindow.cpp @@ -400,6 +400,8 @@ MainWindow::MainWindow(QWidget * parent, Qt::WindowFlags f) pcReport->setObjectName (QString::fromLatin1(QT_TRANSLATE_NOOP("QDockWidget","Report view"))); pDockMgr->registerDockWindow("Std_ReportView", pcReport); + ReportOutputObserver* rvObserver = new ReportOutputObserver((QDockWidget*)pcReport->parent()); + qApp->installEventFilter(rvObserver); } // Python console diff --git a/src/Gui/ReportView.cpp b/src/Gui/ReportView.cpp index 4e0490d4b6..504f6e2496 100644 --- a/src/Gui/ReportView.cpp +++ b/src/Gui/ReportView.cpp @@ -29,6 +29,8 @@ # include # include # include +# include +# include #endif #include @@ -150,8 +152,6 @@ void ReportHighlighter::highlightBlock (const QString & text) ud->block.append(b); QVector block = ud->block; - bool hasErrors = false; - bool hasWarnings = false; int start = 0; for (QVector::Iterator it = block.begin(); it != block.end(); ++it) { switch (it->type) @@ -161,11 +161,9 @@ void ReportHighlighter::highlightBlock (const QString & text) break; case Warning: setFormat(start, it->length-start, warnCol); - hasWarnings = true; break; case Error: setFormat(start, it->length-start, errCol); - hasErrors = true; break; case LogText: setFormat(start, it->length-start, logCol); @@ -176,21 +174,6 @@ void ReportHighlighter::highlightBlock (const QString & text) start = it->length; } - if(hasErrors || hasWarnings){ - //activate report view unless this is disabled in preferences - - ParameterGrp::handle group = App::GetApplication().GetUserParameter(). - GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("OutputWindow"); - bool showReportViewOnWarningOrError = group->GetBool("checkShowReportViewOnWarningOrError", true); - if (showReportViewOnWarningOrError){ - QWidget* reportView = Gui::getMainWindow()->findChild(QString::fromLatin1("Report view")); - if (reportView){ - if (!reportView->isVisible()){ - reportView->show(); - } - } - } - } } void ReportHighlighter::setParagraphType(ReportHighlighter::Paragraph t) @@ -247,6 +230,48 @@ private: // ---------------------------------------------------------- +/** + * The ReportOutputObserver class is used to check if messages sent to the + * report view are warnings or errors, and if so and if the user has not + * disabled this in preferences, the report view is toggled on so the + * user always gets the warnings/errors + */ + +ReportOutputObserver::ReportOutputObserver(QDockWidget *parent) +{ + this->reportViewParent = parent; +} + +ReportOutputObserver::~ReportOutputObserver(){ + +} + +bool ReportOutputObserver::eventFilter(QObject *obj, QEvent *event){ + if (event->type() == QEvent::User) { + CustomReportEvent* cr = (CustomReportEvent*) event; + QDockWidget* rv = this->reportViewParent->findChild + (QString::fromLatin1(QT_TRANSLATE_NOOP("QDockWidget","Report view"))); + if(cr && rv){ + ReportHighlighter::Paragraph msgType = cr->messageType(); + if (msgType == ReportHighlighter::Error || msgType == ReportHighlighter::Warning){ + ParameterGrp::handle group = App::GetApplication().GetUserParameter(). + GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("OutputWindow"); + if(group->GetBool("checkShowReportViewOnWarningOrError", true)){ + if(!rv->toggleViewAction()->isChecked()){ + rv->toggleViewAction()->activate(QAction::Trigger); + } + } + } + } + return false; //true would prevent the messages reaching the report view + } else { + // standard event processing + return QObject::eventFilter(obj, event); + } +} + +// ---------------------------------------------------------- + class ReportOutput::Data { public: @@ -492,8 +517,8 @@ void ReportOutput::onToggleError() } void ReportOutput::onToggleShowReportViewOnWarningOrError(){ - bShow = bShow ? false : true; - getWindowParameter()->SetBool("checkShowReportViewOnWarningOrError", bShow); + bool show = getWindowParameter()->GetBool("checkShowReportViewOnWarningOrError", true); + getWindowParameter()->SetBool("checkShowReportViewOnWarningOrError", !show); } void ReportOutput::onToggleWarning() { diff --git a/src/Gui/ReportView.h b/src/Gui/ReportView.h index 9aaeede88d..f9718f87b2 100644 --- a/src/Gui/ReportView.h +++ b/src/Gui/ReportView.h @@ -27,6 +27,8 @@ #include #include #include +#include +#include #include "DockWindow.h" #include "Window.h" @@ -38,6 +40,7 @@ namespace DockWnd { class ReportOutput; class ReportHighlighter; +class ReportOutputObserver; /** Report view containing an output window and a very simple Python console. * @see ReportOutput @@ -188,6 +191,23 @@ private: ParameterGrp::handle _prefs; }; +/** + * Observer to enable report view on warnings / errors if not already + * enabled. + */ + +class ReportOutputObserver : public QObject +{ + Q_OBJECT + +public: + ReportOutputObserver (QDockWidget* parent = 0); + ~ReportOutputObserver(); + bool eventFilter(QObject *obj, QEvent *event); +protected: + QPointer reportViewParent; +}; + } // namespace DockWnd } // namespace Gui