Commit 4655accd authored by Marco Bubke's avatar Marco Bubke

QmlDesigner.NodeInstances: Add import support

parent 864c3bfc
......@@ -117,7 +117,8 @@ SOURCES += $$PWD/model/abstractview.cpp \
$$PWD/instances/informationcontainer.cpp \
$$PWD/instances/changestatecommand.cpp \
$$PWD/instances/nodeinstanceserverproxy.cpp \
$$PWD/instances/nodeinstanceclientproxy.cpp
$$PWD/instances/nodeinstanceclientproxy.cpp \
$$PWD/instances/addimportcommand.cpp
HEADERS += $$PWD/include/corelib_global.h \
$$PWD/include/abstractview.h \
$$PWD/include/nodeinstanceview.h \
......@@ -233,7 +234,8 @@ HEADERS += $$PWD/include/corelib_global.h \
$$PWD/include/commondefines.h \
$$PWD/instances/changestatecommand.h \
$$PWD/instances/nodeinstanceserverproxy.h \
$$PWD/instances/nodeinstanceclientproxy.h
$$PWD/instances/nodeinstanceclientproxy.h \
$$PWD/instances/addimportcommand.h
contains(CONFIG, plugin) {
# If core.pri has been included in the qmldesigner plugin
......
......@@ -31,6 +31,7 @@
#define IMPORT_H
#include <QtCore/QString>
#include <QStringList>
#include "corelib_global.h"
......@@ -39,8 +40,8 @@ namespace QmlDesigner {
class CORESHARED_EXPORT Import
{
public:
static Import createLibraryImport(const QString &url, const QString &version = QString(), const QString &alias = QString());
static Import createFileImport(const QString &file, const QString &version = QString(), const QString &alias = QString());
static Import createLibraryImport(const QString &url, const QString &version = QString(), const QString &alias = QString(), const QStringList &importPaths = QStringList());
static Import createFileImport(const QString &file, const QString &version = QString(), const QString &alias = QString(), const QStringList &importPaths = QStringList());
static Import empty();
bool isEmpty() const { return m_url.isEmpty() && m_file.isEmpty(); }
......@@ -53,19 +54,21 @@ public:
QString file() const { return m_file; }
QString version() const { return m_version; }
QString alias() const { return m_alias; }
QStringList importPaths() const { return m_importPathList; }
QString toString(bool addSemicolon = false) const;
bool operator==(const Import &other) const;
private:
Import(const QString &url, const QString &file, const QString &version, const QString &alias);
Import(const QString &url, const QString &file, const QString &version, const QString &alias, const QStringList &importPaths);
private:
QString m_url;
QString m_file;
QString m_version;
QString m_alias;
QStringList m_importPathList;
};
CORESHARED_EXPORT uint qHash(const Import &import);
......
......@@ -20,6 +20,7 @@ class ChangeIdsCommand;
class RemoveInstancesCommand;
class RemovePropertiesCommand;
class ChangeStateCommand;
class AddImportCommand;
class NodeInstanceServerInterface : public QObject
{
......@@ -38,6 +39,7 @@ public:
virtual void reparentInstances(const ReparentInstancesCommand &command) = 0;
virtual void changeIds(const ChangeIdsCommand &command) = 0;
virtual void changeState(const ChangeStateCommand &command) = 0;
virtual void addImport(const AddImportCommand &command) = 0;
virtual void setBlockUpdates(bool block) {}
......
......@@ -62,6 +62,7 @@ class ChangeBindingsCommand;
class ChangeIdsCommand;
class RemoveInstancesCommand;
class RemovePropertiesCommand;
class AddImportCommand;
class CORESHARED_EXPORT NodeInstanceView : public AbstractView, public NodeInstanceClientInterface
{
......@@ -92,7 +93,7 @@ public:
void selectedNodesChanged(const QList<ModelNode> &selectedNodeList, const QList<ModelNode> &lastSelectedNodeList);
void scriptFunctionsChanged(const ModelNode &node, const QStringList &scriptFunctionList);
void instancePropertyChange(const QList<QPair<ModelNode, QString> > &propertyList);
void importAdded(const Import &import);
QList<NodeInstance> instances() const;
NodeInstance instanceForNode(const ModelNode &node) const ;
......@@ -149,6 +150,7 @@ private: // functions
RemoveInstancesCommand createRemoveInstancesCommand(const QList<ModelNode> &nodeList) const;
RemoveInstancesCommand createRemoveInstancesCommand(const ModelNode &node) const;
RemovePropertiesCommand createRemovePropertiesCommand(const QList<AbstractProperty> &propertyList) const;
AddImportCommand createImportCommand(const Import &import);
qint32 generateInstanceId();
......
#include "addimportcommand.h"
namespace QmlDesigner {
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)
{
}
QUrl AddImportCommand::url() const
{
return m_url;
}
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();
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;
return in;
}
} // namespace QmlDesigner
#ifndef ADDIMPORTCOMMAND_H
#define ADDIMPORTCOMMAND_H
#include <QMetaType>
#include <QUrl>
#include <QString>
#include <QStringList>
namespace QmlDesigner {
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);
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 AddImportCommand &command);
QDataStream &operator>>(QDataStream &in, AddImportCommand &command);
} // namespace QmlDesigner
Q_DECLARE_METATYPE(QmlDesigner::AddImportCommand);
#endif // ADDIMPORTCOMMAND_H
......@@ -3,6 +3,7 @@ INCLUDEPATH += $$PWD/../include
HEADERS += $$PWD/behaviornodeinstance.h
HEADERS += $$PWD/addimportcommand.h
HEADERS += $$PWD/changebindingscommand.h
HEADERS += $$PWD/changefileurlcommand.h
HEADERS += $$PWD/changeidscommand.h
......@@ -41,6 +42,7 @@ HEADERS += $$PWD/../include/nodeinstanceserverinterface.h
SOURCES += $$PWD/behaviornodeinstance.cpp
SOURCES += $$PWD/addimportcommand.cpp
SOURCES += $$PWD/changebindingscommand.cpp
SOURCES += $$PWD/changefileurlcommand.cpp
SOURCES += $$PWD/changeidscommand.cpp
......
......@@ -22,6 +22,7 @@
#include "reparentinstancescommand.h"
#include "changeidscommand.h"
#include "changestatecommand.h"
#include "addimportcommand.h"
#include "informationchangedcommand.h"
#include "pixmapchangedcommand.h"
......@@ -127,6 +128,7 @@ void NodeInstanceClientProxy::dispatchCommand(const QVariant &command)
static const int reparentInstancesCommandType = QMetaType::type("ReparentInstancesCommand");
static const int changeIdsCommandType = QMetaType::type("ChangeIdsCommand");
static const int changeStateCommandType = QMetaType::type("ChangeStateCommand");
static const int addImportCommandType = QMetaType::type("AddImportCommand");
if (command.userType() == createInstancesCommandType)
nodeInstanceServer()->createInstances(command.value<CreateInstancesCommand>());
......@@ -150,6 +152,8 @@ void NodeInstanceClientProxy::dispatchCommand(const QVariant &command)
nodeInstanceServer()->changeIds(command.value<ChangeIdsCommand>());
else if (command.userType() == changeStateCommandType)
nodeInstanceServer()->changeState(command.value<ChangeStateCommand>());
else if (command.userType() == addImportCommandType)
nodeInstanceServer()->addImport(command.value<AddImportCommand>());
else
Q_ASSERT(false);
}
......
......@@ -10,6 +10,7 @@
#include <QSet>
#include <QVariant>
#include <QMetaType>
#include <QDeclarativeComponent>
#include "servernodeinstance.h"
#include "childrenchangeeventfilter.h"
......@@ -33,6 +34,7 @@
#include "commondefines.h"
#include "childrenchangeeventfilter.h"
#include "changestatecommand.h"
#include "addimportcommand.h"
#include <iostream>
#include <stdio.h>
......@@ -44,7 +46,8 @@ NodeInstanceServer::NodeInstanceServer(NodeInstanceClientInterface *nodeInstance
NodeInstanceServerInterface(),
m_childrenChangeEventFilter(new Internal::ChildrenChangeEventFilter(this)),
m_nodeInstanceClient(nodeInstanceClient),
m_timer(0)
m_timer(0),
m_slowRenderTimer(false)
{
connect(m_childrenChangeEventFilter.data(), SIGNAL(childrenChanged(QObject*)), this, SLOT(emitParentChanged(QObject*)));
}
......@@ -117,8 +120,24 @@ bool NodeInstanceServer::hasInstanceForObject(QObject *object) const
void NodeInstanceServer::startRenderTimer()
{
if (m_slowRenderTimer)
stopRenderTimer();
if (m_timer == 0)
m_timer = startTimer(16);
m_slowRenderTimer = false;
}
void NodeInstanceServer::slowDownRenderTimer()
{
if (!m_slowRenderTimer)
stopRenderTimer();
if (m_timer == 0)
m_timer = startTimer(1000);
m_slowRenderTimer = true;
}
void NodeInstanceServer::stopRenderTimer()
......@@ -135,7 +154,6 @@ void NodeInstanceServer::createScene(const CreateSceneCommand &/*command*/)
m_declarativeView = new QDeclarativeView;
m_declarativeView->setAttribute(Qt::WA_DontShowOnScreen, true);
m_declarativeView->setViewportUpdateMode(QGraphicsView::NoViewportUpdate);
m_declarativeView->viewport()->setUpdatesEnabled(false);
m_declarativeView->show();
if (!m_fileUrl.isEmpty())
......@@ -201,6 +219,35 @@ void NodeInstanceServer::changeState(const ChangeStateCommand &command)
startRenderTimer();
}
void NodeInstanceServer::addImport(const AddImportCommand &command)
{
QString importStatement = QString("import ");
if (!command.fileName().isEmpty())
importStatement += '"' + command.fileName() + '"';
else if (!command.url().isEmpty())
importStatement += command.url().toString();
if (!command.version().isEmpty())
importStatement += " " + command.version();
if (!command.alias().isEmpty())
importStatement += " as " + command.alias();
QDeclarativeComponent importComponent(engine(), 0);
QString componentString = QString("import Qt 4.7\n%1\n Item{}\n").arg(importStatement);
foreach(const QString &importPath, command.importPaths()) {
engine()->addImportPath(importPath);
engine()->addPluginPath(importPath);
}
importComponent.setData(componentString.toLatin1(), QUrl());
if (!importComponent.errorString().isEmpty())
qDebug() << "QmlDesigner.NodeInstances: import wrong: " << importComponent.errorString();
}
void NodeInstanceServer::changeFileUrl(const ChangeFileUrlCommand &command)
{
m_fileUrl = command.fileUrl();
......@@ -598,6 +645,7 @@ void NodeInstanceServer::removeInstanceRelationsip(qint32 instanceId)
PixmapChangedCommand NodeInstanceServer::createPixmapChangedCommand(const ServerNodeInstance &instance) const
{
qDebug() << __FUNCTION__ << instance.internalObject();
return PixmapChangedCommand(instance.instanceId(), instance.renderImage());
}
......@@ -653,8 +701,6 @@ void NodeInstanceServer::findItemChangesAndSendChangeCommands()
if((d->dirty && d->notifyBoundingRectChanged)|| (d->dirty && !d->dirtySceneTransform) || nonInstanceChildIsDirty(graphicsObject))
dirtyInstanceSet.insert(instance);
if (d->geometryChanged) {
if (instance.isRootNodeInstance())
m_declarativeView->scene()->setSceneRect(item->boundingRect());
......@@ -702,7 +748,7 @@ void NodeInstanceServer::findItemChangesAndSendChangeCommands()
}
}
stopRenderTimer();
slowDownRenderTimer();
nodeInstanceClient()->flush();
}
......
......@@ -46,7 +46,7 @@ public:
void removeProperties(const RemovePropertiesCommand &command);
void reparentInstances(const ReparentInstancesCommand &command);
void changeState(const ChangeStateCommand &command);
void addImport(const AddImportCommand &command);
ServerNodeInstance instanceForId(qint32 id) const;
bool hasInstanceForId(qint32 id) const;
......@@ -103,6 +103,7 @@ protected:
void addChangedProperty(const InstancePropertyPair &property);
void startRenderTimer();
void slowDownRenderTimer();
void stopRenderTimer();
private:
......@@ -117,6 +118,7 @@ private:
QUrl m_fileUrl;
NodeInstanceClientInterface *m_nodeInstanceClient;
int m_timer;
bool m_slowRenderTimer;
QVector<InstancePropertyPair> m_changedPropertyList;
};
......
......@@ -20,7 +20,7 @@
#include "informationchangedcommand.h"
#include "pixmapchangedcommand.h"
#include "valueschangedcommand.h"
#include "addimportcommand.h"
namespace QmlDesigner {
......@@ -101,6 +101,9 @@ void NodeInstanceServerInterface::registerCommands()
qRegisterMetaType<IdContainer>("IdContainer");
qRegisterMetaTypeStreamOperators<IdContainer>("IdContainer");
qRegisterMetaType<AddImportCommand>("AddImportCommand");
qRegisterMetaTypeStreamOperators<AddImportCommand>("AddImportCommand");
}
}
......@@ -21,6 +21,7 @@
#include "reparentinstancescommand.h"
#include "changeidscommand.h"
#include "changestatecommand.h"
#include "addimportcommand.h"
#include "informationchangedcommand.h"
#include "pixmapchangedcommand.h"
......@@ -199,4 +200,8 @@ void NodeInstanceServerProxy::changeState(const ChangeStateCommand &command)
writeCommand(QVariant::fromValue(command));
}
void NodeInstanceServerProxy::addImport(const AddImportCommand &command)
{
writeCommand(QVariant::fromValue(command));
}
} // namespace QmlDesigner
......@@ -36,6 +36,7 @@ public:
void reparentInstances(const ReparentInstancesCommand &command);
void changeIds(const ChangeIdsCommand &command);
void changeState(const ChangeStateCommand &command);
void addImport(const AddImportCommand &command);
void setBlockUpdates(bool block);
......
......@@ -70,6 +70,7 @@
#include "pixmapchangedcommand.h"
#include "informationchangedcommand.h"
#include "changestatecommand.h"
#include "addimportcommand.h"
#include "nodeinstanceserverproxy.h"
......@@ -139,6 +140,8 @@ void NodeInstanceView::modelAttached(Model *model)
nodeInstanceServer()->createScene(createCreateSceneCommand());
nodeInstanceServer()->changeFileUrl(createChangeFileUrlCommand(model->fileUrl()));
foreach(const Import &import, model->imports())
nodeInstanceServer()->addImport(createImportCommand(import));
loadNodes(allModelNodes());
setBlockUpdates(false);
......@@ -422,6 +425,10 @@ void NodeInstanceView::instancePropertyChange(const QList<QPair<ModelNode, QStri
}
void NodeInstanceView::importAdded(const Import &import)
{
nodeInstanceServer()->addImport(createImportCommand(import));
}
//\}
......@@ -861,6 +868,11 @@ RemovePropertiesCommand NodeInstanceView::createRemovePropertiesCommand(const QL
return RemovePropertiesCommand(containerList);
}
AddImportCommand NodeInstanceView::createImportCommand(const Import &import)
{
return AddImportCommand(import.url(), import.file(), import.version(), import.alias(), import.importPaths());
}
void NodeInstanceView::valuesChanged(const ValuesChangedCommand &command)
{
foreach(const PropertyValueContainer &container, command.valueChanges()) {
......
......@@ -33,26 +33,27 @@
namespace QmlDesigner {
Import Import::createLibraryImport(const QString &url, const QString &version, const QString &alias)
Import Import::createLibraryImport(const QString &url, const QString &version, const QString &alias, const QStringList &importPaths)
{
return Import(url, QString(), version, alias);
return Import(url, QString(), version, alias, importPaths);
}
Import Import::createFileImport(const QString &file, const QString &version, const QString &alias)
Import Import::createFileImport(const QString &file, const QString &version, const QString &alias, const QStringList &importPaths)
{
return Import(QString(), file, version, alias);
return Import(QString(), file, version, alias, importPaths);
}
Import Import::empty()
{
return Import(QString(), QString(), QString(), QString());
return Import(QString(), QString(), QString(), QString(), QStringList());
}
Import::Import(const QString &url, const QString &file, const QString &version, const QString &alias):
Import::Import(const QString &url, const QString &file, const QString &version, const QString &alias, const QStringList &importPaths):
m_url(url),
m_file(file),
m_version(version),
m_alias(alias)
m_alias(alias),
m_importPathList(importPaths)
{
}
......
......@@ -536,13 +536,13 @@ void TextToModelMerger::setupImports(const Document::Ptr &doc,
if (import->fileName) {
const QString strippedFileName = stripQuotes(import->fileName->asString());
const Import newImport = Import::createFileImport(strippedFileName,
version, as);
version, as, m_rewriterView->textModifier()->importPaths());
if (!existingImports.removeOne(newImport))
differenceHandler.modelMissesImport(newImport);
} else {
const Import newImport =
Import::createLibraryImport(flatten(import->importUri), version, as);
Import::createLibraryImport(flatten(import->importUri), version, as, m_rewriterView->textModifier()->importPaths());
if (!existingImports.removeOne(newImport))
differenceHandler.modelMissesImport(newImport);
......
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