Commit 35263628 authored by Marco Bubke's avatar Marco Bubke

Add script function to the model

This is needed to suppert inline script function of Qml in the designer
parent 24f07b7a
......@@ -235,7 +235,7 @@ FormEditorWidget *FormEditorView::widget() const
void FormEditorView::nodeIdChanged(const ModelNode& node, const QString& newId, const QString& oldId)
{
nodeInstanceView()->nodeIdChanged(node, newId, oldId);
QmlModelView::nodeIdChanged(node, newId, oldId);
}
void FormEditorView::selectedNodesChanged(const QList<ModelNode> &selectedNodeList,
......@@ -258,6 +258,12 @@ void FormEditorView::selectedNodesChanged(const QList<ModelNode> &selectedNodeLi
m_scene->update();
}
void FormEditorView::scriptFunctionsChanged(const ModelNode &node, const QStringList &scriptFunctionList)
{
QmlModelView::scriptFunctionsChanged(node, scriptFunctionList);
}
AbstractFormEditorTool* FormEditorView::currentTool() const
{
return m_currentTool;
......
......@@ -77,6 +77,7 @@ public:
void selectedNodesChanged(const QList<ModelNode> &selectedNodeList,
const QList<ModelNode> &lastSelectedNodeList);
void scriptFunctionsChanged(const ModelNode &node, const QStringList &scriptFunctionList);
// FormEditorView
FormEditorWidget *widget() const;
......
......@@ -159,6 +159,7 @@ void ComponentView::propertiesRemoved(const QList<AbstractProperty>& /*propertyL
void ComponentView::variantPropertiesChanged(const QList<VariantProperty>& /*propertyList*/, PropertyChangeFlags /*propertyChange*/) {}
void ComponentView::bindingPropertiesChanged(const QList<BindingProperty>& /*propertyList*/, PropertyChangeFlags /*propertyChange*/) {}
void ComponentView::rootNodeTypeChanged(const QString &/*type*/, int /*majorVersion*/, int /*minorVersion*/) {}
void ComponentView::scriptFunctionsChanged(const ModelNode &/*node*/, const QStringList &/*scriptFunctionList*/) {}
......
......@@ -66,7 +66,7 @@ public:
void variantPropertiesChanged(const QList<VariantProperty>& propertyList, PropertyChangeFlags propertyChange);
void bindingPropertiesChanged(const QList<BindingProperty>& propertyList, PropertyChangeFlags propertyChange);
void rootNodeTypeChanged(const QString &type, int majorVersion, int minorVersion);
void scriptFunctionsChanged(const ModelNode &node, const QStringList &scriptFunctionList);
void selectedNodesChanged(const QList<ModelNode> &selectedNodeList,
......
......@@ -56,6 +56,11 @@ void DesignDocumentControllerView::selectedNodesChanged(const QList<ModelNode> &
void DesignDocumentControllerView::nodeOrderChanged(const NodeListProperty & /*listProperty*/, const ModelNode & /*movedNode*/, int /*oldIndex*/) {};
void DesignDocumentControllerView::scriptFunctionsChanged(const ModelNode &/*node*/, const QStringList &/*scriptFunctionList*/)
{
}
static QStringList arrayToStringList(const QByteArray &byteArray)
{
QString str(QString::fromLatin1(byteArray));
......
......@@ -57,6 +57,7 @@ public:
const QList<ModelNode> &lastSelectedNodeList);
virtual void nodeOrderChanged(const NodeListProperty &listProperty, const ModelNode &movedNode, int oldIndex);
virtual void scriptFunctionsChanged(const ModelNode &node, const QStringList &scriptFunctionList);
ModelNode insertModel(const ModelNode &modelNode)
{ return m_modelMerger.insertModel(modelNode); }
......
......@@ -186,6 +186,11 @@ void NavigatorView::auxiliaryDataChanged(const ModelNode &node, const QString &
}
}
void NavigatorView::scriptFunctionsChanged(const ModelNode &/*node*/, const QStringList &/*scriptFunctionList*/)
{
}
void NavigatorView::nodeOrderChanged(const NodeListProperty &/*listProperty*/, const ModelNode &node, int /*oldIndex*/)
{
if (m_treeModel->isInTree(node))
......
......@@ -80,6 +80,7 @@ public:
void selectedNodesChanged(const QList<ModelNode> &selectedNodeList,
const QList<ModelNode> &lastSelectedNodeList);
void auxiliaryDataChanged(const ModelNode &node, const QString &name, const QVariant &data);
void scriptFunctionsChanged(const ModelNode &node, const QStringList &scriptFunctionList);
private slots:
......
......@@ -798,6 +798,11 @@ void PropertyEditor::nodeIdChanged(const ModelNode& node, const QString& newId,
}
}
void PropertyEditor::scriptFunctionsChanged(const ModelNode &node, const QStringList &scriptFunctionList)
{
QmlModelView::scriptFunctionsChanged(node, scriptFunctionList);
}
void PropertyEditor::select(const ModelNode &node)
{
if (QmlItemNode(node).isValid())
......
......@@ -101,6 +101,7 @@ public:
void bindingPropertiesChanged(const QList<BindingProperty>& propertyList, PropertyChangeFlags propertyChange);
void nodeIdChanged(const ModelNode& node, const QString& newId, const QString& oldId);
void scriptFunctionsChanged(const ModelNode &node, const QStringList &scriptFunctionList);
protected:
void timerEvent(QTimerEvent *event);
......
......@@ -399,6 +399,15 @@ void StatesEditorView::customNotification(const AbstractView * view, const QStri
QmlModelView::customNotification(view, identifier, nodeList, data);
}
void StatesEditorView::scriptFunctionsChanged(const ModelNode &node, const QStringList &scriptFunctionList)
{
if (debug)
qDebug() << __FUNCTION__;
QmlModelView::scriptFunctionsChanged(node, scriptFunctionList);
}
QPixmap StatesEditorView::renderState(int i)
{
if (debug)
......
......@@ -57,7 +57,6 @@ public:
void nodeInstancePropertyChanged(const ModelNode &node, const QString &propertyName);
protected:
// AbstractView
void modelAttached(Model *model);
void modelAboutToBeDetached(Model *model);
......@@ -76,6 +75,7 @@ protected:
void otherPropertyChanged(const QmlObjectNode &qmlObjectNode, const QString &propertyName);
void customNotification(const AbstractView *view, const QString &identifier, const QList<ModelNode> &nodeList, const QList<QVariant> &data);
void scriptFunctionsChanged(const ModelNode &node, const QStringList &scriptFunctionList);
protected:
......
......@@ -129,6 +129,8 @@ public:
virtual void customNotification(const AbstractView *view, const QString &identifier, const QList<ModelNode> &nodeList, const QList<QVariant> &data);
virtual void scriptFunctionsChanged(const ModelNode &node, const QStringList &scriptFunctionList) = 0;
QmlModelView *toQmlModelView();
void changeRootNodeType(const QString &type, int majorVersion, int minorVersion);
......
......@@ -76,6 +76,7 @@ public:
void auxiliaryDataChanged(const ModelNode &node, const QString &name, const QVariant &data);
void scriptFunctionsChanged(const ModelNode &node, const QStringList &scriptFunctionList);
protected:
void appendView(ViewType *view);
......@@ -245,6 +246,13 @@ void ForwardView<ViewType>::auxiliaryDataChanged(const ModelNode &node, const QS
view->auxiliaryDataChanged(ModelNode(node, view.data()), name, data);
}
template <class ViewType>
void ForwardView<ViewType>::scriptFunctionsChanged(const ModelNode &node, const QStringList &scriptFunctionList)
{
foreach (const ViewTypePointer &view, m_targetViewList)
view->scriptFunctionsChanged(node, scriptFunctionList);
}
template <class ViewType>
void ForwardView<ViewType>::appendView(ViewType *view)
{
......
......@@ -135,6 +135,10 @@ public:
bool hasNodeProperty(const QString &name) const;
bool hasNodeListProperty(const QString &name) const;
void setScriptFunctions(const QStringList &scriptFunctionList);
QStringList scriptFunctions() const;
//###
void destroy();
......
......@@ -84,6 +84,8 @@ public:
void nodeIdChanged(const ModelNode& node, const QString& newId, const QString& oldId);
void nodeOrderChanged(const NodeListProperty &listProperty, const ModelNode &movedNode, int oldIndex);
void selectedNodesChanged(const QList<ModelNode> &selectedNodeList, const QList<ModelNode> &lastSelectedNodeList);
void scriptFunctionsChanged(const ModelNode &node, const QStringList &scriptFunctionList);
QList<NodeInstance> instances() const;
NodeInstance instanceForNode(const ModelNode &node);
......
......@@ -124,6 +124,7 @@ public:
void nodeOrderChanged(const NodeListProperty &listProperty, const ModelNode &movedNode, int oldIndex);
void rootNodeTypeChanged(const QString &type, int majorVersion, int minorVersion);
void customNotification(const AbstractView *view, const QString &identifier, const QList<ModelNode> &nodeList, const QList<QVariant> &data);
void scriptFunctionsChanged(const ModelNode &node, const QStringList &scriptFunctionList);
void importAdded(const Import &import);
void importRemoved(const Import &import);
......
......@@ -374,6 +374,10 @@ void NodeInstanceView::selectedNodesChanged(const QList<ModelNode> &/*selectedNo
{
}
void NodeInstanceView::scriptFunctionsChanged(const ModelNode &/*node*/, const QStringList &/*scriptFunctionList*/)
{
}
//\}
......
......@@ -311,5 +311,15 @@ bool operator <(const InternalNode::Pointer &firstNode, const InternalNode::Poin
return firstNode.data() < secondNode.data();
}
void InternalNode::setScriptFunctions(const QStringList &scriptFunctionList)
{
m_scriptFunctionList = scriptFunctionList;
}
QStringList InternalNode::scriptFunctions() const
{
return m_scriptFunctionList;
}
}
}
......@@ -34,6 +34,7 @@
#include <QHash>
#include <QSharedPointer>
#include <QWeakPointer>
#include <QStringList>
#include "internalproperty.h"
#include "internalvariantproperty.h"
#include "internalbindingproperty.h"
......@@ -112,6 +113,9 @@ public:
QList<InternalNode::Pointer> allSubNodes() const;
QList<InternalNode::Pointer> allDirectSubNodes() const;
void setScriptFunctions(const QStringList &scriptFunctionList);
QStringList scriptFunctions() const;
protected:
Pointer internalPointer() const;
void setInternalWeakPointer(const Pointer &pointer);
......@@ -133,6 +137,7 @@ private:
bool m_valid;
QHash<QString, InternalPropertyPointer> m_namePropertyHash;
QStringList m_scriptFunctionList;
};
uint qHash(const InternalNodePointer& node);
......
......@@ -531,6 +531,29 @@ void ModelPrivate::notifyBindingPropertiesChanged(const QList<InternalBindingPro
}
}
void ModelPrivate::notifyScriptFunctionsChanged(const InternalNodePointer &internalNodePointer, const QStringList &scriptFunctionList)
{
bool resetModel = false;
QString description;
foreach (const QWeakPointer<AbstractView> &view, m_viewList) {
Q_ASSERT(view != 0);
ModelNode node(internalNodePointer, model(), view.data());
try {
view->scriptFunctionsChanged(node, scriptFunctionList);
} catch (RewritingException &e) {
description = e.description();
resetModel = true;
}
}
if (resetModel) {
resetModelByRewriter(description);
}
}
void ModelPrivate::notifyVariantPropertiesChanged(const InternalNodePointer &internalNodePointer, const QStringList& propertyNameList, AbstractView::PropertyChangeFlags propertyChange)
{
bool resetModel = false;
......@@ -840,6 +863,13 @@ void ModelPrivate::changeRootNodeType(const QString &type, int majorVersion, int
notifyRootNodeTypeChanged(type, majorVersion, minorVersion);
}
void ModelPrivate::setScriptFunctions(const InternalNode::Pointer &internalNode, const QStringList &scriptFunctionList)
{
internalNode->setScriptFunctions(scriptFunctionList);
notifyScriptFunctionsChanged(internalNode, scriptFunctionList);
}
void ModelPrivate::changeNodeOrder(const InternalNode::Pointer &internalParentNode, const QString &listPropertyName, int from, int to)
{
InternalNodeListProperty::Pointer nodeList(internalParentNode->nodeListProperty(listPropertyName));
......
......@@ -132,6 +132,7 @@ public:
void notifyPropertiesAboutToBeRemoved(const QList<InternalPropertyPointer> &propertyList);
void notifyBindingPropertiesChanged(const QList<InternalBindingPropertyPointer> &propertyList, AbstractView::PropertyChangeFlags propertyChange);
void notifyVariantPropertiesChanged(const InternalNodePointer &internalNodePointer, const QStringList& propertyNameList, AbstractView::PropertyChangeFlags propertyChange);
void notifyScriptFunctionsChanged(const InternalNodePointer &internalNodePointer, const QStringList &scriptFunctionList);
void notifyNodeOrderChanged(const InternalNodeListPropertyPointer &internalListPropertyPointer, const InternalNodePointer &internalNodePointer, int oldIndex);
void notifyAuxiliaryDataChanged(const InternalNodePointer &internalNode, const QString &name, const QVariant &data);
......@@ -140,6 +141,8 @@ public:
void notifyCustomNotification(const AbstractView *senderView, const QString &identifier, const QList<ModelNode> &nodeList, const QList<QVariant> &data);
void setSelectedNodes(const QList<InternalNodePointer> &selectedNodeList);
void clearSelectedNodes();
QList<InternalNodePointer> selectedNodes() const;
......@@ -176,6 +179,7 @@ public:
void checkPropertyName(const QString &propertyName);
void clearParent(const InternalNodePointer &internalNode);
void changeRootNodeType(const QString &type, int majorVersion, int minorVersion);
void setScriptFunctions(const InternalNodePointer &internalNode, const QStringList &scriptFunctionList);
InternalNodePointer nodeForId(const QString &id) const;
bool hasId(const QString &id) const;
......
......@@ -908,4 +908,14 @@ bool ModelNode::hasAuxiliaryData(const QString &name) const
return internalNode()->hasAuxiliaryData(name);
}
void ModelNode::setScriptFunctions(const QStringList &scriptFunctionList)
{
model()->m_d->setScriptFunctions(internalNode(), scriptFunctionList);
}
QStringList ModelNode::scriptFunctions() const
{
return internalNode()->scriptFunctions();
}
}
......@@ -352,6 +352,10 @@ void RewriterView::customNotification(const AbstractView * /*view*/, const QStri
}
}
void RewriterView::scriptFunctionsChanged(const ModelNode &/*node*/, const QStringList &/*scriptFunctionList*/)
{
}
void RewriterView::selectedNodesChanged(const QList<ModelNode> & /* selectedNodeList, */, const QList<ModelNode> & /*lastSelectedNodeList */)
{
}
......
......@@ -194,6 +194,12 @@ void ViewLogger::customNotification(const AbstractView *view, const QString &ide
m_output << time() << indent("data: ") << variant.toString() << endl;
}
void ViewLogger::scriptFunctionsChanged(const ModelNode &node, const QStringList &/*scriptFunctionList*/)
{
m_output << time() << indent("function scripts changed:") << node << endl;
}
} // namespace Internal
} // namespace QmlDesigner
......@@ -70,6 +70,7 @@ public:
void auxiliaryDataChanged(const ModelNode &node, const QString &name, const QVariant &data);
void customNotification(const AbstractView *view, const QString &identifier, const QList<ModelNode> &nodeList, const QList<QVariant> &data);
void scriptFunctionsChanged(const ModelNode &node, const QStringList &scriptFunctionList);
protected:
QString time() const;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment