Commit 3bec12a4 authored by Kai Koehne's avatar Kai Koehne
Browse files

QmlJsDebugger: Avoid CURRENT_OBJECTS_CHANGED message flooding

parent dcebdcd6
......@@ -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");
......
......@@ -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);
......
......@@ -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;
......
......@@ -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;
......
......@@ -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(); }
};
......
Supports Markdown
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