feat: smart caching of TorrentDelegate::sizeHint() (#1026)

* feat: smart caching of TorrentDelegate::sizeHint()

* chore: bump c++ requirement to c++17 / c++1z
This commit is contained in:
Charles Kerr 2019-11-06 18:17:48 -06:00 committed by GitHub
parent 973afda057
commit 2cc5cfe3e3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 24 additions and 7 deletions

View File

@ -378,12 +378,12 @@ endif()
if(CMAKE_VERSION VERSION_LESS "3.1")
if(CMAKE_C_COMPILER_ID STREQUAL "GNU" OR CMAKE_C_COMPILER_ID STREQUAL "Clang")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++17")
endif()
else()
set(CMAKE_C_STANDARD 99)
set(CMAKE_C_STANDARD_REQUIRED ON)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
endif()

View File

@ -403,8 +403,21 @@ QSize TorrentDelegate::sizeHint(QStyleOptionViewItem const& option, Torrent cons
QSize TorrentDelegate::sizeHint(QStyleOptionViewItem const& option, QModelIndex const& index) const
{
Torrent const* tor(index.data(TorrentModel::TorrentRole).value<Torrent const*>());
return sizeHint(option, *tor);
// if the font changed, invalidate the height cache
if (myHeightFont != option.font)
{
myHeightFont = option.font;
myHeightHint.reset();
}
// ensure the height is cached
if (!myHeightHint)
{
auto const* tor = index.data(TorrentModel::TorrentRole).value<Torrent const*>();
myHeightHint = sizeHint(option, *tor).height();
}
return QSize(option.rect.width(), *myHeightHint);
}
void TorrentDelegate::paint(QPainter* painter, QStyleOptionViewItem const& option, QModelIndex const& index) const

View File

@ -8,6 +8,8 @@
#pragma once
#include <optional>
#include <QStyledItemDelegate>
class QStyle;
@ -49,4 +51,8 @@ protected:
static QColor blueBack;
static QColor greenBack;
static QColor silverBack;
private:
mutable std::optional<int> myHeightHint;
mutable QFont myHeightFont;
};

View File

@ -11,7 +11,7 @@ unix: INSTALLS += man
man.path = /share/man/man1/
man.files = transmission-qt.1
CONFIG += qt thread link_pkgconfig c++11 warn_on
CONFIG += qt thread link_pkgconfig c++1z warn_on
QT += network dbus
win32:QT += winextras
PKGCONFIG = fontconfig libcurl openssl libevent
@ -39,8 +39,6 @@ unix: LIBS += -L$${EVENT_TOP}/lib -lz -lrt
win32:LIBS += -levent-2.0 -lws2_32 -lintl
win32:LIBS += -lidn -liconv -lwldap32 -liphlpapi
lessThan(QT_MAJOR_VERSION, 5) : *-g++* | *-clang* : QMAKE_CXXFLAGS += -std=gnu++11
TRANSLATIONS += translations/transmission_de.ts \
translations/transmission_en.ts \
translations/transmission_es.ts \