2022-08-19 15:59:36 +02:00
|
|
|
// Copyright (C) 2016 The Qt Company Ltd.
|
2022-12-21 10:12:09 +01:00
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
2014-10-07 15:51:02 +02:00
|
|
|
|
2016-03-18 07:55:01 +01:00
|
|
|
#pragma once
|
2014-10-07 15:51:02 +02:00
|
|
|
|
|
|
|
|
#include "testresultmodel.h"
|
|
|
|
|
|
|
|
|
|
#include <QStyledItemDelegate>
|
2015-08-19 10:22:25 +02:00
|
|
|
#include <QTextLayout>
|
2014-10-07 15:51:02 +02:00
|
|
|
|
|
|
|
|
namespace Autotest {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
|
|
|
|
class TestResultDelegate : public QStyledItemDelegate
|
|
|
|
|
{
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
public:
|
2018-05-31 07:38:04 +02:00
|
|
|
explicit TestResultDelegate(QObject *parent = nullptr);
|
2014-10-07 15:51:02 +02:00
|
|
|
|
2016-09-29 12:15:43 +02:00
|
|
|
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
|
|
|
|
|
QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const override;
|
2014-10-07 15:51:02 +02:00
|
|
|
void currentChanged(const QModelIndex ¤t, const QModelIndex &previous);
|
2017-10-12 14:56:21 +02:00
|
|
|
void clearCache();
|
2014-10-07 15:51:02 +02:00
|
|
|
|
|
|
|
|
private:
|
2021-07-27 14:26:28 +02:00
|
|
|
void limitTextOutput(QString &output) const;
|
2015-08-19 10:22:25 +02:00
|
|
|
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;
|
2020-07-01 15:50:34 +02:00
|
|
|
mutable int m_lastWidth = -1;
|
2015-08-19 10:22:25 +02:00
|
|
|
|
2014-10-07 15:51:02 +02:00
|
|
|
class LayoutPositions
|
|
|
|
|
{
|
|
|
|
|
public:
|
2018-01-26 07:29:20 +01:00
|
|
|
LayoutPositions(QStyleOptionViewItem &options, const TestResultFilterModel *filterModel)
|
2020-07-01 15:45:48 +02:00
|
|
|
: m_top(options.rect.top()),
|
|
|
|
|
m_left(options.rect.left()),
|
|
|
|
|
m_right(options.rect.right())
|
2014-10-07 15:51:02 +02:00
|
|
|
{
|
2015-08-20 15:59:15 +02:00
|
|
|
TestResultModel *srcModel = static_cast<TestResultModel *>(filterModel->sourceModel());
|
|
|
|
|
m_maxFileLength = srcModel->maxWidthOfFileName(options.font);
|
|
|
|
|
m_maxLineLength = srcModel->maxWidthOfLineNumber(options.font);
|
|
|
|
|
m_realFileLength = m_maxFileLength;
|
2019-02-11 10:32:46 +01:00
|
|
|
m_typeAreaWidth = QFontMetrics(options.font).horizontalAdvance("XXXXXXXX");
|
2020-07-01 15:45:48 +02:00
|
|
|
|
2014-10-07 15:51:02 +02:00
|
|
|
int flexibleArea = lineAreaLeft() - textAreaLeft() - ITEM_SPACING;
|
|
|
|
|
if (m_maxFileLength > flexibleArea / 2)
|
|
|
|
|
m_realFileLength = flexibleArea / 2;
|
|
|
|
|
m_fontHeight = QFontMetrics(options.font).height();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int top() const { return m_top + ITEM_MARGIN; }
|
2020-07-01 15:45:48 +02:00
|
|
|
int left() const { return m_left + ITEM_MARGIN; }
|
|
|
|
|
int right() const { return m_right - ITEM_MARGIN; }
|
2014-10-07 15:51:02 +02:00
|
|
|
int minimumHeight() const { return ICON_SIZE + 2 * ITEM_MARGIN; }
|
|
|
|
|
|
|
|
|
|
int iconSize() const { return ICON_SIZE; }
|
|
|
|
|
int typeAreaLeft() const { return left() + ICON_SIZE + ITEM_SPACING; }
|
2016-10-31 13:11:52 +01:00
|
|
|
int textAreaLeft() const { return typeAreaLeft() + m_typeAreaWidth + ITEM_SPACING; }
|
2014-10-07 15:51:02 +02:00
|
|
|
int textAreaWidth() const { return fileAreaLeft() - ITEM_SPACING - textAreaLeft(); }
|
|
|
|
|
int fileAreaLeft() const { return lineAreaLeft() - ITEM_SPACING - m_realFileLength; }
|
|
|
|
|
int lineAreaLeft() const { return right() - m_maxLineLength; }
|
|
|
|
|
|
|
|
|
|
QRect textArea() const { return QRect(textAreaLeft(), top(),
|
2015-08-20 15:59:15 +02:00
|
|
|
textAreaWidth(), m_fontHeight); }
|
2014-10-07 15:51:02 +02:00
|
|
|
QRect fileArea() const { return QRect(fileAreaLeft(), top(),
|
2015-08-20 15:59:15 +02:00
|
|
|
m_realFileLength + ITEM_SPACING, m_fontHeight); }
|
2014-10-07 15:51:02 +02:00
|
|
|
|
|
|
|
|
QRect lineArea() const { return QRect(lineAreaLeft(), top(),
|
|
|
|
|
m_maxLineLength, m_fontHeight); }
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
int m_maxFileLength;
|
|
|
|
|
int m_maxLineLength;
|
|
|
|
|
int m_realFileLength;
|
|
|
|
|
int m_top;
|
2020-07-01 15:45:48 +02:00
|
|
|
int m_left;
|
|
|
|
|
int m_right;
|
2014-10-07 15:51:02 +02:00
|
|
|
int m_fontHeight;
|
|
|
|
|
int m_typeAreaWidth;
|
|
|
|
|
|
|
|
|
|
static const int ICON_SIZE = 16;
|
|
|
|
|
static const int ITEM_MARGIN = 2;
|
|
|
|
|
static const int ITEM_SPACING = 4;
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace Autotest
|