Commit 42a86035 authored by Marco Bubke's avatar Marco Bubke
Browse files

QmlDesigner.NodeInstances: Refactor scene creation

parent 2f787df3
......@@ -106,7 +106,8 @@ SOURCES += $$PWD/model/abstractview.cpp \
$$PWD/instances/statepreviewimagechangedcommand.cpp \
$$PWD/instances/imagecontainer.cpp \
$$PWD/instances/completecomponentcommand.cpp \
$$PWD/instances/componentcompletedcommand.cpp
$$PWD/instances/componentcompletedcommand.cpp \
$$PWD/instances/addimportcontainer.cpp
HEADERS += $$PWD/include/corelib_global.h \
$$PWD/include/abstractview.h \
......@@ -212,7 +213,8 @@ HEADERS += $$PWD/include/corelib_global.h \
$$PWD/instances/statepreviewimagechangedcommand.h \
$$PWD/instances/imagecontainer.h \
$$PWD/instances/completecomponentcommand.h \
$$PWD/instances/componentcompletedcommand.h
$$PWD/instances/componentcompletedcommand.h \
$$PWD/instances/addimportcontainer.h
contains(CONFIG, plugin) {
# If core.pri has been included in the qmldesigner plugin
SOURCES += $$PWD/model/basetexteditmodifier.cpp
......
......@@ -6,58 +6,27 @@ AddImportCommand::AddImportCommand()
{
}
AddImportCommand::AddImportCommand(const QUrl &url, const QString &fileName, const QString &version, const QString &alias, const QStringList &importPathList)
: m_url(url),
m_fileName(fileName),
m_version(version),
m_alias(alias),
m_importPathList(importPathList)
AddImportCommand::AddImportCommand(const AddImportContainer &container)
: m_importContainer(container)
{
}
QUrl AddImportCommand::url() const
AddImportContainer AddImportCommand::import() const
{
return m_url;
return m_importContainer;
}
QString AddImportCommand::fileName() const
{
return m_fileName;
}
QString AddImportCommand::version() const
{
return m_version;
}
QString AddImportCommand::alias() const
{
return m_alias;
}
QStringList AddImportCommand::importPaths() const
{
return m_importPathList;
}
QDataStream &operator<<(QDataStream &out, const AddImportCommand &command)
{
out << command.url();
out << command.fileName();
out << command.version();
out << command.alias();
out << command.importPaths();
out << command.import();
return out;
}
QDataStream &operator>>(QDataStream &in, AddImportCommand &command)
{
in >> command.m_url;
in >> command.m_fileName;
in >> command.m_version;
in >> command.m_alias;
in >> command.m_importPathList;
in >> command.m_importContainer;
return in;
}
......
#ifndef ADDIMPORTCOMMAND_H
#define ADDIMPORTCOMMAND_H
#include <QMetaType>
#include <QUrl>
#include <QString>
#include <QStringList>
#include "addimportcontainer.h"
namespace QmlDesigner {
......@@ -13,20 +10,12 @@ class AddImportCommand
friend QDataStream &operator>>(QDataStream &in, AddImportCommand &command);
public:
AddImportCommand();
AddImportCommand(const QUrl &url, const QString &fileName, const QString &version, const QString &alias, const QStringList &mportPathList);
AddImportCommand(const AddImportContainer &container);
QUrl url() const;
QString fileName() const;
QString version() const;
QString alias() const;
QStringList importPaths() const;
AddImportContainer import() const;
private:
QUrl m_url;
QString m_fileName;
QString m_version;
QString m_alias;
QStringList m_importPathList;
AddImportContainer m_importContainer;
};
QDataStream &operator<<(QDataStream &out, const AddImportCommand &command);
......
#include "addimportcontainer.h"
namespace QmlDesigner {
AddImportContainer::AddImportContainer()
{
}
AddImportContainer::AddImportContainer(const QUrl &url, const QString &fileName, const QString &version, const QString &alias, const QStringList &importPathList)
: m_url(url),
m_fileName(fileName),
m_version(version),
m_alias(alias),
m_importPathList(importPathList)
{
}
QUrl AddImportContainer::url() const
{
return m_url;
}
QString AddImportContainer::fileName() const
{
return m_fileName;
}
QString AddImportContainer::version() const
{
return m_version;
}
QString AddImportContainer::alias() const
{
return m_alias;
}
QStringList AddImportContainer::importPaths() const
{
return m_importPathList;
}
QDataStream &operator<<(QDataStream &out, const AddImportContainer &command)
{
out << command.url();
out << command.fileName();
out << command.version();
out << command.alias();
out << command.importPaths();
return out;
}
QDataStream &operator>>(QDataStream &in, AddImportContainer &command)
{
in >> command.m_url;
in >> command.m_fileName;
in >> command.m_version;
in >> command.m_alias;
in >> command.m_importPathList;
return in;
}
} // namespace QmlDesigner
#ifndef ADDIMPORTCONTAINER_H
#define ADDIMPORTCONTAINER_H
#include <QMetaType>
#include <QUrl>
#include <QString>
#include <QStringList>
namespace QmlDesigner {
class AddImportContainer
{
friend QDataStream &operator>>(QDataStream &in, AddImportContainer &command);
public:
AddImportContainer();
AddImportContainer(const QUrl &url, const QString &fileName, const QString &version, const QString &alias, const QStringList &mportPathList);
QUrl url() const;
QString fileName() const;
QString version() const;
QString alias() const;
QStringList importPaths() const;
private:
QUrl m_url;
QString m_fileName;
QString m_version;
QString m_alias;
QStringList m_importPathList;
};
QDataStream &operator<<(QDataStream &out, const AddImportContainer &command);
QDataStream &operator>>(QDataStream &in, AddImportContainer &command);
} // namespace QmlDesigner
Q_DECLARE_METATYPE(QmlDesigner::AddImportContainer)
#endif // ADDIMPORTCONTAINER_H
......@@ -11,12 +11,14 @@ CreateSceneCommand::CreateSceneCommand(const QVector<InstanceContainer> &instanc
const QVector<IdContainer> &idVector,
const QVector<PropertyValueContainer> &valueChangeVector,
const QVector<PropertyBindingContainer> &bindingChangeVector,
const QVector<AddImportContainer> &importVector,
const QUrl &fileUrl)
: m_instanceVector(instanceContainer),
m_reparentInstanceVector(reparentContainer),
m_idVector(idVector),
m_valueChangeVector(valueChangeVector),
m_bindingChangeVector(bindingChangeVector),
m_importVector(importVector),
m_fileUrl(fileUrl)
{
}
......@@ -46,6 +48,11 @@ QVector<PropertyBindingContainer> CreateSceneCommand::bindingChanges() const
return m_bindingChangeVector;
}
QVector<AddImportContainer> CreateSceneCommand::imports() const
{
return m_importVector;
}
QUrl CreateSceneCommand::fileUrl() const
{
return m_fileUrl;
......@@ -58,6 +65,7 @@ QDataStream &operator<<(QDataStream &out, const CreateSceneCommand &command)
out << command.ids();
out << command.valueChanges();
out << command.bindingChanges();
out << command.imports();
out << command.fileUrl();
return out;
......@@ -70,6 +78,7 @@ QDataStream &operator>>(QDataStream &in, CreateSceneCommand &command)
in >> command.m_idVector;
in >> command.m_valueChangeVector;
in >> command.m_bindingChangeVector;
in >> command.m_importVector;
in >> command.m_fileUrl;
return in;
......
......@@ -10,7 +10,7 @@
#include "idcontainer.h"
#include "propertyvaluecontainer.h"
#include "propertybindingcontainer.h"
#include "addimportcontainer.h"
namespace QmlDesigner {
......@@ -25,6 +25,7 @@ public:
const QVector<IdContainer> &idVector,
const QVector<PropertyValueContainer> &valueChangeVector,
const QVector<PropertyBindingContainer> &bindingChangeVector,
const QVector<AddImportContainer> &importVector,
const QUrl &fileUrl);
QVector<InstanceContainer> instances() const;
......@@ -32,6 +33,7 @@ public:
QVector<IdContainer> ids() const;
QVector<PropertyValueContainer> valueChanges() const;
QVector<PropertyBindingContainer> bindingChanges() const;
QVector<AddImportContainer> imports() const;
QUrl fileUrl() const;
private:
......@@ -40,6 +42,7 @@ private:
QVector<IdContainer> m_idVector;
QVector<PropertyValueContainer> m_valueChangeVector;
QVector<PropertyBindingContainer> m_bindingChangeVector;
QVector<AddImportContainer> m_importVector;
QUrl m_fileUrl;
};
......
......@@ -3,6 +3,8 @@ INCLUDEPATH += $$PWD/../include
HEADERS += $$PWD/behaviornodeinstance.h
HEADERS += $$PWD/addimportcontainer.h
HEADERS += $$PWD/previewnodeinstanceserver.h
HEADERS += $$PWD/componentcompletedcommand.h
HEADERS += $$PWD//completecomponentcommand.h
HEADERS += $$PWDstatepreviewimagechangedcommand.h
......@@ -47,6 +49,8 @@ HEADERS += $$PWD/../include/nodeinstanceserverinterface.h
SOURCES += $$PWD/behaviornodeinstance.cpp
SOURCES += $$PWD/addimportcontainer.cpp
SOURCES += $$PWD/previewnodeinstanceserver.cpp
SOURCES += $$PWD/componentcompletedcommand.cpp
SOURCES += $$PWD/completecomponentcommand.cpp
SOURCES += $$PWD/statepreviewimagechangedcommand.cpp
......
......@@ -6,6 +6,7 @@
#include <QStringList>
#include "nodeinstanceserver.h"
#include "previewnodeinstanceserver.h"
#include "propertyabstractcontainer.h"
#include "propertyvaluecontainer.h"
......@@ -37,7 +38,8 @@ namespace QmlDesigner {
NodeInstanceClientProxy::NodeInstanceClientProxy(QObject *parent)
: QObject(parent),
m_nodeinstanceServer(new NodeInstanceServer(this)),
m_nodeInstanceServer(new NodeInstanceServer(this)),
m_baseStateNodeInstancePreview(new PreviewNodeInstanceServer(this)),
m_blockSize(0)
{
m_slowSocket = new QLocalSocket(this);
......@@ -148,7 +150,72 @@ void NodeInstanceClientProxy::readDataStream()
NodeInstanceServerInterface *NodeInstanceClientProxy::nodeInstanceServer() const
{
return m_nodeinstanceServer;
return m_nodeInstanceServer;
}
void NodeInstanceClientProxy::createInstances(const CreateInstancesCommand &command)
{
nodeInstanceServer()->createInstances(command);
}
void NodeInstanceClientProxy::changeFileUrl(const ChangeFileUrlCommand &command)
{
nodeInstanceServer()->changeFileUrl(command);
}
void NodeInstanceClientProxy::createScene(const CreateSceneCommand &command)
{
nodeInstanceServer()->createScene(command);
}
void NodeInstanceClientProxy::clearScene(const ClearSceneCommand &command)
{
nodeInstanceServer()->clearScene(command);
}
void NodeInstanceClientProxy::removeInstances(const RemoveInstancesCommand &command)
{
nodeInstanceServer()->removeInstances(command);
}
void NodeInstanceClientProxy::removeProperties(const RemovePropertiesCommand &command)
{
nodeInstanceServer()->removeProperties(command);
}
void NodeInstanceClientProxy::changePropertyBindings(const ChangeBindingsCommand &command)
{
nodeInstanceServer()->changePropertyBindings(command);
}
void NodeInstanceClientProxy::changePropertyValues(const ChangeValuesCommand &command)
{
nodeInstanceServer()->changePropertyValues(command);
}
void NodeInstanceClientProxy::reparentInstances(const ReparentInstancesCommand &command)
{
nodeInstanceServer()->reparentInstances(command);
}
void NodeInstanceClientProxy::changeIds(const ChangeIdsCommand &command)
{
nodeInstanceServer()->changeIds(command);
}
void NodeInstanceClientProxy::changeState(const ChangeStateCommand &command)
{
nodeInstanceServer()->changeState(command);
}
void NodeInstanceClientProxy::addImport(const AddImportCommand &command)
{
nodeInstanceServer()->addImport(command);
}
void NodeInstanceClientProxy::completeComponent(const CompleteComponentCommand &command)
{
nodeInstanceServer()->completeComponent(command);
}
void NodeInstanceClientProxy::dispatchCommand(const QVariant &command)
......@@ -167,32 +234,32 @@ void NodeInstanceClientProxy::dispatchCommand(const QVariant &command)
static const int addImportCommandType = QMetaType::type("AddImportCommand");
static const int completeComponentCommandType = QMetaType::type("CompleteComponentCommand");
if (command.userType() == createInstancesCommandType)
nodeInstanceServer()->createInstances(command.value<CreateInstancesCommand>());
else if (command.userType() == changeFileUrlCommandType)
nodeInstanceServer()->changeFileUrl(command.value<ChangeFileUrlCommand>());
if (command.userType() == createInstancesCommandType) {
createInstances(command.value<CreateInstancesCommand>());
} else if (command.userType() == changeFileUrlCommandType)
changeFileUrl(command.value<ChangeFileUrlCommand>());
else if (command.userType() == createSceneCommandType)
nodeInstanceServer()->createScene(command.value<CreateSceneCommand>());
createScene(command.value<CreateSceneCommand>());
else if (command.userType() == clearSceneCommandType)
nodeInstanceServer()->clearScene(command.value<ClearSceneCommand>());
clearScene(command.value<ClearSceneCommand>());
else if (command.userType() == removeInstancesCommandType)
nodeInstanceServer()->removeInstances(command.value<RemoveInstancesCommand>());
removeInstances(command.value<RemoveInstancesCommand>());
else if (command.userType() == removePropertiesCommandType)
nodeInstanceServer()->removeProperties(command.value<RemovePropertiesCommand>());
removeProperties(command.value<RemovePropertiesCommand>());
else if (command.userType() == changeBindingsCommandType)
nodeInstanceServer()->changePropertyBindings(command.value<ChangeBindingsCommand>());
changePropertyBindings(command.value<ChangeBindingsCommand>());
else if (command.userType() == changeValuesCommandType)
nodeInstanceServer()->changePropertyValues(command.value<ChangeValuesCommand>());
changePropertyValues(command.value<ChangeValuesCommand>());
else if (command.userType() == reparentInstancesCommandType)
nodeInstanceServer()->reparentInstances(command.value<ReparentInstancesCommand>());
reparentInstances(command.value<ReparentInstancesCommand>());
else if (command.userType() == changeIdsCommandType)
nodeInstanceServer()->changeIds(command.value<ChangeIdsCommand>());
changeIds(command.value<ChangeIdsCommand>());
else if (command.userType() == changeStateCommandType)
nodeInstanceServer()->changeState(command.value<ChangeStateCommand>());
changeState(command.value<ChangeStateCommand>());
else if (command.userType() == addImportCommandType)
nodeInstanceServer()->addImport(command.value<AddImportCommand>());
addImport(command.value<AddImportCommand>());
else if (command.userType() == completeComponentCommandType)
nodeInstanceServer()->completeComponent(command.value<CompleteComponentCommand>());
completeComponent(command.value<CompleteComponentCommand>());
else
Q_ASSERT(false);
}
......
......@@ -4,6 +4,8 @@
#include "nodeinstanceclientinterface.h"
#include <QObject>
#include <QHash>
#include <QWeakPointer>
QT_BEGIN_NAMESPACE
class QLocalSocket;
......@@ -12,6 +14,19 @@ QT_END_NAMESPACE
namespace QmlDesigner {
class NodeInstanceServerInterface;
class CreateSceneCommand;
class CreateInstancesCommand;
class ClearSceneCommand;
class ReparentInstancesCommand;
class ChangeFileUrlCommand;
class ChangeValuesCommand;
class ChangeBindingsCommand;
class ChangeIdsCommand;
class RemoveInstancesCommand;
class RemovePropertiesCommand;
class AddImportCommand;
class CompleteComponentCommand;
class ChangeStateCommand;
class NodeInstanceClientProxy : public QObject, public NodeInstanceClientInterface
{
......@@ -36,13 +51,29 @@ protected:
void dispatchCommand(const QVariant &command);
NodeInstanceServerInterface *nodeInstanceServer() const;
void createInstances(const CreateInstancesCommand &command);
void changeFileUrl(const ChangeFileUrlCommand &command);
void createScene(const CreateSceneCommand &command);
void clearScene(const ClearSceneCommand &command);
void removeInstances(const RemoveInstancesCommand &command);
void removeProperties(const RemovePropertiesCommand &command);
void changePropertyBindings(const ChangeBindingsCommand &command);
void changePropertyValues(const ChangeValuesCommand &command);
void reparentInstances(const ReparentInstancesCommand &command);
void changeIds(const ChangeIdsCommand &command);
void changeState(const ChangeStateCommand &command);
void addImport(const AddImportCommand &command);
void completeComponent(const CompleteComponentCommand &command);
private slots:
void readDataStream();
private:
QLocalSocket *m_slowSocket;
QLocalSocket *m_fastSocket;
NodeInstanceServerInterface *m_nodeinstanceServer;
NodeInstanceServerInterface *m_nodeInstanceServer;
NodeInstanceServerInterface *m_baseStateNodeInstancePreview;
QHash<qint32, QWeakPointer<NodeInstanceServerInterface> > m_nodeInstancePreviewVector;
quint32 m_blockSize;
};
......
......@@ -53,12 +53,8 @@ NodeInstanceServer::NodeInstanceServer(NodeInstanceClientInterface *nodeInstance
m_timer(0),
m_slowRenderTimer(false)
{
m_importList.append("import Qt 4.7");
connect(m_childrenChangeEventFilter.data(), SIGNAL(childrenChanged(QObject*)), this, SLOT(emitParentChanged(QObject*)));
m_declarativeView = new QDeclarativeView;
m_declarativeView->setAttribute(Qt::WA_DontShowOnScreen, true);
m_declarativeView->setViewportUpdateMode(QGraphicsView::NoViewportUpdate);
m_declarativeView->show();
}
NodeInstanceServer::~NodeInstanceServer()
......@@ -159,9 +155,18 @@ void NodeInstanceServer::stopRenderTimer()
void NodeInstanceServer::createScene(const CreateSceneCommand &command)
{
Q_ASSERT(!m_declarativeView.data());
m_declarativeView = new QDeclarativeView;
m_declarativeView->setAttribute(Qt::WA_DontShowOnScreen, true);
m_declarativeView->setViewportUpdateMode(QGraphicsView::NoViewportUpdate);
m_declarativeView->show();
if (!command.fileUrl().isEmpty())
engine()->setBaseUrl(command.fileUrl());
addImports(command.imports());
static_cast<QGraphicsScenePrivate*>(QObjectPrivate::get(m_declarativeView->scene()))->processDirtyItemsEmitted = true;
QList<ServerNodeInstance> instanceList = createInstances(command.instances());
......@@ -270,30 +275,37 @@ void NodeInstanceServer::completeComponent(const CompleteComponentCommand &comma
nodeInstanceClient()->componentCompleted(createComponentCompletedCommand(instanceList));
}
void NodeInstanceServer::addImport(const AddImportCommand &command)
void NodeInstanceServer::addImports(const QVector<AddImportContainer> &containerVector)
{
QString importStatement = QString("import ");
foreach (const AddImportContainer &container, containerVector) {
QString importStatement = QString("import ");
if (!container.fileName().isEmpty())
importStatement += '"' + container.fileName() + '"';
else if (!container.url().isEmpty())
importStatement += container.url().toString();
if (!command.fileName().isEmpty())
importStatement += '"' + command.fileName() + '"';
else if (!command.url().isEmpty())
importStatement += command.url().toString();
if (!container.version().isEmpty())
importStatement += " " + container.version();
if (!command.version().isEmpty())
importStatement += " " + command.version();
if (!container.alias().isEmpty())
importStatement += " as " + container.alias();
if (!