mirror of
https://github.com/AleziaKurdis/overte.git
synced 2025-04-08 23:12:16 +02:00
changing raw pointer to unique pointer with custom deleter
This commit is contained in:
parent
4dc67b5c58
commit
b2e07fd990
2 changed files with 17 additions and 15 deletions
|
@ -134,14 +134,13 @@ InteractiveWindow::InteractiveWindow(const QString& sourceUrl, const QVariantMap
|
|||
InteractiveWindowPresentationMode presentationMode = InteractiveWindowPresentationMode::Native;
|
||||
|
||||
if (properties.contains(PRESENTATION_MODE_PROPERTY)) {
|
||||
presentationMode = (InteractiveWindowPresentationMode) properties[PRESENTATION_MODE_PROPERTY].toInt();
|
||||
presentationMode = (InteractiveWindowPresentationMode)properties[PRESENTATION_MODE_PROPERTY].toInt();
|
||||
}
|
||||
|
||||
if (!_interactiveWindowProxy) {
|
||||
_interactiveWindowProxy = new InteractiveWindowProxy();
|
||||
QObject::connect(_interactiveWindowProxy, &InteractiveWindowProxy::webEventReceived, this, &InteractiveWindow::emitWebEvent, Qt::QueuedConnection);
|
||||
QObject::connect(this, &InteractiveWindow::scriptEventReceived, _interactiveWindowProxy, &InteractiveWindowProxy::emitScriptEvent, Qt::QueuedConnection);
|
||||
}
|
||||
_interactiveWindowProxy = std::unique_ptr<InteractiveWindowProxy, InteractiveWindowProxyDeleter>(new InteractiveWindowProxy());
|
||||
|
||||
QObject::connect(_interactiveWindowProxy.get(), &InteractiveWindowProxy::webEventReceived, this, &InteractiveWindow::emitWebEvent, Qt::QueuedConnection);
|
||||
QObject::connect(this, &InteractiveWindow::scriptEventReceived, _interactiveWindowProxy.get(), &InteractiveWindowProxy::emitScriptEvent, Qt::QueuedConnection);
|
||||
|
||||
if (properties.contains(DOCKED_PROPERTY) && presentationMode == InteractiveWindowPresentationMode::Native) {
|
||||
QVariantMap nativeWindowInfo = properties[DOCKED_PROPERTY].toMap();
|
||||
|
@ -161,7 +160,7 @@ InteractiveWindow::InteractiveWindow(const QString& sourceUrl, const QVariantMap
|
|||
_dockWidget = std::shared_ptr<DockWidget>(new DockWidget(title, mainWindow), dockWidgetDeleter);
|
||||
auto quickView = _dockWidget->getQuickView();
|
||||
|
||||
Application::setupQmlSurface(quickView->rootContext() , true);
|
||||
Application::setupQmlSurface(quickView->rootContext(), true);
|
||||
|
||||
//add any whitelisted callbacks
|
||||
OffscreenUi::applyWhiteList(sourceUrl, quickView->rootContext());
|
||||
|
@ -201,7 +200,7 @@ InteractiveWindow::InteractiveWindow(const QString& sourceUrl, const QVariantMap
|
|||
QObject::connect(quickView.get(), &QQuickView::statusChanged, [&, this] (QQuickView::Status status) {
|
||||
if (status == QQuickView::Ready) {
|
||||
QQuickItem* rootItem = _dockWidget->getRootItem();
|
||||
_dockWidget->getQuickView()->rootContext()->setContextProperty(EVENT_BRIDGE_PROPERTY, _interactiveWindowProxy);
|
||||
_dockWidget->getQuickView()->rootContext()->setContextProperty(EVENT_BRIDGE_PROPERTY, _interactiveWindowProxy.get());
|
||||
// The qmlToScript method handles the thread-safety of this call. Because the QVariant argument
|
||||
// passed to the sendToScript signal may wrap an externally managed and thread-unsafe QJSValue,
|
||||
// qmlToScript needs to be called directly, so the QJSValue can be immediately converted to a plain QVariant.
|
||||
|
@ -222,7 +221,7 @@ InteractiveWindow::InteractiveWindow(const QString& sourceUrl, const QVariantMap
|
|||
// Build the event bridge and wrapper on the main thread
|
||||
offscreenUi->loadInNewContext(CONTENT_WINDOW_QML, [&](QQmlContext* context, QObject* object) {
|
||||
_qmlWindowProxy = std::shared_ptr<QmlWindowProxy>(new QmlWindowProxy(object, nullptr), qmlWindowProxyDeleter);
|
||||
context->setContextProperty(EVENT_BRIDGE_PROPERTY, _interactiveWindowProxy);
|
||||
context->setContextProperty(EVENT_BRIDGE_PROPERTY, _interactiveWindowProxy.get());
|
||||
if (properties.contains(ADDITIONAL_FLAGS_PROPERTY)) {
|
||||
object->setProperty(ADDITIONAL_FLAGS_PROPERTY, properties[ADDITIONAL_FLAGS_PROPERTY].toUInt());
|
||||
}
|
||||
|
@ -313,10 +312,6 @@ void InteractiveWindow::close() {
|
|||
_qmlWindowProxy->deleteLater();
|
||||
}
|
||||
|
||||
if (_interactiveWindowProxy) {
|
||||
_interactiveWindowProxy->deleteLater();
|
||||
}
|
||||
|
||||
if (_dockWidget) {
|
||||
auto window = qApp->getWindow();
|
||||
if (QThread::currentThread() != window->thread()) {
|
||||
|
|
|
@ -37,11 +37,12 @@ private:
|
|||
};
|
||||
|
||||
|
||||
|
||||
class InteractiveWindowProxy : public QObject {
|
||||
Q_OBJECT
|
||||
public:
|
||||
InteractiveWindowProxy(){}
|
||||
|
||||
|
||||
public slots:
|
||||
|
||||
void emitScriptEvent(const QVariant& scriptMessage);
|
||||
|
@ -53,6 +54,12 @@ signals:
|
|||
void webEventReceived(const QVariant& message);
|
||||
};
|
||||
|
||||
struct InteractiveWindowProxyDeleter {
|
||||
void operator()(InteractiveWindowProxy * p) {
|
||||
p->deleteLater();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
namespace InteractiveWindowEnums {
|
||||
Q_NAMESPACE
|
||||
|
@ -325,7 +332,7 @@ protected slots:
|
|||
private:
|
||||
std::shared_ptr<QmlWindowProxy> _qmlWindowProxy;
|
||||
std::shared_ptr<DockWidget> _dockWidget { nullptr };
|
||||
InteractiveWindowProxy *_interactiveWindowProxy{ nullptr };
|
||||
std::unique_ptr<InteractiveWindowProxy, InteractiveWindowProxyDeleter> _interactiveWindowProxy;
|
||||
};
|
||||
|
||||
typedef InteractiveWindow* InteractiveWindowPointer;
|
||||
|
|
Loading…
Reference in a new issue