diff --git a/src/plugins/debugger/debugger.pro b/src/plugins/debugger/debugger.pro index a87cf96ca3282f1eb4ab4cd93edc5bd2e14d182a..fdcd141aa532668963de458ee786840cfefbff48 100644 --- a/src/plugins/debugger/debugger.pro +++ b/src/plugins/debugger/debugger.pro @@ -37,6 +37,7 @@ HEADERS += attachexternaldialog.h \ scriptengine.h \ stackhandler.h \ stackwindow.h \ + sourcefileswindow.h \ startexternaldialog.h \ threadswindow.h \ watchhandler.h \ @@ -64,6 +65,7 @@ SOURCES += attachexternaldialog.cpp \ scriptengine.cpp \ stackhandler.cpp \ stackwindow.cpp \ + sourcefileswindow.cpp \ startexternaldialog.cpp \ threadswindow.cpp \ watchhandler.cpp \ diff --git a/src/plugins/debugger/debuggermanager.cpp b/src/plugins/debugger/debuggermanager.cpp index 9130d57c54b847e7d8d45ed066d019cf9cbe599f..769d63c72289864334c3652443ce314ebbbd33bd 100644 --- a/src/plugins/debugger/debuggermanager.cpp +++ b/src/plugins/debugger/debuggermanager.cpp @@ -42,6 +42,7 @@ #include "moduleswindow.h" #include "registerwindow.h" #include "stackwindow.h" +#include "sourcefileswindow.h" #include "threadswindow.h" #include "watchwindow.h" @@ -165,6 +166,7 @@ void DebuggerManager::init() m_outputWindow = new DebuggerOutputWindow; m_registerWindow = new RegisterWindow; m_stackWindow = new StackWindow; + m_sourceFilesWindow = new SourceFilesWindow; m_threadsWindow = new ThreadsWindow; m_localsWindow = new WatchWindow(WatchWindow::LocalsType); m_watchersWindow = new WatchWindow(WatchWindow::WatchersType); @@ -227,6 +229,13 @@ void DebuggerManager::init() connect(modulesView, SIGNAL(loadAllSymbolsRequested()), this, SLOT(loadAllSymbols())); + // Source Files + //m_sourceFilesHandler = new SourceFilesHandler; + QAbstractItemView *sourceFilesView = + qobject_cast<QAbstractItemView *>(m_sourceFilesWindow); + //sourceFileView->setModel(m_stackHandler->stackModel()); + connect(sourceFilesView, SIGNAL(reloadSourceFilesRequested()), + this, SLOT(reloadSourceFiles())); // Registers QAbstractItemView *registerView = @@ -403,6 +412,10 @@ void DebuggerManager::init() m_stackDock = createDockForWidget(m_stackWindow); + m_sourceFilesDock = createDockForWidget(m_sourceFilesWindow); + connect(m_sourceFilesDock->toggleViewAction(), SIGNAL(toggled(bool)), + this, SLOT(reloadSourceFiles()), Qt::QueuedConnection); + m_threadsDock = createDockForWidget(m_threadsWindow); setStatus(DebuggerProcessNotReady); @@ -1240,6 +1253,26 @@ void DebuggerManager::disassemblerDockToggled(bool on) } +////////////////////////////////////////////////////////////////////// +// +// Sourec files specific stuff +// +////////////////////////////////////////////////////////////////////// + +void DebuggerManager::reloadSourceFiles() +{ + if (!m_sourceFilesDock || !m_sourceFilesDock->isVisible()) + return; + m_engine->reloadSourceFiles(); +} + +void DebuggerManager::sourceFilesDockToggled(bool on) +{ + if (on) + reloadSourceFiles(); +} + + ////////////////////////////////////////////////////////////////////// // // Modules specific stuff diff --git a/src/plugins/debugger/debuggermanager.h b/src/plugins/debugger/debuggermanager.h index 636187d68cda6491617133e64822f2c6edf6ad09..fd5c06e4c6e8bdf10186eeebd20583e596e33063 100644 --- a/src/plugins/debugger/debuggermanager.h +++ b/src/plugins/debugger/debuggermanager.h @@ -66,6 +66,7 @@ class RegisterHandler; class StackHandler; class ThreadsHandler; class WatchHandler; +class SourceFilesWindow; class WatchData; class BreakpointData; @@ -166,6 +167,7 @@ private: virtual StackHandler *stackHandler() = 0; virtual ThreadsHandler *threadsHandler() = 0; virtual WatchHandler *watchHandler() = 0; + virtual SourceFilesWindow *sourceFileWindow() = 0; virtual void showApplicationOutput(const QString &data) = 0; virtual bool skipKnownFrames() const = 0; @@ -179,6 +181,7 @@ private: virtual void reloadDisassembler() = 0; virtual void reloadModules() = 0; + virtual void reloadSourceFiles() = 0; virtual void reloadRegisters() = 0; }; @@ -302,6 +305,9 @@ private slots: void reloadDisassembler(); void disassemblerDockToggled(bool on); + void reloadSourceFiles(); + void sourceFilesDockToggled(bool on); + void reloadModules(); void modulesDockToggled(bool on); void loadSymbols(const QString &moduleName); @@ -323,6 +329,7 @@ private: StackHandler *stackHandler() { return m_stackHandler; } ThreadsHandler *threadsHandler() { return m_threadsHandler; } WatchHandler *watchHandler() { return m_watchHandler; } + SourceFilesWindow *sourceFileWindow() { return m_sourceFilesWindow; } bool skipKnownFrames() const; bool debugDumpers() const; @@ -416,6 +423,7 @@ private: QDockWidget *m_outputDock; QDockWidget *m_registerDock; QDockWidget *m_stackDock; + QDockWidget *m_sourceFilesDock; QDockWidget *m_threadsDock; QDockWidget *m_watchDock; QList<QDockWidget*> m_dockWidgets; @@ -427,6 +435,7 @@ private: StackHandler *m_stackHandler; ThreadsHandler *m_threadsHandler; WatchHandler *m_watchHandler; + SourceFilesWindow *m_sourceFilesWindow; /// Actions friend class DebuggerPlugin; diff --git a/src/plugins/debugger/gdbengine.cpp b/src/plugins/debugger/gdbengine.cpp index a9df09e5e93ebe34b416f3d1ef58e10c89137241..4c01fb756ead5ee3cd1b782465080641e5d3e95b 100644 --- a/src/plugins/debugger/gdbengine.cpp +++ b/src/plugins/debugger/gdbengine.cpp @@ -44,6 +44,7 @@ #include "registerhandler.h" #include "stackhandler.h" #include "watchhandler.h" +#include "sourcefileswindow.h" #include "startexternaldialog.h" #include "attachexternaldialog.h" @@ -986,6 +987,7 @@ void GdbEngine::handleQueryPwd(const GdbResultRecord &record) void GdbEngine::handleQuerySources(const GdbResultRecord &record) { if (record.resultClass == GdbResultDone) { + QMap<QString, QString> oldShortToFull = m_shortToFullName; m_shortToFullName.clear(); m_fullToShortName.clear(); // "^done,files=[{file="../../../../bin/gdbmacros/gdbmacros.cpp", @@ -1004,6 +1006,8 @@ void GdbEngine::handleQuerySources(const GdbResultRecord &record) m_fullToShortName[full] = fileName; } } + if (m_shortToFullName != oldShortToFull) + qq->sourceFileWindow()->setSourceFiles(m_shortToFullName); } } @@ -1128,7 +1132,7 @@ void GdbEngine::handleAsyncOutput(const GdbMi &data) #if defined(Q_OS_MAC) sendCommand("info pid", GdbInfoProc, QVariant(), true); #endif - sendCommand("-file-list-exec-source-files", GdbQuerySources); + reloadSourceFiles(); tryLoadCustomDumpers(); // intentionally after tryLoadCustomDumpers(), @@ -1262,7 +1266,7 @@ void GdbEngine::handleAsyncOutput(const GdbMi &data) frame.findChild("func").data() + '%'; QApplication::alert(q->mainWindow(), 3000); - sendCommand("-file-list-exec-source-files", GdbQuerySources); + reloadSourceFiles(); sendCommand("-break-list", BreakList); QVariant var = QVariant::fromValue<GdbMi>(data); sendCommand("p 0", GdbAsyncOutput2, var); // dummy @@ -2317,6 +2321,18 @@ void GdbEngine::handleModulesList(const GdbResultRecord &record) } +////////////////////////////////////////////////////////////////////// +// +// Source files specific stuff +// +////////////////////////////////////////////////////////////////////// + +void GdbEngine::reloadSourceFiles() +{ + sendCommand("-file-list-exec-source-files", GdbQuerySources); +} + + ////////////////////////////////////////////////////////////////////// // // Stack specific stuff @@ -2546,7 +2562,7 @@ bool GdbEngine::supportsThreads() const static WatchData m_toolTip; static QString m_toolTipExpression; static QPoint m_toolTipPos; -static QHash<QString, WatchData> m_toolTipCache; +static QMap<QString, WatchData> m_toolTipCache; static bool hasLetterOrNumber(const QString &exp) { @@ -3672,7 +3688,7 @@ void GdbEngine::handleStackListLocals(const GdbResultRecord &record) void GdbEngine::setLocals(const QList<GdbMi> &locals) { //qDebug() << m_varToType; - QHash<QString, int> seen; + QMap<QString, int> seen; foreach (const GdbMi &item, locals) { // Local variables of inlined code are reported as diff --git a/src/plugins/debugger/gdbengine.h b/src/plugins/debugger/gdbengine.h index 0b59af8b1c76398dd3835a30645ac5d4a1591ef6..43b87b873c8f51b28accef6d05716de1bcf8667f 100644 --- a/src/plugins/debugger/gdbengine.h +++ b/src/plugins/debugger/gdbengine.h @@ -222,8 +222,8 @@ private: int m_gdbVersion; // 6.8.0 is 680 // awful hack to keep track of used files - QHash<QString, QString> m_shortToFullName; - QHash<QString, QString> m_fullToShortName; + QMap<QString, QString> m_shortToFullName; + QMap<QString, QString> m_fullToShortName; // // Breakpoint specific stuff @@ -263,6 +263,10 @@ private: void handleRegisterListNames(const GdbResultRecord &record); void handleRegisterListValues(const GdbResultRecord &record); + // + // Source file specific stuff + // + void reloadSourceFiles(); // // Stack specific stuff diff --git a/src/plugins/debugger/idebuggerengine.h b/src/plugins/debugger/idebuggerengine.h index ee1e15793f3bc564c25089cd91f120cbd3b902e9..6da7ecb15edabf0f1d35f45b289ec9f19a840974 100644 --- a/src/plugins/debugger/idebuggerengine.h +++ b/src/plugins/debugger/idebuggerengine.h @@ -87,6 +87,8 @@ public: virtual void reloadRegisters() = 0; virtual void setDebugDumpers(bool on) = 0; virtual void setUseCustomDumpers(bool on) = 0; + + virtual void reloadSourceFiles() = 0; }; } // namespace Internal diff --git a/src/plugins/debugger/scriptengine.h b/src/plugins/debugger/scriptengine.h index b7f37f2cc67b8a8372ec959e35c08dd219583cd3..8368d367e825aa7adcbf0be7da496d05e5b768b0 100644 --- a/src/plugins/debugger/scriptengine.h +++ b/src/plugins/debugger/scriptengine.h @@ -112,6 +112,7 @@ private: void reloadDisassembler(); void reloadModules(); void reloadRegisters() {} + void reloadSourceFiles() {} bool supportsThreads() const { return true; } void maybeBreakNow(bool byFunction); diff --git a/src/plugins/debugger/sourcefileswindow.cpp b/src/plugins/debugger/sourcefileswindow.cpp new file mode 100644 index 0000000000000000000000000000000000000000..17b68a1c775af4cbf225b78a2856f3563f79d1e0 --- /dev/null +++ b/src/plugins/debugger/sourcefileswindow.cpp @@ -0,0 +1,213 @@ +/*************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Qt Software Information (qt-info@nokia.com) +** +** +** Non-Open Source Usage +** +** Licensees may use this file in accordance with the Qt Beta Version +** License Agreement, Agreement version 2.2 provided with the Software or, +** alternatively, in accordance with the terms contained in a written +** agreement between you and Nokia. +** +** GNU General Public License Usage +** +** Alternatively, this file may be used under the terms of the GNU General +** Public License versions 2.0 or 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the packaging +** of this file. Please review the following information to ensure GNU +** General Public Licensing requirements will be met: +** +** http://www.fsf.org/licensing/licenses/info/GPLv2.html and +** http://www.gnu.org/copyleft/gpl.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt GPL Exception +** version 1.3, included in the file GPL_EXCEPTION.txt in this package. +** +***************************************************************************/ + +#include "sourcefileswindow.h" + +#include <QDebug> +#include <QAction> +#include <QComboBox> +#include <QFileInfo> +#include <QDebug> +#include <QHeaderView> +#include <QMenu> +#include <QResizeEvent> +#include <QTreeView> +#include <QSortFilterProxyModel> +#include <QVBoxLayout> + +using Debugger::Internal::SourceFilesWindow; +using Debugger::Internal::SourceFilesModel; + +////////////////////////////////////////////////////////////////// +// +// SourceFilesModel +// +////////////////////////////////////////////////////////////////// + +class Debugger::Internal::SourceFilesModel : public QAbstractItemModel +{ +public: + SourceFilesModel(QObject *parent = 0) : QAbstractItemModel(parent) {} + + // QAbstractItemModel + int columnCount(const QModelIndex &parent) const + { return parent.isValid() ? 0 : 2; } + int rowCount(const QModelIndex &parent) const + { return parent.isValid() ? 0 : m_shortNames.size(); } + 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; + QVariant data(const QModelIndex &index, int role) const; + bool setData(const QModelIndex &index, const QVariant &value, int role); + Qt::ItemFlags flags(const QModelIndex &index) const; + + void clearModel(); + void update() { reset(); } + void setSourceFiles(const QMap<QString, QString> &sourceFiles); + +public: + QStringList m_shortNames; + QStringList m_fullNames; +}; + +void SourceFilesModel::clearModel() +{ + if (m_shortNames.isEmpty()) + return; + m_shortNames.clear(); + m_fullNames.clear(); + reset(); +} + +QVariant SourceFilesModel::headerData(int section, + Qt::Orientation orientation, int role) const +{ + if (orientation == Qt::Horizontal && role == Qt::DisplayRole) { + static QString headers[] = { + tr("Internal name") + " ", + tr("Full name") + " ", + }; + return headers[section]; + } + return QVariant(); +} + +Qt::ItemFlags SourceFilesModel::flags(const QModelIndex &index) const +{ + if (index.row() >= m_fullNames.size()) + return 0; + QFileInfo fi(m_fullNames.at(index.row())); + return fi.isReadable() ? QAbstractItemModel::flags(index) : Qt::ItemFlags(0); +} + +QVariant SourceFilesModel::data(const QModelIndex &index, int role) const +{ + //static const QIcon icon(":/gdbdebugger/images/breakpoint.svg"); + //static const QIcon icon2(":/gdbdebugger/images/breakpoint_pending.svg"); + + int row = index.row(); + if (row < 0 || row >= m_shortNames.size()) + return QVariant(); + + switch (index.column()) { + case 0: + if (role == Qt::DisplayRole) + return m_shortNames.at(row); + // FIXME: add icons + //if (role == Qt::DecorationRole) + // return module.symbolsRead ? icon2 : icon; + break; + case 1: + if (role == Qt::DisplayRole) + return m_fullNames.at(row); + //if (role == Qt::DecorationRole) + // return module.symbolsRead ? icon2 : icon; + break; + } + return QVariant(); +} + +bool SourceFilesModel::setData(const QModelIndex &index, const QVariant &value, int role) +{ + return QAbstractItemModel::setData(index, value, role); +} + +void SourceFilesModel::setSourceFiles(const QMap<QString, QString> &sourceFiles) +{ + m_shortNames.clear(); + m_fullNames.clear(); + QMap<QString, QString>::ConstIterator it = sourceFiles.begin(); + QMap<QString, QString>::ConstIterator et = sourceFiles.end(); + for (; it != et; ++it) { + m_shortNames.append(it.key()); + m_fullNames.append(it.value()); + } + reset(); +} + +////////////////////////////////////////////////////////////////// +// +// SourceFilesWindow +// +////////////////////////////////////////////////////////////////// + +SourceFilesWindow::SourceFilesWindow(QWidget *parent) + : QTreeView(parent) +{ + m_model = new SourceFilesModel(this); + + QSortFilterProxyModel *proxyModel = new QSortFilterProxyModel(this); + proxyModel->setSourceModel(m_model); + setModel(proxyModel); + + setWindowTitle(tr("Source Files")); + setSortingEnabled(true); + setAlternatingRowColors(true); + setRootIsDecorated(false); + setIconSize(QSize(10, 10)); + //header()->setDefaultAlignment(Qt::AlignLeft); + + connect(this, SIGNAL(activated(QModelIndex)), + this, SLOT(sourceFileActivated(QModelIndex))); +} + +SourceFilesWindow::~SourceFilesWindow() +{ +} + +void SourceFilesWindow::sourceFileActivated(const QModelIndex &index) +{ + qDebug() << "ACTIVATED: " << index.row() << index.column(); +} + +void SourceFilesWindow::contextMenuEvent(QContextMenuEvent *ev) +{ + QMenu menu; + QAction *act1 = new QAction(tr("Reload data"), &menu); + //act1->setCheckable(true); + + menu.addAction(act1); + + QAction *act = menu.exec(ev->globalPos()); + + if (act == act1) { + emit reloadSourceFilesRequested(); + } +} + +void SourceFilesWindow::setSourceFiles(const QMap<QString, QString> &sourceFiles) +{ + m_model->setSourceFiles(sourceFiles); + header()->setResizeMode(0, QHeaderView::ResizeToContents); +} diff --git a/src/plugins/debugger/sourcefileswindow.h b/src/plugins/debugger/sourcefileswindow.h new file mode 100644 index 0000000000000000000000000000000000000000..4d17d0cb1e91f46e4dc9e30a2fd417761ebd3fde --- /dev/null +++ b/src/plugins/debugger/sourcefileswindow.h @@ -0,0 +1,76 @@ +/*************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Qt Software Information (qt-info@nokia.com) +** +** +** Non-Open Source Usage +** +** Licensees may use this file in accordance with the Qt Beta Version +** License Agreement, Agreement version 2.2 provided with the Software or, +** alternatively, in accordance with the terms contained in a written +** agreement between you and Nokia. +** +** GNU General Public License Usage +** +** Alternatively, this file may be used under the terms of the GNU General +** Public License versions 2.0 or 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the packaging +** of this file. Please review the following information to ensure GNU +** General Public Licensing requirements will be met: +** +** http://www.fsf.org/licensing/licenses/info/GPLv2.html and +** http://www.gnu.org/copyleft/gpl.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt GPL Exception +** version 1.3, included in the file GPL_EXCEPTION.txt in this package. +** +***************************************************************************/ + +#ifndef DEBUGGER_SOURCEFILEWINDOW_H +#define DEBUGGER_SOURCEFILEWINDOW_H + +#include <QtGui/QTreeWidget> +#include <QtGui/QWidget> + +QT_BEGIN_NAMESPACE +class QComboBox; +class QModelIndex; +class QStandardItemModel; +QT_END_NAMESPACE + +namespace Debugger { +namespace Internal { + +class SourceFilesModel; + +class SourceFilesWindow : public QTreeView +{ + Q_OBJECT + +public: + SourceFilesWindow(QWidget *parent = 0); + ~SourceFilesWindow(); + + void setSourceFiles(const QMap<QString, QString> &sourceFiles); + +signals: + void reloadSourceFilesRequested(); + +private slots: + void sourceFileActivated(const QModelIndex &index); + +private: + void contextMenuEvent(QContextMenuEvent *ev); + SourceFilesModel *m_model; +}; + +} // namespace Internal +} // namespace Debugger + +#endif // DEBUGGER_SOURCEFILEWINDOW_H + diff --git a/src/plugins/debugger/statuswindow.cpp b/src/plugins/debugger/statuswindow.cpp new file mode 100644 index 0000000000000000000000000000000000000000..17b68a1c775af4cbf225b78a2856f3563f79d1e0 --- /dev/null +++ b/src/plugins/debugger/statuswindow.cpp @@ -0,0 +1,213 @@ +/*************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Qt Software Information (qt-info@nokia.com) +** +** +** Non-Open Source Usage +** +** Licensees may use this file in accordance with the Qt Beta Version +** License Agreement, Agreement version 2.2 provided with the Software or, +** alternatively, in accordance with the terms contained in a written +** agreement between you and Nokia. +** +** GNU General Public License Usage +** +** Alternatively, this file may be used under the terms of the GNU General +** Public License versions 2.0 or 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the packaging +** of this file. Please review the following information to ensure GNU +** General Public Licensing requirements will be met: +** +** http://www.fsf.org/licensing/licenses/info/GPLv2.html and +** http://www.gnu.org/copyleft/gpl.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt GPL Exception +** version 1.3, included in the file GPL_EXCEPTION.txt in this package. +** +***************************************************************************/ + +#include "sourcefileswindow.h" + +#include <QDebug> +#include <QAction> +#include <QComboBox> +#include <QFileInfo> +#include <QDebug> +#include <QHeaderView> +#include <QMenu> +#include <QResizeEvent> +#include <QTreeView> +#include <QSortFilterProxyModel> +#include <QVBoxLayout> + +using Debugger::Internal::SourceFilesWindow; +using Debugger::Internal::SourceFilesModel; + +////////////////////////////////////////////////////////////////// +// +// SourceFilesModel +// +////////////////////////////////////////////////////////////////// + +class Debugger::Internal::SourceFilesModel : public QAbstractItemModel +{ +public: + SourceFilesModel(QObject *parent = 0) : QAbstractItemModel(parent) {} + + // QAbstractItemModel + int columnCount(const QModelIndex &parent) const + { return parent.isValid() ? 0 : 2; } + int rowCount(const QModelIndex &parent) const + { return parent.isValid() ? 0 : m_shortNames.size(); } + 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; + QVariant data(const QModelIndex &index, int role) const; + bool setData(const QModelIndex &index, const QVariant &value, int role); + Qt::ItemFlags flags(const QModelIndex &index) const; + + void clearModel(); + void update() { reset(); } + void setSourceFiles(const QMap<QString, QString> &sourceFiles); + +public: + QStringList m_shortNames; + QStringList m_fullNames; +}; + +void SourceFilesModel::clearModel() +{ + if (m_shortNames.isEmpty()) + return; + m_shortNames.clear(); + m_fullNames.clear(); + reset(); +} + +QVariant SourceFilesModel::headerData(int section, + Qt::Orientation orientation, int role) const +{ + if (orientation == Qt::Horizontal && role == Qt::DisplayRole) { + static QString headers[] = { + tr("Internal name") + " ", + tr("Full name") + " ", + }; + return headers[section]; + } + return QVariant(); +} + +Qt::ItemFlags SourceFilesModel::flags(const QModelIndex &index) const +{ + if (index.row() >= m_fullNames.size()) + return 0; + QFileInfo fi(m_fullNames.at(index.row())); + return fi.isReadable() ? QAbstractItemModel::flags(index) : Qt::ItemFlags(0); +} + +QVariant SourceFilesModel::data(const QModelIndex &index, int role) const +{ + //static const QIcon icon(":/gdbdebugger/images/breakpoint.svg"); + //static const QIcon icon2(":/gdbdebugger/images/breakpoint_pending.svg"); + + int row = index.row(); + if (row < 0 || row >= m_shortNames.size()) + return QVariant(); + + switch (index.column()) { + case 0: + if (role == Qt::DisplayRole) + return m_shortNames.at(row); + // FIXME: add icons + //if (role == Qt::DecorationRole) + // return module.symbolsRead ? icon2 : icon; + break; + case 1: + if (role == Qt::DisplayRole) + return m_fullNames.at(row); + //if (role == Qt::DecorationRole) + // return module.symbolsRead ? icon2 : icon; + break; + } + return QVariant(); +} + +bool SourceFilesModel::setData(const QModelIndex &index, const QVariant &value, int role) +{ + return QAbstractItemModel::setData(index, value, role); +} + +void SourceFilesModel::setSourceFiles(const QMap<QString, QString> &sourceFiles) +{ + m_shortNames.clear(); + m_fullNames.clear(); + QMap<QString, QString>::ConstIterator it = sourceFiles.begin(); + QMap<QString, QString>::ConstIterator et = sourceFiles.end(); + for (; it != et; ++it) { + m_shortNames.append(it.key()); + m_fullNames.append(it.value()); + } + reset(); +} + +////////////////////////////////////////////////////////////////// +// +// SourceFilesWindow +// +////////////////////////////////////////////////////////////////// + +SourceFilesWindow::SourceFilesWindow(QWidget *parent) + : QTreeView(parent) +{ + m_model = new SourceFilesModel(this); + + QSortFilterProxyModel *proxyModel = new QSortFilterProxyModel(this); + proxyModel->setSourceModel(m_model); + setModel(proxyModel); + + setWindowTitle(tr("Source Files")); + setSortingEnabled(true); + setAlternatingRowColors(true); + setRootIsDecorated(false); + setIconSize(QSize(10, 10)); + //header()->setDefaultAlignment(Qt::AlignLeft); + + connect(this, SIGNAL(activated(QModelIndex)), + this, SLOT(sourceFileActivated(QModelIndex))); +} + +SourceFilesWindow::~SourceFilesWindow() +{ +} + +void SourceFilesWindow::sourceFileActivated(const QModelIndex &index) +{ + qDebug() << "ACTIVATED: " << index.row() << index.column(); +} + +void SourceFilesWindow::contextMenuEvent(QContextMenuEvent *ev) +{ + QMenu menu; + QAction *act1 = new QAction(tr("Reload data"), &menu); + //act1->setCheckable(true); + + menu.addAction(act1); + + QAction *act = menu.exec(ev->globalPos()); + + if (act == act1) { + emit reloadSourceFilesRequested(); + } +} + +void SourceFilesWindow::setSourceFiles(const QMap<QString, QString> &sourceFiles) +{ + m_model->setSourceFiles(sourceFiles); + header()->setResizeMode(0, QHeaderView::ResizeToContents); +}