QmlDesigner: Implement combobox to disable 3d editor

The combobox is in the toolbar of the form editor.
For pure 2D scenes the combobox is disabled.

Since auxiliaryData is persistent, this setting is
also persistent.

Change-Id: I1bf1d9acba7320b8503311ca785410df27d650db
Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io>
Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
This commit is contained in:
Thomas Hartmann
2019-10-15 18:14:13 +02:00
parent 3f5af7545d
commit e2e18ff625
10 changed files with 196 additions and 11 deletions

View File

@@ -231,6 +231,7 @@ extend_qtc_plugin(QmlDesigner
snapper.cpp snapper.h
snappinglinecreator.cpp snappinglinecreator.h
toolbox.cpp toolbox.h
option3daction.cpp option3daction.h
)
extend_qtc_plugin(QmlDesigner

View File

@@ -36,7 +36,8 @@ SOURCES += formeditoritem.cpp \
bindingindicatorgraphicsitem.cpp \
contentnoteditableindicator.cpp \
backgroundaction.cpp \
formeditortoolbutton.cpp
formeditortoolbutton.cpp \
option3daction.cpp
HEADERS += formeditorscene.h \
formeditorwidget.h \
@@ -75,6 +76,7 @@ HEADERS += formeditorscene.h \
bindingindicatorgraphicsitem.h \
contentnoteditableindicator.h \
backgroundaction.h \
formeditortoolbutton.h
formeditortoolbutton.h \
option3daction.h
RESOURCES += formeditor.qrc

View File

@@ -26,6 +26,7 @@
#include "formeditorview.h"
#include "selectiontool.h"
#include "movetool.h"
#include "option3daction.h"
#include "resizetool.h"
#include "dragtool.h"
#include "formeditorwidget.h"
@@ -45,6 +46,7 @@
#include <coreplugin/icore.h>
#include <utils/algorithm.h>
#include <utils/qtcassert.h>
#include <QDebug>
#include <QPair>
@@ -83,6 +85,7 @@ void FormEditorView::modelAttached(Model *model)
setupFormEditorItemTree(rootModelNode());
m_formEditorWidget->updateActions();
setupOption3DAction();
if (!rewriterView()->errors().isEmpty())
formEditorWidget()->showErrorMessageBox(rewriterView()->errors());
@@ -178,6 +181,22 @@ void FormEditorView::temporaryBlockView()
});
}
void FormEditorView::setupOption3DAction()
{
auto import = Import::createLibraryImport("QtQuick3D", "1.0");
auto action = m_formEditorWidget->option3DAction();
if (model() && model()->hasImport(import, true, true)) {
bool enabled = true;
if (rootModelNode().hasAuxiliaryData("3d-view"))
enabled = rootModelNode().auxiliaryData("3d-view").toBool();
action->set3DEnabled(enabled);
action->setEnabled(true);
} else {
action->set3DEnabled(false);
action->setEnabled(false);
}
}
void FormEditorView::nodeCreated(const ModelNode &node)
{
//If the node has source for components/custom parsers we ignore it.
@@ -567,6 +586,16 @@ void FormEditorView::exportAsImage()
m_formEditorWidget->exportAsImage(m_scene->rootFormEditorItem()->boundingRect());
}
void FormEditorView::toggle3DViewEnabled(bool enabled)
{
QTC_ASSERT(model(), return);
QTC_ASSERT(rootModelNode().isValid(), return);
if (enabled)
rootModelNode().removeAuxiliaryData("3d-view");
else
rootModelNode().setAuxiliaryData("3d-view", false);
}
QmlItemNode findRecursiveQmlItemNode(const QmlObjectNode &firstQmlObjectNode)
{
QmlObjectNode qmlObjectNode = firstQmlObjectNode;
@@ -629,6 +658,8 @@ void FormEditorView::delayedReset()
m_scene->clearFormEditorItems();
if (isAttached() && QmlItemNode::isValidQmlItemNode(rootModelNode()))
setupFormEditorItemTree(rootModelNode());
setupOption3DAction();
}
}

View File

@@ -118,6 +118,8 @@ public:
void exportAsImage();
void toggle3DViewEnabled(bool enabled);
protected:
void reset();
void delayedReset();
@@ -129,6 +131,7 @@ private: //functions
void hideNodeFromScene(const QmlItemNode &qmlItemNode);
void createFormEditorWidget();
void temporaryBlockView();
void setupOption3DAction();
private: //variables
QPointer<FormEditorWidget> m_formEditorWidget;

View File

@@ -34,24 +34,25 @@
#include <model.h>
#include <theme.h>
#include <QWheelEvent>
#include <QVBoxLayout>
#include <QActionGroup>
#include <toolbox.h>
#include <zoomaction.h>
#include <backgroundaction.h>
#include <formeditorgraphicsview.h>
#include <formeditorscene.h>
#include <formeditorview.h>
#include <lineeditaction.h>
#include <backgroundaction.h>
#include <option3daction.h>
#include <zoomaction.h>
#include <toolbox.h>
#include <coreplugin/icore.h>
#include <utils/fileutils.h>
#include <utils/utilsicons.h>
#include <QActionGroup>
#include <QFileDialog>
#include <QPainter>
#include <QVBoxLayout>
#include <QWheelEvent>
namespace QmlDesigner {
@@ -143,6 +144,15 @@ FormEditorWidget::FormEditorWidget(FormEditorView *view) :
upperActions.append(m_backgroundAction.data());
m_toolBox->addRightSideAction(m_backgroundAction.data());
m_option3DAction = new Option3DAction(m_toolActionGroup.data());
addAction(m_option3DAction.data());
upperActions.append(m_option3DAction.data());
m_toolBox->addRightSideAction(m_option3DAction.data());
connect(m_option3DAction.data(), &Option3DAction::enabledChanged,
m_formEditorView.data(), &FormEditorView::toggle3DViewEnabled);
connect(m_option3DAction.data(), &Option3DAction::activated,
this, &FormEditorWidget::resetNodeInstanceView);
m_zoomAction = new ZoomAction(m_toolActionGroup.data());
connect(m_zoomAction.data(), &ZoomAction::zoomLevelChanged,
this, &FormEditorWidget::setZoomLevel);
@@ -285,6 +295,11 @@ ZoomAction *FormEditorWidget::zoomAction() const
return m_zoomAction.data();
}
Option3DAction *FormEditorWidget::option3DAction() const
{
return m_option3DAction.data();
}
QAction *FormEditorWidget::showBoundingRectAction() const
{
return m_showBoundingRectAction.data();

View File

@@ -40,6 +40,7 @@ namespace QmlDesigner {
class ZoomAction;
class LineEditAction;
class BackgroundAction;
class Option3DAction;
class FormEditorView;
class FormEditorScene;
class FormEditorGraphicsView;
@@ -54,6 +55,7 @@ public:
FormEditorWidget(FormEditorView *view);
ZoomAction *zoomAction() const;
Option3DAction *option3DAction() const;
QAction *showBoundingRectAction() const;
QAction *snappingAction() const;
QAction *snappingAndAnchoringAction() const;
@@ -112,6 +114,7 @@ private:
QPointer<LineEditAction> m_rootWidthAction;
QPointer<LineEditAction> m_rootHeightAction;
QPointer<BackgroundAction> m_backgroundAction;
QPointer<Option3DAction> m_option3DAction;
QPointer<QAction> m_resetAction;
QPointer<DocumentWarningWidget> m_documentErrorWidget;
};

View File

@@ -0,0 +1,66 @@
/****************************************************************************
**
** 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 "option3daction.h"
#include <QComboBox>
#include <QPainter>
namespace QmlDesigner {
Option3DAction::Option3DAction(QObject *parent) :
QWidgetAction(parent)
{
}
void Option3DAction::set3DEnabled(bool enabled)
{
m_comboBox->setCurrentIndex(enabled ? 1 : 0);
}
QWidget *Option3DAction::createWidget(QWidget *parent)
{
m_comboBox = new QComboBox(parent);
m_comboBox->setFixedWidth(82);
m_comboBox->addItem(tr("2D"));
m_comboBox->addItem(tr("2D/3D"));
m_comboBox->setCurrentIndex(0);
connect(m_comboBox, QOverload<int>::of(&QComboBox::currentIndexChanged),
this, [this](){
emit enabledChanged(m_comboBox->currentIndex() != 0);
});
connect(m_comboBox, QOverload<int>::of(&QComboBox::activated),
this, [this](){
emit activated();
});
m_comboBox->setProperty("hideborder", true);
m_comboBox->setToolTip(tr("Enable/Disable 3D edit mode."));
return m_comboBox;
}
} // namespace QmlDesigner

View File

@@ -0,0 +1,52 @@
/****************************************************************************
**
** 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 <QWidgetAction>
QT_FORWARD_DECLARE_CLASS(QComboBox)
namespace QmlDesigner {
class Option3DAction : public QWidgetAction
{
Q_OBJECT
public:
explicit Option3DAction(QObject *parent);
void set3DEnabled(bool enabled);
signals:
void enabledChanged(bool enabled);
void activated();
protected:
QWidget *createWidget(QWidget *parent) override;
private:
QComboBox *m_comboBox = nullptr;
};
} // namespace QmlDesigner

View File

@@ -459,18 +459,28 @@ QProcessEnvironment PuppetCreator::processEnvironment() const
if (!m_qrcMapping.isEmpty()) {
environment.set("QMLDESIGNER_RC_PATHS", m_qrcMapping);
}
AbstractView *view = nullptr;
#ifndef QMLDESIGNER_TEST
QmlDesignerPlugin::instance()->viewManager().nodeInstanceView()->emitCustomNotification("PuppetStatus", {}, {QVariant(m_qrcMapping)});
view = QmlDesignerPlugin::instance()->viewManager().nodeInstanceView();
view->emitCustomNotification("PuppetStatus", {}, {QVariant(m_qrcMapping)});
#endif
QStringList importPaths = m_model->importPaths();
QmlDesigner::Import import = QmlDesigner::Import::createLibraryImport("QtQuick3D", "1.0");
bool view3DEnabled = false;
if (m_model->hasImport(import, true, true))
if (view && m_model->hasImport(import, true, true)) {
if (view->rootModelNode().hasAuxiliaryData("3d-view"))
view3DEnabled = view->rootModelNode().auxiliaryData("3d-view").toBool();
else
view3DEnabled = true;
}
if (view3DEnabled)
environment.set("QMLDESIGNER_QUICK3D_MODE", "true");
/* For the fallback puppet we have to remove the path to the original qtbase plugins to avoid conflics */
if (m_availablePuppetType == FallbackPuppet)
filterOutQtBaseImportPath(&importPaths);

View File

@@ -505,6 +505,8 @@ Project {
"formeditor/toolbox.h",
"formeditor/formeditortoolbutton.cpp",
"formeditor/formeditortoolbutton.h",
"formeditor/option3daction.cpp",
"formeditor/option3daction.h",
"importmanager/importlabel.cpp",
"importmanager/importlabel.h",
"importmanager/importmanagercombobox.cpp",