forked from qt-creator/qt-creator
QmlDesigner: Introduce QmlVisualNode and Qml3DNode
We have to support QQuick3DNodes for the timeline and states editor. QmlVisualNode aggregates the shared properties between QQuickItem and QQuick3DNodes. Both have states and are visual nodes shown in the navigator. Task-number: QDS-1102 Change-Id: Iab8c20921012bb751caeafb1c2ee91c0d8922b2e Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io> Reviewed-by: Henning Gründl <henning.gruendl@qt.io> Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
This commit is contained in:
@@ -425,6 +425,8 @@ extend_qtc_plugin(QmlDesigner
|
||||
include/qmlchangeset.h
|
||||
include/qmldesignercorelib_global.h
|
||||
include/qmlitemnode.h
|
||||
include/qmlvisualnode.h
|
||||
include/qml3dnode.h
|
||||
include/qmlmodelnodefacade.h
|
||||
include/qmlobjectnode.h
|
||||
include/qmlstate.h
|
||||
@@ -493,6 +495,8 @@ extend_qtc_plugin(QmlDesigner
|
||||
model/qmlanchors.cpp
|
||||
model/qmlchangeset.cpp
|
||||
model/qmlitemnode.cpp
|
||||
model/qmlvisualnode.h
|
||||
model/qml3dnode.h
|
||||
model/qmlmodelnodefacade.cpp
|
||||
model/qmlobjectnode.cpp
|
||||
model/qmlstate.cpp
|
||||
|
@@ -238,7 +238,7 @@ void TimelineAnimationForm::populateStateComboBox()
|
||||
return;
|
||||
QmlObjectNode rootNode = QmlObjectNode(m_animation.view()->rootModelNode());
|
||||
if (rootNode.isValid() && rootNode.modelNode().hasId()) {
|
||||
for (const QmlModelState &state : QmlItemNode(rootNode).states().allStates()) {
|
||||
for (const QmlModelState &state : QmlVisualNode(rootNode).states().allStates()) {
|
||||
ui->transitionToState
|
||||
->addItem(state.modelNode().variantProperty("name").value().toString(),
|
||||
QVariant::fromValue<ModelNode>(state.modelNode()));
|
||||
|
@@ -29,7 +29,7 @@
|
||||
|
||||
#include <modelnode.h>
|
||||
#include <variantproperty.h>
|
||||
#include <qmlitemnode.h>
|
||||
#include <qmlvisualnode.h>
|
||||
|
||||
#include <utils/qtcassert.h>
|
||||
|
||||
@@ -152,7 +152,7 @@ void TimelineSettingsModel::resetModel()
|
||||
if (timelineView()->isAttached() && timelineView()->rootModelNode().hasId()) {
|
||||
addState(ModelNode());
|
||||
for (const QmlModelState &state :
|
||||
QmlItemNode(timelineView()->rootModelNode()).states().allStates())
|
||||
QmlVisualNode(timelineView()->rootModelNode()).states().allStates())
|
||||
addState(state);
|
||||
}
|
||||
|
||||
|
@@ -500,7 +500,7 @@ QmlModelState TimelineView::stateForTimeline(const QmlTimeline &timeline)
|
||||
return QmlModelState(rootModelNode());
|
||||
}
|
||||
|
||||
for (const QmlModelState &state : QmlItemNode(rootModelNode()).states().allStates()) {
|
||||
for (const QmlModelState &state : QmlVisualNode(rootModelNode()).states().allStates()) {
|
||||
if (timelineForState(state) == timeline)
|
||||
return state;
|
||||
}
|
||||
|
@@ -61,6 +61,8 @@ SOURCES += $$PWD/model/abstractview.cpp \
|
||||
$$PWD/model/componenttextmodifier.cpp \
|
||||
$$PWD/model/textmodifier.cpp \
|
||||
$$PWD/model/qmlitemnode.cpp \
|
||||
$$PWD/model/qmlvisualnode.cpp \
|
||||
$$PWD/model/qml3dnode.cpp \
|
||||
$$PWD/model/qmlstate.cpp \
|
||||
$$PWD/model/qmlchangeset.cpp \
|
||||
$$PWD/model/qmlmodelnodefacade.cpp \
|
||||
@@ -134,6 +136,8 @@ HEADERS += $$PWD/include/qmldesignercorelib_global.h \
|
||||
$$PWD/model/modeltotextmerger.h \
|
||||
$$PWD/model/texttomodelmerger.h \
|
||||
$$PWD/include/qmlitemnode.h \
|
||||
$$PWD/model/qmlvisualnode.h \
|
||||
$$PWD/model/qml3dnode.h \
|
||||
$$PWD/include/qmlstate.h \
|
||||
$$PWD/include/qmlchangeset.h \
|
||||
$$PWD/include/qmlmodelnodefacade.h \
|
||||
|
59
src/plugins/qmldesigner/designercore/include/qml3dnode.h
Normal file
59
src/plugins/qmldesigner/designercore/include/qml3dnode.h
Normal 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 <qmldesignercorelib_global.h>
|
||||
#include <modelnode.h>
|
||||
#include "qmlobjectnode.h"
|
||||
#include "qmlstate.h"
|
||||
#include "qmlvisualnode.h"
|
||||
|
||||
#include <QStringList>
|
||||
#include <QRectF>
|
||||
#include <QTransform>
|
||||
|
||||
namespace QmlDesigner {
|
||||
|
||||
class QmlModelStateGroup;
|
||||
class QmlAnchors;
|
||||
class ItemLibraryEntry;
|
||||
|
||||
class QMLDESIGNERCORE_EXPORT Qml3DNode : public QmlVisualNode
|
||||
{
|
||||
friend class QmlAnchors;
|
||||
public:
|
||||
Qml3DNode() : QmlVisualNode() {}
|
||||
Qml3DNode(const ModelNode &modelNode) : QmlVisualNode(modelNode) {}
|
||||
bool isValid() const override;
|
||||
static bool isValidQml3DNode(const ModelNode &modelNode);
|
||||
};
|
||||
|
||||
QMLDESIGNERCORE_EXPORT uint qHash(const Qml3DNode &node);
|
||||
|
||||
QMLDESIGNERCORE_EXPORT QList<ModelNode> toModelNodeList(const QList<Qml3DNode> &fxItemNodeList);
|
||||
QMLDESIGNERCORE_EXPORT QList<Qml3DNode> toQml3DNodeList(const QList<ModelNode> &modelNodeList);
|
||||
|
||||
} //QmlDesigner
|
@@ -29,6 +29,7 @@
|
||||
#include <modelnode.h>
|
||||
#include "qmlobjectnode.h"
|
||||
#include "qmlstate.h"
|
||||
#include "qmlvisualnode.h"
|
||||
|
||||
#include <QStringList>
|
||||
#include <QRectF>
|
||||
@@ -40,15 +41,14 @@ class QmlModelStateGroup;
|
||||
class QmlAnchors;
|
||||
class ItemLibraryEntry;
|
||||
|
||||
class QMLDESIGNERCORE_EXPORT QmlItemNode : public QmlObjectNode
|
||||
class QMLDESIGNERCORE_EXPORT QmlItemNode : public QmlVisualNode
|
||||
{
|
||||
friend class QmlAnchors;
|
||||
public:
|
||||
QmlItemNode() : QmlObjectNode() {}
|
||||
QmlItemNode(const ModelNode &modelNode) : QmlObjectNode(modelNode) {}
|
||||
QmlItemNode() : QmlVisualNode() {}
|
||||
QmlItemNode(const ModelNode &modelNode) : QmlVisualNode(modelNode) {}
|
||||
bool isValid() const override;
|
||||
static bool isValidQmlItemNode(const ModelNode &modelNode);
|
||||
bool isRootNode() const;
|
||||
|
||||
static bool isItemOrWindow(const ModelNode &modelNode);
|
||||
|
||||
@@ -74,7 +74,6 @@ public:
|
||||
const QPointF &position,
|
||||
NodeAbstractProperty parentproperty);
|
||||
|
||||
QmlModelStateGroup states() const;
|
||||
QList<QmlItemNode> children() const;
|
||||
QList<QmlObjectNode> resources() const;
|
||||
QList<QmlObjectNode> allDirectSubNodes() const;
|
||||
@@ -131,29 +130,6 @@ public:
|
||||
|
||||
QMLDESIGNERCORE_EXPORT uint qHash(const QmlItemNode &node);
|
||||
|
||||
class QMLDESIGNERCORE_EXPORT QmlModelStateGroup
|
||||
{
|
||||
friend class QmlItemNode;
|
||||
friend class StatesEditorView;
|
||||
|
||||
public:
|
||||
|
||||
QmlModelStateGroup() : m_modelNode(ModelNode()) {}
|
||||
|
||||
ModelNode modelNode() const { return m_modelNode; }
|
||||
QStringList names() const;
|
||||
QList<QmlModelState> allStates() const;
|
||||
QmlModelState state(const QString &name) const;
|
||||
QmlModelState addState(const QString &name);
|
||||
void removeState(const QString &name);
|
||||
|
||||
protected:
|
||||
QmlModelStateGroup(const ModelNode &modelNode) : m_modelNode(modelNode) {}
|
||||
|
||||
private:
|
||||
ModelNode m_modelNode;
|
||||
};
|
||||
|
||||
QMLDESIGNERCORE_EXPORT QList<ModelNode> toModelNodeList(const QList<QmlItemNode> &fxItemNodeList);
|
||||
QMLDESIGNERCORE_EXPORT QList<QmlItemNode> toQmlItemNodeList(const QList<ModelNode> &modelNodeList);
|
||||
|
||||
|
96
src/plugins/qmldesigner/designercore/include/qmlvisualnode.h
Normal file
96
src/plugins/qmldesigner/designercore/include/qmlvisualnode.h
Normal file
@@ -0,0 +1,96 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** 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 <qmldesignercorelib_global.h>
|
||||
#include <modelnode.h>
|
||||
#include "qmlobjectnode.h"
|
||||
#include "qmlstate.h"
|
||||
|
||||
#include <QStringList>
|
||||
#include <QRectF>
|
||||
#include <QTransform>
|
||||
|
||||
namespace QmlDesigner {
|
||||
|
||||
class QmlModelStateGroup;
|
||||
class QmlAnchors;
|
||||
class ItemLibraryEntry;
|
||||
|
||||
class QMLDESIGNERCORE_EXPORT QmlVisualNode : public QmlObjectNode
|
||||
{
|
||||
friend class QmlAnchors;
|
||||
public:
|
||||
QmlVisualNode() : QmlObjectNode() {}
|
||||
QmlVisualNode(const ModelNode &modelNode) : QmlObjectNode(modelNode) {}
|
||||
bool isValid() const override;
|
||||
static bool isValidQmlVisualNode(const ModelNode &modelNode);
|
||||
bool isRootNode() const;
|
||||
|
||||
QmlModelStateGroup states() const;
|
||||
QList<QmlVisualNode> children() const;
|
||||
QList<QmlObjectNode> resources() const;
|
||||
QList<QmlObjectNode> allDirectSubNodes() const;
|
||||
|
||||
bool hasChildren() const;
|
||||
bool hasResources() const;
|
||||
|
||||
const QList<QmlVisualNode> allDirectSubModelNodes() const;
|
||||
const QList<QmlVisualNode> allSubModelNodes() const;
|
||||
bool hasAnySubModelNodes() const;
|
||||
|
||||
static bool isItemOr3DNode(const ModelNode &modelNode);
|
||||
};
|
||||
|
||||
QMLDESIGNERCORE_EXPORT uint qHash(const QmlItemNode &node);
|
||||
|
||||
class QMLDESIGNERCORE_EXPORT QmlModelStateGroup
|
||||
{
|
||||
friend class QmlVisualNode;
|
||||
friend class StatesEditorView;
|
||||
|
||||
public:
|
||||
|
||||
QmlModelStateGroup() : m_modelNode(ModelNode()) {}
|
||||
|
||||
ModelNode modelNode() const { return m_modelNode; }
|
||||
QStringList names() const;
|
||||
QList<QmlModelState> allStates() const;
|
||||
QmlModelState state(const QString &name) const;
|
||||
QmlModelState addState(const QString &name);
|
||||
void removeState(const QString &name);
|
||||
|
||||
protected:
|
||||
QmlModelStateGroup(const ModelNode &modelNode) : m_modelNode(modelNode) {}
|
||||
|
||||
private:
|
||||
ModelNode m_modelNode;
|
||||
};
|
||||
|
||||
QMLDESIGNERCORE_EXPORT QList<ModelNode> toModelNodeList(const QList<QmlItemNode> &fxItemNodeList);
|
||||
QMLDESIGNERCORE_EXPORT QList<QmlVisualNode> toQmlVisualNodeList(const QList<ModelNode> &modelNodeList);
|
||||
|
||||
} //QmlDesigner
|
83
src/plugins/qmldesigner/designercore/model/qml3dnode.cpp
Normal file
83
src/plugins/qmldesigner/designercore/model/qml3dnode.cpp
Normal file
@@ -0,0 +1,83 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** 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 "qml3dnode.h"
|
||||
#include <metainfo.h>
|
||||
#include "qmlchangeset.h"
|
||||
#include "nodelistproperty.h"
|
||||
#include "nodehints.h"
|
||||
#include "variantproperty.h"
|
||||
#include "bindingproperty.h"
|
||||
#include "qmlanchors.h"
|
||||
#include "invalidmodelnodeexception.h"
|
||||
#include "itemlibraryinfo.h"
|
||||
|
||||
#include "plaintexteditmodifier.h"
|
||||
#include "rewriterview.h"
|
||||
#include "modelmerger.h"
|
||||
#include "rewritingexception.h"
|
||||
|
||||
#include <QUrl>
|
||||
#include <QPlainTextEdit>
|
||||
#include <QFileInfo>
|
||||
#include <QDir>
|
||||
|
||||
namespace QmlDesigner {
|
||||
|
||||
bool Qml3DNode::isValid() const
|
||||
{
|
||||
return isValidQml3DNode(modelNode());
|
||||
}
|
||||
|
||||
bool Qml3DNode::isValidQml3DNode(const ModelNode &modelNode)
|
||||
{
|
||||
return isValidQmlObjectNode(modelNode)
|
||||
&& modelNode.metaInfo().isValid()
|
||||
&& (modelNode.metaInfo().isSubclassOf("QtQuick3D.Node"));
|
||||
}
|
||||
|
||||
QList<ModelNode> toModelNodeList(const QList<Qml3DNode> &qmlVisualNodeList)
|
||||
{
|
||||
QList<ModelNode> modelNodeList;
|
||||
|
||||
for (const Qml3DNode &qml3DNode : qmlVisualNodeList)
|
||||
modelNodeList.append(qml3DNode.modelNode());
|
||||
|
||||
return modelNodeList;
|
||||
}
|
||||
|
||||
QList<Qml3DNode> toQml3DNodeList(const QList<ModelNode> &modelNodeList)
|
||||
{
|
||||
QList<Qml3DNode> qml3DNodeList;
|
||||
|
||||
for (const ModelNode &modelNode : modelNodeList) {
|
||||
if (Qml3DNode::isValidQml3DNode(modelNode))
|
||||
qml3DNodeList.append(modelNode);
|
||||
}
|
||||
|
||||
return qml3DNodeList;
|
||||
}
|
||||
|
||||
} //QmlDesigner
|
@@ -216,39 +216,6 @@ bool QmlItemNode::isValidQmlItemNode(const ModelNode &modelNode)
|
||||
return isValidQmlObjectNode(modelNode) && modelNode.metaInfo().isValid() && isItemOrWindow(modelNode);
|
||||
}
|
||||
|
||||
bool QmlItemNode::isRootNode() const
|
||||
{
|
||||
return modelNode().isValid() && modelNode().isRootNode();
|
||||
}
|
||||
|
||||
QStringList QmlModelStateGroup::names() const
|
||||
{
|
||||
QStringList returnList;
|
||||
|
||||
if (!modelNode().isValid())
|
||||
throw new InvalidModelNodeException(__LINE__, __FUNCTION__, __FILE__);
|
||||
|
||||
if (modelNode().property("states").isNodeListProperty()) {
|
||||
foreach (const ModelNode &node, modelNode().nodeListProperty("states").toModelNodeList()) {
|
||||
if (QmlModelState::isValidQmlModelState(node))
|
||||
returnList.append(QmlModelState(node).name());
|
||||
}
|
||||
}
|
||||
return returnList;
|
||||
}
|
||||
|
||||
/**
|
||||
\brief Returns list of states (without 'base state').
|
||||
The list contains all states defined by this item.
|
||||
*/
|
||||
QmlModelStateGroup QmlItemNode::states() const
|
||||
{
|
||||
if (isValid())
|
||||
return QmlModelStateGroup(modelNode());
|
||||
else
|
||||
return QmlModelStateGroup();
|
||||
}
|
||||
|
||||
QList<QmlItemNode> QmlItemNode::children() const
|
||||
{
|
||||
QList<ModelNode> childrenList;
|
||||
@@ -492,62 +459,11 @@ QPixmap QmlItemNode::instanceBlurredRenderPixmap() const
|
||||
return nodeInstance().blurredRenderPixmap();
|
||||
}
|
||||
|
||||
QList<QmlModelState> QmlModelStateGroup::allStates() const
|
||||
{
|
||||
QList<QmlModelState> returnList;
|
||||
|
||||
if (!modelNode().isValid())
|
||||
throw new InvalidModelNodeException(__LINE__, __FUNCTION__, __FILE__);
|
||||
|
||||
if (modelNode().property("states").isNodeListProperty()) {
|
||||
foreach (const ModelNode &node, modelNode().nodeListProperty("states").toModelNodeList()) {
|
||||
if (QmlModelState::isValidQmlModelState(node))
|
||||
returnList.append(node);
|
||||
}
|
||||
}
|
||||
return returnList;
|
||||
}
|
||||
|
||||
uint qHash(const QmlItemNode &node)
|
||||
{
|
||||
return qHash(node.modelNode());
|
||||
}
|
||||
|
||||
QmlModelState QmlModelStateGroup::addState(const QString &name)
|
||||
{
|
||||
if (!modelNode().isValid())
|
||||
throw new InvalidModelNodeException(__LINE__, __FUNCTION__, __FILE__);
|
||||
|
||||
ModelNode newState = QmlModelState::createQmlState(
|
||||
modelNode().view(), {{PropertyName("name"), QVariant(name)}});
|
||||
modelNode().nodeListProperty("states").reparentHere(newState);
|
||||
|
||||
return newState;
|
||||
}
|
||||
|
||||
void QmlModelStateGroup::removeState(const QString &name)
|
||||
{
|
||||
if (!modelNode().isValid())
|
||||
throw new InvalidModelNodeException(__LINE__, __FUNCTION__, __FILE__);
|
||||
|
||||
if (state(name).isValid())
|
||||
state(name).modelNode().destroy();
|
||||
}
|
||||
|
||||
QmlModelState QmlModelStateGroup::state(const QString &name) const
|
||||
{
|
||||
if (!modelNode().isValid())
|
||||
throw new InvalidModelNodeException(__LINE__, __FUNCTION__, __FILE__);
|
||||
|
||||
if (modelNode().property("states").isNodeListProperty()) {
|
||||
foreach (const ModelNode &node, modelNode().nodeListProperty("states").toModelNodeList()) {
|
||||
if (QmlModelState(node).name() == name)
|
||||
return node;
|
||||
}
|
||||
}
|
||||
return QmlModelState();
|
||||
}
|
||||
|
||||
QList<ModelNode> toModelNodeList(const QList<QmlItemNode> &qmlItemNodeList)
|
||||
{
|
||||
QList<ModelNode> modelNodeList;
|
||||
|
@@ -442,20 +442,20 @@ QList<QmlModelStateOperation> QmlObjectNode::allAffectingStatesOperations() cons
|
||||
return returnList;
|
||||
}
|
||||
|
||||
static QList<QmlItemNode> allQmlItemsRecursive(const QmlItemNode &qmlItemNode)
|
||||
static QList<QmlVisualNode> allQmlVisualNodesRecursive(const QmlItemNode &qmlItemNode)
|
||||
{
|
||||
QList<QmlItemNode> qmlItemNodeList;
|
||||
QList<QmlVisualNode> qmlVisualNodeList;
|
||||
|
||||
if (qmlItemNode.isValid()) {
|
||||
qmlItemNodeList.append(qmlItemNode);
|
||||
qmlVisualNodeList.append(qmlItemNode);
|
||||
|
||||
foreach (const ModelNode &modelNode, qmlItemNode.modelNode().directSubModelNodes()) {
|
||||
if (QmlItemNode::isValidQmlItemNode(modelNode))
|
||||
qmlItemNodeList.append(allQmlItemsRecursive(modelNode));
|
||||
if (QmlVisualNode::isValidQmlVisualNode(modelNode))
|
||||
qmlVisualNodeList.append(allQmlVisualNodesRecursive(modelNode));
|
||||
}
|
||||
}
|
||||
|
||||
return qmlItemNodeList;
|
||||
return qmlVisualNodeList;
|
||||
}
|
||||
|
||||
QList<QmlModelState> QmlObjectNode::allDefinedStates() const
|
||||
@@ -465,14 +465,13 @@ QList<QmlModelState> QmlObjectNode::allDefinedStates() const
|
||||
|
||||
QList<QmlModelState> returnList;
|
||||
|
||||
QList<QmlItemNode> allQmlItems;
|
||||
QList<QmlVisualNode> allVisualNodes;
|
||||
|
||||
if (QmlItemNode::isValidQmlItemNode(view()->rootModelNode()))
|
||||
allQmlItems.append(allQmlItemsRecursive(view()->rootModelNode()));
|
||||
if (QmlVisualNode::isValidQmlVisualNode(view()->rootModelNode()))
|
||||
allVisualNodes.append(allQmlVisualNodesRecursive(view()->rootModelNode()));
|
||||
|
||||
foreach (const QmlItemNode &item, allQmlItems) {
|
||||
returnList.append(item.states().allStates());
|
||||
}
|
||||
for (const QmlVisualNode &node : qAsConst(allVisualNodes))
|
||||
returnList.append(node.states().allStates());
|
||||
|
||||
return returnList;
|
||||
}
|
||||
|
@@ -275,7 +275,7 @@ QmlModelState QmlModelState::duplicate(const QString &name) const
|
||||
|
||||
QmlModelStateGroup QmlModelState::stateGroup() const
|
||||
{
|
||||
QmlItemNode parentNode(modelNode().parentProperty().parentModelNode());
|
||||
QmlVisualNode parentNode(modelNode().parentProperty().parentModelNode());
|
||||
return parentNode.states();
|
||||
}
|
||||
|
||||
|
251
src/plugins/qmldesigner/designercore/model/qmlvisualnode.cpp
Normal file
251
src/plugins/qmldesigner/designercore/model/qmlvisualnode.cpp
Normal file
@@ -0,0 +1,251 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** 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 "qmlvisualnode.h"
|
||||
#include <metainfo.h>
|
||||
#include "qmlchangeset.h"
|
||||
#include "nodelistproperty.h"
|
||||
#include "nodehints.h"
|
||||
#include "variantproperty.h"
|
||||
#include "bindingproperty.h"
|
||||
#include "qmlanchors.h"
|
||||
#include "invalidmodelnodeexception.h"
|
||||
#include "itemlibraryinfo.h"
|
||||
|
||||
#include "plaintexteditmodifier.h"
|
||||
#include "rewriterview.h"
|
||||
#include "modelmerger.h"
|
||||
#include "rewritingexception.h"
|
||||
|
||||
#include <QUrl>
|
||||
#include <QPlainTextEdit>
|
||||
#include <QFileInfo>
|
||||
#include <QDir>
|
||||
|
||||
namespace QmlDesigner {
|
||||
|
||||
bool QmlVisualNode::isItemOr3DNode(const ModelNode &modelNode)
|
||||
{
|
||||
if (modelNode.metaInfo().isSubclassOf("QtQuick.Item"))
|
||||
return true;
|
||||
|
||||
if (modelNode.metaInfo().isSubclassOf("QtQuick3D.Node"))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool QmlVisualNode::isValid() const
|
||||
{
|
||||
return isValidQmlVisualNode(modelNode());
|
||||
}
|
||||
|
||||
bool QmlVisualNode::isValidQmlVisualNode(const ModelNode &modelNode)
|
||||
{
|
||||
return isValidQmlObjectNode(modelNode)
|
||||
&& modelNode.metaInfo().isValid()
|
||||
&& isItemOr3DNode(modelNode);
|
||||
}
|
||||
|
||||
bool QmlVisualNode::isRootNode() const
|
||||
{
|
||||
return modelNode().isValid() && modelNode().isRootNode();
|
||||
}
|
||||
|
||||
|
||||
QList<QmlVisualNode> QmlVisualNode::children() const
|
||||
{
|
||||
QList<ModelNode> childrenList;
|
||||
|
||||
if (isValid()) {
|
||||
|
||||
if (modelNode().hasNodeListProperty("children"))
|
||||
childrenList.append(modelNode().nodeListProperty("children").toModelNodeList());
|
||||
|
||||
if (modelNode().hasNodeListProperty("data")) {
|
||||
for (const ModelNode &node : modelNode().nodeListProperty("data").toModelNodeList()) {
|
||||
if (QmlVisualNode::isValidQmlVisualNode(node))
|
||||
childrenList.append(node);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return toQmlVisualNodeList(childrenList);
|
||||
}
|
||||
|
||||
QList<QmlObjectNode> QmlVisualNode::resources() const
|
||||
{
|
||||
QList<ModelNode> resourcesList;
|
||||
|
||||
if (isValid()) {
|
||||
|
||||
if (modelNode().hasNodeListProperty("resources"))
|
||||
resourcesList.append(modelNode().nodeListProperty("resources").toModelNodeList());
|
||||
|
||||
if (modelNode().hasNodeListProperty("data")) {
|
||||
for (const ModelNode &node : modelNode().nodeListProperty("data").toModelNodeList()) {
|
||||
if (!QmlItemNode::isValidQmlItemNode(node))
|
||||
resourcesList.append(node);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return toQmlObjectNodeList(resourcesList);
|
||||
}
|
||||
|
||||
QList<QmlObjectNode> QmlVisualNode::allDirectSubNodes() const
|
||||
{
|
||||
return toQmlObjectNodeList(modelNode().directSubModelNodes());
|
||||
}
|
||||
|
||||
bool QmlVisualNode::hasChildren() const
|
||||
{
|
||||
if (modelNode().hasNodeListProperty("children"))
|
||||
return true;
|
||||
|
||||
return !children().isEmpty();
|
||||
}
|
||||
|
||||
bool QmlVisualNode::hasResources() const
|
||||
{
|
||||
if (modelNode().hasNodeListProperty("resources"))
|
||||
return true;
|
||||
|
||||
return !resources().isEmpty();
|
||||
}
|
||||
|
||||
const QList<QmlVisualNode> QmlVisualNode::allDirectSubModelNodes() const
|
||||
{
|
||||
return toQmlVisualNodeList(modelNode().directSubModelNodes());
|
||||
}
|
||||
|
||||
const QList<QmlVisualNode> QmlVisualNode::allSubModelNodes() const
|
||||
{
|
||||
return toQmlVisualNodeList(modelNode().allSubModelNodes());
|
||||
}
|
||||
|
||||
bool QmlVisualNode::hasAnySubModelNodes() const
|
||||
{
|
||||
return modelNode().hasAnySubModelNodes();
|
||||
}
|
||||
|
||||
QmlModelStateGroup QmlVisualNode::states() const
|
||||
{
|
||||
if (isValid())
|
||||
return QmlModelStateGroup(modelNode());
|
||||
else
|
||||
return QmlModelStateGroup();
|
||||
}
|
||||
|
||||
QList<ModelNode> toModelNodeList(const QList<QmlVisualNode> &qmlVisualNodeList)
|
||||
{
|
||||
QList<ModelNode> modelNodeList;
|
||||
|
||||
for (const QmlVisualNode &QmlVisualNode : qmlVisualNodeList)
|
||||
modelNodeList.append(QmlVisualNode.modelNode());
|
||||
|
||||
return modelNodeList;
|
||||
}
|
||||
|
||||
QList<QmlVisualNode> toQmlVisualNodeList(const QList<ModelNode> &modelNodeList)
|
||||
{
|
||||
QList<QmlVisualNode> QmlVisualNodeList;
|
||||
|
||||
for (const ModelNode &modelNode : modelNodeList) {
|
||||
if (QmlVisualNode::isValidQmlVisualNode(modelNode))
|
||||
QmlVisualNodeList.append(modelNode);
|
||||
}
|
||||
|
||||
return QmlVisualNodeList;
|
||||
}
|
||||
|
||||
QStringList QmlModelStateGroup::names() const
|
||||
{
|
||||
QStringList returnList;
|
||||
|
||||
if (!modelNode().isValid())
|
||||
throw new InvalidModelNodeException(__LINE__, __FUNCTION__, __FILE__);
|
||||
|
||||
if (modelNode().property("states").isNodeListProperty()) {
|
||||
for (const ModelNode &node : modelNode().nodeListProperty("states").toModelNodeList()) {
|
||||
if (QmlModelState::isValidQmlModelState(node))
|
||||
returnList.append(QmlModelState(node).name());
|
||||
}
|
||||
}
|
||||
return returnList;
|
||||
}
|
||||
|
||||
QList<QmlModelState> QmlModelStateGroup::allStates() const
|
||||
{
|
||||
QList<QmlModelState> returnList;
|
||||
|
||||
if (!modelNode().isValid())
|
||||
throw new InvalidModelNodeException(__LINE__, __FUNCTION__, __FILE__);
|
||||
|
||||
if (modelNode().property("states").isNodeListProperty()) {
|
||||
for (const ModelNode &node : modelNode().nodeListProperty("states").toModelNodeList()) {
|
||||
if (QmlModelState::isValidQmlModelState(node))
|
||||
returnList.append(node);
|
||||
}
|
||||
}
|
||||
return returnList;
|
||||
}
|
||||
|
||||
QmlModelState QmlModelStateGroup::addState(const QString &name)
|
||||
{
|
||||
if (!modelNode().isValid())
|
||||
throw new InvalidModelNodeException(__LINE__, __FUNCTION__, __FILE__);
|
||||
|
||||
ModelNode newState = QmlModelState::createQmlState(
|
||||
modelNode().view(), {{PropertyName("name"), QVariant(name)}});
|
||||
modelNode().nodeListProperty("states").reparentHere(newState);
|
||||
|
||||
return newState;
|
||||
}
|
||||
|
||||
void QmlModelStateGroup::removeState(const QString &name)
|
||||
{
|
||||
if (!modelNode().isValid())
|
||||
throw new InvalidModelNodeException(__LINE__, __FUNCTION__, __FILE__);
|
||||
|
||||
if (state(name).isValid())
|
||||
state(name).modelNode().destroy();
|
||||
}
|
||||
|
||||
QmlModelState QmlModelStateGroup::state(const QString &name) const
|
||||
{
|
||||
if (!modelNode().isValid())
|
||||
throw new InvalidModelNodeException(__LINE__, __FUNCTION__, __FILE__);
|
||||
|
||||
if (modelNode().property("states").isNodeListProperty()) {
|
||||
for (const ModelNode &node : modelNode().nodeListProperty("states").toModelNodeList()) {
|
||||
if (QmlModelState(node).name() == name)
|
||||
return node;
|
||||
}
|
||||
}
|
||||
return QmlModelState();
|
||||
}
|
||||
|
||||
} //QmlDesigner
|
@@ -272,6 +272,8 @@ Project {
|
||||
"include/qmlanchors.h",
|
||||
"include/qmlchangeset.h",
|
||||
"include/qmlitemnode.h",
|
||||
"include/qmlvisualnode.h",
|
||||
"include/qml3dnode.h",
|
||||
"include/qmlmodelnodefacade.h",
|
||||
"include/qmlobjectnode.h",
|
||||
"include/qmlstate.h",
|
||||
@@ -346,6 +348,8 @@ Project {
|
||||
"model/qmlanchors.cpp",
|
||||
"model/qmlchangeset.cpp",
|
||||
"model/qmlitemnode.cpp",
|
||||
"model/qmlvisualnode.h",
|
||||
"model/qml3dnode.h",
|
||||
"model/qmlmodelnodefacade.cpp",
|
||||
"model/qmlobjectnode.cpp",
|
||||
"model/qmlstate.cpp",
|
||||
|
Reference in New Issue
Block a user