display panel with number or warnings and lines in output window, button for jumping to next warning

This commit is contained in:
Axel Kohlmeyer
2024-12-28 18:44:27 -05:00
parent f50b5d63f3
commit 73eeda3b1d
10 changed files with 82 additions and 7 deletions

View File

@ -281,7 +281,11 @@ This text would normally be seen in the command-line window.
LAMMPS-GUI captures the screen output from LAMMPS as it is generated and
updates the *Output* window regularly during a run. If there are any
warnings or errors in the LAMMPS output, they are highlighted by using
bold text colored in red.
bold text colored in red. There is a small panel at the bottom center
of the *Output* window showing how many warnings and errors were
detected and how many lines the entire output has. By clicking on the
button on the right with the warning symbol, you can jump to the next
line with a warning or error.
By default, the *Output* window is replaced each time a run is started.
The runs are counted and the run number for the current run is displayed

Binary file not shown.

Before

Width:  |  Height:  |  Size: 103 KiB

After

Width:  |  Height:  |  Size: 78 KiB

View File

@ -17,17 +17,22 @@
#include <QColor>
#include <QFont>
#include <QLabel>
#include <QTextDocument>
// workaround for Qt-5.12
#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0)
namespace QColorConstants {
const QColor Red = QColor::fromRgb(0xff, 0x00, 0x00);
const QColor Red = QColor::fromRgb(0xff, 0x00, 0x00);
} // namespace QColorConstants
#endif
FlagWarnings::FlagWarnings(QTextDocument *parent) :
QSyntaxHighlighter(parent), isWarning(QStringLiteral("^(ERROR|WARNING).*$"))
FlagWarnings::FlagWarnings(QLabel *label, QTextDocument *parent) :
QSyntaxHighlighter(parent), isWarning(QStringLiteral("^(ERROR|WARNING).*$")), summary(label),
document(parent)
{
nwarnings = nlines = 0;
formatWarning.setForeground(QColorConstants::Red);
formatWarning.setFontWeight(QFont::Bold);
}
@ -39,6 +44,16 @@ void FlagWarnings::highlightBlock(const QString &text)
auto match = isWarning.match(text);
if (match.hasMatch()) {
++nwarnings;
setFormat(match.capturedStart(0), match.capturedLength(0), formatWarning);
}
if (document && summary) {
summary->setText(
QString("%1 Warnings / Errors - %2 Lines").arg(nwarnings).arg(document->lineCount()));
summary->repaint();
}
}
// Local Variables:
// c-basic-offset: 4
// End:

View File

@ -18,11 +18,15 @@
#include <QSyntaxHighlighter>
#include <QTextCharFormat>
class QLabel;
class QTextDocument;
class FlagWarnings : public QSyntaxHighlighter {
Q_OBJECT
public:
FlagWarnings(QTextDocument *parent = 0);
FlagWarnings(QLabel *label = 0, QTextDocument *parent = 0);
int get_nwarnings() const { return nwarnings; }
protected:
void highlightBlock(const QString &text) override;
@ -30,6 +34,9 @@ protected:
private:
QRegularExpression isWarning;
QTextCharFormat formatWarning;
QLabel *summary;
QTextDocument *document;
int nwarnings, nlines;
};
#endif
// Local Variables:

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 KiB

View File

@ -58,6 +58,7 @@
<description>
Update Tutorial menu entries to cover all 8 tutorials
Highlight warnings and error messages in Output window
Make Tutorial wizards more compact
</description>
</release>
<release version="1.6.11" timestamp="1725080055">

View File

@ -1244,7 +1244,7 @@ void LammpsGui::do_run(bool use_buffer)
logwindow->setCenterOnScroll(true);
logwindow->moveCursor(QTextCursor::End);
logwindow->setWindowTitle(
QString("LAMMPS-GUI - Output - %2 - Run %3").arg(current_file).arg(run_counter));
QString("LAMMPS-GUI - Output - %1 - Run %2").arg(current_file).arg(run_counter));
logwindow->setWindowIcon(QIcon(":/icons/lammps-icon-128x128.png"));
QFont text_font;
text_font.fromString(settings.value("textfont", text_font.toString()).toString());

View File

@ -73,6 +73,7 @@
<file>icons/utilities-terminal.png</file>
<file>icons/vdw-style.png</file>
<file>icons/vmd.png</file>
<file>icons/warning.png</file>
<file>icons/window-close.png</file>
<file>icons/x-office-drawing.png</file>
<file>icons/yaml-file-icon.png</file>

View File

@ -20,13 +20,18 @@
#include <QApplication>
#include <QFile>
#include <QFileDialog>
#include <QGridLayout>
#include <QHBoxLayout>
#include <QIcon>
#include <QKeySequence>
#include <QLabel>
#include <QMenu>
#include <QMessageBox>
#include <QPushButton>
#include <QRegularExpression>
#include <QSettings>
#include <QShortcut>
#include <QSpacerItem>
#include <QString>
#include <QTextStream>
@ -39,7 +44,29 @@ LogWindow::LogWindow(const QString &_filename, QWidget *parent) :
QSettings settings;
resize(settings.value("logx", 500).toInt(), settings.value("logy", 320).toInt());
warnings = new FlagWarnings(document());
summary = new QLabel("0 Warnings / Errors - 0 Lines");
summary->setMargin(1);
auto *frame = new QFrame;
frame->setAutoFillBackground(true);
frame->setFrameStyle(QFrame::Box | QFrame::Plain);
frame->setLineWidth(2);
auto *button = new QPushButton(QIcon(":/icons/warning.png"), "");
button->setToolTip("Jump to next warning");
connect(button, &QPushButton::released, this, &LogWindow::next_warning);
auto *spacer = new QSpacerItem(0, 0, QSizePolicy::Minimum, QSizePolicy::Expanding);
auto *panel = new QHBoxLayout(frame);
auto *grid = new QGridLayout(this);
panel->addWidget(summary);
panel->addWidget(button);
grid->addItem(spacer, 0, 0, 1, 3);
grid->addWidget(frame, 1, 1, 1, 1);
warnings = new FlagWarnings(summary, document());
auto *action = new QShortcut(QKeySequence(Qt::CTRL | Qt::Key_S), this);
connect(action, &QShortcut::activated, this, &LogWindow::save_as);
@ -56,6 +83,7 @@ LogWindow::LogWindow(const QString &_filename, QWidget *parent) :
LogWindow::~LogWindow()
{
delete warnings;
delete summary;
}
void LogWindow::closeEvent(QCloseEvent *event)
@ -84,6 +112,22 @@ void LogWindow::stop_run()
if (main) main->stop_run();
}
void LogWindow::next_warning()
{
auto *doc = document();
auto regex = QRegularExpression(QStringLiteral("^(ERROR|WARNING).*$"));
if (warnings->get_nwarnings() > 0) {
// wrap around search
if (!this->find(regex)) {
this->moveCursor(QTextCursor::Start, QTextCursor::MoveAnchor);
this->find(regex);
}
// move cursor to unselect
this->moveCursor(QTextCursor::NextBlock, QTextCursor::MoveAnchor);
}
}
void LogWindow::save_as()
{
QString defaultname = filename + ".log";

View File

@ -17,6 +17,7 @@
#include <QPlainTextEdit>
class FlagWarnings;
class QLabel;
class LogWindow : public QPlainTextEdit {
Q_OBJECT
@ -30,6 +31,7 @@ private slots:
void quit();
void save_as();
void stop_run();
void next_warning();
protected:
void closeEvent(QCloseEvent *event) override;
@ -41,6 +43,7 @@ private:
QString filename;
static const QString yaml_regex;
FlagWarnings *warnings;
QLabel *summary;
};
#endif