Commit ff6e1008 authored by Erik Verbruggen's avatar Erik Verbruggen Committed by Erik Verbruggen

C++: prevent cloning the QTextDocument on the UI thread.

Now the document contents (the text) is passed to the background thread,
which in turn will recreate the text document.

Change-Id: I7af47348fe162b53b8b440f1561a9919bf3c381a
Reviewed-by: default avatarNikolai Kosjar <nikolai.kosjar@digia.com>
parent 53e8e0fb
......@@ -132,6 +132,8 @@ private:
// --------------------
const QChar CodeAssistantPrivate::m_null;
static const int AutomaticProposalTimerInterval = 400;
CodeAssistantPrivate::CodeAssistantPrivate(CodeAssistant *assistant)
: m_q(assistant)
, m_textEditor(0)
......@@ -142,7 +144,7 @@ CodeAssistantPrivate::CodeAssistantPrivate(CodeAssistant *assistant)
, m_settings(TextEditorSettings::instance()->completionSettings())
{
m_automaticProposalTimer.setSingleShot(true);
m_automaticProposalTimer.setInterval(400);
m_automaticProposalTimer.setInterval(AutomaticProposalTimerInterval);
connect(&m_automaticProposalTimer, SIGNAL(timeout()), this, SLOT(automaticProposalTimeout()));
connect(TextEditorSettings::instance(),
......@@ -248,7 +250,7 @@ void CodeAssistantPrivate::requestProposal(AssistReason reason,
m_requestRunner = new ProcessorRunner;
connect(m_requestRunner, SIGNAL(finished()), this, SLOT(proposalComputed()));
connect(m_requestRunner, SIGNAL(finished()), this, SLOT(finalizeRequest()));
assistInterface->detach(m_requestRunner);
assistInterface->prepareForAsyncUse();
m_requestRunner->setReason(reason);
m_requestRunner->setProcessor(processor);
m_requestRunner->setAssistInterface(assistInterface);
......
......@@ -42,7 +42,7 @@ DefaultAssistInterface::DefaultAssistInterface(QTextDocument *textDocument,
Core::IDocument *document,
AssistReason reason)
: m_textDocument(textDocument)
, m_detached(false)
, m_isAsync(false)
, m_position(position)
, m_document(document)
, m_reason(reason)
......@@ -50,7 +50,7 @@ DefaultAssistInterface::DefaultAssistInterface(QTextDocument *textDocument,
DefaultAssistInterface::~DefaultAssistInterface()
{
if (m_detached)
if (m_isAsync)
delete m_textDocument;
}
......@@ -64,11 +64,17 @@ QString DefaultAssistInterface::textAt(int pos, int length) const
return Convenience::textAt(QTextCursor(m_textDocument), pos, length);
}
void DefaultAssistInterface::detach(QThread *destination)
void DefaultAssistInterface::prepareForAsyncUse()
{
m_textDocument = m_textDocument->clone();
m_textDocument->moveToThread(destination);
m_detached = true;
m_text = m_textDocument->toPlainText();
m_textDocument = 0;
m_isAsync = true;
}
void DefaultAssistInterface::recreateTextDocument()
{
m_textDocument = new QTextDocument(m_text);
m_text = QString();
}
AssistReason DefaultAssistInterface::reason() const
......
......@@ -48,15 +48,17 @@ public:
virtual QString textAt(int position, int length) const;
virtual const Core::IDocument *document() const { return m_document; }
virtual QTextDocument *textDocument() const { return m_textDocument; }
virtual void detach(QThread *destination);
virtual void prepareForAsyncUse();
virtual void recreateTextDocument();
virtual AssistReason reason() const;
private:
QTextDocument *m_textDocument;
bool m_detached;
bool m_isAsync;
int m_position;
Core::IDocument *m_document;
AssistReason m_reason;
QString m_text;
};
} // TextEditor
......
......@@ -58,7 +58,8 @@ public:
virtual QString textAt(int position, int length) const = 0;
virtual const Core::IDocument *document() const = 0;
virtual QTextDocument *textDocument() const = 0;
virtual void detach(QThread *destination) = 0;
virtual void prepareForAsyncUse() = 0;
virtual void recreateTextDocument() = 0;
virtual AssistReason reason() const = 0;
};
......
......@@ -60,6 +60,7 @@ void ProcessorRunner::setProcessor(IAssistProcessor *computer)
void ProcessorRunner::run()
{
m_interface->recreateTextDocument();
m_proposal = m_processor->perform(m_interface);
}
......
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