From 12efe108db4fa722c480bee7cb8f65e8303c6901 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Peter=20K=C3=BCmmel?= Date: Tue, 29 Dec 2009 15:05:37 +0000 Subject: [PATCH] Add Pavel's lyxerr extension, add ui for debug levels. Still needs some fiddling with line endings. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@32670 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/frontends/qt4/GuiProgress.cpp | 32 ++- src/frontends/qt4/GuiProgress.h | 9 +- src/frontends/qt4/GuiProgressView.cpp | 55 ++++- src/frontends/qt4/GuiProgressView.h | 12 ++ src/frontends/qt4/ui/ProgressViewUi.ui | 266 ++++++++++++------------- src/support/ProgressInterface.h | 6 +- src/support/Systemcall.cpp | 4 + src/support/debug.cpp | 76 +++++-- src/support/debug.h | 25 ++- 9 files changed, 328 insertions(+), 157 deletions(-) diff --git a/src/frontends/qt4/GuiProgress.cpp b/src/frontends/qt4/GuiProgress.cpp index 03f624e514..ba678f78b6 100644 --- a/src/frontends/qt4/GuiProgress.cpp +++ b/src/frontends/qt4/GuiProgress.cpp @@ -5,6 +5,7 @@ * Licence details can be found in the file COPYING. * * \author Peter Kümmel + * \author Pavel Sanda * * Full author contact details are available in file CREDITS. */ @@ -47,6 +48,7 @@ GuiProgress::GuiProgress(GuiView * view) : view_(view) connect(this, SIGNAL(appendMessage(QString const &)), SLOT(doAppendMessage(QString const &))); connect(this, SIGNAL(appendError(QString const &)), SLOT(doAppendError(QString const &))); connect(this, SIGNAL(clearMessages()), SLOT(doClearMessages())); + connect(this, SIGNAL(lyxerrFlush()), SLOT(dolyxerrFlush())); // Alert interface connect(this, SIGNAL(warning(QString const &, QString const &)), @@ -78,14 +80,13 @@ void GuiProgress::doProcessFinished(QString const & cmd) void GuiProgress::doAppendMessage(QString const & msg) { - appendText(msg); + appendText(msg + "\n"); } void GuiProgress::doAppendError(QString const & msg) { - QString time = QTime::currentTime().toString(); - appendText(time + " : " + msg); + appendText(msg); } @@ -95,6 +96,31 @@ void GuiProgress::doClearMessages() } +void GuiProgress::dolyxerrFlush() +{ + appendError(toqstr(lyxerr_stream_.str())); + lyxerr_stream_.str(""); +} + + +void GuiProgress::lyxerrConnect() +{ + lyxerr.setSecond(&lyxerr_stream_); +} + + +void GuiProgress::lyxerrDisconnect() +{ + lyxerr.setSecond(0); +} + + +GuiProgress::~GuiProgress() +{ + lyxerrDisconnect(); +} + + void GuiProgress::appendText(QString const & text) { if (!text.isEmpty()) diff --git a/src/frontends/qt4/GuiProgress.h b/src/frontends/qt4/GuiProgress.h index a47eb74986..23f47f7bcd 100644 --- a/src/frontends/qt4/GuiProgress.h +++ b/src/frontends/qt4/GuiProgress.h @@ -5,6 +5,7 @@ * Licence details can be found in the file COPYING. * * \author Peter Kümmel + * \author Pavel Sanda * * Full author contact details are available in file CREDITS. */ @@ -20,7 +21,7 @@ #include #include -#include +#include namespace lyx { @@ -35,7 +36,10 @@ class GuiProgress : public: GuiProgress(GuiView * view); + ~GuiProgress(); + void lyxerrConnect(); + void lyxerrDisconnect(); Q_SIGNALS: void processStarted(QString const &); @@ -43,6 +47,7 @@ Q_SIGNALS: void appendMessage(QString const &); void appendError(QString const &); void clearMessages(); + void lyxerrFlush(); // Alert interface void warning(QString const & title, QString const & message); @@ -56,6 +61,7 @@ private Q_SLOTS: void doAppendMessage(QString const &); void doAppendError(QString const &); void doClearMessages(); + void dolyxerrFlush(); void doWarning(QString const &, QString const &); @@ -67,6 +73,7 @@ private Q_SLOTS: private: GuiView* view_; void appendText(QString const &); + std::ostringstream lyxerr_stream_; }; diff --git a/src/frontends/qt4/GuiProgressView.cpp b/src/frontends/qt4/GuiProgressView.cpp index 5554bb952c..d1d1de3391 100644 --- a/src/frontends/qt4/GuiProgressView.cpp +++ b/src/frontends/qt4/GuiProgressView.cpp @@ -5,6 +5,7 @@ * Licence details can be found in the file COPYING. * * \author Peter Kümmel + * \author Pavel Sanda * * Full author contact details are available in file CREDITS. */ @@ -20,12 +21,21 @@ #include #include - +#include +#include +#include namespace lyx { namespace frontend { +struct LevelButton : QRadioButton +{ + LevelButton(const QString& name) : QRadioButton(name) {} + Debug::Type level; +}; + + ProgressViewWidget::ProgressViewWidget() { setupUi(this); @@ -51,6 +61,18 @@ GuiProgressView::GuiProgressView(GuiView & parent, Qt::DockWidgetArea area, font.setStyleHint(QFont::TypeWriter); widget_->outTE->setFont(font); + QButtonGroup* button_group = new QButtonGroup(this); + const std::vector levels = Debug::levels(); + for (unsigned int i = 0; i < levels.size(); i++) { + LevelButton * box = new LevelButton(toqstr(Debug::description(levels[i]))); + box->level = levels[i]; + widget_->settingsLayout->addWidget(box); + button_group->addButton(box); + } + connect(button_group, SIGNAL(buttonClicked(QAbstractButton*)), this, SLOT(levelChanged(QAbstractButton*))); + // TODO settings + button_group->buttons().front()->setChecked(true); + GuiProgress* progress = dynamic_cast(support::ProgressInterface::instance()); if (progress) { @@ -59,10 +81,19 @@ GuiProgressView::GuiProgressView(GuiView & parent, Qt::DockWidgetArea area, connect(progress, SIGNAL(appendMessage(QString const &)), this, SLOT(appendText(QString const &))); connect(progress, SIGNAL(appendError(QString const &)), this, SLOT(appendText(QString const &))); connect(progress, SIGNAL(clearMessages()), this, SLOT(clearText())); + progress->lyxerrConnect(); } } +void GuiProgressView::levelChanged(QAbstractButton* b) +{ + LevelButton* lb = dynamic_cast(b); + if (lb) + lyxerr.level(lb->level); +} + + void GuiProgressView::clearText() { if (widget_->autoClearCB->isChecked()) @@ -75,10 +106,15 @@ void GuiProgressView::appendText(QString const & text) if (text.isEmpty()) return; QString time = QTime::currentTime().toString(); - widget_->outTE->insertPlainText(time + ": " + text.trimmed() + "\n"); + if (text.endsWith("\n")) + widget_->outTE->insertPlainText(time + ": " + text); + else + widget_->outTE->insertPlainText(text); + widget_->outTE->ensureCursorVisible(); } + void GuiProgressView::saveSession() const { Dialog::saveSession(); @@ -87,6 +123,7 @@ void GuiProgressView::saveSession() const sessionKey() + "/autoclear", widget_->autoClearCB->isChecked()); } + void GuiProgressView::restoreSession() { DockView::restoreSession(); @@ -96,6 +133,20 @@ void GuiProgressView::restoreSession() } +void GuiProgressView::showEvent(QShowEvent*) +{ + support::ProgressInterface::instance()->lyxerrConnect(); +} + + +void GuiProgressView::hideEvent(QHideEvent*) +{ + support::ProgressInterface::instance()->lyxerrDisconnect(); +} + + + + Dialog * createGuiProgressView(GuiView & guiview) { #ifdef Q_WS_MACX diff --git a/src/frontends/qt4/GuiProgressView.h b/src/frontends/qt4/GuiProgressView.h index 9a22b71307..944eb06249 100644 --- a/src/frontends/qt4/GuiProgressView.h +++ b/src/frontends/qt4/GuiProgressView.h @@ -5,6 +5,7 @@ * Licence details can be found in the file COPYING. * * \author Peter Kümmel + * \author Pavel Sanda * * Full author contact details are available in file CREDITS. */ @@ -20,9 +21,15 @@ #include +class QAbstractButton; +class QHideEvent; +class QShowEvent; + + namespace lyx { namespace frontend { + class ProgressViewWidget : public QWidget, public Ui::ProgressViewUi { Q_OBJECT @@ -62,8 +69,13 @@ private Q_SLOTS: void appendText(QString const & text); void clearText(); + void levelChanged(QAbstractButton*); + private: ProgressViewWidget * widget_; + + void showEvent(QShowEvent*); + void hideEvent(QHideEvent*); }; diff --git a/src/frontends/qt4/ui/ProgressViewUi.ui b/src/frontends/qt4/ui/ProgressViewUi.ui index e146d8a5f4..bf29233345 100644 --- a/src/frontends/qt4/ui/ProgressViewUi.ui +++ b/src/frontends/qt4/ui/ProgressViewUi.ui @@ -1,159 +1,157 @@ - + + ProgressViewUi - - + + 0 0 - 826 - 252 + 544 + 518 - + - - - 0 - - - 6 - - - - - 6 + + + + + true - - 0 + + + 0 + 0 + - - - - true - - - - 0 - 0 - - - - - 0 - 0 - - - - false - - - Qt::LeftToRight - - - false - - - QTabWidget::East - - - QTabWidget::Rounded - - - 0 - - - - 16 - 16 - - - - true - - - - Output - - - - - - - 1 - 0 - - - - - 16777215 - 16777215 - - - - QFrame::StyledPanel - - - QFrame::Sunken - - - 1 - - - true - - - - - - - - Settings - - - - - 22 - 10 - 144 - 19 - + + + 0 + 0 + + + + false + + + Qt::LeftToRight + + + false + + + QTabWidget::East + + + QTabWidget::Rounded + + + 1 + + + + 16 + 16 + + + + true + + + + Output + + + + + + + 1 + 0 + - - Automatic cleanup of the window before LaTeX compilation proceeds + + + 16777215 + 16777215 + - - &Automatic clear + + QFrame::StyledPanel - + + QFrame::Sunken + + + 1 + + true - - - false - - - - 16 - 35 - 75 - 24 - - - - &Update + + + + + + Settings + + + + + + true + + + + 0 + 0 + 482 + 474 + + + + + + + + + Automatic cleanup of the window before LaTeX compilation proceeds + + + &Automatic clear + + + true + + + + + + + false + + + &Update + + + + + + + - - - - + + + + - qt_i18n.h + qt_i18n.h diff --git a/src/support/ProgressInterface.h b/src/support/ProgressInterface.h index 6ef073ce58..a9b6d2bc43 100644 --- a/src/support/ProgressInterface.h +++ b/src/support/ProgressInterface.h @@ -23,18 +23,22 @@ class ProgressInterface public: virtual ~ProgressInterface() {} + /// will be Signals in Qt classes virtual void processStarted(QString const &) = 0; virtual void processFinished(QString const &) = 0; virtual void appendMessage(QString const &) = 0; virtual void appendError(QString const &) = 0; virtual void clearMessages() = 0; + virtual void lyxerrFlush() = 0; - // Alert interface + /// Alert interface virtual void warning(QString const & title, QString const & message) = 0; virtual void toggleWarning(QString const & title, QString const & msg, QString const & formatted) = 0; virtual void error(QString const & title, QString const & message) = 0; virtual void information(QString const & title, QString const & message) = 0; + virtual void lyxerrConnect() = 0; + virtual void lyxerrDisconnect() = 0; static void setInstance(ProgressInterface*); static ProgressInterface* instance(); diff --git a/src/support/Systemcall.cpp b/src/support/Systemcall.cpp index 809b88b3f4..98d8d125de 100644 --- a/src/support/Systemcall.cpp +++ b/src/support/Systemcall.cpp @@ -61,6 +61,10 @@ public: void appendMessage(QString const &) {} void appendError(QString const &) {} void clearMessages() {} + void lyxerrFlush() {} + + void lyxerrConnect() {} + void lyxerrDisconnect() {} void warning(QString const &, QString const &) {} void toggleWarning(QString const &, QString const &, QString const &) {} diff --git a/src/support/debug.cpp b/src/support/debug.cpp index 2c88a6f38e..6f3ce34e09 100644 --- a/src/support/debug.cpp +++ b/src/support/debug.cpp @@ -5,6 +5,7 @@ * * \author Lars Gullik Bjønnes * \author Jean-Marc Lasgouttes + * \author Pavel Sanda * * Full author contact details are available in file CREDITS. */ @@ -16,6 +17,7 @@ #include "support/gettext.h" #include "support/lstrings.h" #include "support/FileName.h" +#include "support/ProgressInterface.h" #include #include @@ -77,6 +79,35 @@ int const numErrorTags = sizeof(errorTags)/sizeof(errorTags[0]); } // namespace anon +const std::vector Debug::levels() +{ + std::vector vec; + for (int i = 0 ; i < numErrorTags ; ++i) { + vec.push_back(errorTags[i].level); + } + return vec; +} + +string const Debug::description(Debug::Type val) +{ + for (int i = 0 ; i < numErrorTags ; ++i) { + if (errorTags[i].level == val) + return errorTags[i].desc; + } + return "unknown level"; +} + + +string const Debug::name(Debug::Type val) +{ + for (int i = 0 ; i < numErrorTags ; ++i) { + if (errorTags[i].level == val) + return errorTags[i].name; + } + return "unknown level"; +} + + Debug::Type Debug::value(string const & val) { Type l = Debug::NONE; @@ -152,37 +183,54 @@ bool LyXErr::debugging(Debug::Type t) const void LyXErr::endl() { - if (enabled_) + if (enabled_) { stream() << std::endl; + if (second_used_) + second() << "\n"; + } +} + + +// It seems not possible to instantiate operator template out of class body +#define STREAM_OPERATOR(t) \ +{\ + if (l.enabled()){\ + l.stream() << t;\ + if (l.second_used()){\ + l.second() << t;\ + ProgressInterface::instance()->lyxerrFlush();\ + }\ + }\ + return l;\ } LyXErr & operator<<(LyXErr & l, void const * t) -{ if (l.enabled()) l.stream() << t; return l; } +STREAM_OPERATOR(t) LyXErr & operator<<(LyXErr & l, char const * t) -{ if (l.enabled()) l.stream() << t; return l; } +STREAM_OPERATOR(t) LyXErr & operator<<(LyXErr & l, char t) -{ if (l.enabled()) l.stream() << t; return l; } +STREAM_OPERATOR(t) LyXErr & operator<<(LyXErr & l, int t) -{ if (l.enabled()) l.stream() << t; return l; } +STREAM_OPERATOR(t) LyXErr & operator<<(LyXErr & l, unsigned int t) -{ if (l.enabled()) l.stream() << t; return l; } +STREAM_OPERATOR(t) LyXErr & operator<<(LyXErr & l, long t) -{ if (l.enabled()) l.stream() << t; return l; } +STREAM_OPERATOR(t) LyXErr & operator<<(LyXErr & l, unsigned long t) -{ if (l.enabled()) l.stream() << t; return l; } +STREAM_OPERATOR(t) LyXErr & operator<<(LyXErr & l, double t) -{ if (l.enabled()) l.stream() << t; return l; } +STREAM_OPERATOR(t) LyXErr & operator<<(LyXErr & l, string const & t) -{ if (l.enabled()) l.stream() << t; return l; } +STREAM_OPERATOR(t) LyXErr & operator<<(LyXErr & l, docstring const & t) -{ if (l.enabled()) l.stream() << to_utf8(t); return l; } +STREAM_OPERATOR(to_utf8(t)); LyXErr & operator<<(LyXErr & l, FileName const & t) -{ if (l.enabled()) l.stream() << t; return l; } +STREAM_OPERATOR(t) LyXErr & operator<<(LyXErr & l, ostream &(*t)(ostream &)) -{ if (l.enabled()) l.stream() << t; return l; } +STREAM_OPERATOR(t) LyXErr & operator<<(LyXErr & l, ios_base &(*t)(ios_base &)) -{ if (l.enabled()) l.stream() << t; return l; } +STREAM_OPERATOR(t) // The global instance diff --git a/src/support/debug.h b/src/support/debug.h index e27bf8437e..ecabb506c1 100644 --- a/src/support/debug.h +++ b/src/support/debug.h @@ -11,6 +11,7 @@ * * \author Lars Gullik Bjønnes * \author Jean-Marc Lasgouttes + * \author Pavel Sanda * * Full author contact details are available in file CREDITS. */ @@ -19,7 +20,7 @@ #define LYXDEBUG_H #include "support/strfwd.h" - +#include namespace std { @@ -107,11 +108,20 @@ namespace Debug { ANY = 0xffffffff }; + const std::vector levels(); + /** A function to convert symbolic string names on debug levels to their numerical value. */ Type value(std::string const & val); + /// Return description of level + std::string const description(Type val); + + /// Return name of level + std::string const name(Type val); + + /** Display the tags and descriptions of the current debug level of ds */ @@ -132,7 +142,7 @@ inline void operator|=(Debug::Type & d1, Debug::Type d2) class LyXErr { public: - LyXErr(): enabled_(true) {} + LyXErr(): enabled_(true), second_used_(false) {} /// Disable the stream completely void disable(); /// Enable the stream after a possible call of disable() @@ -153,6 +163,13 @@ public: Debug::Type level() const { return dt; } /// Returns stream operator std::ostream &() { return *stream_; } + /// Returns second_used_ + bool second_used() { return second_used_; } + // Returns second stream + std::ostream & second() { return *second_; }; + /// Sets the second stream + void setSecond(std::ostream * os) { second_used_ = (second_ = os); } + private: /// The current debug level Debug::Type dt; @@ -160,6 +177,10 @@ private: bool enabled_; /// The real stream std::ostream * stream_; + /// Next stream for output duplication + std::ostream * second_; + /// Is the second stream enabled? + bool second_used_; }; namespace support { class FileName; }