Commit 3cf53793 authored by Christiaan Janssen's avatar Christiaan Janssen Committed by Kai Koehne
Browse files

QmlLivePreview: removing and inserting animations and transitions

Change-Id: Ic776f63f5d7925ac7dfd99be53c10b9af4cb9545
Reviewed-on: http://codereview.qt.nokia.com/75

Reviewed-by: default avatarKai Koehne <kai.koehne@nokia.com>
parent 779fafcb
......@@ -82,8 +82,9 @@ Q_SIGNALS:
void colorPickerToolRequested();
void objectCreationRequested(const QString &qml, QObject *parent,
const QStringList &imports, const QString &filename = QString());
const QStringList &imports, const QString &filename = QString(), int order = -1);
void objectReparentRequested(QObject *object, QObject *newParent);
void objectDeletionRequested(QObject *object);
// 1 = normal speed,
// 1 < x < 16 = slowdown by some factor
......
......@@ -135,14 +135,19 @@ void QDeclarativeObserverService::messageReceived(const QByteArray &message)
QString filename;
QStringList imports;
ds >> qml >> parentId >> imports >> filename;
emit objectCreationRequested(qml, objectForId(parentId), imports, filename);
int order = -1;
if (!ds.atEnd()) {
ds >> order;
}
emit objectCreationRequested(qml, objectForId(parentId), imports, filename, order);
break;
}
case ObserverProtocol::DestroyObject: {
int debugId;
ds >> debugId;
if (QObject* obj = objectForId(debugId))
obj->deleteLater();
if (QObject* obj = objectForId(debugId)) {
emit objectDeletionRequested(obj);
}
break;
}
case ObserverProtocol::MoveObject: {
......
......@@ -159,8 +159,10 @@ QDeclarativeViewObserver::QDeclarativeViewObserver(QDeclarativeView *view, QObje
connect(data->debugService, SIGNAL(selectToolRequested()), data.data(), SLOT(_q_changeToSingleSelectTool()));
connect(data->debugService, SIGNAL(zoomToolRequested()), data.data(), SLOT(_q_changeToZoomTool()));
connect(data->debugService,
SIGNAL(objectCreationRequested(QString,QObject*,QStringList,QString)),
data.data(), SLOT(_q_createQmlObject(QString,QObject*,QStringList,QString)));
SIGNAL(objectCreationRequested(QString,QObject*,QStringList,QString,int)),
data.data(), SLOT(_q_createQmlObject(QString,QObject*,QStringList,QString,int)));
connect(data->debugService,
SIGNAL(objectDeletionRequested(QObject *)), data.data(), SLOT(_q_deleteQmlObject(QObject *)));
connect(data->debugService,
SIGNAL(objectReparentRequested(QObject *, QObject *)),
data.data(), SLOT(_q_reparentQmlObject(QObject *, QObject *)));
......@@ -400,9 +402,56 @@ bool QDeclarativeViewObserver::keyReleaseEvent(QKeyEvent *event)
return true;
}
bool insertObjectInListProperty(QDeclarativeListReference &fromList, int position, QObject *object)
{
QList<QObject *> tmpList;
int i;
if (!(fromList.canCount() && fromList.canAt() && fromList.canAppend() && fromList.canClear()))
return false;
if (position == fromList.count()) {
fromList.append(object);
return true;
}
for (i=0; i<fromList.count(); ++i)
tmpList << fromList.at(i);
fromList.clear();
for (i=0; i<position; ++i)
fromList.append(tmpList.at(i));
fromList.append(object);
for (; i<tmpList.count(); ++i)
fromList.append(tmpList.at(i));
return true;
}
bool removeObjectFromListProperty(QDeclarativeListReference &fromList, QObject *object)
{
QList<QObject *> tmpList;
int i;
if (!(fromList.canCount() && fromList.canAt() && fromList.canAppend() && fromList.canClear()))
return false;
for (i=0; i<fromList.count(); ++i)
if (object != fromList.at(i))
tmpList << fromList.at(i);
fromList.clear();
foreach (QObject *item, tmpList)
fromList.append(item);
return true;
}
void QDeclarativeViewObserverPrivate::_q_createQmlObject(const QString &qml, QObject *parent,
const QStringList &importList,
const QString &filename)
const QString &filename, int order)
{
if (!parent)
return;
......@@ -458,15 +507,22 @@ void QDeclarativeViewObserverPrivate::_q_createQmlObject(const QString &qml, QOb
if (parent->inherits("QDeclarativeAnimationGroup") &&
newObject->inherits("QDeclarativeAbstractAnimation")) {
QDeclarativeListReference animationsList(parent, "animations");
animationsList.append(newObject);
if (order==-1) {
animationsList.append(newObject);
} else {
if (!insertObjectInListProperty(animationsList, order, newObject)) {
animationsList.append(newObject);
}
}
break;
}
// add transition
if (parentItem && newObject->inherits("QDeclarativeTransition")) {
QDeclarativeListReference transitionsList(parentItem,"transitions");
if (transitionsList.count() == 1 && transitionsList.at(0) == 0)
if (transitionsList.count() == 1 && transitionsList.at(0) == 0) {
transitionsList.clear();
}
transitionsList.append(newObject);
break;
}
......@@ -487,6 +543,26 @@ void QDeclarativeViewObserverPrivate::_q_reparentQmlObject(QObject *object, QObj
item->setParentItem(newParentItem);
}
void QDeclarativeViewObserverPrivate::_q_deleteQmlObject(QObject *object)
{
// special cases for transitions/animations
if (object->inherits("QDeclarativeAbstractAnimation")) {
if (object->parent()) {
QDeclarativeListReference animationsList(object->parent(), "animations");
if (removeObjectFromListProperty(animationsList, object))
object->deleteLater();
return;
}
}
if (object->inherits("QDeclarativeTransition")) {
QDeclarativeListReference transitionsList(object->parent(), "transitions");
if (removeObjectFromListProperty(transitionsList, object))
object->deleteLater();
return;
}
}
void QDeclarativeViewObserverPrivate::_q_clearComponentCache()
{
view->engine()->clearComponentCache();
......
......@@ -130,8 +130,9 @@ public slots:
void _q_onCurrentObjectsChanged(QList<QObject*> objects);
void _q_applyChangesFromClient();
void _q_createQmlObject(const QString &qml, QObject *parent,
const QStringList &imports, const QString &filename = QString());
const QStringList &imports, const QString &filename = QString(), int order = 0);
void _q_reparentQmlObject(QObject *, QObject *);
void _q_deleteQmlObject(QObject *);
void _q_changeToSingleSelectTool();
void _q_changeToMarqueeSelectTool();
......
......@@ -391,14 +391,20 @@ void Delta::insert(UiObjectMember *member, UiObjectMember *parentMember, const Q
+ QLatin1Char(':') + QString::number(startLine-importList.count());
foreach(DebugId debugId, debugReferences) {
if (debugId != -1) {
createObject(qmlText, debugId, importList, filename);
int order = 0;
// skip children which are not objects
foreach (const UiObjectMember *child, children(parentMember)) {
if (child == member) break;
if (child->kind == AST::Node::Kind_UiObjectDefinition)
order++;
}
createObject(qmlText, debugId, importList, filename, order);
}
}
newObjects += member;
}
}
void Delta::update(UiObjectMember* oldObject, const QmlJS::Document::Ptr& oldDoc,
UiObjectMember* newObject, const QmlJS::Document::Ptr& newDoc,
const QList<DebugId>& debugReferences)
......@@ -567,7 +573,7 @@ Document::Ptr Delta::previousDocument() const
return m_previousDoc;
}
void Delta::createObject(const QString &, DebugId, const QStringList &, const QString&)
void Delta::createObject(const QString &, DebugId, const QStringList &, const QString&, int)
{}
void Delta::removeObject(int)
{}
......
......@@ -74,7 +74,7 @@ protected:
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);
const QStringList &importList, const QString &filename, int order = 0);
virtual void notifyUnsyncronizableElementChange(AST::UiObjectMember *parent);
private:
......
......@@ -581,10 +581,10 @@ void ClientProxy::showAppOnTop(bool showOnTop)
}
void ClientProxy::createQmlObject(const QString &qmlText, int parentDebugId,
const QStringList &imports, const QString &filename)
const QStringList &imports, const QString &filename, int order)
{
if (isConnected())
m_observerClient->createQmlObject(qmlText, parentDebugId, imports, filename);
m_observerClient->createQmlObject(qmlText, parentDebugId, imports, filename, order);
}
void ClientProxy::destroyQmlObject(int debugId)
......
......@@ -130,7 +130,7 @@ public slots:
void changeToSelectMarqueeTool();
void showAppOnTop(bool showOnTop);
void createQmlObject(const QString &qmlText, int parentDebugId,
const QStringList &imports, const QString &filename = QString());
const QStringList &imports, const QString &filename = QString(), int order = 0);
void destroyQmlObject(int debugId);
void reparentQmlObject(int debugId, int newParent);
void setContextPathIndex(int contextIndex);
......
......@@ -480,11 +480,11 @@ protected:
}
virtual void createObject(const QString& qmlText, DebugId ref,
const QStringList& importList, const QString& filename)
const QStringList& importList, const QString& filename, int order)
{
appliedChangesToViewer = true;
referenceRefreshRequired = true;
m_clientProxy->createQmlObject(qmlText, ref, importList, filename);
m_clientProxy->createQmlObject(qmlText, ref, importList, filename, order);
}
virtual void reparentObject(int debugId, int newParent)
......
......@@ -414,7 +414,7 @@ void QmlJSObserverClient::showAppOnTop(bool showOnTop)
}
void QmlJSObserverClient::createQmlObject(const QString &qmlText, int parentDebugId,
const QStringList &imports, const QString &filename)
const QStringList &imports, const QString &filename, int order)
{
if (!m_connection || !m_connection->isConnected())
return;
......@@ -427,7 +427,8 @@ void QmlJSObserverClient::createQmlObject(const QString &qmlText, int parentDebu
<< qmlText
<< parentDebugId
<< imports
<< filename;
<< filename
<< order;
log(LogSend, cmd, QString("%1 %2 [%3] %4").arg(qmlText, QString::number(parentDebugId),
imports.join(","), filename));
......
......@@ -58,7 +58,7 @@ public:
void showAppOnTop(bool showOnTop);
void createQmlObject(const QString &qmlText, int parentDebugId,
const QStringList &imports, const QString &filename);
const QStringList &imports, const QString &filename, int order);
void destroyQmlObject(int debugId);
void reparentQmlObject(int debugId, int newParent);
......
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