AutoTest: Fix wrong caching of text layout

The text layout must get recalculated also when the width
of the underlying model index has changed.

Fixes: QTCREATORBUG-24236
Change-Id: I4ded56832c765320b6845cf35ad61453875dad50
Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
Christian Stenger
2020-07-01 15:50:34 +02:00
parent 3db5f4a2af
commit cd1a848e16
2 changed files with 4 additions and 1 deletions

View File

@@ -186,18 +186,20 @@ void TestResultDelegate::clearCache()
{ {
m_lastProcessedIndex = QModelIndex(); m_lastProcessedIndex = QModelIndex();
m_lastProcessedFont = QFont(); m_lastProcessedFont = QFont();
m_lastWidth = -1;
} }
void TestResultDelegate::recalculateTextLayout(const QModelIndex &index, const QString &output, void TestResultDelegate::recalculateTextLayout(const QModelIndex &index, const QString &output,
const QFont &font, int width) const const QFont &font, int width) const
{ {
if (m_lastProcessedIndex == index && m_lastProcessedFont == font) if (m_lastWidth == width && m_lastProcessedIndex == index && m_lastProcessedFont == font)
return; return;
const QFontMetrics fm(font); const QFontMetrics fm(font);
const int leading = fm.leading(); const int leading = fm.leading();
const int fontHeight = fm.height(); const int fontHeight = fm.height();
m_lastWidth = width;
m_lastProcessedIndex = index; m_lastProcessedIndex = index;
m_lastProcessedFont = font; m_lastProcessedFont = font;
m_lastCalculatedHeight = 0; m_lastCalculatedHeight = 0;

View File

@@ -52,6 +52,7 @@ private:
mutable QFont m_lastProcessedFont; mutable QFont m_lastProcessedFont;
mutable QTextLayout m_lastCalculatedLayout; mutable QTextLayout m_lastCalculatedLayout;
mutable int m_lastCalculatedHeight; mutable int m_lastCalculatedHeight;
mutable int m_lastWidth = -1;
class LayoutPositions class LayoutPositions
{ {