aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/qmldesigner/components/textureeditor
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/qmldesigner/components/textureeditor')
-rw-r--r--src/plugins/qmldesigner/components/textureeditor/textureeditorcontextobject.cpp4
-rw-r--r--src/plugins/qmldesigner/components/textureeditor/textureeditorqmlbackend.cpp38
-rw-r--r--src/plugins/qmldesigner/components/textureeditor/textureeditorqmlbackend.h15
-rw-r--r--src/plugins/qmldesigner/components/textureeditor/textureeditorview.cpp4
4 files changed, 33 insertions, 28 deletions
diff --git a/src/plugins/qmldesigner/components/textureeditor/textureeditorcontextobject.cpp b/src/plugins/qmldesigner/components/textureeditor/textureeditorcontextobject.cpp
index 73e784846b..30f276a48d 100644
--- a/src/plugins/qmldesigner/components/textureeditor/textureeditorcontextobject.cpp
+++ b/src/plugins/qmldesigner/components/textureeditor/textureeditorcontextobject.cpp
@@ -47,9 +47,9 @@ QString TextureEditorContextObject::convertColorToString(const QVariant &color)
{
QString colorString;
QColor theColor;
- if (color.canConvert(QVariant::Color)) {
+ if (color.canConvert(QMetaType(QMetaType::QColor))) {
theColor = color.value<QColor>();
- } else if (color.canConvert(QVariant::Vector3D)) {
+ } else if (color.canConvert(QMetaType(QMetaType::QVector3D))) {
auto vec = color.value<QVector3D>();
theColor = QColor::fromRgbF(vec.x(), vec.y(), vec.z());
}
diff --git a/src/plugins/qmldesigner/components/textureeditor/textureeditorqmlbackend.cpp b/src/plugins/qmldesigner/components/textureeditor/textureeditorqmlbackend.cpp
index 80cf5693d2..415d943723 100644
--- a/src/plugins/qmldesigner/components/textureeditor/textureeditorqmlbackend.cpp
+++ b/src/plugins/qmldesigner/components/textureeditor/textureeditorqmlbackend.cpp
@@ -42,21 +42,22 @@ static QObject *variantToQObject(const QVariant &value)
namespace QmlDesigner {
-TextureEditorQmlBackend::TextureEditorQmlBackend(TextureEditorView *textureEditor, AsynchronousImageCache &imageCache)
- : m_view(new QQuickWidget)
- , m_textureEditorTransaction(new TextureEditorTransaction(textureEditor))
- , m_contextObject(new TextureEditorContextObject(m_view->rootContext()))
+TextureEditorQmlBackend::TextureEditorQmlBackend(TextureEditorView *textureEditor,
+ AsynchronousImageCache &imageCache)
+ : m_quickWidget(Utils::makeUniqueObjectPtr<QQuickWidget>())
+ , m_textureEditorTransaction(std::make_unique<TextureEditorTransaction>(textureEditor))
+ , m_contextObject(std::make_unique<TextureEditorContextObject>(m_quickWidget->rootContext()))
{
QImage defaultImage;
defaultImage.load(Utils::StyleHelper::dpiSpecificImageFile(":/textureeditor/images/texture_default.png"));
m_textureEditorImageProvider = new AssetImageProvider(imageCache, defaultImage);
- m_view->setResizeMode(QQuickWidget::SizeRootObjectToView);
- m_view->setObjectName(Constants::OBJECT_NAME_TEXTURE_EDITOR);
- m_view->engine()->addImportPath(propertyEditorResourcesPath() + "/imports");
- m_view->engine()->addImageProvider("qmldesigner_thumbnails", m_textureEditorImageProvider);
+ m_quickWidget->setResizeMode(QQuickWidget::SizeRootObjectToView);
+ m_quickWidget->setObjectName(Constants::OBJECT_NAME_TEXTURE_EDITOR);
+ m_quickWidget->engine()->addImportPath(propertyEditorResourcesPath() + "/imports");
+ m_quickWidget->engine()->addImageProvider("qmldesigner_thumbnails", m_textureEditorImageProvider);
m_contextObject->setBackendValues(&m_backendValuesPropertyMap);
m_contextObject->setModel(textureEditor->model());
- context()->setContextObject(m_contextObject.data());
+ context()->setContextObject(m_contextObject.get());
QObject::connect(&m_backendValuesPropertyMap, &DesignerPropertyMap::valueChanged,
textureEditor, &TextureEditorView::changeValue);
@@ -154,22 +155,22 @@ void TextureEditorQmlBackend::setValue(const QmlObjectNode &, const PropertyName
QQmlContext *TextureEditorQmlBackend::context() const
{
- return m_view->rootContext();
+ return m_quickWidget->rootContext();
}
TextureEditorContextObject *TextureEditorQmlBackend::contextObject() const
{
- return m_contextObject.data();
+ return m_contextObject.get();
}
QQuickWidget *TextureEditorQmlBackend::widget() const
{
- return m_view;
+ return m_quickWidget.get();
}
void TextureEditorQmlBackend::setSource(const QUrl &url)
{
- m_view->setSource(url);
+ m_quickWidget->setSource(url);
}
QmlAnchorBindingProxy &TextureEditorQmlBackend::backendAnchorBinding()
@@ -184,7 +185,7 @@ DesignerPropertyMap &TextureEditorQmlBackend::backendValuesPropertyMap()
TextureEditorTransaction *TextureEditorQmlBackend::textureEditorTransaction() const
{
- return m_textureEditorTransaction.data();
+ return m_textureEditorTransaction.get();
}
PropertyEditorValue *TextureEditorQmlBackend::propertyValueForName(const QString &propertyName)
@@ -227,12 +228,9 @@ void TextureEditorQmlBackend::setup(const QmlObjectNode &selectedTextureNode, co
// anchors
m_backendAnchorBinding.setup(selectedTextureNode.modelNode());
- context()->setContextProperties(
- QVector<QQmlContext::PropertyPair>{
- {{"anchorBackend"}, QVariant::fromValue(&m_backendAnchorBinding)},
- {{"transaction"}, QVariant::fromValue(m_textureEditorTransaction.data())}
- }
- );
+ context()->setContextProperties(QVector<QQmlContext::PropertyPair>{
+ {{"anchorBackend"}, QVariant::fromValue(&m_backendAnchorBinding)},
+ {{"transaction"}, QVariant::fromValue(m_textureEditorTransaction.get())}});
contextObject()->setSpecificsUrl(qmlSpecificsFile);
contextObject()->setStateName(stateName);
diff --git a/src/plugins/qmldesigner/components/textureeditor/textureeditorqmlbackend.h b/src/plugins/qmldesigner/components/textureeditor/textureeditorqmlbackend.h
index b6d3fddf22..f69c46a569 100644
--- a/src/plugins/qmldesigner/components/textureeditor/textureeditorqmlbackend.h
+++ b/src/plugins/qmldesigner/components/textureeditor/textureeditorqmlbackend.h
@@ -7,8 +7,12 @@
#include "qmlanchorbindingproxy.h"
#include "qmlmodelnodeproxy.h"
+#include <utils/uniqueobjectptr.h>
+
#include <nodemetainfo.h>
+#include <memory>
+
class PropertyEditorValue;
QT_BEGIN_NAMESPACE
@@ -58,12 +62,15 @@ private:
TextureEditorView *textureEditor);
PropertyName auxNamePostFix(const PropertyName &propertyName);
- QQuickWidget *m_view = nullptr;
+ // to avoid a crash while destructing DesignerPropertyMap in the QQmlData
+ // this needs be destructed after m_quickWidget->engine() is destructed
+ DesignerPropertyMap m_backendValuesPropertyMap;
+
+ Utils::UniqueObjectPtr<QQuickWidget> m_quickWidget;
QmlAnchorBindingProxy m_backendAnchorBinding;
QmlModelNodeProxy m_backendModelNode;
- DesignerPropertyMap m_backendValuesPropertyMap;
- QScopedPointer<TextureEditorTransaction> m_textureEditorTransaction;
- QScopedPointer<TextureEditorContextObject> m_contextObject;
+ std::unique_ptr<TextureEditorTransaction> m_textureEditorTransaction;
+ std::unique_ptr<TextureEditorContextObject> m_contextObject;
AssetImageProvider *m_textureEditorImageProvider = nullptr;
};
diff --git a/src/plugins/qmldesigner/components/textureeditor/textureeditorview.cpp b/src/plugins/qmldesigner/components/textureeditor/textureeditorview.cpp
index 5de3730c97..a637431c4d 100644
--- a/src/plugins/qmldesigner/components/textureeditor/textureeditorview.cpp
+++ b/src/plugins/qmldesigner/components/textureeditor/textureeditorview.cpp
@@ -43,7 +43,6 @@
#include <QFileInfo>
#include <QQuickWidget>
#include <QQuickItem>
-#include <QScopedPointer>
#include <QStackedWidget>
#include <QShortcut>
#include <QTimer>
@@ -698,7 +697,8 @@ void TextureEditorView::selectedNodesChanged(const QList<ModelNode> &selectedNod
m_selectedModel = selectedNodeList.at(0);
bool hasValidSelection = QmlObjectNode(m_selectedModel).hasBindingProperty("materials");
- m_qmlBackEnd->contextObject()->setHasSingleModelSelection(hasValidSelection);
+ if (m_qmlBackEnd)
+ m_qmlBackEnd->contextObject()->setHasSingleModelSelection(hasValidSelection);
}
void TextureEditorView::currentStateChanged(const ModelNode &node)