Fill PageEditTeam containers only when it is actually required:
authorunc0rr
Thu, 10 Oct 2013 15:05:51 +0400
changeset 9511 1be565d7b4b7
parent 9509 5b3f2ea156c9
child 9513 8cebd1870b2c
Fill PageEditTeam containers only when it is actually required: - Reduces frontend startup time for 20-25% on my test machine - Also reduces memory usage when the page hasn't been shown
QTfrontend/ui/page/pageeditteam.cpp
QTfrontend/ui/page/pageeditteam.h
--- a/QTfrontend/ui/page/pageeditteam.cpp	Wed Oct 09 20:25:16 2013 -0400
+++ b/QTfrontend/ui/page/pageeditteam.cpp	Thu Oct 10 15:05:51 2013 +0400
@@ -203,12 +203,18 @@
 {
     initPage();
 
-    QRegExp pngSuffix("\\.png$");
+    m_playerHash = "0000000000000000000000000000000000000000";
+    m_loaded = false;
+}
 
-    m_playerHash = "0000000000000000000000000000000000000000";
+void PageEditTeam::lazyLoad()
+{
+    if(m_loaded) return;
+    m_loaded = true;
+    qDebug("[LAZYNESS] PageEditTeam::lazyLoad()");
 
+    QRegExp pngSuffix("\\.png$");
     DataManager & dataMgr = DataManager::instance();
-
     QStringList list;
 
 
@@ -236,7 +242,7 @@
             pix = pix.copy(0, 0, 32, 32);
         QIcon icon(pix);
 
-        QString grave = QString(file).remove(pngSuffix);
+        QString grave = file.remove(pngSuffix);
 
         CBGrave->addItem(icon, grave);
     }
@@ -327,6 +333,8 @@
 void PageEditTeam::createTeam(const QString & name, const QString & playerHash)
 {
     m_playerHash = playerHash;
+    lazyLoad();
+
     HWTeam newTeam(name);
     loadTeam(newTeam);
 }
@@ -334,6 +342,8 @@
 void PageEditTeam::editTeam(const QString & name, const QString & playerHash)
 {
     m_playerHash = playerHash;
+    lazyLoad();
+
     HWTeam team(name);
     team.loadFromFile();
     loadTeam(team);
--- a/QTfrontend/ui/page/pageeditteam.h	Wed Oct 09 20:25:16 2013 -0400
+++ b/QTfrontend/ui/page/pageeditteam.h	Thu Oct 10 15:05:51 2013 +0400
@@ -66,6 +66,7 @@
         HWTeam data();
         QString m_playerHash;
         KeyBinder * binder;
+        bool m_loaded;
 
         QLayout * bodyLayoutDefinition();
         QLayout * footerLayoutDefinition();
@@ -78,6 +79,8 @@
         QPushButton * btnRandomTeam;
         QPushButton * btnTestSound;
 
+        void lazyLoad();
+
     private slots:
         void saveTeam();
         void setRandomNames();