code format
This commit is contained in:
@@ -1,15 +1,17 @@
|
||||
#include "logview.h"
|
||||
#include "ui_logview.h"
|
||||
#include "qad_types.h"
|
||||
|
||||
#include "ecombobox.h"
|
||||
#include <QTextDocument>
|
||||
#include "qad_types.h"
|
||||
#include "ui_logview.h"
|
||||
|
||||
#include <QAbstractTextDocumentLayout>
|
||||
#include <QTextEdit>
|
||||
#include <QTextBlock>
|
||||
#include <QScrollBar>
|
||||
#include <QPixmap>
|
||||
#include <QEvent>
|
||||
#include <QPixmap>
|
||||
#include <QScrollBar>
|
||||
#include <QTextBlock>
|
||||
#include <QTextBlockUserData>
|
||||
#include <QTextDocument>
|
||||
#include <QTextEdit>
|
||||
|
||||
|
||||
class TextBlockData: public QTextBlockUserData {
|
||||
@@ -19,8 +21,6 @@ public:
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
LogView::Category::Category() {
|
||||
bold = false;
|
||||
}
|
||||
@@ -104,33 +104,45 @@ int LogView::linesLimit() const {
|
||||
}
|
||||
|
||||
|
||||
void LogView::registerCategory(const QString & label, QString keyword, const QImage & icon, QBrush text_brush, QBrush background, bool bold) {
|
||||
void LogView::registerCategory(const QString & label,
|
||||
QString keyword,
|
||||
const QImage & icon,
|
||||
QBrush text_brush,
|
||||
QBrush background,
|
||||
bool bold) {
|
||||
QRegularExpression regexp(keyword,
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
|
||||
QRegularExpression::PatternOptions(QRegularExpression::CaseInsensitiveOption)
|
||||
QRegularExpression::PatternOptions(QRegularExpression::CaseInsensitiveOption)
|
||||
#else
|
||||
Qt::CaseInsensitive
|
||||
Qt::CaseInsensitive
|
||||
#endif
|
||||
);
|
||||
);
|
||||
registerCategory(label, regexp, icon, text_brush, background, bold);
|
||||
}
|
||||
|
||||
|
||||
void LogView::registerCategory(const QString & label, QRegularExpression regexp, const QImage & icon, QBrush text_brush, QBrush background, bool bold) {
|
||||
void LogView::registerCategory(const QString & label,
|
||||
QRegularExpression regexp,
|
||||
const QImage & icon,
|
||||
QBrush text_brush,
|
||||
QBrush background,
|
||||
bool bold) {
|
||||
if (!regexp.isValid() || regexp.pattern().isEmpty()) return;
|
||||
removeCategory(regexp);
|
||||
Category c;
|
||||
c.regexp = regexp;
|
||||
c.label = label;
|
||||
c.image = icon;
|
||||
c.regexp = regexp;
|
||||
c.label = label;
|
||||
c.image = icon;
|
||||
c.text_brush = text_brush;
|
||||
c.background = background;
|
||||
c.bold = bold;
|
||||
c.makeIcon(iconImageSize(), preferredIconSize(1., this)
|
||||
c.bold = bold;
|
||||
c.makeIcon(iconImageSize(),
|
||||
preferredIconSize(1., this)
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 6, 0)
|
||||
, devicePixelRatioF()
|
||||
,
|
||||
devicePixelRatioF()
|
||||
#endif
|
||||
);
|
||||
);
|
||||
categories.append(c);
|
||||
ui->comboCategory->addItem(c.icon, label, QVariant(regexp));
|
||||
}
|
||||
@@ -139,11 +151,11 @@ void LogView::registerCategory(const QString & label, QRegularExpression regexp,
|
||||
void LogView::removeCategory(QString keyword) {
|
||||
QRegularExpression regexp(keyword,
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
|
||||
QRegularExpression::PatternOptions(QRegularExpression::CaseInsensitiveOption)
|
||||
QRegularExpression::PatternOptions(QRegularExpression::CaseInsensitiveOption)
|
||||
#else
|
||||
Qt::CaseInsensitive
|
||||
Qt::CaseInsensitive
|
||||
#endif
|
||||
);
|
||||
);
|
||||
removeCategory(regexp);
|
||||
}
|
||||
|
||||
@@ -153,13 +165,14 @@ void LogView::removeCategory(QRegularExpression regexp) {
|
||||
c.regexp = regexp;
|
||||
categories.removeAll(c);
|
||||
for (int i = 1; i < ui->comboCategory->count(); ++i) {
|
||||
if (ui->comboCategory->itemData(i).
|
||||
if (ui->comboCategory->itemData(i)
|
||||
.
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
|
||||
toRegularExpression()
|
||||
toRegularExpression()
|
||||
#else
|
||||
toRegExp()
|
||||
toRegExp()
|
||||
#endif
|
||||
.pattern() == regexp.pattern()) {
|
||||
.pattern() == regexp.pattern()) {
|
||||
ui->comboCategory->removeItem(i);
|
||||
--i;
|
||||
}
|
||||
@@ -188,16 +201,13 @@ void LogView::addText(const QString & text, const QString & keyword, bool insert
|
||||
QStringList sl = text.split("\n");
|
||||
tc.movePosition(QTextCursor::End);
|
||||
QScrollBar * bar = ui->textEdit->verticalScrollBar();
|
||||
bool at_end = (bar->value() == bar->maximum()) || bar->isHidden();
|
||||
bool at_end = (bar->value() == bar->maximum()) || bar->isHidden();
|
||||
for (int i = 0; i < sl.size(); ++i) {
|
||||
tc.insertText(sl[i]);
|
||||
if (!keyword.isEmpty())
|
||||
tc.block().setUserData(new TextBlockData(keyword));
|
||||
if ((i < sl.size() - 1) || insert_newline)
|
||||
newLine(keyword);
|
||||
if (!keyword.isEmpty()) tc.block().setUserData(new TextBlockData(keyword));
|
||||
if ((i < sl.size() - 1) || insert_newline) newLine(keyword);
|
||||
}
|
||||
if (at_end)
|
||||
scrollToBottom();
|
||||
if (at_end) scrollToBottom();
|
||||
}
|
||||
|
||||
|
||||
@@ -215,12 +225,14 @@ void LogView::changeEvent(QEvent * e) {
|
||||
ui->labelIconSearch->setFixedSize(preferredIconSize(1.2, this));
|
||||
QSize is = iconImageSize(), is_i = preferredIconSize(1., this);
|
||||
for (int i = 0; i < categories.size(); ++i)
|
||||
categories[i].makeIcon(is, is_i
|
||||
categories[i].makeIcon(is,
|
||||
is_i
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 6, 0)
|
||||
, devicePixelRatioF()
|
||||
,
|
||||
devicePixelRatioF()
|
||||
#endif
|
||||
);
|
||||
} break;
|
||||
);
|
||||
} break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
@@ -232,19 +244,18 @@ void LogView::newLine(const QString & keyword) {
|
||||
tc.movePosition(QTextCursor::StartOfBlock, QTextCursor::KeepAnchor);
|
||||
QString line = tc.selectedText();
|
||||
QImage icon;
|
||||
foreach (const Category & c, categories) {
|
||||
foreach(const Category & c, categories) {
|
||||
bool matched = false;
|
||||
if (keyword.isEmpty()) matched = line.contains(c.regexp);
|
||||
else matched = (keyword == c.regexp.pattern());
|
||||
if (keyword.isEmpty())
|
||||
matched = line.contains(c.regexp);
|
||||
else
|
||||
matched = (keyword == c.regexp.pattern());
|
||||
if (matched) {
|
||||
QTextCharFormat cf = def_cf;
|
||||
QTextCharFormat cf = def_cf;
|
||||
QTextBlockFormat bf = def_bf;
|
||||
if (c.text_brush != Qt::NoBrush)
|
||||
cf.setForeground(c.text_brush);
|
||||
if (c.background != Qt::NoBrush)
|
||||
bf.setBackground(c.background);
|
||||
if (c.bold)
|
||||
cf.setFontWeight(QFont::Bold);
|
||||
if (c.text_brush != Qt::NoBrush) cf.setForeground(c.text_brush);
|
||||
if (c.background != Qt::NoBrush) bf.setBackground(c.background);
|
||||
if (c.bold) cf.setFontWeight(QFont::Bold);
|
||||
tc.setCharFormat(cf);
|
||||
tc.setBlockFormat(bf);
|
||||
icon = c.icon_image;
|
||||
@@ -257,13 +268,12 @@ void LogView::newLine(const QString & keyword) {
|
||||
}
|
||||
QRegularExpression regexp =
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
|
||||
ui->comboCategory->currentData().toRegularExpression();
|
||||
ui->comboCategory->currentData().toRegularExpression();
|
||||
#else
|
||||
ui->comboCategory->itemData(ui->comboCategory->currentIndex()).toRegExp();
|
||||
ui->comboCategory->itemData(ui->comboCategory->currentIndex()).toRegExp();
|
||||
#endif
|
||||
QString fs = ui->lineEdit->text();
|
||||
if (isFilterVisible())
|
||||
filterBlock(tc.block(), fs, regexp);
|
||||
if (isFilterVisible()) filterBlock(tc.block(), fs, regexp);
|
||||
tc.movePosition(QTextCursor::End);
|
||||
tc.setCharFormat(def_cf);
|
||||
tc.insertBlock();
|
||||
@@ -278,15 +288,14 @@ QSize LogView::iconImageSize() {
|
||||
|
||||
|
||||
void LogView::filterBlock(QTextBlock block, const QString & fs, const QRegularExpression & regexp) {
|
||||
bool vis = true;//, pvis = block.isVisible();
|
||||
bool vis = true; //, pvis = block.isVisible();
|
||||
QString line = block.text();
|
||||
if (!line.isEmpty()) {
|
||||
if (line[0] == QChar::ObjectReplacementCharacter)
|
||||
line.remove(0, 1);
|
||||
if (line[0] == QChar::ObjectReplacementCharacter) line.remove(0, 1);
|
||||
}
|
||||
if (regexp.isValid() && !regexp.pattern().isEmpty()) {
|
||||
QString kw;
|
||||
TextBlockData * bd = (TextBlockData*)block.userData();
|
||||
TextBlockData * bd = (TextBlockData *)block.userData();
|
||||
if (bd) kw = bd->keyword;
|
||||
if (!kw.isEmpty())
|
||||
vis = vis && (bd->keyword == regexp.pattern());
|
||||
@@ -295,8 +304,8 @@ void LogView::filterBlock(QTextBlock block, const QString & fs, const QRegularEx
|
||||
}
|
||||
if (!fs.isEmpty()) vis = vis && line.contains(fs, Qt::CaseInsensitive);
|
||||
block.setVisible(vis);
|
||||
//qDebug() << "filterBlock" << line << vis;
|
||||
//if (vis != pvis)
|
||||
// qDebug() << "filterBlock" << line << vis;
|
||||
// if (vis != pvis)
|
||||
// ;//ui->textEdit->document()->mar
|
||||
}
|
||||
|
||||
@@ -325,16 +334,16 @@ void LogView::scrollToBottom() {
|
||||
|
||||
void LogView::filter() {
|
||||
QTextDocument * doc = ui->textEdit->document();
|
||||
int bc = doc->blockCount();
|
||||
int bc = doc->blockCount();
|
||||
QRegularExpression regexp;
|
||||
QString fs;
|
||||
if (isFilterVisible()) {
|
||||
regexp =
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
|
||||
ui->comboCategory->currentData().toRegularExpression();
|
||||
#else
|
||||
ui->comboCategory->itemData(ui->comboCategory->currentIndex()).toRegExp();
|
||||
#endif
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
|
||||
ui->comboCategory->currentData().toRegularExpression();
|
||||
#else
|
||||
ui->comboCategory->itemData(ui->comboCategory->currentIndex()).toRegExp();
|
||||
#endif
|
||||
fs = ui->lineEdit->text();
|
||||
}
|
||||
QTextBlock bl;
|
||||
|
||||
Reference in New Issue
Block a user