#include "GuiProgressView.h"
#include "GuiApplication.h"
+#include "GuiProgress.h"
#include "qt_helpers.h"
#include "FuncRequest.h"
#include "support/convert.h"
#include "support/debug.h"
+#include <algorithm>
+
#include <QCheckBox>
#include <QDebug>
#include <QSettings>
}
+namespace{
+typedef pair<int, QString> DebugMap;
+typedef vector<DebugMap> DebugVector;
+
+bool DebugSorter(DebugMap const & a, DebugMap const & b)
+{
+ return a.second < b.second;
+}
+}
+
+
GuiProgressView::GuiProgressView(GuiView & parent, Qt::DockWidgetArea area,
Qt::WindowFlags flags)
: DockView(parent, "progress", qt_("Progress/Debug Messages"), area, flags)
{
- widget_ = new ProgressViewWidget();
+ eol_last_ = true;
+ widget_ = new ProgressViewWidget;
widget_->setMinimumHeight(150);
widget_->debugMessagesTW->setSizePolicy(QSizePolicy::Ignored,
QSizePolicy::Expanding);
widget_->adjustSize();
setWidget(widget_);
- QFont font(guiApp->typewriterFontName());
- font.setKerning(false);
- font.setFixedPitch(true);
- font.setStyleHint(QFont::TypeWriter);
- widget_->outTE->setFont(font);
+ widget_->outTE->setFont(guiApp->typewriterSystemFont());
widget_->tabWidget->widget(0)->setContentsMargins(-5, -7, 0, -7);
connect(widget_->debugNoneRB, SIGNAL(clicked()),
// ignore Debug::NONE and Debug::ANY
int const level_count = Debug::levelCount() - 1;
- QTreeWidgetItem * item = 0;
+ DebugVector dmap;
+ for (int i = 1 ; i < level_count; i++) {
+ Debug::Type const level = Debug::value(i);
+ QString const desc =
+ toqstr(from_ascii(Debug::name(level) + " - "))
+ + qt_(Debug::description(level));
+ dmap.push_back(DebugMap(level, desc));
+ }
+ sort(dmap.begin(), dmap.end(), DebugSorter);
+
widget_->debugMessagesTW->setColumnCount(2);
widget_->debugMessagesTW->headerItem()->setText(0, qt_("Debug Level"));
widget_->debugMessagesTW->headerItem()->setText(1, qt_("Set"));
- for (int i = 1 ; i < level_count; i++) {
- item = new QTreeWidgetItem(widget_->debugMessagesTW);
- Debug::Type const level = Debug::value(i);
- item->setText(0, qt_(Debug::description(level)));
- item->setData(0, Qt::UserRole, int(level));
+
+ DebugVector::const_iterator dit = dmap.begin();
+ DebugVector::const_iterator const den = dmap.end();
+ for (; dit != den; ++dit) {
+ QTreeWidgetItem * item = new QTreeWidgetItem(widget_->debugMessagesTW);
+ item->setText(0, dit->second);
+ item->setData(0, Qt::UserRole, int(dit->first));
item->setText(1, qt_("No"));
}
widget_->debugMessagesTW->resizeColumnToContents(0);
connect(progress, SIGNAL(appendMessage(QString const &)),
this, SLOT(appendText(QString const &)));
connect(progress, SIGNAL(appendLyXErrMessage(QString const &)),
- this, SLOT(appendLyXErrText(QString const &)));
+ this, SLOT(appendLyXErrText(QString const &)), Qt::QueuedConnection);
connect(progress, SIGNAL(appendError(QString const &)),
this, SLOT(appendText(QString const &)));
connect(progress, SIGNAL(clearMessages()), this, SLOT(clearText()));
void GuiProgressView::levelChanged()
{
- int level = Debug::NONE;
+ unsigned int level = Debug::NONE;
QTreeWidgetItemIterator it(widget_->debugMessagesTW);
while (*it) {
if ((*it)->text(1) == qt_("Yes"))
void GuiProgressView::debugSelectionChanged()
{
- int level = Debug::NONE;
+ unsigned int level = Debug::NONE;
if (widget_->debugAnyRB->isChecked())
level = Debug::ANY;
else if (widget_->debugSelectedRB->isChecked()) {
void GuiProgressView::clearText()
{
- if (widget_->autoClearCB->isChecked())
+ if (widget_->autoClearCB->isChecked()){
widget_->outTE->clear();
+ eol_last_ = true;
+ }
}
void GuiProgressView::appendLyXErrText(QString const & text)
{
+ // Skip verbose messages meant for the terminal
+ if (text.startsWith("\nRunning:"))
+ return;
+
widget_->outTE->moveCursor(QTextCursor::End);
widget_->outTE->insertPlainText(text);
widget_->outTE->ensureCursorVisible();
-
+ eol_last_ = false;
// Give the user a chance to disable debug messages because
// showing Debug::ANY messages completely blocks the GUI.
// Text is not always send as the whole line, so we must be
// careful about eolns.
// WARNING: processing events could cause crashes!
// TODO: find a better solution
- if (text.endsWith("\n"))
+ if (text.endsWith("\n")) {
+ eol_last_ = true;
QApplication::processEvents();
+ }
}
return;
QString str = GuiProgress::currentTime();
str += ": " + text;
- if (!text.endsWith("\n"))
- str += "\n";
+ if (!eol_last_)
+ str = "\n" + str;
+ eol_last_ = text.endsWith("\n");
widget_->outTE->moveCursor(QTextCursor::End);
widget_->outTE->insertPlainText(str);
Dialog * createGuiProgressView(GuiView & guiview)
{
-#ifdef Q_WS_MACX
- return new GuiProgressView(guiview, Qt::RightDockWidgetArea, Qt::Drawer);
-#else
return new GuiProgressView(guiview, Qt::BottomDockWidgetArea);
-#endif
}