From e6be08b388706ade9520146a3455ce7bcb77f7d3 Mon Sep 17 00:00:00 2001 From: hjk <qtc-committer@nokia.com> Date: Wed, 10 Mar 2010 13:58:20 +0100 Subject: [PATCH] debugger: use ITextEditor in DebuggerManager The dependency was there for a while. No need to jump through hoops hoping to maintain a stand-alone debugger anymore. --- src/plugins/debugger/debuggermanager.cpp | 60 ++++++++++++------------ src/plugins/debugger/debuggerplugin.cpp | 11 +---- src/plugins/debugger/debuggerplugin.h | 2 +- 3 files changed, 32 insertions(+), 41 deletions(-) diff --git a/src/plugins/debugger/debuggermanager.cpp b/src/plugins/debugger/debuggermanager.cpp index ebe0b19660e..f2c26ed6585 100644 --- a/src/plugins/debugger/debuggermanager.cpp +++ b/src/plugins/debugger/debuggermanager.cpp @@ -186,6 +186,7 @@ DEBUGGER_EXPORT QDebug operator<<(QDebug str, const DebuggerStartParameters &p) using namespace Constants; using namespace Debugger::Internal; +using namespace TextEditor; static const QString tooltipIName = "tooltip"; @@ -863,12 +864,12 @@ BreakpointData *DebuggerManager::findBreakpoint(const QString &fileName, int lin void DebuggerManager::toggleBreakpoint() { - QString fileName; - int lineNumber = -1; - d->m_plugin->currentTextEditor(&fileName, &lineNumber); - if (lineNumber == -1) - return; - toggleBreakpoint(fileName, lineNumber); + ITextEditor *textEditor = d->m_plugin->currentTextEditor(); + QTC_ASSERT(textEditor, return); + QString fileName = textEditor->file()->fileName(); + int lineNumber = textEditor->currentLine(); + if (lineNumber >= 0) + toggleBreakpoint(fileName, lineNumber); } void DebuggerManager::toggleBreakpoint(const QString &fileName, int lineNumber) @@ -915,7 +916,8 @@ void DebuggerManager::attemptBreakpointSynchronization() d->m_engine->attemptBreakpointSynchronization(); } -void DebuggerManager::setToolTipExpression(const QPoint &mousePos, TextEditor::ITextEditor *editor, int cursorPos) +void DebuggerManager::setToolTipExpression(const QPoint &mousePos, + TextEditor::ITextEditor *editor, int cursorPos) { if (d->m_engine) d->m_engine->setToolTipExpression(mousePos, editor, cursorPos); @@ -933,34 +935,30 @@ static QString msgEngineNotAvailable(const char *engine) "which is disabled.").arg(QLatin1String(engine)); } -static IDebuggerEngine *debuggerEngineForToolChain(ProjectExplorer::ToolChain::ToolChainType tc) +static IDebuggerEngine *debuggerEngineForToolChain(int toolChainType) { - IDebuggerEngine *rc = 0; - switch (tc) { + switch (toolChainType) { //case ProjectExplorer::ToolChain::LinuxICC: case ProjectExplorer::ToolChain::MinGW: case ProjectExplorer::ToolChain::GCC: - rc = gdbEngine; - break; + return gdbEngine; case ProjectExplorer::ToolChain::MSVC: case ProjectExplorer::ToolChain::WINCE: - rc = winEngine; - break; + return winEngine; case ProjectExplorer::ToolChain::WINSCW: // S60 case ProjectExplorer::ToolChain::GCCE: case ProjectExplorer::ToolChain::RVCT_ARMV5: case ProjectExplorer::ToolChain::RVCT_ARMV6: case ProjectExplorer::ToolChain::RVCT_ARMV5_GNUPOC: case ProjectExplorer::ToolChain::GCCE_GNUPOC: - rc = gdbEngine; - break; + return gdbEngine; case ProjectExplorer::ToolChain::OTHER: case ProjectExplorer::ToolChain::UNKNOWN: case ProjectExplorer::ToolChain::INVALID: default: break; } - return rc; + return 0; } // Figure out the debugger type of an executable. Analyze executable @@ -988,8 +986,7 @@ static IDebuggerEngine *determineDebuggerEngine(const QString &executable, } */ - if (IDebuggerEngine *tce = debuggerEngineForToolChain( - static_cast<ProjectExplorer::ToolChain::ToolChainType>(toolChainType))) + if (IDebuggerEngine *tce = debuggerEngineForToolChain(toolChainType)) return tce; #ifndef Q_OS_WIN @@ -1024,8 +1021,7 @@ static IDebuggerEngine *determineDebuggerEngine(int /* pid */, int toolChainType, QString *errorMessage) { - if (IDebuggerEngine *tce = debuggerEngineForToolChain( - static_cast<ProjectExplorer::ToolChain::ToolChainType>(toolChainType))) + if (IDebuggerEngine *tce = debuggerEngineForToolChain(toolChainType)) return tce; #ifdef Q_OS_WIN // Preferably Windows debugger @@ -1380,9 +1376,10 @@ void DebuggerManager::interruptDebuggingRequest() void DebuggerManager::runToLineExec() { - QString fileName; - int lineNumber = -1; - d->m_plugin->currentTextEditor(&fileName, &lineNumber); + ITextEditor *textEditor = d->m_plugin->currentTextEditor(); + QTC_ASSERT(textEditor, return); + QString fileName = textEditor->file()->fileName(); + int lineNumber = textEditor->currentLine(); if (d->m_engine && !fileName.isEmpty()) { STATE_DEBUG(fileName << lineNumber); d->m_engine->runToLineExec(fileName, lineNumber); @@ -1391,10 +1388,10 @@ void DebuggerManager::runToLineExec() void DebuggerManager::runToFunctionExec() { - QString fileName; - int lineNumber = -1; - QObject *object = d->m_plugin->currentTextEditor(&fileName, &lineNumber); - QPlainTextEdit *ed = qobject_cast<QPlainTextEdit*>(object); + ITextEditor *textEditor = d->m_plugin->currentTextEditor(); + QTC_ASSERT(textEditor, return); + QString fileName = textEditor->file()->fileName(); + QPlainTextEdit *ed = qobject_cast<QPlainTextEdit*>(textEditor->widget()); if (!ed) return; QTextCursor cursor = ed->textCursor(); @@ -1423,9 +1420,10 @@ void DebuggerManager::runToFunctionExec() void DebuggerManager::jumpToLineExec() { - QString fileName; - int lineNumber = -1; - d->m_plugin->currentTextEditor(&fileName, &lineNumber); + ITextEditor *textEditor = d->m_plugin->currentTextEditor(); + QTC_ASSERT(textEditor, return); + QString fileName = textEditor->file()->fileName(); + int lineNumber = textEditor->currentLine(); if (d->m_engine && !fileName.isEmpty()) { STATE_DEBUG(fileName << lineNumber); d->m_engine->jumpToLineExec(fileName, lineNumber); diff --git a/src/plugins/debugger/debuggerplugin.cpp b/src/plugins/debugger/debuggerplugin.cpp index 12b0efc6416..ce648eb6b80 100644 --- a/src/plugins/debugger/debuggerplugin.cpp +++ b/src/plugins/debugger/debuggerplugin.cpp @@ -1033,20 +1033,13 @@ void DebuggerPlugin::activateDebugMode() modeManager->activateMode(QLatin1String(MODE_DEBUG)); } -QWidget *DebuggerPlugin::currentTextEditor(QString *fileName, int *lineNumber) +TextEditor::ITextEditor *DebuggerPlugin::currentTextEditor() { EditorManager *editorManager = EditorManager::instance(); if (!editorManager) return 0; Core::IEditor *editor = editorManager->currentEditor(); - ITextEditor *textEditor = qobject_cast<ITextEditor*>(editor); - if (!textEditor) - return 0; - if (fileName) - *fileName = textEditor->file()->fileName(); - if (lineNumber) - *lineNumber = textEditor->currentLine(); - return textEditor->widget(); + return qobject_cast<ITextEditor*>(editor); } void DebuggerPlugin::editorOpened(Core::IEditor *editor) diff --git a/src/plugins/debugger/debuggerplugin.h b/src/plugins/debugger/debuggerplugin.h index 58c96eaa8ab..d9b1bdcd68b 100644 --- a/src/plugins/debugger/debuggerplugin.h +++ b/src/plugins/debugger/debuggerplugin.h @@ -89,7 +89,7 @@ private: virtual void remoteCommand(const QStringList &options, const QStringList &arguments); QVariant configValue(const QString &name) const; - QWidget *currentTextEditor(QString *fileName, int *line); + TextEditor::ITextEditor *currentTextEditor(); QVariant sessionValue(const QString &name); void setSessionValue(const QString &name, const QVariant &value); QVariant configValue(const QString &name); -- GitLab