-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
core/proxywindow: improve QsWindowAttached robustness
Can now track window parent window changes. Added tests.
- Loading branch information
Showing
7 changed files
with
142 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
#include "windowattached.hpp" | ||
|
||
#include <qobject.h> | ||
#include <qquickitem.h> | ||
#include <qsignalspy.h> | ||
#include <qtest.h> | ||
#include <qtestcase.h> | ||
|
||
#include "../proxywindow.hpp" | ||
#include "../windowinterface.hpp" | ||
|
||
void TestWindowAttachment::attachedAfterReload() { | ||
auto window = ProxyWindowBase(); | ||
auto item = QQuickItem(); | ||
item.setParentItem(window.contentItem()); | ||
window.reload(nullptr); | ||
|
||
auto* attached = WindowInterface::qmlAttachedProperties(&item); | ||
QCOMPARE_NE(attached, nullptr); | ||
QCOMPARE(attached->window(), &window); | ||
} | ||
|
||
void TestWindowAttachment::attachedBeforeReload() { | ||
auto window = ProxyWindowBase(); | ||
auto item = QQuickItem(); | ||
item.setParentItem(window.contentItem()); | ||
|
||
auto* attached = WindowInterface::qmlAttachedProperties(&item); | ||
QCOMPARE_NE(attached, nullptr); | ||
QCOMPARE(attached->window(), nullptr); | ||
|
||
auto spy = QSignalSpy(attached, &QsWindowAttached::windowChanged); | ||
window.reload(nullptr); | ||
|
||
QCOMPARE(attached->window(), &window); | ||
QCOMPARE(spy.length(), 1); | ||
} | ||
|
||
void TestWindowAttachment::owningWindowChanged() { | ||
auto window1 = ProxyWindowBase(); | ||
auto window2 = ProxyWindowBase(); | ||
window1.reload(nullptr); | ||
window2.reload(nullptr); | ||
|
||
auto item = QQuickItem(); | ||
item.setParentItem(window1.contentItem()); | ||
|
||
auto* attached = WindowInterface::qmlAttachedProperties(&item); | ||
QCOMPARE_NE(attached, nullptr); | ||
QCOMPARE(attached->window(), &window1); | ||
|
||
auto spy = QSignalSpy(attached, &QsWindowAttached::windowChanged); | ||
item.setParentItem(window2.contentItem()); | ||
QCOMPARE(attached->window(), &window2); | ||
// setParentItem changes the parent to nullptr before the new window. | ||
QCOMPARE(spy.length(), 2); | ||
} | ||
|
||
void TestWindowAttachment::nonItemParents() { | ||
auto window = ProxyWindowBase(); | ||
|
||
auto item = QQuickItem(); | ||
item.setParentItem(window.contentItem()); | ||
auto object = QObject(&item); | ||
|
||
window.reload(nullptr); | ||
|
||
auto* attached = WindowInterface::qmlAttachedProperties(&object); | ||
QCOMPARE_NE(attached, nullptr); | ||
QCOMPARE(attached->window(), &window); | ||
} | ||
|
||
QTEST_MAIN(TestWindowAttachment); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#pragma once | ||
|
||
#include <qobject.h> | ||
#include <qtmetamacros.h> | ||
|
||
class TestWindowAttachment: public QObject { | ||
Q_OBJECT; | ||
|
||
private slots: | ||
static void attachedAfterReload(); | ||
static void attachedBeforeReload(); | ||
static void owningWindowChanged(); | ||
static void nonItemParents(); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters