Commit a6e9f032 authored by hjk's avatar hjk

Debugger: Use Utils::TreeModel for watch window

The circle closes, that's where the code came from.

Change-Id: Ic36ab61ec8886c9a2747aeb29a7245df3ef0b6c4
Reviewed-by: default avatarChristian Stenger <christian.stenger@theqtcompany.com>
parent 37bbc8a4
......@@ -56,7 +56,7 @@ def qdump__Debugger__Internal__WatchData(d, value):
d.putPlainChildren(value)
def qdump__Debugger__Internal__WatchItem(d, value):
d.putByteArrayValue(value["iname"])
d.putByteArrayValue(value["d"]["iname"])
d.putPlainChildren(value)
def qdump__Debugger__Internal__BreakpointModelId(d, value):
......
......@@ -671,6 +671,11 @@ Qt::ItemFlags TreeItem::flags(int column) const
return m_flags;
}
bool TreeItem::hasChildren() const
{
return canFetchMore() || rowCount() > 0;
}
bool TreeItem::canFetchMore() const
{
return false;
......@@ -769,6 +774,22 @@ void TreeItem::setModel(TreeModel *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()
{
while (m_children.size()) {
......@@ -898,6 +919,12 @@ QVariant TreeModel::headerData(int section, Qt::Orientation orientation,
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
{
if (!idx.isValid())
......@@ -929,6 +956,13 @@ TreeItem *TreeModel::rootItem() const
return m_root;
}
void TreeModel::setRootItem(TreeItem *item)
{
delete m_root;
m_root = item;
item->setModel(this);
}
void TreeModel::setHeader(const QStringList &displays)
{
m_header = displays;
......
......@@ -43,8 +43,19 @@
namespace Utils {
class TreeItem;
class TreeModel;
class QTCREATOR_UTILS_EXPORT TreeItemVisitor
{
public:
TreeItemVisitor() {}
virtual ~TreeItemVisitor() {}
bool preVisit(TreeItem *) { return true; }
void visit(TreeItem *) {}
};
class QTCREATOR_UTILS_EXPORT TreeItem
{
public:
......@@ -62,6 +73,7 @@ public:
virtual bool setData(int column, const QVariant &data, int role);
virtual Qt::ItemFlags flags(int column) const;
virtual bool hasChildren() const;
virtual bool canFetchMore() const;
virtual void fetchMore() {}
......@@ -84,6 +96,9 @@ public:
TreeModel *model() const { return m_model; }
void setModel(TreeModel *model);
void walkTree(TreeItemVisitor *visitor);
void walkTree(std::function<void(TreeItem *)> f);
private:
TreeItem(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;
Qt::ItemFlags flags(const QModelIndex &idx) const;
QVariant headerData(int section, Qt::Orientation orientation, int role) const;
bool hasChildren(const QModelIndex &idx) const;
bool canFetchMore(const QModelIndex &idx) const;
void fetchMore(const QModelIndex &idx);
TreeItem *rootItem() const;
void setRootItem(TreeItem *item);
TreeItem *itemFromIndex(const QModelIndex &) const;
QModelIndex indexFromItem(const TreeItem *needle) const;
void removeItems();
......
......@@ -156,6 +156,15 @@ bool WatchData::isEqual(const WatchData &other) const
&& 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
{
// First case: Cdb only. No user type can be named like this, this is safe.
......
......@@ -98,6 +98,7 @@ public:
bool isVTablePointer() const;
bool isEqual(const WatchData &other) const;
bool isAncestorOf(const QByteArray &childIName) const;
void setError(const QString &);
void setValue(const QString &);
......
This diff is collapsed.
......@@ -33,7 +33,8 @@
#include "watchdata.h"
#include <QAbstractItemModel>
#include <utils/treemodel.h>
#include <QPointer>
#include <QVector>
......@@ -125,7 +126,7 @@ public:
typedef QHash<QString, QStringList> DumperTypeFormats; // Type name -> Dumper Formats
class WatchModelBase : public QAbstractItemModel
class WatchModelBase : public Utils::TreeModel
{
Q_OBJECT
......@@ -189,7 +190,6 @@ public:
void scheduleResetLocation();
void resetLocation();
bool isValidToolTip(const QByteArray &iname) const;
void setCurrentItem(const QByteArray &iname);
void updateWatchersWindow();
......
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