summaryrefslogtreecommitdiff
path: root/src/plugins/autotest/testresultdelegate.cpp
diff options
context:
space:
mode:
authorPetar Perisin <petar.perisin@gmail.com>2021-07-27 14:26:28 +0200
committerPetar Perisin <petar.perisin@gmail.com>2021-08-10 11:17:27 +0000
commitfe4c04624310874c5818b9bd674b21fe8af77419 (patch)
tree66e24dd479bd4ce7c10d672a3308b1ce2188be87 /src/plugins/autotest/testresultdelegate.cpp
parenta9ae1a180bfdd543d0d4a97f04dd3246f857357b (diff)
downloadqt-creator-fe4c04624310874c5818b9bd674b21fe8af77419.tar.gz
AutoTest: Add ability to limit test description
Test description is made of entire test output, and if it is very big it can heavily limit test output pane usability. This commit adds option to limit description size. Change-Id: I5aae5e460f1939cd94a84ab1ca79f413d66d8bf2 Reviewed-by: Leena Miettinen <riitta-leena.miettinen@qt.io> Reviewed-by: Christian Stenger <christian.stenger@qt.io>
Diffstat (limited to 'src/plugins/autotest/testresultdelegate.cpp')
-rw-r--r--src/plugins/autotest/testresultdelegate.cpp42
1 files changed, 34 insertions, 8 deletions
diff --git a/src/plugins/autotest/testresultdelegate.cpp b/src/plugins/autotest/testresultdelegate.cpp
index f0e7ec111c..5ff0f8217f 100644
--- a/src/plugins/autotest/testresultdelegate.cpp
+++ b/src/plugins/autotest/testresultdelegate.cpp
@@ -102,11 +102,8 @@ void TestResultDelegate::paint(QPainter *painter, const QStyleOptionViewItem &op
QString output = testResult->outputString(selected);
if (selected) {
+ limitTextOutput(output);
output.replace('\n', QChar::LineSeparator);
-
- if (AutotestPlugin::settings()->limitResultOutput && output.length() > outputLimit)
- output = output.left(outputLimit).append("...");
-
recalculateTextLayout(index, output, painter->font(), positions.textAreaWidth());
m_lastCalculatedLayout.draw(painter, QPoint(positions.textAreaLeft(), positions.top()));
@@ -154,11 +151,8 @@ QSize TestResultDelegate::sizeHint(const QStyleOptionViewItem &option, const QMo
const TestResult *testResult = resultFilterModel->testResult(index);
QTC_ASSERT(testResult, return QSize());
QString output = testResult->outputString(selected);
+ limitTextOutput(output);
output.replace('\n', QChar::LineSeparator);
-
- if (AutotestPlugin::settings()->limitResultOutput && output.length() > outputLimit)
- output = output.left(outputLimit).append("...");
-
recalculateTextLayout(index, output, opt.font, positions.textAreaWidth());
s.setHeight(m_lastCalculatedHeight + 3);
@@ -185,6 +179,38 @@ void TestResultDelegate::clearCache()
m_lastWidth = -1;
}
+void TestResultDelegate::limitTextOutput(QString &output) const
+{
+ int maxLineCount = Internal::AutotestPlugin::settings()->resultDescriptionMaxSize;
+ bool limited = false;
+
+ if (Internal::AutotestPlugin::settings()->limitResultDescription && maxLineCount > 0) {
+ int index = -1;
+ int lastChar = output.size() - 1;
+
+ for (int i = 0; i < maxLineCount; i++) {
+ index = output.indexOf('\n', index + 1);
+ if (index == -1 || index == lastChar) {
+ index = -1;
+ break;
+ }
+ }
+
+ if (index > 0) {
+ output = output.left(index);
+ limited = true;
+ }
+ }
+
+ if (AutotestPlugin::settings()->limitResultOutput && output.length() > outputLimit) {
+ output = output.left(outputLimit);
+ limited = true;
+ }
+
+ if (limited)
+ output.append("...");
+}
+
void TestResultDelegate::recalculateTextLayout(const QModelIndex &index, const QString &output,
const QFont &font, int width) const
{