diff options
author | Christian Ehrlicher <ch.ehrlicher@gmx.de> | 2018-01-14 09:34:56 +0100 |
---|---|---|
committer | Christian Ehrlicher <ch.ehrlicher@gmx.de> | 2018-01-16 18:53:38 +0000 |
commit | 0aecac1dcfd4b8e353e2fc0b0ad06d77b4b125d6 (patch) | |
tree | 897b0967f030e350059fee05090f97be8bb9a44a /src/widgets/itemviews/qitemdelegate.cpp | |
parent | ea7a9d694b8548f39d4e66684793ad17be837a66 (diff) |
QItemDelegate::doLayout: only call QStyle::pixelMetric() once
QStyle::pixelMetric(QStyle::PM_FocusFrameHMargin) was called three times
in the worst case but it returns a constant value. Therefore cache this
value and call pixelMetric() only once.
Since this code is duplicated from QCommonStylePrivate::viewItemLayout()
also change it there.
Change-Id: I6d5f0a8d2b1373bd36f0520f404e6a3cb0794f12
Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
Reviewed-by: Thorbjørn Lund Martsum <tmartsum@gmail.com>
Diffstat (limited to 'src/widgets/itemviews/qitemdelegate.cpp')
-rw-r--r-- | src/widgets/itemviews/qitemdelegate.cpp | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/src/widgets/itemviews/qitemdelegate.cpp b/src/widgets/itemviews/qitemdelegate.cpp index df5f9afb0e..e1089e3158 100644 --- a/src/widgets/itemviews/qitemdelegate.cpp +++ b/src/widgets/itemviews/qitemdelegate.cpp @@ -803,11 +803,14 @@ void QItemDelegate::doLayout(const QStyleOptionViewItem &option, const bool hasCheck = checkRect->isValid(); const bool hasPixmap = pixmapRect->isValid(); const bool hasText = textRect->isValid(); - const int textMargin = hasText ? style->pixelMetric(QStyle::PM_FocusFrameHMargin, 0, widget) + 1 : 0; - const int pixmapMargin = hasPixmap ? style->pixelMetric(QStyle::PM_FocusFrameHMargin, 0, widget) + 1 : 0; - const int checkMargin = hasCheck ? style->pixelMetric(QStyle::PM_FocusFrameHMargin, 0, widget) + 1 : 0; - int x = option.rect.left(); - int y = option.rect.top(); + const bool hasMargin = (hasText | hasPixmap | hasCheck); + const int frameHMargin = hasMargin ? + style->pixelMetric(QStyle::PM_FocusFrameHMargin, 0, widget) + 1 : 0; + const int textMargin = hasText ? frameHMargin : 0; + const int pixmapMargin = hasPixmap ? frameHMargin : 0; + const int checkMargin = hasCheck ? frameHMargin : 0; + const int x = option.rect.left(); + const int y = option.rect.top(); int w, h; textRect->adjust(-textMargin, 0, textMargin, 0); // add width padding |