1 /**************************************************************************
3 ** This file is part of Qt Creator
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
7 ** Contact: Nokia Corporation (qt-info@nokia.com)
11 ** This file contains pre-release code and may not be distributed.
12 ** You may use this file in accordance with the terms and conditions
13 ** contained in the Technology Preview License Agreement accompanying
16 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25 ** In addition, as a special exception, Nokia gives you certain additional
26 ** rights. These rights are described in the Nokia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29 ** If you have questions regarding the use of this file, please contact
30 ** Nokia at qt-info@nokia.com.
32 **************************************************************************/
34 #include "stackwindow.h"
35 #include "stackhandler.h"
37 #include "debuggeractions.h"
38 #include "debuggerconstants.h"
39 #include "debuggercore.h"
40 #include "debuggerengine.h"
42 #include <utils/qtcassert.h>
43 #include <utils/savedaction.h>
45 #include <QtCore/QDebug>
47 #include <QtGui/QApplication>
48 #include <QtGui/QClipboard>
49 #include <QtGui/QHeaderView>
50 #include <QtGui/QMenu>
51 #include <QtGui/QResizeEvent>
56 static DebuggerEngine *currentEngine()
58 return debuggerCore()->currentEngine();
61 StackWindow::StackWindow(QWidget *parent)
64 setAttribute(Qt::WA_MacShowFocusRect, false);
65 setFrameStyle(QFrame::NoFrame);
67 QAction *act = debuggerCore()->action(UseAlternatingRowColors);
68 setWindowTitle(tr("Stack"));
70 setAlternatingRowColors(act->isChecked());
71 setRootIsDecorated(false);
72 setIconSize(QSize(10, 10));
74 header()->setDefaultAlignment(Qt::AlignLeft);
76 connect(this, SIGNAL(activated(QModelIndex)),
77 SLOT(rowActivated(QModelIndex)));
78 connect(act, SIGNAL(toggled(bool)),
79 SLOT(setAlternatingRowColorsHelper(bool)));
80 connect(debuggerCore()->action(UseAddressInStackView), SIGNAL(toggled(bool)),
81 SLOT(showAddressColumn(bool)));
82 connect(debuggerCore()->action(ExpandStack), SIGNAL(triggered()),
83 SLOT(reloadFullStack()));
84 connect(debuggerCore()->action(MaximalStackDepth), SIGNAL(triggered()),
85 SLOT(reloadFullStack()));
86 connect(debuggerCore()->action(AlwaysAdjustStackColumnWidths),
87 SIGNAL(triggered(bool)),
88 SLOT(setAlwaysResizeColumnsToContents(bool)));
89 showAddressColumn(false);
92 void StackWindow::showAddressColumn(bool on)
94 setColumnHidden(4, !on);
97 void StackWindow::rowActivated(const QModelIndex &index)
99 currentEngine()->activateFrame(index.row());
102 void StackWindow::setModel(QAbstractItemModel *model)
104 QTreeView::setModel(model);
105 //resizeColumnsToContents();
106 resizeColumnToContents(0);
107 resizeColumnToContents(3);
110 void StackWindow::contextMenuEvent(QContextMenuEvent *ev)
112 DebuggerEngine *engine = currentEngine();
113 StackHandler *handler = engine->stackHandler();
114 const QModelIndex index = indexAt(ev->pos());
115 const int row = index.row();
116 const unsigned engineCapabilities = engine->debuggerCapabilities();
118 if (row >= 0 && row < handler->stackSize())
119 frame = handler->frameAt(row);
120 const quint64 address = frame.address;
123 menu.addAction(debuggerCore()->action(ExpandStack));
125 QAction *actCopyContents = menu.addAction(tr("Copy Contents to Clipboard"));
126 actCopyContents->setEnabled(model() != 0);
128 if (engineCapabilities & CreateFullBacktraceCapability)
129 menu.addAction(debuggerCore()->action(CreateFullBacktrace));
131 QAction *actShowMemory = menu.addAction(QString());
133 actShowMemory->setText(tr("Open Memory Editor"));
134 actShowMemory->setEnabled(false);
136 actShowMemory->setText(tr("Open Memory Editor at 0x%1").arg(address, 0, 16));
137 actShowMemory->setEnabled(engineCapabilities & ShowMemoryCapability);
140 QAction *actShowDisassembler = menu.addAction(QString());
142 actShowDisassembler->setText(tr("Open Disassembler"));
143 actShowDisassembler->setEnabled(false);
145 actShowDisassembler->setText(tr("Open Disassembler at 0x%1").arg(address, 0, 16));
146 actShowDisassembler->setEnabled(engineCapabilities & DisassemblerCapability);
149 QAction *actLoadSymbols = 0;
150 if (engineCapabilities & ShowModuleSymbolsCapability)
151 actLoadSymbols = menu.addAction(tr("Try to Load Unknown Symbols"));
154 #if 0 // @TODO: not implemented
155 menu.addAction(debuggerCore()->action(UseToolTipsInStackView));
157 menu.addAction(debuggerCore()->action(UseAddressInStackView));
159 QAction *actAdjust = menu.addAction(tr("Adjust Column Widths to Contents"));
160 menu.addAction(debuggerCore()->action(AlwaysAdjustStackColumnWidths));
163 menu.addAction(debuggerCore()->action(SettingsDialog));
165 QAction *act = menu.exec(ev->globalPos());
169 else if (act == actCopyContents)
170 copyContentsToClipboard();
171 else if (act == actAdjust)
172 resizeColumnsToContents();
173 else if (act == actShowMemory)
174 engine->openMemoryView(address);
175 else if (act == actShowDisassembler)
176 engine->openDisassemblerView(frame);
177 else if (act == actLoadSymbols)
178 engine->loadSymbolsForStack();
181 void StackWindow::copyContentsToClipboard()
184 int n = model()->rowCount();
185 int m = model()->columnCount();
186 for (int i = 0; i != n; ++i) {
187 for (int j = 0; j != m; ++j) {
188 QModelIndex index = model()->index(i, j);
189 str += model()->data(index).toString();
194 QClipboard *clipboard = QApplication::clipboard();
196 clipboard->setText(str, QClipboard::Selection);
198 clipboard->setText(str, QClipboard::Clipboard);
201 void StackWindow::reloadFullStack()
203 currentEngine()->reloadFullStack();
206 void StackWindow::resizeColumnsToContents()
208 for (int i = model()->columnCount(); --i >= 0; )
209 resizeColumnToContents(i);
212 void StackWindow::setAlwaysResizeColumnsToContents(bool on)
214 QHeaderView::ResizeMode mode =
215 on ? QHeaderView::ResizeToContents : QHeaderView::Interactive;
216 for (int i = model()->columnCount(); --i >= 0; )
217 header()->setResizeMode(i, mode);
220 } // namespace Internal
221 } // namespace Debugger