Commit ac77a8d1 authored by hjk's avatar hjk
Browse files

Debugger: Use Utils::TreeModel for breakpoints



Change-Id: I7f62f9d64daf7624794aa82495d4b2c8d97b33df
Reviewed-by: default avatarChristian Stenger <christian.stenger@theqtcompany.com>
parent 2f17b747
This diff is collapsed.
......@@ -33,7 +33,7 @@
#include "breakpoint.h"
#include <QAbstractTableModel>
#include <utils/treemodel.h>
//////////////////////////////////////////////////////////////////
//
......@@ -47,13 +47,12 @@ namespace Internal {
class BreakpointMarker;
class DebuggerEngine;
class BreakHandler : public QAbstractItemModel
class BreakHandler : public Utils::TreeModel
{
Q_OBJECT
public:
BreakHandler();
~BreakHandler();
void loadSessionData();
void saveSessionData();
......@@ -69,7 +68,6 @@ public:
BreakpointModelIds allBreakpointIds() const;
BreakpointModelIds engineBreakpointIds(DebuggerEngine *engine) const;
BreakpointModelIds unclaimedBreakpointIds() const;
int size() const { return m_storage.size(); }
QStringList engineBreakpointPaths(DebuggerEngine *engine) const;
// Find a breakpoint matching approximately the data in needle.
......@@ -166,20 +164,10 @@ public:
void setWatchpointAtAddress(quint64 address, unsigned size);
void setWatchpointAtExpression(const QString &exp);
signals:
void requestExpansion(QModelIndex);
private:
// QAbstractItemModel implementation.
int columnCount(const QModelIndex &parent) const;
int rowCount(const QModelIndex &parent) const;
QVariant data(const QModelIndex &index, int role) const;
QVariant headerData(int section, Qt::Orientation orientation, int role) const;
Qt::ItemFlags flags(const QModelIndex &index) const;
QModelIndex index(int row, int col, const QModelIndex &parent) const;
QModelIndex parent(const QModelIndex &parent) const;
QModelIndex createIndex(int row, int column, quint32 id) const;
QModelIndex createIndex(int row, int column, void *ptr) const;
int indexOf(BreakpointModelId id) const;
BreakpointModelId at(int index) const;
bool isEngineRunning(BreakpointModelId id) const;
void setState(BreakpointModelId id, BreakpointState state);
void loadBreakpoints();
......@@ -188,32 +176,42 @@ private:
void appendBreakpointInternal(const BreakpointParameters &data);
Q_SLOT void changeLineNumberFromMarkerHelper(Debugger::Internal::BreakpointModelId id, int lineNumber);
struct BreakpointItem
struct BreakpointItem : public Utils::TreeItem
{
BreakpointItem();
~BreakpointItem();
int columnCount() const { return 8; }
QVariant data(int column, int role) const;
void destroyMarker();
bool needsChange() const;
bool isLocatedAt(const QString &fileName, int lineNumber,
bool useMarkerPosition) const;
void updateMarker(BreakpointModelId id);
void updateMarker();
void updateMarkerIcon();
QString toToolTip() const;
QString markerFileName() const;
int markerLineNumber() const;
QIcon icon() const;
BreakpointParameters data;
BreakpointModelId id;
BreakpointParameters params;
BreakpointState state; // Current state of breakpoint.
DebuggerEngine *engine; // Engine currently handling the breakpoint.
BreakpointResponse response;
BreakpointMarker *marker;
QList<BreakpointResponse> subItems;
};
typedef QHash<BreakpointModelId, BreakpointItem> BreakpointStorage;
typedef BreakpointStorage::ConstIterator ConstIterator;
typedef BreakpointStorage::Iterator Iterator;
BreakpointStorage m_storage;
struct LocationItem : public Utils::TreeItem
{
int columnCount() const { return 8; }
QVariant data(int column, int role) const;
BreakpointResponse params;
};
BreakpointItem *breakpointById(BreakpointModelId id) const;
void scheduleSynchronization();
void timerEvent(QTimerEvent *event);
......
/****************************************************************************
**
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia. For licensing terms and
** conditions see http://www.qt.io/licensing. For further information
** use the contact form at http://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Digia gives you certain additional
** rights. These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
#include "breakpointmarker.h"
#include "breakhandler.h"
#include "debuggercore.h"
//////////////////////////////////////////////////////////////////
//
// BreakpointMarker
//
//////////////////////////////////////////////////////////////////
namespace Debugger {
namespace Internal {
BreakpointMarker::BreakpointMarker(BreakpointModelId id,
const QString &fileName, int lineNumber)
: TextMark(fileName, lineNumber), m_id(id)
{
setIcon(breakHandler()->icon(m_id));
setPriority(TextEditor::TextMark::NormalPriority);
//qDebug() << "CREATE MARKER " << fileName << lineNumber;
}
BreakpointMarker::~BreakpointMarker()
{
//qDebug() << "REMOVE MARKER ";
}
void BreakpointMarker::removedFromEditor()
{
breakHandler()->removeBreakpoint(m_id);
}
void BreakpointMarker::updateLineNumber(int lineNumber)
{
TextMark::updateLineNumber(lineNumber);
breakHandler()->updateLineNumberFromMarker(m_id, lineNumber);
}
void BreakpointMarker::dragToLine(int lineNumber)
{
breakHandler()->changeLineNumberFromMarker(m_id, lineNumber);
}
void BreakpointMarker::clicked()
{
breakHandler()->removeBreakpoint(m_id);
}
void BreakpointMarker::updateFileName(const QString &fileName)
{
TextMark::updateFileName(fileName);
breakHandler()->updateFileNameFromMarker(m_id, fileName);
}
} // namespace Internal
} // namespace Debugger
/****************************************************************************
**
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia. For licensing terms and
** conditions see http://www.qt.io/licensing. For further information
** use the contact form at http://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Digia gives you certain additional
** rights. These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
#ifndef DEBUGGER_BREAKPOINTMARKER_H
#define DEBUGGER_BREAKPOINTMARKER_H
#include "breakpoint.h"
#include <texteditor/textmark.h>
namespace Debugger {
namespace Internal {
// The red blob on the left side in the cpp editor.
class BreakpointMarker : public TextEditor::TextMark
{
public:
BreakpointMarker(BreakpointModelId id, const QString &fileName, int lineNumber);
~BreakpointMarker();
void removedFromEditor();
void updateLineNumber(int lineNumber);
void updateFileName(const QString &fileName);
bool isDraggable() const { return true; }
void dragToLine(int lineNumber);
bool isClickable() const { return true; }
void clicked();
private:
BreakpointModelId m_id;
friend class BreakHandler;
};
} // namespace Internal
} // namespace Debugger
#endif
......@@ -692,17 +692,17 @@ void BreakTreeView::keyPressEvent(QKeyEvent *ev)
if (ev->key() == Qt::Key_Delete) {
QItemSelectionModel *sm = selectionModel();
QTC_ASSERT(sm, return);
QModelIndexList si = sm->selectedIndexes();
QModelIndexList si = sm->selectedRows();
if (si.isEmpty())
si.append(currentIndex());
const BreakpointModelIds ids = breakHandler()->findBreakpointsByIndex(si);
int row = qMin(model()->rowCount() - ids.size() - 1, currentIndex().row());
deleteBreakpoints(ids);
setCurrentIndex(si.at(0).sibling(row, 0));
setCurrentIndex(model()->index(row, 0));
} else if (ev->key() == Qt::Key_Space) {
QItemSelectionModel *sm = selectionModel();
QTC_ASSERT(sm, return);
const QModelIndexList selectedIds = sm->selectedIndexes();
const QModelIndexList selectedIds = sm->selectedRows();
if (!selectedIds.isEmpty()) {
BreakHandler *handler = breakHandler();
const BreakpointModelIds validIds = handler->findBreakpointsByIndex(selectedIds);
......@@ -734,7 +734,7 @@ void BreakTreeView::contextMenuEvent(QContextMenuEvent *ev)
QMenu menu;
QItemSelectionModel *sm = selectionModel();
QTC_ASSERT(sm, return);
QModelIndexList selectedIndices = sm->selectedIndexes();
QModelIndexList selectedIndices = sm->selectedRows();
QModelIndex indexUnderMouse = indexAt(ev->pos());
if (selectedIndices.isEmpty() && indexUnderMouse.isValid())
selectedIndices.append(indexUnderMouse);
......
......@@ -15,7 +15,6 @@ CONFIG += exceptions
HEADERS += \
breakhandler.h \
breakpoint.h \
breakpointmarker.h \
breakwindow.h \
commonoptionspage.h \
debugger_global.h \
......@@ -75,7 +74,6 @@ HEADERS += \
SOURCES += \
breakhandler.cpp \
breakpoint.cpp \
breakpointmarker.cpp \
breakwindow.cpp \
commonoptionspage.cpp \
debuggeractions.cpp \
......
......@@ -28,7 +28,6 @@ QtcPlugin {
files: [
"breakhandler.cpp", "breakhandler.h",
"breakpoint.cpp", "breakpoint.h",
"breakpointmarker.cpp", "breakpointmarker.h",
"breakwindow.cpp", "breakwindow.h",
"commonoptionspage.cpp", "commonoptionspage.h",
"debugger.qrc",
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment