highlight error URLs in logwindow

This commit is contained in:
Axel Kohlmeyer
2025-04-28 10:55:24 -04:00
parent 7151f261a0
commit db3d93210d
3 changed files with 21 additions and 1 deletions

View File

@ -2,6 +2,7 @@ LAMMPS-GUI TODO list:
# Short term goals (v1.x) # Short term goals (v1.x)
- open highlighted errorURL in web browser when clicking on it in the logfile viewer.
- add a "Colors" menu to the image viewer to adjust color settings for the - add a "Colors" menu to the image viewer to adjust color settings for the
current image (unlike the defaults in the perferences) including assigning current image (unlike the defaults in the perferences) including assigning
colors to individual atom types. colors to individual atom types.

View File

@ -28,13 +28,16 @@ const QColor Red = QColor::fromRgb(0xff, 0x00, 0x00);
#endif #endif
FlagWarnings::FlagWarnings(QLabel *label, QTextDocument *parent) : FlagWarnings::FlagWarnings(QLabel *label, QTextDocument *parent) :
QSyntaxHighlighter(parent), isWarning(QStringLiteral("^(ERROR|WARNING).*$")), summary(label), QSyntaxHighlighter(parent), isWarning(QStringLiteral("^(ERROR|WARNING).*$")),
isURL(QStringLiteral("^.*(https://docs.lammps.org/err[0-9]+).*$")), summary(label),
document(parent) document(parent)
{ {
nwarnings = nlines = 0; nwarnings = nlines = 0;
formatWarning.setForeground(QColorConstants::Red); formatWarning.setForeground(QColorConstants::Red);
formatWarning.setFontWeight(QFont::Bold); formatWarning.setFontWeight(QFont::Bold);
formatURL.setForeground(QColorConstants::Blue);
formatURL.setFontWeight(QFont::Bold);
} }
void FlagWarnings::highlightBlock(const QString &text) void FlagWarnings::highlightBlock(const QString &text)
@ -42,11 +45,20 @@ void FlagWarnings::highlightBlock(const QString &text)
// nothing to do for empty lines // nothing to do for empty lines
if (text.isEmpty()) return; if (text.isEmpty()) return;
// highlight errors or warnings
auto match = isWarning.match(text); auto match = isWarning.match(text);
if (match.hasMatch()) { if (match.hasMatch()) {
++nwarnings; ++nwarnings;
setFormat(match.capturedStart(0), match.capturedLength(0), formatWarning); setFormat(match.capturedStart(0), match.capturedLength(0), formatWarning);
} }
// highlight ErrorURL links
match = isURL.match(text);
if (match.hasMatch()) {
setFormat(match.capturedStart(1), match.capturedLength(1), formatURL);
}
// update error summary label
if (document && summary) { if (document && summary) {
summary->setText( summary->setText(
QString("%1 Warnings / Errors - %2 Lines").arg(nwarnings).arg(document->lineCount())); QString("%1 Warnings / Errors - %2 Lines").arg(nwarnings).arg(document->lineCount()));

View File

@ -32,8 +32,15 @@ protected:
void highlightBlock(const QString &text) override; void highlightBlock(const QString &text) override;
private: private:
#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
QRegExp isWarning;
QRegExp isURL;
#else
QRegularExpression isWarning; QRegularExpression isWarning;
QRegularExpression isURL;
#endif
QTextCharFormat formatWarning; QTextCharFormat formatWarning;
QTextCharFormat formatURL;
QLabel *summary; QLabel *summary;
QTextDocument *document; QTextDocument *document;
int nwarnings, nlines; int nwarnings, nlines;