aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAleksei German <aleksei.german@qt.io>2020-07-28 17:03:35 +0200
committerThomas Hartmann <thomas.hartmann@qt.io>2020-08-27 10:05:44 +0000
commitf642c02eb651b8146c57f735e03e4db29078abca (patch)
tree561ed8450b1a4ee8eb7526999e9a556109edec49 /src
parentac5d35a53d81212b8ca99af792f312d336e2f087 (diff)
QmlDesigner: Annotations for States
- Added Annotations support for States Task: QDS-2312 Change-Id: I204ec958f85bd0f05eae0abbb3848d6d59e7e397 Reviewed-by: Vikas Pachdha <vikas.pachdha@qt.io>
Diffstat (limited to 'src')
-rw-r--r--src/plugins/qmldesigner/components/annotationeditor/annotationeditor.cpp9
-rw-r--r--src/plugins/qmldesigner/components/stateseditor/stateseditormodel.cpp15
-rw-r--r--src/plugins/qmldesigner/components/stateseditor/stateseditormodel.h3
-rw-r--r--src/plugins/qmldesigner/components/stateseditor/stateseditorview.cpp94
-rw-r--r--src/plugins/qmldesigner/components/stateseditor/stateseditorview.h5
-rw-r--r--src/plugins/qmldesigner/designercore/include/qmlstate.h8
-rw-r--r--src/plugins/qmldesigner/designercore/model/qmlstate.cpp39
7 files changed, 158 insertions, 15 deletions
diff --git a/src/plugins/qmldesigner/components/annotationeditor/annotationeditor.cpp b/src/plugins/qmldesigner/components/annotationeditor/annotationeditor.cpp
index c119dfdca1e..21add0a7526 100644
--- a/src/plugins/qmldesigner/components/annotationeditor/annotationeditor.cpp
+++ b/src/plugins/qmldesigner/components/annotationeditor/annotationeditor.cpp
@@ -38,7 +38,8 @@
namespace QmlDesigner {
-AnnotationEditor::AnnotationEditor(QObject *)
+AnnotationEditor::AnnotationEditor(QObject *parent)
+ : QObject(parent)
{
}
@@ -55,9 +56,9 @@ void AnnotationEditor::registerDeclarativeType()
void AnnotationEditor::showWidget()
{
m_dialog = new AnnotationEditorDialog(Core::ICore::dialogParent(),
- modelNode().validId(),
- modelNode().customId(),
- modelNode().annotation());
+ m_modelNode.id(),
+ m_modelNode.customId(),
+ m_modelNode.annotation());
QObject::connect(m_dialog, &AnnotationEditorDialog::accepted,
this, &AnnotationEditor::acceptedClicked);
diff --git a/src/plugins/qmldesigner/components/stateseditor/stateseditormodel.cpp b/src/plugins/qmldesigner/components/stateseditor/stateseditormodel.cpp
index f2a83d05182..1828317a9e8 100644
--- a/src/plugins/qmldesigner/components/stateseditor/stateseditormodel.cpp
+++ b/src/plugins/qmldesigner/components/stateseditor/stateseditormodel.cpp
@@ -249,4 +249,19 @@ bool StatesEditorModel::hasDefaultState() const
return m_statesEditorView->hasDefaultState();
}
+void StatesEditorModel::setAnnotation(int internalNodeId)
+{
+ m_statesEditorView->setAnnotation(internalNodeId);
+}
+
+void StatesEditorModel::removeAnnotation(int internalNodeId)
+{
+ m_statesEditorView->removeAnnotation(internalNodeId);
+}
+
+bool StatesEditorModel::hasAnnotation(int internalNodeId) const
+{
+ return m_statesEditorView->hasAnnotation(internalNodeId);
+}
+
} // namespace QmlDesigner
diff --git a/src/plugins/qmldesigner/components/stateseditor/stateseditormodel.h b/src/plugins/qmldesigner/components/stateseditor/stateseditormodel.h
index 97c4c6a9ec5..65c1385e897 100644
--- a/src/plugins/qmldesigner/components/stateseditor/stateseditormodel.h
+++ b/src/plugins/qmldesigner/components/stateseditor/stateseditormodel.h
@@ -67,6 +67,9 @@ public:
Q_INVOKABLE void setStateAsDefault(int internalNodeId);
Q_INVOKABLE void resetDefaultState();
Q_INVOKABLE bool hasDefaultState() const;
+ Q_INVOKABLE void setAnnotation(int internalNodeId);
+ Q_INVOKABLE void removeAnnotation(int internalNodeId);
+ Q_INVOKABLE bool hasAnnotation(int internalNodeId) const;
void reset();
diff --git a/src/plugins/qmldesigner/components/stateseditor/stateseditorview.cpp b/src/plugins/qmldesigner/components/stateseditor/stateseditorview.cpp
index 8a2ca50c154..78ac9da2303 100644
--- a/src/plugins/qmldesigner/components/stateseditor/stateseditorview.cpp
+++ b/src/plugins/qmldesigner/components/stateseditor/stateseditorview.cpp
@@ -30,6 +30,7 @@
#include <QDebug>
#include <QRegExp>
+#include <QScopeGuard>
#include <cmath>
#include <nodemetainfo.h>
@@ -40,6 +41,7 @@
#include <qmlitemnode.h>
#include <qmlstate.h>
+#include <annotationeditor/annotationeditor.h>
namespace QmlDesigner {
@@ -51,7 +53,8 @@ namespace QmlDesigner {
StatesEditorView::StatesEditorView(QObject *parent) :
AbstractView(parent),
m_statesEditorModel(new StatesEditorModel(this)),
- m_lastIndex(-1)
+ m_lastIndex(-1),
+ m_editor(nullptr)
{
Q_ASSERT(m_statesEditorModel);
// base state
@@ -59,6 +62,8 @@ StatesEditorView::StatesEditorView(QObject *parent) :
StatesEditorView::~StatesEditorView()
{
+ if (m_editor)
+ delete m_editor;
delete m_statesEditorWidget.data();
}
@@ -274,6 +279,8 @@ void StatesEditorView::setWhenCondition(int internalNodeId, const QString &condi
return;
m_block = true;
+ auto guard = [this]() { m_block = false; };
+ QScopeGuard<decltype(guard)> lock(guard);
if (hasModelNodeForInternalId(internalNodeId)) {
QmlModelState state(modelNodeForInternalId(internalNodeId));
@@ -285,8 +292,6 @@ void StatesEditorView::setWhenCondition(int internalNodeId, const QString &condi
e.showException();
}
}
-
- m_block = false;
}
void StatesEditorView::resetWhenCondition(int internalNodeId)
@@ -295,6 +300,8 @@ void StatesEditorView::resetWhenCondition(int internalNodeId)
return;
m_block = true;
+ auto guard = [this]() { m_block = false; };
+ QScopeGuard<decltype(guard)> lock(guard);
if (hasModelNodeForInternalId(internalNodeId)) {
QmlModelState state(modelNodeForInternalId(internalNodeId));
@@ -306,8 +313,6 @@ void StatesEditorView::resetWhenCondition(int internalNodeId)
e.showException();
}
}
-
- m_block = false;
}
void StatesEditorView::setStateAsDefault(int internalNodeId)
@@ -316,6 +321,8 @@ void StatesEditorView::setStateAsDefault(int internalNodeId)
return;
m_block = true;
+ auto guard = [this]() { m_block = false; };
+ QScopeGuard<decltype(guard)> lock(guard);
if (hasModelNodeForInternalId(internalNodeId)) {
QmlModelState state(modelNodeForInternalId(internalNodeId));
@@ -327,8 +334,6 @@ void StatesEditorView::setStateAsDefault(int internalNodeId)
e.showException();
}
}
-
- m_block = false;
}
void StatesEditorView::resetDefaultState()
@@ -337,6 +342,8 @@ void StatesEditorView::resetDefaultState()
return;
m_block = true;
+ auto guard = [this]() { m_block = false; };
+ QScopeGuard<decltype(guard)> lock(guard);
try {
if (rootModelNode().hasProperty("state"))
@@ -345,8 +352,6 @@ void StatesEditorView::resetDefaultState()
} catch (const RewritingException &e) {
e.showException();
}
-
- m_block = false;
}
bool StatesEditorView::hasDefaultState() const
@@ -354,6 +359,70 @@ bool StatesEditorView::hasDefaultState() const
return rootModelNode().hasProperty("state");
}
+void StatesEditorView::setAnnotation(int internalNodeId)
+{
+ if (m_block)
+ return;
+
+ m_block = true;
+ auto guard = [this]() { m_block = false; };
+ QScopeGuard<decltype(guard)> lock(guard);
+
+ if (hasModelNodeForInternalId(internalNodeId)) {
+ QmlModelState state(modelNodeForInternalId(internalNodeId));
+ try {
+ if (state.isValid()) {
+ ModelNode modelNode = state.modelNode();
+
+ if (modelNode.isValid()) {
+ if (!m_editor)
+ m_editor = new AnnotationEditor(this);
+
+ m_editor->setModelNode(modelNode);
+ m_editor->showWidget();
+ }
+ }
+
+ } catch (const RewritingException &e) {
+ e.showException();
+ }
+ }
+}
+
+void StatesEditorView::removeAnnotation(int internalNodeId)
+{
+ if (m_block)
+ return;
+
+ m_block = true;
+ auto guard = [this]() { m_block = false; };
+ QScopeGuard<decltype(guard)> lock(guard);
+
+ if (hasModelNodeForInternalId(internalNodeId)) {
+ QmlModelState state(modelNodeForInternalId(internalNodeId));
+ try {
+ if (state.isValid()) {
+ state.removeAnnotation();
+ }
+
+ } catch (const RewritingException &e) {
+ e.showException();
+ }
+ }
+}
+
+bool StatesEditorView::hasAnnotation(int internalNodeId) const
+{
+ if (hasModelNodeForInternalId(internalNodeId)) {
+ QmlModelState state(modelNodeForInternalId(internalNodeId));
+ if (state.isValid()) {
+ return state.hasAnnotation();
+ }
+ }
+
+ return false;
+}
+
void StatesEditorView::modelAttached(Model *model)
{
if (model == AbstractView::model())
@@ -444,7 +513,12 @@ void StatesEditorView::bindingPropertiesChanged(const QList<BindingProperty> &pr
void StatesEditorView::variantPropertiesChanged(const QList<VariantProperty> &propertyList,
AbstractView::PropertyChangeFlags /*propertyChange*/)
{
+ if (m_block)
+ return;
+
m_block = true;
+ auto guard = [this]() { m_block = false; };
+ QScopeGuard<decltype(guard)> lock(guard);
for (const VariantProperty &property : propertyList) {
if (property.name() == "name" && QmlModelState::isValidQmlModelState(property.parentModelNode()))
@@ -452,8 +526,6 @@ void StatesEditorView::variantPropertiesChanged(const QList<VariantProperty> &pr
else if (property.name() == "state" && property.parentModelNode().isRootNode())
resetModel();
}
-
- m_block = false;
}
void StatesEditorView::currentStateChanged(const ModelNode &node)
diff --git a/src/plugins/qmldesigner/components/stateseditor/stateseditorview.h b/src/plugins/qmldesigner/components/stateseditor/stateseditorview.h
index 66ab998e041..44b4a3a380d 100644
--- a/src/plugins/qmldesigner/components/stateseditor/stateseditorview.h
+++ b/src/plugins/qmldesigner/components/stateseditor/stateseditorview.h
@@ -33,6 +33,7 @@ namespace QmlDesigner {
class StatesEditorModel;
class StatesEditorWidget;
+class AnnotationEditor;
class StatesEditorView : public AbstractView {
Q_OBJECT
@@ -47,6 +48,9 @@ public:
void setStateAsDefault(int internalNodeId);
void resetDefaultState();
bool hasDefaultState() const;
+ void setAnnotation(int internalNodeId);
+ void removeAnnotation(int internalNodeId);
+ bool hasAnnotation(int internalNodeId) const;
bool validStateName(const QString &name) const;
QString currentStateName() const;
void setCurrentState(const QmlModelState &state);
@@ -102,6 +106,7 @@ private:
QPointer<StatesEditorWidget> m_statesEditorWidget;
int m_lastIndex;
bool m_block = false;
+ QPointer<AnnotationEditor> m_editor;
};
} // namespace QmlDesigner
diff --git a/src/plugins/qmldesigner/designercore/include/qmlstate.h b/src/plugins/qmldesigner/designercore/include/qmlstate.h
index 156e441615f..7c43ac87761 100644
--- a/src/plugins/qmldesigner/designercore/include/qmlstate.h
+++ b/src/plugins/qmldesigner/designercore/include/qmlstate.h
@@ -34,6 +34,8 @@ namespace QmlDesigner {
class AbstractViewAbstractVieweGroup;
class QmlObjectNode;
class QmlModelStateGroup;
+class Annotation;
+class AnnotationEditor;
class QMLDESIGNERCORE_EXPORT QmlModelState : public QmlModelNodeFacade
{
@@ -72,6 +74,12 @@ public:
void setAsDefault();
bool isDefault() const;
+ void setAnnotation(const Annotation &annotation, const QString &id);
+ Annotation annotation() const;
+ QString annotationName() const;
+ bool hasAnnotation() const;
+ void removeAnnotation();
+
protected:
void addChangeSetIfNotExists(const ModelNode &node);
static QmlModelState createBaseState(const AbstractView *view);
diff --git a/src/plugins/qmldesigner/designercore/model/qmlstate.cpp b/src/plugins/qmldesigner/designercore/model/qmlstate.cpp
index 89bbec351eb..4a38985ad1b 100644
--- a/src/plugins/qmldesigner/designercore/model/qmlstate.cpp
+++ b/src/plugins/qmldesigner/designercore/model/qmlstate.cpp
@@ -32,6 +32,8 @@
#include "bindingproperty.h"
#include "qmlchangeset.h"
#include "qmlitemnode.h"
+#include "annotation.h"
+#include "annotationeditor/annotationeditor.h"
#include <utils/qtcassert.h>
@@ -304,6 +306,43 @@ bool QmlModelState::isDefault() const
return false;
}
+void QmlModelState::setAnnotation(const Annotation &annotation, const QString &id)
+{
+ if (modelNode().isValid()) {
+ modelNode().setCustomId(id);
+ modelNode().setAnnotation(annotation);
+ }
+}
+
+Annotation QmlModelState::annotation() const
+{
+ if (modelNode().isValid())
+ return modelNode().annotation();
+ return {};
+}
+
+QString QmlModelState::annotationName() const
+{
+ if (modelNode().isValid())
+ return modelNode().customId();
+ return {};
+}
+
+bool QmlModelState::hasAnnotation() const
+{
+ if (modelNode().isValid())
+ return modelNode().hasAnnotation() || modelNode().hasCustomId();
+ return false;
+}
+
+void QmlModelState::removeAnnotation()
+{
+ if (modelNode().isValid()) {
+ modelNode().removeCustomId();
+ modelNode().removeAnnotation();
+ }
+}
+
QmlModelState QmlModelState::createBaseState(const AbstractView *view)
{
QmlModelState qmlModelState(view->rootModelNode());