From 6217f910f095adea4b06f370726636b09efea4ed Mon Sep 17 00:00:00 2001
From: isanae <14251494+isanae@users.noreply.github.com>
Date: Tue, 16 Jul 2019 05:42:22 -0400
Subject: renamed logbuffer files to loglist
---
src/loglist.h | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 61 insertions(+)
create mode 100644 src/loglist.h
(limited to 'src/loglist.h')
diff --git a/src/loglist.h b/src/loglist.h
new file mode 100644
index 00000000..1bf8901b
--- /dev/null
+++ b/src/loglist.h
@@ -0,0 +1,61 @@
+/*
+Copyright (C) 2012 Sebastian Herbord. All rights reserved.
+
+This file is part of Mod Organizer.
+
+Mod Organizer is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+Mod Organizer is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with Mod Organizer. If not, see .
+*/
+
+#ifndef LOGBUFFER_H
+#define LOGBUFFER_H
+
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+class LogModel : public QAbstractItemModel
+{
+ Q_OBJECT
+
+public:
+ static void create();
+ static LogModel& instance();
+
+ void add(MOBase::log::Entry e);
+
+protected:
+ QModelIndex index(int row, int column, const QModelIndex& parent) const override;
+ QModelIndex parent(const QModelIndex &child) const override;
+ int rowCount(const QModelIndex &parent) const override;
+ int columnCount(const QModelIndex &parent) const override;
+ QVariant data(const QModelIndex &index, int role) const override;
+
+ QVariant headerData(
+ int section, Qt::Orientation ori, int role=Qt::DisplayRole) const override;
+
+signals:
+ void entryAdded(MOBase::log::Entry e);
+
+private:
+ std::deque m_messages;
+
+ LogModel();
+ void onEntryAdded(MOBase::log::Entry e);
+};
+
+#endif // LOGBUFFER_H
--
cgit v1.3.1
From d1b4dec8ad1635738ada3dfbde5907e7f0df3448 Mon Sep 17 00:00:00 2001
From: isanae <14251494+isanae@users.noreply.github.com>
Date: Tue, 16 Jul 2019 05:58:51 -0400
Subject: moved setup to new LogList class
---
src/loglist.cpp | 61 +++++++++++++++++++++++++++++++++++++++++++++++-------
src/loglist.h | 14 +++++++++++--
src/mainwindow.cpp | 35 ++-----------------------------
src/mainwindow.h | 1 -
src/mainwindow.ui | 10 +++++----
5 files changed, 74 insertions(+), 47 deletions(-)
(limited to 'src/loglist.h')
diff --git a/src/loglist.cpp b/src/loglist.cpp
index cb927272..9e876d37 100644
--- a/src/loglist.cpp
+++ b/src/loglist.cpp
@@ -52,21 +52,26 @@ void LogModel::add(MOBase::log::Entry e)
emit entryAdded(std::move(e));
}
+const std::deque& LogModel::entries() const
+{
+ return m_entries;
+}
+
void LogModel::onEntryAdded(MOBase::log::Entry e)
{
bool full = false;
- if (m_messages.size() > MaxLines) {
- m_messages.pop_front();
+ if (m_entries.size() > MaxLines) {
+ m_entries.pop_front();
full = true;
}
- const int row = static_cast(m_messages.size());
+ const int row = static_cast(m_entries.size());
if (!full) {
beginInsertRows(QModelIndex(), row, row + 1);
}
- m_messages.emplace_back(std::move(e));
+ m_entries.emplace_back(std::move(e));
if (!full) {
endInsertRows();
@@ -92,7 +97,7 @@ int LogModel::rowCount(const QModelIndex& parent) const
if (parent.isValid())
return 0;
else
- return static_cast(m_messages.size());
+ return static_cast(m_entries.size());
}
int LogModel::columnCount(const QModelIndex&) const
@@ -105,11 +110,11 @@ QVariant LogModel::data(const QModelIndex& index, int role) const
using namespace std::chrono;
const auto row = static_cast(index.row());
- if (row >= m_messages.size()) {
+ if (row >= m_entries.size()) {
return {};
}
- const auto& e = m_messages[row];
+ const auto& e = m_entries[row];
if (role == Qt::DisplayRole) {
if (index.column() == 1) {
@@ -153,6 +158,48 @@ QVariant LogModel::headerData(int, Qt::Orientation, int) const
return {};
}
+
+LogList::LogList(QWidget* parent)
+ : QTreeView(parent)
+{
+ setModel(&LogModel::instance());
+
+ const int timestampWidth = QFontMetrics(font()).width("00:00:00.000");
+
+ header()->setMinimumSectionSize(0);
+ header()->resizeSection(0, 20);
+ header()->resizeSection(1, timestampWidth + 8);
+
+ setAutoScroll(true);
+ scrollToBottom();
+
+ connect(
+ model(), SIGNAL(rowsInserted(const QModelIndex &, int, int)),
+ this, SLOT(scrollToBottom()));
+
+ connect(
+ model(), SIGNAL(dataChanged(QModelIndex,QModelIndex)),
+ this, SLOT(scrollToBottom()));
+}
+
+void LogList::copyToClipboard()
+{
+ std::string s;
+
+ auto* m = static_cast(model());
+ for (const auto& e : m->entries()) {
+ s += e.formattedMessage + "\n";
+ }
+
+ if (!s.empty()) {
+ // last newline
+ s.pop_back();
+ }
+
+ QApplication::clipboard()->setText(QString::fromStdString(s));
+}
+
+
void vlog(const char *format, ...)
{
va_list argList;
diff --git a/src/loglist.h b/src/loglist.h
index 1bf8901b..d1f7a2ad 100644
--- a/src/loglist.h
+++ b/src/loglist.h
@@ -37,6 +37,7 @@ public:
static LogModel& instance();
void add(MOBase::log::Entry e);
+ const std::deque& entries() const;
protected:
QModelIndex index(int row, int column, const QModelIndex& parent) const override;
@@ -44,7 +45,7 @@ protected:
int rowCount(const QModelIndex &parent) const override;
int columnCount(const QModelIndex &parent) const override;
QVariant data(const QModelIndex &index, int role) const override;
-
+
QVariant headerData(
int section, Qt::Orientation ori, int role=Qt::DisplayRole) const override;
@@ -52,10 +53,19 @@ signals:
void entryAdded(MOBase::log::Entry e);
private:
- std::deque m_messages;
+ std::deque m_entries;
LogModel();
void onEntryAdded(MOBase::log::Entry e);
};
+
+class LogList : public QTreeView
+{
+public:
+ LogList(QWidget* parent=nullptr);
+
+ void copyToClipboard();
+};
+
#endif // LOGBUFFER_H
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp
index 107f3e09..4e91ef9f 100644
--- a/src/mainwindow.cpp
+++ b/src/mainwindow.cpp
@@ -357,7 +357,7 @@ MainWindow::MainWindow(QSettings &initSettings
m_CategoryFactory.loadCategories();
- setupLogList();
+ ui->logList->addAction(ui->actionCopy_Log_to_Clipboard);
int splitterSize = this->size().height(); // actually total window size, but the splitter doesn't seem to return the true value
ui->topLevelSplitter->setSizes(QList() << splitterSize - 100 << 100);
@@ -586,30 +586,6 @@ MainWindow::MainWindow(QSettings &initSettings
updateModCount();
}
-void MainWindow::setupLogList()
-{
- ui->logList->setModel(&LogModel::instance());
-
- const int timestampWidth =
- QFontMetrics(ui->logList->font()).width("00:00:00.000");
-
- ui->logList->header()->setMinimumSectionSize(0);
- ui->logList->header()->resizeSection(0, 20);
- ui->logList->header()->resizeSection(1, timestampWidth + 8);
-
- ui->logList->setAutoScroll(true);
- ui->logList->scrollToBottom();
- ui->logList->addAction(ui->actionCopy_Log_to_Clipboard);
-
- connect(
- ui->logList->model(), SIGNAL(rowsInserted(const QModelIndex &, int, int)),
- ui->logList, SLOT(scrollToBottom()));
-
- connect(
- ui->logList->model(), SIGNAL(dataChanged(QModelIndex,QModelIndex)),
- ui->logList, SLOT(scrollToBottom()));
-}
-
void MainWindow::resetActionIcons()
{
// this is a bit of a hack
@@ -6837,14 +6813,7 @@ void MainWindow::on_restoreModsButton_clicked()
void MainWindow::on_actionCopy_Log_to_Clipboard_triggered()
{
- QStringList lines;
- QAbstractItemModel *model = ui->logList->model();
- for (int i = 0; i < model->rowCount(); ++i) {
- lines.append(QString("%1 [%2] %3").arg(model->index(i, 0).data().toString())
- .arg(model->index(i, 1).data(Qt::UserRole).toString())
- .arg(model->index(i, 1).data().toString()));
- }
- QApplication::clipboard()->setText(lines.join("\n"));
+ ui->logList->copyToClipboard();
}
void MainWindow::on_categoriesAndBtn_toggled(bool checked)
diff --git a/src/mainwindow.h b/src/mainwindow.h
index 9ca3e5c3..d7dbfd90 100644
--- a/src/mainwindow.h
+++ b/src/mainwindow.h
@@ -636,7 +636,6 @@ private slots:
void resetActionIcons();
void updateModCount();
void updatePluginCount();
- void setupLogList();
private slots: // ui slots
// actions
diff --git a/src/mainwindow.ui b/src/mainwindow.ui
index 5a45b3b4..c694abd4 100644
--- a/src/mainwindow.ui
+++ b/src/mainwindow.ui
@@ -1426,13 +1426,10 @@ p, li { white-space: pre-wrap; }
0
-
-
+
Qt::ActionsContextMenu
-
- QAbstractItemView::ExtendedSelection
-
false
@@ -1807,6 +1804,11 @@ p, li { white-space: pre-wrap; }
QWidget
+
+ LogList
+ QTreeView
+
+
--
cgit v1.3.1
From 3c7712a32dd5079a9543485b6a85d548460faefd Mon Sep 17 00:00:00 2001
From: isanae <14251494+isanae@users.noreply.github.com>
Date: Sat, 20 Jul 2019 05:34:31 -0400
Subject: moved setLogLevel() to OrganizerCore moved context menu to LogList
---
src/loglist.cpp | 61 +++++++++++++++++++++++++++++++++++++++++++--------
src/loglist.h | 16 +++++++++-----
src/mainwindow.cpp | 57 ++---------------------------------------------
src/mainwindow.h | 4 ----
src/mainwindow.ui | 14 ------------
src/organizercore.cpp | 12 ++++++++++
src/organizercore.h | 2 ++
7 files changed, 78 insertions(+), 88 deletions(-)
(limited to 'src/loglist.h')
diff --git a/src/loglist.cpp b/src/loglist.cpp
index c34ac76e..26aea682 100644
--- a/src/loglist.cpp
+++ b/src/loglist.cpp
@@ -18,14 +18,7 @@ along with Mod Organizer. If not, see .
*/
#include "loglist.h"
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
+#include "organizercore.h"
using namespace MOBase;
@@ -158,7 +151,7 @@ QVariant LogModel::headerData(int, Qt::Orientation, int) const
LogList::LogList(QWidget* parent)
- : QTreeView(parent)
+ : QTreeView(parent), m_core(nullptr)
{
setModel(&LogModel::instance());
@@ -171,6 +164,10 @@ LogList::LogList(QWidget* parent)
setAutoScroll(true);
scrollToBottom();
+ connect(
+ this, &QWidget::customContextMenuRequested,
+ [&](auto&& pos){ onContextMenu(pos); });
+
connect(
model(), SIGNAL(rowsInserted(const QModelIndex &, int, int)),
this, SLOT(scrollToBottom()));
@@ -180,6 +177,11 @@ LogList::LogList(QWidget* parent)
this, SLOT(scrollToBottom()));
}
+void LogList::setCore(OrganizerCore& core)
+{
+ m_core = &core;
+}
+
void LogList::copyToClipboard()
{
std::string s;
@@ -196,3 +198,44 @@ void LogList::copyToClipboard()
QApplication::clipboard()->setText(QString::fromStdString(s));
}
+
+QMenu* LogList::createMenu(QWidget* parent)
+{
+ auto* menu = new QMenu(parent);
+
+ menu->addAction(tr("Copy& Log"), [&]{ copyToClipboard(); });
+ menu->addSeparator();
+
+ auto* levels = new QMenu(tr("&Level"));
+ menu->addMenu(levels);
+
+ auto* ag = new QActionGroup(menu);
+
+ auto addAction = [&](auto&& text, auto&& level) {
+ auto* a = new QAction(text, ag);
+
+ a->setCheckable(true);
+ a->setChecked(log::getDefault().level() == level);
+
+ connect(a, &QAction::triggered, [this, level]{
+ if (m_core) {
+ m_core->setLogLevel(level);
+ }
+ });
+
+ levels->addAction(a);
+ };
+
+ addAction(tr("&Debug"), log::Debug);
+ addAction(tr("&Info"), log::Info);
+ addAction(tr("&Warnings"), log::Warning);
+ addAction(tr("&Errors"), log::Error);
+
+ return menu;
+}
+
+void LogList::onContextMenu(const QPoint& pos)
+{
+ auto* menu = createMenu(this);
+ menu->popup(viewport()->mapToGlobal(pos));
+}
diff --git a/src/loglist.h b/src/loglist.h
index d1f7a2ad..ae827ca7 100644
--- a/src/loglist.h
+++ b/src/loglist.h
@@ -20,14 +20,11 @@ along with Mod Organizer. If not, see .
#ifndef LOGBUFFER_H
#define LOGBUFFER_H
-#include
-#include
-#include
-#include
-#include
-#include
+#include
#include
+class OrganizerCore;
+
class LogModel : public QAbstractItemModel
{
Q_OBJECT
@@ -65,7 +62,14 @@ class LogList : public QTreeView
public:
LogList(QWidget* parent=nullptr);
+ void setCore(OrganizerCore& core);
+
void copyToClipboard();
+ QMenu* createMenu(QWidget* parent=nullptr);
+
+private:
+ OrganizerCore* m_core;
+ void onContextMenu(const QPoint& pos);
};
#endif // LOGBUFFER_H
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp
index 8a8a99ef..761e9843 100644
--- a/src/mainwindow.cpp
+++ b/src/mainwindow.cpp
@@ -59,7 +59,6 @@ along with Mod Organizer. If not, see .
#include "installationmanager.h"
#include "lockeddialog.h"
#include "waitingonclosedialog.h"
-#include "loglist.h"
#include "downloadlistsortproxy.h"
#include "motddialog.h"
#include "filedialogmemory.h"
@@ -358,7 +357,7 @@ MainWindow::MainWindow(QSettings &initSettings
m_CategoryFactory.loadCategories();
- setupLogMenu();
+ ui->logList->setCore(m_OrganizerCore);
int splitterSize = this->size().height(); // actually total window size, but the splitter doesn't seem to return the true value
ui->topLevelSplitter->setSizes(QList() << splitterSize - 100 << 100);
@@ -813,36 +812,6 @@ void MainWindow::setupActionMenu(QAction* a)
tb->setPopupMode(QToolButton::InstantPopup);
}
-void MainWindow::setupLogMenu()
-{
- connect(ui->logList, &QWidget::customContextMenuRequested, [&](auto&& pos){
- auto* menu = new QMenu(ui->logList);
-
- menu->addAction(tr("Copy& Log"), [&]{ ui->logList->copyToClipboard(); });
- menu->addSeparator();
-
- auto* levels = new QMenu(tr("&Level"));
- menu->addMenu(levels);
-
- auto* ag = new QActionGroup(menu);
-
- auto addAction = [&](auto&& text, auto&& level) {
- auto* a = new QAction(text, ag);
- a->setCheckable(true);
- a->setChecked(log::getDefault().level() == level);
- connect(a, &QAction::triggered, [this, level]{ setLogLevel(level); });
- levels->addAction(a);
- };
-
- addAction(tr("&Debug"), log::Debug);
- addAction(tr("&Info"), log::Info);
- addAction(tr("&Warnings"), log::Warning);
- addAction(tr("&Errors"), log::Error);
-
- menu->popup(ui->logList->viewport()->mapToGlobal(pos));
- });
-}
-
void MainWindow::updatePinnedExecutables()
{
for (auto* a : ui->toolBar->actions()) {
@@ -1432,11 +1401,6 @@ bool MainWindow::confirmExit()
void MainWindow::cleanup()
{
- if (ui->logList->model() != nullptr) {
- disconnect(ui->logList->model(), nullptr, nullptr, nullptr);
- ui->logList->setModel(nullptr);
- }
-
QWebEngineProfile::defaultProfile()->clearAllVisitedLinks();
m_IntegratedBrowser.close();
m_SaveMetaTimer.stop();
@@ -5317,24 +5281,12 @@ void MainWindow::on_actionSettings_triggered()
m_statusBar->checkSettings(m_OrganizerCore.settings());
updateDownloadView();
- setLogLevel(settings.logLevel());
+ m_OrganizerCore.setLogLevel(settings.logLevel());
m_OrganizerCore.cycleDiagnostics();
toggleMO2EndorseState();
}
-void MainWindow::setLogLevel(log::Levels level)
-{
- auto& s = m_OrganizerCore.settings();
-
- s.setLogLevel(level);
-
- m_OrganizerCore.updateVFSParams(
- s.logLevel(), s.crashDumpsType(), s.executablesBlacklist());
-
- log::getDefault().setLevel(s.logLevel());
-}
-
void MainWindow::on_actionNexus_triggered()
{
const IPluginGame *game = m_OrganizerCore.managedGame();
@@ -6858,11 +6810,6 @@ void MainWindow::on_restoreModsButton_clicked()
}
}
-void MainWindow::on_actionLogCopy_triggered()
-{
- ui->logList->copyToClipboard();
-}
-
void MainWindow::on_categoriesAndBtn_toggled(bool checked)
{
if (checked) {
diff --git a/src/mainwindow.h b/src/mainwindow.h
index 74993667..aa49205d 100644
--- a/src/mainwindow.h
+++ b/src/mainwindow.h
@@ -636,13 +636,10 @@ private slots:
void search_activated();
void searchClear_activated();
- void setupLogMenu();
void resetActionIcons();
void updateModCount();
void updatePluginCount();
- void setLogLevel(MOBase::log::Levels level);
-
private slots: // ui slots
// actions
void on_actionAdd_Profile_triggered();
@@ -696,7 +693,6 @@ private slots: // ui slots
void on_restoreButton_clicked();
void on_restoreModsButton_clicked();
void on_saveModsButton_clicked();
- void on_actionLogCopy_triggered();
void on_categoriesAndBtn_toggled(bool checked);
void on_categoriesOrBtn_toggled(bool checked);
void on_managedArchiveLabel_linkHovered(const QString &link);
diff --git a/src/mainwindow.ui b/src/mainwindow.ui
index fc2bcdd3..6c6d0bca 100644
--- a/src/mainwindow.ui
+++ b/src/mainwindow.ui
@@ -1757,20 +1757,6 @@ p, li { white-space: pre-wrap; }
Log
-
-
- Copy &Log
-
-
- Copy &Log
-
-
- Copy log to clipboard
-
-
- Copy log to clipboard
-
-
diff --git a/src/organizercore.cpp b/src/organizercore.cpp
index 92372d82..1e164525 100644
--- a/src/organizercore.cpp
+++ b/src/organizercore.cpp
@@ -731,6 +731,18 @@ void OrganizerCore::updateVFSParams(
m_USVFS.updateParams(logLevel, crashDumpsType, executableBlacklist);
}
+void OrganizerCore::setLogLevel(log::Levels level)
+{
+ m_Settings.setLogLevel(level);
+
+ updateVFSParams(
+ m_Settings.logLevel(),
+ m_Settings.crashDumpsType(),
+ m_Settings.executablesBlacklist());
+
+ log::getDefault().setLevel(m_Settings.logLevel());
+}
+
bool OrganizerCore::cycleDiagnostics() {
if (int maxDumps = settings().crashDumpsMax())
removeOldFiles(QString::fromStdWString(crashDumpsPath()), "*.dmp", maxDumps, QDir::Time|QDir::Reversed);
diff --git a/src/organizercore.h b/src/organizercore.h
index c368d101..2aa7e707 100644
--- a/src/organizercore.h
+++ b/src/organizercore.h
@@ -196,6 +196,8 @@ public:
MOBase::log::Levels logLevel, int crashDumpsType,
QString executableBlacklist);
+ void setLogLevel(MOBase::log::Levels level);
+
bool cycleDiagnostics();
static CrashDumpsType getGlobalCrashDumpsType() { return m_globalCrashDumpsType; }
--
cgit v1.3.1
From 6f1a8f5b7af3018b38fd40375d46776b2eefe684 Mon Sep 17 00:00:00 2001
From: isanae <14251494+isanae@users.noreply.github.com>
Date: Sat, 20 Jul 2019 05:40:09 -0400
Subject: added clear option to log list
---
src/loglist.cpp | 15 ++++++++++++++-
src/loglist.h | 4 ++++
2 files changed, 18 insertions(+), 1 deletion(-)
(limited to 'src/loglist.h')
diff --git a/src/loglist.cpp b/src/loglist.cpp
index 26aea682..01cbf6ce 100644
--- a/src/loglist.cpp
+++ b/src/loglist.cpp
@@ -45,6 +45,13 @@ void LogModel::add(MOBase::log::Entry e)
emit entryAdded(std::move(e));
}
+void LogModel::clear()
+{
+ beginResetModel();
+ m_entries.clear();
+ endResetModel();
+}
+
const std::deque& LogModel::entries() const
{
return m_entries;
@@ -199,12 +206,18 @@ void LogList::copyToClipboard()
QApplication::clipboard()->setText(QString::fromStdString(s));
}
+void LogList::clear()
+{
+ static_cast(model())->clear();
+}
+
QMenu* LogList::createMenu(QWidget* parent)
{
auto* menu = new QMenu(parent);
- menu->addAction(tr("Copy& Log"), [&]{ copyToClipboard(); });
+ menu->addAction(tr("&Copy"), [&]{ copyToClipboard(); });
menu->addSeparator();
+ menu->addAction(tr("C&lear"), [&]{ clear(); });
auto* levels = new QMenu(tr("&Level"));
menu->addMenu(levels);
diff --git a/src/loglist.h b/src/loglist.h
index ae827ca7..0b25dfd1 100644
--- a/src/loglist.h
+++ b/src/loglist.h
@@ -34,6 +34,8 @@ public:
static LogModel& instance();
void add(MOBase::log::Entry e);
+ void clear();
+
const std::deque& entries() const;
protected:
@@ -65,6 +67,8 @@ public:
void setCore(OrganizerCore& core);
void copyToClipboard();
+ void clear();
+
QMenu* createMenu(QWidget* parent=nullptr);
private:
--
cgit v1.3.1