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 | |
| parent | 9e663691b0ad23faa979361facb416b7ea0fb08d (diff) | |
Allow extended selection in log list and implement copy.
Diffstat (limited to 'src')
| -rw-r--r-- | src/copyeventfilter.cpp | 6 | ||||
| -rw-r--r-- | src/copyeventfilter.h | 2 | ||||
| -rw-r--r-- | src/loglist.cpp | 19 | ||||
| -rw-r--r-- | src/loglist.h | 4 | ||||
| -rw-r--r-- | src/mainwindow.cpp | 8 | ||||
| -rw-r--r-- | src/mainwindow.h | 1 | ||||
| -rw-r--r-- | src/mainwindow.ui | 3 |
7 files changed, 28 insertions, 15 deletions
diff --git a/src/copyeventfilter.cpp b/src/copyeventfilter.cpp index 223561b0..bd61e04d 100644 --- a/src/copyeventfilter.cpp +++ b/src/copyeventfilter.cpp @@ -4,8 +4,8 @@ #include <QGuiApplication> #include <QKeyEvent> -CopyEventFilter::CopyEventFilter(QAbstractItemView* view, int role) : - CopyEventFilter(view, [=](auto& index) { return index.data(role).toString(); }) +CopyEventFilter::CopyEventFilter(QAbstractItemView* view, int column, int role) : + CopyEventFilter(view, [=](auto& index) { return index.sibling(index.row(), column).data(role).toString(); }) { } @@ -27,7 +27,7 @@ void CopyEventFilter::copySelection() const QModelIndexList selectedRows = m_view->selectionModel()->selectedRows(); std::sort(selectedRows.begin(), selectedRows.end(), [=](const auto& lidx, const auto& ridx) { return m_view->visualRect(lidx).top() < m_view->visualRect(ridx).top(); - }); + }); QStringList rows; for (auto& idx : selectedRows) { diff --git a/src/copyeventfilter.h b/src/copyeventfilter.h index a9d0a1c1..141ddae1 100644 --- a/src/copyeventfilter.h +++ b/src/copyeventfilter.h @@ -23,7 +23,7 @@ class CopyEventFilter : public QObject public: - CopyEventFilter(QAbstractItemView* view, int role = Qt::DisplayRole); + CopyEventFilter(QAbstractItemView* view, int column = 0, int role = Qt::DisplayRole); CopyEventFilter(QAbstractItemView* view, std::function<QString(const QModelIndex&)> format); // copy the selection of the view associated with this 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(); });
diff --git a/src/loglist.h b/src/loglist.h index 0745ed3e..d502f193 100644 --- a/src/loglist.h +++ b/src/loglist.h @@ -22,6 +22,7 @@ along with Mod Organizer. If not, see <http://www.gnu.org/licenses/>. #include "shared/appconfig.h"
+#include "copyeventfilter.h"
#include <log.h>
#include <QTreeView>
#include <deque>
@@ -41,6 +42,8 @@ public: const std::deque<MOBase::log::Entry>& entries() const;
+ QString formattedMessage(const QModelIndex& index) const;
+
protected:
QModelIndex index(int row, int column, const QModelIndex& parent) const override;
QModelIndex parent(const QModelIndex &child) const override;
@@ -77,6 +80,7 @@ public: private:
OrganizerCore* m_core;
QTimer m_timer;
+ CopyEventFilter m_copyFilter;
void onContextMenu(const QPoint& pos);
void onNewEntry();
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index ce98772a..f7ff7b04 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -2317,12 +2317,6 @@ void MainWindow::openInstanceFolder() shell::Explore(dataPath); } -void MainWindow::openLogsFolder() -{ - QString logsPath = qApp->property("dataPath").toString() + "/" + QString::fromStdWString(AppConfig::logPath()); - shell::Explore(logsPath); -} - void MainWindow::openInstallFolder() { shell::Explore(qApp->applicationDirPath()); @@ -2400,7 +2394,7 @@ QMenu *MainWindow::openFolderMenu() FolderMenu->addAction(tr("Open MO2 Install folder"), this, SLOT(openInstallFolder())); FolderMenu->addAction(tr("Open MO2 Plugins folder"), this, SLOT(openPluginsFolder())); FolderMenu->addAction(tr("Open MO2 Stylesheets folder"), this, SLOT(openStylesheetsFolder())); - FolderMenu->addAction(tr("Open MO2 Logs folder"), this, SLOT(openLogsFolder())); + FolderMenu->addAction(tr("Open MO2 Logs folder"), [=] { ui->logList->openLogsFolder(); }); return FolderMenu; } diff --git a/src/mainwindow.h b/src/mainwindow.h index 6ead7a77..1f521f38 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -348,7 +348,6 @@ private slots: bool shouldStartTutorial() const; void openInstanceFolder(); - void openLogsFolder(); void openInstallFolder(); void openPluginsFolder(); void openStylesheetsFolder(); diff --git a/src/mainwindow.ui b/src/mainwindow.ui index 14cbdda1..a0900542 100644 --- a/src/mainwindow.ui +++ b/src/mainwindow.ui @@ -1550,6 +1550,9 @@ p, li { white-space: pre-wrap; } <property name="alternatingRowColors"> <bool>true</bool> </property> + <property name="selectionMode"> + <enum>QAbstractItemView::ExtendedSelection</enum> + </property> <property name="rootIsDecorated"> <bool>false</bool> </property> |
