aboutsummaryrefslogtreecommitdiff
path: root/launcher/launch/LogModel.cpp
diff options
context:
space:
mode:
authorTheKodeToad <TheKodeToad@proton.me>2023-08-16 20:46:16 +0100
committerTheKodeToad <TheKodeToad@proton.me>2023-08-16 22:23:38 +0100
commit3e2733d840d24ce4f46b49bca0b8656d4d6e3d87 (patch)
tree386113207514b8071b0122b318c10439259ca83c /launcher/launch/LogModel.cpp
parent57430fd189aed592a170d597de61b3acabaaa43d (diff)
parentc88088c91a92a371a9bc2b7384c2897157772b7e (diff)
downloadPrismLauncher-3e2733d840d24ce4f46b49bca0b8656d4d6e3d87.tar.gz
PrismLauncher-3e2733d840d24ce4f46b49bca0b8656d4d6e3d87.tar.bz2
PrismLauncher-3e2733d840d24ce4f46b49bca0b8656d4d6e3d87.zip
Merge branch 'develop' into better-launch
Signed-off-by: TheKodeToad <TheKodeToad@proton.me>
Diffstat (limited to 'launcher/launch/LogModel.cpp')
-rw-r--r--launcher/launch/LogModel.cpp56
1 files changed, 20 insertions, 36 deletions
diff --git a/launcher/launch/LogModel.cpp b/launcher/launch/LogModel.cpp
index 92f9487a..23a33ae1 100644
--- a/launcher/launch/LogModel.cpp
+++ b/launcher/launch/LogModel.cpp
@@ -1,11 +1,11 @@
#include "LogModel.h"
-LogModel::LogModel(QObject *parent):QAbstractListModel(parent)
+LogModel::LogModel(QObject* parent) : QAbstractListModel(parent)
{
m_content.resize(m_maxLines);
}
-int LogModel::rowCount(const QModelIndex &parent) const
+int LogModel::rowCount(const QModelIndex& parent) const
{
if (parent.isValid())
return 0;
@@ -13,19 +13,17 @@ int LogModel::rowCount(const QModelIndex &parent) const
return m_numLines;
}
-QVariant LogModel::data(const QModelIndex &index, int role) const
+QVariant LogModel::data(const QModelIndex& index, int role) const
{
if (index.row() < 0 || index.row() >= m_numLines)
return QVariant();
auto row = index.row();
auto realRow = (row + m_firstLine) % m_maxLines;
- if (role == Qt::DisplayRole || role == Qt::EditRole)
- {
+ if (role == Qt::DisplayRole || role == Qt::EditRole) {
return m_content[realRow].line;
}
- if(role == LevelRole)
- {
+ if (role == LevelRole) {
return m_content[realRow].level;
}
@@ -34,31 +32,26 @@ QVariant LogModel::data(const QModelIndex &index, int role) const
void LogModel::append(MessageLevel::Enum level, QString line)
{
- if(m_suspended)
- {
+ if (m_suspended) {
return;
}
int lineNum = (m_firstLine + m_numLines) % m_maxLines;
// overflow
- if(m_numLines == m_maxLines)
- {
- if(m_stopOnOverflow)
- {
+ if (m_numLines == m_maxLines) {
+ if (m_stopOnOverflow) {
// nothing more to do, the buffer is full
return;
}
beginRemoveRows(QModelIndex(), 0, 0);
m_firstLine = (m_firstLine + 1) % m_maxLines;
- m_numLines --;
+ m_numLines--;
endRemoveRows();
- }
- else if (m_numLines == m_maxLines - 1 && m_stopOnOverflow)
- {
+ } else if (m_numLines == m_maxLines - 1 && m_stopOnOverflow) {
level = MessageLevel::Fatal;
line = m_overflowMessage;
}
beginInsertRows(QModelIndex(), m_numLines, m_numLines);
- m_numLines ++;
+ m_numLines++;
m_content[lineNum].level = level;
m_content[lineNum].line = line;
endInsertRows();
@@ -86,9 +79,8 @@ QString LogModel::toPlainText()
{
QString out;
out.reserve(m_numLines * 80);
- for(int i = 0; i < m_numLines; i++)
- {
- QString & line = m_content[(m_firstLine + i) % m_maxLines].line;
+ for (int i = 0; i < m_numLines; i++) {
+ QString& line = m_content[(m_firstLine + i) % m_maxLines].line;
out.append(line + '\n');
}
out.squeeze();
@@ -98,13 +90,11 @@ QString LogModel::toPlainText()
void LogModel::setMaxLines(int maxLines)
{
// no-op
- if(maxLines == m_maxLines)
- {
+ if (maxLines == m_maxLines) {
return;
}
// if it all still fits in the buffer, just resize it
- if(m_firstLine + m_numLines < m_maxLines)
- {
+ if (m_firstLine + m_numLines < m_maxLines) {
m_maxLines = maxLines;
m_content.resize(maxLines);
return;
@@ -112,22 +102,17 @@ void LogModel::setMaxLines(int maxLines)
// otherwise, we need to reorganize the data because it crosses the wrap boundary
QVector<entry> newContent;
newContent.resize(maxLines);
- if(m_numLines <= maxLines)
- {
+ if (m_numLines <= maxLines) {
// if it all fits in the new buffer, just copy it over
- for(int i = 0; i < m_numLines; i++)
- {
+ for (int i = 0; i < m_numLines; i++) {
newContent[i] = m_content[(m_firstLine + i) % m_maxLines];
}
m_content.swap(newContent);
- }
- else
- {
+ } else {
// if it doesn't fit, part of the data needs to be thrown away (the oldest log messages)
int lead = m_numLines - maxLines;
beginRemoveRows(QModelIndex(), 0, lead - 1);
- for(int i = 0; i < maxLines; i++)
- {
+ for (int i = 0; i < maxLines; i++) {
newContent[i] = m_content[(m_firstLine + lead + i) % m_maxLines];
}
m_numLines = m_maxLines;
@@ -155,8 +140,7 @@ void LogModel::setOverflowMessage(const QString& overflowMessage)
void LogModel::setLineWrap(bool state)
{
- if(m_lineWrap != state)
- {
+ if (m_lineWrap != state) {
m_lineWrap = state;
}
}