Qt: Allow to filter the log multiple times

This commit is contained in:
Megamouse 2022-04-10 22:20:32 +02:00
parent 127ad508b4
commit f24b0c2ffe
2 changed files with 20 additions and 9 deletions

View file

@ -71,6 +71,7 @@ void log_viewer::show_context_menu(const QPoint& pos)
connect(clear, &QAction::triggered, this, [this]()
{
m_log_text->clear();
m_full_log.clear();
});
connect(open, &QAction::triggered, this, [this]()
@ -106,13 +107,14 @@ void log_viewer::show_context_menu(const QPoint& pos)
menu.exec(origin);
}
void log_viewer::show_log() const
void log_viewer::show_log()
{
if (m_path_last.isEmpty())
{
return;
}
m_full_log.clear();
m_log_text->clear();
m_log_text->setPlainText(tr("Loading file..."));
QApplication::processEvents();
@ -137,18 +139,26 @@ void log_viewer::filter_log()
{
if (m_filter_term.isEmpty())
{
if (!m_full_log.isEmpty())
{
m_log_text->setPlainText(m_full_log);
}
return;
}
if (m_full_log.isEmpty())
{
m_full_log = m_log_text->toPlainText();
if (m_full_log.isEmpty())
{
return;
}
}
QString result;
QString text = m_log_text->toPlainText();
if (text.isEmpty())
{
return;
}
QTextStream stream(&text);
QTextStream stream(&m_full_log);
for (QString line = stream.readLine(); !line.isNull(); line = stream.readLine())
{
if (line.contains(m_filter_term))

View file

@ -15,7 +15,7 @@ class log_viewer : public QWidget
public:
explicit log_viewer(std::shared_ptr<gui_settings> gui_settings);
void show_log() const;
void show_log();
private Q_SLOTS:
void show_context_menu(const QPoint& pos);
@ -27,6 +27,7 @@ private:
std::shared_ptr<gui_settings> m_gui_settings;
QString m_path_last;
QString m_filter_term;
QString m_full_log;
QPlainTextEdit* m_log_text;
LogHighlighter* m_log_highlighter;
std::unique_ptr<find_dialog> m_find_dialog;