History

changing raw pointer to unique pointer with custom deleter

amer cerkic committed 7 years ago

Commit b2e07fd1 parent 4dc67b52 files · +17 −15Browse files

Showing the changes to interface/src/ui/InteractiveWindow.cpp (1 of 2 files). Show all

Unified · Split

interface/src/ui/InteractiveWindow.cpp+8−13
@@ -134,14 +134,13 @@ InteractiveWindow::InteractiveWindow(const QString& sourceUrl, const QVariantMap · 133 unmodified lines
134134 InteractiveWindowPresentationMode presentationMode = InteractiveWindowPresentationMode::Native;
135135
136136 if (properties.contains(PRESENTATION_MODE_PROPERTY)) {
137− presentationMode = (InteractiveWindowPresentationMode) properties[PRESENTATION_MODE_PROPERTY].toInt();
137+ presentationMode = (InteractiveWindowPresentationMode)properties[PRESENTATION_MODE_PROPERTY].toInt();
138138 }
139139
140− if (!_interactiveWindowProxy) {
141− _interactiveWindowProxy = new InteractiveWindowProxy();
142− QObject::connect(_interactiveWindowProxy, &InteractiveWindowProxy::webEventReceived, this, &InteractiveWindow::emitWebEvent, Qt::QueuedConnection);
143− QObject::connect(this, &InteractiveWindow::scriptEventReceived, _interactiveWindowProxy, &InteractiveWindowProxy::emitScriptEvent, Qt::QueuedConnection);
144− }
140+ _interactiveWindowProxy = std::unique_ptr<InteractiveWindowProxy, InteractiveWindowProxyDeleter>(new InteractiveWindowProxy());
141+
142+ QObject::connect(_interactiveWindowProxy.get(), &InteractiveWindowProxy::webEventReceived, this, &InteractiveWindow::emitWebEvent, Qt::QueuedConnection);
143+ QObject::connect(this, &InteractiveWindow::scriptEventReceived, _interactiveWindowProxy.get(), &InteractiveWindowProxy::emitScriptEvent, Qt::QueuedConnection);
145144
146145 if (properties.contains(DOCKED_PROPERTY) && presentationMode == InteractiveWindowPresentationMode::Native) {
147146 QVariantMap nativeWindowInfo = properties[DOCKED_PROPERTY].toMap();
@@ -161,7 +160,7 @@ InteractiveWindow::InteractiveWindow(const QString& sourceUrl, const QVariantMap · 13 unmodified lines
161160 _dockWidget = std::shared_ptr<DockWidget>(new DockWidget(title, mainWindow), dockWidgetDeleter);
162161 auto quickView = _dockWidget->getQuickView();
163162
164− Application::setupQmlSurface(quickView->rootContext() , true);
163+ Application::setupQmlSurface(quickView->rootContext(), true);
165164
166165 //add any whitelisted callbacks
167166 OffscreenUi::applyWhiteList(sourceUrl, quickView->rootContext());
@@ -201,7 +200,7 @@ InteractiveWindow::InteractiveWindow(const QString& sourceUrl, const QVariantMap · 33 unmodified lines
201200 QObject::connect(quickView.get(), &QQuickView::statusChanged, [&, this] (QQuickView::Status status) {
202201 if (status == QQuickView::Ready) {
203202 QQuickItem* rootItem = _dockWidget->getRootItem();
204− _dockWidget->getQuickView()->rootContext()->setContextProperty(EVENT_BRIDGE_PROPERTY, _interactiveWindowProxy);
203+ _dockWidget->getQuickView()->rootContext()->setContextProperty(EVENT_BRIDGE_PROPERTY, _interactiveWindowProxy.get());
205204 // The qmlToScript method handles the thread-safety of this call. Because the QVariant argument
206205 // passed to the sendToScript signal may wrap an externally managed and thread-unsafe QJSValue,
207206 // 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 · 14 unmodified lines
222221 // Build the event bridge and wrapper on the main thread
223222 offscreenUi->loadInNewContext(CONTENT_WINDOW_QML, [&](QQmlContext* context, QObject* object) {
224223 _qmlWindowProxy = std::shared_ptr<QmlWindowProxy>(new QmlWindowProxy(object, nullptr), qmlWindowProxyDeleter);
225− context->setContextProperty(EVENT_BRIDGE_PROPERTY, _interactiveWindowProxy);
224+ context->setContextProperty(EVENT_BRIDGE_PROPERTY, _interactiveWindowProxy.get());
226225 if (properties.contains(ADDITIONAL_FLAGS_PROPERTY)) {
227226 object->setProperty(ADDITIONAL_FLAGS_PROPERTY, properties[ADDITIONAL_FLAGS_PROPERTY].toUInt());
228227 }
@@ -313,10 +312,6 @@ void InteractiveWindow::close() { · 84 unmodified lines
313312 _qmlWindowProxy->deleteLater();
314313 }
315314
316− if (_interactiveWindowProxy) {
317− _interactiveWindowProxy->deleteLater();
318− }
319−
320315 if (_dockWidget) {
321316 auto window = qApp->getWindow();
322317 if (QThread::currentThread() != window->thread()) {

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t