OSDN Git Service

QmlJsDebugger: Avoid CURRENT_OBJECTS_CHANGED message flooding
authorKai Koehne <kai.koehne@nokia.com>
Fri, 22 Oct 2010 10:41:39 +0000 (12:41 +0200)
committerKai Koehne <kai.koehne@nokia.com>
Fri, 12 Nov 2010 14:08:09 +0000 (15:08 +0100)
share/qtcreator/qml/qmljsdebugger/editor/abstractformeditortool.cpp
share/qtcreator/qml/qmljsdebugger/editor/abstractformeditortool.h
share/qtcreator/qml/qmljsdebugger/include/qdeclarativeviewobserver.h
share/qtcreator/qml/qmljsdebugger/qdeclarativeviewobserver.cpp
share/qtcreator/qml/qmljsdebugger/qdeclarativeviewobserver_p.h

index dea47b7..27a6c55 100644 (file)
@@ -153,18 +153,6 @@ QList<QGraphicsObject*> AbstractFormEditorTool::toGraphicsObjectList(const QList
     return gfxObjects;
 }
 
-QList<QObject*> AbstractFormEditorTool::toObjectList(const QList<QGraphicsItem*> &itemList)
-{
-    QList<QObject*> objects;
-    foreach(QGraphicsItem *item, itemList) {
-        QObject *obj = item->toGraphicsObject();
-        if (obj)
-            objects << obj;
-    }
-
-    return objects;
-}
-
 QString AbstractFormEditorTool::titleForItem(QGraphicsItem *item)
 {
     QString className("QGraphicsItem");
index 63f50c8..c9bf4a5 100644 (file)
@@ -83,7 +83,6 @@ public:
     bool topSelectedItemIsMovable(const QList<QGraphicsItem*> &itemList);
 
     static QString titleForItem(QGraphicsItem *item);
-    static QList<QObject*> toObjectList(const QList<QGraphicsItem*> &itemList);
     static QList<QGraphicsObject*> toGraphicsObjectList(const QList<QGraphicsItem*> &itemList);
     static QGraphicsItem* topMovableGraphicsItem(const QList<QGraphicsItem*> &itemList);
     static QDeclarativeItem* topMovableDeclarativeItem(const QList<QGraphicsItem*> &itemList);
index fbfdf2a..e8f3194 100644 (file)
@@ -115,6 +115,7 @@ private:
     Q_PRIVATE_SLOT(d_func(), void _q_changeToColorPickerTool())
     Q_PRIVATE_SLOT(d_func(), void _q_changeContextPathIndex(int index))
     Q_PRIVATE_SLOT(d_func(), void _q_clearComponentCache());
+    Q_PRIVATE_SLOT(d_func(), void _q_removeFromSelection(QObject *));
 
     inline QDeclarativeViewObserverPrivate *d_func() { return data.data(); }
     QScopedPointer<QDeclarativeViewObserverPrivate> data;
index 20c9c44..d028e78 100644 (file)
@@ -125,8 +125,9 @@ void QDeclarativeViewObserver::setObserverContext(int contextIndex)
 {
     if (data->subcomponentEditorTool->contextIndex() != contextIndex) {
         QGraphicsObject *object = data->subcomponentEditorTool->setContext(contextIndex);
-        if (object)
-            data->debugService->setCurrentObjects(QList<QObject*>() << object);
+        if (object) {
+            setSelectedItems(QList<QGraphicsItem*>() << object);
+        }
     }
 }
 
@@ -244,8 +245,6 @@ bool QDeclarativeViewObserver::mouseReleaseEvent(QMouseEvent *event)
 
     data->cursorPos = event->pos();
     data->currentTool->mouseReleaseEvent(event);
-
-    data->debugService->setCurrentObjects(AbstractFormEditorTool::toObjectList(selectedItems()));
     return true;
 }
 
@@ -342,6 +341,15 @@ void QDeclarativeViewObserverPrivate::_q_clearComponentCache()
     view->engine()->clearComponentCache();
 }
 
+void QDeclarativeViewObserverPrivate::_q_removeFromSelection(QObject *obj)
+{
+    QList<QGraphicsItem*> items = selectedItems();
+    if (QGraphicsItem *item = dynamic_cast<QGraphicsItem*>(obj)) {
+        items.removeOne(item);
+    }
+    setSelectedItems(items);
+}
+
 QGraphicsItem *QDeclarativeViewObserverPrivate::currentRootItem() const
 {
     return subcomponentEditorTool->currentRootItem();
@@ -374,8 +382,9 @@ bool QDeclarativeViewObserver::mouseDoubleClickEvent(QMouseEvent *event)
 
     if ((event->buttons() & Qt::LeftButton) && itemToEnter) {
         QGraphicsObject *objectToEnter = itemToEnter->toGraphicsObject();
-        if (objectToEnter)
-            data->debugService->setCurrentObjects(QList<QObject*>() << objectToEnter);
+        if (objectToEnter) {
+            setSelectedItems(QList<QGraphicsItem*>() << objectToEnter);
+        }
     }
 
     return true;
@@ -440,32 +449,51 @@ void QDeclarativeViewObserverPrivate::changeTool(Constants::DesignTool tool, Con
 
 void QDeclarativeViewObserverPrivate::setSelectedItemsForTools(QList<QGraphicsItem *> items)
 {
-    currentSelection.clear();
-    foreach(QGraphicsItem *item, items) {
+    foreach (QWeakPointer<QGraphicsObject> obj, currentSelection) {
+        if (QGraphicsItem *item = obj.data()) {
+            if (!items.contains(item)) {
+                QObject::disconnect(obj.data(), SIGNAL(destroyed(QObject*)),
+                                    q, SLOT(_q_removeFromSelection(QObject*)));
+                currentSelection.removeOne(obj);
+            }
+        }
+    }
+
+    foreach (QGraphicsItem *item, items) {
         if (item) {
             QGraphicsObject *obj = item->toGraphicsObject();
-            if (obj)
-                currentSelection << obj;
+            if (obj) {
+                QObject::connect(obj, SIGNAL(destroyed(QObject*)),
+                                 q, SLOT(_q_removeFromSelection(QObject*)));
+                currentSelection.append(obj);
+            }
         }
     }
+
     currentTool->updateSelectedItems();
 }
 
 void QDeclarativeViewObserverPrivate::setSelectedItems(QList<QGraphicsItem *> items)
 {
+    QList<QWeakPointer<QGraphicsObject> > oldList = currentSelection;
     setSelectedItemsForTools(items);
-    debugService->setCurrentObjects(AbstractFormEditorTool::toObjectList(items));
+    if (oldList != currentSelection) {
+        QList<QObject*> objectList;
+        foreach (QWeakPointer<QGraphicsObject> graphicsObject, currentSelection) {
+            if (graphicsObject)
+                objectList << graphicsObject.data();
+        }
+
+        debugService->setCurrentObjects(objectList);
+    }
 }
 
 QList<QGraphicsItem *> QDeclarativeViewObserverPrivate::selectedItems()
 {
     QList<QGraphicsItem *> selection;
     foreach(const QWeakPointer<QGraphicsObject> &selectedObject, currentSelection) {
-        if (selectedObject.isNull()) {
-            currentSelection.removeOne(selectedObject);
-        } else {
+        if (selectedObject.data())
             selection << selectedObject.data();
-        }
     }
 
     return selection;
index 4f90a28..d3e52e3 100644 (file)
@@ -130,6 +130,7 @@ public:
     void _q_changeToColorPickerTool();
     void _q_changeContextPathIndex(int index);
     void _q_clearComponentCache();
+    void _q_removeFromSelection(QObject *);
 
     static QDeclarativeViewObserverPrivate *get(QDeclarativeViewObserver *v) { return v->d_func(); }
 };