AutoTest: Improve test output handling

Instead of just providing the hidden search, provide a more
obvious present filter functionality for the text output
similar to what is done in other output windows.
This still has the find functionality present as well.

Task-number: QTCREATORBUG-28706
Change-Id: I8f8b1494d86c90cbb9ea6bfad3f0e74caf3de2c9
Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
Christian Stenger
2023-01-19 22:13:30 +01:00
parent a8d493d352
commit 0ffb85b4d8
2 changed files with 32 additions and 65 deletions

View File

@@ -15,15 +15,13 @@
#include "testsettings.h"
#include "testtreemodel.h"
#include <aggregation/aggregate.h>
#include <coreplugin/actionmanager/actionmanager.h>
#include <coreplugin/coreconstants.h>
#include <coreplugin/editormanager/editormanager.h>
#include <coreplugin/find/basetextfind.h>
#include <coreplugin/find/itemviewfind.h>
#include <coreplugin/icontext.h>
#include <coreplugin/icore.h>
#include <coreplugin/outputwindow.h>
#include <projectexplorer/buildmanager.h>
#include <projectexplorer/projectexplorer.h>
@@ -115,16 +113,22 @@ TestResultsPane::TestResultsPane(QObject *parent) :
outputLayout->addWidget(ItemViewFind::createSearchableWrapper(m_treeView));
m_textOutput = new QPlainTextEdit;
m_textOutput->setPalette(pal);
m_textOutput->setFont(TextEditor::TextEditorSettings::fontSettings().font());
m_textOutput = new Core::OutputWindow(Core::Context("AutoTest.TextOutput"),
"AutoTest.TextOutput.Filter");
m_textOutput->setBaseFont(TextEditor::TextEditorSettings::fontSettings().font());
m_textOutput->setWordWrapMode(QTextOption::WordWrap);
m_textOutput->setReadOnly(true);
m_outputWidget->addWidget(m_textOutput);
auto agg = new Aggregation::Aggregate;
agg->add(m_textOutput);
agg->add(new BaseTextFind(m_textOutput));
setupFilterUi("AutoTest.TextOutput.Filter");
setupContext("AutoTest.TextOutput", m_textOutput);
setFilteringEnabled(false);
setZoomButtonsEnabled(false);
connect(this, &IOutputPane::zoomInRequested, m_textOutput, &Core::OutputWindow::zoomIn);
connect(this, &IOutputPane::zoomOutRequested, m_textOutput, &Core::OutputWindow::zoomOut);
connect(this, &IOutputPane::resetZoomRequested, m_textOutput, &Core::OutputWindow::resetZoom);
connect(this, &IOutputPane::fontChanged, m_textOutput, &OutputWindow::setBaseFont);
createToolButtons();
@@ -235,33 +239,6 @@ void TestResultsPane::addTestResult(const TestResult &result)
navigateStateChanged();
}
static void checkAndFineTuneColors(QTextCharFormat *format)
{
QTC_ASSERT(format, return);
const QColor bgColor = format->background().color();
QColor fgColor = format->foreground().color();
if (StyleHelper::isReadableOn(bgColor, fgColor))
return;
int h, s, v;
fgColor.getHsv(&h, &s, &v);
// adjust the color value to ensure better readability
if (StyleHelper::luminance(bgColor) < .5)
v = v + 64;
else
v = v - 64;
fgColor.setHsv(h, s, v);
if (!StyleHelper::isReadableOn(bgColor, fgColor)) {
s = (s + 128) % 255; // adjust the saturation to ensure better readability
fgColor.setHsv(h, s, v);
if (!StyleHelper::isReadableOn(bgColor, fgColor))
return;
}
format->setForeground(fgColor);
}
void TestResultsPane::addOutputLine(const QByteArray &outputLine, OutputChannel channel)
{
@@ -271,20 +248,9 @@ void TestResultsPane::addOutputLine(const QByteArray &outputLine, OutputChannel
return;
}
const FormattedText formattedText
= FormattedText{QString::fromUtf8(outputLine), m_defaultFormat};
const QList<FormattedText> formatted = channel == OutputChannel::StdOut
? m_stdOutHandler.parseText(formattedText)
: m_stdErrHandler.parseText(formattedText);
QTextCursor cursor = m_textOutput->textCursor();
cursor.beginEditBlock();
for (auto formattedText : formatted) {
checkAndFineTuneColors(&formattedText.format);
cursor.insertText(formattedText.text, formattedText.format);
}
cursor.insertText("\n");
cursor.endEditBlock();
m_textOutput->appendMessage(QString::fromUtf8(outputLine) + '\n',
channel == OutputChannel::StdOut ? OutputFormat::StdOutFormat
: OutputFormat::StdErrFormat);
}
QWidget *TestResultsPane::outputWidget(QWidget *parent)
@@ -299,8 +265,11 @@ QWidget *TestResultsPane::outputWidget(QWidget *parent)
QList<QWidget *> TestResultsPane::toolBarWidgets() const
{
return {m_expandCollapse, m_runAll, m_runSelected, m_runFailed, m_runFile, m_stopTestRun,
m_outputToggleButton, m_filterButton};
QList<QWidget *> result = {m_expandCollapse, m_runAll, m_runSelected, m_runFailed,
m_runFile, m_stopTestRun, m_outputToggleButton, m_filterButton};
for (QWidget *widget : IOutputPane::toolBarWidgets())
result.append(widget);
return result;
}
QString TestResultsPane::displayName() const
@@ -325,14 +294,6 @@ void TestResultsPane::clearContents()
connect(m_treeView->verticalScrollBar(), &QScrollBar::rangeChanged,
this, &TestResultsPane::onScrollBarRangeChanged, Qt::UniqueConnection);
m_textOutput->clear();
m_defaultFormat.setBackground(creatorTheme()->palette().color(
m_textOutput->backgroundRole()));
m_defaultFormat.setForeground(creatorTheme()->palette().color(
m_textOutput->foregroundRole()));
// in case they had been forgotten to reset
m_stdErrHandler.endFormatScope();
m_stdOutHandler.endFormatScope();
clearMarks();
}
@@ -445,6 +406,12 @@ void TestResultsPane::goToPrev()
onItemActivated(nextCurrentIndex);
}
void TestResultsPane::updateFilter()
{
m_textOutput->updateFilterProperties(filterText(), filterCaseSensitivity(), filterUsesRegexp(),
filterIsInverted());
}
void TestResultsPane::onItemActivated(const QModelIndex &index)
{
if (!index.isValid())
@@ -711,6 +678,8 @@ void TestResultsPane::toggleOutputStyle()
m_outputWidget->setCurrentIndex(displayText ? 1 : 0);
m_outputToggleButton->setIcon(displayText ? Icons::VISUAL_DISPLAY.icon()
: Icons::TEXT_DISPLAY.icon());
setFilteringEnabled(displayText);
setZoomButtonsEnabled(displayText);
}
// helper for onCopyWholeTriggered() and onSaveWholeTriggered()

View File

@@ -7,7 +7,6 @@
#include <coreplugin/ioutputpane.h>
#include <utils/ansiescapecodehandler.h>
#include <utils/itemviews.h>
QT_BEGIN_NAMESPACE
@@ -24,6 +23,7 @@ QT_END_NAMESPACE
namespace Core {
class IContext;
class OutputWindow;
}
namespace Autotest {
@@ -71,6 +71,7 @@ public:
bool canPrevious() const override;
void goToNext() override;
void goToPrev() override;
void updateFilter() override;
void addTestResult(const TestResult &result);
void addOutputLine(const QByteArray &outputLine, OutputChannel channel);
@@ -118,15 +119,12 @@ private:
QToolButton *m_stopTestRun;
QToolButton *m_filterButton;
QToolButton *m_outputToggleButton;
QPlainTextEdit *m_textOutput;
Core::OutputWindow *m_textOutput;
QMenu *m_filterMenu;
bool m_autoScroll = false;
bool m_atEnd = false;
bool m_testRunning = false;
QVector<TestEditorMark *> m_marks;
QTextCharFormat m_defaultFormat;
Utils::AnsiEscapeCodeHandler m_stdErrHandler;
Utils::AnsiEscapeCodeHandler m_stdOutHandler;
};
} // namespace Internal