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: Eike Ziller <eike.ziller@theqtcompany.com>
This commit is contained in:
hjk
2015-04-22 15:56:03 +02:00
parent 2b19081cb0
commit 66fd805809
3 changed files with 12 additions and 39 deletions

View File

@@ -611,14 +611,12 @@ namespace Utils {
// TreeItem // TreeItem
// //
TreeItem::TreeItem() TreeItem::TreeItem()
: m_parent(0), m_model(0), m_displays(0), m_lazy(false), m_populated(false), : m_parent(0), m_model(0), m_displays(0), m_flags(Qt::ItemIsEnabled|Qt::ItemIsSelectable)
m_flags(Qt::ItemIsEnabled|Qt::ItemIsSelectable)
{ {
} }
TreeItem::TreeItem(const QStringList &displays, int flags) 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_parent(0), m_model(0), m_displays(new QStringList(displays)), m_flags(flags)
m_flags(flags)
{ {
} }
@@ -630,26 +628,15 @@ TreeItem::~TreeItem()
TreeItem *TreeItem::child(int pos) const TreeItem *TreeItem::child(int pos) const
{ {
ensurePopulated();
QTC_ASSERT(pos >= 0, return 0); QTC_ASSERT(pos >= 0, return 0);
return pos < m_children.size() ? m_children.at(pos) : 0; return pos < m_children.size() ? m_children.at(pos) : 0;
} }
bool TreeItem::isLazy() const
{
return m_lazy;
}
int TreeItem::rowCount() const int TreeItem::rowCount() const
{ {
ensurePopulated();
return m_children.size(); return m_children.size();
} }
void TreeItem::populate()
{
}
QVariant TreeItem::data(int column, int role) const QVariant TreeItem::data(int column, int role) const
{ {
if (role == Qt::DisplayRole && m_displays && column >= 0 && column < m_displays->size()) 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_CHECK(!item->parent());
QTC_ASSERT(0 <= pos && pos <= m_children.size(), return); // '<= size' is intentional. QTC_ASSERT(0 <= pos && pos <= m_children.size(), return); // '<= size' is intentional.
if (m_model && !m_lazy) { if (m_model) {
QModelIndex idx = index(); QModelIndex idx = index();
m_model->beginInsertRows(idx, pos, pos); m_model->beginInsertRows(idx, pos, pos);
item->m_parent = this; item->m_parent = this;
@@ -770,11 +757,6 @@ int TreeItem::level() const
return l; return l;
} }
void TreeItem::setLazy(bool on)
{
m_lazy = on;
}
void TreeItem::setFlags(Qt::ItemFlags flags) void TreeItem::setFlags(Qt::ItemFlags flags)
{ {
m_flags = flags; m_flags = flags;
@@ -830,15 +812,6 @@ void TreeItem::expand()
m_model->requestExpansion(index()); 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) void TreeItem::propagateModel(TreeModel *m)
{ {
QTC_ASSERT(m, return); QTC_ASSERT(m, return);

View File

@@ -72,9 +72,7 @@ public:
virtual TreeItem *parent() const { return m_parent; } virtual TreeItem *parent() const { return m_parent; }
virtual TreeItem *child(int pos) const; virtual TreeItem *child(int pos) const;
virtual bool isLazy() const;
virtual int rowCount() const; virtual int rowCount() const;
virtual void populate();
virtual QVariant data(int column, int role) const; virtual QVariant data(int column, int role) const;
virtual bool setData(int column, const QVariant &data, int role); virtual bool setData(int column, const QVariant &data, int role);
@@ -96,8 +94,6 @@ public:
TreeItem *lastChild() const; TreeItem *lastChild() const;
int level() const; int level() const;
void setLazy(bool on);
void setPopulated(bool on);
void setFlags(Qt::ItemFlags flags); void setFlags(Qt::ItemFlags flags);
int childCount() const { return m_children.size(); } int childCount() const { return m_children.size(); }
TreeItem *childAt(int index) const { return m_children.at(index); } TreeItem *childAt(int index) const { return m_children.at(index); }
@@ -115,14 +111,12 @@ private:
void operator=(const TreeItem &) Q_DECL_EQ_DELETE; void operator=(const TreeItem &) Q_DECL_EQ_DELETE;
void clear(); void clear();
void ensurePopulated() const;
void propagateModel(TreeModel *m); void propagateModel(TreeModel *m);
TreeItem *m_parent; // Not owned. TreeItem *m_parent; // Not owned.
TreeModel *m_model; // Not owned. TreeModel *m_model; // Not owned.
QVector<TreeItem *> m_children; // Owned. QVector<TreeItem *> m_children; // Owned.
QStringList *m_displays; QStringList *m_displays;
bool m_lazy;
mutable bool m_populated; mutable bool m_populated;
Qt::ItemFlags m_flags; Qt::ItemFlags m_flags;

View File

@@ -127,9 +127,8 @@ class VariableGroupItem : public TreeItem
{ {
public: public:
VariableGroupItem() VariableGroupItem()
: m_chooser(0) : m_chooser(0), m_populated(false)
{ {
setLazy(true);
} }
QVariant data(int column, int role) const QVariant data(int column, int role) const
@@ -143,16 +142,23 @@ public:
return QVariant(); return QVariant();
} }
void populate() bool canFetchMore() const
{
return !m_populated;
}
void fetchMore()
{ {
if (MacroExpander *expander = m_provider()) if (MacroExpander *expander = m_provider())
populateGroup(expander); populateGroup(expander);
m_populated = true;
} }
void populateGroup(MacroExpander *expander); void populateGroup(MacroExpander *expander);
public: public:
VariableChooserPrivate *m_chooser; // Not owned. VariableChooserPrivate *m_chooser; // Not owned.
bool m_populated;
MacroExpanderProvider m_provider; MacroExpanderProvider m_provider;
}; };