blob: 2ee5ada35ffc31988af70b924d3ffd12b87417c2 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
// Copyright (C) 2022 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0 WITH Qt-GPL-exception-1.0
#include "asyncprocessor.h"
#include "assistinterface.h"
#include "iassistproposal.h"
#include <utils/runextensions.h>
namespace TextEditor {
AsyncProcessor::AsyncProcessor()
{
QObject::connect(&m_watcher, &QFutureWatcher<IAssistProposal *>::finished, [this]() {
setAsyncProposalAvailable(m_watcher.result());
});
}
IAssistProposal *AsyncProcessor::perform(AssistInterface *interface)
{
IAssistProposal *result = immediateProposal(interface);
m_interface = interface;
m_interface->prepareForAsyncUse();
m_watcher.setFuture(Utils::runAsync([this]() {
m_interface->recreateTextDocument();
return performAsync(m_interface);
}));
return result;
}
bool AsyncProcessor::running()
{
return m_watcher.isRunning();
}
void AsyncProcessor::cancel()
{
setAsyncCompletionAvailableHandler([this](IAssistProposal *proposal){
delete proposal;
QMetaObject::invokeMethod(QCoreApplication::instance(), [this] {
delete this;
}, Qt::QueuedConnection);
});
}
IAssistProposal *AsyncProcessor::immediateProposal(AssistInterface *interface)
{
Q_UNUSED(interface)
return nullptr;
}
bool AsyncProcessor::isCanceled() const
{
return m_watcher.isCanceled();
}
} // namespace TextEditor
|