From d4aed1ae24a8d64d897447a329d0cc15899719d6 Mon Sep 17 00:00:00 2001
From: hjk <qtc-committer@nokia.com>
Date: Fri, 9 Apr 2010 15:19:10 +0200
Subject: [PATCH] debugger: refactoring of breakpoint creation

---
 src/plugins/debugger/breakhandler.cpp    | 21 +-------------
 src/plugins/debugger/breakhandler.h      |  2 +-
 src/plugins/debugger/debuggermanager.cpp | 36 ++++++++++++++++++------
 src/plugins/debugger/debuggermanager.h   |  1 -
 4 files changed, 29 insertions(+), 31 deletions(-)

diff --git a/src/plugins/debugger/breakhandler.cpp b/src/plugins/debugger/breakhandler.cpp
index 683117239c2..f1d1a0140a1 100644
--- a/src/plugins/debugger/breakhandler.cpp
+++ b/src/plugins/debugger/breakhandler.cpp
@@ -712,27 +712,8 @@ void BreakHandler::toggleBreakpointEnabled(const QString &fileName, int lineNumb
     toggleBreakpointEnabled(at(findBreakpoint(fileName, lineNumber)));
 }
 
-void BreakHandler::setBreakpoint(const QString &fileName, int lineNumber)
+void BreakHandler::appendBreakpoint(BreakpointData *data)
 {
-    QFileInfo fi(fileName);
-
-    BreakpointData *data = new BreakpointData(this);
-    if (lineNumber > 0) {
-        data->fileName = fileName;
-        data->lineNumber = QByteArray::number(lineNumber);
-        data->pending = true;
-        data->setMarkerFileName(fileName);
-        data->setMarkerLineNumber(lineNumber);
-    } else {
-        data->funcName = fileName;
-        data->lineNumber = 0;
-        data->pending = true;
-        // FIXME: Figure out in which disassembler view the Marker sits.
-        // Might be better to let the user code create the BreakpointData
-        // structure and insert it here.
-        data->setMarkerFileName(QString());
-        data->setMarkerLineNumber(0);
-    }
     append(data);
     emit layoutChanged();
     saveBreakpoints();
diff --git a/src/plugins/debugger/breakhandler.h b/src/plugins/debugger/breakhandler.h
index de7b751e701..638ec497c9e 100644
--- a/src/plugins/debugger/breakhandler.h
+++ b/src/plugins/debugger/breakhandler.h
@@ -157,7 +157,7 @@ public:
     QIcon pendingBreakPointIcon() const  { return m_pendingBreakPointIcon; }
 
 public slots:
-    void setBreakpoint(const QString &fileName, int lineNumber);
+    void appendBreakpoint(BreakpointData *data);
     void toggleBreakpointEnabled(BreakpointData *data);
     void toggleBreakpointEnabled(const QString &fileName, int lineNumber);
     void breakByFunction(const QString &functionName);
diff --git a/src/plugins/debugger/debuggermanager.cpp b/src/plugins/debugger/debuggermanager.cpp
index f776251580e..dea5e4f482b 100644
--- a/src/plugins/debugger/debuggermanager.cpp
+++ b/src/plugins/debugger/debuggermanager.cpp
@@ -899,6 +899,31 @@ void DebuggerManager::toggleBreakpoint()
         toggleBreakpoint(fileName, lineNumber);
 }
 
+// FIXME: move further up the plugin where there's more specific context
+// information available.
+static BreakpointData *createBreakpointByFileAndLine
+    (const QString &fileName, int lineNumber, BreakHandler *handler)
+{
+    BreakpointData *data = new BreakpointData(handler);
+    if (lineNumber > 0) {
+        data->fileName = fileName;
+        data->lineNumber = QByteArray::number(lineNumber);
+        data->pending = true;
+        data->setMarkerFileName(fileName);
+        data->setMarkerLineNumber(lineNumber);
+    } else {
+        data->funcName = fileName;
+        data->lineNumber = 0;
+        data->pending = true;
+        // FIXME: Figure out in which disassembler view the Marker sits.
+        // Might be better to let the user code create the BreakpointData
+        // structure and insert it here.
+        data->setMarkerFileName(QString());
+        data->setMarkerLineNumber(0);
+    }
+    return data;
+}
+
 void DebuggerManager::toggleBreakpoint(const QString &fileName, int lineNumber)
 {
     STATE_DEBUG(fileName << lineNumber);
@@ -913,7 +938,8 @@ void DebuggerManager::toggleBreakpoint(const QString &fileName, int lineNumber)
 
     int index = d->m_breakHandler->findBreakpoint(fileName, lineNumber);
     if (index == -1)
-        d->m_breakHandler->setBreakpoint(fileName, lineNumber);
+        d->m_breakHandler->appendBreakpoint(
+            createBreakpointByFileAndLine(fileName, lineNumber, d->m_breakHandler));
     else
         d->m_breakHandler->removeBreakpoint(index);
 
@@ -1339,14 +1365,6 @@ void DebuggerManager::addToWatchWindow()
         d->m_watchHandler->watchExpression(exp);
 }
 
-void DebuggerManager::setBreakpoint(const QString &fileName, int lineNumber)
-{
-    STATE_DEBUG(Q_FUNC_INFO << fileName << lineNumber);
-    QTC_ASSERT(d->m_breakHandler, return);
-    d->m_breakHandler->setBreakpoint(fileName, lineNumber);
-    attemptBreakpointSynchronization();
-}
-
 void DebuggerManager::breakByFunctionMain()
 {
 #ifdef Q_OS_WIN
diff --git a/src/plugins/debugger/debuggermanager.h b/src/plugins/debugger/debuggermanager.h
index b1e5dd2b542..955ca1aa4b2 100644
--- a/src/plugins/debugger/debuggermanager.h
+++ b/src/plugins/debugger/debuggermanager.h
@@ -219,7 +219,6 @@ public slots:
     void toggleBreakpoint();
     void breakByFunction(const QString &functionName);
     void breakByFunctionMain();
-    void setBreakpoint(const QString &fileName, int lineNumber);
     void activateFrame(int index);
     void selectThread(int index);
     void activateSnapshot(int index);
-- 
GitLab