QIcon::availableSizes(): don't return duplicates

QIcon::availableSizes() returned duplicate sizes when there are pixmaps
with a different dpi but same size. This is not useful and therefore
filter them out. Also rearrange the conditions a little bit to bail out
on wrong mode/state early.

Pick-to: 6.7
Task-number: QTBUG-119915
Change-Id: I9d18c78fc2a149a3a9eaaed67c6110979029705b
Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
bb10
Christian Ehrlicher 2023-12-14 13:54:05 +01:00
parent 742be5254c
commit c53b91cc12
1 changed files with 6 additions and 5 deletions

View File

@ -351,15 +351,16 @@ QSize QPixmapIconEngine::actualSize(const QSize &size, QIcon::Mode mode, QIcon::
QList<QSize> QPixmapIconEngine::availableSizes(QIcon::Mode mode, QIcon::State state)
{
QList<QSize> sizes;
for (int i = 0; i < pixmaps.size(); ++i) {
QPixmapIconEngineEntry &pe = pixmaps[i];
if (pe.size == QSize() && pe.pixmap.isNull()) {
for (QPixmapIconEngineEntry &pe : pixmaps) {
if (pe.mode != mode || pe.state != state)
continue;
if (pe.size.isEmpty() && pe.pixmap.isNull()) {
pe.pixmap = QPixmap(pe.fileName);
pe.size = pe.pixmap.size();
}
if (pe.mode == mode && pe.state == state && !pe.size.isEmpty())
if (!pe.size.isEmpty() && !sizes.contains(pe.size))
sizes.push_back(pe.size);
}
}
return sizes;
}