OSDN Git Service

use global static for icon engines interface
authorIvailo Monev <xakepa10@laimg.moc>
Sun, 7 Aug 2016 16:14:51 +0000 (16:14 +0000)
committerIvailo Monev <xakepa10@laimg.moc>
Sun, 7 Aug 2016 16:14:51 +0000 (16:14 +0000)
Signed-off-by: Ivailo Monev <xakepa10@laimg.moc>
src/gui/image/qiconloader.cpp
src/gui/image/qiconloader_p.h

index 7f34ff5..2fe17f5 100644 (file)
 QT_BEGIN_NAMESPACE
 
 Q_GLOBAL_STATIC(QIconLoader, iconLoaderInstance)
+#ifndef QT_NO_LIBRARY
+Q_GLOBAL_STATIC_WITH_ARGS(QFactoryLoader, loader,
+    (QIconEngineFactoryInterface_iid, QLatin1String("/iconengines"), Qt::CaseInsensitive))
+#endif
 
 /* Theme to use in last resort, if the theme does not have the icon, neither the parents  */
 static QString fallbackTheme()
@@ -88,30 +92,17 @@ static QString fallbackTheme()
 }
 
 QIconLoader::QIconLoader() :
-        m_themeKey(1), m_supportsSvg(false), m_initialized(false)
-{
-}
-
-// We lazily initialize the loader to make static icons
-// work. Though we do not officially support this.
-void QIconLoader::ensureInitialized()
+        m_themeKey(1), m_supportsSvg(false)
 {
-    if (!m_initialized) {
-        m_initialized = true;
+    Q_ASSERT(qApp);
 
-        Q_ASSERT(qApp);
-
-        m_systemTheme = qt_guiPlatformPlugin()->systemIconThemeName();
-        if (m_systemTheme.isEmpty())
-            m_systemTheme = fallbackTheme();
+    m_systemTheme = qt_guiPlatformPlugin()->systemIconThemeName();
+    if (m_systemTheme.isEmpty())
+        m_systemTheme = fallbackTheme();
 #ifndef QT_NO_LIBRARY
-        QFactoryLoader iconFactoryLoader(QIconEngineFactoryInterface_iid,
-                                         QLatin1String("/iconengines"),
-                                         Qt::CaseInsensitive);
-        if (iconFactoryLoader.keys().contains(QLatin1String("svg")))
-            m_supportsSvg = true;
+    if (loader()->keys().contains(QLatin1String("svg")))
+        m_supportsSvg = true;
 #endif //QT_NO_LIBRARY
-    }
 }
 
 QIconLoader *QIconLoader::instance()
@@ -352,9 +343,6 @@ bool QIconLoaderEngine::hasIcon() const
 // Lazily load the icon
 void QIconLoaderEngine::ensureLoaded()
 {
-
-    iconLoaderInstance()->ensureInitialized();
-
     if (!(iconLoaderInstance()->themeKey() == m_key)) {
 
         while (!m_entries.isEmpty())
index bee6baa..0608f0b 100644 (file)
@@ -167,7 +167,6 @@ public:
     static QIconLoader *instance();
     void updateSystemTheme();
     void invalidateKey() { m_themeKey++; }
-    void ensureInitialized();
 
 private:
     QThemeIconEntries findIconHelper(const QString &themeName,
@@ -175,7 +174,6 @@ private:
                                      QStringList &visited) const;
     uint m_themeKey;
     bool m_supportsSvg;
-    bool m_initialized;
 
     mutable QString m_userTheme;
     mutable QString m_systemTheme;