Persist option3daction state

- the selected option3daction state is persisted between sessions.
- option3daction state do not change to 2D anymore when there is no
3D view in the scene. It just becomes disabled.
- option3daction is enabled/disabled based on existence of Nodes
  not View3D
- some relevant tweaks and refactoring.

Task-number: QDS-1538
Change-Id: I27f6f00cf7840204af6fc0f033dcf55bdddc7ad4
Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io>
Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
This commit is contained in:
Mahmoud Badri
2020-01-28 16:02:16 +02:00
parent 7f5a67a927
commit 22b64369c0
10 changed files with 60 additions and 60 deletions

View File

@@ -95,12 +95,12 @@ void FormEditorView::modelAttached(Model *model)
m_formEditorWidget->option3DAction()->setEnabled(false);
if (!rewriterView()->errors().isEmpty())
formEditorWidget()->showErrorMessageBox(rewriterView()->errors());
m_formEditorWidget->showErrorMessageBox(rewriterView()->errors());
else
formEditorWidget()->hideErrorMessageBox();
m_formEditorWidget->hideErrorMessageBox();
if (!rewriterView()->warnings().isEmpty())
formEditorWidget()->showWarningMessageBox(rewriterView()->warnings());
m_formEditorWidget->showWarningMessageBox(rewriterView()->warnings());
}
@@ -201,36 +201,37 @@ void FormEditorView::createFormEditorWidget()
auto formEditorContext = new Internal::FormEditorContext(m_formEditorWidget.data());
Core::ICore::addContextObject(formEditorContext);
connect(formEditorWidget()->zoomAction(), &ZoomAction::zoomLevelChanged, [this]() {
connect(m_formEditorWidget->zoomAction(), &ZoomAction::zoomLevelChanged, [this]() {
m_currentTool->formEditorItemsChanged(scene()->allFormEditorItems());
});
connect(formEditorWidget()->showBoundingRectAction(), &QAction::toggled,
scene(), &FormEditorScene::setShowBoundingRects);
connect(m_formEditorWidget->showBoundingRectAction(), &QAction::toggled, scene(), &FormEditorScene::setShowBoundingRects);
connect(m_formEditorWidget->option3DAction(), &Option3DAction::enabledChanged, this, &FormEditorView::toggle3DViewEnabled);
connect(m_formEditorWidget->resetAction(), &QAction::triggered, this, &FormEditorView::resetNodeInstanceView);
}
void FormEditorView::temporaryBlockView()
{
formEditorWidget()->graphicsView()->setUpdatesEnabled(false);
m_formEditorWidget->graphicsView()->setUpdatesEnabled(false);
static auto timer = new QTimer(qApp);
timer->setSingleShot(true);
timer->start(1000);
connect(timer, &QTimer::timeout, this, [this]() {
formEditorWidget()->graphicsView()->setUpdatesEnabled(true);
m_formEditorWidget->graphicsView()->setUpdatesEnabled(true);
});
}
void FormEditorView::nodeCreated(const ModelNode &node)
{
//If the node has source for components/custom parsers we ignore it.
if (QmlItemNode::isValidQmlItemNode(node) && node.nodeSourceType() == ModelNode::NodeWithoutSource) { //only setup QmlItems
if (QmlItemNode::isValidQmlItemNode(node) && node.nodeSourceType() == ModelNode::NodeWithoutSource) //only setup QmlItems
setupFormEditorItemTree(QmlItemNode(node));
if (node.isSubclassOf("QtQuick3D.View3D"))
m_formEditorWidget->option3DAction()->setEnabled(true);
}
else if (QmlVisualNode::isFlowTransition(node))
setupFormEditorItemTree(QmlItemNode(node));
if (node.isSubclassOf("QtQuick3D.Node"))
m_formEditorWidget->option3DAction()->setEnabled(true);
}
void FormEditorView::modelAboutToBeDetached(Model *model)
@@ -263,15 +264,13 @@ void FormEditorView::nodeAboutToBeRemoved(const ModelNode &removedNode)
removeNodeFromScene(qmlItemNode);
const QList<ModelNode> views3D = rootModelNode().subModelNodesOfType("QtQuick3D.View3D");
const QList<ModelNode> nodes3D = rootModelNode().subModelNodesOfType("QtQuick3D.Node");
// if no more View3D(s) exist after the node removal, set option3DAction to 2D and disable it
bool hasView3D = views3D.size() > 1 || (views3D.size() == 1 && views3D[0] != removedNode);
if (!hasView3D) {
rootModelNode().removeAuxiliaryData("3d-view"); // this will cause option3DAction to select 2D option
// if no more 3D Nodes exist after the node removal, disable option3DAction
bool hasView3D = nodes3D.size() > 1 || (nodes3D.size() == 1 && nodes3D[0] != removedNode);
if (!hasView3D)
m_formEditorWidget->option3DAction()->setEnabled(false);
}
}
void FormEditorView::rootNodeTypeChanged(const QString &/*type*/, int /*majorVersion*/, int /*minorVersion*/)
{
@@ -396,16 +395,16 @@ void FormEditorView::bindingPropertiesChanged(const QList<BindingProperty> &prop
void FormEditorView::documentMessagesChanged(const QList<DocumentMessage> &errors, const QList<DocumentMessage> &)
{
if (!errors.isEmpty())
formEditorWidget()->showErrorMessageBox(errors);
m_formEditorWidget->showErrorMessageBox(errors);
else
formEditorWidget()->hideErrorMessageBox();
m_formEditorWidget->hideErrorMessageBox();
}
void FormEditorView::customNotification(const AbstractView * /*view*/, const QString &identifier, const QList<ModelNode> &/*nodeList*/, const QList<QVariant> &/*data*/)
{
if (identifier == QStringLiteral("puppet crashed"))
if (identifier == QLatin1String("puppet crashed"))
m_dragTool->clearMoveDelay();
if (identifier == QStringLiteral("reset QmlPuppet"))
if (identifier == QLatin1String("reset QmlPuppet"))
temporaryBlockView();
}
@@ -525,6 +524,7 @@ void FormEditorView::auxiliaryDataChanged(const ModelNode &node, const PropertyN
newNode.deselectNode();
}
} else if (name == "3d-view") {
DesignerSettings::setValue(DesignerSettingsKey::VIEW_3D_ACTIVE, data);
m_formEditorWidget->option3DAction()->set3DEnabled(data.toBool());
} else if (item.isFlowTransition() || item.isFlowItem() || item.isFlowActionArea()) {
FormEditorItem *editorItem = m_scene->itemForQmlItemNode(item);
@@ -660,12 +660,16 @@ void FormEditorView::toggle3DViewEnabled(bool enabled)
{
QTC_ASSERT(model(), return);
QTC_ASSERT(rootModelNode().isValid(), return);
if (enabled)
rootModelNode().setAuxiliaryData("3d-view", true);
else
rootModelNode().removeAuxiliaryData("3d-view");
nodeInstanceView()->enable3DView(enabled);
resetNodeInstanceView();
// TODO: the line below is not in use. It should replace the resetNodeInstanceView(); to have a clean API
// nodeInstanceView()->enable3DView(enabled);
}
QmlItemNode findRecursiveQmlItemNode(const QmlObjectNode &firstQmlObjectNode)
@@ -716,6 +720,12 @@ bool FormEditorView::isMoveToolAvailable() const
return true;
}
void FormEditorView::resetNodeInstanceView()
{
setCurrentStateNode(rootModelNode());
resetPuppet();
}
void FormEditorView::reset()
{
QTimer::singleShot(200, this, &FormEditorView::delayedReset);

View File

@@ -121,22 +121,20 @@ public:
void exportAsImage();
void toggle3DViewEnabled(bool enabled);
void setupOption3DAction();
protected:
void reset();
void delayedReset();
bool isMoveToolAvailable() const;
private: //functions
private:
void setupFormEditorItemTree(const QmlItemNode &qmlItemNode);
void removeNodeFromScene(const QmlItemNode &qmlItemNode);
void hideNodeFromScene(const QmlItemNode &qmlItemNode);
void createFormEditorWidget();
void temporaryBlockView();
void resetNodeInstanceView();
void toggle3DViewEnabled(bool enabled);
private: //variables
QPointer<FormEditorWidget> m_formEditorWidget;
QPointer<FormEditorScene> m_scene;
QList<AbstractCustomTool*> m_customToolList;

View File

@@ -148,10 +148,6 @@ FormEditorWidget::FormEditorWidget(FormEditorView *view) :
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,
@@ -164,7 +160,7 @@ FormEditorWidget::FormEditorWidget(FormEditorView *view) :
m_resetAction->setShortcut(Qt::Key_R);
m_resetAction->setShortcutContext(Qt::WidgetWithChildrenShortcut);
m_resetAction->setIcon(Utils::Icons::RESET_TOOLBAR.icon());
connect(m_resetAction.data(), &QAction::triggered, this, &FormEditorWidget::resetNodeInstanceView);
addAction(m_resetAction.data());
upperActions.append(m_resetAction.data());
m_toolBox->addRightSideAction(m_resetAction.data());
@@ -209,12 +205,6 @@ void FormEditorWidget::changeBackgound(const QColor &color)
m_graphicsView->activateColoredBackground(color);
}
void FormEditorWidget::resetNodeInstanceView()
{
m_formEditorView->setCurrentStateNode(m_formEditorView->rootModelNode());
m_formEditorView->resetPuppet();
}
void FormEditorWidget::wheelEvent(QWheelEvent *event)
{
if (event->modifiers().testFlag(Qt::ControlModifier)) {
@@ -299,6 +289,11 @@ Option3DAction *FormEditorWidget::option3DAction() const
return m_option3DAction.data();
}
QAction *FormEditorWidget::resetAction() const
{
return m_resetAction.data();
}
QAction *FormEditorWidget::showBoundingRectAction() const
{
return m_showBoundingRectAction.data();

View File

@@ -58,6 +58,7 @@ public:
QAction *showBoundingRectAction() const;
QAction *snappingAction() const;
QAction *snappingAndAnchoringAction() const;
QAction *resetAction() const;
void setScene(FormEditorScene *scene);
ToolBox *toolBox() const;
@@ -97,9 +98,7 @@ private:
void changeRootItemWidth(const QString &widthText);
void changeRootItemHeight(const QString &heightText);
void changeBackgound(const QColor &color);
void resetNodeInstanceView();
private:
QPointer<FormEditorView> m_formEditorView;
QPointer<FormEditorGraphicsView> m_graphicsView;
QPointer<ZoomAction> m_zoomAction;

View File

@@ -37,8 +37,11 @@ Option3DAction::Option3DAction(QObject *parent) :
void Option3DAction::set3DEnabled(bool enabled)
{
if (m_comboBox)
if (m_comboBox) {
m_comboBox->blockSignals(true);
m_comboBox->setCurrentIndex(enabled ? 1 : 0);
m_comboBox->blockSignals(false);
}
}
QWidget *Option3DAction::createWidget(QWidget *parent)
@@ -50,17 +53,13 @@ QWidget *Option3DAction::createWidget(QWidget *parent)
m_comboBox->addItem(tr("2D/3D"));
m_comboBox->setCurrentIndex(0);
connect(m_comboBox, QOverload<int>::of(&QComboBox::currentIndexChanged),
this, [this](){
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;
}

View File

@@ -41,7 +41,6 @@ public:
signals:
void enabledChanged(bool enabled);
void activated();
protected:
QWidget *createWidget(QWidget *parent) override;

View File

@@ -473,18 +473,16 @@ QProcessEnvironment PuppetCreator::processEnvironment() const
}
#ifndef QMLDESIGNER_TEST
AbstractView *view = nullptr;
view = QmlDesignerPlugin::instance()->viewManager().nodeInstanceView();
auto view = QmlDesignerPlugin::instance()->viewManager().nodeInstanceView();
view->emitCustomNotification("PuppetStatus", {}, {QVariant(m_qrcMapping)});
// set env var and aux data if 3d-view is enabled
QmlDesigner::Import import = QmlDesigner::Import::createLibraryImport("QtQuick3D", "1.0");
bool view3DEnabled = false;
if (m_model->hasImport(import, true, true))
view3DEnabled = view->rootModelNode().hasAuxiliaryData("3d-view");
if (view3DEnabled)
if (m_model->hasImport(import, true, true)
&& DesignerSettings::getValue(DesignerSettingsKey::VIEW_3D_ACTIVE).toBool()) {
view->rootModelNode().setAuxiliaryData("3d-view", true);
environment.set("QMLDESIGNER_QUICK3D_MODE", "true");
}
#endif
QStringList importPaths = m_model->importPaths();

View File

@@ -797,7 +797,7 @@ const QList<ModelNode> ModelNode::directSubModelNodesOfType(const TypeName &type
const QList<ModelNode> ModelNode::subModelNodesOfType(const TypeName &typeName) const
{
return Utils::filtered(allSubModelNodes(), [typeName](const ModelNode &node){
return node.metaInfo().isValid() && node.metaInfo().typeName() == typeName;
return node.metaInfo().isValid() && node.metaInfo().isSubclassOf(typeName);
});
}

View File

@@ -84,6 +84,7 @@ void DesignerSettings::fromSettings(QSettings *settings)
);
restoreValue(settings, DesignerSettingsKey::SIMPLE_COLOR_PALETTE_CONTENT, QStringList());
restoreValue(settings, DesignerSettingsKey::ALWAYS_DESIGN_MODE, true);
restoreValue(settings, DesignerSettingsKey::VIEW_3D_ACTIVE, false);
settings->endGroup();
settings->endGroup();

View File

@@ -67,6 +67,7 @@ const char STANDALONE_MODE[] = "StandAloneMode";
const char ENABLE_TIMELINEVIEW[] = "EnableTimelineView";
const char SIMPLE_COLOR_PALETTE_CONTENT[] = "SimpleColorPaletteContent";
const char ALWAYS_DESIGN_MODE[] = "AlwaysDesignMode";
const char VIEW_3D_ACTIVE[] = "View3DActive";
}
class DesignerSettings : public QHash<QByteArray, QVariant>