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
This commit is contained in:
Peter Kümmel 2009-12-29 15:05:37 +00:00
parent 248f47f06a
commit 12efe108db
9 changed files with 328 additions and 157 deletions

View File

@ -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())

View File

@ -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 <QSplashScreen>
#include <QTimer>
#include <string>
#include <sstream>
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_;
};

View File

@ -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 <QSettings>
#include <QTime>
#include <QGroupBox>
#include <QRadioButton>
#include <QButtonGroup>
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<Debug::Type> 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<GuiProgress*>(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<LevelButton*>(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

View File

@ -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 <string>
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*);
};

View File

@ -1,159 +1,157 @@
<ui version="4.0" >
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ProgressViewUi</class>
<widget class="QWidget" name="ProgressViewUi" >
<property name="geometry" >
<widget class="QWidget" name="ProgressViewUi">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>826</width>
<height>252</height>
<width>544</width>
<height>518</height>
</rect>
</property>
<property name="windowTitle" >
<property name="windowTitle">
<string/>
</property>
<layout class="QGridLayout" >
<property name="margin" >
<number>0</number>
</property>
<property name="spacing" >
<number>6</number>
</property>
<item row="1" column="1" >
<layout class="QVBoxLayout" >
<property name="spacing" >
<number>6</number>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QTabWidget" name="tabWidget">
<property name="enabled">
<bool>true</bool>
</property>
<property name="margin" >
<number>0</number>
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Ignored">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<item>
<widget class="QTabWidget" name="tabWidget" >
<property name="enabled" >
<bool>true</bool>
</property>
<property name="sizePolicy" >
<sizepolicy vsizetype="Ignored" hsizetype="Expanding" >
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="baseSize" >
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="acceptDrops" >
<bool>false</bool>
</property>
<property name="layoutDirection" >
<enum>Qt::LeftToRight</enum>
</property>
<property name="autoFillBackground" >
<bool>false</bool>
</property>
<property name="tabPosition" >
<enum>QTabWidget::East</enum>
</property>
<property name="tabShape" >
<enum>QTabWidget::Rounded</enum>
</property>
<property name="currentIndex" >
<number>0</number>
</property>
<property name="iconSize" >
<size>
<width>16</width>
<height>16</height>
</size>
</property>
<property name="usesScrollButtons" >
<bool>true</bool>
</property>
<widget class="QWidget" name="tab" >
<attribute name="title" >
<string>Output</string>
</attribute>
<layout class="QGridLayout" name="gridLayout9" >
<item row="0" column="0" >
<widget class="QTextEdit" name="outTE" >
<property name="sizePolicy" >
<sizepolicy vsizetype="Ignored" hsizetype="Expanding" >
<horstretch>1</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maximumSize" >
<size>
<width>16777215</width>
<height>16777215</height>
</size>
</property>
<property name="frameShape" >
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow" >
<enum>QFrame::Sunken</enum>
</property>
<property name="lineWidth" >
<number>1</number>
</property>
<property name="readOnly" >
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="tab_2" >
<attribute name="title" >
<string>Settings</string>
</attribute>
<widget class="QCheckBox" name="autoClearCB" >
<property name="geometry" >
<rect>
<x>22</x>
<y>10</y>
<width>144</width>
<height>19</height>
</rect>
<property name="baseSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="acceptDrops">
<bool>false</bool>
</property>
<property name="layoutDirection">
<enum>Qt::LeftToRight</enum>
</property>
<property name="autoFillBackground">
<bool>false</bool>
</property>
<property name="tabPosition">
<enum>QTabWidget::East</enum>
</property>
<property name="tabShape">
<enum>QTabWidget::Rounded</enum>
</property>
<property name="currentIndex">
<number>1</number>
</property>
<property name="iconSize">
<size>
<width>16</width>
<height>16</height>
</size>
</property>
<property name="usesScrollButtons">
<bool>true</bool>
</property>
<widget class="QWidget" name="tab">
<attribute name="title">
<string>Output</string>
</attribute>
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0">
<widget class="QTextEdit" name="outTE">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Ignored">
<horstretch>1</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip" >
<string>Automatic cleanup of the window before LaTeX compilation proceeds</string>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>16777215</height>
</size>
</property>
<property name="text" >
<string>&amp;Automatic clear</string>
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="checked" >
<property name="frameShadow">
<enum>QFrame::Sunken</enum>
</property>
<property name="lineWidth">
<number>1</number>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
<widget class="QPushButton" name="updatePB" >
<property name="enabled" >
<bool>false</bool>
</property>
<property name="geometry" >
<rect>
<x>16</x>
<y>35</y>
<width>75</width>
<height>24</height>
</rect>
</property>
<property name="text" >
<string>&amp;Update</string>
</item>
</layout>
</widget>
<widget class="QWidget" name="tab_2">
<attribute name="title">
<string>Settings</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QScrollArea" name="scrollArea">
<property name="widgetResizable">
<bool>true</bool>
</property>
<widget class="QWidget" name="scrollAreaWidgetContents">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>482</width>
<height>474</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_4">
<item>
<layout class="QVBoxLayout" name="settingsLayout">
<item>
<widget class="QCheckBox" name="autoClearCB">
<property name="toolTip">
<string>Automatic cleanup of the window before LaTeX compilation proceeds</string>
</property>
<property name="text">
<string>&amp;Automatic clear</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="updatePB">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>&amp;Update</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</widget>
</widget>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</widget>
</item>
</layout>
</widget>
<includes>
<include location="local" >qt_i18n.h</include>
<include location="local">qt_i18n.h</include>
</includes>
<resources/>
<connections/>

View File

@ -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();

View File

@ -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 &) {}

View File

@ -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 <iostream>
#include <iomanip>
@ -77,6 +79,35 @@ int const numErrorTags = sizeof(errorTags)/sizeof(errorTags[0]);
} // namespace anon
const std::vector<Debug::Type> Debug::levels()
{
std::vector<Debug::Type> 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

View File

@ -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 <vector>
namespace std {
@ -107,11 +108,20 @@ namespace Debug {
ANY = 0xffffffff
};
const std::vector<Type> 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; }