From 0afd504748f49ae6c6d77403fd1d6f6604b6eaa8 Mon Sep 17 00:00:00 2001 From: Christian Stenger Date: Thu, 16 Apr 2015 08:54:41 +0200 Subject: [PATCH] Add auto-scroll feature for results pane Change-Id: Iff209384c2bf30b3ce2b9241ce1c719a44592e65 Reviewed-by: David Schulz Reviewed-by: Christian Stenger --- plugins/autotest/testresultspane.cpp | 18 +- plugins/autotest/testresultspane.h | 3 + plugins/autotest/testsettings.cpp | 8 +- plugins/autotest/testsettings.h | 1 + plugins/autotest/testsettingspage.cpp | 2 + plugins/autotest/testsettingspage.ui | 488 ++++++++++++-------------- 6 files changed, 256 insertions(+), 264 deletions(-) diff --git a/plugins/autotest/testresultspane.cpp b/plugins/autotest/testresultspane.cpp index 0d6b9052b84..9ebb1c09fbb 100644 --- a/plugins/autotest/testresultspane.cpp +++ b/plugins/autotest/testresultspane.cpp @@ -37,6 +37,7 @@ #include #include #include +#include #include #include @@ -46,7 +47,8 @@ namespace Internal { TestResultsPane::TestResultsPane(QObject *parent) : Core::IOutputPane(parent), m_context(new Core::IContext(this)), - m_wasVisibleBefore(false) + m_wasVisibleBefore(false), + m_autoScroll(false) { m_outputWidget = new QWidget; QVBoxLayout *outputLayout = new QVBoxLayout; @@ -144,6 +146,9 @@ TestResultsPane::~TestResultsPane() void TestResultsPane::addTestResult(const TestResult &result) { + const QScrollBar *scrollBar = m_treeView->verticalScrollBar(); + m_atEnd = scrollBar ? scrollBar->value() == scrollBar->maximum() : true; + m_model->addTestResult(result); if (!m_treeView->isVisible()) popup(Core::IOutputPane::NoModeSwitch); @@ -181,6 +186,9 @@ void TestResultsPane::clearContents() m_filterModel->clearTestResults(); navigateStateChanged(); m_summaryWidget->setVisible(false); + m_autoScroll = AutotestPlugin::instance()->settings()->autoScroll; + connect(m_treeView->verticalScrollBar(), &QScrollBar::rangeChanged, + this, &TestResultsPane::onScrollBarRangeChanged, Qt::UniqueConnection); } void TestResultsPane::visibilityChanged(bool visible) @@ -381,6 +389,14 @@ void TestResultsPane::onTestRunFinished() updateSummaryLabel(); m_summaryWidget->setVisible(true); m_model->removeCurrentTestMessage(); + disconnect(m_treeView->verticalScrollBar(), &QScrollBar::rangeChanged, + this, &TestResultsPane::onScrollBarRangeChanged); +} + +void TestResultsPane::onScrollBarRangeChanged(int, int max) +{ + if (m_autoScroll && m_atEnd) + m_treeView->verticalScrollBar()->setValue(max); } void TestResultsPane::onTestTreeModelChanged() diff --git a/plugins/autotest/testresultspane.h b/plugins/autotest/testresultspane.h index 0d76c56ff48..37a35eece81 100644 --- a/plugins/autotest/testresultspane.h +++ b/plugins/autotest/testresultspane.h @@ -88,6 +88,7 @@ private: void createToolButtons(); void onTestRunStarted(); void onTestRunFinished(); + void onScrollBarRangeChanged(int, int max); void onTestTreeModelChanged(); QWidget *m_outputWidget; @@ -103,6 +104,8 @@ private: QToolButton *m_filterButton; QMenu *m_filterMenu; bool m_wasVisibleBefore; + bool m_autoScroll; + bool m_atEnd; }; } // namespace Internal diff --git a/plugins/autotest/testsettings.cpp b/plugins/autotest/testsettings.cpp index 3a11b8c66b9..bb5bcd61ece 100644 --- a/plugins/autotest/testsettings.cpp +++ b/plugins/autotest/testsettings.cpp @@ -30,11 +30,12 @@ static const char metricsKey[] = "Metrics"; static const char omitInternalKey[] = "OmitInternal"; static const char omitRunConfigWarnKey[] = "OmitRCWarnings"; static const char limitResultOutputKey[] = "LimitResultOutput"; +static const char autoScrollKey[] = "AutoScrollResults"; static const int defaultTimeout = 60000; TestSettings::TestSettings() : timeout(defaultTimeout), metrics(Walltime), omitInternalMssg(true), omitRunConfigWarn(false), - limitResultOutput(true) + limitResultOutput(true), autoScroll(true) { } @@ -46,6 +47,7 @@ void TestSettings::toSettings(QSettings *s) const s->setValue(QLatin1String(omitInternalKey), omitInternalMssg); s->setValue(QLatin1String(omitRunConfigWarnKey), omitRunConfigWarn); s->setValue(QLatin1String(limitResultOutputKey), limitResultOutput); + s->setValue(QLatin1String(autoScrollKey), autoScroll); s->endGroup(); } @@ -75,6 +77,7 @@ void TestSettings::fromSettings(const QSettings *s) omitInternalMssg = s->value(root + QLatin1String(omitInternalKey), true).toBool(); omitRunConfigWarn = s->value(root + QLatin1String(omitRunConfigWarnKey), false).toBool(); limitResultOutput = s->value(root + QLatin1String(limitResultOutputKey), true).toBool(); + autoScroll = s->value(root + QLatin1String(autoScrollKey), true).toBool(); } bool TestSettings::equals(const TestSettings &rhs) const @@ -82,7 +85,8 @@ bool TestSettings::equals(const TestSettings &rhs) const return timeout == rhs.timeout && metrics == rhs.metrics && omitInternalMssg == rhs.omitInternalMssg && omitRunConfigWarn == rhs.omitRunConfigWarn - && limitResultOutput == rhs.limitResultOutput; + && limitResultOutput == rhs.limitResultOutput + && autoScroll == rhs.autoScroll; } QString TestSettings::metricsTypeToOption(const MetricsType type) diff --git a/plugins/autotest/testsettings.h b/plugins/autotest/testsettings.h index 520edde6fc6..8ef368e8040 100644 --- a/plugins/autotest/testsettings.h +++ b/plugins/autotest/testsettings.h @@ -50,6 +50,7 @@ struct TestSettings bool omitInternalMssg; bool omitRunConfigWarn; bool limitResultOutput; + bool autoScroll; }; inline bool operator==(const TestSettings &s1, const TestSettings &s2) { return s1.equals(s2); } diff --git a/plugins/autotest/testsettingspage.cpp b/plugins/autotest/testsettingspage.cpp index e65bff754a4..cf96ef92b63 100644 --- a/plugins/autotest/testsettingspage.cpp +++ b/plugins/autotest/testsettingspage.cpp @@ -42,6 +42,7 @@ void TestSettingsWidget::setSettings(const TestSettings &settings) m_ui.omitInternalMsgCB->setChecked(settings.omitInternalMssg); m_ui.omitRunConfigWarnCB->setChecked(settings.omitRunConfigWarn); m_ui.limitResultOutputCB->setChecked(settings.limitResultOutput); + m_ui.autoScrollCB->setChecked(settings.autoScroll); switch (settings.metrics) { case MetricsType::Walltime: @@ -71,6 +72,7 @@ TestSettings TestSettingsWidget::settings() const result.omitInternalMssg = m_ui.omitInternalMsgCB->isChecked(); result.omitRunConfigWarn = m_ui.omitRunConfigWarnCB->isChecked(); result.limitResultOutput = m_ui.limitResultOutputCB->isChecked(); + result.autoScroll = m_ui.autoScrollCB->isChecked(); if (m_ui.walltimeRB->isChecked()) result.metrics = MetricsType::Walltime; diff --git a/plugins/autotest/testsettingspage.ui b/plugins/autotest/testsettingspage.ui index bc3c6f6b0c5..1822cfbbd9b 100644 --- a/plugins/autotest/testsettingspage.ui +++ b/plugins/autotest/testsettingspage.ui @@ -6,289 +6,255 @@ 0 0 - 463 - 338 + 407 + 228 Form - - - - 9 - 10 - 435 - 307 - - - - - - - - - + + + + + + + Timeout used when executing each test case. + + + Timeout: + + + + + + + Timeout used when executing test cases. This will apply for each test case on its own, not the whole project. + + + s + + + 5 + + + 36000 + + + 60 + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + + + Benchmark Metrics + + - + + + + 0 + 0 + + - Timeout used when executing each test case. + Uses walltime metrics for executing benchmarks (default). - Timeout: + Walltime + + + true - + + + + 0 + 0 + + - Timeout used when executing test cases. This will apply for each test case on its own, not the whole project. + Uses tick counter when executing benchmarks. - - s + + Tick counter - - 5 + + + + + + + 0 + 0 + - - 36000 + + Uses event counter when executing benchmarks. - - 60 + + Event counter + + + + + + + false + + + + 0 + 0 + + + + Uses Valgrind Callgrind when executing benchmarks (it must be installed). + + + Callgrind + + + + + + + false + + + + 0 + 0 + + + + Uses Perf when executing benchmarks (it must be installed). + + + Perf - - - - - - - Qt::Horizontal - - - QSizePolicy::Fixed - - - - 40 - 20 - - - - - - - - - - Hides internal messages by default. You can still enable them by using the test results filter. - - - Omit internal messages - - - true - - - - - - - Hides warnings related to a guessed run configuration. - - - Omit run configuration warnings - - - - - - - Limit result output to 100000 characters. - - - Limit result output - - - true - - - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - Qt::Vertical - - - QSizePolicy::Fixed - - - - 20 - 20 - - - - - - - - - - - 0 - 0 - - - - Benchmark Metrics - - - - - - - - - 0 - 0 - - - - Uses walltime metrics for executing benchmarks (default). - - - Walltime - - - true - - - - - - - - 0 - 0 - - - - Uses tick counter when executing benchmarks. - - - Tick counter - - - - - - - - 0 - 0 - - - - Uses event counter when executing benchmarks. - - - Event counter - - - - - - - false - - - - 0 - 0 - - - - Uses Valgrind Callgrind when executing benchmarks (it must be installed). - - - Callgrind - - - - - - - false - - - - 0 - 0 - - - - Uses Perf when executing benchmarks (it must be installed). - - - Perf - - - - - - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + + General + + + + + + Hides internal messages by default. You can still enable them by using the test results filter. + + + Omit internal messages + + + true + + + + + + + Hides warnings related to a guessed run configuration. + + + Omit run configuration warnings + + + + + + + Limit result output to 100000 characters. + + + Limit result output + + + true + + + + + + + Automatically scroll down when new items are added and scrollbar is at bottom. + + + Automatically scroll results + + + true + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + +