[enable report view on warnings/erros] add reportoutputobserver class, manage report view visibility via QDocketWidget toggleViewAction() rather than directly with show(), remove unnecessary variables
This commit is contained in:
@@ -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;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -29,6 +29,8 @@
|
||||
# include <QContextMenuEvent>
|
||||
# include <QTextCursor>
|
||||
# include <QTextStream>
|
||||
# include <QDockWidget>
|
||||
# include <QPointer>
|
||||
#endif
|
||||
|
||||
#include <Base/Interpreter.h>
|
||||
@@ -150,8 +152,6 @@ void ReportHighlighter::highlightBlock (const QString & text)
|
||||
ud->block.append(b);
|
||||
|
||||
QVector<TextBlockData::State> block = ud->block;
|
||||
bool hasErrors = false;
|
||||
bool hasWarnings = false;
|
||||
int start = 0;
|
||||
for (QVector<TextBlockData::State>::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<QWidget*>(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
|
||||
<QDockWidget*>(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()
|
||||
{
|
||||
|
||||
@@ -27,6 +27,8 @@
|
||||
#include <QTextEdit>
|
||||
#include <QSyntaxHighlighter>
|
||||
#include <Base/Console.h>
|
||||
#include <QPointer>
|
||||
#include <QDockWidget>
|
||||
#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 <QDockWidget> reportViewParent;
|
||||
};
|
||||
|
||||
} // namespace DockWnd
|
||||
} // namespace Gui
|
||||
|
||||
|
||||
Reference in New Issue
Block a user