diff options
| author | Mikaël Capelle <capelle.mikael@gmail.com> | 2021-01-12 20:34:02 +0100 |
|---|---|---|
| committer | Mikaël Capelle <capelle.mikael@gmail.com> | 2021-01-13 09:17:05 +0100 |
| commit | f32e74c2a78ae2fea6c1f825900287202778bf59 (patch) | |
| tree | ce0a1a726859a5a2c4ec1a57549b853217bd6f24 /src/loglist.cpp | |
| parent | 9e663691b0ad23faa979361facb416b7ea0fb08d (diff) | |
Allow extended selection in log list and implement copy.
Diffstat (limited to 'src/loglist.cpp')
| -rw-r--r-- | src/loglist.cpp | 19 |
1 files changed, 16 insertions, 3 deletions
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 <http://www.gnu.org/licenses/>. #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<LogModel*>(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(); });
|
