Commit 2e9fd40d authored by hjk's avatar hjk Committed by hjk

debugger: use common baseclass for all dock treeviews

Reduces amount of boilerplate code.

Change-Id: I048d901b4b80860df05f09b48650ea58b83fbc66
Reviewed-on: http://codereview.qt-project.org/5864Reviewed-by: default avatarhjk <qthjk@ovi.com>
parent 1b5e10e1
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (info@qt.nokia.com)
**
**
** GNU Lesser General Public License Usage
**
** 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.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** 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.
**
** If you have questions regarding the use of this file, please contact
** Nokia at info@qt.nokia.com.
**
**************************************************************************/
#include "basewindow.h"
#include "debuggeractions.h"
#include "debuggercore.h"
#include <utils/savedaction.h>
#include <QtCore/QDebug>
#include <QtGui/QContextMenuEvent>
#include <QtGui/QHeaderView>
#include <QtGui/QMenu>
namespace Debugger {
namespace Internal {
BaseWindow::BaseWindow(QWidget *parent)
: QTreeView(parent)
{
QAction *act = debuggerCore()->action(UseAlternatingRowColors);
setAttribute(Qt::WA_MacShowFocusRect, false);
setFrameStyle(QFrame::NoFrame);
setAlternatingRowColors(act->isChecked());
setRootIsDecorated(false);
setIconSize(QSize(10, 10));
setSelectionMode(QAbstractItemView::ExtendedSelection);
header()->setDefaultAlignment(Qt::AlignLeft);
connect(act, SIGNAL(toggled(bool)),
SLOT(setAlternatingRowColorsHelper(bool)));
connect(this, SIGNAL(activated(QModelIndex)),
SLOT(rowActivatedHelper(QModelIndex)));
m_adjustColumnsAction = new QAction(tr("Adjust Column Widths to Contents"), 0);
m_alwaysAdjustColumnsAction = 0;
}
void BaseWindow::setAlwaysAdjustColumnsAction(QAction *action)
{
m_alwaysAdjustColumnsAction = action;
connect(action, SIGNAL(toggled(bool)),
SLOT(setAlwaysResizeColumnsToContents(bool)));
}
void BaseWindow::addBaseContextActions(QMenu *menu)
{
menu->addSeparator();
if (m_alwaysAdjustColumnsAction)
menu->addAction(m_alwaysAdjustColumnsAction);
menu->addAction(m_adjustColumnsAction);
menu->addSeparator();
menu->addAction(debuggerCore()->action(SettingsDialog));
}
bool BaseWindow::handleBaseContextAction(QAction *act)
{
if (act == 0)
return true;
if (act == m_adjustColumnsAction) {
resizeColumnsToContents();
return true;
}
if (act == m_alwaysAdjustColumnsAction) {
// Action triggered automatically.
return true;
}
return false;
}
void BaseWindow::setModel(QAbstractItemModel *model)
{
QTreeView::setModel(model);
if (header() && m_alwaysAdjustColumnsAction)
setAlwaysResizeColumnsToContents(m_alwaysAdjustColumnsAction->isChecked());
}
void BaseWindow::resizeColumnsToContents()
{
const int columnCount = model()->columnCount();
for (int c = 0 ; c != columnCount; ++c)
resizeColumnToContents(c);
}
void BaseWindow::setAlwaysResizeColumnsToContents(bool on)
{
QHeaderView::ResizeMode mode = on
? QHeaderView::ResizeToContents : QHeaderView::Interactive;
header()->setResizeMode(0, mode);
}
} // namespace Internal
} // namespace Debugger
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (info@qt.nokia.com)
**
**
** GNU Lesser General Public License Usage
**
** 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.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** 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.
**
** If you have questions regarding the use of this file, please contact
** Nokia at info@qt.nokia.com.
**
**************************************************************************/
#ifndef DEBUGGER_BASEWINDOW_H
#define DEBUGGER_BASEWINDOW_H
#include <QtGui/QTreeView>
namespace Debugger {
namespace Internal {
class BaseWindow : public QTreeView
{
Q_OBJECT
public:
BaseWindow(QWidget *parent = 0);
void setAlwaysAdjustColumnsAction(QAction *action);
void addBaseContextActions(QMenu *menu);
bool handleBaseContextAction(QAction *action);
void setModel(QAbstractItemModel *model);
virtual void rowActivated(const QModelIndex &) {}
public slots:
void resizeColumnsToContents();
void setAlwaysResizeColumnsToContents(bool on);
private slots:
void setAlternatingRowColorsHelper(bool on) { setAlternatingRowColors(on); }
void rowActivatedHelper(const QModelIndex &index) { rowActivated(index); }
private:
QAction *m_alwaysAdjustColumnsAction;
QAction *m_adjustColumnsAction;
};
} // namespace Internal
} // namespace Debugger
#endif // DEBUGGER_BASEWINDOW_H
......@@ -469,28 +469,15 @@ MultiBreakPointsDialog::MultiBreakPointsDialog(unsigned engineCapabilities, QWid
///////////////////////////////////////////////////////////////////////
BreakWindow::BreakWindow(QWidget *parent)
: QTreeView(parent)
: BaseWindow(parent)
{
QAction *act = debuggerCore()->action(UseAlternatingRowColors);
setFrameStyle(QFrame::NoFrame);
setAttribute(Qt::WA_MacShowFocusRect, false);
setWindowTitle(tr("Breakpoints"));
setObjectName(QLatin1String("ThreadsWindow"));
setWindowIcon(QIcon(QLatin1String(":/debugger/images/debugger_breakpoints.png")));
setAlternatingRowColors(act->isChecked());
setRootIsDecorated(false);
setIconSize(QSize(10, 10));
setSelectionMode(QAbstractItemView::ExtendedSelection);
connect(this, SIGNAL(activated(QModelIndex)),
SLOT(rowActivated(QModelIndex)));
connect(act, SIGNAL(toggled(bool)),
SLOT(setAlternatingRowColorsHelper(bool)));
setAlwaysAdjustColumnsAction(debuggerCore()->action(AlwaysAdjustBreakpointsColumnWidths));
connect(debuggerCore()->action(UseAddressInBreakpointsView),
SIGNAL(toggled(bool)),
SLOT(showAddressColumn(bool)));
connect(debuggerCore()->action(AlwaysAdjustBreakpointsColumnWidths),
SIGNAL(toggled(bool)),
SLOT(setAlwaysResizeColumnsToContents(bool)));
SIGNAL(toggled(bool)), SLOT(showAddressColumn(bool)));
}
void BreakWindow::showAddressColumn(bool on)
......@@ -514,11 +501,6 @@ void BreakWindow::keyPressEvent(QKeyEvent *ev)
QTreeView::keyPressEvent(ev);
}
void BreakWindow::resizeEvent(QResizeEvent *ev)
{
QTreeView::resizeEvent(ev);
}
void BreakWindow::mouseDoubleClickEvent(QMouseEvent *ev)
{
QModelIndex indexUnderMouse = indexAt(ev->pos());
......@@ -531,14 +513,10 @@ void BreakWindow::mouseDoubleClickEvent(QMouseEvent *ev)
void BreakWindow::setModel(QAbstractItemModel *model)
{
QTreeView::setModel(model);
BaseWindow::setModel(model);
resizeColumnToContents(0); // Number
resizeColumnToContents(3); // Line
resizeColumnToContents(6); // Ignore count
if (header()) {
bool adjust = debuggerCore()->boolSetting(AlwaysAdjustBreakpointsColumnWidths);
setAlwaysResizeColumnsToContents(adjust);
}
connect(model, SIGNAL(layoutChanged()), this, SLOT(expandAll()));
}
......@@ -631,10 +609,7 @@ void BreakWindow::contextMenuEvent(QContextMenuEvent *ev)
menu.addSeparator();
menu.addAction(debuggerCore()->action(UseToolTipsInBreakpointsView));
menu.addAction(debuggerCore()->action(UseAddressInBreakpointsView));
menu.addAction(adjustColumnAction);
menu.addAction(debuggerCore()->action(AlwaysAdjustBreakpointsColumnWidths));
menu.addSeparator();
menu.addAction(debuggerCore()->action(SettingsDialog));
addBaseContextActions(&menu);
QAction *act = menu.exec(ev->globalPos());
......@@ -656,6 +631,8 @@ void BreakWindow::contextMenuEvent(QContextMenuEvent *ev)
setBreakpointsEnabled(selectedIds, !enabled);
else if (act == addBreakpointAction)
addBreakpoint();
else
handleBaseContextAction(act);
}
void BreakWindow::setBreakpointsEnabled(const BreakpointModelIds &ids, bool enabled)
......@@ -743,20 +720,6 @@ void BreakWindow::associateBreakpoint(const BreakpointModelIds &ids, int threadI
handler->setThreadSpec(id, threadId);
}
void BreakWindow::resizeColumnsToContents()
{
for (int i = model()->columnCount(); --i >= 0; )
resizeColumnToContents(i);
}
void BreakWindow::setAlwaysResizeColumnsToContents(bool on)
{
QHeaderView::ResizeMode mode = on
? QHeaderView::ResizeToContents : QHeaderView::Interactive;
for (int i = model()->columnCount(); --i >= 0; )
header()->setResizeMode(i, mode);
}
void BreakWindow::rowActivated(const QModelIndex &index)
{
breakHandler()->gotoLocation(breakHandler()->findBreakpointByIndex(index));
......
......@@ -34,13 +34,12 @@
#define DEBUGGER_BREAKWINDOW_H
#include "breakpoint.h"
#include <QtGui/QTreeView>
#include "basewindow.h"
namespace Debugger {
namespace Internal {
class BreakWindow : public QTreeView
class BreakWindow : public BaseWindow
{
Q_OBJECT
......@@ -51,15 +50,10 @@ public:
void setModel(QAbstractItemModel *model);
private slots:
void resizeColumnsToContents();
void setAlwaysResizeColumnsToContents(bool on);
void rowActivated(const QModelIndex &index);
void setAlternatingRowColorsHelper(bool on) { setAlternatingRowColors(on); }
void showAddressColumn(bool on);
private:
void resizeEvent(QResizeEvent *ev);
void rowActivated(const QModelIndex &index);
void contextMenuEvent(QContextMenuEvent *ev);
void keyPressEvent(QKeyEvent *ev);
void mouseDoubleClickEvent(QMouseEvent *ev);
......
......@@ -16,7 +16,9 @@ QT += gui \
network \
script
HEADERS += breakhandler.h \
HEADERS += \
basewindow.h \
breakhandler.h \
breakpoint.h \
breakpointmarker.h \
breakwindow.h \
......@@ -67,7 +69,9 @@ HEADERS += breakhandler.h \
debuggersourcepathmappingwidget.h \
memoryview.h
SOURCES += breakhandler.cpp \
SOURCES += \
basewindow.cpp \
breakhandler.cpp \
breakpoint.cpp \
breakpointmarker.cpp \
breakwindow.cpp \
......
......@@ -58,23 +58,13 @@ namespace Debugger {
namespace Internal {
ModulesWindow::ModulesWindow(QWidget *parent)
: QTreeView(parent)
: BaseWindow(parent)
{
QAction *act = debuggerCore()->action(UseAlternatingRowColors);
setWindowTitle(tr("Modules"));
setAttribute(Qt::WA_MacShowFocusRect, false);
setSortingEnabled(true);
setAlternatingRowColors(act->isChecked());
setRootIsDecorated(false);
setIconSize(QSize(10, 10));
setAlwaysAdjustColumnsAction(debuggerCore()->action(AlwaysAdjustModulesColumnWidths));
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)
......@@ -163,19 +153,12 @@ void ModulesWindow::contextMenuEvent(QContextMenuEvent *ev)
menu.addAction(actLoadSymbolsForModule);
menu.addAction(actEditFile);
menu.addAction(actShowModuleSymbols);
menu.addSeparator();
QAction *actAdjustColumnWidths =
menu.addAction(tr("Adjust Column Widths to Contents"));
menu.addAction(debuggerCore()->action(AlwaysAdjustModulesColumnWidths));
menu.addSeparator();
menu.addAction(debuggerCore()->action(SettingsDialog));
addBaseContextActions(&menu);
QAction *act = menu.exec(ev->globalPos());
if (act == actUpdateModuleList)
engine->reloadModules();
else if (act == actAdjustColumnWidths)
resizeColumnsToContents();
else if (act == actShowModuleSources)
engine->loadSymbols(name);
else if (act == actLoadSymbolsForAllModules)
......@@ -190,35 +173,8 @@ void ModulesWindow::contextMenuEvent(QContextMenuEvent *ev)
engine->requestModuleSymbols(name);
else if (actShowDependencies && act == actShowDependencies)
QProcess::startDetached(QLatin1String("depends"), QStringList(fileName));
}
void ModulesWindow::resizeColumnsToContents()
{
resizeColumnToContents(0);
resizeColumnToContents(1);
resizeColumnToContents(2);
resizeColumnToContents(3);
}
void ModulesWindow::setAlwaysResizeColumnsToContents(bool on)
{
QHeaderView::ResizeMode mode = on
? QHeaderView::ResizeToContents : QHeaderView::Interactive;
header()->setResizeMode(0, mode);
header()->setResizeMode(1, mode);
header()->setResizeMode(2, mode);
header()->setResizeMode(3, mode);
header()->setResizeMode(4, mode);
//setColumnHidden(3, true);
}
void ModulesWindow::setModel(QAbstractItemModel *model)
{
QTreeView::setModel(model);
if (header()) {
bool adjust = debuggerCore()->boolSetting(AlwaysAdjustModulesColumnWidths);
setAlwaysResizeColumnsToContents(adjust);
}
else
handleBaseContextAction(act);
}
} // namespace Internal
......
......@@ -33,12 +33,12 @@
#ifndef DEBUGGER_MODULESWINDOW_H
#define DEBUGGER_MODULESWINDOW_H
#include <QtGui/QTreeView>
#include "basewindow.h"
namespace Debugger {
namespace Internal {
class ModulesWindow : public QTreeView
class ModulesWindow : public BaseWindow
{
Q_OBJECT
......@@ -46,14 +46,10 @@ public:
explicit ModulesWindow(QWidget *parent = 0);
private slots:
void resizeColumnsToContents();
void setAlwaysResizeColumnsToContents(bool on);
void moduleActivated(const QModelIndex &index);
void setAlternatingRowColorsHelper(bool on) { setAlternatingRowColors(on); }
private:
void contextMenuEvent(QContextMenuEvent *ev);
void setModel(QAbstractItemModel *model);
};
} // namespace Internal
......
......@@ -164,21 +164,11 @@ public:
///////////////////////////////////////////////////////////////////////
RegisterWindow::RegisterWindow(QWidget *parent)
: QTreeView(parent)
: BaseWindow(parent)
{
QAction *act = debuggerCore()->action(UseAlternatingRowColors);
setFrameStyle(QFrame::NoFrame);
setWindowTitle(tr("Registers"));
setAttribute(Qt::WA_MacShowFocusRect, false);
setAlternatingRowColors(act->isChecked());
setRootIsDecorated(false);
setAlwaysAdjustColumnsAction(debuggerCore()->action(UseAlternatingRowColors));
setItemDelegate(new RegisterDelegate(this));
connect(act, SIGNAL(toggled(bool)),
SLOT(setAlternatingRowColorsHelper(bool)));
connect(debuggerCore()->action(AlwaysAdjustRegistersColumnWidths),
SIGNAL(toggled(bool)),
SLOT(setAlwaysResizeColumnsToContents(bool)));
setObjectName(QLatin1String("RegisterWindow"));
}
......@@ -245,20 +235,13 @@ void RegisterWindow::contextMenuEvent(QContextMenuEvent *ev)
QAction *act2 = menu.addAction(tr("Binary"));
act2->setCheckable(true);
act2->setChecked(base == 2);
menu.addSeparator();
QAction *actAdjust = menu.addAction(tr("Adjust Column Widths to Contents"));
menu.addAction(debuggerCore()->action(AlwaysAdjustRegistersColumnWidths));
menu.addSeparator();
menu.addAction(debuggerCore()->action(SettingsDialog));
addBaseContextActions(&menu);
const QPoint position = ev->globalPos();
QAction *act = menu.exec(position);
if (act == actAdjust)
resizeColumnsToContents();
else if (act == actReload)
if (act == actReload)
engine->reloadRegisters();
else if (act == actEditMemory) {
const QString registerName = QString::fromAscii(aRegister.name, address);
......@@ -285,29 +268,8 @@ void RegisterWindow::contextMenuEvent(QContextMenuEvent *ev)
handler->setNumberBase(8);
else if (act == act2)
handler->setNumberBase(2);
}
void RegisterWindow::resizeColumnsToContents()
{
resizeColumnToContents(0);
resizeColumnToContents(1);
}
void RegisterWindow::setAlwaysResizeColumnsToContents(bool on)
{
QHeaderView::ResizeMode mode = on
? QHeaderView::ResizeToContents : QHeaderView::Interactive;
header()->setResizeMode(0, mode);
header()->setResizeMode(1, mode);
}
void RegisterWindow::setModel(QAbstractItemModel *model)
{
QTreeView::setModel(model);
if (header()) {
bool adjust = debuggerCore()->boolSetting(AlwaysAdjustRegistersColumnWidths);
setAlwaysResizeColumnsToContents(adjust);
}
else
handleBaseContextAction(act);
}
void RegisterWindow::reloadRegisters()
......
......@@ -33,27 +33,23 @@
#ifndef DEBUGGER_REGISTERWINDOW_H
#define DEBUGGER_REGISTERWINDOW_H
#include <QtGui/QTreeView>
#include "basewindow.h"
namespace Debugger {
namespace Internal {
class RegisterWindow : public QTreeView
class RegisterWindow : public BaseWindow
{
Q_OBJECT
public:
explicit RegisterWindow(QWidget *parent = 0);
void setModel(QAbstractItemModel *model);
public slots:
void resizeColumnsToContents();
void setAlwaysResizeColumnsToContents(bool on);
void setAlternatingRowColorsHelper(bool on) { setAlternatingRowColors(on); }
void reloadRegisters();
private:
virtual void contextMenuEvent(QContextMenuEvent *ev);
void contextMenuEvent(QContextMenuEvent *ev);
};
} // namespace Internal
......
......@@ -59,24 +59,8 @@ namespace Internal {
SnapshotWindow::SnapshotWindow(SnapshotHandler *handler)
{
m_snapshotHandler = handler;
QAction *act = debuggerCore()->action(UseAlternatingRowColors);
setWindowTitle(tr("Snapshots"));
setAttribute(Qt::WA_MacShowFocusRect, false);
setFrameStyle(QFrame::NoFrame);
setAlternatingRowColors(act->isChecked());
setRootIsDecorated(false);
setIconSize(QSize(10, 10));
header()->setDefaultAlignment(Qt::AlignLeft);
connect(this, SIGNAL(activated(QModelIndex)),
SLOT(rowActivated(QModelIndex)));
connect(act, SIGNAL(toggled(bool)),
SLOT(setAlternatingRowColorsHelper(bool)));
connect(debuggerCore()->action(AlwaysAdjustSnapshotsColumnWidths),
SIGNAL(toggled(bool)),
SLOT(setAlwaysResizeColumnsToContents(bool)));
setAlwaysAdjustColumnsAction(debuggerCore()->action(AlwaysAdjustSnapshotsColumnWidths));
}
void SnapshotWindow::rowActivated(const QModelIndex &index)
......@@ -112,13 +96,8 @@ void SnapshotWindow::contextMenuEvent(QContextMenuEvent *ev)