2009-02-25 09:15:00 +01:00
|
|
|
/**************************************************************************
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator
|
|
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
|
|
|
|
** Contact: Qt Software Information (qt-info@nokia.com)
|
|
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** Commercial Usage
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** Licensees holding valid Qt Commercial licenses may use this file in
|
|
|
|
|
** accordance with the Qt Commercial License Agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
|
|
|
|
** a written agreement between you and Nokia.
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** GNU Lesser General Public License Usage
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** Alternatively, 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.
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** If you are unsure which license is appropriate for your use, please
|
|
|
|
|
** contact the sales department at qt-sales@nokia.com.
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
**************************************************************************/
|
2008-12-02 15:08:31 +01:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
#include "watchwindow.h"
|
|
|
|
|
|
2009-03-17 17:00:06 +01:00
|
|
|
#include "debuggeractions.h"
|
|
|
|
|
|
2009-03-19 15:24:18 +01:00
|
|
|
#include <utils/qtcassert.h>
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
#include <QtCore/QDebug>
|
|
|
|
|
#include <QtCore/QTimer>
|
|
|
|
|
|
|
|
|
|
#include <QtGui/QAction>
|
|
|
|
|
#include <QtGui/QContextMenuEvent>
|
|
|
|
|
#include <QtGui/QHeaderView>
|
2009-03-19 15:24:18 +01:00
|
|
|
#include <QtGui/QItemDelegate>
|
2008-12-02 12:01:29 +01:00
|
|
|
#include <QtGui/QLineEdit>
|
|
|
|
|
#include <QtGui/QMenu>
|
|
|
|
|
#include <QtGui/QResizeEvent>
|
|
|
|
|
#include <QtGui/QSplitter>
|
|
|
|
|
|
|
|
|
|
using namespace Debugger::Internal;
|
|
|
|
|
|
2009-03-19 15:24:18 +01:00
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
|
//
|
|
|
|
|
// WatchDelegate
|
|
|
|
|
//
|
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
2008-12-08 11:00:46 +01:00
|
|
|
enum { INameRole = Qt::UserRole, VisualRole, ExpandedRole };
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2009-03-19 15:24:18 +01:00
|
|
|
class WatchDelegate : public QItemDelegate
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
WatchDelegate(QObject *parent) : QItemDelegate(parent) {}
|
|
|
|
|
|
|
|
|
|
QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &,
|
|
|
|
|
const QModelIndex &) const
|
|
|
|
|
{
|
|
|
|
|
return new QLineEdit(parent);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void setEditorData(QWidget *editor, const QModelIndex &index) const
|
|
|
|
|
{
|
|
|
|
|
QLineEdit *lineEdit = qobject_cast<QLineEdit *>(editor);
|
|
|
|
|
QTC_ASSERT(lineEdit, return);
|
|
|
|
|
lineEdit->setText(index.model()->data(index, Qt::EditRole).toString());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void setModelData(QWidget *editor, QAbstractItemModel *,
|
|
|
|
|
const QModelIndex &index) const
|
|
|
|
|
{
|
|
|
|
|
QLineEdit *lineEdit = qobject_cast<QLineEdit*>(editor);
|
|
|
|
|
QTC_ASSERT(lineEdit, return);
|
|
|
|
|
QString value = lineEdit->text();
|
|
|
|
|
QString exp = index.model()->data(index, Qt::EditRole).toString();
|
|
|
|
|
if (index.column() == 1) {
|
|
|
|
|
// the value column
|
|
|
|
|
theDebuggerSetting(AssignValue)->trigger(exp + '=' + value);
|
|
|
|
|
} else if (index.column() == 0) {
|
|
|
|
|
// the watcher name column
|
|
|
|
|
theDebuggerSetting(RemoveWatchExpression)->trigger(exp);
|
|
|
|
|
theDebuggerSetting(WatchExpression)->trigger(lineEdit->text());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option,
|
|
|
|
|
const QModelIndex &) const
|
|
|
|
|
{
|
|
|
|
|
editor->setGeometry(option.rect);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
|
//
|
|
|
|
|
// WatchWindow
|
|
|
|
|
//
|
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
WatchWindow::WatchWindow(Type type, QWidget *parent)
|
2009-03-19 15:24:18 +01:00
|
|
|
: QTreeView(parent), m_alwaysResizeColumnsToContents(true), m_type(type)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
|
|
|
|
setWindowTitle(tr("Locals and Watchers"));
|
|
|
|
|
setAlternatingRowColors(true);
|
|
|
|
|
setIndentation(indentation() * 9/10);
|
|
|
|
|
setUniformRowHeights(true);
|
2009-03-19 15:24:18 +01:00
|
|
|
setItemDelegate(new WatchDelegate(this));
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
connect(this, SIGNAL(expanded(QModelIndex)),
|
|
|
|
|
this, SLOT(expandNode(QModelIndex)));
|
|
|
|
|
connect(this, SIGNAL(collapsed(QModelIndex)),
|
|
|
|
|
this, SLOT(collapseNode(QModelIndex)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WatchWindow::expandNode(const QModelIndex &idx)
|
|
|
|
|
{
|
|
|
|
|
//QModelIndex mi0 = idx.sibling(idx.row(), 0);
|
|
|
|
|
//QString iname = model()->data(mi0, INameRole).toString();
|
|
|
|
|
//QString name = model()->data(mi0, Qt::DisplayRole).toString();
|
|
|
|
|
emit requestExpandChildren(idx);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WatchWindow::collapseNode(const QModelIndex &idx)
|
|
|
|
|
{
|
|
|
|
|
//QModelIndex mi0 = idx.sibling(idx.row(), 0);
|
|
|
|
|
//QString iname = model()->data(mi0, INameRole).toString();
|
|
|
|
|
//QString name = model()->data(mi0, Qt::DisplayRole).toString();
|
|
|
|
|
//qDebug() << "COLLAPSE NODE " << idx;
|
|
|
|
|
emit requestCollapseChildren(idx);
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-17 18:02:08 +01:00
|
|
|
void WatchWindow::keyPressEvent(QKeyEvent *ev)
|
|
|
|
|
{
|
|
|
|
|
if (ev->key() == Qt::Key_Delete) {
|
|
|
|
|
QModelIndex idx = currentIndex();
|
|
|
|
|
QModelIndex idx1 = idx.sibling(idx.row(), 0);
|
|
|
|
|
QString exp = model()->data(idx1).toString();
|
2009-03-19 10:54:27 +01:00
|
|
|
theDebuggerSetting(RemoveWatchExpression)->setValue(exp);
|
2008-12-17 18:02:08 +01:00
|
|
|
}
|
|
|
|
|
QTreeView::keyPressEvent(ev);
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
void WatchWindow::contextMenuEvent(QContextMenuEvent *ev)
|
|
|
|
|
{
|
|
|
|
|
QMenu menu;
|
|
|
|
|
QAction *act1 = new QAction("Adjust column widths to contents", &menu);
|
|
|
|
|
QAction *act2 = new QAction("Always adjust column widths to contents", &menu);
|
|
|
|
|
act2->setCheckable(true);
|
|
|
|
|
act2->setChecked(m_alwaysResizeColumnsToContents);
|
2009-03-19 15:24:18 +01:00
|
|
|
//QAction *act3 = 0;
|
2009-02-27 11:41:19 +01:00
|
|
|
QAction *act4 = 0;
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
menu.addAction(act1);
|
|
|
|
|
menu.addAction(act2);
|
|
|
|
|
|
|
|
|
|
QModelIndex idx = indexAt(ev->pos());
|
|
|
|
|
QModelIndex mi0 = idx.sibling(idx.row(), 0);
|
|
|
|
|
QString exp = model()->data(mi0).toString();
|
|
|
|
|
QModelIndex mi1 = idx.sibling(idx.row(), 0);
|
|
|
|
|
QString value = model()->data(mi1).toString();
|
|
|
|
|
bool visual = false;
|
2009-03-19 12:24:04 +01:00
|
|
|
|
|
|
|
|
menu.addSeparator();
|
|
|
|
|
int type = (m_type == LocalsType) ? WatchExpression : RemoveWatchExpression;
|
|
|
|
|
menu.addAction(theDebuggerSetting(type)->updatedAction(exp));
|
|
|
|
|
|
|
|
|
|
visual = model()->data(mi0, VisualRole).toBool();
|
|
|
|
|
//act4 = theDebuggerSetting(WatchExpressionInWindow)->action();
|
|
|
|
|
//act4->setCheckable(true);
|
|
|
|
|
//act4->setChecked(visual);
|
2009-03-19 15:24:18 +01:00
|
|
|
//menu.addAction(act4);
|
|
|
|
|
|
|
|
|
|
//act3 = new QAction(tr("Add to watch window..."), &menu);
|
|
|
|
|
//menu.addAction(act3);
|
2009-03-19 12:24:04 +01:00
|
|
|
|
2009-02-27 11:41:19 +01:00
|
|
|
menu.addSeparator();
|
2009-03-19 10:54:27 +01:00
|
|
|
menu.addAction(theDebuggerSetting(RecheckDumpers)->action());
|
|
|
|
|
menu.addAction(theDebuggerSetting(UseDumpers)->action());
|
2009-03-18 09:03:47 +01:00
|
|
|
menu.addSeparator();
|
2009-03-19 10:54:27 +01:00
|
|
|
menu.addAction(theDebuggerSetting(SettingsDialog)->action());
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
QAction *act = menu.exec(ev->globalPos());
|
|
|
|
|
|
2009-03-19 09:32:09 +01:00
|
|
|
if (act == act1)
|
2008-12-02 12:01:29 +01:00
|
|
|
resizeColumnsToContents();
|
|
|
|
|
else if (act == act2)
|
|
|
|
|
setAlwaysResizeColumnsToContents(!m_alwaysResizeColumnsToContents);
|
|
|
|
|
else if (act == act4)
|
|
|
|
|
model()->setData(mi0, !visual, VisualRole);
|
2009-03-19 15:24:18 +01:00
|
|
|
else if (act == act4)
|
|
|
|
|
model()->setData(mi0, !visual, VisualRole);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WatchWindow::resizeColumnsToContents()
|
|
|
|
|
{
|
|
|
|
|
resizeColumnToContents(0);
|
|
|
|
|
resizeColumnToContents(1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WatchWindow::setAlwaysResizeColumnsToContents(bool on)
|
|
|
|
|
{
|
|
|
|
|
if (!header())
|
|
|
|
|
return;
|
|
|
|
|
m_alwaysResizeColumnsToContents = on;
|
|
|
|
|
QHeaderView::ResizeMode mode = on
|
|
|
|
|
? QHeaderView::ResizeToContents : QHeaderView::Interactive;
|
|
|
|
|
header()->setResizeMode(0, mode);
|
|
|
|
|
header()->setResizeMode(1, mode);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WatchWindow::editItem(const QModelIndex &idx)
|
|
|
|
|
{
|
|
|
|
|
Q_UNUSED(idx); // FIXME
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WatchWindow::reset()
|
|
|
|
|
{
|
|
|
|
|
int row = 0;
|
|
|
|
|
if (m_type == TooltipType)
|
|
|
|
|
row = 1;
|
|
|
|
|
else if (m_type == WatchersType)
|
|
|
|
|
row = 2;
|
|
|
|
|
//qDebug() << "WATCHWINDOW::RESET" << row;
|
|
|
|
|
QTreeView::reset();
|
|
|
|
|
setRootIndex(model()->index(row, 0, model()->index(0, 0)));
|
|
|
|
|
//setRootIndex(model()->index(0, 0));
|
2008-12-08 11:00:46 +01:00
|
|
|
resetHelper(model()->index(0, 0));
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WatchWindow::setModel(QAbstractItemModel *model)
|
|
|
|
|
{
|
|
|
|
|
QTreeView::setModel(model);
|
|
|
|
|
|
|
|
|
|
setRootIsDecorated(true);
|
|
|
|
|
header()->setDefaultAlignment(Qt::AlignLeft);
|
|
|
|
|
header()->setResizeMode(QHeaderView::ResizeToContents);
|
|
|
|
|
if (m_type != LocalsType)
|
|
|
|
|
header()->hide();
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-08 11:00:46 +01:00
|
|
|
void WatchWindow::resetHelper(const QModelIndex &idx)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2008-12-08 11:00:46 +01:00
|
|
|
if (model()->data(idx, ExpandedRole).toBool()) {
|
2008-12-02 12:01:29 +01:00
|
|
|
expand(idx);
|
|
|
|
|
for (int i = 0, n = model()->rowCount(idx); i != n; ++i) {
|
|
|
|
|
QModelIndex idx1 = model()->index(i, 0, idx);
|
2008-12-08 11:00:46 +01:00
|
|
|
resetHelper(idx1);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|