Commit 7d905695 authored by Christiaan Janssen's avatar Christiaan Janssen
Browse files

QmlInspector: Added reparenting of items in the Qml Live Preview. Reviewed by: Lasse Holmstedt

parent 57cc0df0
......@@ -84,6 +84,7 @@ Q_SIGNALS:
void objectCreationRequested(const QString &qml, QObject *parent,
const QStringList &imports, const QString &filename = QString());
void objectReparentRequested(QObject *object, QObject *newParent);
// 1 = normal speed,
// 0 = paused,
......
......@@ -105,6 +105,7 @@ private:
Q_PRIVATE_SLOT(d_func(), void _q_onCurrentObjectsChanged(QList<QObject*>))
Q_PRIVATE_SLOT(d_func(), void _q_applyChangesFromClient())
Q_PRIVATE_SLOT(d_func(), void _q_createQmlObject(const QString &, QObject *, const QStringList &, const QString &))
Q_PRIVATE_SLOT(d_func(), void _q_reparentQmlObject(QObject *, QObject *))
Q_PRIVATE_SLOT(d_func(), void _q_changeToSingleSelectTool())
Q_PRIVATE_SLOT(d_func(), void _q_changeToMarqueeSelectTool())
Q_PRIVATE_SLOT(d_func(), void _q_changeToZoomTool())
......
......@@ -108,6 +108,10 @@ void QDeclarativeDesignDebugServer::messageReceived(const QByteArray &message)
ds >> debugId;
if (QObject* obj = objectForId(debugId))
obj->deleteLater();
} else if (type == "MOVE_OBJECT") {
int debugId, newParent;
ds >> debugId >> newParent;
emit objectReparentRequested(objectForId(debugId), objectForId(newParent));
} else if (type == "OBJECT_ID_LIST") {
int itemCount;
ds >> itemCount;
......
......@@ -98,6 +98,9 @@ QDeclarativeDesignView::QDeclarativeDesignView(QWidget *parent) :
connect(qmlDesignDebugServer(),
SIGNAL(objectCreationRequested(QString,QObject*,QStringList,QString)),
SLOT(_q_createQmlObject(QString,QObject*,QStringList,QString)));
connect(qmlDesignDebugServer(),
SIGNAL(objectReparentRequested(QObject *, QObject *)),
SLOT(_q_reparentQmlObject(QObject *, QObject *)));
connect(qmlDesignDebugServer(), SIGNAL(contextPathIndexChanged(int)), SLOT(_q_changeContextPathIndex(int)));
connect(qmlDesignDebugServer(), SIGNAL(clearComponentCacheRequested()), SLOT(_q_clearComponentCache()));
connect(this, SIGNAL(statusChanged(QDeclarativeView::Status)), SLOT(_q_onStatusChanged(QDeclarativeView::Status)));
......@@ -277,6 +280,19 @@ void QDeclarativeDesignViewPrivate::_q_createQmlObject(const QString &qml, QObje
}
}
void QDeclarativeDesignViewPrivate::_q_reparentQmlObject(QObject *object, QObject *newParent)
{
if (!newParent)
return;
object->setParent(newParent);
QDeclarativeItem *newParentItem = qobject_cast<QDeclarativeItem*>(newParent);
QDeclarativeItem *item = qobject_cast<QDeclarativeItem*>(object);
if (newParentItem && item) {
item->setParentItem(newParentItem);
}
}
void QDeclarativeDesignViewPrivate::_q_clearComponentCache()
{
q->engine()->clearComponentCache();
......
......@@ -122,6 +122,7 @@ public:
void _q_applyChangesFromClient();
void _q_createQmlObject(const QString &qml, QObject *parent,
const QStringList &imports, const QString &filename = QString());
void _q_reparentQmlObject(QObject *, QObject *);
void _q_changeToSingleSelectTool();
void _q_changeToMarqueeSelectTool();
......
......@@ -432,6 +432,14 @@ void Delta::remove(const QList<DebugId>& debugReferences)
}
}
void Delta::reparent(const QList <DebugId> &member, const QList<DebugId> &newParent)
{
if (member.length() != newParent.length()) return;
for (int i=0; i<member.length(); i++)
reparentObject(member.at(i), newParent.at(i));
}
Delta::DebugIdMap Delta::operator()(const Document::Ptr &doc1, const Document::Ptr &doc2, const DebugIdMap &debugIds)
{
......@@ -478,7 +486,8 @@ Delta::DebugIdMap Delta::operator()(const Document::Ptr &doc1, const Document::P
if (!M.contains(parents1.parent.value(x),parents2.parent.value(y))) {
qDebug () << "Delta::operator(): move " << label(y, doc2) << " from " << label(parents1.parent.value(x), doc1)
<< " to " << label(parents2.parent.value(y), doc2) << " ### TODO";
<< " to " << label(parents2.parent.value(y), doc2);
reparent(newDebuggIds.value(y), newDebuggIds.value(parents2.parent.value(y)));
continue;
}
}
......@@ -514,6 +523,8 @@ void Delta::createObject(const QString &, DebugId, const QStringList &, const QS
{}
void Delta::removeObject(int)
{}
void Delta::reparentObject(int, int)
{}
void Delta::resetBindingForObject(int, const QString &)
{}
void Delta::updateMethodBody(DebugId, UiObjectDefinition *, UiScriptBinding *, const QString &, const QString &)
......
......@@ -54,6 +54,7 @@ private:
AST::UiObjectDefinition* newObject, const QmlJS::Document::Ptr& newDoc,
const QList<DebugId>& debugReferences);
void remove(const QList<DebugId> &debugReferences);
void reparent(const QList <DebugId> &member, const QList<DebugId> &newParent);
protected:
virtual void updateScriptBinding(DebugId objectReference,
......@@ -68,6 +69,7 @@ protected:
const QString &methodBody);
virtual void resetBindingForObject(int debugId, const QString &propertyName);
virtual void removeObject(int debugId);
virtual void reparentObject(int debugId, int newParent);
virtual void createObject(const QString &qmlText, DebugId ref,
const QStringList &importList, const QString &filename);
......
......@@ -393,6 +393,12 @@ void ClientProxy::destroyQmlObject(int debugId)
m_designClient->destroyQmlObject(debugId);
}
void ClientProxy::reparentQmlObject(int debugId, int newParent)
{
if (isDesignClientConnected())
m_designClient->reparentQmlObject(debugId, newParent);
}
void ClientProxy::setContextPathIndex(int contextIndex)
{
if (isDesignClientConnected())
......
......@@ -113,6 +113,7 @@ public slots:
void createQmlObject(const QString &qmlText, int parentDebugId,
const QStringList &imports, const QString &filename = QString());
void destroyQmlObject(int debugId);
void reparentQmlObject(int debugId, int newParent);
void setContextPathIndex(int contextIndex);
private slots:
......
......@@ -313,6 +313,20 @@ void QmlJSDesignDebugClient::destroyQmlObject(int debugId)
sendMessage(message);
}
void QmlJSDesignDebugClient::reparentQmlObject(int debugId, int newParent)
{
if (!m_connection || !m_connection->isConnected())
return;
QByteArray message;
QDataStream ds(&message, QIODevice::WriteOnly);
ds << QByteArray("MOVE_OBJECT")
<< debugId
<< newParent;
sendMessage(message);
}
void QmlJSDesignDebugClient::applyChangesToQmlFile()
{
......
......@@ -66,6 +66,7 @@ public:
void createQmlObject(const QString &qmlText, int parentDebugId,
const QStringList &imports, const QString &filename);
void destroyQmlObject(int debugId);
void reparentQmlObject(int debugId, int newParent);
void applyChangesToQmlFile();
void applyChangesFromQmlFile();
......
......@@ -40,7 +40,6 @@
#include <qmljs/qmljsmodelmanagerinterface.h>
#include <qmljs/qmljsdocument.h>
#include <qmljs/qmljsdelta.h>
#include <debugger/debuggerrunner.h>
#include <debugger/debuggerconstants.h>
......
......@@ -514,6 +514,12 @@ protected:
m_clientProxy->createQmlObject(qmlText, ref, importList, filename);
}
virtual void reparentObject(int debugId, int newParent)
{
appliedChangesToViewer = true;
m_clientProxy->reparentQmlObject(debugId, newParent);
}
void checkUnsyncronizableElementChanges(UiObjectDefinition *parentDefinition)
{
if (unsyncronizableChanges == QmlJSLiveTextPreview::NoUnsyncronizableChanges) {
......
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