QmlDesigner: Check if root element is a graphical item

If the root element is not a graphical item, then we show a proper error
message.

Task-number: QTCREATORBUG-20014
Change-Id: I9c1ccbbeb6765bd098344ceef8024a703a8dc919
Reviewed-by: Leena Miettinen <riitta-leena.miettinen@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
This commit is contained in:
Thomas Hartmann
2021-11-01 17:12:41 +01:00
committed by Thomas Hartmann
parent 08a86169db
commit 3d64aa7aa6
4 changed files with 34 additions and 0 deletions

View File

@@ -44,6 +44,7 @@
#include <model.h> #include <model.h>
#include <nodeabstractproperty.h> #include <nodeabstractproperty.h>
#include <nodelistproperty.h> #include <nodelistproperty.h>
#include <nodemetainfo.h>
#include <rewriterview.h> #include <rewriterview.h>
#include <zoomaction.h> #include <zoomaction.h>
@@ -159,6 +160,8 @@ void FormEditorView::setupFormEditorItemTree(const QmlItemNode &qmlItemNode)
if (QmlItemNode::isValidQmlItemNode(nextNode) && nextNode.modelNode().nodeSourceType() == ModelNode::NodeWithoutSource) if (QmlItemNode::isValidQmlItemNode(nextNode) && nextNode.modelNode().nodeSourceType() == ModelNode::NodeWithoutSource)
setupFormEditorItemTree(nextNode.toQmlItemNode()); setupFormEditorItemTree(nextNode.toQmlItemNode());
} }
checkRootModelNode();
} }
static void deleteWithoutChildren(const QList<FormEditorItem*> &items) static void deleteWithoutChildren(const QList<FormEditorItem*> &items)
@@ -296,7 +299,11 @@ void FormEditorView::rootNodeTypeChanged(const QString &/*type*/, int /*majorVer
if (newItemNode.isValid()) //only setup QmlItems if (newItemNode.isValid()) //only setup QmlItems
setupFormEditorItemTree(newItemNode); setupFormEditorItemTree(newItemNode);
m_currentTool->setItems(scene()->itemsForQmlItemNodes(toQmlItemNodeList(selectedModelNodes()))); m_currentTool->setItems(scene()->itemsForQmlItemNodes(toQmlItemNodeList(selectedModelNodes())));
checkRootModelNode();
} }
void FormEditorView::propertiesAboutToBeRemoved(const QList<AbstractProperty>& propertyList) void FormEditorView::propertiesAboutToBeRemoved(const QList<AbstractProperty>& propertyList)
@@ -464,6 +471,8 @@ void FormEditorView::documentMessagesChanged(const QList<DocumentMessage> &error
m_formEditorWidget->showErrorMessageBox(errors); m_formEditorWidget->showErrorMessageBox(errors);
else else
m_formEditorWidget->hideErrorMessageBox(); m_formEditorWidget->hideErrorMessageBox();
checkRootModelNode();
} }
void FormEditorView::customNotification(const AbstractView * /*view*/, const QString &identifier, const QList<ModelNode> &/*nodeList*/, const QList<QVariant> &/*data*/) void FormEditorView::customNotification(const AbstractView * /*view*/, const QString &identifier, const QList<ModelNode> &/*nodeList*/, const QList<QVariant> &/*data*/)
@@ -796,6 +805,8 @@ void FormEditorView::setupFormEditorWidget()
if (!rewriterView()->warnings().isEmpty()) if (!rewriterView()->warnings().isEmpty())
m_formEditorWidget->showWarningMessageBox(rewriterView()->warnings()); m_formEditorWidget->showWarningMessageBox(rewriterView()->warnings());
checkRootModelNode();
} }
QmlItemNode findRecursiveQmlItemNode(const QmlObjectNode &firstQmlObjectNode) QmlItemNode findRecursiveQmlItemNode(const QmlObjectNode &firstQmlObjectNode)
@@ -884,6 +895,21 @@ void FormEditorView::addOrRemoveFormEditorItem(const ModelNode &node)
} }
} }
void FormEditorView::checkRootModelNode()
{
if (m_formEditorWidget->errorMessageBoxIsVisible())
return;
QTC_ASSERT(rootModelNode().isValid(), return);
if (!rootModelNode().metaInfo().isGraphicalItem())
m_formEditorWidget->showErrorMessageBox(
{DocumentMessage(tr("%1 is not supported as the root element by Form Editor.")
.arg(rootModelNode().simplifiedTypeName()))});
else
m_formEditorWidget->hideErrorMessageBox();
}
void FormEditorView::reset() void FormEditorView::reset()
{ {
QTimer::singleShot(200, this, &FormEditorView::delayedReset); QTimer::singleShot(200, this, &FormEditorView::delayedReset);

View File

@@ -149,6 +149,7 @@ private:
void temporaryBlockView(int duration = 1000); void temporaryBlockView(int duration = 1000);
void resetNodeInstanceView(); void resetNodeInstanceView();
void addOrRemoveFormEditorItem(const ModelNode &node); void addOrRemoveFormEditorItem(const ModelNode &node);
void checkRootModelNode();
QPointer<FormEditorWidget> m_formEditorWidget; QPointer<FormEditorWidget> m_formEditorWidget;
QPointer<FormEditorScene> m_scene; QPointer<FormEditorScene> m_scene;

View File

@@ -549,6 +549,11 @@ FormEditorGraphicsView *FormEditorWidget::graphicsView() const
return m_graphicsView; return m_graphicsView;
} }
bool FormEditorWidget::errorMessageBoxIsVisible() const
{
return m_documentErrorWidget && m_documentErrorWidget->isVisible();
}
DocumentWarningWidget *FormEditorWidget::errorWidget() DocumentWarningWidget *FormEditorWidget::errorWidget()
{ {
if (m_documentErrorWidget.isNull()) { if (m_documentErrorWidget.isNull()) {

View File

@@ -89,6 +89,8 @@ public:
FormEditorGraphicsView *graphicsView() const; FormEditorGraphicsView *graphicsView() const;
bool errorMessageBoxIsVisible() const;
protected: protected:
QActionGroup *toolActionGroup() const; QActionGroup *toolActionGroup() const;
DocumentWarningWidget *errorWidget(); DocumentWarningWidget *errorWidget();