aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMarco Bubke <marco.bubke@qt.io>2020-09-01 16:36:56 +0200
committerMarco Bubke <marco.bubke@qt.io>2020-09-16 08:37:53 +0000
commit7c8847333b6e0dab509e1e06006d133ff773c4bf (patch)
treedf4b37e0c117a519d7f08360545fdcc8391f095d /src
parentaf88afe943fef260f59c530313d2cef8247ca601 (diff)
QmlDesigner: Go into components
Task-nubmer: QDS-2696 Change-Id: I2f0ee71deea593da08fa4a754d783b53867473ed Reviewed-by: Michael Winkelmann <michael.winkelmann@qt.io> Reviewed-by: Leena Miettinen <riitta-leena.miettinen@qt.io> Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
Diffstat (limited to 'src')
-rw-r--r--src/plugins/qmldesigner/components/componentcore/designeractionmanager.cpp58
-rw-r--r--src/plugins/qmldesigner/components/componentcore/modelnodeoperations.cpp4
-rw-r--r--src/plugins/qmldesigner/components/componentcore/modelnodeoperations.h2
-rw-r--r--src/plugins/qmldesigner/components/listmodeleditor/listmodeleditormodel.cpp14
-rw-r--r--src/plugins/qmldesigner/components/listmodeleditor/listmodeleditormodel.h5
-rw-r--r--src/plugins/qmldesigner/documentmanager.cpp7
-rw-r--r--src/plugins/qmldesigner/documentmanager.h2
7 files changed, 73 insertions, 19 deletions
diff --git a/src/plugins/qmldesigner/components/componentcore/designeractionmanager.cpp b/src/plugins/qmldesigner/components/componentcore/designeractionmanager.cpp
index d9cc152181..5c961eb8ae 100644
--- a/src/plugins/qmldesigner/components/componentcore/designeractionmanager.cpp
+++ b/src/plugins/qmldesigner/components/componentcore/designeractionmanager.cpp
@@ -26,14 +26,15 @@
#include "designeractionmanager.h"
#include "changestyleaction.h"
+#include "designeractionmanagerview.h"
#include "modelnodecontextmenu_helper.h"
+#include "qmldesignerconstants.h"
+#include "rewritingexception.h"
#include <bindingproperty.h>
-#include <nodeproperty.h>
-#include <nodelistproperty.h>
#include <nodehints.h>
+#include <nodelistproperty.h>
#include <nodemetainfo.h>
-#include "designeractionmanagerview.h"
-#include "qmldesignerconstants.h"
+#include <nodeproperty.h>
#include <formeditortoolbutton.h>
@@ -44,8 +45,6 @@
#include <listmodeleditor/listmodeleditordialog.h>
#include <listmodeleditor/listmodeleditormodel.h>
-#include <QHBoxLayout>
-#include <QGraphicsLinearLayout>
#include <coreplugin/actionmanager/actionmanager.h>
#include <coreplugin/icore.h>
@@ -53,6 +52,12 @@
#include <utils/qtcassert.h>
#include <utils/utilsicons.h>
+#include <QGraphicsLinearLayout>
+#include <QHBoxLayout>
+#include <QMessageBox>
+
+#include <exception>
+
namespace QmlDesigner {
static inline QString captionForModelNode(const ModelNode &modelNode)
@@ -339,6 +344,12 @@ public:
}
};
+class DocumentError : public std::exception
+{
+public:
+ const char *what() const override { return "Current document contains errors."; }
+};
+
class EditListModelAction final : public ModelNodeContextMenuAction
{
public:
@@ -384,6 +395,24 @@ public:
return view->createModelNode(elementMetaInfo.typeName(),
elementMetaInfo.majorVersion(),
elementMetaInfo.minorVersion());
+ },
+ [&](const ModelNode &node) {
+ bool isNowInComponent = ModelNodeOperations::goIntoComponent(
+ node);
+
+ Model *currentModel = QmlDesignerPlugin::instance()
+ ->currentDesignDocument()
+ ->currentModel();
+
+ if (currentModel->rewriterView()
+ && currentModel->rewriterView()->inErrorState()) {
+ throw DocumentError{};
+ }
+
+ if (isNowInComponent)
+ return view->rootModelNode();
+
+ return node;
}};
model.setListView(targetNode);
@@ -391,7 +420,22 @@ public:
ListModelEditorDialog dialog{Core::ICore::mainWindow()};
dialog.setModel(&model);
- dialog.exec();
+ try {
+ dialog.exec();
+ } catch (const DocumentError &) {
+ QMessageBox::warning(
+ Core::ICore::mainWindow(),
+ QCoreApplication::translate("DesignerActionManager", "Document has errors"),
+ QCoreApplication::translate("DesignerActionManager",
+ "The document which contains the list model "
+ "contains errors. So we cannot edit it."));
+ } catch (const RewritingException &) {
+ QMessageBox::warning(
+ Core::ICore::mainWindow(),
+ QCoreApplication::translate("DesignerActionManager", "Document cannot be written"),
+ QCoreApplication::translate("DesignerActionManager",
+ "An error occurred during a write attemp."));
+ }
}
};
diff --git a/src/plugins/qmldesigner/components/componentcore/modelnodeoperations.cpp b/src/plugins/qmldesigner/components/componentcore/modelnodeoperations.cpp
index 7453807a83..0fbaca4679 100644
--- a/src/plugins/qmldesigner/components/componentcore/modelnodeoperations.cpp
+++ b/src/plugins/qmldesigner/components/componentcore/modelnodeoperations.cpp
@@ -127,9 +127,9 @@ static void setUpperLeftPostionToNode(const ModelNode &layoutNode, const QList<M
namespace ModelNodeOperations {
-void goIntoComponent(const ModelNode &modelNode)
+bool goIntoComponent(const ModelNode &modelNode)
{
- DocumentManager::goIntoComponent(modelNode);
+ return DocumentManager::goIntoComponent(modelNode);
}
void select(const SelectionContext &selectionState)
diff --git a/src/plugins/qmldesigner/components/componentcore/modelnodeoperations.h b/src/plugins/qmldesigner/components/componentcore/modelnodeoperations.h
index 96dedf352a..e676e4a4ee 100644
--- a/src/plugins/qmldesigner/components/componentcore/modelnodeoperations.h
+++ b/src/plugins/qmldesigner/components/componentcore/modelnodeoperations.h
@@ -30,7 +30,7 @@
namespace QmlDesigner {
namespace ModelNodeOperations {
-void goIntoComponent(const ModelNode &modelNode);
+bool goIntoComponent(const ModelNode &modelNode);
void select(const SelectionContext &selectionState);
void deSelect(const SelectionContext &selectionState);
diff --git a/src/plugins/qmldesigner/components/listmodeleditor/listmodeleditormodel.cpp b/src/plugins/qmldesigner/components/listmodeleditor/listmodeleditormodel.cpp
index b73a53f76c..c63b087389 100644
--- a/src/plugins/qmldesigner/components/listmodeleditor/listmodeleditormodel.cpp
+++ b/src/plugins/qmldesigner/components/listmodeleditor/listmodeleditormodel.cpp
@@ -199,13 +199,15 @@ void renameProperties(const QStandardItemModel *model,
}
ModelNode listModelNode(const ModelNode &listViewNode,
- const std::function<ModelNode()> &createModelCallback)
+ const std::function<ModelNode()> &createModelCallback,
+ const std::function<ModelNode(const ModelNode &)> &goIntoComponentCallback)
{
if (listViewNode.hasProperty("model")) {
- if (listViewNode.hasBindingProperty("model"))
- return listViewNode.bindingProperty("model").resolveToModelNode();
- else if (listViewNode.hasNodeProperty("model"))
- return listViewNode.nodeProperty("model").modelNode();
+ if (listViewNode.hasBindingProperty("model")) {
+ return goIntoComponentCallback(listViewNode.bindingProperty("model").resolveToModelNode());
+ } else if (listViewNode.hasNodeProperty("model")) {
+ return goIntoComponentCallback(listViewNode.nodeProperty("model").modelNode());
+ }
}
ModelNode newModel = createModelCallback();
@@ -251,7 +253,7 @@ void ListModelEditorModel::setListModel(ModelNode node)
void ListModelEditorModel::setListView(ModelNode listView)
{
- setListModel(listModelNode(listView, m_createModelCallback));
+ setListModel(listModelNode(listView, m_createModelCallback, m_goIntoComponentCallback));
}
void ListModelEditorModel::addRow()
diff --git a/src/plugins/qmldesigner/components/listmodeleditor/listmodeleditormodel.h b/src/plugins/qmldesigner/components/listmodeleditor/listmodeleditormodel.h
index 97bd9c18d8..5d3b87bbd7 100644
--- a/src/plugins/qmldesigner/components/listmodeleditor/listmodeleditormodel.h
+++ b/src/plugins/qmldesigner/components/listmodeleditor/listmodeleditormodel.h
@@ -39,9 +39,11 @@ class ListModelEditorModel : public QStandardItemModel
public:
ListModelEditorModel(std::function<ModelNode()> createModelCallback,
- std::function<ModelNode()> createElementCallback)
+ std::function<ModelNode()> createElementCallback,
+ std::function<ModelNode(const ModelNode &)> goIntoComponentCallback)
: m_createModelCallback(std::move(createModelCallback))
, m_createElementCallback(std::move(createElementCallback))
+ , m_goIntoComponentCallback(std::move(goIntoComponentCallback))
{}
void setListModel(ModelNode node);
@@ -76,6 +78,7 @@ private:
QList<QmlDesigner::PropertyName> m_propertyNames;
std::function<ModelNode()> m_createModelCallback;
std::function<ModelNode()> m_createElementCallback;
+ std::function<ModelNode(const ModelNode &)> m_goIntoComponentCallback;
};
} // namespace QmlDesigner
diff --git a/src/plugins/qmldesigner/documentmanager.cpp b/src/plugins/qmldesigner/documentmanager.cpp
index 4550d8a4ea..109b6577b4 100644
--- a/src/plugins/qmldesigner/documentmanager.cpp
+++ b/src/plugins/qmldesigner/documentmanager.cpp
@@ -271,7 +271,7 @@ void DocumentManager::removeEditors(const QList<Core::IEditor *> &editors)
delete m_designDocumentHash.take(editor).data();
}
-void DocumentManager::goIntoComponent(const ModelNode &modelNode)
+bool DocumentManager::goIntoComponent(const ModelNode &modelNode)
{
if (modelNode.isValid() && modelNode.isComponent() && designDocument()) {
QmlDesignerPlugin::instance()->viewManager().setComponentNode(modelNode);
@@ -286,9 +286,14 @@ void DocumentManager::goIntoComponent(const ModelNode &modelNode)
openComponentSourcePropertyOfLoader(modelNode);
else
openInlineComponent(modelNode);
+
ModelNode rootModelNode = designDocument()->rewriterView()->rootModelNode();
applyProperties(rootModelNode, oldProperties);
+
+ return true;
}
+
+ return false;
}
bool DocumentManager::createFile(const QString &filePath, const QString &contents)
diff --git a/src/plugins/qmldesigner/documentmanager.h b/src/plugins/qmldesigner/documentmanager.h
index bb3b13c9ac..8cd67eca9f 100644
--- a/src/plugins/qmldesigner/documentmanager.h
+++ b/src/plugins/qmldesigner/documentmanager.h
@@ -51,7 +51,7 @@ public:
void removeEditors(const QList<Core::IEditor *> &editors);
- static void goIntoComponent(const ModelNode &modelNode);
+ static bool goIntoComponent(const ModelNode &modelNode);
static bool createFile(const QString &filePath, const QString &contents);
static void addFileToVersionControl(const QString &directoryPath, const QString &newFilePath);