highlight error URLs in logwindow
This commit is contained in:
@ -2,6 +2,7 @@ LAMMPS-GUI TODO list:
|
||||
|
||||
# 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
|
||||
current image (unlike the defaults in the perferences) including assigning
|
||||
colors to individual atom types.
|
||||
|
||||
@ -28,13 +28,16 @@ const QColor Red = QColor::fromRgb(0xff, 0x00, 0x00);
|
||||
#endif
|
||||
|
||||
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)
|
||||
{
|
||||
nwarnings = nlines = 0;
|
||||
|
||||
formatWarning.setForeground(QColorConstants::Red);
|
||||
formatWarning.setFontWeight(QFont::Bold);
|
||||
formatURL.setForeground(QColorConstants::Blue);
|
||||
formatURL.setFontWeight(QFont::Bold);
|
||||
}
|
||||
|
||||
void FlagWarnings::highlightBlock(const QString &text)
|
||||
@ -42,11 +45,20 @@ void FlagWarnings::highlightBlock(const QString &text)
|
||||
// nothing to do for empty lines
|
||||
if (text.isEmpty()) return;
|
||||
|
||||
// highlight errors or warnings
|
||||
auto match = isWarning.match(text);
|
||||
if (match.hasMatch()) {
|
||||
++nwarnings;
|
||||
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) {
|
||||
summary->setText(
|
||||
QString("%1 Warnings / Errors - %2 Lines").arg(nwarnings).arg(document->lineCount()));
|
||||
|
||||
@ -32,8 +32,15 @@ protected:
|
||||
void highlightBlock(const QString &text) override;
|
||||
|
||||
private:
|
||||
#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
|
||||
QRegExp isWarning;
|
||||
QRegExp isURL;
|
||||
#else
|
||||
QRegularExpression isWarning;
|
||||
QRegularExpression isURL;
|
||||
#endif
|
||||
QTextCharFormat formatWarning;
|
||||
QTextCharFormat formatURL;
|
||||
QLabel *summary;
|
||||
QTextDocument *document;
|
||||
int nwarnings, nlines;
|
||||
|
||||
Reference in New Issue
Block a user