From ccd37a6655ed1d840a553902120cdcf3e2119518 Mon Sep 17 00:00:00 2001
From: hjk <qtc-committer@nokia.com>
Date: Thu, 1 Oct 2009 11:22:44 +0200
Subject: [PATCH] debugger: make 'address column' in stack and breakpoint view
 optional

---
 src/plugins/debugger/breakhandler.cpp         | 16 +++++----
 src/plugins/debugger/breakhandler.h           |  7 ++--
 src/plugins/debugger/breakwindow.cpp          | 21 +++++++-----
 src/plugins/debugger/breakwindow.h            |  1 +
 src/plugins/debugger/commonoptionspage.ui     | 20 -----------
 src/plugins/debugger/debuggeractions.cpp      | 34 +++++++++++++++++++
 src/plugins/debugger/debuggeractions.h        |  9 +++--
 src/plugins/debugger/debuggerplugin.cpp       |  9 ++---
 src/plugins/debugger/stackhandler.h           |  4 +--
 src/plugins/debugger/stackwindow.cpp          | 32 ++++++-----------
 src/plugins/debugger/stackwindow.h            |  2 +-
 src/plugins/debugger/watchwindow.cpp          |  1 +
 .../qmleditor/parser/qmljsastvisitor.cpp      |  4 +--
 13 files changed, 88 insertions(+), 72 deletions(-)

diff --git a/src/plugins/debugger/breakhandler.cpp b/src/plugins/debugger/breakhandler.cpp
index a24f53f8e7d..e0b397fcef5 100644
--- a/src/plugins/debugger/breakhandler.cpp
+++ b/src/plugins/debugger/breakhandler.cpp
@@ -257,9 +257,8 @@ bool BreakpointData::conditionsMatch() const
 //////////////////////////////////////////////////////////////////
 
 BreakHandler::BreakHandler(DebuggerManager *manager, QObject *parent)
-    : QAbstractItemModel(parent), m_manager(manager)
-{
-}
+    : QAbstractTableModel(parent), m_manager(manager)
+{}
 
 BreakHandler::~BreakHandler()
 {
@@ -268,7 +267,7 @@ BreakHandler::~BreakHandler()
 
 int BreakHandler::columnCount(const QModelIndex &parent) const
 {
-    return parent.isValid() ? 0 : 6;
+    return parent.isValid() ? 0 : 7;
 }
 
 int BreakHandler::rowCount(const QModelIndex &parent) const
@@ -436,7 +435,7 @@ QVariant BreakHandler::headerData(int section,
     if (orientation == Qt::Horizontal && role == Qt::DisplayRole) {
         static QString headers[] = {
             tr("Number"),  tr("Function"), tr("File"), tr("Line"),
-            tr("Condition"), tr("Ignore")
+            tr("Condition"), tr("Ignore"), tr("Address")
         };
         return headers[section];
     }
@@ -505,10 +504,13 @@ QVariant BreakHandler::data(const QModelIndex &mi, int role) const
                 return data->pending ? data->ignoreCount : data->bpIgnoreCount;
             if (role == Qt::ToolTipRole)
                 return tr("Breakpoint will only be hit after being ignored so many times.");
+        case 6:
+            if (role == Qt::DisplayRole)
+                return data->bpAddress;
             break;
     }
     if (role == Qt::ToolTipRole)
-        return theDebuggerBoolSetting(UseToolTipsInLocalsView)
+        return theDebuggerBoolSetting(UseToolTipsInBreakpointsView)
                 ? data->toToolTip() : QVariant();
     return QVariant();
 }
@@ -519,7 +521,7 @@ Qt::ItemFlags BreakHandler::flags(const QModelIndex &mi) const
         //case 0:
         //    return Qt::ItemIsUserCheckable | Qt::ItemIsEnabled;
         default:
-            return  QAbstractItemModel::flags(mi);
+            return QAbstractTableModel::flags(mi);
     }
 }
 
diff --git a/src/plugins/debugger/breakhandler.h b/src/plugins/debugger/breakhandler.h
index 0e5fbbbfb11..75058ffc640 100644
--- a/src/plugins/debugger/breakhandler.h
+++ b/src/plugins/debugger/breakhandler.h
@@ -33,7 +33,7 @@
 #include <utils/qtcassert.h>
 
 #include <QtCore/QObject>
-#include <QtCore/QAbstractItemModel>
+#include <QtCore/QAbstractTableModel>
 
 namespace Debugger {
 class DebuggerManager;
@@ -109,7 +109,7 @@ public:
 //
 //////////////////////////////////////////////////////////////////
 
-class BreakHandler : public QAbstractItemModel
+class BreakHandler : public QAbstractTableModel
 {
     Q_OBJECT
 
@@ -158,9 +158,6 @@ private:
     int rowCount(const QModelIndex &parent) const;
     QVariant data(const QModelIndex &index, int role) const;
     bool setData(const QModelIndex &index, const QVariant &, int role);
-    QModelIndex parent(const QModelIndex &) const { return QModelIndex(); }
-    QModelIndex index(int row, int column, const QModelIndex &) const
-        { return createIndex(row, column); }
     QVariant headerData(int section, Qt::Orientation orientation, int role) const;
     Qt::ItemFlags flags(const QModelIndex &index) const;
 
diff --git a/src/plugins/debugger/breakwindow.cpp b/src/plugins/debugger/breakwindow.cpp
index d26e6ed01f9..46dc6faac71 100644
--- a/src/plugins/debugger/breakwindow.cpp
+++ b/src/plugins/debugger/breakwindow.cpp
@@ -93,6 +93,13 @@ BreakWindow::BreakWindow(QWidget *parent)
         this, SLOT(rowActivated(QModelIndex)));
     connect(act, SIGNAL(toggled(bool)),
         this, SLOT(setAlternatingRowColorsHelper(bool)));
+    connect(theDebuggerAction(UseAddressInBreakpointsView), SIGNAL(toggled(bool)),
+        this, SLOT(showAddressColumn(bool)));
+}
+
+void BreakWindow::showAddressColumn(bool on)
+{
+    setColumnHidden(6, !on);
 }
 
 static QModelIndexList normalizeIndexes(const QModelIndexList &list)
@@ -201,6 +208,8 @@ void BreakWindow::contextMenuEvent(QContextMenuEvent *ev)
     menu.addAction(breakAtFunctionAction);
     menu.addAction(breakAtMainAction);
     menu.addSeparator();
+    menu.addAction(theDebuggerAction(UseToolTipsInBreakpointsView));
+    menu.addAction(theDebuggerAction(UseAddressInBreakpointsView));
     menu.addAction(adjustColumnAction);
     menu.addAction(alwaysAdjustAction);
     menu.addSeparator();
@@ -300,10 +309,8 @@ void BreakWindow::editConditions(const QModelIndexList &list)
 
 void BreakWindow::resizeColumnsToContents()
 {
-    resizeColumnToContents(0);
-    resizeColumnToContents(1);
-    resizeColumnToContents(2);
-    resizeColumnToContents(3);
+    for (int i = model()->columnCount(); --i >= 0; )
+        resizeColumnToContents(i);
 }
 
 void BreakWindow::setAlwaysResizeColumnsToContents(bool on)
@@ -311,10 +318,8 @@ void BreakWindow::setAlwaysResizeColumnsToContents(bool on)
     m_alwaysResizeColumnsToContents = on;
     QHeaderView::ResizeMode mode = on 
         ? QHeaderView::ResizeToContents : QHeaderView::Interactive;
-    header()->setResizeMode(0, mode);
-    header()->setResizeMode(1, mode);
-    header()->setResizeMode(2, mode);
-    header()->setResizeMode(3, mode);
+    for (int i = model()->columnCount(); --i >= 0; )
+        header()->setResizeMode(i, mode);
 }
 
 void BreakWindow::rowActivated(const QModelIndex &idx)
diff --git a/src/plugins/debugger/breakwindow.h b/src/plugins/debugger/breakwindow.h
index 7518b9af4a6..18a39ba7ba2 100644
--- a/src/plugins/debugger/breakwindow.h
+++ b/src/plugins/debugger/breakwindow.h
@@ -56,6 +56,7 @@ signals:
 private slots:
     void rowActivated(const QModelIndex &index);
     void setAlternatingRowColorsHelper(bool on) { setAlternatingRowColors(on); }
+    void showAddressColumn(bool on);
 
 protected:
     void resizeEvent(QResizeEvent *ev);
diff --git a/src/plugins/debugger/commonoptionspage.ui b/src/plugins/debugger/commonoptionspage.ui
index 24551580597..04176b57dc3 100644
--- a/src/plugins/debugger/commonoptionspage.ui
+++ b/src/plugins/debugger/commonoptionspage.ui
@@ -52,26 +52,6 @@
         </property>
        </widget>
       </item>
-      <item>
-       <widget class="QCheckBox" name="checkBoxUseToolTipsInMainEditor">
-        <property name="toolTip">
-         <string>Checking this will enable tooltips for variable values during debugging. Since this can slow down debugging and does not provide reliable information as it does not use scope information, it is switched off by default.</string>
-        </property>
-        <property name="text">
-         <string>Use tooltips in locals view while debugging</string>
-        </property>
-       </widget>
-      </item>
-      <item>
-       <widget class="QCheckBox" name="checkBoxUseToolTipsInLocalsView">
-        <property name="toolTip">
-         <string>Checking this will enable tooltips for in the locals view during debugging.</string>
-        </property>
-        <property name="text">
-         <string>Use tooltips in main editor while debugging</string>
-        </property>
-       </widget>
-      </item>
       <item>
        <widget class="QCheckBox" name="checkBoxEnableReverseDebugging">
         <property name="text">
diff --git a/src/plugins/debugger/debuggeractions.cpp b/src/plugins/debugger/debuggeractions.cpp
index 5113a494c4c..6ef805bd96d 100644
--- a/src/plugins/debugger/debuggeractions.cpp
+++ b/src/plugins/debugger/debuggeractions.cpp
@@ -259,6 +259,10 @@ DebuggerSettings *DebuggerSettings::instance()
     item = new SavedAction(instance);
     item->setSettingsKey(debugModeGroup, QLatin1String("UseToolTips"));
     item->setText(tr("Use tooltips in main editor when debugging"));
+    item->setToolTip(tr("Checking this will enable tooltips for variable "
+        "values during debugging. Since this can slow down debugging and "
+        "does not provide reliable information as it does not use scope "
+        "information, it is switched off by default."));
     item->setCheckable(true);
     item->setDefaultValue(false);
     instance->insertItem(UseToolTipsInMainEditor, item);
@@ -266,11 +270,41 @@ DebuggerSettings *DebuggerSettings::instance()
     item = new SavedAction(instance);
     item->setSettingsKey(debugModeGroup, QLatin1String("UseToolTipsInLocalsView"));
     item->setText(tr("Use tooltips in locals view when debugging"));
+    item->setToolTip(tr("Checking this will enable tooltips in the locals "
+        "view during debugging."));
     item->setCheckable(true);
     item->setDefaultValue(false);
     instance->insertItem(UseToolTipsInLocalsView, item);
 
     item = new SavedAction(instance);
+    item->setSettingsKey(debugModeGroup, QLatin1String("UseToolTipsInBreakpointsView"));
+    item->setText(tr("Use tooltips in breakpoints view when debugging"));
+    item->setToolTip(tr("Checking this will enable tooltips in the breakpoints "
+        "view during debugging."));
+    item->setCheckable(true);
+    item->setDefaultValue(false);
+    instance->insertItem(UseToolTipsInBreakpointsView, item);
+
+    item = new SavedAction(instance);
+    item->setSettingsKey(debugModeGroup, QLatin1String("UseAddressInBreakpointsView"));
+    item->setText(tr("Show address data in breakpoints view when debugging"));
+    item->setToolTip(tr("Checking this will show a column with address "
+        "information in the breakpoint view during debugging."));
+    item->setCheckable(true);
+    item->setDefaultValue(false);
+    instance->insertItem(UseAddressInBreakpointsView, item);
+    item = new SavedAction(instance);
+
+    item = new SavedAction(instance);
+    item->setSettingsKey(debugModeGroup, QLatin1String("UseAddressInStackView"));
+    item->setText(tr("Show address data in stack view when debugging"));
+    item->setToolTip(tr("Checking this will show a column with address "
+        "information in the stack view during debugging."));
+    item->setCheckable(true);
+    item->setDefaultValue(false);
+    instance->insertItem(UseAddressInStackView, item);
+    item = new SavedAction(instance);
+
     item->setSettingsKey(debugModeGroup, QLatin1String("ListSourceFiles"));
     item->setText(tr("List source files"));
     item->setCheckable(true);
diff --git a/src/plugins/debugger/debuggeractions.h b/src/plugins/debugger/debuggeractions.h
index 0109baf74b7..d8c1966abde 100644
--- a/src/plugins/debugger/debuggeractions.h
+++ b/src/plugins/debugger/debuggeractions.h
@@ -85,6 +85,13 @@ enum DebuggerActionCode
     CustomDebuggingHelperLocation,
     DebugDebuggingHelpers,
     
+    UseToolTipsInMainEditor,
+    UseToolTipsInLocalsView,
+    UseToolTipsInBreakpointsView,
+    UseToolTipsInStackView,
+    UseAddressInBreakpointsView,
+    UseAddressInStackView,
+
     // Gdb
     GdbLocation,
     GdbEnvironment,
@@ -100,8 +107,6 @@ enum DebuggerActionCode
     WatchExpressionInWindow,
     RemoveWatchExpression,
     WatchPoint,
-    UseToolTipsInMainEditor,
-    UseToolTipsInLocalsView,
     AssignValue,
     AssignType,
 
diff --git a/src/plugins/debugger/debuggerplugin.cpp b/src/plugins/debugger/debuggerplugin.cpp
index 421eaeea4d4..d7e024b02ed 100644
--- a/src/plugins/debugger/debuggerplugin.cpp
+++ b/src/plugins/debugger/debuggerplugin.cpp
@@ -292,10 +292,11 @@ QWidget *CommonOptionsPage::createPage(QWidget *parent)
         m_ui.checkBoxUseMessageBoxForSignals);
     m_group.insert(theDebuggerAction(SkipKnownFrames),
         m_ui.checkBoxSkipKnownFrames);
-    m_group.insert(theDebuggerAction(UseToolTipsInMainEditor),
-        m_ui.checkBoxUseToolTipsInMainEditor);
-    m_group.insert(theDebuggerAction(UseToolTipsInLocalsView),
-        m_ui.checkBoxUseToolTipsInLocalsView);
+    m_group.insert(theDebuggerAction(UseToolTipsInMainEditor), 0);
+    m_group.insert(theDebuggerAction(UseToolTipsInLocalsView), 0);
+    m_group.insert(theDebuggerAction(UseToolTipsInBreakpointsView), 0);
+    m_group.insert(theDebuggerAction(UseAddressInBreakpointsView), 0);
+    m_group.insert(theDebuggerAction(UseAddressInStackView), 0);
     m_group.insert(theDebuggerAction(EnableReverseDebugging), 
         m_ui.checkBoxEnableReverseDebugging);
     m_group.insert(theDebuggerAction(MaximalStackDepth), 
diff --git a/src/plugins/debugger/stackhandler.h b/src/plugins/debugger/stackhandler.h
index 3fee2a5f872..7db40a263b3 100644
--- a/src/plugins/debugger/stackhandler.h
+++ b/src/plugins/debugger/stackhandler.h
@@ -32,7 +32,7 @@
 
 #include "stackframe.h"
 
-#include <QtCore/QAbstractTableModel>
+#include <QtCore/QAbstractItemModel>
 #include <QtCore/QObject>
 
 #include <QtGui/QIcon>
@@ -72,7 +72,7 @@ private:
     int rowCount(const QModelIndex &parent = QModelIndex()) const;
     int columnCount(const QModelIndex &parent = QModelIndex()) const;
     QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
-    QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
+    QVariant headerData(int section, Qt::Orientation orientation, int role) const;
     Qt::ItemFlags flags(const QModelIndex &index) const;
 
     QList<StackFrame> m_stackFrames;
diff --git a/src/plugins/debugger/stackwindow.cpp b/src/plugins/debugger/stackwindow.cpp
index 5450e20f5d7..9b94856deac 100644
--- a/src/plugins/debugger/stackwindow.cpp
+++ b/src/plugins/debugger/stackwindow.cpp
@@ -69,22 +69,13 @@ StackWindow::StackWindow(DebuggerManager *manager, QWidget *parent)
         this, SLOT(rowActivated(QModelIndex)));
     connect(act, SIGNAL(toggled(bool)),
         this, SLOT(setAlternatingRowColorsHelper(bool)));
+    connect(theDebuggerAction(UseAddressInStackView), SIGNAL(toggled(bool)),
+        this, SLOT(showAddressColumn(bool)));
 }
 
-void StackWindow::resizeEvent(QResizeEvent *event)
+void StackWindow::showAddressColumn(bool on)
 {
-/*
-    QHeaderView *hv = header();
-
-    int totalSize = event->size().width() - 120;
-    if (totalSize > 10) {
-        hv->resizeSection(0, 45);
-        hv->resizeSection(1, totalSize / 2);
-        hv->resizeSection(2, totalSize / 2);
-        hv->resizeSection(3, 55);
-    }
-*/
-    QTreeView::resizeEvent(event);
+    setColumnHidden(4, !on);
 }
 
 void StackWindow::rowActivated(const QModelIndex &index)
@@ -124,6 +115,9 @@ void StackWindow::contextMenuEvent(QContextMenuEvent *ev)
 
     menu.addSeparator();
 
+    //menu.addAction(theDebuggerAction(UseTooltipsInStackView));
+    menu.addAction(theDebuggerAction(UseAddressInStackView));
+
     QAction *actAdjust = menu.addAction(tr("Adjust column widths to contents"));
 
     QAction *actAlwaysAdjust =
@@ -171,10 +165,8 @@ void StackWindow::copyContentsToClipboard()
 
 void StackWindow::resizeColumnsToContents()
 {
-    resizeColumnToContents(0);
-    resizeColumnToContents(1);
-    resizeColumnToContents(2);
-    resizeColumnToContents(3);
+    for (int i = model()->columnCount(); --i >= 0; )
+        resizeColumnToContents(i);
 }
 
 void StackWindow::setAlwaysResizeColumnsToContents(bool on)
@@ -182,10 +174,8 @@ void StackWindow::setAlwaysResizeColumnsToContents(bool on)
     m_alwaysResizeColumnsToContents = on;
     QHeaderView::ResizeMode mode =
         on ? QHeaderView::ResizeToContents : QHeaderView::Interactive;
-    header()->setResizeMode(0, mode);
-    header()->setResizeMode(1, mode);
-    header()->setResizeMode(2, mode);
-    header()->setResizeMode(3, mode);
+    for (int i = model()->columnCount(); --i >= 0; )
+        header()->setResizeMode(i, mode);
 }
 
 } // namespace Internal
diff --git a/src/plugins/debugger/stackwindow.h b/src/plugins/debugger/stackwindow.h
index 52390bcc342..0256fbeee05 100644
--- a/src/plugins/debugger/stackwindow.h
+++ b/src/plugins/debugger/stackwindow.h
@@ -61,9 +61,9 @@ public slots:
 private slots:
     void rowActivated(const QModelIndex &index);
     void setAlternatingRowColorsHelper(bool on) { setAlternatingRowColors(on); }
+    void showAddressColumn(bool on);
 
 private:
-    void resizeEvent(QResizeEvent *ev);
     void contextMenuEvent(QContextMenuEvent *ev);
     void copyContentsToClipboard();
 
diff --git a/src/plugins/debugger/watchwindow.cpp b/src/plugins/debugger/watchwindow.cpp
index 1ee5871bbd2..ca5e6425b79 100644
--- a/src/plugins/debugger/watchwindow.cpp
+++ b/src/plugins/debugger/watchwindow.cpp
@@ -273,6 +273,7 @@ void WatchWindow::contextMenuEvent(QContextMenuEvent *ev)
     menu.addAction(theDebuggerAction(UseDebuggingHelpers));
 
     menu.addSeparator();
+    menu.addAction(theDebuggerAction(UseToolTipsInLocalsView));
     QAction *actAdjustColumnWidths =
         menu.addAction(tr("Adjust column widths to contents"));
     QAction *actAlwaysAdjustColumnWidth =
diff --git a/src/plugins/qmleditor/parser/qmljsastvisitor.cpp b/src/plugins/qmleditor/parser/qmljsastvisitor.cpp
index 642bcee26b9..d3a1d530682 100644
--- a/src/plugins/qmleditor/parser/qmljsastvisitor.cpp
+++ b/src/plugins/qmleditor/parser/qmljsastvisitor.cpp
@@ -41,7 +41,7 @@
 
 #include "qmljsastvisitor_p.h"
 
-QT_BEGIN_NAMESPACE
+QT_QML_BEGIN_NAMESPACE
 
 namespace QmlJS { namespace AST {
 
@@ -55,4 +55,4 @@ Visitor::~Visitor()
 
 } } // namespace QmlJS::AST
 
-QT_END_NAMESPACE
+QT_QML_END_NAMESPACE
-- 
GitLab