aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristiaan Janssen <christiaan.janssen@nokia.com>2011-05-24 11:40:17 +0200
committerKai Koehne <kai.koehne@nokia.com>2011-05-24 13:03:43 +0200
commit3cf5379380e888de8dde18e461a01b1aa653cc93 (patch)
tree3d14186e89c3fe5109075897bebbbc203d489a89
parent779fafcbfe6f92dd1288664fae512f69bc12418b (diff)
QmlLivePreview: removing and inserting animations and transitions
Change-Id: Ic776f63f5d7925ac7dfd99be53c10b9af4cb9545 Reviewed-on: http://codereview.qt.nokia.com/75 Reviewed-by: Kai Koehne <kai.koehne@nokia.com>
-rw-r--r--share/qtcreator/qml/qmljsdebugger/include/qdeclarativeobserverservice.h3
-rw-r--r--share/qtcreator/qml/qmljsdebugger/qdeclarativeobserverservice.cpp11
-rw-r--r--share/qtcreator/qml/qmljsdebugger/qdeclarativeviewobserver.cpp86
-rw-r--r--share/qtcreator/qml/qmljsdebugger/qdeclarativeviewobserver_p.h3
-rw-r--r--src/libs/qmljs/qmljsdelta.cpp12
-rw-r--r--src/libs/qmljs/qmljsdelta.h2
-rw-r--r--src/plugins/qmljsinspector/qmljsclientproxy.cpp4
-rw-r--r--src/plugins/qmljsinspector/qmljsclientproxy.h2
-rw-r--r--src/plugins/qmljsinspector/qmljslivetextpreview.cpp4
-rw-r--r--src/plugins/qmljsinspector/qmljsobserverclient.cpp5
-rw-r--r--src/plugins/qmljsinspector/qmljsobserverclient.h2
11 files changed, 112 insertions, 22 deletions
diff --git a/share/qtcreator/qml/qmljsdebugger/include/qdeclarativeobserverservice.h b/share/qtcreator/qml/qmljsdebugger/include/qdeclarativeobserverservice.h
index ae9f48e07e..5d05f621c1 100644
--- a/share/qtcreator/qml/qmljsdebugger/include/qdeclarativeobserverservice.h
+++ b/share/qtcreator/qml/qmljsdebugger/include/qdeclarativeobserverservice.h
@@ -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
diff --git a/share/qtcreator/qml/qmljsdebugger/qdeclarativeobserverservice.cpp b/share/qtcreator/qml/qmljsdebugger/qdeclarativeobserverservice.cpp
index 54b7e73b50..5249329f27 100644
--- a/share/qtcreator/qml/qmljsdebugger/qdeclarativeobserverservice.cpp
+++ b/share/qtcreator/qml/qmljsdebugger/qdeclarativeobserverservice.cpp
@@ -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: {
diff --git a/share/qtcreator/qml/qmljsdebugger/qdeclarativeviewobserver.cpp b/share/qtcreator/qml/qmljsdebugger/qdeclarativeviewobserver.cpp
index 00ba6b2537..4a13f26317 100644
--- a/share/qtcreator/qml/qmljsdebugger/qdeclarativeviewobserver.cpp
+++ b/share/qtcreator/qml/qmljsdebugger/qdeclarativeviewobserver.cpp
@@ -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();
diff --git a/share/qtcreator/qml/qmljsdebugger/qdeclarativeviewobserver_p.h b/share/qtcreator/qml/qmljsdebugger/qdeclarativeviewobserver_p.h
index aac988fbdd..4b447c512c 100644
--- a/share/qtcreator/qml/qmljsdebugger/qdeclarativeviewobserver_p.h
+++ b/share/qtcreator/qml/qmljsdebugger/qdeclarativeviewobserver_p.h
@@ -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();
diff --git a/src/libs/qmljs/qmljsdelta.cpp b/src/libs/qmljs/qmljsdelta.cpp
index 75caaabc3a..dbc0bfc9ac 100644
--- a/src/libs/qmljs/qmljsdelta.cpp
+++ b/src/libs/qmljs/qmljsdelta.cpp
@@ -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)
{}
diff --git a/src/libs/qmljs/qmljsdelta.h b/src/libs/qmljs/qmljsdelta.h
index f69d892b9b..fdde3bbc44 100644
--- a/src/libs/qmljs/qmljsdelta.h
+++ b/src/libs/qmljs/qmljsdelta.h
@@ -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:
diff --git a/src/plugins/qmljsinspector/qmljsclientproxy.cpp b/src/plugins/qmljsinspector/qmljsclientproxy.cpp
index a3291d5b75..83efb1d5b5 100644
--- a/src/plugins/qmljsinspector/qmljsclientproxy.cpp
+++ b/src/plugins/qmljsinspector/qmljsclientproxy.cpp
@@ -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)
diff --git a/src/plugins/qmljsinspector/qmljsclientproxy.h b/src/plugins/qmljsinspector/qmljsclientproxy.h
index ce37887b5c..b5d79bdb4c 100644
--- a/src/plugins/qmljsinspector/qmljsclientproxy.h
+++ b/src/plugins/qmljsinspector/qmljsclientproxy.h
@@ -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);
diff --git a/src/plugins/qmljsinspector/qmljslivetextpreview.cpp b/src/plugins/qmljsinspector/qmljslivetextpreview.cpp
index 3a7e1e0e9f..687edf7f00 100644
--- a/src/plugins/qmljsinspector/qmljslivetextpreview.cpp
+++ b/src/plugins/qmljsinspector/qmljslivetextpreview.cpp
@@ -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)
diff --git a/src/plugins/qmljsinspector/qmljsobserverclient.cpp b/src/plugins/qmljsinspector/qmljsobserverclient.cpp
index 8f740d80b6..4c25c0b4a0 100644
--- a/src/plugins/qmljsinspector/qmljsobserverclient.cpp
+++ b/src/plugins/qmljsinspector/qmljsobserverclient.cpp
@@ -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));
diff --git a/src/plugins/qmljsinspector/qmljsobserverclient.h b/src/plugins/qmljsinspector/qmljsobserverclient.h
index 4ed64aa8d5..7772de3a82 100644
--- a/src/plugins/qmljsinspector/qmljsobserverclient.h
+++ b/src/plugins/qmljsinspector/qmljsobserverclient.h
@@ -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);