summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Stenger <christian.stenger@theqtcompany.com>2015-08-19 10:22:25 +0200
committerDavid Schulz <david.schulz@theqtcompany.com>2015-09-04 15:34:20 +0300
commit71d5142fcc65ec1af13d861660b19a84c317eafb (patch)
treedb5e0bb2d99940932a1050b9dfdd86a14cc452f0
parente6bd5e68ac899d6a519f92693ea30ea359f1dd2b (diff)
downloadqt-creator-71d5142fcc65ec1af13d861660b19a84c317eafb.tar.gz
Cache some information to speed up handling of large output
Change-Id: I93c37566af029028dc40e5eb48a398eb9c7fff7c Reviewed-by: David Schulz <david.schulz@theqtcompany.com>
-rw-r--r--plugins/autotest/testresultdelegate.cpp77
-rw-r--r--plugins/autotest/testresultdelegate.h9
2 files changed, 46 insertions, 40 deletions
diff --git a/plugins/autotest/testresultdelegate.cpp b/plugins/autotest/testresultdelegate.cpp
index 57dc2de847..7cf841dd78 100644
--- a/plugins/autotest/testresultdelegate.cpp
+++ b/plugins/autotest/testresultdelegate.cpp
@@ -126,32 +126,15 @@ void TestResultDelegate::paint(QPainter *painter, const QStyleOptionViewItem &op
}
if (selected) {
- int height = 0;
- int leading = fm.leading();
- int fontHeight = fm.height();
output.replace(QLatin1Char('\n'), QChar::LineSeparator);
if (AutotestPlugin::instance()->settings()->limitResultOutput
&& output.length() > outputLimit)
output = output.left(outputLimit).append(QLatin1String("..."));
- QTextLayout tl(output);
- tl.setFont(painter->font());
- QTextOption txtOption;
- txtOption.setWrapMode(QTextOption::WrapAtWordBoundaryOrAnywhere);
- tl.setTextOption(txtOption);
- tl.beginLayout();
- while (true) {
- QTextLine tLine = tl.createLine();
- if (!tLine.isValid())
- break;
- tLine.setLineWidth(positions.textAreaWidth());
- height += leading;
- tLine.setPosition(QPoint(0, height));
- height += fontHeight;
- }
- tl.endLayout();
- tl.draw(painter, QPoint(positions.textAreaLeft(), positions.top()));
+ recalculateTextLayout(index, output, painter->font(), positions.textAreaWidth());
+
+ m_lastCalculatedLayout.draw(painter, QPoint(positions.textAreaLeft(), positions.top()));
} else {
painter->setClipRect(positions.textArea());
// cut output before generating elided text as this takes quite long for exhaustive output
@@ -234,31 +217,13 @@ QSize TestResultDelegate::sizeHint(const QStyleOptionViewItem &option, const QMo
output.replace(QLatin1Char('\n'), QChar::LineSeparator);
- int height = 0;
- int leading = fm.leading();
-
if (AutotestPlugin::instance()->settings()->limitResultOutput
&& output.length() > outputLimit)
output = output.left(outputLimit).append(QLatin1String("..."));
- QTextLayout tl(output);
- tl.setFont(opt.font);
- QTextOption txtOption;
- txtOption.setWrapMode(QTextOption::WrapAtWordBoundaryOrAnywhere);
- tl.setTextOption(txtOption);
- tl.beginLayout();
- while (true) {
- QTextLine line = tl.createLine();
- if (!line.isValid())
- break;
- line.setLineWidth(positions.textAreaWidth());
- height += leading;
- line.setPosition(QPoint(0, height));
- height += fontHeight;
- }
- tl.endLayout();
+ recalculateTextLayout(index, output, opt.font, positions.textAreaWidth());
- s.setHeight(height + 3);
+ s.setHeight(m_lastCalculatedHeight + 3);
} else {
s.setHeight(fontHeight + 3);
}
@@ -275,5 +240,37 @@ void TestResultDelegate::currentChanged(const QModelIndex &current, const QModel
emit sizeHintChanged(previous);
}
+void TestResultDelegate::recalculateTextLayout(const QModelIndex &index, const QString &output,
+ const QFont &font, int width) const
+{
+ if (m_lastProcessedIndex == index && m_lastProcessedFont == font)
+ return;
+
+ const QFontMetrics fm(font);
+ const int leading = fm.leading();
+ const int fontHeight = fm.height();
+
+ m_lastProcessedIndex = index;
+ m_lastProcessedFont = font;
+ m_lastCalculatedHeight = 0;
+ m_lastCalculatedLayout.clearLayout();
+ m_lastCalculatedLayout.setText(output);
+ m_lastCalculatedLayout.setFont(font);
+ QTextOption txtOption;
+ txtOption.setWrapMode(QTextOption::WrapAtWordBoundaryOrAnywhere);
+ m_lastCalculatedLayout.setTextOption(txtOption);
+ m_lastCalculatedLayout.beginLayout();
+ while (true) {
+ QTextLine line = m_lastCalculatedLayout.createLine();
+ if (!line.isValid())
+ break;
+ line.setLineWidth(width);
+ m_lastCalculatedHeight += leading;
+ line.setPosition(QPoint(0, m_lastCalculatedHeight));
+ m_lastCalculatedHeight += fontHeight;
+ }
+ m_lastCalculatedLayout.endLayout();
+}
+
} // namespace Internal
} // namespace Autotest
diff --git a/plugins/autotest/testresultdelegate.h b/plugins/autotest/testresultdelegate.h
index 0b837ed2b2..d70b0d8902 100644
--- a/plugins/autotest/testresultdelegate.h
+++ b/plugins/autotest/testresultdelegate.h
@@ -23,6 +23,7 @@
#include "testresultmodel.h"
#include <QStyledItemDelegate>
+#include <QTextLayout>
namespace Autotest {
namespace Internal {
@@ -41,6 +42,14 @@ public slots:
void currentChanged(const QModelIndex &current, const QModelIndex &previous);
private:
+ void recalculateTextLayout(const QModelIndex &index, const QString &output,
+ const QFont &font, int width) const;
+
+ mutable QModelIndex m_lastProcessedIndex;
+ mutable QFont m_lastProcessedFont;
+ mutable QTextLayout m_lastCalculatedLayout;
+ mutable int m_lastCalculatedHeight;
+
class LayoutPositions
{
public: