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:
parent
af8a6cdd87
commit
533105cadf
@ -3202,6 +3202,9 @@ void QGraphicsItem::setActive(bool active)
|
||||
// Activate this item.
|
||||
d_ptr->scene->setActivePanel(this);
|
||||
} else {
|
||||
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;
|
||||
@ -3215,6 +3218,7 @@ void QGraphicsItem::setActive(bool active)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
Returns true if this item is active, and it or its \l{focusProxy()}{focus
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user