Fix QGuiApplication::topLevelWindows(), introducing allWindows()
As discussed on the development mailing list, the window list returned by QGuiApplication::topLevellWindows() included all QWindows, even the non top-level ones. This commit introduces the new method allWindows(), which returns the list of all QWindows, fixes the list returned by topLevelWindows() and also introduces tests for both methods. Change-Id: I761f0fcdec79f83949012c628655ed12cd18572c Reviewed-by: Jonas Gastal <jgastal@profusion.mobi> Reviewed-by: Samuel Rødal <samuel.rodal@nokia.com>
This commit is contained in:
parent
e8105e4783
commit
8839a0a001
@ -214,11 +214,38 @@ QObject *QGuiApplication::focusObject()
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
QWindowList QGuiApplication::topLevelWindows()
|
/*!
|
||||||
|
\fn QGuiApplication::allWindows()
|
||||||
|
|
||||||
|
Returns a list of all the windows in the application.
|
||||||
|
|
||||||
|
The list is empty if there are no windows.
|
||||||
|
|
||||||
|
\sa topLevelWindows()
|
||||||
|
*/
|
||||||
|
QWindowList QGuiApplication::allWindows()
|
||||||
{
|
{
|
||||||
return QGuiApplicationPrivate::window_list;
|
return QGuiApplicationPrivate::window_list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
\fn QGuiApplication::topLevelWindows()
|
||||||
|
|
||||||
|
Returns a list of the top-level windows in the application.
|
||||||
|
|
||||||
|
\sa allWindows()
|
||||||
|
*/
|
||||||
|
QWindowList QGuiApplication::topLevelWindows()
|
||||||
|
{
|
||||||
|
const QWindowList &list = QGuiApplicationPrivate::window_list;
|
||||||
|
QWindowList topLevelWindows;
|
||||||
|
for (int i = 0; i < list.size(); i++) {
|
||||||
|
if (!list.at(i)->parent())
|
||||||
|
topLevelWindows.prepend(list.at(i));
|
||||||
|
}
|
||||||
|
return topLevelWindows;
|
||||||
|
}
|
||||||
|
|
||||||
QScreen *QGuiApplication::primaryScreen()
|
QScreen *QGuiApplication::primaryScreen()
|
||||||
{
|
{
|
||||||
if (QGuiApplicationPrivate::screen_list.isEmpty())
|
if (QGuiApplicationPrivate::screen_list.isEmpty())
|
||||||
|
@ -81,6 +81,7 @@ public:
|
|||||||
QGuiApplication(int &argc, char **argv, int = ApplicationFlags);
|
QGuiApplication(int &argc, char **argv, int = ApplicationFlags);
|
||||||
virtual ~QGuiApplication();
|
virtual ~QGuiApplication();
|
||||||
|
|
||||||
|
static QWindowList allWindows();
|
||||||
static QWindowList topLevelWindows();
|
static QWindowList topLevelWindows();
|
||||||
static QWindow *topLevelAt(const QPoint &pos);
|
static QWindow *topLevelAt(const QPoint &pos);
|
||||||
|
|
||||||
|
@ -42,6 +42,7 @@
|
|||||||
|
|
||||||
#include <QtTest/QtTest>
|
#include <QtTest/QtTest>
|
||||||
#include <QtGui/QGuiApplication>
|
#include <QtGui/QGuiApplication>
|
||||||
|
#include <QtGui/QWindow>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
class tst_QGuiApplication: public QObject
|
class tst_QGuiApplication: public QObject
|
||||||
@ -50,6 +51,8 @@ class tst_QGuiApplication: public QObject
|
|||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void focusObject();
|
void focusObject();
|
||||||
|
void allWindows();
|
||||||
|
void topLevelWindows();
|
||||||
};
|
};
|
||||||
|
|
||||||
class DummyWindow : public QWindow
|
class DummyWindow : public QWindow
|
||||||
@ -115,6 +118,39 @@ void tst_QGuiApplication::focusObject()
|
|||||||
QCOMPARE(app.focusObject(), &obj3);
|
QCOMPARE(app.focusObject(), &obj3);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void tst_QGuiApplication::allWindows()
|
||||||
|
{
|
||||||
|
int argc = 0;
|
||||||
|
QGuiApplication app(argc, 0);
|
||||||
|
QWindow *window1 = new QWindow;
|
||||||
|
QWindow *window2 = new QWindow(window1);
|
||||||
|
QVERIFY(app.allWindows().contains(window1));
|
||||||
|
QVERIFY(app.allWindows().contains(window2));
|
||||||
|
QCOMPARE(app.allWindows().count(), 2);
|
||||||
|
delete window1;
|
||||||
|
window1 = 0;
|
||||||
|
window2 = 0;
|
||||||
|
QVERIFY(!app.allWindows().contains(window2));
|
||||||
|
QVERIFY(!app.allWindows().contains(window1));
|
||||||
|
QCOMPARE(app.allWindows().count(), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void tst_QGuiApplication::topLevelWindows()
|
||||||
|
{
|
||||||
|
int argc = 0;
|
||||||
|
QGuiApplication app(argc, 0);
|
||||||
|
QWindow *window1 = new QWindow;
|
||||||
|
QWindow *window2 = new QWindow(window1);
|
||||||
|
QVERIFY(app.topLevelWindows().contains(window1));
|
||||||
|
QVERIFY(!app.topLevelWindows().contains(window2));
|
||||||
|
QCOMPARE(app.topLevelWindows().count(), 1);
|
||||||
|
delete window1;
|
||||||
|
window1 = 0;
|
||||||
|
window2 = 0;
|
||||||
|
QVERIFY(!app.topLevelWindows().contains(window2));
|
||||||
|
QVERIFY(!app.topLevelWindows().contains(window1));
|
||||||
|
QCOMPARE(app.topLevelWindows().count(), 0);
|
||||||
|
}
|
||||||
|
|
||||||
QTEST_APPLESS_MAIN(tst_QGuiApplication)
|
QTEST_APPLESS_MAIN(tst_QGuiApplication)
|
||||||
#include "tst_qguiapplication.moc"
|
#include "tst_qguiapplication.moc"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user