Commit 47fea305 authored by hjk's avatar hjk Committed by hjk
Browse files

debugger: rework the searchable view

This reverts most of commit 32ec6095


and keeps the tree widgets fully accessible.

Change-Id: I34422c175bc43261bb8fe48e0130acb71cdfd721
Reviewed-by: default avatarhjk <qthjk@ovi.com>
parent 3a8ad685
......@@ -38,7 +38,6 @@
#include <aggregation/aggregate.h>
#include <coreplugin/findplaceholder.h>
#include <find/treeviewfind.h>
#include <utils/qtcassert.h>
#include <utils/savedaction.h>
#include <QContextMenuEvent>
......@@ -50,52 +49,41 @@
namespace Debugger {
namespace Internal {
BaseWindow::BaseWindow(QWidget *parent)
: QWidget(parent)
BaseTreeView::BaseTreeView(QWidget *parent)
: QTreeView(parent)
{
QAction *act = debuggerCore()->action(UseAlternatingRowColors);
m_treeView = new QTreeView(this);
m_treeView->setAttribute(Qt::WA_MacShowFocusRect, false);
m_treeView->setFrameStyle(QFrame::NoFrame);
m_treeView->setAlternatingRowColors(act->isChecked());
m_treeView->setRootIsDecorated(false);
m_treeView->setIconSize(QSize(10, 10));
m_treeView->setSelectionMode(QAbstractItemView::ExtendedSelection);
m_treeView->setUniformRowHeights(true);
setAttribute(Qt::WA_MacShowFocusRect, false);
setFrameStyle(QFrame::NoFrame);
setAlternatingRowColors(act->isChecked());
setRootIsDecorated(false);
setIconSize(QSize(10, 10));
setSelectionMode(QAbstractItemView::ExtendedSelection);
setUniformRowHeights(true);
m_treeView->header()->setDefaultAlignment(Qt::AlignLeft);
m_treeView->header()->setClickable(true);
header()->setDefaultAlignment(Qt::AlignLeft);
header()->setClickable(true);
connect(act, SIGNAL(toggled(bool)),
SLOT(setAlternatingRowColorsHelper(bool)));
connect(m_treeView, SIGNAL(activated(QModelIndex)),
connect(this, SIGNAL(activated(QModelIndex)),
SLOT(rowActivatedHelper(QModelIndex)));
connect(m_treeView->header(), SIGNAL(sectionClicked(int)),
connect(header(), SIGNAL(sectionClicked(int)),
SLOT(headerSectionClicked(int)));
QVBoxLayout *vbox = new QVBoxLayout(this);
vbox->setMargin(0);
vbox->setSpacing(0);
vbox->addWidget(m_treeView);
vbox->addWidget(new Core::FindToolBarPlaceHolder(this));
Aggregation::Aggregate *agg = new Aggregation::Aggregate;
agg->add(m_treeView);
agg->add(new Find::TreeViewFind(m_treeView));
m_adjustColumnsAction = new QAction(tr("Adjust Column Widths to Contents"), 0);
m_alwaysAdjustColumnsAction = 0;
}
void BaseWindow::setAlwaysAdjustColumnsAction(QAction *action)
void BaseTreeView::setAlwaysAdjustColumnsAction(QAction *action)
{
m_alwaysAdjustColumnsAction = action;
connect(action, SIGNAL(toggled(bool)),
SLOT(setAlwaysResizeColumnsToContents(bool)));
}
void BaseWindow::addBaseContextActions(QMenu *menu)
void BaseTreeView::addBaseContextActions(QMenu *menu)
{
menu->addSeparator();
if (m_alwaysAdjustColumnsAction)
......@@ -105,7 +93,7 @@ void BaseWindow::addBaseContextActions(QMenu *menu)
menu->addAction(debuggerCore()->action(SettingsDialog));
}
bool BaseWindow::handleBaseContextAction(QAction *act)
bool BaseTreeView::handleBaseContextAction(QAction *act)
{
if (act == 0)
return true;
......@@ -122,68 +110,59 @@ bool BaseWindow::handleBaseContextAction(QAction *act)
return false;
}
void BaseWindow::setModel(QAbstractItemModel *model)
void BaseTreeView::setModel(QAbstractItemModel *model)
{
m_treeView->setModel(model);
if (m_treeView->header() && m_alwaysAdjustColumnsAction)
QTreeView::setModel(model);
if (header() && m_alwaysAdjustColumnsAction)
setAlwaysResizeColumnsToContents(m_alwaysAdjustColumnsAction->isChecked());
}
void BaseWindow::mousePressEvent(QMouseEvent *ev)
void BaseTreeView::mousePressEvent(QMouseEvent *ev)
{
QWidget::mousePressEvent(ev);
if (!m_treeView->indexAt(ev->pos()).isValid())
QTreeView::mousePressEvent(ev);
if (!indexAt(ev->pos()).isValid())
resizeColumnsToContents();
}
void BaseWindow::resizeColumnsToContents()
void BaseTreeView::resizeColumnsToContents()
{
const int columnCount = model()->columnCount();
for (int c = 0 ; c != columnCount; ++c)
resizeColumnToContents(c);
}
void BaseWindow::setAlwaysResizeColumnsToContents(bool on)
void BaseTreeView::setAlwaysResizeColumnsToContents(bool on)
{
QHeaderView::ResizeMode mode = on
? QHeaderView::ResizeToContents : QHeaderView::Interactive;
m_treeView->header()->setResizeMode(0, mode);
}
void BaseWindow::setAlternatingRowColorsHelper(bool on)
{
m_treeView->setAlternatingRowColors(on);
header()->setResizeMode(0, mode);
}
void BaseWindow::rowActivatedHelper(const QModelIndex &index)
{
rowActivated(index);
}
void BaseWindow::headerSectionClicked(int logicalIndex)
void BaseTreeView::headerSectionClicked(int logicalIndex)
{
resizeColumnToContents(logicalIndex);
}
void BaseWindow::reset()
void BaseTreeView::reset()
{
m_treeView->reset();
if (m_treeView->header() && m_alwaysAdjustColumnsAction
QTreeView::reset();
if (header() && m_alwaysAdjustColumnsAction
&& m_alwaysAdjustColumnsAction->isChecked())
resizeColumnsToContents();
}
QModelIndexList BaseWindow::selectedIndices(QContextMenuEvent *ev)
BaseWindow::BaseWindow(QTreeView *treeView, QWidget *parent)
: QWidget(parent), m_treeView(treeView)
{
QItemSelectionModel *sm = treeView()->selectionModel();
QTC_ASSERT(sm, return QModelIndexList());
QModelIndexList si = sm->selectedIndexes();
if (ev) {
QModelIndex indexUnderMouse = m_treeView->indexAt(ev->pos());
if (si.isEmpty() && indexUnderMouse.isValid())
si.append(indexUnderMouse);
}
return si;
QVBoxLayout *vbox = new QVBoxLayout(this);
vbox->setMargin(0);
vbox->setSpacing(0);
vbox->addWidget(m_treeView);
vbox->addWidget(new Core::FindToolBarPlaceHolder(this));
Aggregation::Aggregate *agg = new Aggregation::Aggregate;
agg->add(m_treeView);
agg->add(new Find::TreeViewFind(m_treeView));
}
} // namespace Internal
......
......@@ -38,42 +38,46 @@
namespace Debugger {
namespace Internal {
class BaseWindow : public QWidget
class BaseTreeView : public QTreeView
{
Q_OBJECT
public:
BaseWindow(QWidget *parent = 0);
virtual void setModel(QAbstractItemModel *model);
QHeaderView *header() const { return m_treeView->header(); }
QAbstractItemModel *model() const { return m_treeView->model(); }
BaseTreeView(QWidget *parent = 0);
void setAlwaysAdjustColumnsAction(QAction *action);
void addBaseContextActions(QMenu *menu);
bool handleBaseContextAction(QAction *action);
protected slots:
void setModel(QAbstractItemModel *model);
virtual void rowActivated(const QModelIndex &) {}
void mousePressEvent(QMouseEvent *ev);
public slots:
void resizeColumnsToContents();
void setAlwaysResizeColumnsToContents(bool on);
private slots:
void setAlternatingRowColorsHelper(bool on);
void rowActivatedHelper(const QModelIndex &index);
void setAlternatingRowColorsHelper(bool on) { setAlternatingRowColors(on); }
void rowActivatedHelper(const QModelIndex &index) { rowActivated(index); }
void headerSectionClicked(int logicalIndex);
void reset();
protected:
void setAlwaysAdjustColumnsAction(QAction *action);
void addBaseContextActions(QMenu *menu);
bool handleBaseContextAction(QAction *action);
private:
QAction *m_alwaysAdjustColumnsAction;
QAction *m_adjustColumnsAction;
};
QTreeView *treeView() const { return m_treeView; }
QModelIndex indexAt(const QPoint &p) const { return m_treeView->indexAt(p); }
void resizeColumnToContents(int col) { m_treeView->resizeColumnToContents(col); }
void mousePressEvent(QMouseEvent *ev);
virtual void rowActivated(const QModelIndex &) {}
QModelIndexList selectedIndices(QContextMenuEvent *ev = 0);
class BaseWindow : public QWidget
{
public:
explicit BaseWindow(QTreeView *treeView, QWidget *parent = 0);
void setModel(QAbstractItemModel *model) { m_treeView->setModel(model); }
QHeaderView *header() const { return m_treeView->header(); }
QAbstractItemModel *model() const { return m_treeView->model(); }
private:
QTreeView *m_treeView;
QAction *m_alwaysAdjustColumnsAction;
QAction *m_adjustColumnsAction;
};
} // namespace Internal
......
......@@ -486,65 +486,68 @@ MultiBreakPointsDialog::MultiBreakPointsDialog(QWidget *parent) :
//
///////////////////////////////////////////////////////////////////////
BreakWindow::BreakWindow(QWidget *parent)
: BaseWindow(parent)
BreakTreeView::BreakTreeView(QWidget *parent)
: BaseTreeView(parent)
{
setWindowTitle(tr("Breakpoints"));
setObjectName(QLatin1String("ThreadsWindow"));
setWindowIcon(QIcon(QLatin1String(":/debugger/images/debugger_breakpoints.png")));
treeView()->setSelectionMode(QAbstractItemView::ExtendedSelection);
setSelectionMode(QAbstractItemView::ExtendedSelection);
setAlwaysAdjustColumnsAction(debuggerCore()->action(AlwaysAdjustBreakpointsColumnWidths));
connect(debuggerCore()->action(UseAddressInBreakpointsView),
SIGNAL(toggled(bool)), SLOT(showAddressColumn(bool)));
}
void BreakWindow::showAddressColumn(bool on)
void BreakTreeView::showAddressColumn(bool on)
{
treeView()->setColumnHidden(7, !on);
setColumnHidden(7, !on);
}
void BreakWindow::keyPressEvent(QKeyEvent *ev)
void BreakTreeView::keyPressEvent(QKeyEvent *ev)
{
if (ev->key() == Qt::Key_Delete) {
QItemSelectionModel *sm = treeView()->selectionModel();
QItemSelectionModel *sm = selectionModel();
QTC_ASSERT(sm, return);
QModelIndexList si = sm->selectedIndexes();
if (si.isEmpty())
si.append(treeView()->currentIndex());
si.append(currentIndex());
const BreakpointModelIds ids = breakHandler()->findBreakpointsByIndex(si);
int row = qMin(model()->rowCount() - ids.size() - 1, treeView()->currentIndex().row());
int row = qMin(model()->rowCount() - ids.size() - 1, currentIndex().row());
deleteBreakpoints(ids);
treeView()->setCurrentIndex(si.at(0).sibling(row, 0));
setCurrentIndex(si.at(0).sibling(row, 0));
}
BaseWindow::keyPressEvent(ev);
QTreeView::keyPressEvent(ev);
}
void BreakWindow::mouseDoubleClickEvent(QMouseEvent *ev)
void BreakTreeView::mouseDoubleClickEvent(QMouseEvent *ev)
{
QModelIndex indexUnderMouse = indexAt(ev->pos());
if (indexUnderMouse.isValid() && indexUnderMouse.column() >= 4) {
BreakpointModelId id = breakHandler()->findBreakpointByIndex(indexUnderMouse);
editBreakpoints(BreakpointModelIds() << id);
}
BaseWindow::mouseDoubleClickEvent(ev);
QTreeView::mouseDoubleClickEvent(ev);
}
void BreakWindow::setModel(QAbstractItemModel *model)
void BreakTreeView::setModel(QAbstractItemModel *model)
{
BaseWindow::setModel(model);
BaseTreeView::setModel(model);
resizeColumnToContents(0); // Number
resizeColumnToContents(3); // Line
resizeColumnToContents(6); // Ignore count
connect(model, SIGNAL(layoutChanged()), treeView(), SLOT(expandAll()));
connect(model, SIGNAL(layoutChanged()), this, SLOT(expandAll()));
}
void BreakWindow::contextMenuEvent(QContextMenuEvent *ev)
void BreakTreeView::contextMenuEvent(QContextMenuEvent *ev)
{
QMenu menu;
QItemSelectionModel *sm = selectionModel();
QTC_ASSERT(sm, return);
QModelIndexList selectedIndices = sm->selectedIndexes();
QModelIndex indexUnderMouse = indexAt(ev->pos());
if (selectedIndices.isEmpty() && indexUnderMouse.isValid())
selectedIndices.append(indexUnderMouse);
QModelIndexList si = selectedIndices();
BreakHandler *handler = breakHandler();
BreakpointModelIds selectedIds = handler->findBreakpointsByIndex(si);
BreakpointModelIds selectedIds = handler->findBreakpointsByIndex(selectedIndices);
const int rowCount = model()->rowCount();
QAction *deleteAction = new QAction(tr("Delete Breakpoint"), &menu);
......@@ -556,8 +559,8 @@ void BreakWindow::contextMenuEvent(QContextMenuEvent *ev)
// Delete by file: Find indices of breakpoints of the same file.
QAction *deleteByFileAction = 0;
BreakpointModelIds breakpointsInFile;
if (si.size() == 1) {
const QModelIndex index = si.at(0).sibling(si.at(0).row(), 2);
if (indexUnderMouse.isValid()) {
const QModelIndex index = indexUnderMouse.sibling(indexUnderMouse.row(), 2);
const QString file = index.data().toString();
if (!file.isEmpty()) {
for (int i = 0; i != rowCount; ++i)
......@@ -649,21 +652,21 @@ void BreakWindow::contextMenuEvent(QContextMenuEvent *ev)
handleBaseContextAction(act);
}
void BreakWindow::setBreakpointsEnabled(const BreakpointModelIds &ids, bool enabled)
void BreakTreeView::setBreakpointsEnabled(const BreakpointModelIds &ids, bool enabled)
{
BreakHandler *handler = breakHandler();
foreach (const BreakpointModelId id, ids)
handler->setEnabled(id, enabled);
}
void BreakWindow::deleteBreakpoints(const BreakpointModelIds &ids)
void BreakTreeView::deleteBreakpoints(const BreakpointModelIds &ids)
{
BreakHandler *handler = breakHandler();
foreach (const BreakpointModelId id, ids)
handler->removeBreakpoint(id);
}
void BreakWindow::editBreakpoint(BreakpointModelId id, QWidget *parent)
void BreakTreeView::editBreakpoint(BreakpointModelId id, QWidget *parent)
{
BreakpointParameters data = breakHandler()->breakpointData(id);
BreakpointParts parts = NoParts;
......@@ -672,7 +675,7 @@ void BreakWindow::editBreakpoint(BreakpointModelId id, QWidget *parent)
breakHandler()->changeBreakpointData(id, data, parts);
}
void BreakWindow::addBreakpoint()
void BreakTreeView::addBreakpoint()
{
BreakpointParameters data(BreakpointByFileAndLine);
BreakpointParts parts = NoParts;
......@@ -682,7 +685,7 @@ void BreakWindow::addBreakpoint()
breakHandler()->appendBreakpoint(data);
}
void BreakWindow::editBreakpoints(const BreakpointModelIds &ids)
void BreakTreeView::editBreakpoints(const BreakpointModelIds &ids)
{
QTC_ASSERT(!ids.isEmpty(), return);
......@@ -721,18 +724,24 @@ void BreakWindow::editBreakpoints(const BreakpointModelIds &ids)
}
}
void BreakWindow::associateBreakpoint(const BreakpointModelIds &ids, int threadId)
void BreakTreeView::associateBreakpoint(const BreakpointModelIds &ids, int threadId)
{
BreakHandler *handler = breakHandler();
foreach (const BreakpointModelId id, ids)
handler->setThreadSpec(id, threadId);
}
void BreakWindow::rowActivated(const QModelIndex &index)
void BreakTreeView::rowActivated(const QModelIndex &index)
{
breakHandler()->gotoLocation(breakHandler()->findBreakpointByIndex(index));
}
BreakWindow::BreakWindow()
: BaseWindow(new BreakTreeView)
{
setWindowTitle(tr("Breakpoints"));
}
} // namespace Internal
} // namespace Debugger
......
......@@ -39,12 +39,12 @@
namespace Debugger {
namespace Internal {
class BreakWindow : public BaseWindow
class BreakTreeView : public BaseTreeView
{
Q_OBJECT
public:
explicit BreakWindow(QWidget *parent = 0);
explicit BreakTreeView(QWidget *parent = 0);
static void editBreakpoint(BreakpointModelId id, QWidget *parent);
void setModel(QAbstractItemModel *model);
......@@ -65,6 +65,12 @@ private:
void setBreakpointsEnabled(const BreakpointModelIds &ids, bool enabled);
};
class BreakWindow : public BaseWindow
{
public:
BreakWindow();
};
} // namespace Internal
} // namespace Debugger
......
......@@ -1001,7 +1001,7 @@ public slots:
QTC_ASSERT(act, return);
const BreakpointModelId id = act->data().value<BreakpointModelId>();
QTC_ASSERT(id > 0, return);
BreakWindow::editBreakpoint(id, mainWindow());
BreakTreeView::editBreakpoint(id, mainWindow());
}
void slotRunToLine()
......@@ -1169,16 +1169,16 @@ public:
Utils::StatusLabel *m_statusLabel;
QComboBox *m_threadBox;
BreakWindow *m_breakWindow;
BaseWindow *m_breakWindow;
BreakHandler *m_breakHandler;
QtMessageLogWindow *m_qtMessageLogWindow;
BaseWindow *m_returnWindow;
BaseWindow *m_localsWindow;
BaseWindow *m_watchersWindow;
WatchWindow *m_returnWindow;
WatchWindow *m_localsWindow;
WatchWindow *m_watchersWindow;
BaseWindow *m_registerWindow;
BaseWindow *m_modulesWindow;
BaseWindow *m_snapshotWindow;
SourceFilesWindow *m_sourceFilesWindow;
BaseWindow *m_sourceFilesWindow;
BaseWindow *m_stackWindow;
BaseWindow *m_threadsWindow;
LogWindow *m_logWindow;
......@@ -2908,11 +2908,11 @@ void DebuggerPluginPrivate::extensionsInitialized()
m_sourceFilesWindow->setObjectName(QLatin1String(DOCKWIDGET_SOURCE_FILES));
m_threadsWindow = new ThreadsWindow;
m_threadsWindow->setObjectName(QLatin1String(DOCKWIDGET_THREADS));
m_returnWindow = new WatchWindow(WatchWindow::ReturnType);
m_returnWindow = new WatchWindow(WatchTreeView::ReturnType);
m_returnWindow->setObjectName(QLatin1String("CppDebugReturn"));
m_localsWindow = new WatchWindow(WatchWindow::LocalsType);
m_localsWindow = new WatchWindow(WatchTreeView::LocalsType);
m_localsWindow->setObjectName(QLatin1String("CppDebugLocals"));
m_watchersWindow = new WatchWindow(WatchWindow::WatchersType);
m_watchersWindow = new WatchWindow(WatchTreeView::WatchersType);
m_watchersWindow->setObjectName(QLatin1String("CppDebugWatchers"));
// Snapshot
......
......@@ -57,18 +57,17 @@
namespace Debugger {
namespace Internal {
ModulesWindow::ModulesWindow(QWidget *parent)
: BaseWindow(parent)
ModulesTreeView::ModulesTreeView(QWidget *parent)
: BaseTreeView(parent)
{
setWindowTitle(tr("Modules"));
treeView()->setSortingEnabled(true);
setSortingEnabled(true);
setAlwaysAdjustColumnsAction(debuggerCore()->action(AlwaysAdjustModulesColumnWidths));
connect(treeView(), SIGNAL(activated(QModelIndex)),
connect(this, SIGNAL(activated(QModelIndex)),
SLOT(moduleActivated(QModelIndex)));
}
void ModulesWindow::moduleActivated(const QModelIndex &index)
void ModulesTreeView::moduleActivated(const QModelIndex &index)
{
DebuggerEngine *engine = debuggerCore()->currentEngine();
QTC_ASSERT(engine, return);
......@@ -76,11 +75,11 @@ void ModulesWindow::moduleActivated(const QModelIndex &index)
engine->gotoLocation(index.sibling(index.row(), 1).data().toString());
}
void ModulesWindow::contextMenuEvent(QContextMenuEvent *ev)
void ModulesTreeView::contextMenuEvent(QContextMenuEvent *ev)
{
QString name;
QString fileName;
QModelIndex index = treeView()->indexAt(ev->pos());
QModelIndex index = indexAt(ev->pos());
if (index.isValid())
index = index.sibling(index.row(), 0);
if (index.isValid()) {
......@@ -174,5 +173,11 @@ void ModulesWindow::contextMenuEvent(QContextMenuEvent *ev)
handleBaseContextAction(act);
}
ModulesWindow::ModulesWindow()
: BaseWindow(new ModulesTreeView)
{
setWindowTitle(tr("Modules"));
}
} // namespace Internal
} // namespace Debugger
......@@ -38,12 +38,12 @@
namespace Debugger {
namespace Internal {
class ModulesWindow : public BaseWindow
class ModulesTreeView : public BaseTreeView
{
Q_OBJECT
public:
explicit ModulesWindow(QWidget *parent = 0);
explicit ModulesTreeView(QWidget *parent = 0);
private slots:
void moduleActivated(const QModelIndex &index);
......@@ -52,6 +52,12 @@ private:
void contextMenuEvent(QContextMenuEvent *ev);
};
class ModulesWindow : public BaseWindow
{
public:
ModulesWindow();
};
} // namespace Internal
} // namespace Debugger
......
......@@ -163,16 +163,14 @@ public:
//
///////////////////////////////////////////////////////////////////////
RegisterWindow::RegisterWindow(QWidget *parent)
: BaseWindow(parent)
RegisterTreeView::RegisterTreeView(QWidget *parent)
: BaseTreeView(parent)
{
setWindowTitle(tr("Registers"));
setAlwaysAdjustColumnsAction(debuggerCore()->action(UseAlternatingRowColors));
treeView()->setItemDelegate(new RegisterDelegate(this));
setObjectName(QLatin1String("RegisterWindow"));
setItemDelegate(new RegisterDelegate(this));
}
void RegisterWindow::contextMenuEvent(QContextMenuEvent *ev)
void RegisterTreeView::contextMenuEvent(QContextMenuEvent *ev)
{
QMenu menu;
......@@ -271,11 +269,17 @@ void RegisterWindow::contextMenuEvent(QContextMenuEvent *ev)
handleBaseContextAction(act);
}
void RegisterWindow::reloadRegisters()