forked from qt-creator/qt-creator
Debugger: Use Utils::TreeModel for watch window
The circle closes, that's where the code came from. Change-Id: Ic36ab61ec8886c9a2747aeb29a7245df3ef0b6c4 Reviewed-by: Christian Stenger <christian.stenger@theqtcompany.com>
This commit is contained in:
@@ -56,7 +56,7 @@ def qdump__Debugger__Internal__WatchData(d, value):
|
|||||||
d.putPlainChildren(value)
|
d.putPlainChildren(value)
|
||||||
|
|
||||||
def qdump__Debugger__Internal__WatchItem(d, value):
|
def qdump__Debugger__Internal__WatchItem(d, value):
|
||||||
d.putByteArrayValue(value["iname"])
|
d.putByteArrayValue(value["d"]["iname"])
|
||||||
d.putPlainChildren(value)
|
d.putPlainChildren(value)
|
||||||
|
|
||||||
def qdump__Debugger__Internal__BreakpointModelId(d, value):
|
def qdump__Debugger__Internal__BreakpointModelId(d, value):
|
||||||
|
@@ -671,6 +671,11 @@ Qt::ItemFlags TreeItem::flags(int column) const
|
|||||||
return m_flags;
|
return m_flags;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool TreeItem::hasChildren() const
|
||||||
|
{
|
||||||
|
return canFetchMore() || rowCount() > 0;
|
||||||
|
}
|
||||||
|
|
||||||
bool TreeItem::canFetchMore() const
|
bool TreeItem::canFetchMore() const
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
@@ -769,6 +774,22 @@ void TreeItem::setModel(TreeModel *model)
|
|||||||
item->setModel(model);
|
item->setModel(model);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TreeItem::walkTree(TreeItemVisitor *visitor)
|
||||||
|
{
|
||||||
|
if (visitor->preVisit(this)) {
|
||||||
|
visitor->visit(this);
|
||||||
|
foreach (TreeItem *item, m_children)
|
||||||
|
item->walkTree(visitor);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void TreeItem::walkTree(std::function<void (TreeItem *)> f)
|
||||||
|
{
|
||||||
|
f(this);
|
||||||
|
foreach (TreeItem *item, m_children)
|
||||||
|
item->walkTree(f);
|
||||||
|
}
|
||||||
|
|
||||||
void TreeItem::clear()
|
void TreeItem::clear()
|
||||||
{
|
{
|
||||||
while (m_children.size()) {
|
while (m_children.size()) {
|
||||||
@@ -898,6 +919,12 @@ QVariant TreeModel::headerData(int section, Qt::Orientation orientation,
|
|||||||
return QVariant();
|
return QVariant();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool TreeModel::hasChildren(const QModelIndex &idx) const
|
||||||
|
{
|
||||||
|
TreeItem *item = itemFromIndex(idx);
|
||||||
|
return !item || item->hasChildren();
|
||||||
|
}
|
||||||
|
|
||||||
Qt::ItemFlags TreeModel::flags(const QModelIndex &idx) const
|
Qt::ItemFlags TreeModel::flags(const QModelIndex &idx) const
|
||||||
{
|
{
|
||||||
if (!idx.isValid())
|
if (!idx.isValid())
|
||||||
@@ -929,6 +956,13 @@ TreeItem *TreeModel::rootItem() const
|
|||||||
return m_root;
|
return m_root;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TreeModel::setRootItem(TreeItem *item)
|
||||||
|
{
|
||||||
|
delete m_root;
|
||||||
|
m_root = item;
|
||||||
|
item->setModel(this);
|
||||||
|
}
|
||||||
|
|
||||||
void TreeModel::setHeader(const QStringList &displays)
|
void TreeModel::setHeader(const QStringList &displays)
|
||||||
{
|
{
|
||||||
m_header = displays;
|
m_header = displays;
|
||||||
|
@@ -43,8 +43,19 @@
|
|||||||
|
|
||||||
namespace Utils {
|
namespace Utils {
|
||||||
|
|
||||||
|
class TreeItem;
|
||||||
class TreeModel;
|
class TreeModel;
|
||||||
|
|
||||||
|
class QTCREATOR_UTILS_EXPORT TreeItemVisitor
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
TreeItemVisitor() {}
|
||||||
|
virtual ~TreeItemVisitor() {}
|
||||||
|
|
||||||
|
bool preVisit(TreeItem *) { return true; }
|
||||||
|
void visit(TreeItem *) {}
|
||||||
|
};
|
||||||
|
|
||||||
class QTCREATOR_UTILS_EXPORT TreeItem
|
class QTCREATOR_UTILS_EXPORT TreeItem
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -62,6 +73,7 @@ public:
|
|||||||
virtual bool setData(int column, const QVariant &data, int role);
|
virtual bool setData(int column, const QVariant &data, int role);
|
||||||
virtual Qt::ItemFlags flags(int column) const;
|
virtual Qt::ItemFlags flags(int column) const;
|
||||||
|
|
||||||
|
virtual bool hasChildren() const;
|
||||||
virtual bool canFetchMore() const;
|
virtual bool canFetchMore() const;
|
||||||
virtual void fetchMore() {}
|
virtual void fetchMore() {}
|
||||||
|
|
||||||
@@ -84,6 +96,9 @@ public:
|
|||||||
TreeModel *model() const { return m_model; }
|
TreeModel *model() const { return m_model; }
|
||||||
void setModel(TreeModel *model);
|
void setModel(TreeModel *model);
|
||||||
|
|
||||||
|
void walkTree(TreeItemVisitor *visitor);
|
||||||
|
void walkTree(std::function<void(TreeItem *)> f);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
TreeItem(const TreeItem &) Q_DECL_EQ_DELETE;
|
TreeItem(const TreeItem &) Q_DECL_EQ_DELETE;
|
||||||
void operator=(const TreeItem &) Q_DECL_EQ_DELETE;
|
void operator=(const TreeItem &) Q_DECL_EQ_DELETE;
|
||||||
@@ -245,11 +260,13 @@ public:
|
|||||||
QModelIndex parent(const QModelIndex &idx) const;
|
QModelIndex parent(const QModelIndex &idx) const;
|
||||||
Qt::ItemFlags flags(const QModelIndex &idx) const;
|
Qt::ItemFlags flags(const QModelIndex &idx) const;
|
||||||
QVariant headerData(int section, Qt::Orientation orientation, int role) const;
|
QVariant headerData(int section, Qt::Orientation orientation, int role) const;
|
||||||
|
bool hasChildren(const QModelIndex &idx) const;
|
||||||
|
|
||||||
bool canFetchMore(const QModelIndex &idx) const;
|
bool canFetchMore(const QModelIndex &idx) const;
|
||||||
void fetchMore(const QModelIndex &idx);
|
void fetchMore(const QModelIndex &idx);
|
||||||
|
|
||||||
TreeItem *rootItem() const;
|
TreeItem *rootItem() const;
|
||||||
|
void setRootItem(TreeItem *item);
|
||||||
TreeItem *itemFromIndex(const QModelIndex &) const;
|
TreeItem *itemFromIndex(const QModelIndex &) const;
|
||||||
QModelIndex indexFromItem(const TreeItem *needle) const;
|
QModelIndex indexFromItem(const TreeItem *needle) const;
|
||||||
void removeItems();
|
void removeItems();
|
||||||
|
@@ -156,6 +156,15 @@ bool WatchData::isEqual(const WatchData &other) const
|
|||||||
&& error == other.error;
|
&& error == other.error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool WatchData::isAncestorOf(const QByteArray &childIName) const
|
||||||
|
{
|
||||||
|
if (iname.size() >= childIName.size())
|
||||||
|
return false;
|
||||||
|
if (!childIName.startsWith(iname))
|
||||||
|
return false;
|
||||||
|
return childIName.at(iname.size()) == '.';
|
||||||
|
}
|
||||||
|
|
||||||
bool WatchData::isVTablePointer() const
|
bool WatchData::isVTablePointer() const
|
||||||
{
|
{
|
||||||
// First case: Cdb only. No user type can be named like this, this is safe.
|
// First case: Cdb only. No user type can be named like this, this is safe.
|
||||||
|
@@ -98,6 +98,7 @@ public:
|
|||||||
bool isVTablePointer() const;
|
bool isVTablePointer() const;
|
||||||
|
|
||||||
bool isEqual(const WatchData &other) const;
|
bool isEqual(const WatchData &other) const;
|
||||||
|
bool isAncestorOf(const QByteArray &childIName) const;
|
||||||
|
|
||||||
void setError(const QString &);
|
void setError(const QString &);
|
||||||
void setValue(const QString &);
|
void setValue(const QString &);
|
||||||
|
File diff suppressed because it is too large
Load Diff
@@ -33,7 +33,8 @@
|
|||||||
|
|
||||||
#include "watchdata.h"
|
#include "watchdata.h"
|
||||||
|
|
||||||
#include <QAbstractItemModel>
|
#include <utils/treemodel.h>
|
||||||
|
|
||||||
#include <QPointer>
|
#include <QPointer>
|
||||||
#include <QVector>
|
#include <QVector>
|
||||||
|
|
||||||
@@ -125,7 +126,7 @@ public:
|
|||||||
|
|
||||||
typedef QHash<QString, QStringList> DumperTypeFormats; // Type name -> Dumper Formats
|
typedef QHash<QString, QStringList> DumperTypeFormats; // Type name -> Dumper Formats
|
||||||
|
|
||||||
class WatchModelBase : public QAbstractItemModel
|
class WatchModelBase : public Utils::TreeModel
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
@@ -189,7 +190,6 @@ public:
|
|||||||
|
|
||||||
void scheduleResetLocation();
|
void scheduleResetLocation();
|
||||||
void resetLocation();
|
void resetLocation();
|
||||||
bool isValidToolTip(const QByteArray &iname) const;
|
|
||||||
|
|
||||||
void setCurrentItem(const QByteArray &iname);
|
void setCurrentItem(const QByteArray &iname);
|
||||||
void updateWatchersWindow();
|
void updateWatchersWindow();
|
||||||
|
Reference in New Issue
Block a user