mirror of
https://github.com/qbittorrent/qBittorrent
synced 2025-07-30 03:28:41 -07:00
Add ability to filter log messages by type.
This commit is contained in:
parent
b0c324ace8
commit
73832a5ed8
10 changed files with 194 additions and 46 deletions
|
@ -37,9 +37,10 @@
|
|||
#include "loglistwidget.h"
|
||||
#include "guiiconprovider.h"
|
||||
|
||||
LogListWidget::LogListWidget(int max_lines, QWidget *parent) :
|
||||
QListWidget(parent),
|
||||
m_maxLines(max_lines)
|
||||
LogListWidget::LogListWidget(int maxLines, const Log::MsgTypes &types, QWidget *parent)
|
||||
: QListWidget(parent)
|
||||
, m_maxLines(maxLines)
|
||||
, m_types(types)
|
||||
{
|
||||
// Allow multiple selections
|
||||
setSelectionMode(QAbstractItemView::ExtendedSelection);
|
||||
|
@ -53,6 +54,18 @@ LogListWidget::LogListWidget(int max_lines, QWidget *parent) :
|
|||
setContextMenuPolicy(Qt::ActionsContextMenu);
|
||||
}
|
||||
|
||||
void LogListWidget::showMsgTypes(const Log::MsgTypes &types)
|
||||
{
|
||||
m_types = types;
|
||||
for (int i = 0; i < count(); ++i) {
|
||||
QListWidgetItem *tempItem = item(i);
|
||||
if (!tempItem) continue;
|
||||
|
||||
Log::MsgType itemType = static_cast<Log::MsgType>(tempItem->data(Qt::UserRole).toInt());
|
||||
setRowHidden(i, !(m_types & itemType));
|
||||
}
|
||||
}
|
||||
|
||||
void LogListWidget::keyPressEvent(QKeyEvent *event)
|
||||
{
|
||||
if (event->matches(QKeySequence::Copy))
|
||||
|
@ -61,15 +74,18 @@ void LogListWidget::keyPressEvent(QKeyEvent *event)
|
|||
selectAll();
|
||||
}
|
||||
|
||||
void LogListWidget::appendLine(const QString &line)
|
||||
void LogListWidget::appendLine(const QString &line, const Log::MsgType &type)
|
||||
{
|
||||
QListWidgetItem *item = new QListWidgetItem;
|
||||
// We need to use QLabel here to support rich text
|
||||
QLabel *lbl = new QLabel(line);
|
||||
lbl->setContentsMargins(4, 2, 4, 2);
|
||||
item->setSizeHint(lbl->sizeHint());
|
||||
item->setData(Qt::UserRole, type);
|
||||
insertItem(0, item);
|
||||
setItemWidget(item, lbl);
|
||||
setRowHidden(0, !(m_types & type));
|
||||
|
||||
const int nbLines = count();
|
||||
// Limit log size
|
||||
if (nbLines > m_maxLines)
|
||||
|
@ -78,11 +94,10 @@ void LogListWidget::appendLine(const QString &line)
|
|||
|
||||
void LogListWidget::copySelection()
|
||||
{
|
||||
static QRegExp html_tag("<[^>]+>");
|
||||
QList<QListWidgetItem*> items = selectedItems();
|
||||
static QRegExp htmlTag("<[^>]+>");
|
||||
QStringList strings;
|
||||
foreach (QListWidgetItem* it, items)
|
||||
strings << static_cast<QLabel*>(itemWidget(it))->text().replace(html_tag, "");
|
||||
foreach (QListWidgetItem* it, selectedItems())
|
||||
strings << static_cast<QLabel*>(itemWidget(it))->text().replace(htmlTag, "");
|
||||
|
||||
QApplication::clipboard()->setText(strings.join("\n"));
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue