Enable object selection in the 3D edit view

Clicking an object in the 3D object selection view, selects it in the
creator side. Multiselection (i.e. Ctrl+click) is not implemented yet.
Also selected object is not highlighted in the view yet.

Task-number: QDS-1124
Change-Id: I0b10162539ecedc40ed117896e385975c52b04a9
Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io>
This commit is contained in:
Mahmoud Badri
2019-10-23 15:40:55 +03:00
parent 9469432035
commit 3c78d4d74d
4 changed files with 24 additions and 2 deletions

View File

@@ -42,12 +42,23 @@ Window {
property alias showEditLight: editLightCheckbox.checked
property alias usePerspective: usePerspectiveCheckbox.checked
signal objectClicked(var object)
Rectangle {
id: sceneBg
color: "#FFFFFF"
anchors.fill: parent
focus: true
TapHandler { // check tapping/clicking an object in the scene
onTapped: {
var pickResult = editView.pick(eventPoint.scenePosition.x,
eventPoint.scenePosition.y);
if (pickResult.objectHit)
viewWindow.objectClicked(pickResult.objectHit);
}
}
View3D {
id: editView
anchors.fill: parent

View File

@@ -75,7 +75,7 @@ static QVariant objectToVariant(QObject *object)
return QVariant::fromValue(object);
}
static QObject *createEditView3D(QQmlEngine *engine)
QObject *Qt5InformationNodeInstanceServer::createEditView3D(QQmlEngine *engine)
{
QmlDesigner::Internal::CameraControlHelper *helper = new QmlDesigner::Internal::CameraControlHelper();
engine->rootContext()->setContextProperty("designStudioNativeCameraControlHelper", helper);
@@ -89,6 +89,8 @@ static QObject *createEditView3D(QQmlEngine *engine)
return nullptr;
}
QObject::connect(window, SIGNAL(objectClicked(QVariant)), this, SLOT(objectClicked(QVariant)));
//For macOS we have to use the 4.1 core profile
QSurfaceFormat surfaceFormat = window->requestedFormat();
surfaceFormat.setVersion(4, 1);
@@ -99,6 +101,11 @@ static QObject *createEditView3D(QQmlEngine *engine)
return window;
}
void Qt5InformationNodeInstanceServer::objectClicked(const QVariant &object) {
QObject *item = qobject_cast<QObject *>(object.value<QObject *>());
selectInstance(instanceForObject(item));
}
Qt5InformationNodeInstanceServer::Qt5InformationNodeInstanceServer(NodeInstanceClientInterface *nodeInstanceClient) :
Qt5NodeInstanceServer(nodeInstanceClient)
{

View File

@@ -44,6 +44,9 @@ public:
void removeSharedMemory(const RemoveSharedMemoryCommand &command) override;
void changeSelection(const ChangeSelectionCommand &command) override;
public slots:
void objectClicked(const QVariant &object);
protected:
void collectItemChangesAndSendChangeCommands() override;
void sendChildrenChangedCommand(const QList<ServerNodeInstance> &childList);
@@ -54,6 +57,7 @@ protected:
void modifyProperties(const QVector<InstancePropertyValueTriple> &properties);
private:
QObject *createEditView3D(QQmlEngine *engine);
void setup3DEditView(const QList<ServerNodeInstance> &instanceList);
QObject *findRootNodeOf3DViewport(const QList<ServerNodeInstance> &instanceList) const;

View File

@@ -1329,7 +1329,6 @@ void NodeInstanceView::childrenChanged(const ChildrenChangedCommand &command)
if (!model())
return;
QVector<ModelNode> childNodeVector;
foreach (qint32 instanceId, command.childrenInstances()) {
@@ -1396,6 +1395,7 @@ void NodeInstanceView::sendToken(const QString &token, int number, const QVector
void NodeInstanceView::selectionChanged(const ChangeSelectionCommand &command)
{
clearSelectedModelNodes();
foreach (const qint32 &instanceId, command.instanceIds()) {
if (hasModelNodeForInternalId(instanceId))
selectModelNode(modelNodeForInternalId(instanceId));