forked from qt-creator/qt-creator
MacroExpander: Delay variable chooser population
Change-Id: I4bf81bcf8bb4f14bf6c31f613d79e79380b666e0 Reviewed-by: Eike Ziller <eike.ziller@theqtcompany.com> Reviewed-by: hjk <hjk121@nokiamail.com>
This commit is contained in:
@@ -411,15 +411,9 @@ QString MacroExpander::variableDescription(const QByteArray &variable) const
|
|||||||
return d->m_descriptions.value(variable);
|
return d->m_descriptions.value(variable);
|
||||||
}
|
}
|
||||||
|
|
||||||
MacroExpanders MacroExpander::subExpanders() const
|
MacroExpanderProviders MacroExpander::subProviders() const
|
||||||
{
|
{
|
||||||
MacroExpanders expanders;
|
return d->m_subProviders;
|
||||||
foreach (const MacroExpanderProvider &provider, d->m_subProviders)
|
|
||||||
if (provider)
|
|
||||||
if (MacroExpander *expander = provider())
|
|
||||||
expanders.append(expander);
|
|
||||||
|
|
||||||
return expanders;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QString MacroExpander::displayName() const
|
QString MacroExpander::displayName() const
|
||||||
|
|||||||
@@ -46,6 +46,7 @@ namespace Internal { class MacroExpanderPrivate; }
|
|||||||
class MacroExpander;
|
class MacroExpander;
|
||||||
typedef std::function<MacroExpander *()> MacroExpanderProvider;
|
typedef std::function<MacroExpander *()> MacroExpanderProvider;
|
||||||
typedef QVector<MacroExpander *> MacroExpanders;
|
typedef QVector<MacroExpander *> MacroExpanders;
|
||||||
|
typedef QVector<MacroExpanderProvider> MacroExpanderProviders;
|
||||||
|
|
||||||
class QTCREATOR_UTILS_EXPORT MacroExpander
|
class QTCREATOR_UTILS_EXPORT MacroExpander
|
||||||
{
|
{
|
||||||
@@ -89,7 +90,7 @@ public:
|
|||||||
QList<QByteArray> visibleVariables() const;
|
QList<QByteArray> visibleVariables() const;
|
||||||
QString variableDescription(const QByteArray &variable) const;
|
QString variableDescription(const QByteArray &variable) const;
|
||||||
|
|
||||||
MacroExpanders subExpanders() const;
|
MacroExpanderProviders subProviders() const;
|
||||||
|
|
||||||
QString displayName() const;
|
QString displayName() const;
|
||||||
void setDisplayName(const QString &displayName);
|
void setDisplayName(const QString &displayName);
|
||||||
|
|||||||
@@ -127,23 +127,17 @@ class VariableGroupItem : public TreeItem
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
VariableGroupItem()
|
VariableGroupItem()
|
||||||
: m_chooser(0), m_expander(0)
|
: m_chooser(0)
|
||||||
{
|
{
|
||||||
setLazy(true);
|
setLazy(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ensureExpander() const
|
|
||||||
{
|
|
||||||
if (!m_expander)
|
|
||||||
m_expander = m_provider();
|
|
||||||
return m_expander != 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
QVariant data(int column, int role) const
|
QVariant data(int column, int role) const
|
||||||
{
|
{
|
||||||
if (role == Qt::DisplayRole || role == Qt::EditRole) {
|
if (role == Qt::DisplayRole || role == Qt::EditRole) {
|
||||||
if (column == 0 && ensureExpander())
|
if (column == 0)
|
||||||
return m_expander->displayName();
|
if (MacroExpander *expander = m_provider())
|
||||||
|
return expander->displayName();
|
||||||
}
|
}
|
||||||
|
|
||||||
return QVariant();
|
return QVariant();
|
||||||
@@ -151,8 +145,8 @@ public:
|
|||||||
|
|
||||||
void populate()
|
void populate()
|
||||||
{
|
{
|
||||||
if (ensureExpander())
|
if (MacroExpander *expander = m_provider())
|
||||||
populateGroup(m_expander);
|
populateGroup(expander);
|
||||||
}
|
}
|
||||||
|
|
||||||
void populateGroup(MacroExpander *expander);
|
void populateGroup(MacroExpander *expander);
|
||||||
@@ -160,7 +154,6 @@ public:
|
|||||||
public:
|
public:
|
||||||
VariableChooserPrivate *m_chooser; // Not owned.
|
VariableChooserPrivate *m_chooser; // Not owned.
|
||||||
MacroExpanderProvider m_provider;
|
MacroExpanderProvider m_provider;
|
||||||
mutable MacroExpander *m_expander; // Not owned.
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class VariableItem : public TreeItem
|
class VariableItem : public TreeItem
|
||||||
@@ -260,6 +253,9 @@ VariableChooserPrivate::VariableChooserPrivate(VariableChooser *parent)
|
|||||||
|
|
||||||
void VariableGroupItem::populateGroup(MacroExpander *expander)
|
void VariableGroupItem::populateGroup(MacroExpander *expander)
|
||||||
{
|
{
|
||||||
|
if (!expander)
|
||||||
|
return;
|
||||||
|
|
||||||
foreach (const QByteArray &variable, expander->visibleVariables()) {
|
foreach (const QByteArray &variable, expander->visibleVariables()) {
|
||||||
auto item = new VariableItem;
|
auto item = new VariableItem;
|
||||||
item->m_variable = QString::fromUtf8(variable);
|
item->m_variable = QString::fromUtf8(variable);
|
||||||
@@ -269,13 +265,15 @@ void VariableGroupItem::populateGroup(MacroExpander *expander)
|
|||||||
appendChild(item);
|
appendChild(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (MacroExpander *subExpander, expander->subExpanders()) {
|
foreach (const MacroExpanderProvider &subProvider, expander->subProviders()) {
|
||||||
|
if (!subProvider)
|
||||||
|
continue;
|
||||||
if (expander->isAccumulating()) {
|
if (expander->isAccumulating()) {
|
||||||
populateGroup(subExpander);
|
populateGroup(subProvider());
|
||||||
} else {
|
} else {
|
||||||
auto item = new VariableGroupItem;
|
auto item = new VariableGroupItem;
|
||||||
item->m_chooser = m_chooser;
|
item->m_chooser = m_chooser;
|
||||||
item->m_expander = subExpander;
|
item->m_provider = subProvider;
|
||||||
appendChild(item);
|
appendChild(item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user