Implement DnD 3D objects from the item library to the EditView3D

Proof of concept drag and drop implementation. Basic functionality
working but needs polish.

Task-number: QDS-1132
Change-Id: Ie3b9e80de9a414c4955d6e38daf338045bc1e614
Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io>
Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
This commit is contained in:
Mahmoud Badri
2019-11-01 10:51:09 +02:00
parent 1d357f6b33
commit 5df7ad94ec
19 changed files with 194 additions and 1 deletions

View File

@@ -27,6 +27,7 @@ HEADERS += $$PWD/changeauxiliarycommand.h
HEADERS += $$PWD/removesharedmemorycommand.h
HEADERS += $$PWD/puppetalivecommand.h
HEADERS += $$PWD/changeselectioncommand.h
HEADERS += $$PWD/drop3dlibraryitemcommand.h
SOURCES += $$PWD/synchronizecommand.cpp
SOURCES += $$PWD/debugoutputcommand.cpp
@@ -55,3 +56,4 @@ SOURCES += $$PWD/changeauxiliarycommand.cpp
SOURCES += $$PWD/removesharedmemorycommand.cpp
SOURCES += $$PWD/puppetalivecommand.cpp
SOURCES += $$PWD/changeselectioncommand.cpp
SOURCES += $$PWD/drop3dlibraryitemcommand.cpp

View File

@@ -0,0 +1,56 @@
/****************************************************************************
**
** Copyright (C) 2019 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
****************************************************************************/
#include "drop3dlibraryitemcommand.h"
#include <QDataStream>
namespace QmlDesigner {
Drop3DLibraryItemCommand::Drop3DLibraryItemCommand(const QByteArray &itemData)
: m_itemData(itemData)
{
}
QDataStream &operator<<(QDataStream &out, const Drop3DLibraryItemCommand &command)
{
out << command.itemData();
return out;
}
QDataStream &operator>>(QDataStream &in, Drop3DLibraryItemCommand &command)
{
in >> command.m_itemData;
return in;
}
bool operator==(const Drop3DLibraryItemCommand &first, const Drop3DLibraryItemCommand &second)
{
return first.m_itemData == second.m_itemData;
}
} // namespace QmlDesigner

View File

@@ -0,0 +1,59 @@
/****************************************************************************
**
** Copyright (C) 2019 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
****************************************************************************/
#pragma once
#include <QVector>
#include <QDataStream>
#include <QMimeData>
#include "instancecontainer.h"
namespace QmlDesigner {
class Drop3DLibraryItemCommand
{
friend QDataStream &operator>>(QDataStream &in, Drop3DLibraryItemCommand &command);
friend QDebug operator<<(QDebug debug, const Drop3DLibraryItemCommand &command);
friend bool operator==(const Drop3DLibraryItemCommand &first,
const Drop3DLibraryItemCommand &second);
public:
explicit Drop3DLibraryItemCommand(const QByteArray &itemData);
Drop3DLibraryItemCommand() = default;
QByteArray itemData() const { return m_itemData; }
private:
QByteArray m_itemData;
};
QDataStream &operator<<(QDataStream &out, const Drop3DLibraryItemCommand &command);
QDataStream &operator>>(QDataStream &in, Drop3DLibraryItemCommand &command);
bool operator==(const Drop3DLibraryItemCommand &first, const Drop3DLibraryItemCommand &second);
} // namespace QmlDesigner
Q_DECLARE_METATYPE(QmlDesigner::Drop3DLibraryItemCommand)

View File

@@ -68,6 +68,7 @@
#include "debugoutputcommand.h"
#include "puppetalivecommand.h"
#include "changeselectioncommand.h"
#include "drop3dlibraryitemcommand.h"
namespace QmlDesigner {
@@ -139,6 +140,7 @@ bool compareCommands(const QVariant &command, const QVariant &controlCommand)
static const int tokenCommandType = QMetaType::type("TokenCommand");
static const int debugOutputCommandType = QMetaType::type("DebugOutputCommand");
static const int changeSelectionCommandType = QMetaType::type("ChangeSelectionCommand");
static const int drop3DLibraryItemCommandType = QMetaType::type("Drop3DLibraryItemCommand");
if (command.userType() == controlCommand.userType()) {
if (command.userType() == informationChangedCommandType)
@@ -163,6 +165,8 @@ bool compareCommands(const QVariant &command, const QVariant &controlCommand)
return command.value<DebugOutputCommand>() == controlCommand.value<DebugOutputCommand>();
else if (command.userType() == changeSelectionCommandType)
return command.value<ChangeSelectionCommand>() == controlCommand.value<ChangeSelectionCommand>();
else if (command.userType() == drop3DLibraryItemCommandType)
return command.value<Drop3DLibraryItemCommand>() == controlCommand.value<Drop3DLibraryItemCommand>();
}
return false;
@@ -250,6 +254,11 @@ void NodeInstanceClientProxy::selectionChanged(const ChangeSelectionCommand &com
writeCommand(QVariant::fromValue(command));
}
void NodeInstanceClientProxy::library3DItemDropped(const Drop3DLibraryItemCommand &command)
{
writeCommand(QVariant::fromValue(command));
}
void NodeInstanceClientProxy::flush()
{
}

View File

@@ -57,6 +57,7 @@ class ChangeStateCommand;
class ChangeNodeSourceCommand;
class EndPuppetCommand;
class ChangeSelectionCommand;
class Drop3DLibraryItemCommand;
class NodeInstanceClientProxy : public QObject, public NodeInstanceClientInterface
{
@@ -76,6 +77,7 @@ public:
void debugOutput(const DebugOutputCommand &command) override;
void puppetAlive(const PuppetAliveCommand &command);
void selectionChanged(const ChangeSelectionCommand &command) override;
void library3DItemDropped(const Drop3DLibraryItemCommand &command) override;
void flush() override;
void synchronizeWithClientProcess() override;

View File

@@ -41,6 +41,7 @@ class RemoveSharedMemoryCommand;
class DebugOutputCommand;
class PuppetAliveCommand;
class ChangeSelectionCommand;
class Drop3DLibraryItemCommand;
class NodeInstanceClientInterface
{
@@ -55,6 +56,7 @@ public:
virtual void token(const TokenCommand &command) = 0;
virtual void debugOutput(const DebugOutputCommand &command) = 0;
virtual void selectionChanged(const ChangeSelectionCommand &command) = 0;
virtual void library3DItemDropped(const Drop3DLibraryItemCommand &command) = 0;
virtual void flush() {}
virtual void synchronizeWithClientProcess() {}

View File

@@ -46,6 +46,7 @@
#include "addimportcontainer.h"
#include "changenodesourcecommand.h"
#include "changeselectioncommand.h"
#include "drop3dlibraryitemcommand.h"
#include "informationchangedcommand.h"
#include "pixmapchangedcommand.h"
@@ -107,6 +108,9 @@ void NodeInstanceServerInterface::registerCommands()
qRegisterMetaType<ChangeSelectionCommand>("ChangeSelectionCommand");
qRegisterMetaTypeStreamOperators<ChangeSelectionCommand>("ChangeSelectionCommand");
qRegisterMetaType<Drop3DLibraryItemCommand>("Drop3DLibraryItemCommand");
qRegisterMetaTypeStreamOperators<Drop3DLibraryItemCommand>("Drop3DLibraryItemCommand");
qRegisterMetaType<RemovePropertiesCommand>("RemovePropertiesCommand");
qRegisterMetaTypeStreamOperators<RemovePropertiesCommand>("RemovePropertiesCommand");

View File

@@ -161,6 +161,10 @@ Window {
}
}
DropArea {
anchors.fill: parent
}
View3D {
id: editView
anchors.fill: parent

View File

@@ -67,6 +67,7 @@
#include <tokencommand.h>
#include <removesharedmemorycommand.h>
#include <changeselectioncommand.h>
#include <drop3dlibraryitemcommand.h>
#include <QDebug>
#include <QQmlEngine>
@@ -1171,6 +1172,11 @@ ChangeSelectionCommand NodeInstanceServer::createChangeSelectionCommand(const QL
return ChangeSelectionCommand(idVector);
}
Drop3DLibraryItemCommand NodeInstanceServer::createDrop3DLibraryItemCommand(const QByteArray &itemData)
{
return Drop3DLibraryItemCommand(itemData);
}
ValuesChangedCommand NodeInstanceServer::createValuesChangedCommand(const QVector<InstancePropertyPair> &propertyList) const
{
QVector<PropertyValueContainer> valueVector;

View File

@@ -70,6 +70,7 @@ class AddImportContainer;
class MockupTypeContainer;
class IdContainer;
class ChangeSelectionCommand;
class Drop3DLibraryItemCommand;
namespace Internal {
class ChildrenChangeEventFilter;
@@ -180,6 +181,7 @@ protected:
ChildrenChangedCommand createChildrenChangedCommand(const ServerNodeInstance &parentInstance, const QList<ServerNodeInstance> &instanceList) const;
ComponentCompletedCommand createComponentCompletedCommand(const QList<ServerNodeInstance> &instanceList);
ChangeSelectionCommand createChangeSelectionCommand(const QList<ServerNodeInstance> &instanceList);
Drop3DLibraryItemCommand createDrop3DLibraryItemCommand(const QByteArray &itemData);
void addChangedProperty(const InstancePropertyPair &property);

View File

@@ -27,6 +27,8 @@
#include <QQuickItem>
#include <QQuickView>
#include <QDropEvent>
#include <QMimeData>
#include "servernodeinstance.h"
#include "childrenchangeeventfilter.h"
@@ -57,6 +59,7 @@
#include "removesharedmemorycommand.h"
#include "changeselectioncommand.h"
#include "objectnodeinstance.h"
#include <drop3dlibraryitemcommand.h>
#include "dummycontextobject.h"
#include "../editor3d/cameracontrolhelper.h"
@@ -79,6 +82,25 @@ static QVariant objectToVariant(QObject *object)
return QVariant::fromValue(object);
}
bool Qt5InformationNodeInstanceServer::eventFilter(QObject *, QEvent *event)
{
switch (event->type()) {
case QEvent::Drop: {
QDropEvent *dropEvent = static_cast<QDropEvent *>(event);
QByteArray data = dropEvent->mimeData()->data(
QStringLiteral("application/vnd.bauhaus.itemlibraryinfo"));
if (!data.isEmpty())
nodeInstanceClient()->library3DItemDropped(createDrop3DLibraryItemCommand(data));
} break;
default:
break;
}
return false;
}
QObject *Qt5InformationNodeInstanceServer::createEditView3D(QQmlEngine *engine)
{
auto helper = new QmlDesigner::Internal::CameraControlHelper();
@@ -98,6 +120,7 @@ QObject *Qt5InformationNodeInstanceServer::createEditView3D(QQmlEngine *engine)
return nullptr;
}
window->installEventFilter(this);
QObject::connect(window, SIGNAL(objectClicked(QVariant)), this, SLOT(objectClicked(QVariant)));
QObject::connect(window, SIGNAL(commitObjectProperty(QVariant, QVariant)),
this, SLOT(handleObjectPropertyCommit(QVariant, QVariant)));

View File

@@ -57,6 +57,7 @@ private slots:
protected:
void collectItemChangesAndSendChangeCommands() override;
bool eventFilter(QObject *obj, QEvent *event) override;
void sendChildrenChangedCommand(const QList<ServerNodeInstance> &childList);
void sendTokenBack();
bool isDirtyRecursiveForNonInstanceItems(QQuickItem *item) const;

View File

@@ -139,6 +139,7 @@ extend_qtc_plugin(QmlDesigner
tokencommand.cpp tokencommand.h
valueschangedcommand.cpp valueschangedcommand.h
changeselectioncommand.cpp changeselectioncommand.h
drop3dlibraryitemcommand.cpp drop3dlibraryitemcommand.h
)
extend_qtc_plugin(QmlDesigner

View File

@@ -137,6 +137,7 @@ public:
void sendToken(const QString &token, int number, const QVector<ModelNode> &nodeVector);
void selectionChanged(const ChangeSelectionCommand &command) override;
void library3DItemDropped(const Drop3DLibraryItemCommand &command) override;
void selectedNodesChanged(const QList<ModelNode> &selectedNodeList,
const QList<ModelNode> &lastSelectedNodeList) override;

View File

@@ -42,6 +42,7 @@
#include <completecomponentcommand.h>
#include <changenodesourcecommand.h>
#include <changeselectioncommand.h>
#include <drop3dlibraryitemcommand.h>
#include <informationchangedcommand.h>
#include <pixmapchangedcommand.h>
@@ -281,6 +282,7 @@ void NodeInstanceServerProxy::dispatchCommand(const QVariant &command, PuppetStr
static const int debugOutputCommandType = QMetaType::type("DebugOutputCommand");
static const int puppetAliveCommandType = QMetaType::type("PuppetAliveCommand");
static const int changeSelectionCommandType = QMetaType::type("ChangeSelectionCommand");
static const int drop3DLibraryItemCommandType = QMetaType::type("Drop3DLibraryItemCommand");
if (m_destructing)
return;
@@ -306,6 +308,8 @@ void NodeInstanceServerProxy::dispatchCommand(const QVariant &command, PuppetStr
nodeInstanceClient()->debugOutput(command.value<DebugOutputCommand>());
} else if (command.userType() == changeSelectionCommandType) {
nodeInstanceClient()->selectionChanged(command.value<ChangeSelectionCommand>());
} else if (command.userType() == drop3DLibraryItemCommandType) {
nodeInstanceClient()->library3DItemDropped(command.value<Drop3DLibraryItemCommand>());
} else if (command.userType() == puppetAliveCommandType) {
puppetAlive(puppetStreamType);
} else if (command.userType() == synchronizeCommandType) {

View File

@@ -41,6 +41,7 @@
#include "qmlstate.h"
#include "qmltimeline.h"
#include "qmltimelinekeyframegroup.h"
#include "qmlvisualnode.h"
#include "createscenecommand.h"
#include "createinstancescommand.h"
@@ -52,6 +53,7 @@
#include "changebindingscommand.h"
#include "changeidscommand.h"
#include "changeselectioncommand.h"
#include "drop3dlibraryitemcommand.h"
#include "changenodesourcecommand.h"
#include "removeinstancescommand.h"
#include "removepropertiescommand.h"
@@ -66,7 +68,6 @@
#include "tokencommand.h"
#include "removesharedmemorycommand.h"
#include "debugoutputcommand.h"
#include "nodeinstanceserverproxy.h"
#include <utils/algorithm.h>
@@ -1439,6 +1440,17 @@ void NodeInstanceView::selectionChanged(const ChangeSelectionCommand &command)
selectModelNode(modelNodeForInternalId(instanceId));
}
}
void NodeInstanceView::library3DItemDropped(const Drop3DLibraryItemCommand &command)
{
QDataStream stream(command.itemData());
ItemLibraryEntry itemLibraryEntry;
stream >> itemLibraryEntry;
if (itemLibraryEntry.category() != "Qt Quick 3D")
return;
QmlVisualNode::createQmlVisualNode(this, itemLibraryEntry, {});
}
void NodeInstanceView::selectedNodesChanged(const QList<ModelNode> &selectedNodeList,
const QList<ModelNode> & /*lastSelectedNodeList*/)

View File

@@ -169,6 +169,8 @@ Project {
"commands/valueschangedcommand.h",
"commands/changeselectioncommand.cpp",
"commands/changeselectioncommand.h",
"commands/drop3dlibraryitemcommand.cpp",
"commands/drop3dlibraryitemcommand.h",
"container/addimportcontainer.cpp",
"container/addimportcontainer.h",
"container/idcontainer.cpp",

View File

@@ -45,6 +45,7 @@ extend_qtc_executable(qml2puppet
synchronizecommand.cpp synchronizecommand.h
tokencommand.cpp tokencommand.h
changeselectioncommand.cpp changeselectioncommand.h
drop3dlibraryitemcommand.cpp drop3dlibraryitemcommand.h
valueschangedcommand.cpp
)

View File

@@ -95,6 +95,8 @@ QtcTool {
"commands/valueschangedcommand.h",
"commands/changeselectioncommand.cpp",
"commands/changeselectioncommand.h",
"commands/drop3dlibraryitemcommand.cpp",
"commands/drop3dlibraryitemcommand.h",
"container/addimportcontainer.cpp",
"container/addimportcontainer.h",
"container/idcontainer.cpp",