forked from qt-creator/qt-creator
QmlDesigner: Add default template to Component item in library
The default template includes an "Item" child node under the component. Also added "Component 3D" item that will have a "Node" child. Task-number: QDS-5308 Change-Id: I254f18a2ec7b623d8cd4a72e6e727d0d17a1a91d Reviewed-by: Mahmoud Badri <mahmoud.badri@qt.io> Reviewed-by: Samuel Ghinet <samuel.ghinet@qt.io> Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
This commit is contained in:
@@ -179,6 +179,8 @@ public:
|
||||
|
||||
void sanitizeModel();
|
||||
|
||||
void setAllowComponentRoot(bool allow);
|
||||
bool allowComponentRoot() const;
|
||||
signals:
|
||||
void modelInterfaceProjectUpdated();
|
||||
|
||||
@@ -221,6 +223,7 @@ private: //variables
|
||||
bool m_hasIncompleteTypeInformation = false;
|
||||
bool m_restoringAuxData = false;
|
||||
bool m_modelAttachPending = false;
|
||||
bool m_allowComponentRoot = false;
|
||||
|
||||
mutable QHash<int, ModelNode> m_canonicalIntModelNode;
|
||||
mutable QHash<ModelNode, int> m_canonicalModelNodeInt;
|
||||
|
||||
@@ -249,6 +249,7 @@ static QmlObjectNode createQmlObjectNodeFromSource(AbstractView *view,
|
||||
QScopedPointer<RewriterView> rewriterView(new RewriterView(RewriterView::Amend, nullptr));
|
||||
rewriterView->setCheckSemanticErrors(false);
|
||||
rewriterView->setTextModifier(&modifier);
|
||||
rewriterView->setAllowComponentRoot(true);
|
||||
inputModel->setRewriterView(rewriterView.data());
|
||||
|
||||
if (rewriterView->errors().isEmpty() && rewriterView->rootModelNode().isValid()) {
|
||||
|
||||
@@ -704,6 +704,16 @@ void RewriterView::sanitizeModel()
|
||||
});
|
||||
}
|
||||
|
||||
void RewriterView::setAllowComponentRoot(bool allow)
|
||||
{
|
||||
m_allowComponentRoot = allow;
|
||||
}
|
||||
|
||||
bool RewriterView::allowComponentRoot() const
|
||||
{
|
||||
return m_allowComponentRoot;
|
||||
}
|
||||
|
||||
Internal::ModelNodePositionStorage *RewriterView::positionStorage() const
|
||||
{
|
||||
return m_positionStorage.data();
|
||||
|
||||
@@ -1200,7 +1200,7 @@ void TextToModelMerger::syncNode(ModelNode &modelNode,
|
||||
return;
|
||||
}
|
||||
|
||||
if (modelNode.isRootNode() && isComponentType(typeName)) {
|
||||
if (modelNode.isRootNode() && !m_rewriterView->allowComponentRoot() && isComponentType(typeName)) {
|
||||
for (AST::UiObjectMemberList *iter = astInitializer->members; iter; iter = iter->next) {
|
||||
if (auto def = AST::cast<AST::UiObjectDefinition *>(iter->member)) {
|
||||
syncNode(modelNode, def, context, differenceHandler);
|
||||
|
||||
@@ -43,6 +43,8 @@
|
||||
<file>source/texteditv2.qml</file>
|
||||
<file>source/textinput.qml</file>
|
||||
<file>source/textinputv2.qml</file>
|
||||
<file>source/component.qml</file>
|
||||
<file>source/component3d.qml</file>
|
||||
<file>images/column-positioner-icon.png</file>
|
||||
<file>images/column-positioner-icon-16px.png</file>
|
||||
<file>images/default-icon.png</file>
|
||||
|
||||
@@ -446,6 +446,28 @@ MetaInfo {
|
||||
category: "e.Qt Quick - Component"
|
||||
libraryIcon: ":/qtquickplugin/images/component-icon.png"
|
||||
version: "2.0"
|
||||
|
||||
QmlSource { source: ":/qtquickplugin/source/component.qml" }
|
||||
}
|
||||
}
|
||||
|
||||
Type {
|
||||
name: "QtQml.Component"
|
||||
icon: ":/qtquickplugin/images/component-icon16.png"
|
||||
|
||||
Hints {
|
||||
canBeDroppedInNavigator: true
|
||||
canBeDroppedInFormEditor: false
|
||||
}
|
||||
|
||||
ItemLibraryEntry {
|
||||
name: "Component 3D"
|
||||
category: "Qt Quick 3D Component"
|
||||
libraryIcon: ":/qtquickplugin/images/component-icon.png"
|
||||
version: "2.0"
|
||||
requiredImport: "QtQuick3D"
|
||||
|
||||
QmlSource { source: ":/qtquickplugin/source/component3d.qml" }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
34
src/plugins/qmldesigner/qtquickplugin/source/component.qml
Normal file
34
src/plugins/qmldesigner/qtquickplugin/source/component.qml
Normal file
@@ -0,0 +1,34 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2021 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.
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
import QtQuick 2.0
|
||||
|
||||
Component {
|
||||
Item {
|
||||
id: componentRoot
|
||||
width: 100
|
||||
height: 100
|
||||
}
|
||||
}
|
||||
33
src/plugins/qmldesigner/qtquickplugin/source/component3d.qml
Normal file
33
src/plugins/qmldesigner/qtquickplugin/source/component3d.qml
Normal file
@@ -0,0 +1,33 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2021 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.
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
import QtQuick 2.0
|
||||
import QtQuick3D 6.0
|
||||
|
||||
Component {
|
||||
Node {
|
||||
id: componentRoot
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user