Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Qt UI Viewer
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Jira
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Design Studio
QML Viewer Projects
Qt UI Viewer
Commits
cb9c9aa8
Verified
Commit
cb9c9aa8
authored
1 year ago
by
Burak Hançerli
Browse files
Options
Downloads
Patches
Plain Diff
chore: add changes missing in rebase
parent
186f4d3a
No related branches found
No related tags found
1 merge request
!1
QDS-9900 Update the design viewer app to work with Qt 6.5 / emsdk 3.1.25
Pipeline
#61331
canceled
1 year ago
Changes
1
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
design-viewer/src/dv_wasm.cpp
+33
-55
33 additions, 55 deletions
design-viewer/src/dv_wasm.cpp
with
33 additions
and
55 deletions
design-viewer/src/dv_wasm.cpp
+
33
−
55
View file @
cb9c9aa8
...
...
@@ -26,64 +26,23 @@
#include
"dv_wasm.h"
#if defined(Q_OS_WASM)
#include
<emscripten/val.h>
#include
<emscripten.h>
#include
<functional>
#include
<QFile>
std
::
function
<
void
(
char
*
,
size_t
,
char
*
)
>
g_setFileDataCallback
;
extern
"C"
EMSCRIPTEN_KEEPALIVE
void
qt_callSetFileData
(
char
*
content
,
size_t
contentSize
,
char
*
fileName
)
{
if
(
g_setFileDataCallback
==
nullptr
)
return
;
g_setFileDataCallback
(
content
,
contentSize
,
fileName
);
g_setFileDataCallback
=
nullptr
;
}
#include
<QTimer>
void
DvWasm
::
fetchProject
(
QByteArray
*
data
,
QString
*
fileName
)
{
// Call qt_callSetFileData to make sure the emscripten linker does not
// optimize it away, which may happen if the function is called from JavaScript
// only. Set g_setFileDataCallback to null to make it a no-op.
::
g_setFileDataCallback
=
nullptr
;
::
qt_callSetFileData
(
nullptr
,
0
,
nullptr
);
auto
setFileDataCallback
=
[
data
,
fileName
](
char
*
content
,
size_t
contentSize
,
char
*
projectFilename
)
{
data
->
setRawData
(
content
,
contentSize
);
*
fileName
=
QString
::
fromUtf8
(
projectFilename
);
};
g_setFileDataCallback
=
setFileDataCallback
;
EM_ASM_
({
// Copy the file file content to the C++ heap.
// Note: this could be simplified by passing the content as an
// "array" type to ccall and then let it copy to C++ memory.
// However, this built-in solution does not handle files larger
// than ~15M (Chrome). Instead, allocate memory manually and
// pass a pointer to the C++ side (which will free() it when done).
// Access global variables set by index.html
emscripten
::
val
jsData
=
emscripten
::
val
::
global
(
"contentArray"
);
emscripten
::
val
jsFileName
=
emscripten
::
val
::
global
(
"projectfileName"
);
// TODO: consider slice()ing the file to read it picewise and
// then assembling it in a QByteArray on the C++ side.
const
contentSize
=
contentArray
.
byteLength
;
const
heapPointer
=
_malloc
(
contentSize
);
const
heapBytes
=
new
Uint8Array
(
Module
.
HEAPU8
.
buffer
,
heapPointer
,
contentSize
);
heapBytes
.
set
(
contentArray
);
// Null out the first data copy to enable GC
reader
=
null
;
contentArray
=
null
;
// Call the C++ file data ready callback
ccall
(
"qt_callSetFileData"
,
null
,
[
"number"
,
"number"
,
"string"
],
[
heapPointer
,
contentSize
,
projectfileName
]);
});
// Copy project data to the C++ heap and convert string
*
data
=
QByteArray
::
fromEcmaUint8Array
(
jsData
);
*
fileName
=
QString
::
fromStdString
(
jsFileName
.
as
<
std
::
string
>
());
}
void
DvWasm
::
printLog
(
const
QString
&
message
)
...
...
@@ -96,22 +55,41 @@ void DvWasm::printWarn(const QString &message)
QString
escaped
=
message
;
escaped
.
replace
(
"'"
,
"
\'
"
);
escaped
.
replace
(
"
\n
"
,
"
\\
n"
);
emscripten
_run_script
(
"alert
('"
+
escaped
.
to
Utf8
()
+
"');"
);
emscripten
::
val
::
global
(
"window"
).
call
<
void
>
(
"alert
"
,
escaped
.
to
StdString
()
);
}
void
DvWasm
::
printError
(
const
QString
&
message
,
const
QString
&
fileName
,
int
line
)
{
printWarn
(
message
);
emscripten_run_script
(
"location.hash = ''; location.reload();"
);
emscripten
::
val
location
=
emscripten
::
val
::
global
(
"window"
)[
"location"
];
location
.
set
(
"hash"
,
std
::
string
());
location
.
call
<
void
>
(
"reload"
);
}
void
DvWasm
::
showAppWindow
()
{
printLog
(
"Resizing the QML app window"
);
const
QSize
size
;
const
QString
command
=
QString
::
fromLatin1
(
"setScreenSize(%1, %2);"
).
arg
(
size
.
width
()).
arg
(
size
.
height
());
emscripten_run_script
(
command
.
toUtf8
());
emscripten
::
val
qtContainer
=
emscripten
::
val
::
global
(
"container"
);
// global from index.html
emscripten
::
val
qtContainerStyle
=
qtContainer
[
"style"
];
if
(
size
.
isEmpty
())
{
qtContainerStyle
.
set
(
"width"
,
std
::
string
(
"100%"
));
qtContainerStyle
.
set
(
"height"
,
std
::
string
(
"100%"
));
// ### FIXME: 100% height gives 0px height for some reason
}
else
{
qtContainerStyle
.
set
(
"width"
,
QString
(
"%1px"
).
arg
(
size
.
width
()).
toStdString
());
qtContainerStyle
.
set
(
"height"
,
QString
(
"%1px"
).
arg
(
size
.
height
()).
toStdString
());
}
// Make Qt pick up the new container size by calling the resizeCanvasElement()
// qtloader API. This needs to be done on delay after initial setup to make
// sure qtloader is initialized.
QTimer
::
singleShot
(
0
,
[
qtContainer
]()
{
emscripten
::
val
qtLoader
=
emscripten
::
val
::
global
(
"qtLoader"
);
qtLoader
.
call
<
void
>
(
"resizeCanvasElement"
,
qtContainer
);
});
printLog
(
"Showing the QML app window"
);
m_quickWindow
->
show
();
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment