Commit 70b64280 authored by Leandro Melo's avatar Leandro Melo
Browse files

Improve code-assist API isSortable



Now IGenericProposalModel::isSortable also takes the current prefix
as a parameter. This is particularly useful for cases like in the C++
completion: For global completions it will only sort if there's
already a content prefix - Notice, however, that the "sorting threshold"
for a maximum number of items is still kept in IGenericProposalModel::sort.

Task-number: QTCREATORBUG-6404
Change-Id: I3c2f282aa565287b8b4989930b6a27093862ef25
Reviewed-by: default avatarRoberto Raggi <roberto.raggi@nokia.com>
parent ef979ae7
......@@ -183,16 +183,14 @@ class CppAssistProposalModel : public TextEditor::BasicProposalItemListModel
public:
CppAssistProposalModel()
: TextEditor::BasicProposalItemListModel()
, m_sortable(false)
, m_completionOperator(T_EOF_SYMBOL)
, m_replaceDotForArrow(false)
, m_typeOfExpression(new TypeOfExpression)
{}
virtual bool isSortable() const { return m_sortable; }
virtual bool isSortable(const QString &prefix) const;
virtual IAssistProposalItem *proposalItem(int index) const;
bool m_sortable;
unsigned m_completionOperator;
bool m_replaceDotForArrow;
QSharedPointer<TypeOfExpression> m_typeOfExpression;
......@@ -229,6 +227,14 @@ private:
Q_DECLARE_METATYPE(CppTools::Internal::CompleteFunctionDeclaration)
bool CppAssistProposalModel::isSortable(const QString &prefix) const
{
if (m_completionOperator != T_EOF_SYMBOL)
return true;
return !prefix.isEmpty();
}
IAssistProposalItem *CppAssistProposalModel::proposalItem(int index) const
{
BasicProposalItem *item =
......@@ -699,10 +705,6 @@ IAssistProposal * CppCompletionAssistProcessor::perform(const IAssistInterface *
if (m_hintProposal)
return m_hintProposal;
if (m_model->m_completionOperator != T_EOF_SYMBOL)
m_model->m_sortable = true;
else
m_model->m_sortable = false;
return createContentProposal();
}
......
......@@ -225,7 +225,7 @@ ProFileAssistProposalModel::ProFileAssistProposalModel(
ProFileAssistProposalModel::~ProFileAssistProposalModel()
{}
bool ProFileAssistProposalModel::isSortable() const
bool ProFileAssistProposalModel::isSortable(const QString &prefix) const
{
return false;
}
......@@ -97,7 +97,7 @@ public:
ProFileAssistProposalModel(const QList<TextEditor::BasicProposalItem *> &items);
virtual ~ProFileAssistProposalModel();
virtual bool isSortable() const;
virtual bool isSortable(const QString &prefix) const;
};
} // Internal
......
......@@ -216,8 +216,10 @@ void BasicProposalItemListModel::filter(const QString &prefix)
}
}
bool BasicProposalItemListModel::isSortable() const
bool BasicProposalItemListModel::isSortable(const QString &prefix) const
{
Q_UNUSED(prefix);
if (m_currentItems.size() < kMaxSort)
return true;
return false;
......
......@@ -60,7 +60,7 @@ public:
virtual int persistentId(int index) const;
virtual void removeDuplicates();
virtual void filter(const QString &prefix);
virtual bool isSortable() const;
virtual bool isSortable(const QString &prefix) const;
virtual void sort();
virtual bool supportsPrefixExpansion() const;
virtual QString proposalPrefix() const;
......
......@@ -437,7 +437,7 @@ bool GenericProposalWidget::updateAndCheck(const QString &prefix)
abort();
return false;
}
if (d->m_model->isSortable())
if (d->m_model->isSortable(prefix))
d->m_model->sort();
d->m_completionListView->reset();
......
......@@ -55,7 +55,7 @@ public:
virtual int persistentId(int index) const = 0;
virtual void removeDuplicates() = 0;
virtual void filter(const QString &prefix) = 0;
virtual bool isSortable() const = 0;
virtual bool isSortable(const QString &prefix) const = 0;
virtual void sort() = 0;
virtual bool supportsPrefixExpansion() const = 0;
virtual QString proposalPrefix() const = 0;
......
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