logview improvments and fixes
This commit is contained in:
@@ -118,11 +118,25 @@
|
|||||||
</message>
|
</message>
|
||||||
<message>
|
<message>
|
||||||
<location filename="../logview.ui" line="119"/>
|
<location filename="../logview.ui" line="119"/>
|
||||||
|
<location filename="../logview.cpp" line="37"/>
|
||||||
|
<location filename="../logview.cpp" line="133"/>
|
||||||
<source>Clear</source>
|
<source>Clear</source>
|
||||||
<translation type="unfinished"></translation>
|
<translation type="unfinished"></translation>
|
||||||
</message>
|
</message>
|
||||||
<message>
|
<message>
|
||||||
<location filename="../logview.cpp" line="38"/>
|
<location filename="../logview.cpp" line="35"/>
|
||||||
|
<location filename="../logview.cpp" line="131"/>
|
||||||
|
<source>Select All</source>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
|
<message>
|
||||||
|
<location filename="../logview.cpp" line="36"/>
|
||||||
|
<location filename="../logview.cpp" line="132"/>
|
||||||
|
<source>Copy</source>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
|
<message>
|
||||||
|
<location filename="../logview.cpp" line="46"/>
|
||||||
<source>All</source>
|
<source>All</source>
|
||||||
<translation type="unfinished"></translation>
|
<translation type="unfinished"></translation>
|
||||||
</message>
|
</message>
|
||||||
|
|||||||
@@ -118,11 +118,25 @@
|
|||||||
</message>
|
</message>
|
||||||
<message>
|
<message>
|
||||||
<location filename="../logview.ui" line="119"/>
|
<location filename="../logview.ui" line="119"/>
|
||||||
|
<location filename="../logview.cpp" line="37"/>
|
||||||
|
<location filename="../logview.cpp" line="133"/>
|
||||||
<source>Clear</source>
|
<source>Clear</source>
|
||||||
<translation>Очистить</translation>
|
<translation>Очистить</translation>
|
||||||
</message>
|
</message>
|
||||||
<message>
|
<message>
|
||||||
<location filename="../logview.cpp" line="38"/>
|
<location filename="../logview.cpp" line="35"/>
|
||||||
|
<location filename="../logview.cpp" line="131"/>
|
||||||
|
<source>Select All</source>
|
||||||
|
<translation>Выделить всё</translation>
|
||||||
|
</message>
|
||||||
|
<message>
|
||||||
|
<location filename="../logview.cpp" line="36"/>
|
||||||
|
<location filename="../logview.cpp" line="132"/>
|
||||||
|
<source>Copy</source>
|
||||||
|
<translation>Копировать</translation>
|
||||||
|
</message>
|
||||||
|
<message>
|
||||||
|
<location filename="../logview.cpp" line="46"/>
|
||||||
<source>All</source>
|
<source>All</source>
|
||||||
<translation>Все</translation>
|
<translation>Все</translation>
|
||||||
</message>
|
</message>
|
||||||
|
|||||||
@@ -28,11 +28,19 @@ void LogView::Category::makeIcon(QSize size, QSize size_icon) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
LogView::LogView(QWidget * parent): QWidget(parent) {
|
LogView::LogView(QWidget * parent): QWidget(parent) {
|
||||||
ui = new Ui::LogView();
|
ui = new Ui::LogView();
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
ui->textEdit->setContextMenuPolicy(Qt::ActionsContextMenu);
|
||||||
|
actionLogSelectAll = new QAction(QIcon(":/icons/select-all.png"), tr("Select All"));
|
||||||
|
actionLogCopy = new QAction(QIcon(":/icons/edit-copy.png"), tr("Copy"));
|
||||||
|
actionLogClear = new QAction(QIcon(":/icons/edit-clear.png"), tr("Clear"));
|
||||||
|
connect(actionLogSelectAll, SIGNAL(triggered(bool)), ui->textEdit, SLOT(selectAll()));
|
||||||
|
connect(actionLogCopy, SIGNAL(triggered(bool)), ui->textEdit, SLOT(copy()));
|
||||||
|
connect(actionLogClear, SIGNAL(triggered(bool)), ui->textEdit, SLOT(clear()));
|
||||||
|
ui->textEdit->addAction(actionLogSelectAll);
|
||||||
|
ui->textEdit->addAction(actionLogCopy);
|
||||||
|
ui->textEdit->addAction(actionLogClear);
|
||||||
ui->buttonClear->setDefaultAction(ui->actionClear);
|
ui->buttonClear->setDefaultAction(ui->actionClear);
|
||||||
ui->labelIconSearch->setFixedSize(preferredIconSize(1.2, this));
|
ui->labelIconSearch->setFixedSize(preferredIconSize(1.2, this));
|
||||||
ui->comboCategory->addItem(tr("All"));
|
ui->comboCategory->addItem(tr("All"));
|
||||||
@@ -66,7 +74,7 @@ QFont LogView::logFont() const {
|
|||||||
|
|
||||||
|
|
||||||
bool LogView::isFilterVisible() const {
|
bool LogView::isFilterVisible() const {
|
||||||
return !ui->widgetToolbar->isHidden();
|
return ui->widgetToolbar->isVisible();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -76,43 +84,64 @@ int LogView::linesLimit() const {
|
|||||||
|
|
||||||
|
|
||||||
void LogView::registerCategory(const QString & label, QString keyword, const QImage & icon, QColor color, bool bold) {
|
void LogView::registerCategory(const QString & label, QString keyword, const QImage & icon, QColor color, bool bold) {
|
||||||
if (keyword.isEmpty()) keyword = label;
|
QRegularExpression regexp(keyword, QRegularExpression::PatternOptions(QRegularExpression::CaseInsensitiveOption));
|
||||||
if (keyword.isEmpty()) return;
|
registerCategory(label, regexp, icon, color, bold);
|
||||||
Category & c(categories[keyword]);
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void LogView::registerCategory(const QString & label, QRegularExpression regexp, const QImage & icon, QColor color, bool bold) {
|
||||||
|
if (!regexp.isValid()) return;
|
||||||
|
Category c;
|
||||||
|
c.regexp = regexp;
|
||||||
|
categories.removeAll(c);
|
||||||
c.label = label;
|
c.label = label;
|
||||||
c.keyword = keyword;
|
|
||||||
c.image = icon;
|
c.image = icon;
|
||||||
c.color = color;
|
c.color = color;
|
||||||
c.bold = bold;
|
c.bold = bold;
|
||||||
c.makeIcon(iconImageSize(), preferredIconSize(1., this));
|
c.makeIcon(iconImageSize(), preferredIconSize(1., this));
|
||||||
ui->comboCategory->addItem(c.icon, label, keyword);
|
categories.append(c);
|
||||||
|
ui->comboCategory->addItem(c.icon, label, regexp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void LogView::addText(const QString & text, bool insert_newline) {
|
void LogView::addText(const QString & text, bool insert_newline) {
|
||||||
|
if (text.isEmpty()) return;
|
||||||
QTextCursor tc(ui->textEdit->document());
|
QTextCursor tc(ui->textEdit->document());
|
||||||
QStringList sl = text.split("\n");
|
QStringList sl = text.split("\n");
|
||||||
tc.movePosition(QTextCursor::End);
|
tc.movePosition(QTextCursor::End);
|
||||||
QScrollBar * bar = ui->textEdit->verticalScrollBar();
|
QScrollBar * bar = ui->textEdit->verticalScrollBar();
|
||||||
bool at_end = (bar->value() == bar->maximum());
|
bool at_end = (bar->value() == bar->maximum());
|
||||||
for (int i = 0; i < sl.size(); ++i) {
|
for (int i = 0; i < sl.size(); ++i) {
|
||||||
|
if (sl[i].isEmpty()) return;
|
||||||
tc.insertText(sl[i]);
|
tc.insertText(sl[i]);
|
||||||
if ((i < sl.size() - 1) || insert_newline)
|
if ((i < sl.size() - 1) || insert_newline)
|
||||||
newLine();
|
newLine();
|
||||||
}
|
}
|
||||||
if (at_end)
|
if (at_end)
|
||||||
bar->setValue(bar->maximum());
|
bar->setValue(bar->maximum());
|
||||||
filter();
|
if (ui->widgetToolbar->isVisible())
|
||||||
|
filter();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void LogView::changeEvent(QEvent * e) {
|
void LogView::changeEvent(QEvent * e) {
|
||||||
if (e->type() == QEvent::Polish) {
|
QWidget::changeEvent(e);
|
||||||
ui->labelIconSearch->setFixedSize(preferredIconSize(1.2, this));
|
switch (e->type()) {
|
||||||
QSize is = iconImageSize(), is_i = preferredIconSize(1., this);
|
case QEvent::LanguageChange:
|
||||||
QMutableMapIterator<QString, Category> it(categories);
|
ui->retranslateUi(this);
|
||||||
while (it.hasNext())
|
actionLogSelectAll->setText(tr("Select All"));
|
||||||
it.next().value().makeIcon(is, is_i);
|
actionLogCopy->setText(tr("Copy"));
|
||||||
|
actionLogClear->setText(tr("Clear"));
|
||||||
|
break;
|
||||||
|
case QEvent::Polish: {
|
||||||
|
ui->labelIconSearch->setFixedSize(preferredIconSize(1.2, this));
|
||||||
|
QSize is = iconImageSize(), is_i = preferredIconSize(1., this);
|
||||||
|
QMutableListIterator<Category> it(categories);
|
||||||
|
while (it.hasNext())
|
||||||
|
it.next().makeIcon(is, is_i);
|
||||||
|
} break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -123,16 +152,16 @@ void LogView::newLine() {
|
|||||||
tc.movePosition(QTextCursor::StartOfBlock, QTextCursor::KeepAnchor);
|
tc.movePosition(QTextCursor::StartOfBlock, QTextCursor::KeepAnchor);
|
||||||
QString line = tc.selectedText();
|
QString line = tc.selectedText();
|
||||||
QImage icon;
|
QImage icon;
|
||||||
QMapIterator<QString, Category> it(categories);
|
QListIterator<Category> it(categories);
|
||||||
while (it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
it.next();
|
const Category & c(it.next());
|
||||||
if (line.contains(it.key(), Qt::CaseInsensitive)) {
|
if (line.contains(c.regexp)) {
|
||||||
QTextCharFormat cf = def_cf;
|
QTextCharFormat cf = def_cf;
|
||||||
cf.setForeground(it.value().color);
|
cf.setForeground(c.color);
|
||||||
if (it.value().bold)
|
if (c.bold)
|
||||||
cf.setFontWeight(QFont::Bold);
|
cf.setFontWeight(QFont::Bold);
|
||||||
tc.setCharFormat(cf);
|
tc.setCharFormat(cf);
|
||||||
icon = it.value().icon_image;
|
icon = c.icon_image;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -170,13 +199,14 @@ void LogView::clear() {
|
|||||||
void LogView::filter() {
|
void LogView::filter() {
|
||||||
QTextDocument * doc = ui->textEdit->document();
|
QTextDocument * doc = ui->textEdit->document();
|
||||||
int bc = doc->blockCount();
|
int bc = doc->blockCount();
|
||||||
QString fs[2] = {ui->comboCategory->currentData().toString(), ui->lineEdit->text()};
|
QRegularExpression regexp = ui->comboCategory->currentData().toRegularExpression();
|
||||||
|
QString fs = ui->lineEdit->text();
|
||||||
QTextBlock bl;
|
QTextBlock bl;
|
||||||
for (int i = 0; i < bc; ++i) {
|
for (int i = 0; i < bc; ++i) {
|
||||||
bl = doc->findBlockByNumber(i);
|
bl = doc->findBlockByNumber(i);
|
||||||
bool vis = true;
|
bool vis = true;
|
||||||
if (!fs[0].isEmpty()) vis = vis && bl.text().contains(fs[0], Qt::CaseInsensitive);
|
if (regexp.isValid()) vis = vis && bl.text().contains(regexp);
|
||||||
if (!fs[1].isEmpty()) vis = vis && bl.text().contains(fs[1], Qt::CaseInsensitive);
|
if (!fs.isEmpty()) vis = vis && bl.text().contains(fs[1], Qt::CaseInsensitive);
|
||||||
bl.setVisible(vis);
|
bl.setVisible(vis);
|
||||||
}
|
}
|
||||||
doc->markContentsDirty(0, bl.position() + bl.length());
|
doc->markContentsDirty(0, bl.position() + bl.length());
|
||||||
|
|||||||
@@ -23,11 +23,12 @@
|
|||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
#include <QIcon>
|
#include <QIcon>
|
||||||
#include <QImage>
|
#include <QImage>
|
||||||
#include <QDebug>
|
|
||||||
#include <QTextBlockFormat>
|
#include <QTextBlockFormat>
|
||||||
|
#include <QRegularExpression>
|
||||||
#include "qad_export.h"
|
#include "qad_export.h"
|
||||||
|
|
||||||
class QTextEdit;
|
class QTextEdit;
|
||||||
|
class QAction;
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
class LogView;
|
class LogView;
|
||||||
@@ -56,6 +57,12 @@ public:
|
|||||||
QColor color = QColor(),
|
QColor color = QColor(),
|
||||||
bool bold = false);
|
bool bold = false);
|
||||||
|
|
||||||
|
void registerCategory(const QString & label,
|
||||||
|
QRegularExpression regexp = QRegularExpression(),
|
||||||
|
const QImage & icon = QImage(),
|
||||||
|
QColor color = QColor(),
|
||||||
|
bool bold = false);
|
||||||
|
|
||||||
void addText(const QString & text, bool insert_newline = true);
|
void addText(const QString & text, bool insert_newline = true);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@@ -63,11 +70,12 @@ private:
|
|||||||
Category();
|
Category();
|
||||||
void makeIcon(QSize size, QSize size_icon);
|
void makeIcon(QSize size, QSize size_icon);
|
||||||
QString label;
|
QString label;
|
||||||
QString keyword;
|
QRegularExpression regexp;
|
||||||
QImage image, icon_image;
|
QImage image, icon_image;
|
||||||
QIcon icon;
|
QIcon icon;
|
||||||
QColor color;
|
QColor color;
|
||||||
bool bold;
|
bool bold;
|
||||||
|
inline bool operator ==(const Category & it) const {return (regexp.pattern() == it.regexp.pattern());}
|
||||||
};
|
};
|
||||||
|
|
||||||
void changeEvent(QEvent * e);
|
void changeEvent(QEvent * e);
|
||||||
@@ -75,8 +83,9 @@ private:
|
|||||||
QSize iconImageSize();
|
QSize iconImageSize();
|
||||||
|
|
||||||
Ui::LogView * ui;
|
Ui::LogView * ui;
|
||||||
QMap<QString, Category> categories; // by keyword
|
QList<Category> categories;
|
||||||
QTextCharFormat def_cf;
|
QTextCharFormat def_cf;
|
||||||
|
QAction * actionLogSelectAll, * actionLogCopy, * actionLogClear;
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void setFilterVisible(bool yes);
|
void setFilterVisible(bool yes);
|
||||||
|
|||||||
@@ -29,5 +29,7 @@
|
|||||||
<file>../icons/layer-visible-on.png</file>
|
<file>../icons/layer-visible-on.png</file>
|
||||||
<file>../icons/logview.png</file>
|
<file>../icons/logview.png</file>
|
||||||
<file>../icons/qt.png</file>
|
<file>../icons/qt.png</file>
|
||||||
|
<file>../icons/select-all.png</file>
|
||||||
|
<file>../icons/select-none.png</file>
|
||||||
</qresource>
|
</qresource>
|
||||||
</RCC>
|
</RCC>
|
||||||
|
|||||||
BIN
qad/icons/select-all.png
Normal file
BIN
qad/icons/select-all.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 21 KiB |
BIN
qad/icons/select-none.png
Normal file
BIN
qad/icons/select-none.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 36 KiB |
Reference in New Issue
Block a user