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:
parent
973afda057
commit
2cc5cfe3e3
|
@ -378,12 +378,12 @@ endif()
|
||||||
if(CMAKE_VERSION VERSION_LESS "3.1")
|
if(CMAKE_VERSION VERSION_LESS "3.1")
|
||||||
if(CMAKE_C_COMPILER_ID STREQUAL "GNU" OR CMAKE_C_COMPILER_ID STREQUAL "Clang")
|
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_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()
|
endif()
|
||||||
else()
|
else()
|
||||||
set(CMAKE_C_STANDARD 99)
|
set(CMAKE_C_STANDARD 99)
|
||||||
set(CMAKE_C_STANDARD_REQUIRED ON)
|
set(CMAKE_C_STANDARD_REQUIRED ON)
|
||||||
set(CMAKE_CXX_STANDARD 11)
|
set(CMAKE_CXX_STANDARD 17)
|
||||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
|
|
@ -403,8 +403,21 @@ QSize TorrentDelegate::sizeHint(QStyleOptionViewItem const& option, Torrent cons
|
||||||
|
|
||||||
QSize TorrentDelegate::sizeHint(QStyleOptionViewItem const& option, QModelIndex const& index) const
|
QSize TorrentDelegate::sizeHint(QStyleOptionViewItem const& option, QModelIndex const& index) const
|
||||||
{
|
{
|
||||||
Torrent const* tor(index.data(TorrentModel::TorrentRole).value<Torrent const*>());
|
// if the font changed, invalidate the height cache
|
||||||
return sizeHint(option, *tor);
|
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
|
void TorrentDelegate::paint(QPainter* painter, QStyleOptionViewItem const& option, QModelIndex const& index) const
|
||||||
|
|
|
@ -8,6 +8,8 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <optional>
|
||||||
|
|
||||||
#include <QStyledItemDelegate>
|
#include <QStyledItemDelegate>
|
||||||
|
|
||||||
class QStyle;
|
class QStyle;
|
||||||
|
@ -49,4 +51,8 @@ protected:
|
||||||
static QColor blueBack;
|
static QColor blueBack;
|
||||||
static QColor greenBack;
|
static QColor greenBack;
|
||||||
static QColor silverBack;
|
static QColor silverBack;
|
||||||
|
|
||||||
|
private:
|
||||||
|
mutable std::optional<int> myHeightHint;
|
||||||
|
mutable QFont myHeightFont;
|
||||||
};
|
};
|
||||||
|
|
|
@ -11,7 +11,7 @@ unix: INSTALLS += man
|
||||||
man.path = /share/man/man1/
|
man.path = /share/man/man1/
|
||||||
man.files = transmission-qt.1
|
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
|
QT += network dbus
|
||||||
win32:QT += winextras
|
win32:QT += winextras
|
||||||
PKGCONFIG = fontconfig libcurl openssl libevent
|
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 += -levent-2.0 -lws2_32 -lintl
|
||||||
win32:LIBS += -lidn -liconv -lwldap32 -liphlpapi
|
win32:LIBS += -lidn -liconv -lwldap32 -liphlpapi
|
||||||
|
|
||||||
lessThan(QT_MAJOR_VERSION, 5) : *-g++* | *-clang* : QMAKE_CXXFLAGS += -std=gnu++11
|
|
||||||
|
|
||||||
TRANSLATIONS += translations/transmission_de.ts \
|
TRANSLATIONS += translations/transmission_de.ts \
|
||||||
translations/transmission_en.ts \
|
translations/transmission_en.ts \
|
||||||
translations/transmission_es.ts \
|
translations/transmission_es.ts \
|
||||||
|
|
Loading…
Reference in New Issue