OSDN Git Service

Fix original string messages
[qt-creator-jp/qt-creator-jp.git] / src / plugins / debugger / stackwindow.cpp
1 /**************************************************************************
2 **
3 ** This file is part of Qt Creator
4 **
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
6 **
7 ** Contact: Nokia Corporation (info@qt.nokia.com)
8 **
9 **
10 ** GNU Lesser General Public License Usage
11 **
12 ** This file may be used under the terms of the GNU Lesser General Public
13 ** License version 2.1 as published by the Free Software Foundation and
14 ** appearing in the file LICENSE.LGPL included in the packaging of this file.
15 ** Please review the following information to ensure the GNU Lesser General
16 ** Public License version 2.1 requirements will be met:
17 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
18 **
19 ** In addition, as a special exception, Nokia gives you certain additional
20 ** rights. These rights are described in the Nokia Qt LGPL Exception
21 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
22 **
23 ** Other Usage
24 **
25 ** Alternatively, this file may be used in accordance with the terms and
26 ** conditions contained in a signed written agreement between you and Nokia.
27 **
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at info@qt.nokia.com.
30 **
31 **************************************************************************/
32
33 #include "stackwindow.h"
34 #include "stackhandler.h"
35
36 #include "debuggeractions.h"
37 #include "debuggercore.h"
38 #include "debuggerengine.h"
39 #include "debuggerdialogs.h"
40 #include "memoryagent.h"
41
42 #include <utils/qtcassert.h>
43 #include <utils/savedaction.h>
44
45 #include <QtCore/QDebug>
46
47 #include <QtGui/QApplication>
48 #include <QtGui/QClipboard>
49 #include <QtGui/QHeaderView>
50 #include <QtGui/QMenu>
51 #include <QtGui/QResizeEvent>
52
53 namespace Debugger {
54 namespace Internal {
55
56 static DebuggerEngine *currentEngine()
57 {
58     return debuggerCore()->currentEngine();
59 }
60
61 StackWindow::StackWindow(QWidget *parent)
62     : QTreeView(parent)
63 {
64     setAttribute(Qt::WA_MacShowFocusRect, false);
65     setFrameStyle(QFrame::NoFrame);
66
67     QAction *act = debuggerCore()->action(UseAlternatingRowColors);
68     setWindowTitle(tr("Stack"));
69
70     setAlternatingRowColors(act->isChecked());
71     setRootIsDecorated(false);
72     setIconSize(QSize(10, 10));
73
74     header()->setDefaultAlignment(Qt::AlignLeft);
75
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);
90 }
91
92 void StackWindow::showAddressColumn(bool on)
93 {
94     setColumnHidden(4, !on);
95 }
96
97 void StackWindow::rowActivated(const QModelIndex &index)
98 {
99     currentEngine()->activateFrame(index.row());
100 }
101
102 void StackWindow::setModel(QAbstractItemModel *model)
103 {
104     QTreeView::setModel(model);
105     //resizeColumnsToContents();
106     resizeColumnToContents(0);
107     resizeColumnToContents(3);
108 }
109
110 void StackWindow::contextMenuEvent(QContextMenuEvent *ev)
111 {
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();
117     StackFrame frame;
118     if (row >= 0 && row < handler->stackSize())
119         frame = handler->frameAt(row);
120     const quint64 address = frame.address;
121
122     QMenu menu;
123     menu.addAction(debuggerCore()->action(ExpandStack));
124
125     QAction *actCopyContents = menu.addAction(tr("Copy Contents to Clipboard"));
126     actCopyContents->setEnabled(model() != 0);
127
128     if (engineCapabilities & CreateFullBacktraceCapability)
129         menu.addAction(debuggerCore()->action(CreateFullBacktrace));
130
131     QAction *actShowMemory = menu.addAction(QString());
132     if (address == 0) {
133         actShowMemory->setText(tr("Open Memory Editor"));
134         actShowMemory->setEnabled(false);
135     } else {
136         actShowMemory->setText(tr("Open Memory Editor at 0x%1").arg(address, 0, 16));
137         actShowMemory->setEnabled(engineCapabilities & ShowMemoryCapability);
138     }
139
140     QAction *actShowDisassemblerAt = menu.addAction(QString());
141     QAction *actShowDisassembler = menu.addAction(tr("Open Disassembler..."));
142     actShowDisassembler->setEnabled(engineCapabilities & DisassemblerCapability);
143     if (address == 0) {
144         actShowDisassemblerAt->setText(tr("Open Disassembler"));
145         actShowDisassemblerAt->setEnabled(false);
146     } else {
147         actShowDisassemblerAt->setText(tr("Open Disassembler at 0x%1").arg(address, 0, 16));
148         actShowDisassemblerAt->setEnabled(engineCapabilities & DisassemblerCapability);
149     }
150
151     QAction *actLoadSymbols = 0;
152     if (engineCapabilities & ShowModuleSymbolsCapability)
153         actLoadSymbols = menu.addAction(tr("Try to Load Unknown Symbols"));
154
155     menu.addSeparator();
156 #if 0 // @TODO: not implemented
157     menu.addAction(debuggerCore()->action(UseToolTipsInStackView));
158 #endif
159     menu.addAction(debuggerCore()->action(UseAddressInStackView));
160
161     QAction *actAdjust = menu.addAction(tr("Adjust Column Widths to Contents"));
162     menu.addAction(debuggerCore()->action(AlwaysAdjustStackColumnWidths));
163     menu.addSeparator();
164
165     menu.addAction(debuggerCore()->action(SettingsDialog));
166
167     QAction *act = menu.exec(ev->globalPos());
168
169     if (!act)
170         ;
171     else if (act == actCopyContents)
172         copyContentsToClipboard();
173     else if (act == actAdjust)
174         resizeColumnsToContents();
175     else if (act == actShowMemory) {
176         const QString title = tr("Memory at Frame #%1 (%2) 0x%3").
177         arg(row).arg(frame.function).arg(address, 0, 16);
178         QList<MemoryMarkup> ml;
179         ml.push_back(MemoryMarkup(address, 1, QColor(Qt::blue).lighter(),
180                                   tr("Frame #%1 (%2)").arg(row).arg(frame.function)));
181         engine->openMemoryView(address, 0, ml, QPoint(), title);
182     } else if (act == actShowDisassembler) {
183         AddressDialog dialog;
184         if (address)
185             dialog.setAddress(address);
186         if (dialog.exec() == QDialog::Accepted)
187             currentEngine()->openDisassemblerView(Location(dialog.address()));
188     } else if (act == actShowDisassemblerAt)
189         engine->openDisassemblerView(frame);
190     else if (act == actLoadSymbols)
191         engine->loadSymbolsForStack();
192 }
193
194 void StackWindow::copyContentsToClipboard()
195 {
196     QString str;
197     int n = model()->rowCount();
198     int m = model()->columnCount();
199     for (int i = 0; i != n; ++i) {
200         for (int j = 0; j != m; ++j) {
201             QModelIndex index = model()->index(i, j);
202             str += model()->data(index).toString();
203             str += '\t';
204         }
205         str += '\n';
206     }
207     QClipboard *clipboard = QApplication::clipboard();
208 #    ifdef Q_WS_X11
209     clipboard->setText(str, QClipboard::Selection);
210 #    endif
211     clipboard->setText(str, QClipboard::Clipboard);
212 }
213
214 void StackWindow::reloadFullStack()
215 {
216     currentEngine()->reloadFullStack();
217 }
218
219 void StackWindow::resizeColumnsToContents()
220 {
221     for (int i = model()->columnCount(); --i >= 0; )
222         resizeColumnToContents(i);
223 }
224
225 void StackWindow::setAlwaysResizeColumnsToContents(bool on)
226 {
227     QHeaderView::ResizeMode mode =
228         on ? QHeaderView::ResizeToContents : QHeaderView::Interactive;
229     for (int i = model()->columnCount(); --i >= 0; )
230         header()->setResizeMode(i, mode);
231 }
232
233 } // namespace Internal
234 } // namespace Debugger