-
Notifications
You must be signed in to change notification settings - Fork 23
/
providessomething.cpp
40 lines (32 loc) · 985 Bytes
/
providessomething.cpp
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
#include "providessomething.h"
#include "urlinterceptor.h"
#include <QDirIterator>
#include <QJSEngine>
#include <QQmlEngine>
ProvidesSomething::ProvidesSomething()
{
connect(UrlInterceptor::self(), &UrlInterceptor::newFile, this, [this](const QUrl& path){
_fileSystemWatcher.addPath(path.toLocalFile());
});
connect(&_fileSystemWatcher, &QFileSystemWatcher::fileChanged, this, [this](const QString& path){
Q_UNUSED(path)
m_engine->clearComponentCache();
emit filePathChanged();
});
}
void ProvidesSomething::setEngine(QQmlEngine* engine)
{
m_engine = engine;
}
QObject* ProvidesSomething::qmlSingletonRegister(QQmlEngine* engine, QJSEngine* scriptEngine)
{
Q_UNUSED(scriptEngine)
engine->setObjectOwnership(self(), QQmlEngine::CppOwnership);
return self();
}
ProvidesSomething* ProvidesSomething::self()
{
static ProvidesSomething self;
return &self;
}
ProvidesSomething::~ProvidesSomething() = default;