Commit a5c4c3b2 authored by Marco Bubke's avatar Marco Bubke

Add BehaviorNodeInstance

This is for disabling behavios in Bauhaus
parent 686b2119
......@@ -93,7 +93,8 @@ SOURCES += $$PWD/model/abstractview.cpp \
$$PWD/model/modelmerger.cpp \
$$PWD/instances/qmltransitionnodeinstance.cpp \
$$PWD/exceptions/rewritingexception.cpp \
$$PWD/instances/nodeinstancemetaobject.cpp
$$PWD/instances/nodeinstancemetaobject.cpp \
core/instances/behaviornodeinstance.cpp
HEADERS += $$PWD/include/corelib_global.h \
$$PWD/include/abstractview.h \
$$PWD/include/nodeinstanceview.h \
......@@ -183,7 +184,8 @@ HEADERS += $$PWD/include/corelib_global.h \
$$PWD/instances/qmltransitionnodeinstance.h \
$$PWD/include/customnotifications.h \
$$PWD/include/rewritingexception.h \
$$PWD/instances/nodeinstancemetaobject.h
$$PWD/instances/nodeinstancemetaobject.h \
core/instances/behaviornodeinstance.h
DISTFILES += $$PWD/metafile/widget.metafile
RESOURCES += $$PWD/core.qrc
OTHER_FILES += $$PWD/metainfo/gui.metainfo
#include "behaviornodeinstance.h"
#include <private/qmlbehavior_p.h>
#include "invalidnodeinstanceexception.h"
namespace QmlDesigner {
namespace Internal {
BehaviorNodeInstance::BehaviorNodeInstance(QObject *object)
: ObjectNodeInstance(object),
m_isEnabled(true)
{
}
BehaviorNodeInstance::Pointer BehaviorNodeInstance::create(const NodeMetaInfo &nodeMetaInfo, QmlContext *context, QObject *objectToBeWrapped)
{
QObject *object = 0;
if (objectToBeWrapped)
object = objectToBeWrapped;
else
object = createObject(nodeMetaInfo, context);
QmlBehavior* behavior = qobject_cast<QmlBehavior*>(object);
if (behavior == 0)
throw InvalidNodeInstanceException(__LINE__, __FUNCTION__, __FILE__);
Pointer instance(new BehaviorNodeInstance(behavior));
if (objectToBeWrapped)
instance->setDeleteHeldInstance(false); // the object isn't owned
instance->populateResetValueHash();
behavior->setEnabled(false);
return instance;
}
void BehaviorNodeInstance::setPropertyVariant(const QString &name, const QVariant &value)
{
if (name == "enabled")
return;
ObjectNodeInstance::setPropertyVariant(name, value);
}
void BehaviorNodeInstance::setPropertyBinding(const QString &name, const QString &expression)
{
if (name == "enabled")
return;
ObjectNodeInstance::setPropertyBinding(name, expression);
}
QVariant BehaviorNodeInstance::property(const QString &name) const
{
if (name == "enabled")
return QVariant::fromValue(m_isEnabled);
return ObjectNodeInstance::property(name);
}
void BehaviorNodeInstance::resetProperty(const QString &name)
{
if (name == "enabled")
m_isEnabled = true;
ObjectNodeInstance::resetProperty(name);
}
} // namespace Internal
} // namespace QmlDesigner
#ifndef BEHAVIORNODEINSTANCE_H
#define BEHAVIORNODEINSTANCE_H
#include "objectnodeinstance.h"
namespace QmlDesigner {
namespace Internal {
class BehaviorNodeInstance : public ObjectNodeInstance
{
public:
typedef QSharedPointer<BehaviorNodeInstance> Pointer;
typedef QWeakPointer<BehaviorNodeInstance> WeakPointer;
BehaviorNodeInstance(QObject *object);
static Pointer create(const NodeMetaInfo &metaInfo, QmlContext *context, QObject *objectToBeWrapped);
void setPropertyVariant(const QString &name, const QVariant &value);
void setPropertyBinding(const QString &name, const QString &expression);
QVariant property(const QString &name) const;
void resetProperty(const QString &name);
private:
bool m_isEnabled;
};
} // namespace Internal
} // namespace QmlDesigner
#endif // BEHAVIORNODEINSTANCE_H
......@@ -42,6 +42,7 @@
#include "componentnodeinstance.h"
#include "qmltransitionnodeinstance.h"
#include "qmlpropertychangesnodeinstance.h"
#include "behaviornodeinstance.h"
#include "qmlstatenodeinstance.h"
#include "nodeabstractproperty.h"
#include "variantproperty.h"
......@@ -151,6 +152,8 @@ Internal::ObjectNodeInstance::Pointer NodeInstance::createInstance(const NodeMet
instance = Internal::QmlStateNodeInstance::create(metaInfo, context, objectToBeWrapped);
else if (metaInfo.isSubclassOf("Qt/Transition", 4, 6))
instance = Internal::QmlTransitionNodeInstance::create(metaInfo, context, objectToBeWrapped);
else if (metaInfo.isSubclassOf("Qt/Behavior", 4, 6))
instance = Internal::BehaviorNodeInstance::create(metaInfo, context, objectToBeWrapped);
else if (metaInfo.isSubclassOf("Qt/QtObject", 4, 6))
instance = Internal::ObjectNodeInstance::create(metaInfo, context, objectToBeWrapped);
......
......@@ -42,6 +42,8 @@
#include <QSet>
#include <QStringList>
#include <QtDebug>
namespace QmlDesigner {
static ModelNode createNodeFromNode(const ModelNode &modelNode,const QHash<QString, QString> &idRenamingHash, AbstractView *view);
......@@ -77,6 +79,20 @@ static void syncId(ModelNode &outputNode, const ModelNode &inputNode, const QHas
}
}
static void splitIdInBaseNameAndNumber(const QString &id, QString *baseId, int *number)
{
QRegExp regularExpression("(.*)(\\d*)");
// regularExpression.setMinimal(true);
regularExpression.setPatternSyntax(QRegExp::RegExp2);
regularExpression.indexIn(id);
QStringList splitedList = regularExpression.capturedTexts();
*baseId = regularExpression.cap(1);
qDebug() <<splitedList;
}
static void setupIdRenamingHash(const ModelNode &modelNode, QHash<QString, QString> &idRenamingHash, AbstractView *view)
{
QList<ModelNode> allNodes(modelNode.allSubModelNodes());
......@@ -84,10 +100,14 @@ static void setupIdRenamingHash(const ModelNode &modelNode, QHash<QString, QStri
foreach (const ModelNode &node, allNodes) {
if (!node.id().isEmpty()) {
QString newId = node.id();
int i = 1;
QString baseId;
int number = 1;
splitIdInBaseNameAndNumber(newId, &baseId, &number);
while (view->hasId(newId) || idRenamingHash.contains(newId)) {
newId = node.id() + QString::number(i).toLower();
i++;
newId = baseId + QString::number(number).toLower();
number++;
}
idRenamingHash.insert(node.id(), newId);
}
......
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