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

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 @@ ...@@ -38,7 +38,6 @@
#include <aggregation/aggregate.h> #include <aggregation/aggregate.h>
#include <coreplugin/findplaceholder.h> #include <coreplugin/findplaceholder.h>
#include <find/treeviewfind.h> #include <find/treeviewfind.h>
#include <utils/qtcassert.h>
#include <utils/savedaction.h> #include <utils/savedaction.h>
#include <QContextMenuEvent> #include <QContextMenuEvent>
...@@ -50,52 +49,41 @@ ...@@ -50,52 +49,41 @@
namespace Debugger { namespace Debugger {
namespace Internal { namespace Internal {
BaseWindow::BaseWindow(QWidget *parent) BaseTreeView::BaseTreeView(QWidget *parent)
: QWidget(parent) : QTreeView(parent)
{ {
QAction *act = debuggerCore()->action(UseAlternatingRowColors); QAction *act = debuggerCore()->action(UseAlternatingRowColors);
m_treeView = new QTreeView(this); setAttribute(Qt::WA_MacShowFocusRect, false);
m_treeView->setAttribute(Qt::WA_MacShowFocusRect, false); setFrameStyle(QFrame::NoFrame);
m_treeView->setFrameStyle(QFrame::NoFrame); setAlternatingRowColors(act->isChecked());
m_treeView->setAlternatingRowColors(act->isChecked()); setRootIsDecorated(false);
m_treeView->setRootIsDecorated(false); setIconSize(QSize(10, 10));
m_treeView->setIconSize(QSize(10, 10)); setSelectionMode(QAbstractItemView::ExtendedSelection);
m_treeView->setSelectionMode(QAbstractItemView::ExtendedSelection); setUniformRowHeights(true);
m_treeView->setUniformRowHeights(true);
m_treeView->header()->setDefaultAlignment(Qt::AlignLeft); header()->setDefaultAlignment(Qt::AlignLeft);
m_treeView->header()->setClickable(true); header()->setClickable(true);
connect(act, SIGNAL(toggled(bool)), connect(act, SIGNAL(toggled(bool)),
SLOT(setAlternatingRowColorsHelper(bool))); SLOT(setAlternatingRowColorsHelper(bool)));
connect(m_treeView, SIGNAL(activated(QModelIndex)), connect(this, SIGNAL(activated(QModelIndex)),
SLOT(rowActivatedHelper(QModelIndex))); SLOT(rowActivatedHelper(QModelIndex)));
connect(m_treeView->header(), SIGNAL(sectionClicked(int)), connect(header(), SIGNAL(sectionClicked(int)),
SLOT(headerSectionClicked(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_adjustColumnsAction = new QAction(tr("Adjust Column Widths to Contents"), 0);
m_alwaysAdjustColumnsAction = 0; m_alwaysAdjustColumnsAction = 0;
} }
void BaseWindow::setAlwaysAdjustColumnsAction(QAction *action) void BaseTreeView::setAlwaysAdjustColumnsAction(QAction *action)
{ {
m_alwaysAdjustColumnsAction = action; m_alwaysAdjustColumnsAction = action;
connect(action, SIGNAL(toggled(bool)), connect(action, SIGNAL(toggled(bool)),
SLOT(setAlwaysResizeColumnsToContents(bool))); SLOT(setAlwaysResizeColumnsToContents(bool)));
} }
void BaseWindow::addBaseContextActions(QMenu *menu) void BaseTreeView::addBaseContextActions(QMenu *menu)
{ {
menu->addSeparator(); menu->addSeparator();
if (m_alwaysAdjustColumnsAction) if (m_alwaysAdjustColumnsAction)
...@@ -105,7 +93,7 @@ void BaseWindow::addBaseContextActions(QMenu *menu) ...@@ -105,7 +93,7 @@ void BaseWindow::addBaseContextActions(QMenu *menu)
menu->addAction(debuggerCore()->action(SettingsDialog)); menu->addAction(debuggerCore()->action(SettingsDialog));
} }
bool BaseWindow::handleBaseContextAction(QAction *act) bool BaseTreeView::handleBaseContextAction(QAction *act)
{ {
if (act == 0) if (act == 0)
return true; return true;
...@@ -122,68 +110,59 @@ bool BaseWindow::handleBaseContextAction(QAction *act) ...@@ -122,68 +110,59 @@ bool BaseWindow::handleBaseContextAction(QAction *act)
return false; return false;
} }
void BaseWindow::setModel(QAbstractItemModel *model) void BaseTreeView::setModel(QAbstractItemModel *model)
{ {
m_treeView->setModel(model); QTreeView::setModel(model);
if (m_treeView->header() && m_alwaysAdjustColumnsAction) if (header() && m_alwaysAdjustColumnsAction)
setAlwaysResizeColumnsToContents(m_alwaysAdjustColumnsAction->isChecked()); setAlwaysResizeColumnsToContents(m_alwaysAdjustColumnsAction->isChecked());
} }
void BaseWindow::mousePressEvent(QMouseEvent *ev) void BaseTreeView::mousePressEvent(QMouseEvent *ev)
{ {
QWidget::mousePressEvent(ev); QTreeView::mousePressEvent(ev);
if (!m_treeView->indexAt(ev->pos()).isValid()) if (!indexAt(ev->pos()).isValid())
resizeColumnsToContents(); resizeColumnsToContents();
} }
void BaseWindow::resizeColumnsToContents() void BaseTreeView::resizeColumnsToContents()
{ {
const int columnCount = model()->columnCount(); const int columnCount = model()->columnCount();
for (int c = 0 ; c != columnCount; ++c) for (int c = 0 ; c != columnCount; ++c)
resizeColumnToContents(c); resizeColumnToContents(c);
} }
void BaseWindow::setAlwaysResizeColumnsToContents(bool on) void BaseTreeView::setAlwaysResizeColumnsToContents(bool on)
{ {
QHeaderView::ResizeMode mode = on QHeaderView::ResizeMode mode = on
? QHeaderView::ResizeToContents : QHeaderView::Interactive; ? QHeaderView::ResizeToContents : QHeaderView::Interactive;
m_treeView->header()->setResizeMode(0, mode); header()->setResizeMode(0, mode);
}
void BaseWindow::setAlternatingRowColorsHelper(bool on)
{
m_treeView->setAlternatingRowColors(on);
} }
void BaseWindow::rowActivatedHelper(const QModelIndex &index) void BaseTreeView::headerSectionClicked(int logicalIndex)
{
rowActivated(index);
}
void BaseWindow::headerSectionClicked(int logicalIndex)
{ {
resizeColumnToContents(logicalIndex); resizeColumnToContents(logicalIndex);
} }
void BaseWindow::reset() void BaseTreeView::reset()
{ {
m_treeView->reset(); QTreeView::reset();
if (m_treeView->header() && m_alwaysAdjustColumnsAction if (header() && m_alwaysAdjustColumnsAction
&& m_alwaysAdjustColumnsAction->isChecked()) && m_alwaysAdjustColumnsAction->isChecked())
resizeColumnsToContents(); resizeColumnsToContents();
} }
QModelIndexList BaseWindow::selectedIndices(QContextMenuEvent *ev) BaseWindow::BaseWindow(QTreeView *treeView, QWidget *parent)
: QWidget(parent), m_treeView(treeView)
{ {
QItemSelectionModel *sm = treeView()->selectionModel(); QVBoxLayout *vbox = new QVBoxLayout(this);
QTC_ASSERT(sm, return QModelIndexList()); vbox->setMargin(0);
QModelIndexList si = sm->selectedIndexes(); vbox->setSpacing(0);
if (ev) { vbox->addWidget(m_treeView);
QModelIndex indexUnderMouse = m_treeView->indexAt(ev->pos()); vbox->addWidget(new Core::FindToolBarPlaceHolder(this));
if (si.isEmpty() && indexUnderMouse.isValid())
si.append(indexUnderMouse); Aggregation::Aggregate *agg = new Aggregation::Aggregate;
} agg->add(m_treeView);
return si; agg->add(new Find::TreeViewFind(m_treeView));
} }
} // namespace Internal } // namespace Internal
......
...@@ -38,42 +38,46 @@ ...@@ -38,42 +38,46 @@
namespace Debugger { namespace Debugger {
namespace Internal { namespace Internal {
class BaseWindow : public QWidget class BaseTreeView : public QTreeView
{ {
Q_OBJECT Q_OBJECT
public: public:
BaseWindow(QWidget *parent = 0); BaseTreeView(QWidget *parent = 0);
virtual void setModel(QAbstractItemModel *model);
QHeaderView *header() const { return m_treeView->header(); } void setAlwaysAdjustColumnsAction(QAction *action);
QAbstractItemModel *model() const { return m_treeView->model(); } 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 resizeColumnsToContents();
void setAlwaysResizeColumnsToContents(bool on); void setAlwaysResizeColumnsToContents(bool on);
private slots: private slots:
void setAlternatingRowColorsHelper(bool on); void setAlternatingRowColorsHelper(bool on) { setAlternatingRowColors(on); }
void rowActivatedHelper(const QModelIndex &index); void rowActivatedHelper(const QModelIndex &index) { rowActivated(index); }
void headerSectionClicked(int logicalIndex); void headerSectionClicked(int logicalIndex);
void reset(); void reset();
protected: private:
void setAlwaysAdjustColumnsAction(QAction *action); QAction *m_alwaysAdjustColumnsAction;
void addBaseContextActions(QMenu *menu); QAction *m_adjustColumnsAction;
bool handleBaseContextAction(QAction *action); };
QTreeView *treeView() const { return m_treeView; } class BaseWindow : public QWidget
QModelIndex indexAt(const QPoint &p) const { return m_treeView->indexAt(p); } {
void resizeColumnToContents(int col) { m_treeView->resizeColumnToContents(col); } public:
void mousePressEvent(QMouseEvent *ev); explicit BaseWindow(QTreeView *treeView, QWidget *parent = 0);
virtual void rowActivated(const QModelIndex &) {} void setModel(QAbstractItemModel *model) { m_treeView->setModel(model); }
QModelIndexList selectedIndices(QContextMenuEvent *ev = 0); QHeaderView *header() const { return m_treeView->header(); }
QAbstractItemModel *model() const { return m_treeView->model(); }
private: private:
QTreeView *m_treeView; QTreeView *m_treeView;
QAction *m_alwaysAdjustColumnsAction;
QAction *m_adjustColumnsAction;
}; };
} // namespace Internal } // namespace Internal
......
...@@ -486,65 +486,68 @@ MultiBreakPointsDialog::MultiBreakPointsDialog(QWidget *parent) : ...@@ -486,65 +486,68 @@ MultiBreakPointsDialog::MultiBreakPointsDialog(QWidget *parent) :
// //
/////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////
BreakWindow::BreakWindow(QWidget *parent) BreakTreeView::BreakTreeView(QWidget *parent)
: BaseWindow(parent) : BaseTreeView(parent)
{ {
setWindowTitle(tr("Breakpoints"));
setObjectName(QLatin1String("ThreadsWindow"));
setWindowIcon(QIcon(QLatin1String(":/debugger/images/debugger_breakpoints.png"))); setWindowIcon(QIcon(QLatin1String(":/debugger/images/debugger_breakpoints.png")));
treeView()->setSelectionMode(QAbstractItemView::ExtendedSelection); setSelectionMode(QAbstractItemView::ExtendedSelection);
setAlwaysAdjustColumnsAction(debuggerCore()->action(AlwaysAdjustBreakpointsColumnWidths)); setAlwaysAdjustColumnsAction(debuggerCore()->action(AlwaysAdjustBreakpointsColumnWidths));
connect(debuggerCore()->action(UseAddressInBreakpointsView), connect(debuggerCore()->action(UseAddressInBreakpointsView),
SIGNAL(toggled(bool)), SLOT(showAddressColumn(bool))); 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) { if (ev->key() == Qt::Key_Delete) {
QItemSelectionModel *sm = treeView()->selectionModel(); QItemSelectionModel *sm = selectionModel();
QTC_ASSERT(sm, return); QTC_ASSERT(sm, return);
QModelIndexList si = sm->selectedIndexes(); QModelIndexList si = sm->selectedIndexes();
if (si.isEmpty()) if (si.isEmpty())
si.append(treeView()->currentIndex()); si.append(currentIndex());
const BreakpointModelIds ids = breakHandler()->findBreakpointsByIndex(si); 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); 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()); QModelIndex indexUnderMouse = indexAt(ev->pos());
if (indexUnderMouse.isValid() && indexUnderMouse.column() >= 4) { if (indexUnderMouse.isValid() && indexUnderMouse.column() >= 4) {
BreakpointModelId id = breakHandler()->findBreakpointByIndex(indexUnderMouse); BreakpointModelId id = breakHandler()->findBreakpointByIndex(indexUnderMouse);
editBreakpoints(BreakpointModelIds() << id); 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(0); // Number
resizeColumnToContents(3); // Line resizeColumnToContents(3); // Line
resizeColumnToContents(6); // Ignore count 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; 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(); BreakHandler *handler = breakHandler();
BreakpointModelIds selectedIds = handler->findBreakpointsByIndex(si); BreakpointModelIds selectedIds = handler->findBreakpointsByIndex(selectedIndices);
const int rowCount = model()->rowCount(); const int rowCount = model()->rowCount();
QAction *deleteAction = new QAction(tr("Delete Breakpoint"), &menu); QAction *deleteAction = new QAction(tr("Delete Breakpoint"), &menu);
...@@ -556,8 +559,8 @@ void BreakWindow::contextMenuEvent(QContextMenuEvent *ev) ...@@ -556,8 +559,8 @@ void BreakWindow::contextMenuEvent(QContextMenuEvent *ev)
// Delete by file: Find indices of breakpoints of the same file. // Delete by file: Find indices of breakpoints of the same file.
QAction *deleteByFileAction = 0; QAction *deleteByFileAction = 0;
BreakpointModelIds breakpointsInFile; BreakpointModelIds breakpointsInFile;
if (si.size() == 1) { if (indexUnderMouse.isValid()) {
const QModelIndex index = si.at(0).sibling(si.at(0).row(), 2); const QModelIndex index = indexUnderMouse.sibling(indexUnderMouse.row(), 2);
const QString file = index.data().toString(); const QString file = index.data().toString();
if (!file.isEmpty()) { if (!file.isEmpty()) {
for (int i = 0; i != rowCount; ++i) for (int i = 0; i != rowCount; ++i)
...@@ -649,21 +652,21 @@ void BreakWindow::contextMenuEvent(QContextMenuEvent *ev) ...@@ -649,21 +652,21 @@ void BreakWindow::contextMenuEvent(QContextMenuEvent *ev)
handleBaseContextAction(act); handleBaseContextAction(act);
} }
void BreakWindow::setBreakpointsEnabled(const BreakpointModelIds &ids, bool enabled) void BreakTreeView::setBreakpointsEnabled(const BreakpointModelIds &ids, bool enabled)
{ {
BreakHandler *handler = breakHandler(); BreakHandler *handler = breakHandler();
foreach (const BreakpointModelId id, ids) foreach (const BreakpointModelId id, ids)
handler->setEnabled(id, enabled); handler->setEnabled(id, enabled);
} }
void BreakWindow::deleteBreakpoints(const BreakpointModelIds &ids) void BreakTreeView::deleteBreakpoints(const BreakpointModelIds &ids)
{ {
BreakHandler *handler = breakHandler(); BreakHandler *handler = breakHandler();
foreach (const BreakpointModelId id, ids) foreach (const BreakpointModelId id, ids)
handler->removeBreakpoint(id); handler->removeBreakpoint(id);
} }
void BreakWindow::editBreakpoint(BreakpointModelId id, QWidget *parent) void BreakTreeView::editBreakpoint(BreakpointModelId id, QWidget *parent)
{ {
BreakpointParameters data = breakHandler()->breakpointData(id); BreakpointParameters data = breakHandler()->breakpointData(id);
BreakpointParts parts = NoParts; BreakpointParts parts = NoParts;
...@@ -672,7 +675,7 @@ void BreakWindow::editBreakpoint(BreakpointModelId id, QWidget *parent) ...@@ -672,7 +675,7 @@ void BreakWindow::editBreakpoint(BreakpointModelId id, QWidget *parent)
breakHandler()->changeBreakpointData(id, data, parts); breakHandler()->changeBreakpointData(id, data, parts);
} }
void BreakWindow::addBreakpoint() void BreakTreeView::addBreakpoint()
{ {
BreakpointParameters data(BreakpointByFileAndLine); BreakpointParameters data(BreakpointByFileAndLine);
BreakpointParts parts = NoParts; BreakpointParts parts = NoParts;
...@@ -682,7 +685,7 @@ void BreakWindow::addBreakpoint() ...@@ -682,7 +685,7 @@ void BreakWindow::addBreakpoint()
breakHandler()->appendBreakpoint(data); breakHandler()->appendBreakpoint(data);
} }
void BreakWindow::editBreakpoints(const BreakpointModelIds &ids) void BreakTreeView::editBreakpoints(const BreakpointModelIds &ids)
{ {
QTC_ASSERT(!ids.isEmpty(), return); QTC_ASSERT(!ids.isEmpty(), return);
...@@ -721,18 +724,24 @@ void BreakWindow::editBreakpoints(const BreakpointModelIds &ids) ...@@ -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(); BreakHandler *handler = breakHandler();
foreach (const BreakpointModelId id, ids) foreach (const BreakpointModelId id, ids)
handler->setThreadSpec(id, threadId); handler->setThreadSpec(id, threadId);
} }
void BreakWindow::rowActivated(const QModelIndex &index) void BreakTreeView::rowActivated(const QModelIndex &index)
{ {
breakHandler()->gotoLocation(breakHandler()->findBreakpointByIndex(index)); breakHandler()->gotoLocation(breakHandler()->findBreakpointByIndex(index));
} }
BreakWindow::BreakWindow()
: BaseWindow(new BreakTreeView)
{
setWindowTitle(tr("Breakpoints"));
}
} // namespace Internal } // namespace Internal
} // namespace Debugger } // namespace Debugger
......
...@@ -39,12 +39,12 @@ ...@@ -39,12 +39,12 @@
namespace Debugger { namespace Debugger {
namespace Internal { namespace Internal {
class BreakWindow : public BaseWindow class BreakTreeView : public BaseTreeView
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit BreakWindow(QWidget *parent = 0); explicit BreakTreeView(QWidget *parent = 0);
static void editBreakpoint(BreakpointModelId id, QWidget *parent); static void editBreakpoint(BreakpointModelId id, QWidget *parent);
void setModel(QAbstractItemModel *model); void setModel(QAbstractItemModel *model);
...@@ -65,6 +65,12 @@ private: ...@@ -65,6 +65,12 @@ private:
void setBreakpointsEnabled(const BreakpointModelIds &ids, bool enabled); void setBreakpointsEnabled(const BreakpointModelIds &ids, bool enabled);
}; };
class BreakWindow : public BaseWindow
{
public:
BreakWindow();
};
} // namespace Internal } // namespace Internal
} // namespace Debugger } // namespace Debugger