From 045e6dd1b4e97e5e79ec60db85e81616275fb770 Mon Sep 17 00:00:00 2001
From: hjk <qtc-committer@nokia.com>
Date: Mon, 8 Dec 2008 11:00:46 +0100
Subject: [PATCH] simplify WatchWindow expansion handling a bit

---
 src/plugins/debugger/watchhandler.cpp |  7 ++++
 src/plugins/debugger/watchhandler.h   |  2 +-
 src/plugins/debugger/watchwindow.cpp  | 52 +++------------------------
 src/plugins/debugger/watchwindow.h    |  4 ---
 4 files changed, 13 insertions(+), 52 deletions(-)

diff --git a/src/plugins/debugger/watchhandler.cpp b/src/plugins/debugger/watchhandler.cpp
index 1792e4705d6..1041c2edcc6 100644
--- a/src/plugins/debugger/watchhandler.cpp
+++ b/src/plugins/debugger/watchhandler.cpp
@@ -488,6 +488,13 @@ QVariant WatchHandler::data(const QModelIndex &idx, int role) const
         case VisualRole:
             return m_displayedINames.contains(data.iname);
     
+        case ExpandedRole:
+            //qDebug() << " FETCHING: " << data.iname
+            //    << m_expandedINames.contains(data.iname)
+            //    << m_expandedINames;
+            // Level 0 and 1 are always expanded
+            return node < 4 || m_expandedINames.contains(data.iname);
+    
         default:
             break; 
     }
diff --git a/src/plugins/debugger/watchhandler.h b/src/plugins/debugger/watchhandler.h
index 989b99b3d22..f27e167dc1b 100644
--- a/src/plugins/debugger/watchhandler.h
+++ b/src/plugins/debugger/watchhandler.h
@@ -135,7 +135,7 @@ public:
     bool changed;
 };
 
-enum { INameRole = Qt::UserRole, VisualRole };
+enum { INameRole = Qt::UserRole, VisualRole, ExpandedRole };
 
 
 class WatchHandler : public QAbstractItemModel
diff --git a/src/plugins/debugger/watchwindow.cpp b/src/plugins/debugger/watchwindow.cpp
index d528bf09242..f49b7073aef 100644
--- a/src/plugins/debugger/watchwindow.cpp
+++ b/src/plugins/debugger/watchwindow.cpp
@@ -46,7 +46,7 @@
 
 using namespace Debugger::Internal;
 
-enum { INameRole = Qt::UserRole, VisualRole };
+enum { INameRole = Qt::UserRole, VisualRole, ExpandedRole };
 
 /////////////////////////////////////////////////////////////////////
 //
@@ -75,8 +75,6 @@ void WatchWindow::expandNode(const QModelIndex &idx)
     //QModelIndex mi0 = idx.sibling(idx.row(), 0);
     //QString iname = model()->data(mi0, INameRole).toString();
     //QString name = model()->data(mi0, Qt::DisplayRole).toString();
-    //if (isExpanded(idx))
-    //    return;
     emit requestExpandChildren(idx);
 }
 
@@ -174,6 +172,7 @@ void WatchWindow::reset()
     QTreeView::reset(); 
     setRootIndex(model()->index(row, 0, model()->index(0, 0)));
     //setRootIndex(model()->index(0, 0));
+    resetHelper(model()->index(0, 0));
 }
 
 void WatchWindow::setModel(QAbstractItemModel *model)
@@ -185,57 +184,16 @@ void WatchWindow::setModel(QAbstractItemModel *model)
     header()->setResizeMode(QHeaderView::ResizeToContents);
     if (m_type != LocalsType)
         header()->hide();
-
-    connect(model, SIGNAL(modelAboutToBeReset()),
-        this, SLOT(modelAboutToBeReset()));
-    connect(model, SIGNAL(modelReset()),
-        this, SLOT(modelReset()));
-}
-
-void WatchWindow::modelAboutToBeReset()
-{
-    //qDebug() << "Model about to be reset";
-    m_expandedItems.clear();
-    m_expandedItems.insert("local");
-    m_expandedItems.insert("watch");
-    modelAboutToBeResetHelper(model()->index(0, 0));
-    //qDebug() << "   expanded: " << m_expandedItems;
-}
-
-void WatchWindow::modelAboutToBeResetHelper(const QModelIndex &idx)
-{
-    QString iname = model()->data(idx, INameRole).toString();
-    //qDebug() << "Model about to be reset helper" << iname << idx
-    //    << isExpanded(idx);
-    if (isExpanded(idx))
-        m_expandedItems.insert(iname);
-    for (int i = 0, n = model()->rowCount(idx); i != n; ++i) {
-        QModelIndex idx1 = model()->index(i, 0, idx);
-        modelAboutToBeResetHelper(idx1);
-    }
-}
-
-void WatchWindow::modelReset()
-{
-    collapseAll();
-    expand(model()->index(0, 0));
-    modelResetHelper(model()->index(0, 0));
 }
 
-void WatchWindow::modelResetHelper(const QModelIndex &idx)
+void WatchWindow::resetHelper(const QModelIndex &idx)
 {
-    QString name = model()->data(idx, Qt::DisplayRole).toString();
-    QString iname = model()->data(idx, INameRole).toString();
-    //qDebug() << "Model reset helper" << iname << name;
-    if (m_expandedItems.contains(iname)) {
+    if (model()->data(idx, ExpandedRole).toBool()) {
         expand(idx);
         for (int i = 0, n = model()->rowCount(idx); i != n; ++i) {
             QModelIndex idx1 = model()->index(i, 0, idx);
-            modelResetHelper(idx1);
+            resetHelper(idx1);
         }
-    } else {
-    //    if (!iname.isEmpty())
-    //        collapse(idx);
     }
 }
 
diff --git a/src/plugins/debugger/watchwindow.h b/src/plugins/debugger/watchwindow.h
index 8b9b5d13ae4..33aafe1d59b 100644
--- a/src/plugins/debugger/watchwindow.h
+++ b/src/plugins/debugger/watchwindow.h
@@ -72,20 +72,16 @@ private slots:
     void handleChangedItem(QWidget *);
     void expandNode(const QModelIndex &index);
     void collapseNode(const QModelIndex &index);
-    void modelAboutToBeReset();
-    void modelReset();
 
 private:
     void contextMenuEvent(QContextMenuEvent *ev);
     void editItem(const QModelIndex &idx);
     void reset(); /* reimpl */
 
-    void modelAboutToBeResetHelper(const QModelIndex &idx);
     void modelResetHelper(const QModelIndex &idx);
 
     bool m_alwaysResizeColumnsToContents;
     Type m_type;
-    QSet<QString> m_expandedItems;
 };
 
 
-- 
GitLab