Skip to content

Commit 98999b1

Browse files
committed
Merge pull request #7 from neclepsio/gen2brain-v1
add AddImportPath
2 parents 3817cca + f172bdb commit 98999b1

File tree

4 files changed

+28
-0
lines changed

4 files changed

+28
-0
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,6 @@ examples/snapweb/snapweb
33
examples/particle/particle
44
gl/gengl/gengl
55
*.swp
6+
cpp/capi.h
7+
cpp/capi.h
8+
cpp/capi.h

cpp/capi.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,14 @@ void engineAddImageProvider(QQmlEngine_ *engine, QString_ *providerId, void *ima
222222
qengine->addImageProvider(*qproviderId, new GoImageProvider(imageFunc));
223223
}
224224

225+
void engineAddImportPath(QQmlEngine_ *engine, QString_ *path)
226+
{
227+
QQmlEngine *qengine = reinterpret_cast<QQmlEngine *>(engine);
228+
QString *qpath = reinterpret_cast<QString *>(path);
229+
230+
qengine->addImportPath(*qpath);
231+
}
232+
225233
void componentLoadURL(QQmlComponent_ *component, const char *url, int urlLen)
226234
{
227235
QByteArray qurl(url, urlLen);

cpp/capi.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ void engineClearPluginPaths(QQmlEngine_ *engine);
130130
void engineAddPluginPath(QQmlEngine_ *engine, const char *path, int pathLen);
131131
void engineClearComponentCache(QQmlEngine_ *engine);
132132
void coreAddLibraryPath(const char *path, int pathLen);
133+
void engineAddImportPath(QQmlEngine_ *engine, QString_ *path);
133134

134135
void contextGetProperty(QQmlContext_ *context, QString_ *name, DataValue *value);
135136
void contextSetProperty(QQmlContext_ *context, QString_ *name, DataValue *value);

qml.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,22 @@ func (e *Engine) AddImageProvider(prvId string, f func(imgId string, width, heig
281281
})
282282
}
283283

284+
// AddImportPath adds path as a directory where the engine searches for installed modules in a
285+
// URL-based directory structure.
286+
//
287+
// The path may be a local filesystem directory, a Qt Resource path (:/imports),
288+
// a Qt Resource url (qrc:/imports) or a URL.
289+
//
290+
// The newly added path will be first in the importPathList().
291+
func (e *Engine) AddImportPath(path string) {
292+
cpath, cpathLen := unsafeStringData(path)
293+
RunMain(func() {
294+
qpath := C.newString(cpath, cpathLen)
295+
defer C.delString(qpath)
296+
C.engineAddImportPath(e.addr, qpath)
297+
})
298+
}
299+
284300
//export hookRequestImage
285301
func hookRequestImage(imageFunc unsafe.Pointer, cid *C.char, cidLen, cwidth, cheight C.int) unsafe.Pointer {
286302
f := *(*func(imgId string, width, height int) image.Image)(imageFunc)

0 commit comments

Comments
 (0)