summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorOlivier Goffart <ogoffart@woboq.com>2015-09-07 15:10:03 +0200
committerOlivier Goffart (Woboq GmbH) <ogoffart@woboq.com>2015-09-11 12:42:20 +0000
commitd3a21a18de73b70d0f20a36ae36439eac1f17ce4 (patch)
tree9b75c1cd1021d01880377cd399c6f5356ee87cbc /src
parent1464118b67a030d290eb14e7c6612202273e1366 (diff)
QIcon: add a new overload of QIcon that does not call availableSizes
This is done so icons from QIcon::fromTheme are loaded lazily and we do not pay for looking up icons that are never used [ChangeLog][QtGui][QIcon] Split fromTheme() in two different overload, one of which would only lazily lookup the icons, in order to speed up startup of applications that initialize many icons that are not necessarily visible. Change-Id: I2ba3aa3a0eae6c8f1ff041a0f5bbb10ad32e3991 Reviewed-by: Volker Krause <volker.krause@kdab.com> Reviewed-by: David Faure <david.faure@kdab.com>
Diffstat (limited to 'src')
-rw-r--r--src/gui/image/qicon.cpp31
-rw-r--r--src/gui/image/qicon.h3
2 files changed, 24 insertions, 10 deletions
diff --git a/src/gui/image/qicon.cpp b/src/gui/image/qicon.cpp
index ef039f0678..ee41efc3e7 100644
--- a/src/gui/image/qicon.cpp
+++ b/src/gui/image/qicon.cpp
@@ -1143,8 +1143,7 @@ QString QIcon::themeName()
\since 4.6
Returns the QIcon corresponding to \a name in the current
- icon theme. If no such icon is found in the current theme
- \a fallback is returned instead.
+ icon theme.
The latest version of the freedesktop icon specification and naming
specification can be obtained here:
@@ -1158,11 +1157,6 @@ QString QIcon::themeName()
\snippet code/src_gui_image_qicon.cpp 3
- Or if you want to provide a guaranteed fallback for platforms that
- do not support theme icons, you can use the second argument:
-
- \snippet code/src_gui_image_qicon.cpp 4
-
\note By default, only X11 will support themed icons. In order to
use themed icons on Mac and Windows, you will have to bundle a
compliant theme in one of your themeSearchPaths() and set the
@@ -1170,7 +1164,7 @@ QString QIcon::themeName()
\sa themeName(), setThemeName(), themeSearchPaths()
*/
-QIcon QIcon::fromTheme(const QString &name, const QIcon &fallback)
+QIcon QIcon::fromTheme(const QString &name)
{
QIcon icon;
@@ -1186,7 +1180,26 @@ QIcon QIcon::fromTheme(const QString &name, const QIcon &fallback)
qtIconCache()->insert(name, cachedIcon);
}
- if (qApp && icon.availableSizes().isEmpty())
+ return icon;
+}
+
+/*!
+ \overload
+
+ Returns the QIcon corresponding to \a name in the current
+ icon theme. If no such icon is found in the current theme
+ \a fallback is returned instead.
+
+ If you want to provide a guaranteed fallback for platforms that
+ do not support theme icons, you can use the second argument:
+
+ \snippet code/src_gui_image_qicon.cpp 4
+*/
+QIcon QIcon::fromTheme(const QString &name, const QIcon &fallback)
+{
+ QIcon icon = fromTheme(name);
+
+ if (icon.isNull() || icon.availableSizes().isEmpty())
return fallback;
return icon;
diff --git a/src/gui/image/qicon.h b/src/gui/image/qicon.h
index ccddf69101..329ae3deb3 100644
--- a/src/gui/image/qicon.h
+++ b/src/gui/image/qicon.h
@@ -105,7 +105,8 @@ public:
void setIsMask(bool isMask);
bool isMask() const;
- static QIcon fromTheme(const QString &name, const QIcon &fallback = QIcon());
+ static QIcon fromTheme(const QString &name);
+ static QIcon fromTheme(const QString &name, const QIcon &fallback);
static bool hasThemeIcon(const QString &name);
static QStringList themeSearchPaths();