OSDN Git Service

Stop navigationwidget from going haywire
authorTobias Hunger <tobias.hunger@nokia.com>
Thu, 21 Oct 2010 09:54:11 +0000 (11:54 +0200)
committerTobias Hunger <tobias.hunger@nokia.com>
Thu, 21 Oct 2010 16:09:29 +0000 (18:09 +0200)
Stop navigationwidget from going haywire when faced with old
configuration data. This issue could lead to different effects:
 * A crash
 * Creator not being able to exit anymore
 * The sidebar being messed up

Task-number: QTCREATORBUG-2780
Reviewed-by: con
src/plugins/coreplugin/navigationwidget.cpp

index 1766774..30bcf48 100644 (file)
@@ -165,7 +165,6 @@ NavigationWidget::NavigationWidget(QAction *toggleSideBarAction) :
 {
     d->m_factoryModel->setSortRole(FactoryPriorityRole);
     setOrientation(Qt::Vertical);
-    insertSubItem(0, -1); // we don't have any entry to show yet
     d->m_instance = this;
 }
 
@@ -327,17 +326,22 @@ void NavigationWidget::restoreSettings(QSettings *settings)
         settings->setValue("Navigation/Version", 2);
     }
 
-    for (int i=0; i<viewIds.count(); ++i) {
-        const QString &view = viewIds.at(i);
-        int index = factoryIndex(view);
-
-        if (i >= d->m_subWidgets.size()) {
-            insertSubItem(i, index);
+    int position = 0;
+    foreach (const QString &id, viewIds) {
+        int index = factoryIndex(id);
+        if (index >= 0) {
+            // Only add if the id was actually found!
+            insertSubItem(position, index);
+            ++position;
         } else {
-            d->m_subWidgets.at(i)->setFactoryIndex(index);
+            restoreSplitterState = false;
         }
     }
 
+    if (d->m_subWidgets.isEmpty())
+        // Make sure we have at least the projects widget
+        insertSubItem(0, qMax(0, factoryIndex(QLatin1String("Projects"))));
+
     if (settings->contains("Navigation/Visible")) {
         setShown(settings->value("Navigation/Visible").toBool());
     } else {