diff --git a/doc/src/Howto_lammps_gui.rst b/doc/src/Howto_lammps_gui.rst index 67260519ea..0b5c4f509e 100644 --- a/doc/src/Howto_lammps_gui.rst +++ b/doc/src/Howto_lammps_gui.rst @@ -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 diff --git a/doc/src/JPG/lammps-gui-log.png b/doc/src/JPG/lammps-gui-log.png index 894af371f0..61ab2e0601 100644 Binary files a/doc/src/JPG/lammps-gui-log.png and b/doc/src/JPG/lammps-gui-log.png differ diff --git a/tools/lammps-gui/flagwarnings.cpp b/tools/lammps-gui/flagwarnings.cpp index 8c0a4c4cde..e91547288f 100644 --- a/tools/lammps-gui/flagwarnings.cpp +++ b/tools/lammps-gui/flagwarnings.cpp @@ -17,17 +17,22 @@ #include #include +#include +#include // 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: diff --git a/tools/lammps-gui/flagwarnings.h b/tools/lammps-gui/flagwarnings.h index b34f1eba6a..ad82942d62 100644 --- a/tools/lammps-gui/flagwarnings.h +++ b/tools/lammps-gui/flagwarnings.h @@ -18,11 +18,15 @@ #include #include +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: diff --git a/tools/lammps-gui/icons/warning.png b/tools/lammps-gui/icons/warning.png new file mode 100644 index 0000000000..72dae39766 Binary files /dev/null and b/tools/lammps-gui/icons/warning.png differ diff --git a/tools/lammps-gui/lammps-gui.appdata.xml b/tools/lammps-gui/lammps-gui.appdata.xml index a40f56d3d0..05300f361d 100644 --- a/tools/lammps-gui/lammps-gui.appdata.xml +++ b/tools/lammps-gui/lammps-gui.appdata.xml @@ -58,6 +58,7 @@ Update Tutorial menu entries to cover all 8 tutorials Highlight warnings and error messages in Output window + Make Tutorial wizards more compact diff --git a/tools/lammps-gui/lammpsgui.cpp b/tools/lammps-gui/lammpsgui.cpp index 7b12aa1d0d..701a21505a 100644 --- a/tools/lammps-gui/lammpsgui.cpp +++ b/tools/lammps-gui/lammpsgui.cpp @@ -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()); diff --git a/tools/lammps-gui/lammpsgui.qrc b/tools/lammps-gui/lammpsgui.qrc index 52bcbbb167..3f9697392b 100644 --- a/tools/lammps-gui/lammpsgui.qrc +++ b/tools/lammps-gui/lammpsgui.qrc @@ -73,6 +73,7 @@ icons/utilities-terminal.png icons/vdw-style.png icons/vmd.png + icons/warning.png icons/window-close.png icons/x-office-drawing.png icons/yaml-file-icon.png diff --git a/tools/lammps-gui/logwindow.cpp b/tools/lammps-gui/logwindow.cpp index 85ed1d8744..b4ff36564c 100644 --- a/tools/lammps-gui/logwindow.cpp +++ b/tools/lammps-gui/logwindow.cpp @@ -20,13 +20,18 @@ #include #include #include +#include +#include #include #include +#include #include #include +#include #include #include #include +#include #include #include @@ -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"; diff --git a/tools/lammps-gui/logwindow.h b/tools/lammps-gui/logwindow.h index 84240b6e70..38bca9ba24 100644 --- a/tools/lammps-gui/logwindow.h +++ b/tools/lammps-gui/logwindow.h @@ -17,6 +17,7 @@ #include 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