forked from qt-creator/qt-creator
		
	CodeAssist: use shared pointer to pass around proposal models
Task-number: QTCREATORBUG-17752 Change-Id: Ia41f169b86ead209830e6f15764062389ced2b67 Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
		@@ -115,17 +115,17 @@ public:
 | 
			
		||||
        ai->recreateTextDocument();
 | 
			
		||||
        InternalCppCompletionAssistProcessor processor;
 | 
			
		||||
 | 
			
		||||
        const Tests::IAssistProposalScopedPointer proposal(processor.perform(ai));
 | 
			
		||||
        if (!proposal.d)
 | 
			
		||||
        const QScopedPointer<IAssistProposal> proposal(processor.perform(ai));
 | 
			
		||||
        if (!proposal)
 | 
			
		||||
            return completions;
 | 
			
		||||
        IAssistProposalModel *model = proposal.d->model();
 | 
			
		||||
        ProposalModelPtr model = proposal->model();
 | 
			
		||||
        if (!model)
 | 
			
		||||
            return completions;
 | 
			
		||||
        CppAssistProposalModel *listmodel = dynamic_cast<CppAssistProposalModel *>(model);
 | 
			
		||||
        CppAssistProposalModelPtr listmodel = model.staticCast<CppAssistProposalModel>();
 | 
			
		||||
        if (!listmodel)
 | 
			
		||||
            return completions;
 | 
			
		||||
 | 
			
		||||
        const int pos = proposal.d->basePosition();
 | 
			
		||||
        const int pos = proposal->basePosition();
 | 
			
		||||
        const int length = m_position - pos;
 | 
			
		||||
        const QString prefix = Utils::Text::textAt(QTextCursor(m_textDocument), pos, length);
 | 
			
		||||
        if (!prefix.isEmpty())
 | 
			
		||||
 
 | 
			
		||||
@@ -443,9 +443,9 @@ AssistInterface *InternalCompletionAssistProvider::createAssistInterface(const Q
 | 
			
		||||
class CppAssistProposal : public GenericProposal
 | 
			
		||||
{
 | 
			
		||||
public:
 | 
			
		||||
    CppAssistProposal(int cursorPos, GenericProposalModel *model)
 | 
			
		||||
    CppAssistProposal(int cursorPos, GenericProposalModelPtr model)
 | 
			
		||||
        : GenericProposal(cursorPos, model)
 | 
			
		||||
        , m_replaceDotForArrow(static_cast<CppAssistProposalModel *>(model)->m_replaceDotForArrow)
 | 
			
		||||
        , m_replaceDotForArrow(model.staticCast<CppAssistProposalModel>()->m_replaceDotForArrow)
 | 
			
		||||
    {}
 | 
			
		||||
 | 
			
		||||
    bool isCorrective(TextEditorWidget *) const override { return m_replaceDotForArrow; }
 | 
			
		||||
@@ -922,16 +922,15 @@ IAssistProposal *InternalCppCompletionAssistProcessor::createContentProposal()
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    m_model->loadContent(m_completions);
 | 
			
		||||
    return new CppAssistProposal(m_positionForProposal, m_model.take());
 | 
			
		||||
    return new CppAssistProposal(m_positionForProposal, m_model);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
IAssistProposal *InternalCppCompletionAssistProcessor::createHintProposal(
 | 
			
		||||
    QList<Function *> functionSymbols) const
 | 
			
		||||
{
 | 
			
		||||
    IFunctionHintProposalModel *model =
 | 
			
		||||
            new CppFunctionHintModel(functionSymbols, m_model->m_typeOfExpression);
 | 
			
		||||
    IAssistProposal *proposal = new FunctionHintProposal(m_positionForProposal, model);
 | 
			
		||||
    return proposal;
 | 
			
		||||
    FunctionHintProposalModelPtr model(new CppFunctionHintModel(functionSymbols,
 | 
			
		||||
                                                                m_model->m_typeOfExpression));
 | 
			
		||||
    return new FunctionHintProposal(m_positionForProposal, model);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int InternalCppCompletionAssistProcessor::startOfOperator(int positionInDocument,
 | 
			
		||||
 
 | 
			
		||||
@@ -77,6 +77,8 @@ public:
 | 
			
		||||
    QSharedPointer<CPlusPlus::TypeOfExpression> m_typeOfExpression;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
using CppAssistProposalModelPtr = QSharedPointer<CppAssistProposalModel>;
 | 
			
		||||
 | 
			
		||||
class InternalCompletionAssistProvider : public CppCompletionAssistProvider
 | 
			
		||||
{
 | 
			
		||||
    Q_OBJECT
 | 
			
		||||
@@ -158,7 +160,7 @@ private:
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    QScopedPointer<const CppCompletionAssistInterface> m_interface;
 | 
			
		||||
    QScopedPointer<CppAssistProposalModel> m_model;
 | 
			
		||||
    CppAssistProposalModelPtr m_model;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
class CppCompletionAssistInterface : public TextEditor::AssistInterface
 | 
			
		||||
 
 | 
			
		||||
@@ -395,16 +395,6 @@ FileWriterAndRemover::~FileWriterAndRemover()
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
IAssistProposalScopedPointer::IAssistProposalScopedPointer(TextEditor::IAssistProposal *proposal)
 | 
			
		||||
    : d(proposal)
 | 
			
		||||
{}
 | 
			
		||||
 | 
			
		||||
IAssistProposalScopedPointer::~IAssistProposalScopedPointer()
 | 
			
		||||
{
 | 
			
		||||
    if (d && d->model())
 | 
			
		||||
        delete d->model();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
VerifyCleanCppModelManager::VerifyCleanCppModelManager()
 | 
			
		||||
{
 | 
			
		||||
    QVERIFY(isClean());
 | 
			
		||||
 
 | 
			
		||||
@@ -172,16 +172,5 @@ private:
 | 
			
		||||
    bool m_writtenSuccessfully;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
// Normally the proposal is deleted by the ProcessorRunner or the
 | 
			
		||||
// GenericProposalWidget, but in tests we usually don't make use of them.
 | 
			
		||||
class CPPTOOLS_EXPORT IAssistProposalScopedPointer
 | 
			
		||||
{
 | 
			
		||||
public:
 | 
			
		||||
    IAssistProposalScopedPointer(TextEditor::IAssistProposal *proposal);
 | 
			
		||||
    ~IAssistProposalScopedPointer();
 | 
			
		||||
 | 
			
		||||
    QScopedPointer<TextEditor::IAssistProposal> d;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
} // namespace Tests
 | 
			
		||||
} // namespace CppTools
 | 
			
		||||
 
 | 
			
		||||
@@ -83,7 +83,7 @@ protected:
 | 
			
		||||
 | 
			
		||||
    void showProposal(const QString &prefix) override
 | 
			
		||||
    {
 | 
			
		||||
        GenericProposalModel *proposalModel = model();
 | 
			
		||||
        GenericProposalModelPtr proposalModel = model();
 | 
			
		||||
        if (proposalModel && proposalModel->size() == 1) {
 | 
			
		||||
            emit proposalItemActivated(proposalModel->proposalItem(0));
 | 
			
		||||
            deleteLater();
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user