Deactivating an inactive panel no longer causes unwanted deactivation.

QGraphicsItem::setActive() is by design not guarded against calls that
do not change the current activation state of the item (e.g., calling
setActive(true) on an active item or calling setActive(false) on an
inactive item). This is to ensure that it's possible to set explicit
activation state on items, either before they are added to a scene, or
while the scene itself is inactive.

Before this fix, calling setActive(false) on a panel item that is not
currently active would by accident clear activation from any other
panel that might have focus. After this fix, activation is only cleared
if the item setActive() was called on itself is the active panel, or
is the panel that will regain activation once the scene is reactivated.

Task-number: QTBUG-28544
Change-Id: Ic4752f1e4400f9a0660bc968834747610212bb52
Reviewed-by: Bjørn Erik Nilsen <post@bjoernen.com>
Reviewed-by: Andreas Aardal Hanssen <andreas@hanssen.name>
Reviewed-by: Yoann Lopes <yoann.lopes@digia.com>
This commit is contained in:
Andreas Aardal Hanssen 2012-12-11 21:04:12 +01:00 committed by The Qt Project
parent af8a6cdd87
commit 533105cadf
2 changed files with 49 additions and 10 deletions

View File

@ -3202,16 +3202,20 @@ void QGraphicsItem::setActive(bool active)
// Activate this item.
d_ptr->scene->setActivePanel(this);
} else {
// Deactivate this item, and reactivate the parent panel,
// or the last active panel (if any).
QGraphicsItem *nextToActivate = 0;
if (d_ptr->parent)
nextToActivate = d_ptr->parent->panel();
if (!nextToActivate)
nextToActivate = d_ptr->scene->d_func()->lastActivePanel;
if (nextToActivate == this || isAncestorOf(nextToActivate))
nextToActivate = 0;
d_ptr->scene->setActivePanel(nextToActivate);
QGraphicsItem *activePanel = d_ptr->scene->activePanel();
QGraphicsItem *thisPanel = panel();
if (!activePanel || activePanel == thisPanel) {
// Deactivate this item, and reactivate the parent panel,
// or the last active panel (if any).
QGraphicsItem *nextToActivate = 0;
if (d_ptr->parent)
nextToActivate = d_ptr->parent->panel();
if (!nextToActivate)
nextToActivate = d_ptr->scene->d_func()->lastActivePanel;
if (nextToActivate == this || isAncestorOf(nextToActivate))
nextToActivate = 0;
d_ptr->scene->setActivePanel(nextToActivate);
}
}
}
}

View File

@ -428,6 +428,7 @@ private slots:
void activate();
void setActivePanelOnInactiveScene();
void activationOnShowHide();
void deactivateInactivePanel();
void moveWhileDeleting();
void ensureDirtySceneTransform();
void focusScope();
@ -9030,6 +9031,40 @@ public:
}
};
void tst_QGraphicsItem::deactivateInactivePanel()
{
QGraphicsScene scene;
QGraphicsItem *panel1 = scene.addRect(QRectF(0, 0, 10, 10));
panel1->setFlag(QGraphicsItem::ItemIsPanel);
QGraphicsItem *panel2 = scene.addRect(QRectF(0, 0, 10, 10));
panel2->setFlag(QGraphicsItem::ItemIsPanel);
QEvent event(QEvent::WindowActivate);
qApp->sendEvent(&scene, &event);
panel1->setActive(true);
QVERIFY(scene.isActive());
QVERIFY(panel1->isActive());
QVERIFY(!panel2->isActive());
QCOMPARE(scene.activePanel(), panel1);
panel2->setActive(true);
QVERIFY(panel2->isActive());
QVERIFY(!panel1->isActive());
QCOMPARE(scene.activePanel(), panel2);
panel2->setActive(false);
QVERIFY(panel1->isActive());
QVERIFY(!panel2->isActive());
QCOMPARE(scene.activePanel(), panel1);
panel2->setActive(false);
QVERIFY(panel1->isActive());
QVERIFY(!panel2->isActive());
QCOMPARE(scene.activePanel(), panel1);
}
void tst_QGraphicsItem::moveWhileDeleting()
{
QGraphicsScene scene;