NOISSUE preserve log page checkbox state when the instance window is closed

Only for a single session, not between sessions.
This commit is contained in:
Petr Mrázek 2017-12-18 01:19:43 +01:00
parent fb7897a6f4
commit 9eb0525dab
4 changed files with 81 additions and 4 deletions

View File

@ -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;
}

View File

@ -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)

View File

@ -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<LaunchTask> 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<LaunchTask> 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<LaunchTask> proc)
}
}
void LogPage::onInstanceLaunchTaskChanged(std::shared_ptr<LaunchTask> 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()

View File

@ -71,6 +71,11 @@ private slots:
void onInstanceLaunchTaskChanged(std::shared_ptr<LaunchTask> proc);
private:
void modelStateToUI();
void UIToModelState();
void setInstanceLaunchTaskChanged(std::shared_ptr<LaunchTask> proc, bool initial);
private:
Ui::LogPage *ui;
InstancePtr m_instance;