QmlDesigner: crash when dragging an effect twice to component in 2D

When an effect is dragged twice, same effect or other effect it caused
QDS to crash, in layer mode the effect is replaced,
otherwise effect is added upon previous effect

Task-number: QDS-8172
Change-Id: I2a3682b21492de0d0cc62bce9bd2965cedfbc826
Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io>
Reviewed-by: Mahmoud Badri <mahmoud.badri@qt.io>
This commit is contained in:
Amr Essam
2022-11-11 10:07:53 +02:00
committed by amr.elsayed
parent 8bb3c8f923
commit e3e5524f88
3 changed files with 11 additions and 15 deletions

View File

@@ -230,8 +230,8 @@ void DragTool::dropEvent(const QList<QGraphicsItem *> &itemList, QGraphicsSceneD
QString effectPath; QString effectPath;
const QStringList assetPaths = QString::fromUtf8(event->mimeData() const QStringList assetPaths = QString::fromUtf8(event->mimeData()
->data(Constants::MIME_TYPE_ASSETS)).split(','); ->data(Constants::MIME_TYPE_ASSETS)).split(',');
for (auto &path : assetPaths) { for (const QString &path : assetPaths) {
auto assetType = AssetsLibraryWidget::getAssetTypeAndData(path).first; const QString assetType = AssetsLibraryWidget::getAssetTypeAndData(path).first;
if (assetType == Constants::MIME_TYPE_ASSET_EFFECT) { if (assetType == Constants::MIME_TYPE_ASSET_EFFECT) {
effectPath = path; effectPath = path;
break; break;
@@ -266,8 +266,7 @@ void DragTool::dropEvent(const QList<QGraphicsItem *> &itemList, QGraphicsSceneD
return; return;
} }
QmlItemNode effectNode = QmlItemNode:: QmlItemNode::createQmlItemNodeForEffect(view(), parentQmlItemNode, effectName);
createQmlItemNodeForEffect(view(), parentQmlItemNode, effectName);
view()->setSelectedModelNodes({parentQmlItemNode}); view()->setSelectedModelNodes({parentQmlItemNode});
view()->resetPuppet(); view()->resetPuppet();

View File

@@ -60,7 +60,7 @@ public:
const QPointF &position, const QPointF &position,
NodeAbstractProperty parentproperty, NodeAbstractProperty parentproperty,
bool executeInTransaction = true); bool executeInTransaction = true);
static QmlItemNode createQmlItemNodeForEffect(AbstractView *view, static void createQmlItemNodeForEffect(AbstractView *view,
const QmlItemNode &parentNode, const QmlItemNode &parentNode,
const QString &effectName); const QString &effectName);
QList<QmlItemNode> children() const; QList<QmlItemNode> children() const;

View File

@@ -5,6 +5,7 @@
#include <metainfo.h> #include <metainfo.h>
#include "nodelistproperty.h" #include "nodelistproperty.h"
#include "nodehints.h" #include "nodehints.h"
#include "nodeproperty.h"
#include "variantproperty.h" #include "variantproperty.h"
#include "bindingproperty.h" #include "bindingproperty.h"
#include "qmlanchors.h" #include "qmlanchors.h"
@@ -161,7 +162,7 @@ static bool useLayerEffect()
return settings->value(layerEffectEntry, true).toBool(); return settings->value(layerEffectEntry, true).toBool();
} }
QmlItemNode QmlItemNode::createQmlItemNodeForEffect(AbstractView *view, void QmlItemNode::createQmlItemNodeForEffect(AbstractView *view,
const QmlItemNode &parentNode, const QmlItemNode &parentNode,
const QString &effectName) const QString &effectName)
{ {
@@ -174,7 +175,7 @@ QmlItemNode QmlItemNode::createQmlItemNodeForEffect(AbstractView *view,
if (!view->model()->hasImport(import, true, true)) if (!view->model()->hasImport(import, true, true))
view->model()->changeImports({import}, {}); view->model()->changeImports({import}, {});
} catch (const Exception &) { } catch (const Exception &) {
QTC_ASSERT(false, return QmlItemNode()); QTC_ASSERT(false, return);
} }
TypeName type(effectName.toUtf8()); TypeName type(effectName.toUtf8());
@@ -190,10 +191,6 @@ QmlItemNode QmlItemNode::createQmlItemNodeForEffect(AbstractView *view,
} else { } else {
parentNode.modelNode().variantProperty("layer.enabled").setValue(true); parentNode.modelNode().variantProperty("layer.enabled").setValue(true);
} }
QTC_ASSERT(newQmlItemNode.isValid(), return QmlItemNode());
return newQmlItemNode;
} }
bool QmlItemNode::isValid() const bool QmlItemNode::isValid() const