Files
qt-creator/src/plugins/debugger/moduleswindow.cpp

224 lines
7.7 KiB
C++
Raw Normal View History

/**************************************************************************
2008-12-02 12:01:29 +01:00
**
** This file is part of Qt Creator
**
2011-01-11 16:28:15 +01:00
** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
2008-12-02 12:01:29 +01:00
**
2011-04-13 08:42:33 +02:00
** Contact: Nokia Corporation (info@qt.nokia.com)
2008-12-02 12:01:29 +01:00
**
**
** GNU Lesser General Public License Usage
**
2011-04-13 08:42:33 +02:00
** This file may be used under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation and
** appearing in the file LICENSE.LGPL included in the packaging of this file.
** Please review the following information to ensure the GNU Lesser General
** Public License version 2.1 requirements will be met:
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
2010-12-17 16:01:08 +01:00
** In addition, as a special exception, Nokia gives you certain additional
2011-04-13 08:42:33 +02:00
** rights. These rights are described in the Nokia Qt LGPL Exception
2010-12-17 16:01:08 +01:00
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
2011-04-13 08:42:33 +02:00
** Other Usage
**
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
2010-12-17 16:01:08 +01:00
** If you have questions regarding the use of this file, please contact
** Nokia at info@qt.nokia.com.
2008-12-02 12:01:29 +01:00
**
**************************************************************************/
2008-12-02 15:08:31 +01:00
2008-12-02 12:01:29 +01:00
#include "moduleswindow.h"
#include "debuggeractions.h"
#include "debuggerconstants.h"
#include "debuggercore.h"
#include "debuggerengine.h"
2008-12-02 12:01:29 +01:00
#include <utils/qtcassert.h>
#include <utils/savedaction.h>
#include <QtCore/QDebug>
#include <QtCore/QProcess>
2008-12-02 12:01:29 +01:00
#include <QtGui/QHeaderView>
#include <QtGui/QMenu>
#include <QtGui/QResizeEvent>
///////////////////////////////////////////////////////////////////////////
//
// ModulesWindow
//
///////////////////////////////////////////////////////////////////////////
2008-12-02 12:01:29 +01:00
namespace Debugger {
namespace Internal {
2008-12-02 12:01:29 +01:00
ModulesWindow::ModulesWindow(QWidget *parent)
: QTreeView(parent)
2008-12-02 12:01:29 +01:00
{
QAction *act = debuggerCore()->action(UseAlternatingRowColors);
2008-12-02 12:01:29 +01:00
setWindowTitle(tr("Modules"));
setAttribute(Qt::WA_MacShowFocusRect, false);
2008-12-02 12:01:29 +01:00
setSortingEnabled(true);
setAlternatingRowColors(act->isChecked());
2008-12-02 12:01:29 +01:00
setRootIsDecorated(false);
setIconSize(QSize(10, 10));
connect(this, SIGNAL(activated(QModelIndex)),
SLOT(moduleActivated(QModelIndex)));
connect(act, SIGNAL(toggled(bool)),
SLOT(setAlternatingRowColorsHelper(bool)));
connect(debuggerCore()->action(AlwaysAdjustModulesColumnWidths),
SIGNAL(toggled(bool)),
SLOT(setAlwaysResizeColumnsToContents(bool)));
}
void ModulesWindow::moduleActivated(const QModelIndex &index)
{
DebuggerEngine *engine = debuggerCore()->currentEngine();
QTC_ASSERT(engine, return);
engine->gotoLocation(index.data().toString());
2008-12-02 12:01:29 +01:00
}
void ModulesWindow::contextMenuEvent(QContextMenuEvent *ev)
{
QString name;
QString fileName;
2008-12-02 12:01:29 +01:00
QModelIndex index = indexAt(ev->pos());
if (index.isValid())
index = index.sibling(index.row(), 0);
if (index.isValid()) {
name = index.data().toString();
fileName = index.sibling(index.row(), 1).data().toString();
}
2008-12-02 12:01:29 +01:00
DebuggerEngine *engine = debuggerCore()->currentEngine();
QTC_ASSERT(engine, return);
const bool enabled = engine->debuggerActionsEnabled();
const unsigned capabilities = engine->debuggerCapabilities();
2008-12-02 12:01:29 +01:00
QMenu menu;
QAction *actUpdateModuleList
= new QAction(tr("Update Module List"), &menu);
actUpdateModuleList
->setEnabled(enabled && (capabilities & ReloadModuleCapability));
2010-11-26 09:58:34 +01:00
QAction *actShowModuleSources
= new QAction(tr("Show Source Files for Module \"%1\"").arg(name), &menu);
2010-11-26 09:58:34 +01:00
actShowModuleSources
->setEnabled(enabled && (capabilities & ReloadModuleCapability));
QAction *actLoadSymbolsForAllModules
= new QAction(tr("Load Symbols for All Modules"), &menu);
actLoadSymbolsForAllModules
-> setEnabled(enabled && (capabilities & ReloadModuleSymbolsCapability));
QAction *actExamineAllModules
= new QAction(tr("Examine All Modules"), &menu);
actExamineAllModules
-> setEnabled(enabled && (capabilities & ReloadModuleSymbolsCapability));
QAction *actLoadSymbolsForModule = 0;
QAction *actEditFile = 0;
2010-11-26 09:58:34 +01:00
QAction *actShowModuleSymbols = 0;
QAction *actShowDependencies = 0; // Show dependencies by running 'depends.exe'
if (name.isEmpty()) {
actLoadSymbolsForModule = new QAction(tr("Load Symbols for Module"), &menu);
actLoadSymbolsForModule->setEnabled(false);
actEditFile = new QAction(tr("Edit File"), &menu);
actEditFile->setEnabled(false);
2010-11-26 09:58:34 +01:00
actShowModuleSymbols = new QAction(tr("Show Symbols"), &menu);
actShowModuleSymbols->setEnabled(false);
#ifdef Q_OS_WIN
actShowDependencies = new QAction(tr("Show Dependencies"), &menu);
actShowDependencies->setEnabled(false);
#endif
} else {
actLoadSymbolsForModule
= new QAction(tr("Load Symbols for Module \"%1\"").arg(name), &menu);
actLoadSymbolsForModule
->setEnabled(capabilities & ReloadModuleSymbolsCapability);
actEditFile
= new QAction(tr("Edit File \"%1\"").arg(name), &menu);
2010-11-26 09:58:34 +01:00
actShowModuleSymbols
= new QAction(tr("Show Symbols in File \"%1\"").arg(name), &menu);
2010-11-26 09:58:34 +01:00
actShowModuleSymbols
->setEnabled(capabilities & ShowModuleSymbolsCapability);
#ifdef Q_OS_WIN
actShowDependencies = new QAction(tr("Show Dependencies of \"%1\"").arg(name), &menu);
actShowDependencies->setEnabled(!fileName.isEmpty());
#endif
}
2008-12-02 12:01:29 +01:00
menu.addAction(actUpdateModuleList);
2010-11-26 09:58:34 +01:00
//menu.addAction(actShowModuleSources); // FIXME
if (actShowDependencies)
menu.addAction(actShowDependencies);
menu.addAction(actLoadSymbolsForAllModules);
menu.addAction(actExamineAllModules);
menu.addAction(actLoadSymbolsForModule);
menu.addAction(actEditFile);
2010-11-26 09:58:34 +01:00
menu.addAction(actShowModuleSymbols);
2008-12-02 12:01:29 +01:00
menu.addSeparator();
QAction *actAdjustColumnWidths =
menu.addAction(tr("Adjust Column Widths to Contents"));
menu.addAction(debuggerCore()->action(AlwaysAdjustModulesColumnWidths));
menu.addSeparator();
menu.addAction(debuggerCore()->action(SettingsDialog));
2008-12-02 12:01:29 +01:00
QAction *act = menu.exec(ev->globalPos());
2010-11-26 09:58:34 +01:00
if (act == actUpdateModuleList)
engine->reloadModules();
2010-11-26 09:58:34 +01:00
else if (act == actAdjustColumnWidths)
resizeColumnsToContents();
2010-11-26 09:58:34 +01:00
else if (act == actShowModuleSources)
engine->loadSymbols(name);
2010-11-26 09:58:34 +01:00
else if (act == actLoadSymbolsForAllModules)
engine->loadAllSymbols();
2010-11-26 09:58:34 +01:00
else if (act == actExamineAllModules)
engine->examineModules();
2010-11-26 09:58:34 +01:00
else if (act == actLoadSymbolsForModule)
engine->loadSymbols(name);
2010-11-26 09:58:34 +01:00
else if (act == actEditFile)
engine->gotoLocation(name);
2010-11-26 09:58:34 +01:00
else if (act == actShowModuleSymbols)
engine->requestModuleSymbols(name);
else if (actShowDependencies && act == actShowDependencies)
QProcess::startDetached(QLatin1String("depends"), QStringList(fileName));
2008-12-02 12:01:29 +01:00
}
void ModulesWindow::resizeColumnsToContents()
{
resizeColumnToContents(0);
resizeColumnToContents(1);
resizeColumnToContents(2);
2010-05-03 19:12:52 +02:00
resizeColumnToContents(3);
2008-12-02 12:01:29 +01:00
}
void ModulesWindow::setAlwaysResizeColumnsToContents(bool on)
{
QHeaderView::ResizeMode mode = on
2008-12-02 12:01:29 +01:00
? QHeaderView::ResizeToContents : QHeaderView::Interactive;
header()->setResizeMode(0, mode);
header()->setResizeMode(1, mode);
header()->setResizeMode(2, mode);
header()->setResizeMode(3, mode);
2010-05-03 19:12:52 +02:00
header()->setResizeMode(4, mode);
2008-12-02 12:01:29 +01:00
//setColumnHidden(3, true);
}
void ModulesWindow::setModel(QAbstractItemModel *model)
{
QTreeView::setModel(model);
setAlwaysResizeColumnsToContents(true);
}
2009-05-05 10:22:44 +02:00
} // namespace Internal
} // namespace Debugger