Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add AddImportPath #1

Merged
merged 1 commit into from
Nov 16, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions cpp/capi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,14 @@ void engineAddImageProvider(QQmlEngine_ *engine, QString_ *providerId, void *ima
qengine->addImageProvider(*qproviderId, new GoImageProvider(imageFunc));
}

void engineAddImportPath(QQmlEngine_ *engine, QString_ *path)
{
QQmlEngine *qengine = reinterpret_cast<QQmlEngine *>(engine);
QString *qpath = reinterpret_cast<QString *>(path);

qengine->addImportPath(*qpath);
}

void componentLoadURL(QQmlComponent_ *component, const char *url, int urlLen)
{
QByteArray qurl(url, urlLen);
Expand Down
1 change: 1 addition & 0 deletions cpp/capi.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ void engineSetOwnershipCPP(QQmlEngine_ *engine, QObject_ *object);
void engineSetOwnershipJS(QQmlEngine_ *engine, QObject_ *object);
void engineSetContextForObject(QQmlEngine_ *engine, QObject_ *object);
void engineAddImageProvider(QQmlEngine_ *engine, QString_ *providerId, void *imageFunc);
void engineAddImportPath(QQmlEngine_ *engine, QString_ *path);

void contextGetProperty(QQmlContext_ *context, QString_ *name, DataValue *value);
void contextSetProperty(QQmlContext_ *context, QString_ *name, DataValue *value);
Expand Down
16 changes: 16 additions & 0 deletions qml.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,22 @@ func (e *Engine) AddImageProvider(prvId string, f func(imgId string, width, heig
})
}

// AddImportPath adds path as a directory where the engine searches for installed modules in a
// URL-based directory structure.
//
// The path may be a local filesystem directory, a Qt Resource path (:/imports),
// a Qt Resource url (qrc:/imports) or a URL.
//
// The newly added path will be first in the importPathList().
func (e *Engine) AddImportPath(path string) {
cpath, cpathLen := unsafeStringData(path)
RunMain(func() {
qpath := C.newString(cpath, cpathLen)
defer C.delString(qpath)
C.engineAddImportPath(e.addr, qpath)
})
}

//export hookRequestImage
func hookRequestImage(imageFunc unsafe.Pointer, cid *C.char, cidLen, cwidth, cheight C.int) unsafe.Pointer {
f := *(*func(imgId string, width, height int) image.Image)(imageFunc)
Expand Down