From f32e74c2a78ae2fea6c1f825900287202778bf59 Mon Sep 17 00:00:00 2001 From: Mikaƫl Capelle Date: Tue, 12 Jan 2021 20:34:02 +0100 Subject: Allow extended selection in log list and implement copy. --- src/loglist.cpp | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'src/loglist.cpp') diff --git a/src/loglist.cpp b/src/loglist.cpp index 8df21111..7f8f05bd 100644 --- a/src/loglist.cpp +++ b/src/loglist.cpp @@ -19,6 +19,7 @@ along with Mod Organizer. If not, see . #include "loglist.h" #include "organizercore.h" +#include "copyeventfilter.h" using namespace MOBase; @@ -45,6 +46,14 @@ void LogModel::add(MOBase::log::Entry e) this, [this, e]{ onEntryAdded(std::move(e)); }, Qt::QueuedConnection); } +QString LogModel::formattedMessage(const QModelIndex& index) const +{ + if (!index.isValid()) { + return ""; + } + return QString::fromStdString(m_entries[index.row()].formattedMessage); +} + void LogModel::clear() { beginResetModel(); @@ -160,7 +169,9 @@ QVariant LogModel::headerData(int, Qt::Orientation, int) const LogList::LogList(QWidget* parent) - : QTreeView(parent), m_core(nullptr) + : QTreeView(parent), + m_core(nullptr), + m_copyFilter(this, [=](auto&& index) { return LogModel::instance().formattedMessage(index); }) { setModel(&LogModel::instance()); @@ -180,6 +191,8 @@ LogList::LogList(QWidget* parent) m_timer.setSingleShot(true); connect(&m_timer, &QTimer::timeout, [&]{ scrollToBottom(); }); + + installEventFilter(&m_copyFilter); } void LogList::onNewEntry() @@ -196,8 +209,7 @@ void LogList::copyToClipboard() { std::string s; - auto* m = static_cast(model()); - for (const auto& e : m->entries()) { + for (const auto& e : LogModel::instance().entries()) { s += e.formattedMessage + "\n"; } @@ -224,6 +236,7 @@ QMenu* LogList::createMenu(QWidget* parent) { auto* menu = new QMenu(parent); + menu->addAction(tr("Copy"), [&]{ m_copyFilter.copySelection(); }); menu->addAction(tr("&Copy all"), [&]{ copyToClipboard(); }); menu->addSeparator(); menu->addAction(tr("C&lear all"), [&]{ clear(); }); -- cgit v1.3.1