Commit 66fd8058 authored by hjk's avatar hjk

TreeModel: Clean up TreeItem API

isLazy/populate was the first incarnation of the canFetchMore/
fetchMore mechanism which now can take over completely. So:

- remove isLazy/populate
- the use in VariableChooser

Change-Id: I885d492c134fb6899759e19a73156b52df7a880a
Reviewed-by: default avatarEike Ziller <eike.ziller@theqtcompany.com>
parent 2b19081c
......@@ -611,14 +611,12 @@ namespace Utils {
// TreeItem
//
TreeItem::TreeItem()
: m_parent(0), m_model(0), m_displays(0), m_lazy(false), m_populated(false),
m_flags(Qt::ItemIsEnabled|Qt::ItemIsSelectable)
: m_parent(0), m_model(0), m_displays(0), m_flags(Qt::ItemIsEnabled|Qt::ItemIsSelectable)
{
}
TreeItem::TreeItem(const QStringList &displays, int flags)
: m_parent(0), m_model(0), m_displays(new QStringList(displays)), m_lazy(false), m_populated(false),
m_flags(flags)
: m_parent(0), m_model(0), m_displays(new QStringList(displays)), m_flags(flags)
{
}
......@@ -630,26 +628,15 @@ TreeItem::~TreeItem()
TreeItem *TreeItem::child(int pos) const
{
ensurePopulated();
QTC_ASSERT(pos >= 0, return 0);
return pos < m_children.size() ? m_children.at(pos) : 0;
}
bool TreeItem::isLazy() const
{
return m_lazy;
}
int TreeItem::rowCount() const
{
ensurePopulated();
return m_children.size();
}
void TreeItem::populate()
{
}
QVariant TreeItem::data(int column, int role) const
{
if (role == Qt::DisplayRole && m_displays && column >= 0 && column < m_displays->size())
......@@ -696,7 +683,7 @@ void TreeItem::insertChild(int pos, TreeItem *item)
QTC_CHECK(!item->parent());
QTC_ASSERT(0 <= pos && pos <= m_children.size(), return); // '<= size' is intentional.
if (m_model && !m_lazy) {
if (m_model) {
QModelIndex idx = index();
m_model->beginInsertRows(idx, pos, pos);
item->m_parent = this;
......@@ -770,11 +757,6 @@ int TreeItem::level() const
return l;
}
void TreeItem::setLazy(bool on)
{
m_lazy = on;
}
void TreeItem::setFlags(Qt::ItemFlags flags)
{
m_flags = flags;
......@@ -830,15 +812,6 @@ void TreeItem::expand()
m_model->requestExpansion(index());
}
void TreeItem::ensurePopulated() const
{
if (!m_populated) {
if (isLazy())
const_cast<TreeItem *>(this)->populate();
m_populated = true;
}
}
void TreeItem::propagateModel(TreeModel *m)
{
QTC_ASSERT(m, return);
......
......@@ -72,9 +72,7 @@ public:
virtual TreeItem *parent() const { return m_parent; }
virtual TreeItem *child(int pos) const;
virtual bool isLazy() const;
virtual int rowCount() const;
virtual void populate();
virtual QVariant data(int column, int role) const;
virtual bool setData(int column, const QVariant &data, int role);
......@@ -96,8 +94,6 @@ public:
TreeItem *lastChild() const;
int level() const;
void setLazy(bool on);
void setPopulated(bool on);
void setFlags(Qt::ItemFlags flags);
int childCount() const { return m_children.size(); }
TreeItem *childAt(int index) const { return m_children.at(index); }
......@@ -115,14 +111,12 @@ private:
void operator=(const TreeItem &) Q_DECL_EQ_DELETE;
void clear();
void ensurePopulated() const;
void propagateModel(TreeModel *m);
TreeItem *m_parent; // Not owned.
TreeModel *m_model; // Not owned.
QVector<TreeItem *> m_children; // Owned.
QStringList *m_displays;
bool m_lazy;
mutable bool m_populated;
Qt::ItemFlags m_flags;
......
......@@ -127,9 +127,8 @@ class VariableGroupItem : public TreeItem
{
public:
VariableGroupItem()
: m_chooser(0)
: m_chooser(0), m_populated(false)
{
setLazy(true);
}
QVariant data(int column, int role) const
......@@ -143,16 +142,23 @@ public:
return QVariant();
}
void populate()
bool canFetchMore() const
{
return !m_populated;
}
void fetchMore()
{
if (MacroExpander *expander = m_provider())
populateGroup(expander);
m_populated = true;
}
void populateGroup(MacroExpander *expander);
public:
VariableChooserPrivate *m_chooser; // Not owned.
bool m_populated;
MacroExpanderProvider m_provider;
};
......
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