Commit 2f17b747 authored by hjk's avatar hjk
Browse files

Debugger: Take advantage of new tree iterator in option page



Change-Id: I1a8e065cfaa57b49c852a3a1d67149447d4d87b2
Reviewed-by: default avatarChristian Stenger <christian.stenger@theqtcompany.com>
parent ac18f9f1
......@@ -936,63 +936,6 @@ UntypedTreeLevelItems::const_iterator::const_iterator(TreeItem *base, int level)
}
}
// Result is either an item of the target level, or 'end'.
void UntypedTreeLevelItems::const_iterator::goDown()
{
QTC_ASSERT(m_depth != -1, return);
QTC_ASSERT(m_depth < m_level, return);
do {
TreeItem *curr = m_item[m_depth];
int size = curr->rowCount();
if (size == 0) {
// This is a dead end not reaching to the desired level.
goUpNextDown();
return;
}
++m_depth;
m_size[m_depth] = size;
m_pos[m_depth] = 0;
m_item[m_depth] = curr->child(0);
} while (m_depth < m_level);
// Did not reach the required level? Set to end().
if (m_depth != m_level)
m_depth = -1;
}
void UntypedTreeLevelItems::const_iterator::goUpNextDown()
{
// Go up until we can move sidewards.
do {
--m_depth;
if (m_depth < 0)
return; // Solid end.
} while (++m_pos[m_depth] >= m_size[m_depth]);
m_item[m_depth] = m_item[m_depth - 1]->child(m_pos[m_depth]);
goDown();
}
bool UntypedTreeLevelItems::const_iterator::operator==(UntypedTreeLevelItems::const_iterator other) const
{
if (m_depth != other.m_depth)
return false;
for (int i = 0; i <= m_depth; ++i)
if (m_item[i] != other.m_item[i])
return false;
return true;
}
void UntypedTreeLevelItems::const_iterator::operator++()
{
QTC_ASSERT(m_depth == m_level, return);
int pos = ++m_pos[m_depth];
if (pos < m_size[m_depth])
m_item[m_depth] = m_item[m_depth - 1]->child(pos);
else
goUpNextDown();
}
UntypedTreeLevelItems::const_iterator UntypedTreeLevelItems::begin() const
{
return const_iterator(m_item, m_level);
......
......@@ -32,7 +32,9 @@
#define UTILS_TREEMODEL_H
#include "utils_global.h"
#include "algorithm.h"
#include "qtcassert.h"
#include <QAbstractItemModel>
......@@ -88,6 +90,7 @@ private:
class QTCREATOR_UTILS_EXPORT UntypedTreeLevelItems
{
public:
enum { MaxSearchDepth = 12 }; // FIXME.
explicit UntypedTreeLevelItems(TreeItem *item, int level = 1);
typedef TreeItem *value_type;
......@@ -104,20 +107,73 @@ public:
const_iterator(TreeItem *base, int level);
TreeItem *operator*() { return m_item[m_depth]; }
void operator++();
bool operator==(const_iterator other) const;
bool operator!=(const_iterator other) const { return !operator==(other); }
void operator++()
{
QTC_ASSERT(m_depth == m_level, return);
int pos = ++m_pos[m_depth];
if (pos < m_size[m_depth])
m_item[m_depth] = m_item[m_depth - 1]->child(pos);
else
goUpNextDown();
}
bool operator==(const const_iterator &other) const
{
if (m_depth != other.m_depth)
return false;
for (int i = 0; i <= m_depth; ++i)
if (m_item[i] != other.m_item[i])
return false;
return true;
}
bool operator!=(const const_iterator &other) const
{
return !operator==(other);
}
private:
void goDown();
void goUpNextDown();
// Result is either an item of the target level, or 'end'.
void goDown()
{
QTC_ASSERT(m_depth != -1, return);
QTC_ASSERT(m_depth < m_level, return);
do {
TreeItem *curr = m_item[m_depth];
int size = curr->rowCount();
if (size == 0) {
// This is a dead end not reaching to the desired level.
goUpNextDown();
return;
}
++m_depth;
m_size[m_depth] = size;
m_pos[m_depth] = 0;
m_item[m_depth] = curr->child(0);
} while (m_depth < m_level);
// Did not reach the required level? Set to end().
if (m_depth != m_level)
m_depth = -1;
}
void goUpNextDown()
{
// Go up until we can move sidewards.
do {
--m_depth;
if (m_depth < 0)
return; // Solid end.
} while (++m_pos[m_depth] >= m_size[m_depth]);
m_item[m_depth] = m_item[m_depth - 1]->child(m_pos[m_depth]);
goDown();
}
int m_level;
int m_depth;
TreeItem *m_item[8];
int m_pos[8];
int m_size[8];
TreeItem *m_item[MaxSearchDepth];
int m_pos[MaxSearchDepth];
int m_size[MaxSearchDepth];
};
const_iterator begin() const;
......@@ -129,7 +185,7 @@ private:
};
template <class T>
class QTCREATOR_UTILS_EXPORT TreeLevelItems
class TreeLevelItems
{
public:
typedef T value_type;
......
......@@ -110,8 +110,6 @@ public:
void apply();
private:
DebuggerTreeItem *findTreeItemById(const QVariant &id) const;
DebuggerTreeItem *m_currentTreeItem;
QStringList removed;
......@@ -138,8 +136,10 @@ void DebuggerItemModel::addDebugger(const DebuggerItem &item, bool changed)
void DebuggerItemModel::updateDebugger(const DebuggerItem &item)
{
DebuggerTreeItem *treeItem = findTreeItemById(item.id());
auto matcher = [item](DebuggerTreeItem *n) { return n->m_item.m_id == item.id(); };
DebuggerTreeItem *treeItem = findItemAtLevel<DebuggerTreeItem *>(2, matcher);
QTC_ASSERT(treeItem, return);
TreeItem *parent = treeItem->parent();
QTC_ASSERT(parent, return);
......@@ -150,20 +150,6 @@ void DebuggerItemModel::updateDebugger(const DebuggerItem &item)
updateItem(treeItem); // Notify views.
}
DebuggerTreeItem *DebuggerItemModel::findTreeItemById(const QVariant &id) const
{
TreeItem *root = rootItem();
for (int k = 0; k < rootItem()->rowCount(); ++k) {
TreeItem *group = root->child(k);
for (int i = 0, n = group->rowCount(); i != n; ++i) {
DebuggerTreeItem *treeItem = static_cast<DebuggerTreeItem *>(group->child(i));
if (treeItem->m_item.m_id == id)
return treeItem;
}
}
return 0;
}
QModelIndex DebuggerItemModel::lastIndex() const
{
TreeItem *manualGroup = rootItem()->lastChild();
......@@ -192,14 +178,9 @@ void DebuggerItemModel::apply()
foreach (const QVariant &id, m_removedItems)
DebuggerItemManager::deregisterDebugger(id);
TreeItem *root = rootItem();
for (int k = 0; k < rootItem()->rowCount(); ++k) {
TreeItem *group = root->child(k);
for (int i = 0, n = group->rowCount(); i != n; ++i) {
DebuggerTreeItem *treeItem = static_cast<DebuggerTreeItem *>(group->child(i));
treeItem->m_changed = false;
DebuggerItemManager::updateOrAddDebugger(treeItem->m_item);
}
foreach (auto item, treeLevelItems<DebuggerTreeItem *>(2)) {
item->m_changed = false;
DebuggerItemManager::updateOrAddDebugger(item->m_item);
}
}
......
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