From 9eb0525dab04aa8c41e71db1290daf3e5048746b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Mon, 18 Dec 2017 01:19:43 +0100 Subject: [PATCH] NOISSUE preserve log page checkbox state when the instance window is closed Only for a single session, not between sessions. --- api/logic/launch/LogModel.cpp | 18 +++++++++++ api/logic/launch/LogModel.h | 6 ++++ application/pages/LogPage.cpp | 56 ++++++++++++++++++++++++++++++++--- application/pages/LogPage.h | 5 ++++ 4 files changed, 81 insertions(+), 4 deletions(-) diff --git a/api/logic/launch/LogModel.cpp b/api/logic/launch/LogModel.cpp index 042feeab..72b076e9 100644 --- a/api/logic/launch/LogModel.cpp +++ b/api/logic/launch/LogModel.cpp @@ -69,6 +69,11 @@ void LogModel::suspend(bool suspend) m_suspended = suspend; } +bool LogModel::suspended() +{ + return m_suspended; +} + void LogModel::clear() { beginResetModel(); @@ -147,3 +152,16 @@ void LogModel::setOverflowMessage(const QString& overflowMessage) { m_overflowMessage = overflowMessage; } + +void LogModel::setLineWrap(bool state) +{ + if(m_lineWrap != state) + { + m_lineWrap = state; + } +} + +bool LogModel::wrapLines() const +{ + return m_lineWrap; +} diff --git a/api/logic/launch/LogModel.h b/api/logic/launch/LogModel.h index 57cd23b0..e6deac89 100644 --- a/api/logic/launch/LogModel.h +++ b/api/logic/launch/LogModel.h @@ -17,7 +17,9 @@ public: void append(MessageLevel::Enum, QString line); void clear(); + void suspend(bool suspend); + bool suspended(); QString toPlainText(); @@ -26,6 +28,9 @@ public: void setStopOnOverflow(bool stop); void setOverflowMessage(const QString & overflowMessage); + void setLineWrap(bool state); + bool wrapLines() const; + enum Roles { LevelRole = Qt::UserRole @@ -48,6 +53,7 @@ private: /* data */ bool m_stopOnOverflow = false; QString m_overflowMessage = "OVERFLOW"; bool m_suspended = false; + bool m_lineWrap = true; private: Q_DISABLE_COPY(LogModel) diff --git a/application/pages/LogPage.cpp b/application/pages/LogPage.cpp index 009a9f55..0fa1ee67 100644 --- a/application/pages/LogPage.cpp +++ b/application/pages/LogPage.cpp @@ -141,13 +141,11 @@ LogPage::LogPage(InstancePtr instance, QWidget *parent) auto launchTask = m_instance->getLaunchTask(); if(launchTask) { - onInstanceLaunchTaskChanged(launchTask); + setInstanceLaunchTaskChanged(launchTask, true); } connect(m_instance.get(), &BaseInstance::launchTaskChanged, this, &LogPage::onInstanceLaunchTaskChanged); } - ui->text->setWordWrap(true); - auto findShortcut = new QShortcut(QKeySequence(QKeySequence::Find), this); connect(findShortcut, SIGNAL(activated()), SLOT(findActivated())); auto findNextShortcut = new QShortcut(QKeySequence(QKeySequence::FindNext), this); @@ -162,13 +160,53 @@ LogPage::~LogPage() delete ui; } -void LogPage::onInstanceLaunchTaskChanged(std::shared_ptr proc) +void LogPage::modelStateToUI() +{ + if(m_model->wrapLines()) + { + ui->text->setWordWrap(true); + ui->wrapCheckbox->setCheckState(Qt::Checked); + } + else + { + ui->text->setWordWrap(false); + ui->wrapCheckbox->setCheckState(Qt::Unchecked); + } + if(m_model->suspended()) + { + ui->trackLogCheckbox->setCheckState(Qt::Unchecked); + } + else + { + ui->trackLogCheckbox->setCheckState(Qt::Checked); + } +} + +void LogPage::UIToModelState() +{ + if(!m_model) + { + return; + } + m_model->setLineWrap(ui->wrapCheckbox->checkState() == Qt::Checked); + m_model->suspend(ui->trackLogCheckbox->checkState() != Qt::Checked); +} + +void LogPage::setInstanceLaunchTaskChanged(std::shared_ptr proc, bool initial) { m_process = proc; if(m_process) { m_model = proc->getLogModel(); m_proxy->setSourceModel(m_model.get()); + if(initial) + { + modelStateToUI(); + } + else + { + UIToModelState(); + } } else { @@ -177,6 +215,11 @@ void LogPage::onInstanceLaunchTaskChanged(std::shared_ptr proc) } } +void LogPage::onInstanceLaunchTaskChanged(std::shared_ptr proc) +{ + setInstanceLaunchTaskChanged(proc, false); +} + bool LogPage::apply() { return true; @@ -228,12 +271,17 @@ void LogPage::on_btnBottom_clicked() void LogPage::on_trackLogCheckbox_clicked(bool checked) { + if(!m_model) + return; m_model->suspend(!checked); } void LogPage::on_wrapCheckbox_clicked(bool checked) { ui->text->setWordWrap(checked); + if(!m_model) + return; + m_model->setLineWrap(checked); } void LogPage::on_findButton_clicked() diff --git a/application/pages/LogPage.h b/application/pages/LogPage.h index 3ca47b8a..8d90541f 100644 --- a/application/pages/LogPage.h +++ b/application/pages/LogPage.h @@ -71,6 +71,11 @@ private slots: void onInstanceLaunchTaskChanged(std::shared_ptr proc); +private: + void modelStateToUI(); + void UIToModelState(); + void setInstanceLaunchTaskChanged(std::shared_ptr proc, bool initial); + private: Ui::LogPage *ui; InstancePtr m_instance;