tests: Remove some QPointer usage
Which in turn also removes some asQWidget() usage
This commit is contained in:
@@ -72,6 +72,9 @@ public:
|
||||
virtual bool tests_waitForEvent(View *, QEvent::Type type, int timeout = 5000) const = 0;
|
||||
virtual bool tests_waitForEvent(std::shared_ptr<Window>, QEvent::Type type, int timeout = 5000) const = 0;
|
||||
|
||||
/// @brief Waits for the specified view to be deleted
|
||||
virtual bool tests_waitForDeleted(View *, int timeout = 2000) const = 0;
|
||||
|
||||
virtual void tests_sendEvent(View *, QEvent *) const = 0;
|
||||
virtual void tests_sendEvent(std::shared_ptr<Window> window, QEvent *ev) const = 0;
|
||||
|
||||
|
||||
@@ -127,6 +127,25 @@ bool Platform_qt::tests_waitForEvent(std::shared_ptr<Window> window, QEvent::Typ
|
||||
return tests_waitForEvent(windowqt->qtWindow(), type, timeout);
|
||||
}
|
||||
|
||||
bool Platform_qt::tests_waitForDeleted(View *view, int timeout) const
|
||||
{
|
||||
QObject *o = view ? view->asQObject() : nullptr;
|
||||
if (!o)
|
||||
return true;
|
||||
|
||||
QPointer<QObject> ptr = o;
|
||||
QElapsedTimer time;
|
||||
time.start();
|
||||
|
||||
while (ptr && time.elapsed() < timeout) {
|
||||
qApp->processEvents();
|
||||
QTest::qWait(50);
|
||||
}
|
||||
|
||||
const bool wasDeleted = !ptr;
|
||||
return wasDeleted;
|
||||
}
|
||||
|
||||
void Platform_qt::tests_sendEvent(View *view, QEvent *ev) const
|
||||
{
|
||||
qApp->sendEvent(view->asQObject(), ev);
|
||||
|
||||
@@ -37,6 +37,7 @@ public:
|
||||
bool tests_waitForEvent(std::shared_ptr<Window>, QEvent::Type type, int timeout = 5000) const override;
|
||||
bool tests_waitForResize(View *, int timeout = 2000) const override;
|
||||
bool tests_waitForResize(Controller *, int timeout = 2000) const override;
|
||||
bool tests_waitForDeleted(View *, int timeout = 2000) const override;
|
||||
void tests_sendEvent(std::shared_ptr<Window>, QEvent *) const override;
|
||||
void tests_sendEvent(View *, QEvent *) const override;
|
||||
#endif
|
||||
|
||||
@@ -5763,12 +5763,11 @@ void TestDocks::tst_maximumSizePolicy()
|
||||
auto dock1 = createDockWidget("dock1", widget);
|
||||
dock1->show();
|
||||
dock1->window()->resize(QSize(500, 500));
|
||||
auto oldFw = Tests::make_qpointer(dock1->window()->asQWidget());
|
||||
auto window1 = dock1->window();
|
||||
dock1->close();
|
||||
dock1->show();
|
||||
auto oldFw2 = dock1->window();
|
||||
|
||||
|
||||
const int tolerance = 50;
|
||||
QVERIFY(dock1->window()->height() <= maxHeight + tolerance); // +tolerance as the floating window is a bit bigger, due to margins etc.
|
||||
QVERIFY(dock1->height() <= maxHeight);
|
||||
@@ -5790,8 +5789,6 @@ void TestDocks::tst_maximumSizePolicy()
|
||||
// Now drop it, and check too
|
||||
m1->addDockWidget(dock1, Location_OnBottom);
|
||||
QVERIFY(dock1->height() <= maxHeight);
|
||||
|
||||
delete oldFw.data();
|
||||
}
|
||||
|
||||
void TestDocks::tst_minSizeChanges()
|
||||
@@ -6300,7 +6297,7 @@ void TestDocks::tst_raise()
|
||||
|
||||
auto dock1 = createDockWidget("1");
|
||||
auto dock2 = createDockWidget("2");
|
||||
auto fw2 = Tests::make_qpointer(dock2->window()->asQWidget());
|
||||
|
||||
dock1->addDockWidgetAsTab(dock2);
|
||||
dock1->setAsCurrentTab();
|
||||
QVERIFY(dock1->isCurrentTab());
|
||||
@@ -6778,7 +6775,7 @@ void TestDocks::tst_addDockWidgetAsTabToDockWidget()
|
||||
dock1->dptr()->morphIntoFloatingWindow();
|
||||
auto dock2 = createDockWidget("dock2", new QPushButton("two"));
|
||||
dock2->dptr()->morphIntoFloatingWindow();
|
||||
auto originalWindow2 = Tests::make_qpointer(dock2->window()->asQWidget());
|
||||
auto originalWindow2 = dock2->window();
|
||||
|
||||
dock1->addDockWidgetAsTab(dock2);
|
||||
|
||||
@@ -6787,8 +6784,8 @@ void TestDocks::tst_addDockWidgetAsTabToDockWidget()
|
||||
QCOMPARE(window1->windowHandle(), window2->windowHandle());
|
||||
QCOMPARE(dock1->dptr()->frame(), dock2->dptr()->frame());
|
||||
QCOMPARE(dock1->dptr()->frame()->dockWidgetCount(), 2);
|
||||
Testing::waitForDeleted(originalWindow2);
|
||||
QVERIFY(!originalWindow2);
|
||||
Platform::instance()->tests_waitForDeleted(originalWindow2.get());
|
||||
|
||||
dock1->deleteLater();
|
||||
dock2->deleteLater();
|
||||
Testing::waitForDeleted(dock2);
|
||||
|
||||
@@ -58,13 +58,6 @@ namespace KDDockWidgets {
|
||||
|
||||
namespace Tests {
|
||||
|
||||
template<typename T>
|
||||
inline QPointer<T> make_qpointer(T *t)
|
||||
{
|
||||
// To support both QWidget and QtQuick we need QPointer<auto>, so use a function instead.
|
||||
return QPointer<T>(t);
|
||||
}
|
||||
|
||||
enum ButtonAction {
|
||||
ButtonAction_None,
|
||||
ButtonAction_Press = 1,
|
||||
|
||||
Reference in New Issue
Block a user