1. Ivan Andrianov
  2. surfer

Commits

Ivan Andrianov  committed beda124

Fixed closed tabs restoring:
- memory leak
- duplicates

committer: PayableOnDeath <>

  • Participants
  • Parent commits db80808
  • Branches default

Comments (0)

Files changed (3)

File src/tabmanager.cpp

View file
     m_tabWidget = tabWidget;
 }
 
-QList<QString> & TabManager::closedTabTitles()
+QList<QString> TabManager::closedTabTitles(int count)
 {
-    return m_closedTabTitles;
+    return m_closedTabTitles.mid(0, count);
 }
 
-QList<QIcon> & TabManager::closedTabIcons()
+QList<QIcon> TabManager::closedTabIcons(int count)
 {
-    return m_closedTabIcons;
+    return m_closedTabIcons.mid(0, count);
 }
 
 void TabManager::setCurrentTab(int index)
             m_closedTabs += tab;
             m_closedTabTitles += m_tabWidget->tabToolTip(index);
             m_closedTabIcons += m_tabWidget->tabIcon(index);
-            if(m_closedTabTitles.count() == 11)
-            {
-                m_closedTabs.removeFirst();
-                m_closedTabTitles.removeFirst();
-                m_closedTabIcons.removeFirst();
-            }
             m_tabWidget->removeTab(index);
         }
 
     if(index >= 0 && index < count)
     {
 
-        Tab * tab = m_closedTabs.at(count - index - 1);
-        QString title = m_closedTabTitles.at(count - index - 1);
+        Tab * tab = m_closedTabs.takeAt(count - index - 1);
+        QString title = m_closedTabTitles.takeAt(count - index - 1);
         QString toolTip = title;
         if(title.size() > 30)
         {
             title.truncate(27);
             title += "...";
         }
-        QIcon icon = m_closedTabIcons.at(count - index - 1);
+        QIcon icon = m_closedTabIcons.takeAt(count - index - 1);
         m_tabWidget->addTab(tab, icon, title);
         m_tabWidget->setTabToolTip(m_tabWidget->count() - 1, toolTip);
         m_tabWidget->setCurrentIndex(m_tabWidget->count() - 1);
 
 void TabManager::clearRestoreList()
 {
-    m_closedTabs.clear();
     m_closedTabTitles.clear();
     m_closedTabIcons.clear();
+    foreach(Tab * tab, m_closedTabs)
+    {
+        tab->deleteLater();
+    }
+    m_closedTabs.clear();
 }
 
 void TabManager::load()

File src/tabmanager.h

View file
 public:
     TabManager(QObject * parent = 0);
     void setTabWidget(QTabWidget * tabWidget);
-    QList<QString> & closedTabTitles();
-    QList<QIcon> & closedTabIcons();
+    QList<QString> closedTabTitles(int count);
+    QList<QIcon> closedTabIcons(int count);
 
 private:
     QTabWidget * m_tabWidget;

File src/toolbar.cpp

View file
 
     m_restoreMenu->clear();
 
-    QList<QString> titles = MainWindow::tabManager()->closedTabTitles();
-    QList<QIcon> icons = MainWindow::tabManager()->closedTabIcons();
+    QList<QString> titles = MainWindow::tabManager()->closedTabTitles(10);
+    QList<QIcon> icons = MainWindow::tabManager()->closedTabIcons(10);
     for(int i = titles.count() - 1; i >= 0; i--)
     {
         action = m_restoreMenu->addAction(icons.at(i), titles.at(i));