2011-04-27 10:05:43 +00:00
|
|
|
/****************************************************************************
|
|
|
|
**
|
2016-01-15 12:36:27 +00:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2011-04-27 10:05:43 +00:00
|
|
|
**
|
|
|
|
** This file is part of the test suite of the Qt Toolkit.
|
|
|
|
**
|
2016-01-15 12:36:27 +00:00
|
|
|
** $QT_BEGIN_LICENSE:GPL-EXCEPT$
|
2012-09-19 12:28:29 +00:00
|
|
|
** Commercial License Usage
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
2015-01-28 08:44:43 +00:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
2016-01-15 12:36:27 +00:00
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
2012-09-19 12:28:29 +00:00
|
|
|
**
|
2016-01-15 12:36:27 +00:00
|
|
|
** GNU General Public License Usage
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
2011-04-27 10:05:43 +00:00
|
|
|
**
|
|
|
|
** $QT_END_LICENSE$
|
|
|
|
**
|
|
|
|
****************************************************************************/
|
|
|
|
|
2020-07-13 12:45:41 +00:00
|
|
|
#define QT_STATICPLUGIN
|
|
|
|
#include <QtWidgets/qstyleplugin.h>
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
#include <qdebug.h>
|
|
|
|
|
2020-11-26 16:31:50 +00:00
|
|
|
#include <QTest>
|
|
|
|
#include <QTimer>
|
|
|
|
#include <QLibraryInfo>
|
|
|
|
#include <QSignalSpy>
|
|
|
|
#include <QFileSystemWatcher>
|
|
|
|
#include <QSharedMemory>
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2011-12-14 08:27:33 +00:00
|
|
|
#include <QtCore/QAbstractEventDispatcher>
|
|
|
|
#include <QtCore/QFileInfo>
|
|
|
|
#include <QtCore/QDir>
|
2016-11-23 11:25:17 +00:00
|
|
|
#if QT_CONFIG(process)
|
|
|
|
# include <QtCore/QProcess>
|
|
|
|
#endif
|
2011-10-26 11:29:51 +00:00
|
|
|
#include <QtCore/private/qeventloop_p.h>
|
2011-12-14 08:27:33 +00:00
|
|
|
|
|
|
|
#include <QtGui/QFontDatabase>
|
|
|
|
#include <QtGui/QClipboard>
|
|
|
|
|
|
|
|
#include <QtWidgets/QApplication>
|
|
|
|
#include <QtWidgets/QMessageBox>
|
|
|
|
#include <QtWidgets/QStyleFactory>
|
|
|
|
#include <QtWidgets/QHBoxLayout>
|
|
|
|
#include <QtWidgets/QPushButton>
|
|
|
|
#include <QtWidgets/QLineEdit>
|
|
|
|
#include <QtWidgets/QLabel>
|
|
|
|
#include <QtWidgets/QMainWindow>
|
QApplication: deliver all wheel events to widget that accepts the first
For kinetic wheel events, Qt tries to make sure that all events in the
stream go to the widget that accepted the first wheel event.
It did so by directing all events from the stream to the widget from
which the spontaneous event was returned as accepted.
However, that widget might have passed the event on to some other
widgets; e.g QScrollArea forwards wheel events from the viewport to the
relevant scroll bar. The event might then have come back accepted only
because parent propagation kicked in (the scrollbar might not accept
the event, so the parents get a chance, and some parent's scrollbar
ultimately accepts the event).
In this scenario, the wheel widget would be the viewport under the
mouse, when it should have been the scrollbar of the parent. The
next events from the stream were then delivered to a widget that didn't
scroll; and parent propagation is not (and should not be) implemented
for the case where Qt has a wheel widget.
Instead, make the first widget that accepts any initial wheel event
the wheel widget, even if the event was not spontaneous. With this
change, all events from the stream are delivered to the widget that
actually handled the event. That has the effect that ie. a viewport
of a scroll area only gets the first event; all following events are
delivered directly to the scrollbar.
The test case added simulates the different scenarios - nesting of
scroll areas, classic wheel events and a stream of kinetic wheel
events.
[ChangeLog][QtWidgets][QApplication] Wheel events from a device that
creates an event stream are correctly delivered to the widget that
accepts the first wheel event in the stream.
Change-Id: I5ebfc7789b5c32ebc8d881686f450fa05ec92cfe
Fixes: QTBUG-79102
Pick-to: 5.15
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
2020-04-21 11:39:59 +00:00
|
|
|
#include <QtWidgets/QScrollArea>
|
|
|
|
#include <QtWidgets/QScrollBar>
|
2021-01-11 05:14:43 +00:00
|
|
|
#include <QtWidgets/QHeaderView>
|
2011-12-14 08:27:33 +00:00
|
|
|
#include <QtWidgets/private/qapplication_p.h>
|
2012-11-23 14:02:46 +00:00
|
|
|
#include <QtWidgets/QStyle>
|
2020-07-13 12:45:41 +00:00
|
|
|
#include <QtWidgets/qproxystyle.h>
|
2021-01-13 10:41:41 +00:00
|
|
|
#include <QtWidgets/QTextEdit>
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2012-07-26 11:23:28 +00:00
|
|
|
#include <qpa/qwindowsysteminterface.h>
|
2019-05-10 09:08:11 +00:00
|
|
|
#include <qpa/qwindowsysteminterface_p.h>
|
2020-03-27 16:06:11 +00:00
|
|
|
#include <private/qevent_p.h>
|
2015-06-18 15:01:01 +00:00
|
|
|
#include <private/qhighdpiscaling_p.h>
|
2012-07-26 16:48:56 +00:00
|
|
|
|
2019-05-10 09:08:11 +00:00
|
|
|
#include <algorithm>
|
2012-07-26 16:48:56 +00:00
|
|
|
|
2019-05-10 09:08:11 +00:00
|
|
|
Q_LOGGING_CATEGORY(lcTests, "qt.widgets.tests")
|
2012-07-26 16:48:56 +00:00
|
|
|
|
2019-05-10 09:08:11 +00:00
|
|
|
QT_BEGIN_NAMESPACE
|
2012-07-26 16:48:56 +00:00
|
|
|
|
2012-10-09 09:27:01 +00:00
|
|
|
extern bool Q_GUI_EXPORT qt_tab_all_widgets(); // from qapplication.cpp
|
2012-02-20 05:12:50 +00:00
|
|
|
QT_END_NAMESPACE
|
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
class tst_QApplication : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
2015-12-03 15:59:30 +00:00
|
|
|
private slots:
|
2011-04-27 10:05:43 +00:00
|
|
|
void cleanup();
|
|
|
|
void sendEventsOnProcessEvents(); // this must be the first test
|
|
|
|
void staticSetup();
|
|
|
|
|
|
|
|
void alert();
|
|
|
|
|
|
|
|
void multiple_data();
|
|
|
|
void multiple();
|
|
|
|
|
|
|
|
void nonGui();
|
|
|
|
|
|
|
|
void setFont_data();
|
|
|
|
void setFont();
|
2021-01-11 05:14:43 +00:00
|
|
|
void setFontForClass();
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
void args_data();
|
|
|
|
void args();
|
2012-06-23 08:02:11 +00:00
|
|
|
void appName();
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
void lastWindowClosed();
|
|
|
|
void quitOnLastWindowClosed();
|
|
|
|
void closeAllWindows();
|
|
|
|
void testDeleteLater();
|
2020-03-31 09:52:19 +00:00
|
|
|
void testDeleteLaterProcessEvents1();
|
|
|
|
void testDeleteLaterProcessEvents2();
|
|
|
|
void testDeleteLaterProcessEvents3();
|
|
|
|
void testDeleteLaterProcessEvents4();
|
|
|
|
void testDeleteLaterProcessEvents5();
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2016-12-19 09:34:32 +00:00
|
|
|
#if QT_CONFIG(library)
|
2011-04-27 10:05:43 +00:00
|
|
|
void libraryPaths();
|
|
|
|
void libraryPaths_qt_plugin_path();
|
|
|
|
void libraryPaths_qt_plugin_path_2();
|
2015-07-20 13:10:33 +00:00
|
|
|
#endif
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
void sendPostedEvents();
|
|
|
|
|
|
|
|
void thread();
|
|
|
|
void desktopSettingsAware();
|
|
|
|
|
|
|
|
void setActiveWindow();
|
|
|
|
|
2021-01-13 10:41:41 +00:00
|
|
|
void focusWidget();
|
2011-04-27 10:05:43 +00:00
|
|
|
void focusChanged();
|
|
|
|
void focusOut();
|
2013-11-16 16:17:15 +00:00
|
|
|
void focusMouseClick();
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
void execAfterExit();
|
|
|
|
|
2017-05-30 20:22:22 +00:00
|
|
|
#if QT_CONFIG(wheelevent)
|
2011-04-27 10:05:43 +00:00
|
|
|
void wheelScrollLines();
|
2015-02-27 09:22:36 +00:00
|
|
|
#endif
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
void task109149();
|
|
|
|
|
|
|
|
void style();
|
2020-07-13 12:45:41 +00:00
|
|
|
void applicationPalettePolish();
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
void allWidgets();
|
|
|
|
void topLevelWidgets();
|
|
|
|
|
|
|
|
void setAttribute();
|
|
|
|
|
|
|
|
void touchEventPropagation();
|
QApplication: deliver all wheel events to widget that accepts the first
For kinetic wheel events, Qt tries to make sure that all events in the
stream go to the widget that accepted the first wheel event.
It did so by directing all events from the stream to the widget from
which the spontaneous event was returned as accepted.
However, that widget might have passed the event on to some other
widgets; e.g QScrollArea forwards wheel events from the viewport to the
relevant scroll bar. The event might then have come back accepted only
because parent propagation kicked in (the scrollbar might not accept
the event, so the parents get a chance, and some parent's scrollbar
ultimately accepts the event).
In this scenario, the wheel widget would be the viewport under the
mouse, when it should have been the scrollbar of the parent. The
next events from the stream were then delivered to a widget that didn't
scroll; and parent propagation is not (and should not be) implemented
for the case where Qt has a wheel widget.
Instead, make the first widget that accepts any initial wheel event
the wheel widget, even if the event was not spontaneous. With this
change, all events from the stream are delivered to the widget that
actually handled the event. That has the effect that ie. a viewport
of a scroll area only gets the first event; all following events are
delivered directly to the scrollbar.
The test case added simulates the different scenarios - nesting of
scroll areas, classic wheel events and a stream of kinetic wheel
events.
[ChangeLog][QtWidgets][QApplication] Wheel events from a device that
creates an event stream are correctly delivered to the widget that
accepts the first wheel event in the stream.
Change-Id: I5ebfc7789b5c32ebc8d881686f450fa05ec92cfe
Fixes: QTBUG-79102
Pick-to: 5.15
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
2020-04-21 11:39:59 +00:00
|
|
|
void wheelEventPropagation_data();
|
|
|
|
void wheelEventPropagation();
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
void qtbug_12673();
|
2012-02-11 00:33:55 +00:00
|
|
|
void noQuitOnHide();
|
2011-10-26 11:29:51 +00:00
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
void globalStaticObjectDestruction(); // run this last
|
2012-02-11 00:10:07 +00:00
|
|
|
|
|
|
|
void abortQuitOnShow();
|
2013-10-15 12:12:34 +00:00
|
|
|
|
2015-02-24 08:35:56 +00:00
|
|
|
void staticFunctions();
|
|
|
|
|
2015-02-23 16:01:24 +00:00
|
|
|
void settableStyleHints_data();
|
2013-10-15 12:12:34 +00:00
|
|
|
void settableStyleHints(); // Needs to run last as it changes style hints.
|
2011-04-27 10:05:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class EventSpy : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
QList<int> recordedEvents;
|
2019-05-10 09:08:11 +00:00
|
|
|
bool eventFilter(QObject *, QEvent *event) override
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
|
|
|
recordedEvents.append(event->type());
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
void tst_QApplication::sendEventsOnProcessEvents()
|
|
|
|
{
|
|
|
|
int argc = 0;
|
2019-05-10 09:08:11 +00:00
|
|
|
QApplication app(argc, nullptr);
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
EventSpy spy;
|
|
|
|
app.installEventFilter(&spy);
|
|
|
|
|
|
|
|
QCoreApplication::postEvent(&app, new QEvent(QEvent::Type(QEvent::User + 1)));
|
|
|
|
QCoreApplication::processEvents();
|
|
|
|
QVERIFY(spy.recordedEvents.contains(QEvent::User + 1));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
class CloseEventTestWindow : public QWidget
|
|
|
|
{
|
|
|
|
public:
|
2019-05-10 09:08:11 +00:00
|
|
|
void closeEvent(QCloseEvent *event) override
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
|
|
|
QWidget dialog;
|
2019-05-10 09:08:11 +00:00
|
|
|
dialog.setWindowTitle(QLatin1String("CloseEventTestWindow"));
|
2011-04-27 10:05:43 +00:00
|
|
|
dialog.show();
|
|
|
|
dialog.close();
|
|
|
|
|
|
|
|
event->ignore();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
static char *argv0;
|
|
|
|
|
|
|
|
void tst_QApplication::cleanup()
|
|
|
|
{
|
|
|
|
// TODO: Add cleanup code here.
|
|
|
|
// This will be executed immediately after each test is run.
|
2014-07-24 13:11:27 +00:00
|
|
|
QVERIFY(QApplication::topLevelWidgets().isEmpty());
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void tst_QApplication::staticSetup()
|
|
|
|
{
|
|
|
|
QVERIFY(!qApp);
|
|
|
|
|
|
|
|
QStyle *style = QStyleFactory::create(QLatin1String("Windows"));
|
|
|
|
QVERIFY(style);
|
|
|
|
QApplication::setStyle(style);
|
|
|
|
|
|
|
|
QPalette pal;
|
|
|
|
QApplication::setPalette(pal);
|
2020-10-16 11:39:11 +00:00
|
|
|
QFont font;
|
|
|
|
QApplication::setFont(font);
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
int argc = 0;
|
2018-10-16 15:11:12 +00:00
|
|
|
QApplication app(argc, nullptr);
|
2020-10-16 11:39:11 +00:00
|
|
|
|
|
|
|
class EventWatcher : public QObject
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
int palette_changed = 0;
|
|
|
|
int font_changed = 0;
|
|
|
|
|
|
|
|
EventWatcher()
|
|
|
|
{
|
|
|
|
qApp->installEventFilter(this);
|
|
|
|
QT_WARNING_PUSH QT_WARNING_DISABLE_DEPRECATED
|
|
|
|
QObject::connect(qApp, &QApplication::paletteChanged, [&]{ ++palette_changed; });
|
|
|
|
QObject::connect(qApp, &QApplication::fontChanged, [&]{ ++font_changed; });
|
|
|
|
QT_WARNING_POP
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
bool eventFilter(QObject *, QEvent *event) override
|
|
|
|
{
|
|
|
|
switch (event->type()) {
|
|
|
|
case QEvent::ApplicationPaletteChange:
|
|
|
|
++palette_changed;
|
|
|
|
break;
|
|
|
|
case QEvent::ApplicationFontChange:
|
|
|
|
++font_changed;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
EventWatcher watcher;
|
|
|
|
|
|
|
|
QCOMPARE(watcher.palette_changed, 0);
|
|
|
|
QCOMPARE(watcher.font_changed, 0);
|
2018-10-16 15:11:12 +00:00
|
|
|
qApp->setPalette(QPalette(Qt::red));
|
2020-10-16 11:39:11 +00:00
|
|
|
|
|
|
|
font.setBold(!font.bold());
|
|
|
|
qApp->setFont(font);
|
|
|
|
QApplication::processEvents();
|
|
|
|
QCOMPARE(watcher.palette_changed, 2);
|
|
|
|
QCOMPARE(watcher.font_changed, 2);
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// QApp subclass that exits the event loop after 150ms
|
|
|
|
class TestApplication : public QApplication
|
|
|
|
{
|
|
|
|
public:
|
2019-05-10 09:08:11 +00:00
|
|
|
TestApplication(int &argc, char **argv) : QApplication( argc, argv)
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2019-05-10 09:08:11 +00:00
|
|
|
startTimer(150);
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
2019-05-10 09:08:11 +00:00
|
|
|
void timerEvent(QTimerEvent *) override
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
|
|
|
quit();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
void tst_QApplication::alert()
|
|
|
|
{
|
|
|
|
int argc = 0;
|
2019-05-10 09:08:11 +00:00
|
|
|
QApplication app(argc, nullptr);
|
|
|
|
QApplication::alert(nullptr, 0);
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
QWidget widget;
|
2019-05-10 09:08:11 +00:00
|
|
|
widget.setWindowTitle(QLatin1String(QTest::currentTestFunction()));
|
2011-04-27 10:05:43 +00:00
|
|
|
QWidget widget2;
|
2019-05-10 09:08:11 +00:00
|
|
|
widget2.setWindowTitle(QLatin1String(QTest::currentTestFunction()) + QLatin1Char('2'));
|
|
|
|
QApplication::alert(&widget, 100);
|
2011-04-27 10:05:43 +00:00
|
|
|
widget.show();
|
|
|
|
widget2.show();
|
2012-07-18 11:12:59 +00:00
|
|
|
QVERIFY(QTest::qWaitForWindowExposed(&widget));
|
|
|
|
QVERIFY(QTest::qWaitForWindowExposed(&widget2));
|
2019-05-10 09:08:11 +00:00
|
|
|
QApplication::alert(&widget, -1);
|
|
|
|
QApplication::alert(&widget, 250);
|
2011-04-27 10:05:43 +00:00
|
|
|
widget2.activateWindow();
|
|
|
|
QApplication::setActiveWindow(&widget2);
|
2019-05-10 09:08:11 +00:00
|
|
|
QApplication::alert(&widget, 0);
|
2011-04-27 10:05:43 +00:00
|
|
|
widget.activateWindow();
|
|
|
|
QApplication::setActiveWindow(&widget);
|
2019-05-10 09:08:11 +00:00
|
|
|
QApplication::alert(&widget, 200);
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void tst_QApplication::multiple_data()
|
|
|
|
{
|
|
|
|
QTest::addColumn<QStringList>("features");
|
|
|
|
|
|
|
|
// return a list of things to try
|
|
|
|
QTest::newRow( "data0" ) << QStringList( "" );
|
|
|
|
QTest::newRow( "data1" ) << QStringList( "QFont" );
|
|
|
|
QTest::newRow( "data2" ) << QStringList( "QPixmap" );
|
|
|
|
QTest::newRow( "data3" ) << QStringList( "QWidget" );
|
|
|
|
}
|
|
|
|
|
|
|
|
void tst_QApplication::multiple()
|
|
|
|
{
|
|
|
|
QFETCH(QStringList,features);
|
|
|
|
|
|
|
|
int i = 0;
|
|
|
|
int argc = 0;
|
2014-01-13 14:48:44 +00:00
|
|
|
while (i++ < 5) {
|
2019-05-10 09:08:11 +00:00
|
|
|
TestApplication app(argc, nullptr);
|
2014-01-13 14:48:44 +00:00
|
|
|
|
|
|
|
if (features.contains("QFont")) {
|
|
|
|
// create font and force loading
|
|
|
|
QFont font("Arial", 12);
|
|
|
|
QFontInfo finfo(font);
|
|
|
|
finfo.exactMatch();
|
|
|
|
}
|
|
|
|
if (features.contains("QPixmap")) {
|
|
|
|
QPixmap pix(100, 100);
|
|
|
|
pix.fill(Qt::black);
|
|
|
|
}
|
|
|
|
if (features.contains("QWidget")) {
|
|
|
|
QWidget widget;
|
|
|
|
}
|
|
|
|
|
2019-05-10 09:08:11 +00:00
|
|
|
QVERIFY(!QCoreApplication::exec());
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void tst_QApplication::nonGui()
|
|
|
|
{
|
|
|
|
#ifdef Q_OS_HPUX
|
|
|
|
// ### This is only to allow us to generate a test report for now.
|
2011-10-19 02:53:13 +00:00
|
|
|
QSKIP("This test shuts down the window manager on HP-UX.");
|
2011-04-27 10:05:43 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
int argc = 0;
|
2019-05-10 09:08:11 +00:00
|
|
|
QApplication app(argc, nullptr, false);
|
2011-04-27 10:05:43 +00:00
|
|
|
QCOMPARE(qApp, &app);
|
|
|
|
}
|
|
|
|
|
|
|
|
void tst_QApplication::setFont_data()
|
|
|
|
{
|
|
|
|
QTest::addColumn<QString>("family");
|
|
|
|
QTest::addColumn<int>("pointsize");
|
|
|
|
QTest::addColumn<bool>("beforeAppConstructor");
|
|
|
|
|
|
|
|
int argc = 0;
|
2019-05-10 09:08:11 +00:00
|
|
|
QApplication app(argc, nullptr); // Needed for QFontDatabase
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2020-11-02 18:48:25 +00:00
|
|
|
const QStringList &families = QFontDatabase::families();
|
2019-05-10 09:08:11 +00:00
|
|
|
for (int i = 0, count = qMin(3, families.size()); i < count; ++i) {
|
|
|
|
const auto &family = families.at(i);
|
2020-11-02 18:48:25 +00:00
|
|
|
const QStringList &styles = QFontDatabase::styles(family);
|
2019-05-10 09:08:11 +00:00
|
|
|
if (!styles.isEmpty()) {
|
2020-11-02 18:48:25 +00:00
|
|
|
QList<int> sizes = QFontDatabase::pointSizes(family, styles.constFirst());
|
2019-05-10 09:08:11 +00:00
|
|
|
if (sizes.isEmpty())
|
|
|
|
sizes = QFontDatabase::standardSizes();
|
|
|
|
if (!sizes.isEmpty()) {
|
|
|
|
const QByteArray name = QByteArrayLiteral("data") + QByteArray::number(i);
|
|
|
|
QTest::newRow((name + 'a').constData())
|
|
|
|
<< family
|
|
|
|
<< sizes.constFirst()
|
|
|
|
<< false;
|
|
|
|
QTest::newRow((name + 'b').constData())
|
|
|
|
<< family
|
|
|
|
<< sizes.constFirst()
|
|
|
|
<< true;
|
2014-01-13 14:48:44 +00:00
|
|
|
}
|
|
|
|
}
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
2012-02-14 03:03:16 +00:00
|
|
|
QTest::newRow("nonexistingfont after") << "nosuchfont_probably_quiteunlikely"
|
2011-04-27 10:05:43 +00:00
|
|
|
<< 0 << false;
|
2012-02-14 03:03:16 +00:00
|
|
|
QTest::newRow("nonexistingfont before") << "nosuchfont_probably_quiteunlikely"
|
2011-04-27 10:05:43 +00:00
|
|
|
<< 0 << true;
|
|
|
|
|
2012-02-14 03:03:16 +00:00
|
|
|
QTest::newRow("largescaleable after") << "smoothtimes" << 100 << false;
|
|
|
|
QTest::newRow("largescaleable before") << "smoothtimes" << 100 << true;
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2012-02-14 03:03:16 +00:00
|
|
|
QTest::newRow("largeunscaleale after") << "helvetica" << 100 << false;
|
|
|
|
QTest::newRow("largeunscaleale before") << "helvetica" << 100 << true;
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void tst_QApplication::setFont()
|
|
|
|
{
|
|
|
|
QFETCH( QString, family );
|
|
|
|
QFETCH( int, pointsize );
|
|
|
|
QFETCH( bool, beforeAppConstructor );
|
|
|
|
|
|
|
|
QFont font( family, pointsize );
|
|
|
|
if (beforeAppConstructor) {
|
|
|
|
QApplication::setFont( font );
|
|
|
|
QCOMPARE(QApplication::font(), font);
|
|
|
|
}
|
|
|
|
|
|
|
|
int argc = 0;
|
2019-05-10 09:08:11 +00:00
|
|
|
QApplication app(argc, nullptr);
|
2011-04-27 10:05:43 +00:00
|
|
|
if (!beforeAppConstructor)
|
|
|
|
QApplication::setFont( font );
|
|
|
|
|
|
|
|
QCOMPARE( app.font(), font );
|
|
|
|
}
|
|
|
|
|
2021-01-11 05:14:43 +00:00
|
|
|
class tstHeaderView : public QHeaderView
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
explicit tstHeaderView(Qt::Orientation orientation, QWidget *parent = nullptr)
|
|
|
|
: QHeaderView(orientation, parent)
|
|
|
|
{}
|
|
|
|
};
|
|
|
|
class tstFrame : public QFrame { Q_OBJECT };
|
|
|
|
class tstWidget : public QWidget { Q_OBJECT };
|
|
|
|
|
|
|
|
void tst_QApplication::setFontForClass()
|
|
|
|
{
|
|
|
|
// QTBUG-89910
|
|
|
|
// If a default font was not registered for the widget's class,
|
|
|
|
// it returns the default font of its nearest registered superclass.
|
|
|
|
int argc = 0;
|
|
|
|
QApplication app(argc, nullptr);
|
|
|
|
|
|
|
|
QFont font;
|
|
|
|
int pointSize = 10;
|
|
|
|
const QByteArrayList classNames{"QHeaderView", "QAbstractItemView", "QAbstractScrollView", "QFrame", "QWidget", "QObject"};
|
|
|
|
for (auto className : classNames) {
|
|
|
|
font.setPointSizeF(pointSize++);
|
|
|
|
app.setFont(font, className.constData());
|
|
|
|
}
|
|
|
|
|
|
|
|
tstHeaderView headView(Qt::Horizontal);
|
|
|
|
tstFrame frame;
|
|
|
|
tstWidget widget;
|
|
|
|
|
|
|
|
QFont headViewFont = QApplication::font(&headView);
|
|
|
|
QFont frameFont = QApplication::font(&frame);
|
|
|
|
QFont widgetFont = QApplication::font(&widget);
|
|
|
|
|
|
|
|
QCOMPARE(headViewFont.pointSize(), QApplication::font("QHeaderView").pointSize());
|
|
|
|
QCOMPARE(frameFont.pointSize(), QApplication::font("QFrame").pointSize());
|
|
|
|
QCOMPARE(widgetFont.pointSize(), QApplication::font("QWidget").pointSize());
|
|
|
|
}
|
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
void tst_QApplication::args_data()
|
|
|
|
{
|
|
|
|
QTest::addColumn<int>("argc_in");
|
|
|
|
QTest::addColumn<QString>("args_in");
|
|
|
|
QTest::addColumn<int>("argc_out");
|
|
|
|
QTest::addColumn<QString>("args_out");
|
|
|
|
|
|
|
|
QTest::newRow( "App name" ) << 1 << "/usr/bin/appname" << 1 << "/usr/bin/appname";
|
|
|
|
QTest::newRow( "No arguments" ) << 0 << QString() << 0 << QString();
|
2012-09-18 11:55:45 +00:00
|
|
|
QTest::newRow( "App name, style" ) << 3 << "/usr/bin/appname -style windows" << 1 << "/usr/bin/appname";
|
|
|
|
QTest::newRow( "App name, style, arbitrary, reverse" ) << 5 << "/usr/bin/appname -style windows -arbitrary -reverse"
|
2014-01-13 14:48:44 +00:00
|
|
|
<< 2 << "/usr/bin/appname -arbitrary";
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void tst_QApplication::task109149()
|
|
|
|
{
|
|
|
|
int argc = 0;
|
2019-05-10 09:08:11 +00:00
|
|
|
QApplication app(argc, nullptr);
|
2011-04-27 10:05:43 +00:00
|
|
|
QApplication::setFont(QFont("helvetica", 100));
|
|
|
|
|
|
|
|
QWidget w;
|
|
|
|
w.setWindowTitle("hello");
|
|
|
|
w.show();
|
|
|
|
|
2019-05-10 09:08:11 +00:00
|
|
|
QCoreApplication::processEvents();
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
2019-05-10 09:08:11 +00:00
|
|
|
static char **QString2cstrings(const QString &args)
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2019-05-10 09:08:11 +00:00
|
|
|
static QByteArrayList cache;
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2020-08-12 11:16:27 +00:00
|
|
|
const auto &list = QStringView{ args }.split(' ');
|
2019-05-10 09:08:11 +00:00
|
|
|
auto argarray = new char*[list.count() + 1];
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2019-05-10 09:08:11 +00:00
|
|
|
int i = 0;
|
|
|
|
for (; i < list.size(); ++i ) {
|
2011-04-27 10:05:43 +00:00
|
|
|
QByteArray l1 = list[i].toLatin1();
|
|
|
|
argarray[i] = l1.data();
|
|
|
|
cache.append(l1);
|
|
|
|
}
|
2019-05-10 09:08:11 +00:00
|
|
|
argarray[i] = nullptr;
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
return argarray;
|
|
|
|
}
|
|
|
|
|
|
|
|
static QString cstrings2QString( char **args )
|
|
|
|
{
|
|
|
|
QString string;
|
|
|
|
if ( !args )
|
2014-01-13 14:48:44 +00:00
|
|
|
return string;
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
int i = 0;
|
|
|
|
while ( args[i] ) {
|
2014-01-13 14:48:44 +00:00
|
|
|
string += args[i];
|
|
|
|
if ( args[i+1] )
|
2015-10-13 07:46:56 +00:00
|
|
|
string += QLatin1Char(' ');
|
2014-01-13 14:48:44 +00:00
|
|
|
++i;
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
return string;
|
|
|
|
}
|
|
|
|
|
|
|
|
void tst_QApplication::args()
|
|
|
|
{
|
|
|
|
QFETCH( int, argc_in );
|
|
|
|
QFETCH( QString, args_in );
|
|
|
|
QFETCH( int, argc_out );
|
|
|
|
QFETCH( QString, args_out );
|
|
|
|
|
|
|
|
char **argv = QString2cstrings( args_in );
|
|
|
|
|
2012-11-23 14:02:46 +00:00
|
|
|
QApplication app( argc_in, argv);
|
2011-04-27 10:05:43 +00:00
|
|
|
QString argv_out = cstrings2QString(argv);
|
|
|
|
|
|
|
|
QCOMPARE( argc_in, argc_out );
|
|
|
|
QCOMPARE( argv_out, args_out );
|
|
|
|
|
|
|
|
delete [] argv;
|
2012-10-10 10:46:37 +00:00
|
|
|
// Make sure we switch back to native style.
|
2019-05-10 09:08:11 +00:00
|
|
|
QApplicationPrivate::styleOverride.clear();
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
2012-06-23 08:02:11 +00:00
|
|
|
void tst_QApplication::appName()
|
|
|
|
{
|
|
|
|
char argv0[] = "tst_qapplication";
|
2019-05-10 09:08:11 +00:00
|
|
|
char *argv[] = { argv0, nullptr };
|
2012-06-23 08:02:11 +00:00
|
|
|
int argc = 1;
|
|
|
|
QApplication app(argc, argv);
|
|
|
|
QCOMPARE(::qAppName(), QString::fromLatin1("tst_qapplication"));
|
|
|
|
QCOMPARE(QCoreApplication::applicationName(), QString::fromLatin1("tst_qapplication"));
|
|
|
|
}
|
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
class CloseWidget : public QWidget
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
CloseWidget()
|
|
|
|
{
|
|
|
|
startTimer(500);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2019-05-10 09:08:11 +00:00
|
|
|
void timerEvent(QTimerEvent *) override
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
|
|
|
close();
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
void tst_QApplication::lastWindowClosed()
|
|
|
|
{
|
|
|
|
int argc = 0;
|
2019-05-10 09:08:11 +00:00
|
|
|
QApplication app(argc, nullptr);
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2019-05-10 09:08:11 +00:00
|
|
|
QSignalSpy spy(&app, &QGuiApplication::lastWindowClosed);
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
QPointer<QDialog> dialog = new QDialog;
|
2019-05-10 09:08:11 +00:00
|
|
|
dialog->setWindowTitle(QLatin1String(QTest::currentTestFunction()) + QLatin1String("Dialog"));
|
2011-04-27 10:05:43 +00:00
|
|
|
QVERIFY(dialog->testAttribute(Qt::WA_QuitOnClose));
|
2019-08-05 12:24:16 +00:00
|
|
|
QTimer::singleShot(1000, dialog.data(), &QDialog::accept);
|
2011-04-27 10:05:43 +00:00
|
|
|
dialog->exec();
|
|
|
|
QVERIFY(dialog);
|
|
|
|
QCOMPARE(spy.count(), 0);
|
|
|
|
|
|
|
|
QPointer<CloseWidget>widget = new CloseWidget;
|
2019-05-10 09:08:11 +00:00
|
|
|
widget->setWindowTitle(QLatin1String(QTest::currentTestFunction()) + QLatin1String("CloseWidget"));
|
2011-04-27 10:05:43 +00:00
|
|
|
QVERIFY(widget->testAttribute(Qt::WA_QuitOnClose));
|
2011-10-26 11:29:51 +00:00
|
|
|
widget->show();
|
2019-05-10 09:08:11 +00:00
|
|
|
QObject::connect(&app, &QGuiApplication::lastWindowClosed, widget.data(), &QObject::deleteLater);
|
|
|
|
QCoreApplication::exec();
|
2011-04-27 10:05:43 +00:00
|
|
|
QVERIFY(!widget);
|
|
|
|
QCOMPARE(spy.count(), 1);
|
|
|
|
spy.clear();
|
|
|
|
|
|
|
|
delete dialog;
|
|
|
|
|
|
|
|
// show 3 windows, close them, should only get lastWindowClosed once
|
|
|
|
QWidget w1;
|
2019-05-10 09:08:11 +00:00
|
|
|
w1.setWindowTitle(QLatin1String(QTest::currentTestFunction()) + QLatin1Char('1'));
|
2011-04-27 10:05:43 +00:00
|
|
|
QWidget w2;
|
2019-05-10 09:08:11 +00:00
|
|
|
w1.setWindowTitle(QLatin1String(QTest::currentTestFunction()) + QLatin1Char('2'));
|
2011-04-27 10:05:43 +00:00
|
|
|
QWidget w3;
|
2019-05-10 09:08:11 +00:00
|
|
|
w1.setWindowTitle(QLatin1String(QTest::currentTestFunction()) + QLatin1Char('3'));
|
2011-04-27 10:05:43 +00:00
|
|
|
w1.show();
|
|
|
|
w2.show();
|
|
|
|
w3.show();
|
|
|
|
|
2019-05-10 09:08:11 +00:00
|
|
|
QTimer::singleShot(1000, &app, &QApplication::closeAllWindows);
|
|
|
|
QCoreApplication::exec();
|
2011-04-27 10:05:43 +00:00
|
|
|
QCOMPARE(spy.count(), 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
class QuitOnLastWindowClosedDialog : public QDialog
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
QuitOnLastWindowClosedDialog()
|
|
|
|
{
|
|
|
|
QHBoxLayout *hbox = new QHBoxLayout(this);
|
2019-05-10 09:08:11 +00:00
|
|
|
m_okButton = new QPushButton("&ok", this);
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2019-05-10 09:08:11 +00:00
|
|
|
hbox->addWidget(m_okButton);
|
|
|
|
connect(m_okButton, &QAbstractButton::clicked, this, &QDialog::accept);
|
|
|
|
connect(m_okButton, &QAbstractButton::clicked, this, &QuitOnLastWindowClosedDialog::ok_clicked);
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public slots:
|
2019-05-10 09:08:11 +00:00
|
|
|
void animateOkClick() { m_okButton->animateClick(); }
|
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
void ok_clicked()
|
|
|
|
{
|
|
|
|
QDialog other;
|
|
|
|
|
|
|
|
QTimer timer;
|
2019-05-10 09:08:11 +00:00
|
|
|
connect(&timer, &QTimer::timeout, &other, &QDialog::accept);
|
|
|
|
QSignalSpy spy(&timer, &QTimer::timeout);
|
|
|
|
QSignalSpy appSpy(qApp, &QGuiApplication::lastWindowClosed);
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
timer.start(1000);
|
|
|
|
other.exec();
|
|
|
|
|
|
|
|
// verify that the eventloop ran and let the timer fire
|
|
|
|
QCOMPARE(spy.count(), 1);
|
|
|
|
QCOMPARE(appSpy.count(), 1);
|
|
|
|
}
|
2019-05-10 09:08:11 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
QPushButton *m_okButton;
|
2011-04-27 10:05:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class QuitOnLastWindowClosedWindow : public QWidget
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
2019-05-10 09:08:11 +00:00
|
|
|
QuitOnLastWindowClosedWindow() = default;
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
public slots:
|
|
|
|
void execDialogThenShow()
|
|
|
|
{
|
|
|
|
QDialog dialog;
|
2019-05-10 09:08:11 +00:00
|
|
|
dialog.setWindowTitle(QLatin1String("QuitOnLastWindowClosedWindow Dialog"));
|
2011-04-27 10:05:43 +00:00
|
|
|
QTimer timer1;
|
2019-05-10 09:08:11 +00:00
|
|
|
connect(&timer1, &QTimer::timeout, &dialog, &QDialog::accept);
|
|
|
|
QSignalSpy spy1(&timer1, &QTimer::timeout);
|
2011-04-27 10:05:43 +00:00
|
|
|
timer1.setSingleShot(true);
|
|
|
|
timer1.start(1000);
|
|
|
|
dialog.exec();
|
|
|
|
QCOMPARE(spy1.count(), 1);
|
|
|
|
|
|
|
|
show();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
void tst_QApplication::quitOnLastWindowClosed()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
int argc = 0;
|
2019-05-10 09:08:11 +00:00
|
|
|
QApplication app(argc, nullptr);
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
QuitOnLastWindowClosedDialog d;
|
2019-05-10 09:08:11 +00:00
|
|
|
d.setWindowTitle(QLatin1String(QTest::currentTestFunction()));
|
2011-04-27 10:05:43 +00:00
|
|
|
d.show();
|
2019-05-10 09:08:11 +00:00
|
|
|
QTimer::singleShot(1000, &d, &QuitOnLastWindowClosedDialog::animateOkClick);
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2019-05-10 09:08:11 +00:00
|
|
|
QSignalSpy appSpy(&app, &QGuiApplication::lastWindowClosed);
|
|
|
|
QCoreApplication::exec();
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
// lastWindowClosed() signal should only be sent after the last dialog is closed
|
|
|
|
QCOMPARE(appSpy.count(), 2);
|
|
|
|
}
|
|
|
|
{
|
|
|
|
int argc = 0;
|
2019-05-10 09:08:11 +00:00
|
|
|
QApplication app(argc, nullptr);
|
|
|
|
QSignalSpy appSpy(&app, &QGuiApplication::lastWindowClosed);
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
QDialog dialog;
|
2019-05-10 09:08:11 +00:00
|
|
|
dialog.setWindowTitle(QLatin1String(QTest::currentTestFunction()));
|
2011-04-27 10:05:43 +00:00
|
|
|
QTimer timer1;
|
2019-05-10 09:08:11 +00:00
|
|
|
connect(&timer1, &QTimer::timeout, &dialog, &QDialog::accept);
|
|
|
|
QSignalSpy spy1(&timer1, &QTimer::timeout);
|
2011-04-27 10:05:43 +00:00
|
|
|
timer1.setSingleShot(true);
|
|
|
|
timer1.start(1000);
|
|
|
|
dialog.exec();
|
|
|
|
QCOMPARE(spy1.count(), 1);
|
|
|
|
QCOMPARE(appSpy.count(), 0);
|
|
|
|
|
|
|
|
QTimer timer2;
|
2019-05-10 09:08:11 +00:00
|
|
|
connect(&timer2, &QTimer::timeout, &app, &QCoreApplication::quit);
|
|
|
|
QSignalSpy spy2(&timer2, &QTimer::timeout);
|
2011-04-27 10:05:43 +00:00
|
|
|
timer2.setSingleShot(true);
|
|
|
|
timer2.start(1000);
|
2019-05-10 09:08:11 +00:00
|
|
|
int returnValue = QCoreApplication::exec();
|
2011-04-27 10:05:43 +00:00
|
|
|
QCOMPARE(returnValue, 0);
|
|
|
|
QCOMPARE(spy2.count(), 1);
|
|
|
|
QCOMPARE(appSpy.count(), 0);
|
|
|
|
}
|
|
|
|
{
|
|
|
|
int argc = 0;
|
2019-05-10 09:08:11 +00:00
|
|
|
QApplication app(argc, nullptr);
|
2011-04-27 10:05:43 +00:00
|
|
|
QTimer timer;
|
|
|
|
timer.setInterval(100);
|
|
|
|
|
2019-05-10 09:08:11 +00:00
|
|
|
QSignalSpy spy(&app, &QCoreApplication::aboutToQuit);
|
|
|
|
QSignalSpy spy2(&timer, &QTimer::timeout);
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2013-07-04 07:55:32 +00:00
|
|
|
QMainWindow mainWindow;
|
2019-05-10 09:08:11 +00:00
|
|
|
mainWindow.setWindowTitle(QLatin1String(QTest::currentTestFunction()));
|
2013-07-04 07:55:32 +00:00
|
|
|
QDialog *dialog = new QDialog(&mainWindow);
|
2019-05-10 09:08:11 +00:00
|
|
|
dialog->setWindowTitle(QLatin1String(QTest::currentTestFunction()) + QLatin1String("Dialog"));
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
QVERIFY(app.quitOnLastWindowClosed());
|
2013-07-04 07:55:32 +00:00
|
|
|
QVERIFY(mainWindow.testAttribute(Qt::WA_QuitOnClose));
|
2011-04-27 10:05:43 +00:00
|
|
|
QVERIFY(dialog->testAttribute(Qt::WA_QuitOnClose));
|
|
|
|
|
2013-07-04 07:55:32 +00:00
|
|
|
mainWindow.show();
|
|
|
|
QVERIFY(QTest::qWaitForWindowExposed(&mainWindow));
|
2011-04-27 10:05:43 +00:00
|
|
|
dialog->show();
|
2013-07-04 07:55:32 +00:00
|
|
|
QVERIFY(QTest::qWaitForWindowExposed(dialog));
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
timer.start();
|
2019-05-10 09:08:11 +00:00
|
|
|
QTimer::singleShot(1000, &mainWindow, &QWidget::close); // This should quit the application
|
|
|
|
QTimer::singleShot(2000, &app, &QCoreApplication::quit); // This makes sure we quit even if it didn't
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2019-05-10 09:08:11 +00:00
|
|
|
QCoreApplication::exec();
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
QCOMPARE(spy.count(), 1);
|
|
|
|
QVERIFY(spy2.count() < 15); // Should be around 10 if closing caused the quit
|
|
|
|
}
|
2019-05-10 09:08:11 +00:00
|
|
|
|
|
|
|
bool quitApplicationTriggered = false;
|
|
|
|
auto quitSlot = [&quitApplicationTriggered] () {
|
|
|
|
quitApplicationTriggered = true;
|
2019-10-15 12:18:40 +00:00
|
|
|
QCoreApplication::exit();
|
2019-05-10 09:08:11 +00:00
|
|
|
};
|
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
|
|
|
int argc = 0;
|
2019-05-10 09:08:11 +00:00
|
|
|
QApplication app(argc, nullptr);
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2019-05-10 09:08:11 +00:00
|
|
|
QSignalSpy spy(&app, &QCoreApplication::aboutToQuit);
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2013-07-04 07:55:32 +00:00
|
|
|
CloseEventTestWindow mainWindow;
|
2019-05-10 09:08:11 +00:00
|
|
|
mainWindow.setWindowTitle(QLatin1String(QTest::currentTestFunction()));
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
QVERIFY(app.quitOnLastWindowClosed());
|
2013-07-04 07:55:32 +00:00
|
|
|
QVERIFY(mainWindow.testAttribute(Qt::WA_QuitOnClose));
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2013-07-04 07:55:32 +00:00
|
|
|
mainWindow.show();
|
|
|
|
QVERIFY(QTest::qWaitForWindowExposed(&mainWindow));
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2019-05-10 09:08:11 +00:00
|
|
|
QTimer::singleShot(1000, &mainWindow, &QWidget::close); // This should NOT quit the application (see CloseEventTestWindow)
|
2015-05-27 12:08:04 +00:00
|
|
|
quitApplicationTriggered = false;
|
2019-05-10 09:08:11 +00:00
|
|
|
QTimer::singleShot(2000, this, quitSlot); // This actually quits the application.
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2019-05-10 09:08:11 +00:00
|
|
|
QCoreApplication::exec();
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
QCOMPARE(spy.count(), 1);
|
2015-05-27 12:08:04 +00:00
|
|
|
QVERIFY(quitApplicationTriggered);
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
{
|
|
|
|
int argc = 0;
|
2019-05-10 09:08:11 +00:00
|
|
|
QApplication app(argc, nullptr);
|
|
|
|
QSignalSpy appSpy(&app, &QApplication::lastWindowClosed);
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
// exec a dialog for 1 second, then show the window
|
|
|
|
QuitOnLastWindowClosedWindow window;
|
2019-05-10 09:08:11 +00:00
|
|
|
window.setWindowTitle(QLatin1String(QTest::currentTestFunction()));
|
|
|
|
QTimer::singleShot(0, &window, &QuitOnLastWindowClosedWindow::execDialogThenShow);
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
QTimer timer;
|
2019-05-10 09:08:11 +00:00
|
|
|
QSignalSpy timerSpy(&timer, &QTimer::timeout);
|
|
|
|
connect(&timer, &QTimer::timeout, &window, &QWidget::close);
|
2011-04-27 10:05:43 +00:00
|
|
|
timer.setSingleShot(true);
|
|
|
|
timer.start(2000);
|
2019-05-10 09:08:11 +00:00
|
|
|
int returnValue = QCoreApplication::exec();
|
2011-04-27 10:05:43 +00:00
|
|
|
QCOMPARE(returnValue, 0);
|
|
|
|
// failure here means the timer above didn't fire, and the
|
2012-09-24 16:12:43 +00:00
|
|
|
// quit was caused the dialog being closed (not the window)
|
2011-04-27 10:05:43 +00:00
|
|
|
QCOMPARE(timerSpy.count(), 1);
|
|
|
|
QCOMPARE(appSpy.count(), 2);
|
|
|
|
}
|
2012-05-14 14:58:26 +00:00
|
|
|
{
|
|
|
|
int argc = 0;
|
2019-05-10 09:08:11 +00:00
|
|
|
QApplication app(argc, nullptr);
|
2012-05-14 14:58:26 +00:00
|
|
|
QVERIFY(app.quitOnLastWindowClosed());
|
|
|
|
|
|
|
|
QWindow w;
|
2019-05-10 09:08:11 +00:00
|
|
|
w.setTitle(QLatin1String(QTest::currentTestFunction()) + QLatin1String("Window"));
|
2012-05-14 14:58:26 +00:00
|
|
|
w.show();
|
|
|
|
|
|
|
|
QWidget wid;
|
2019-05-10 09:08:11 +00:00
|
|
|
wid.setWindowTitle(QLatin1String(QTest::currentTestFunction()) + QLatin1String("Widget"));
|
2012-05-14 14:58:26 +00:00
|
|
|
wid.show();
|
|
|
|
|
2019-05-10 09:08:11 +00:00
|
|
|
QTimer::singleShot(1000, &wid, &QWidget::close); // This should NOT quit the application because the
|
2012-05-14 14:58:26 +00:00
|
|
|
// QWindow is still there.
|
2015-05-27 12:08:04 +00:00
|
|
|
quitApplicationTriggered = false;
|
2019-05-10 09:08:11 +00:00
|
|
|
QTimer::singleShot(2000, this, quitSlot); // This causes the quit.
|
2012-05-14 14:58:26 +00:00
|
|
|
|
2019-05-10 09:08:11 +00:00
|
|
|
QCoreApplication::exec();
|
2012-05-14 14:58:26 +00:00
|
|
|
|
2015-05-27 12:08:04 +00:00
|
|
|
QVERIFY(quitApplicationTriggered); // Should be around 20 if closing did not caused the quit
|
2012-05-14 14:58:26 +00:00
|
|
|
}
|
2013-06-18 12:42:43 +00:00
|
|
|
{ // QTBUG-31569: If the last widget with Qt::WA_QuitOnClose set is closed, other
|
|
|
|
// widgets that don't have the attribute set should be closed automatically.
|
|
|
|
int argc = 0;
|
2019-05-10 09:08:11 +00:00
|
|
|
QApplication app(argc, nullptr);
|
2013-06-18 12:42:43 +00:00
|
|
|
QVERIFY(app.quitOnLastWindowClosed());
|
|
|
|
|
|
|
|
QWidget w1;
|
2019-05-10 09:08:11 +00:00
|
|
|
w1.setWindowTitle(QLatin1String(QTest::currentTestFunction()) + QLatin1Char('1'));
|
2013-06-18 12:42:43 +00:00
|
|
|
w1.show();
|
|
|
|
|
|
|
|
QWidget w2;
|
2019-05-10 09:08:11 +00:00
|
|
|
w1.setWindowTitle(QLatin1String(QTest::currentTestFunction()) + QLatin1Char('2'));
|
2013-06-18 12:42:43 +00:00
|
|
|
w2.setAttribute(Qt::WA_QuitOnClose, false);
|
|
|
|
w2.show();
|
|
|
|
|
|
|
|
QVERIFY(QTest::qWaitForWindowExposed(&w2));
|
|
|
|
|
|
|
|
QTimer timer;
|
|
|
|
timer.setInterval(100);
|
|
|
|
timer.start();
|
2019-05-10 09:08:11 +00:00
|
|
|
QSignalSpy timerSpy(&timer, &QTimer::timeout);
|
2013-06-18 12:42:43 +00:00
|
|
|
|
2019-05-10 09:08:11 +00:00
|
|
|
QTimer::singleShot(100, &w1, &QWidget::close);
|
|
|
|
QCoreApplication::exec();
|
2013-06-18 12:42:43 +00:00
|
|
|
|
|
|
|
QVERIFY(timerSpy.count() < 10);
|
|
|
|
}
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
2019-05-10 09:08:11 +00:00
|
|
|
static inline bool isVisible(const QWidget *w)
|
|
|
|
{
|
|
|
|
return w->isVisible();
|
|
|
|
}
|
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
class PromptOnCloseWidget : public QWidget
|
|
|
|
{
|
|
|
|
public:
|
2019-05-10 09:08:11 +00:00
|
|
|
void closeEvent(QCloseEvent *event) override
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
|
|
|
QMessageBox *messageBox = new QMessageBox(this);
|
|
|
|
messageBox->setWindowTitle("Unsaved data");
|
|
|
|
messageBox->setText("Would you like to save or discard your current data?");
|
|
|
|
messageBox->setStandardButtons(QMessageBox::Save|QMessageBox::Discard|QMessageBox::Cancel);
|
|
|
|
messageBox->setDefaultButton(QMessageBox::Save);
|
|
|
|
|
|
|
|
messageBox->show();
|
2012-07-30 10:36:02 +00:00
|
|
|
QVERIFY(QTest::qWaitForWindowExposed(messageBox));
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
// verify that all windows are visible
|
2019-05-10 09:08:11 +00:00
|
|
|
const auto &topLevels = QApplication::topLevelWidgets();
|
|
|
|
QVERIFY(std::all_of(topLevels.cbegin(), topLevels.cend(), ::isVisible));
|
2011-04-27 10:05:43 +00:00
|
|
|
// flush event queue
|
2019-05-10 09:08:11 +00:00
|
|
|
QCoreApplication::processEvents();
|
2011-04-27 10:05:43 +00:00
|
|
|
// close all windows
|
2019-05-10 09:08:11 +00:00
|
|
|
QApplication::closeAllWindows();
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
if (messageBox->standardButton(messageBox->clickedButton()) == QMessageBox::Cancel)
|
|
|
|
event->ignore();
|
|
|
|
else
|
|
|
|
event->accept();
|
|
|
|
|
|
|
|
delete messageBox;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
void tst_QApplication::closeAllWindows()
|
|
|
|
{
|
|
|
|
int argc = 0;
|
2019-05-10 09:08:11 +00:00
|
|
|
QApplication app(argc, nullptr);
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
// create some windows
|
|
|
|
new QWidget;
|
|
|
|
new QWidget;
|
|
|
|
new QWidget;
|
|
|
|
|
|
|
|
// show all windows
|
2019-05-10 09:08:11 +00:00
|
|
|
auto topLevels = QApplication::topLevelWidgets();
|
|
|
|
for (QWidget *w : qAsConst(topLevels)) {
|
2011-04-27 10:05:43 +00:00
|
|
|
w->show();
|
2012-07-30 10:36:02 +00:00
|
|
|
QVERIFY(QTest::qWaitForWindowExposed(w));
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
// verify that they are visible
|
2019-05-10 09:08:11 +00:00
|
|
|
QVERIFY(std::all_of(topLevels.cbegin(), topLevels.cend(), isVisible));
|
2011-04-27 10:05:43 +00:00
|
|
|
// empty event queue
|
2019-05-10 09:08:11 +00:00
|
|
|
QCoreApplication::processEvents();
|
2011-04-27 10:05:43 +00:00
|
|
|
// close all windows
|
2019-05-10 09:08:11 +00:00
|
|
|
QApplication::closeAllWindows();
|
2011-04-27 10:05:43 +00:00
|
|
|
// all windows should no longer be visible
|
2019-05-10 09:08:11 +00:00
|
|
|
QVERIFY(std::all_of(topLevels.cbegin(), topLevels.cend(), [] (const QWidget *w) { return !w->isVisible(); }));
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
// add a window that prompts the user when closed
|
|
|
|
PromptOnCloseWidget *promptOnCloseWidget = new PromptOnCloseWidget;
|
|
|
|
// show all windows
|
2019-05-10 09:08:11 +00:00
|
|
|
topLevels = QApplication::topLevelWidgets();
|
|
|
|
for (QWidget *w : qAsConst(topLevels)) {
|
2011-04-27 10:05:43 +00:00
|
|
|
w->show();
|
2012-07-30 10:36:02 +00:00
|
|
|
QVERIFY(QTest::qWaitForWindowExposed(w));
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
// close the last window to open the prompt (eventloop recurses)
|
|
|
|
promptOnCloseWidget->close();
|
|
|
|
// all windows should not be visible, except the one that opened the prompt
|
2019-05-10 09:08:11 +00:00
|
|
|
for (QWidget *w : qAsConst(topLevels)) {
|
2011-04-27 10:05:43 +00:00
|
|
|
if (w == promptOnCloseWidget)
|
|
|
|
QVERIFY(w->isVisible());
|
|
|
|
else
|
|
|
|
QVERIFY(!w->isVisible());
|
|
|
|
}
|
|
|
|
|
2019-05-10 09:08:11 +00:00
|
|
|
qDeleteAll(QApplication::topLevelWidgets());
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool isPathListIncluded(const QStringList &l, const QStringList &r)
|
|
|
|
{
|
|
|
|
int size = r.count();
|
|
|
|
if (size > l.count())
|
|
|
|
return false;
|
|
|
|
#if defined (Q_OS_WIN)
|
|
|
|
Qt::CaseSensitivity cs = Qt::CaseInsensitive;
|
|
|
|
#else
|
|
|
|
Qt::CaseSensitivity cs = Qt::CaseSensitive;
|
|
|
|
#endif
|
|
|
|
int i = 0, j = 0;
|
|
|
|
for ( ; i < l.count() && j < r.count(); ++i) {
|
|
|
|
if (QDir::toNativeSeparators(l[i]).compare(QDir::toNativeSeparators(r[j]), cs) == 0) {
|
|
|
|
++j;
|
|
|
|
i = -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return j == r.count();
|
|
|
|
}
|
|
|
|
|
2016-12-19 09:34:32 +00:00
|
|
|
#if QT_CONFIG(library)
|
2011-04-27 10:05:43 +00:00
|
|
|
void tst_QApplication::libraryPaths()
|
|
|
|
{
|
2018-05-17 13:23:03 +00:00
|
|
|
#ifndef BUILTIN_TESTDATA
|
2020-12-17 13:55:57 +00:00
|
|
|
const QString testDir = QFileInfo(QFINDTESTDATA("test/CMakeLists.txt")).absolutePath();
|
2018-05-17 13:23:03 +00:00
|
|
|
#else
|
2020-12-17 13:55:57 +00:00
|
|
|
const QString testDir = QFileInfo(QFINDTESTDATA("CMakeLists.txt")).absolutePath();
|
2018-05-17 13:23:03 +00:00
|
|
|
#endif
|
2014-07-09 12:25:26 +00:00
|
|
|
QVERIFY(!testDir.isEmpty());
|
|
|
|
{
|
2011-04-27 10:05:43 +00:00
|
|
|
QApplication::setLibraryPaths(QStringList() << testDir);
|
|
|
|
QCOMPARE(QApplication::libraryPaths(), (QStringList() << testDir));
|
|
|
|
|
|
|
|
// creating QApplication adds the applicationDirPath to the libraryPath
|
|
|
|
int argc = 1;
|
2012-11-23 14:02:46 +00:00
|
|
|
QApplication app(argc, &argv0);
|
2019-05-10 09:08:11 +00:00
|
|
|
QString appDirPath = QDir(QCoreApplication::applicationDirPath()).canonicalPath();
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
QStringList actual = QApplication::libraryPaths();
|
|
|
|
actual.sort();
|
2019-05-06 12:00:53 +00:00
|
|
|
QStringList expected;
|
|
|
|
expected << testDir << appDirPath;
|
|
|
|
expected = QSet<QString>(expected.constBegin(), expected.constEnd()).values();
|
2011-04-27 10:05:43 +00:00
|
|
|
expected.sort();
|
|
|
|
|
|
|
|
QVERIFY2(isPathListIncluded(actual, expected),
|
|
|
|
qPrintable("actual:\n - " + actual.join("\n - ") +
|
|
|
|
"\nexpected:\n - " + expected.join("\n - ")));
|
|
|
|
}
|
|
|
|
{
|
|
|
|
// creating QApplication adds the applicationDirPath and plugin install path to the libraryPath
|
|
|
|
int argc = 1;
|
2012-11-23 14:02:46 +00:00
|
|
|
QApplication app(argc, &argv0);
|
2019-05-10 09:08:11 +00:00
|
|
|
QString appDirPath = QCoreApplication::applicationDirPath();
|
2020-09-04 07:45:26 +00:00
|
|
|
QString installPathPlugins = QLibraryInfo::path(QLibraryInfo::PluginsPath);
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
QStringList actual = QApplication::libraryPaths();
|
|
|
|
actual.sort();
|
|
|
|
|
2019-05-06 12:00:53 +00:00
|
|
|
QStringList expected;
|
|
|
|
expected << installPathPlugins << appDirPath;
|
|
|
|
expected = QSet<QString>(expected.constBegin(), expected.constEnd()).values();
|
2011-04-27 10:05:43 +00:00
|
|
|
expected.sort();
|
|
|
|
|
|
|
|
QVERIFY2(isPathListIncluded(actual, expected),
|
|
|
|
qPrintable("actual:\n - " + actual.join("\n - ") +
|
|
|
|
"\nexpected:\n - " + expected.join("\n - ")));
|
|
|
|
|
|
|
|
// setting the library paths overrides everything
|
2014-07-09 12:25:26 +00:00
|
|
|
QApplication::setLibraryPaths(QStringList() << testDir);
|
2011-04-27 10:05:43 +00:00
|
|
|
QVERIFY2(isPathListIncluded(QApplication::libraryPaths(), (QStringList() << testDir)),
|
|
|
|
qPrintable("actual:\n - " + QApplication::libraryPaths().join("\n - ") +
|
|
|
|
"\nexpected:\n - " + testDir));
|
|
|
|
}
|
|
|
|
{
|
2019-05-10 09:08:11 +00:00
|
|
|
qCDebug(lcTests) << "Initial library path:" << QApplication::libraryPaths();
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
int count = QApplication::libraryPaths().count();
|
|
|
|
#if 0
|
|
|
|
// this test doesn't work if KDE 4 is installed
|
|
|
|
QCOMPARE(count, 1); // before creating QApplication, only the PluginsPath is in the libraryPaths()
|
|
|
|
#endif
|
2020-09-04 07:45:26 +00:00
|
|
|
QString installPathPlugins = QLibraryInfo::path(QLibraryInfo::PluginsPath);
|
2011-04-27 10:05:43 +00:00
|
|
|
QApplication::addLibraryPath(installPathPlugins);
|
2019-05-10 09:08:11 +00:00
|
|
|
qCDebug(lcTests) << "installPathPlugins" << installPathPlugins;
|
|
|
|
qCDebug(lcTests) << "After adding plugins path:" << QApplication::libraryPaths();
|
2011-04-27 10:05:43 +00:00
|
|
|
QCOMPARE(QApplication::libraryPaths().count(), count);
|
2012-01-25 01:29:16 +00:00
|
|
|
QApplication::addLibraryPath(testDir);
|
2011-04-27 10:05:43 +00:00
|
|
|
QCOMPARE(QApplication::libraryPaths().count(), count + 1);
|
|
|
|
|
|
|
|
// creating QApplication adds the applicationDirPath to the libraryPath
|
|
|
|
int argc = 1;
|
2012-11-23 14:02:46 +00:00
|
|
|
QApplication app(argc, &argv0);
|
2019-05-10 09:08:11 +00:00
|
|
|
QString appDirPath = QCoreApplication::applicationDirPath();
|
|
|
|
qCDebug(lcTests) << QApplication::libraryPaths();
|
2011-04-27 10:05:43 +00:00
|
|
|
// On Windows CE these are identical and might also be the case for other
|
|
|
|
// systems too
|
|
|
|
if (appDirPath != installPathPlugins)
|
|
|
|
QCOMPARE(QApplication::libraryPaths().count(), count + 2);
|
|
|
|
}
|
|
|
|
{
|
|
|
|
int argc = 1;
|
2012-11-23 14:02:46 +00:00
|
|
|
QApplication app(argc, &argv0);
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2019-05-10 09:08:11 +00:00
|
|
|
qCDebug(lcTests) << "Initial library path:" << QCoreApplication::libraryPaths();
|
|
|
|
int count = QCoreApplication::libraryPaths().count();
|
2020-09-04 07:45:26 +00:00
|
|
|
QString installPathPlugins = QLibraryInfo::path(QLibraryInfo::PluginsPath);
|
2019-05-10 09:08:11 +00:00
|
|
|
QCoreApplication::addLibraryPath(installPathPlugins);
|
|
|
|
qCDebug(lcTests) << "installPathPlugins" << installPathPlugins;
|
|
|
|
qCDebug(lcTests) << "After adding plugins path:" << QCoreApplication::libraryPaths();
|
|
|
|
QCOMPARE(QCoreApplication::libraryPaths().count(), count);
|
|
|
|
|
|
|
|
QString appDirPath = QCoreApplication::applicationDirPath();
|
|
|
|
|
|
|
|
QCoreApplication::addLibraryPath(appDirPath);
|
|
|
|
QCoreApplication::addLibraryPath(appDirPath + "/..");
|
|
|
|
qCDebug(lcTests) << "appDirPath" << appDirPath;
|
|
|
|
qCDebug(lcTests) << "After adding appDirPath && appDirPath + /..:" << QCoreApplication::libraryPaths();
|
|
|
|
QCOMPARE(QCoreApplication::libraryPaths().count(), count + 1);
|
|
|
|
#ifdef Q_OS_MACOS
|
|
|
|
QCoreApplication::addLibraryPath(appDirPath + "/../MacOS");
|
2011-04-27 10:05:43 +00:00
|
|
|
#else
|
2019-05-10 09:08:11 +00:00
|
|
|
QCoreApplication::addLibraryPath(appDirPath + "/tmp/..");
|
2011-04-27 10:05:43 +00:00
|
|
|
#endif
|
2019-05-10 09:08:11 +00:00
|
|
|
qCDebug(lcTests) << "After adding appDirPath + /tmp/..:" << QCoreApplication::libraryPaths();
|
|
|
|
QCOMPARE(QCoreApplication::libraryPaths().count(), count + 1);
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void tst_QApplication::libraryPaths_qt_plugin_path()
|
|
|
|
{
|
|
|
|
int argc = 1;
|
|
|
|
|
2012-11-23 14:02:46 +00:00
|
|
|
QApplication app(argc, &argv0);
|
2019-05-10 09:08:11 +00:00
|
|
|
QString appDirPath = QCoreApplication::applicationDirPath();
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
// Our hook into libraryPaths() initialization: Set the QT_PLUGIN_PATH environment variable
|
|
|
|
QString installPathPluginsDeCanon = appDirPath + QString::fromLatin1("/tmp/..");
|
2012-05-02 13:36:35 +00:00
|
|
|
QByteArray ascii = QFile::encodeName(installPathPluginsDeCanon);
|
2011-04-27 10:05:43 +00:00
|
|
|
qputenv("QT_PLUGIN_PATH", ascii);
|
|
|
|
|
2019-05-10 09:08:11 +00:00
|
|
|
QVERIFY(!QCoreApplication::libraryPaths().contains(appDirPath + QString::fromLatin1("/tmp/..")));
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void tst_QApplication::libraryPaths_qt_plugin_path_2()
|
|
|
|
{
|
2011-09-27 09:53:01 +00:00
|
|
|
#ifdef Q_OS_UNIX
|
2011-04-27 10:05:43 +00:00
|
|
|
QByteArray validPath = QDir("/tmp").canonicalPath().toLatin1();
|
|
|
|
QByteArray nonExistentPath = "/nonexistent";
|
2015-10-13 07:46:56 +00:00
|
|
|
QByteArray pluginPath = validPath + ':' + nonExistentPath;
|
2011-04-27 10:05:43 +00:00
|
|
|
#elif defined(Q_OS_WIN)
|
|
|
|
QByteArray validPath = "C:\\windows";
|
|
|
|
QByteArray nonExistentPath = "Z:\\nonexistent";
|
2015-10-13 07:46:56 +00:00
|
|
|
QByteArray pluginPath = validPath + ';' + nonExistentPath;
|
2011-04-27 10:05:43 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
{
|
|
|
|
// Our hook into libraryPaths() initialization: Set the QT_PLUGIN_PATH environment variable
|
|
|
|
qputenv("QT_PLUGIN_PATH", pluginPath);
|
|
|
|
|
|
|
|
int argc = 1;
|
|
|
|
|
2012-11-23 14:02:46 +00:00
|
|
|
QApplication app(argc, &argv0);
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
// library path list should contain the default plus the one valid path
|
|
|
|
QStringList expected =
|
|
|
|
QStringList()
|
2020-09-04 07:45:26 +00:00
|
|
|
<< QLibraryInfo::path(QLibraryInfo::PluginsPath)
|
2019-05-10 09:08:11 +00:00
|
|
|
<< QDir(QCoreApplication::applicationDirPath()).canonicalPath()
|
2011-04-27 10:05:43 +00:00
|
|
|
<< QDir(QDir::fromNativeSeparators(QString::fromLatin1(validPath))).canonicalPath();
|
2016-03-08 14:51:15 +00:00
|
|
|
|
2019-05-10 09:08:11 +00:00
|
|
|
QVERIFY2(isPathListIncluded(QCoreApplication::libraryPaths(), expected),
|
|
|
|
qPrintable("actual:\n - " + QCoreApplication::libraryPaths().join("\n - ") +
|
2011-04-27 10:05:43 +00:00
|
|
|
"\nexpected:\n - " + expected.join("\n - ")));
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
int argc = 1;
|
|
|
|
|
2012-11-23 14:02:46 +00:00
|
|
|
QApplication app(argc, &argv0);
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
// library paths are initialized by the QApplication, setting
|
|
|
|
// the environment variable here doesn't work
|
|
|
|
qputenv("QT_PLUGIN_PATH", pluginPath);
|
|
|
|
|
|
|
|
// library path list should contain the default
|
|
|
|
QStringList expected =
|
|
|
|
QStringList()
|
2020-09-04 07:45:26 +00:00
|
|
|
<< QLibraryInfo::path(QLibraryInfo::PluginsPath)
|
2019-05-10 09:08:11 +00:00
|
|
|
<< QCoreApplication::applicationDirPath();
|
|
|
|
QVERIFY(isPathListIncluded(QCoreApplication::libraryPaths(), expected));
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
qputenv("QT_PLUGIN_PATH", QByteArray());
|
|
|
|
}
|
|
|
|
}
|
2015-07-20 13:10:33 +00:00
|
|
|
#endif
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
class SendPostedEventsTester : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
QList<int> eventSpy;
|
2019-05-10 09:08:11 +00:00
|
|
|
bool event(QEvent *e) override;
|
2011-04-27 10:05:43 +00:00
|
|
|
private slots:
|
|
|
|
void doTest();
|
|
|
|
};
|
|
|
|
|
|
|
|
bool SendPostedEventsTester::event(QEvent *e)
|
|
|
|
{
|
|
|
|
eventSpy.append(e->type());
|
|
|
|
return QObject::event(e);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SendPostedEventsTester::doTest()
|
|
|
|
{
|
|
|
|
QPointer<SendPostedEventsTester> p = this;
|
|
|
|
QApplication::postEvent(this, new QEvent(QEvent::User));
|
|
|
|
// DeferredDelete should not be delivered until returning from this function
|
2012-05-14 11:27:28 +00:00
|
|
|
QApplication::postEvent(this, new QDeferredDeleteEvent());
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
QEventLoop eventLoop;
|
|
|
|
QMetaObject::invokeMethod(&eventLoop, "quit", Qt::QueuedConnection);
|
|
|
|
eventLoop.exec();
|
2019-05-10 09:08:11 +00:00
|
|
|
QVERIFY(p != nullptr);
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
QCOMPARE(eventSpy.count(), 2);
|
|
|
|
QCOMPARE(eventSpy.at(0), int(QEvent::MetaCall));
|
|
|
|
QCOMPARE(eventSpy.at(1), int(QEvent::User));
|
|
|
|
eventSpy.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
void tst_QApplication::sendPostedEvents()
|
|
|
|
{
|
|
|
|
int argc = 0;
|
2019-05-10 09:08:11 +00:00
|
|
|
QApplication app(argc, nullptr);
|
2011-04-27 10:05:43 +00:00
|
|
|
SendPostedEventsTester *tester = new SendPostedEventsTester;
|
|
|
|
QMetaObject::invokeMethod(tester, "doTest", Qt::QueuedConnection);
|
|
|
|
QMetaObject::invokeMethod(&app, "quit", Qt::QueuedConnection);
|
|
|
|
QPointer<SendPostedEventsTester> p = tester;
|
2019-05-10 09:08:11 +00:00
|
|
|
(void) QCoreApplication::exec();
|
2015-07-30 13:16:36 +00:00
|
|
|
QVERIFY(p.isNull());
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void tst_QApplication::thread()
|
|
|
|
{
|
|
|
|
QThread *currentThread = QThread::currentThread();
|
|
|
|
// no app, but still have a valid thread
|
2019-05-10 09:08:11 +00:00
|
|
|
QVERIFY(currentThread != nullptr);
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
// the thread should be running and not finished
|
|
|
|
QVERIFY(currentThread->isRunning());
|
|
|
|
QVERIFY(!currentThread->isFinished());
|
|
|
|
|
|
|
|
// this should probably be in the tst_QObject::thread() test, but
|
|
|
|
// we put it here since we want to make sure that objects created
|
|
|
|
// *before* the QApplication has a thread
|
|
|
|
QObject object;
|
|
|
|
QObject child(&object);
|
2015-07-30 13:16:36 +00:00
|
|
|
QCOMPARE(object.thread(), currentThread);
|
|
|
|
QCOMPARE(child.thread(), currentThread);
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
int argc = 0;
|
2019-05-10 09:08:11 +00:00
|
|
|
QApplication app(argc, nullptr);
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
// current thread still valid
|
2019-05-10 09:08:11 +00:00
|
|
|
QVERIFY(QThread::currentThread() != nullptr);
|
2011-04-27 10:05:43 +00:00
|
|
|
// thread should be the same as before
|
|
|
|
QCOMPARE(QThread::currentThread(), currentThread);
|
|
|
|
|
|
|
|
// app's thread should be the current thread
|
|
|
|
QCOMPARE(app.thread(), currentThread);
|
|
|
|
|
|
|
|
// the thread should still be running and not finished
|
|
|
|
QVERIFY(currentThread->isRunning());
|
|
|
|
QVERIFY(!currentThread->isFinished());
|
|
|
|
|
|
|
|
QTestEventLoop::instance().enterLoop(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
// app dead, current thread still valid
|
2019-05-10 09:08:11 +00:00
|
|
|
QVERIFY(QThread::currentThread() != nullptr);
|
2011-04-27 10:05:43 +00:00
|
|
|
QCOMPARE(QThread::currentThread(), currentThread);
|
|
|
|
|
|
|
|
// the thread should still be running and not finished
|
|
|
|
QVERIFY(currentThread->isRunning());
|
|
|
|
QVERIFY(!currentThread->isFinished());
|
|
|
|
|
|
|
|
// should still have a thread
|
2015-07-30 13:16:36 +00:00
|
|
|
QCOMPARE(object.thread(), currentThread);
|
|
|
|
QCOMPARE(child.thread(), currentThread);
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
// do the test again, making sure that the thread is the same as
|
|
|
|
// before
|
|
|
|
{
|
|
|
|
int argc = 0;
|
2019-05-10 09:08:11 +00:00
|
|
|
QApplication app(argc, nullptr);
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
// current thread still valid
|
2019-05-10 09:08:11 +00:00
|
|
|
QVERIFY(QThread::currentThread() != nullptr);
|
2011-04-27 10:05:43 +00:00
|
|
|
// thread should be the same as before
|
|
|
|
QCOMPARE(QThread::currentThread(), currentThread);
|
|
|
|
|
|
|
|
// app's thread should be the current thread
|
|
|
|
QCOMPARE(app.thread(), currentThread);
|
|
|
|
|
|
|
|
// the thread should be running and not finished
|
|
|
|
QVERIFY(currentThread->isRunning());
|
|
|
|
QVERIFY(!currentThread->isFinished());
|
|
|
|
|
|
|
|
// should still have a thread
|
2015-07-30 13:16:36 +00:00
|
|
|
QCOMPARE(object.thread(), currentThread);
|
|
|
|
QCOMPARE(child.thread(), currentThread);
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
QTestEventLoop::instance().enterLoop(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
// app dead, current thread still valid
|
2019-05-10 09:08:11 +00:00
|
|
|
QVERIFY(QThread::currentThread() != nullptr);
|
2011-04-27 10:05:43 +00:00
|
|
|
QCOMPARE(QThread::currentThread(), currentThread);
|
|
|
|
|
|
|
|
// the thread should still be running and not finished
|
|
|
|
QVERIFY(currentThread->isRunning());
|
|
|
|
QVERIFY(!currentThread->isFinished());
|
|
|
|
|
|
|
|
// should still have a thread
|
2015-07-30 13:16:36 +00:00
|
|
|
QCOMPARE(object.thread(), currentThread);
|
|
|
|
QCOMPARE(child.thread(), currentThread);
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
class DeleteLaterWidget : public QWidget
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
2019-05-10 09:08:11 +00:00
|
|
|
explicit DeleteLaterWidget(QApplication *_app, QWidget *parent = nullptr)
|
|
|
|
: QWidget(parent), app(_app) {}
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2019-05-10 09:08:11 +00:00
|
|
|
bool child_deleted = false;
|
2011-04-27 10:05:43 +00:00
|
|
|
QApplication *app;
|
|
|
|
|
|
|
|
public slots:
|
|
|
|
void runTest();
|
|
|
|
void checkDeleteLater();
|
|
|
|
void childDeleted() { child_deleted = true; }
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
void DeleteLaterWidget::runTest()
|
|
|
|
{
|
2013-03-27 14:16:32 +00:00
|
|
|
QObject *stillAlive = this->findChild<QObject*>("deleteLater");
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
QWidget *w = new QWidget(this);
|
2019-05-10 09:08:11 +00:00
|
|
|
connect(w, &QObject::destroyed, this, &DeleteLaterWidget::childDeleted);
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
w->deleteLater();
|
|
|
|
QVERIFY(!child_deleted);
|
|
|
|
|
|
|
|
QDialog dlg;
|
2019-05-10 09:08:11 +00:00
|
|
|
QTimer::singleShot(500, &dlg, &QDialog::reject);
|
2011-04-27 10:05:43 +00:00
|
|
|
dlg.exec();
|
|
|
|
|
|
|
|
QVERIFY(!child_deleted);
|
2019-05-10 09:08:11 +00:00
|
|
|
QCoreApplication::processEvents();
|
2011-04-27 10:05:43 +00:00
|
|
|
QVERIFY(!child_deleted);
|
|
|
|
|
2019-05-10 09:08:11 +00:00
|
|
|
QTimer::singleShot(500, this, &DeleteLaterWidget::checkDeleteLater);
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2019-05-10 09:08:11 +00:00
|
|
|
QCoreApplication::processEvents();
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2020-03-31 13:43:54 +00:00
|
|
|
// At this point, the event queue is empty. As we want a deferred
|
|
|
|
// deletion to occur before the timer event, we should provoke the
|
|
|
|
// event dispatcher for the next spin.
|
|
|
|
QCoreApplication::eventDispatcher()->interrupt();
|
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
QVERIFY(!stillAlive); // verify at the end to make test terminate
|
|
|
|
}
|
|
|
|
|
|
|
|
void DeleteLaterWidget::checkDeleteLater()
|
|
|
|
{
|
|
|
|
QVERIFY(child_deleted);
|
|
|
|
|
|
|
|
close();
|
|
|
|
}
|
|
|
|
|
|
|
|
void tst_QApplication::testDeleteLater()
|
|
|
|
{
|
2012-02-16 08:22:39 +00:00
|
|
|
#ifdef Q_OS_MAC
|
2015-05-28 10:45:48 +00:00
|
|
|
QSKIP("This test fails and then hangs on OS X, see QTBUG-24318");
|
2012-02-16 08:22:39 +00:00
|
|
|
#endif
|
2011-04-27 10:05:43 +00:00
|
|
|
int argc = 0;
|
2019-05-10 09:08:11 +00:00
|
|
|
QApplication app(argc, nullptr);
|
|
|
|
connect(&app, &QApplication::lastWindowClosed, &app, &QCoreApplication::quit);
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
DeleteLaterWidget *wgt = new DeleteLaterWidget(&app);
|
2019-05-10 09:08:11 +00:00
|
|
|
QTimer::singleShot(500, wgt, &DeleteLaterWidget::runTest);
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
QObject *object = new QObject(wgt);
|
|
|
|
object->setObjectName("deleteLater");
|
|
|
|
object->deleteLater();
|
|
|
|
|
2013-03-27 14:16:32 +00:00
|
|
|
QObject *stillAlive = wgt->findChild<QObject*>("deleteLater");
|
2011-04-27 10:05:43 +00:00
|
|
|
QVERIFY(stillAlive);
|
|
|
|
|
2020-03-31 13:43:54 +00:00
|
|
|
wgt->show();
|
2019-05-10 09:08:11 +00:00
|
|
|
QCoreApplication::exec();
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2020-03-31 13:43:54 +00:00
|
|
|
QVERIFY(wgt->isHidden());
|
2011-04-27 10:05:43 +00:00
|
|
|
delete wgt;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
class EventLoopNester : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public slots:
|
|
|
|
void deleteLaterAndEnterLoop()
|
|
|
|
{
|
|
|
|
QEventLoop eventLoop;
|
|
|
|
QPointer<QObject> p(this);
|
|
|
|
deleteLater();
|
|
|
|
/*
|
|
|
|
DeferredDelete events are compressed, meaning this second
|
|
|
|
deleteLater() will *not* delete the object in the nested
|
|
|
|
event loop
|
|
|
|
*/
|
|
|
|
QMetaObject::invokeMethod(this, "deleteLater", Qt::QueuedConnection);
|
2019-05-10 09:08:11 +00:00
|
|
|
QTimer::singleShot(1000, &eventLoop, &QEventLoop::quit);
|
2011-04-27 10:05:43 +00:00
|
|
|
eventLoop.exec();
|
|
|
|
QVERIFY(p);
|
|
|
|
}
|
|
|
|
void deleteLaterAndExitLoop()
|
|
|
|
{
|
|
|
|
// Check that 'p' is not deleted before exec returns, since the call
|
|
|
|
// to QEventLoop::quit() should stop 'eventLoop' from processing
|
|
|
|
// any more events (that is, delete later) until we return to the
|
|
|
|
// _current_ event loop:
|
|
|
|
QEventLoop eventLoop;
|
|
|
|
QPointer<QObject> p(this);
|
|
|
|
QMetaObject::invokeMethod(this, "deleteLater", Qt::QueuedConnection);
|
|
|
|
QMetaObject::invokeMethod(&eventLoop, "quit", Qt::QueuedConnection);
|
|
|
|
eventLoop.exec();
|
|
|
|
QVERIFY(p); // not dead yet
|
|
|
|
}
|
|
|
|
|
|
|
|
void processEventsOnly()
|
|
|
|
{
|
|
|
|
QApplication::processEvents();
|
|
|
|
}
|
|
|
|
void sendPostedEventsWithDeferredDelete()
|
|
|
|
{
|
2019-05-10 09:08:11 +00:00
|
|
|
QApplication::sendPostedEvents(nullptr, QEvent::DeferredDelete);
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
2012-01-19 10:53:09 +00:00
|
|
|
void deleteLaterAndProcessEvents()
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
|
|
|
QEventLoop eventLoop;
|
|
|
|
|
|
|
|
QPointer<QObject> p = this;
|
|
|
|
deleteLater();
|
|
|
|
|
|
|
|
// trying to delete this object in a deeper eventloop just won't work
|
|
|
|
QMetaObject::invokeMethod(this,
|
|
|
|
"processEventsOnly",
|
|
|
|
Qt::QueuedConnection);
|
|
|
|
QMetaObject::invokeMethod(&eventLoop, "quit", Qt::QueuedConnection);
|
|
|
|
eventLoop.exec();
|
|
|
|
QVERIFY(p);
|
|
|
|
QMetaObject::invokeMethod(this,
|
|
|
|
"sendPostedEventsWithDeferredDelete",
|
|
|
|
Qt::QueuedConnection);
|
|
|
|
QMetaObject::invokeMethod(&eventLoop, "quit", Qt::QueuedConnection);
|
|
|
|
eventLoop.exec();
|
|
|
|
QVERIFY(p);
|
|
|
|
|
|
|
|
// trying to delete it from this eventloop still doesn't work
|
|
|
|
QApplication::processEvents();
|
|
|
|
QVERIFY(p);
|
|
|
|
|
|
|
|
// however, it *will* work with this magic incantation
|
2019-05-10 09:08:11 +00:00
|
|
|
QApplication::sendPostedEvents(nullptr, QEvent::DeferredDelete);
|
2011-04-27 10:05:43 +00:00
|
|
|
QVERIFY(!p);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2020-03-31 09:52:19 +00:00
|
|
|
void tst_QApplication::testDeleteLaterProcessEvents1()
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
|
|
|
// Calling processEvents() with no event dispatcher does nothing.
|
|
|
|
QObject *object = new QObject;
|
|
|
|
QPointer<QObject> p(object);
|
|
|
|
object->deleteLater();
|
|
|
|
QApplication::processEvents();
|
|
|
|
QVERIFY(p);
|
|
|
|
delete object;
|
2020-03-31 09:52:19 +00:00
|
|
|
}
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2020-03-31 09:52:19 +00:00
|
|
|
void tst_QApplication::testDeleteLaterProcessEvents2()
|
|
|
|
{
|
|
|
|
int argc = 0;
|
|
|
|
QApplication app(argc, nullptr);
|
|
|
|
// If you call processEvents() with an event dispatcher present, but
|
|
|
|
// outside any event loops, deferred deletes are not processed unless
|
|
|
|
// sendPostedEvents(0, DeferredDelete) is called.
|
|
|
|
auto object = new QObject;
|
|
|
|
QPointer<QObject> p(object);
|
|
|
|
object->deleteLater();
|
|
|
|
QCoreApplication::processEvents();
|
|
|
|
QVERIFY(p);
|
|
|
|
QCoreApplication::sendPostedEvents(nullptr, QEvent::DeferredDelete);
|
|
|
|
QVERIFY(!p);
|
|
|
|
|
|
|
|
// If you call deleteLater() on an object when there is no parent
|
|
|
|
// event loop, and then enter an event loop, the object will get
|
|
|
|
// deleted.
|
2020-03-31 09:56:53 +00:00
|
|
|
QEventLoop loop;
|
2020-03-31 09:52:19 +00:00
|
|
|
object = new QObject;
|
2020-03-31 09:56:53 +00:00
|
|
|
connect(object, &QObject::destroyed, &loop, &QEventLoop::quit);
|
2020-03-31 09:52:19 +00:00
|
|
|
p = object;
|
|
|
|
object->deleteLater();
|
|
|
|
QTimer::singleShot(1000, &loop, &QEventLoop::quit);
|
|
|
|
loop.exec();
|
|
|
|
QVERIFY(!p);
|
|
|
|
}
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2020-03-31 09:52:19 +00:00
|
|
|
void tst_QApplication::testDeleteLaterProcessEvents3()
|
|
|
|
{
|
|
|
|
int argc = 0;
|
|
|
|
// When an object is in an event loop, then calls deleteLater() and enters
|
|
|
|
// an event loop recursively, it should not die until the parent event
|
|
|
|
// loop continues.
|
|
|
|
QApplication app(argc, nullptr);
|
|
|
|
QEventLoop loop;
|
|
|
|
EventLoopNester *nester = new EventLoopNester;
|
|
|
|
QPointer<QObject> p(nester);
|
|
|
|
QTimer::singleShot(3000, &loop, &QEventLoop::quit);
|
|
|
|
QTimer::singleShot(0, nester, &EventLoopNester::deleteLaterAndEnterLoop);
|
|
|
|
|
|
|
|
loop.exec();
|
|
|
|
QVERIFY(!p);
|
|
|
|
}
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2020-03-31 09:52:19 +00:00
|
|
|
void tst_QApplication::testDeleteLaterProcessEvents4()
|
|
|
|
{
|
|
|
|
int argc = 0;
|
|
|
|
// When the event loop that calls deleteLater() is exited
|
|
|
|
// immediately, the object should die when returning to the
|
|
|
|
// parent event loop
|
|
|
|
QApplication app(argc, nullptr);
|
|
|
|
QEventLoop loop;
|
|
|
|
EventLoopNester *nester = new EventLoopNester;
|
|
|
|
QPointer<QObject> p(nester);
|
|
|
|
QTimer::singleShot(3000, &loop, &QEventLoop::quit);
|
|
|
|
QTimer::singleShot(0, nester, &EventLoopNester::deleteLaterAndExitLoop);
|
|
|
|
|
|
|
|
loop.exec();
|
|
|
|
QVERIFY(!p);
|
|
|
|
}
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2020-03-31 09:52:19 +00:00
|
|
|
void tst_QApplication::testDeleteLaterProcessEvents5()
|
|
|
|
{
|
|
|
|
// when the event loop that calls deleteLater() also calls
|
|
|
|
// processEvents() immediately afterwards, the object should
|
|
|
|
// not die until the parent loop continues
|
|
|
|
int argc = 0;
|
|
|
|
QApplication app(argc, nullptr);
|
|
|
|
QEventLoop loop;
|
|
|
|
EventLoopNester *nester = new EventLoopNester();
|
|
|
|
QPointer<QObject> p(nester);
|
|
|
|
QTimer::singleShot(3000, &loop, &QEventLoop::quit);
|
|
|
|
QTimer::singleShot(0, nester, &EventLoopNester::deleteLaterAndProcessEvents);
|
|
|
|
|
|
|
|
loop.exec();
|
|
|
|
QVERIFY(!p);
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2011-07-04 08:37:56 +00:00
|
|
|
Test for crash with QApplication::setDesktopSettingsAware(false).
|
2011-04-27 10:05:43 +00:00
|
|
|
*/
|
|
|
|
void tst_QApplication::desktopSettingsAware()
|
|
|
|
{
|
2016-11-23 11:25:17 +00:00
|
|
|
#if QT_CONFIG(process)
|
2012-02-20 06:01:43 +00:00
|
|
|
QProcess testProcess;
|
tst_qapplication: Prevent desktopaware test from deactivating main test
Applications on macOS are automatically activated (put into the foreground),
when launched from the Finder, or via 'open' on the command line. But when
launched from the terminal, e.g. foo.app/Contents/MacOS/foo, the application
will launch in the background (inactive).
In Qt we override this behavior, activating the app even when launched from
the terminal, as a convenience, as long as the application is a GUI application.
Unfortunately this means that when tst_qapplication launches a subprocess that
is a GUI app, it will steal activation from tst_qapplication, which in turn
will break tests that later try to activate a window and check that the window
is then active. The window will not be active until the application is active.
We can work around it by preventing Qt from activating the application, but
ideally we'd find a better solution to this, as we don't want to sprinkle
overrides all over our tests.
Fixes: QTBUG-90699
Pick-to: 6.1 6.0 5.15
Change-Id: If53a86548002b739df0c0a7153d6244924a4a205
Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
2021-02-12 13:28:18 +00:00
|
|
|
#ifdef Q_OS_MACOS
|
|
|
|
QStringList environment = QProcess::systemEnvironment();
|
|
|
|
environment += QLatin1String("QT_MAC_DISABLE_FOREGROUND_APPLICATION_TRANSFORM=1");
|
|
|
|
testProcess.setEnvironment(environment);
|
|
|
|
#endif
|
2018-06-28 06:43:42 +00:00
|
|
|
testProcess.start("desktopsettingsaware_helper");
|
2011-12-14 08:27:33 +00:00
|
|
|
QVERIFY2(testProcess.waitForStarted(),
|
2018-06-28 06:43:42 +00:00
|
|
|
qPrintable(QString::fromLatin1("Cannot start 'desktopsettingsaware_helper': %1").arg(testProcess.errorString())));
|
2011-04-27 10:05:43 +00:00
|
|
|
QVERIFY(testProcess.waitForFinished(10000));
|
|
|
|
QCOMPARE(int(testProcess.state()), int(QProcess::NotRunning));
|
|
|
|
QVERIFY(int(testProcess.error()) != int(QProcess::Crashed));
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void tst_QApplication::setActiveWindow()
|
|
|
|
{
|
|
|
|
int argc = 0;
|
2019-05-10 09:08:11 +00:00
|
|
|
QApplication MyApp(argc, nullptr);
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
QWidget* w = new QWidget;
|
|
|
|
QVBoxLayout* layout = new QVBoxLayout(w);
|
|
|
|
|
|
|
|
QLineEdit* pb1 = new QLineEdit("Testbutton1", w);
|
|
|
|
QLineEdit* pb2 = new QLineEdit("Test Line Edit", w);
|
|
|
|
|
|
|
|
layout->addWidget(pb1);
|
|
|
|
layout->addWidget(pb2);
|
|
|
|
|
|
|
|
pb2->setFocus();
|
2019-05-10 09:08:11 +00:00
|
|
|
pb2->setParent(nullptr);
|
2011-04-27 10:05:43 +00:00
|
|
|
delete pb2;
|
|
|
|
|
|
|
|
w->show();
|
|
|
|
QApplication::setActiveWindow(w); // needs this on twm (focus follows mouse)
|
|
|
|
QVERIFY(pb1->hasFocus());
|
|
|
|
delete w;
|
|
|
|
}
|
|
|
|
|
2021-01-13 10:41:41 +00:00
|
|
|
void tst_QApplication::focusWidget()
|
|
|
|
{
|
|
|
|
int argc = 0;
|
|
|
|
QApplication app(argc, nullptr);
|
|
|
|
|
|
|
|
// The focus widget is the active window itself
|
|
|
|
{
|
|
|
|
QTextEdit te;
|
|
|
|
te.show();
|
|
|
|
|
|
|
|
QApplication::setActiveWindow(&te);
|
|
|
|
QVERIFY(QTest::qWaitForWindowActive(&te));
|
|
|
|
|
|
|
|
const auto focusWidget = QApplication::focusWidget();
|
|
|
|
QVERIFY(focusWidget);
|
|
|
|
QVERIFY(focusWidget->hasFocus());
|
|
|
|
QVERIFY(te.hasFocus());
|
|
|
|
QCOMPARE(focusWidget, te.focusWidget());
|
|
|
|
}
|
|
|
|
|
|
|
|
// The focus widget is a child of the active window
|
|
|
|
{
|
|
|
|
QWidget w;
|
|
|
|
QTextEdit te(&w);
|
|
|
|
w.show();
|
|
|
|
|
|
|
|
QApplication::setActiveWindow(&w);
|
|
|
|
QVERIFY(QTest::qWaitForWindowActive(&w));
|
|
|
|
|
|
|
|
const auto focusWidget = QApplication::focusWidget();
|
|
|
|
QVERIFY(focusWidget);
|
|
|
|
QVERIFY(focusWidget->hasFocus());
|
|
|
|
QVERIFY(!w.hasFocus());
|
|
|
|
QVERIFY(te.hasFocus());
|
|
|
|
QCOMPARE(te.focusWidget(), w.focusWidget());
|
|
|
|
QCOMPARE(focusWidget, w.focusWidget());
|
|
|
|
}
|
|
|
|
}
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
/* This might fail on some X11 window managers? */
|
|
|
|
void tst_QApplication::focusChanged()
|
|
|
|
{
|
|
|
|
int argc = 0;
|
2019-05-10 09:08:11 +00:00
|
|
|
QApplication app(argc, nullptr);
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2019-05-10 09:08:11 +00:00
|
|
|
QSignalSpy spy(&app, QOverload<QWidget*,QWidget*>::of(&QApplication::focusChanged));
|
|
|
|
QWidget *now = nullptr;
|
|
|
|
QWidget *old = nullptr;
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
QWidget parent1;
|
2019-05-10 09:08:11 +00:00
|
|
|
parent1.setWindowTitle(QLatin1String(QTest::currentTestFunction()) + QLatin1Char('1'));
|
2011-04-27 10:05:43 +00:00
|
|
|
QHBoxLayout hbox1(&parent1);
|
|
|
|
QLabel lb1(&parent1);
|
|
|
|
QLineEdit le1(&parent1);
|
|
|
|
QPushButton pb1(&parent1);
|
|
|
|
hbox1.addWidget(&lb1);
|
|
|
|
hbox1.addWidget(&le1);
|
|
|
|
hbox1.addWidget(&pb1);
|
|
|
|
|
|
|
|
QCOMPARE(spy.count(), 0);
|
|
|
|
|
|
|
|
parent1.show();
|
|
|
|
QApplication::setActiveWindow(&parent1); // needs this on twm (focus follows mouse)
|
|
|
|
QCOMPARE(spy.count(), 1);
|
|
|
|
QCOMPARE(spy.at(0).count(), 2);
|
2012-04-29 07:11:28 +00:00
|
|
|
old = qvariant_cast<QWidget*>(spy.at(0).at(0));
|
|
|
|
now = qvariant_cast<QWidget*>(spy.at(0).at(1));
|
2015-07-30 13:16:36 +00:00
|
|
|
QCOMPARE(now, &le1);
|
|
|
|
QCOMPARE(now, QApplication::focusWidget());
|
|
|
|
QVERIFY(!old);
|
2011-04-27 10:05:43 +00:00
|
|
|
spy.clear();
|
|
|
|
QCOMPARE(spy.count(), 0);
|
|
|
|
|
|
|
|
pb1.setFocus();
|
|
|
|
QCOMPARE(spy.count(), 1);
|
2012-04-29 07:11:28 +00:00
|
|
|
old = qvariant_cast<QWidget*>(spy.at(0).at(0));
|
|
|
|
now = qvariant_cast<QWidget*>(spy.at(0).at(1));
|
2015-07-30 13:16:36 +00:00
|
|
|
QCOMPARE(now, &pb1);
|
|
|
|
QCOMPARE(now, QApplication::focusWidget());
|
|
|
|
QCOMPARE(old, &le1);
|
2011-04-27 10:05:43 +00:00
|
|
|
spy.clear();
|
|
|
|
|
|
|
|
lb1.setFocus();
|
|
|
|
QCOMPARE(spy.count(), 1);
|
2012-04-29 07:11:28 +00:00
|
|
|
old = qvariant_cast<QWidget*>(spy.at(0).at(0));
|
|
|
|
now = qvariant_cast<QWidget*>(spy.at(0).at(1));
|
2015-07-30 13:16:36 +00:00
|
|
|
QCOMPARE(now, &lb1);
|
|
|
|
QCOMPARE(now, QApplication::focusWidget());
|
|
|
|
QCOMPARE(old, &pb1);
|
2011-04-27 10:05:43 +00:00
|
|
|
spy.clear();
|
|
|
|
|
|
|
|
lb1.clearFocus();
|
|
|
|
QCOMPARE(spy.count(), 1);
|
2012-04-29 07:11:28 +00:00
|
|
|
old = qvariant_cast<QWidget*>(spy.at(0).at(0));
|
|
|
|
now = qvariant_cast<QWidget*>(spy.at(0).at(1));
|
2015-07-30 13:16:36 +00:00
|
|
|
QVERIFY(!now);
|
|
|
|
QCOMPARE(now, QApplication::focusWidget());
|
|
|
|
QCOMPARE(old, &lb1);
|
2011-04-27 10:05:43 +00:00
|
|
|
spy.clear();
|
|
|
|
|
|
|
|
QWidget parent2;
|
2019-05-10 09:08:11 +00:00
|
|
|
parent2.setWindowTitle(QLatin1String(QTest::currentTestFunction()) + QLatin1Char('1'));
|
2011-04-27 10:05:43 +00:00
|
|
|
QHBoxLayout hbox2(&parent2);
|
|
|
|
QLabel lb2(&parent2);
|
|
|
|
QLineEdit le2(&parent2);
|
|
|
|
QPushButton pb2(&parent2);
|
|
|
|
hbox2.addWidget(&lb2);
|
|
|
|
hbox2.addWidget(&le2);
|
|
|
|
hbox2.addWidget(&pb2);
|
|
|
|
|
|
|
|
parent2.show();
|
|
|
|
QApplication::setActiveWindow(&parent2); // needs this on twm (focus follows mouse)
|
|
|
|
QVERIFY(spy.count() > 0); // one for deactivation, one for activation on Windows
|
2012-04-29 07:11:28 +00:00
|
|
|
old = qvariant_cast<QWidget*>(spy.at(spy.count()-1).at(0));
|
|
|
|
now = qvariant_cast<QWidget*>(spy.at(spy.count()-1).at(1));
|
2015-07-30 13:16:36 +00:00
|
|
|
QCOMPARE(now, &le2);
|
|
|
|
QCOMPARE(now, QApplication::focusWidget());
|
|
|
|
QVERIFY(!old);
|
2011-04-27 10:05:43 +00:00
|
|
|
spy.clear();
|
|
|
|
|
2019-05-10 09:08:11 +00:00
|
|
|
QTestKeyEvent tab(QTest::Press, Qt::Key_Tab, Qt::KeyboardModifiers(), 0);
|
|
|
|
QTestKeyEvent backtab(QTest::Press, Qt::Key_Backtab, Qt::KeyboardModifiers(), 0);
|
|
|
|
QTestMouseEvent click(QTest::MouseClick, Qt::LeftButton, Qt::KeyboardModifiers(), QPoint(5, 5), 0);
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
bool tabAllControls = true;
|
2012-01-16 10:49:53 +00:00
|
|
|
#ifdef Q_OS_MAC
|
2011-04-27 10:05:43 +00:00
|
|
|
// Mac has two modes, one where you tab to everything, one where you can
|
|
|
|
// only tab to input controls, here's what we get. Determine which ones we
|
|
|
|
// should get.
|
|
|
|
QSettings appleSettings(QLatin1String("apple.com"));
|
|
|
|
QVariant appleValue = appleSettings.value(QLatin1String("AppleKeyboardUIMode"), 0);
|
|
|
|
tabAllControls = (appleValue.toInt() & 0x2);
|
|
|
|
#endif
|
|
|
|
|
2012-02-20 05:12:50 +00:00
|
|
|
// make sure Qt's idea of tabbing between widgets matches what we think it should
|
2012-10-09 09:27:01 +00:00
|
|
|
QCOMPARE(qt_tab_all_widgets(), tabAllControls);
|
2012-02-20 05:12:50 +00:00
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
tab.simulate(now);
|
|
|
|
if (!tabAllControls) {
|
2015-07-30 13:16:36 +00:00
|
|
|
QCOMPARE(spy.count(), 0);
|
|
|
|
QCOMPARE(now, QApplication::focusWidget());
|
2011-04-27 10:05:43 +00:00
|
|
|
} else {
|
|
|
|
QVERIFY(spy.count() > 0);
|
2012-04-29 07:11:28 +00:00
|
|
|
old = qvariant_cast<QWidget*>(spy.at(0).at(0));
|
|
|
|
now = qvariant_cast<QWidget*>(spy.at(0).at(1));
|
2015-07-30 13:16:36 +00:00
|
|
|
QCOMPARE(now, &pb2);
|
|
|
|
QCOMPARE(now, QApplication::focusWidget());
|
|
|
|
QCOMPARE(old, &le2);
|
2011-04-27 10:05:43 +00:00
|
|
|
spy.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!tabAllControls) {
|
2015-07-30 13:16:36 +00:00
|
|
|
QCOMPARE(spy.count(), 0);
|
|
|
|
QCOMPARE(now, QApplication::focusWidget());
|
2011-04-27 10:05:43 +00:00
|
|
|
} else {
|
|
|
|
tab.simulate(now);
|
|
|
|
QVERIFY(spy.count() > 0);
|
2012-04-29 07:11:28 +00:00
|
|
|
old = qvariant_cast<QWidget*>(spy.at(0).at(0));
|
|
|
|
now = qvariant_cast<QWidget*>(spy.at(0).at(1));
|
2015-07-30 13:16:36 +00:00
|
|
|
QCOMPARE(now, &le2);
|
|
|
|
QCOMPARE(now, QApplication::focusWidget());
|
|
|
|
QCOMPARE(old, &pb2);
|
2011-04-27 10:05:43 +00:00
|
|
|
spy.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!tabAllControls) {
|
2015-07-30 13:16:36 +00:00
|
|
|
QCOMPARE(spy.count(), 0);
|
|
|
|
QCOMPARE(now, QApplication::focusWidget());
|
2011-04-27 10:05:43 +00:00
|
|
|
} else {
|
|
|
|
backtab.simulate(now);
|
|
|
|
QVERIFY(spy.count() > 0);
|
2012-04-29 07:11:28 +00:00
|
|
|
old = qvariant_cast<QWidget*>(spy.at(0).at(0));
|
|
|
|
now = qvariant_cast<QWidget*>(spy.at(0).at(1));
|
2015-07-30 13:16:36 +00:00
|
|
|
QCOMPARE(now, &pb2);
|
|
|
|
QCOMPARE(now, QApplication::focusWidget());
|
|
|
|
QCOMPARE(old, &le2);
|
2011-04-27 10:05:43 +00:00
|
|
|
spy.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!tabAllControls) {
|
2015-07-30 13:16:36 +00:00
|
|
|
QCOMPARE(spy.count(), 0);
|
|
|
|
QCOMPARE(now, QApplication::focusWidget());
|
2011-04-27 10:05:43 +00:00
|
|
|
old = &pb2;
|
|
|
|
} else {
|
|
|
|
backtab.simulate(now);
|
|
|
|
QVERIFY(spy.count() > 0);
|
2012-04-29 07:11:28 +00:00
|
|
|
old = qvariant_cast<QWidget*>(spy.at(0).at(0));
|
|
|
|
now = qvariant_cast<QWidget*>(spy.at(0).at(1));
|
2015-07-30 13:16:36 +00:00
|
|
|
QCOMPARE(now, &le2);
|
|
|
|
QCOMPARE(now, QApplication::focusWidget());
|
|
|
|
QCOMPARE(old, &pb2);
|
2011-04-27 10:05:43 +00:00
|
|
|
spy.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
click.simulate(old);
|
|
|
|
if (!(pb2.focusPolicy() & Qt::ClickFocus)) {
|
2015-07-30 13:16:36 +00:00
|
|
|
QCOMPARE(spy.count(), 0);
|
|
|
|
QCOMPARE(now, QApplication::focusWidget());
|
2011-04-27 10:05:43 +00:00
|
|
|
} else {
|
|
|
|
QVERIFY(spy.count() > 0);
|
2012-04-29 07:11:28 +00:00
|
|
|
old = qvariant_cast<QWidget*>(spy.at(0).at(0));
|
|
|
|
now = qvariant_cast<QWidget*>(spy.at(0).at(1));
|
2015-07-30 13:16:36 +00:00
|
|
|
QCOMPARE(now, &pb2);
|
|
|
|
QCOMPARE(now, QApplication::focusWidget());
|
|
|
|
QCOMPARE(old, &le2);
|
2011-04-27 10:05:43 +00:00
|
|
|
spy.clear();
|
|
|
|
|
|
|
|
click.simulate(old);
|
|
|
|
QVERIFY(spy.count() > 0);
|
2012-04-29 07:11:28 +00:00
|
|
|
old = qvariant_cast<QWidget*>(spy.at(0).at(0));
|
|
|
|
now = qvariant_cast<QWidget*>(spy.at(0).at(1));
|
2015-07-30 13:16:36 +00:00
|
|
|
QCOMPARE(now, &le2);
|
|
|
|
QCOMPARE(now, QApplication::focusWidget());
|
|
|
|
QCOMPARE(old, &pb2);
|
2011-04-27 10:05:43 +00:00
|
|
|
spy.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
parent1.activateWindow();
|
|
|
|
QApplication::setActiveWindow(&parent1); // needs this on twm (focus follows mouse)
|
|
|
|
QVERIFY(spy.count() == 1 || spy.count() == 2); // one for deactivation, one for activation on Windows
|
|
|
|
|
|
|
|
//on windows, the change of focus is made in 2 steps
|
|
|
|
//(the focusChanged SIGNAL is emitted twice)
|
|
|
|
if (spy.count()==1)
|
2012-04-29 07:11:28 +00:00
|
|
|
old = qvariant_cast<QWidget*>(spy.at(spy.count()-1).at(0));
|
2011-04-27 10:05:43 +00:00
|
|
|
else
|
2012-04-29 07:11:28 +00:00
|
|
|
old = qvariant_cast<QWidget*>(spy.at(spy.count()-2).at(0));
|
|
|
|
now = qvariant_cast<QWidget*>(spy.at(spy.count()-1).at(1));
|
2015-07-30 13:16:36 +00:00
|
|
|
QCOMPARE(now, &le1);
|
|
|
|
QCOMPARE(now, QApplication::focusWidget());
|
|
|
|
QCOMPARE(old, &le2);
|
2011-04-27 10:05:43 +00:00
|
|
|
spy.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
class LineEdit : public QLineEdit
|
|
|
|
{
|
|
|
|
public:
|
2019-05-10 09:08:11 +00:00
|
|
|
using QLineEdit::QLineEdit;
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
protected:
|
2019-05-10 09:08:11 +00:00
|
|
|
void focusOutEvent(QFocusEvent *e) override
|
|
|
|
{
|
2011-04-27 10:05:43 +00:00
|
|
|
QLineEdit::focusOutEvent(e);
|
|
|
|
if (objectName() == "le1")
|
|
|
|
setStyleSheet("");
|
|
|
|
}
|
|
|
|
|
2019-05-10 09:08:11 +00:00
|
|
|
void focusInEvent(QFocusEvent *e) override
|
|
|
|
{
|
2011-04-27 10:05:43 +00:00
|
|
|
QLineEdit::focusInEvent(e);
|
|
|
|
if (objectName() == "le2")
|
|
|
|
setStyleSheet("");
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
void tst_QApplication::focusOut()
|
|
|
|
{
|
|
|
|
int argc = 1;
|
2012-11-23 14:02:46 +00:00
|
|
|
QApplication app(argc, &argv0);
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
// Tests the case where the style pointer changes when on focus in/out
|
|
|
|
// (the above is the case when the stylesheet changes)
|
|
|
|
QWidget w;
|
2019-05-10 09:08:11 +00:00
|
|
|
w.setWindowTitle(QLatin1String(QTest::currentTestFunction()));
|
2011-04-27 10:05:43 +00:00
|
|
|
QLineEdit *le1 = new LineEdit(&w);
|
|
|
|
le1->setObjectName("le1");
|
|
|
|
le1->setStyleSheet("background: #fee");
|
|
|
|
le1->setFocus();
|
|
|
|
|
|
|
|
QLineEdit *le2 = new LineEdit(&w);
|
|
|
|
le2->setObjectName("le2");
|
|
|
|
le2->setStyleSheet("background: #fee");
|
|
|
|
le2->move(100, 100);
|
|
|
|
w.show();
|
2018-04-04 09:57:51 +00:00
|
|
|
QVERIFY(QTest::qWaitForWindowExposed(&w));
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
QTest::qWait(2000);
|
|
|
|
le2->setFocus();
|
|
|
|
QTest::qWait(2000);
|
|
|
|
}
|
|
|
|
|
2013-11-16 16:17:15 +00:00
|
|
|
void tst_QApplication::focusMouseClick()
|
|
|
|
{
|
|
|
|
int argc = 1;
|
|
|
|
QApplication app(argc, &argv0);
|
|
|
|
|
2019-10-11 13:21:54 +00:00
|
|
|
if (!QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::WindowActivation))
|
|
|
|
QSKIP("Window activation is not supported");
|
|
|
|
|
2013-11-16 16:17:15 +00:00
|
|
|
QWidget w;
|
2019-05-10 09:08:11 +00:00
|
|
|
w.setWindowTitle(QLatin1String(QTest::currentTestFunction()));
|
2013-11-16 16:17:15 +00:00
|
|
|
w.setFocusPolicy(Qt::StrongFocus);
|
|
|
|
QWidget w2(&w);
|
|
|
|
w2.setFocusPolicy(Qt::TabFocus);
|
|
|
|
w.show();
|
|
|
|
w.setFocus();
|
|
|
|
QTRY_COMPARE(QApplication::focusWidget(), &w);
|
|
|
|
|
|
|
|
// front most widget has Qt::TabFocus, parent widget accepts clicks as well
|
|
|
|
// now send a mouse button press event and check what happens with the focus
|
|
|
|
// it should be given to the parent widget
|
|
|
|
QMouseEvent ev(QEvent::MouseButtonPress, QPointF(), Qt::LeftButton, Qt::LeftButton, Qt::NoModifier);
|
2016-09-27 11:59:37 +00:00
|
|
|
QSpontaneKeyEvent::setSpontaneous(&ev);
|
2013-11-16 16:17:15 +00:00
|
|
|
QVERIFY(ev.spontaneous());
|
|
|
|
qApp->notify(&w2, &ev);
|
|
|
|
QCOMPARE(QApplication::focusWidget(), &w);
|
|
|
|
|
|
|
|
// then we give the inner widget strong focus -> it should get focus
|
|
|
|
w2.setFocusPolicy(Qt::StrongFocus);
|
2016-09-27 11:59:37 +00:00
|
|
|
QSpontaneKeyEvent::setSpontaneous(&ev);
|
2013-11-16 16:17:15 +00:00
|
|
|
QVERIFY(ev.spontaneous());
|
|
|
|
qApp->notify(&w2, &ev);
|
|
|
|
QTRY_COMPARE(QApplication::focusWidget(), &w2);
|
|
|
|
|
|
|
|
// now back to tab focus and click again (it already had focus) -> focus should stay
|
|
|
|
// (focus was revoked as of QTBUG-34042)
|
|
|
|
w2.setFocusPolicy(Qt::TabFocus);
|
2016-09-27 11:59:37 +00:00
|
|
|
QSpontaneKeyEvent::setSpontaneous(&ev);
|
2013-11-16 16:17:15 +00:00
|
|
|
QVERIFY(ev.spontaneous());
|
|
|
|
qApp->notify(&w2, &ev);
|
|
|
|
QCOMPARE(QApplication::focusWidget(), &w2);
|
|
|
|
}
|
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
void tst_QApplication::execAfterExit()
|
|
|
|
{
|
|
|
|
int argc = 1;
|
2012-11-23 14:02:46 +00:00
|
|
|
QApplication app(argc, &argv0);
|
2011-04-27 10:05:43 +00:00
|
|
|
QMetaObject::invokeMethod(&app, "quit", Qt::QueuedConnection);
|
|
|
|
// this should be ignored, as exec() will reset the exitCode
|
|
|
|
QApplication::exit(1);
|
2019-05-10 09:08:11 +00:00
|
|
|
int exitCode = QCoreApplication::exec();
|
2011-04-27 10:05:43 +00:00
|
|
|
QCOMPARE(exitCode, 0);
|
|
|
|
|
|
|
|
// the quitNow flag should have been reset, so we can spin an
|
|
|
|
// eventloop after QApplication::exec() returns
|
|
|
|
QEventLoop eventLoop;
|
|
|
|
QMetaObject::invokeMethod(&eventLoop, "quit", Qt::QueuedConnection);
|
|
|
|
exitCode = eventLoop.exec();
|
|
|
|
QCOMPARE(exitCode, 0);
|
|
|
|
}
|
|
|
|
|
2017-05-30 20:22:22 +00:00
|
|
|
#if QT_CONFIG(wheelevent)
|
2011-04-27 10:05:43 +00:00
|
|
|
void tst_QApplication::wheelScrollLines()
|
|
|
|
{
|
|
|
|
int argc = 1;
|
2012-11-23 14:02:46 +00:00
|
|
|
QApplication app(argc, &argv0);
|
2011-04-27 10:05:43 +00:00
|
|
|
// If wheelScrollLines returns 0, the mose wheel will be disabled.
|
|
|
|
QVERIFY(app.wheelScrollLines() > 0);
|
|
|
|
}
|
2017-05-30 20:22:22 +00:00
|
|
|
#endif // QT_CONFIG(wheelevent)
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
void tst_QApplication::style()
|
|
|
|
{
|
|
|
|
int argc = 1;
|
|
|
|
|
|
|
|
{
|
2012-11-23 14:02:46 +00:00
|
|
|
QApplication app(argc, &argv0);
|
2019-05-10 09:08:11 +00:00
|
|
|
QPointer<QStyle> style = QApplication::style();
|
|
|
|
QApplication::setStyle(QStyleFactory::create(QLatin1String("Windows")));
|
2011-04-27 10:05:43 +00:00
|
|
|
QVERIFY(style.isNull());
|
|
|
|
}
|
|
|
|
|
2012-11-23 14:02:46 +00:00
|
|
|
QApplication app(argc, &argv0);
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
// qApp style can never be 0
|
2019-05-10 09:08:11 +00:00
|
|
|
QVERIFY(QApplication::style() != nullptr);
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
2020-07-13 12:45:41 +00:00
|
|
|
class CustomStyle : public QProxyStyle
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CustomStyle() : QProxyStyle("Windows") { Q_ASSERT(!polished); }
|
|
|
|
~CustomStyle() { polished = 0; }
|
2020-09-10 18:39:49 +00:00
|
|
|
void polish(QPalette &palette) override
|
2020-07-13 12:45:41 +00:00
|
|
|
{
|
|
|
|
polished++;
|
|
|
|
palette.setColor(QPalette::Active, QPalette::Link, Qt::red);
|
|
|
|
}
|
|
|
|
static int polished;
|
|
|
|
};
|
|
|
|
|
|
|
|
int CustomStyle::polished = 0;
|
|
|
|
|
|
|
|
class CustomStylePlugin : public QStylePlugin
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QStyleFactoryInterface" FILE "customstyle.json")
|
|
|
|
public:
|
2020-09-10 18:39:49 +00:00
|
|
|
QStyle *create(const QString &) override { return new CustomStyle; }
|
2020-07-13 12:45:41 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
Q_IMPORT_PLUGIN(CustomStylePlugin)
|
|
|
|
|
|
|
|
void tst_QApplication::applicationPalettePolish()
|
|
|
|
{
|
|
|
|
int argc = 1;
|
|
|
|
|
|
|
|
#if defined(QT_BUILD_INTERNAL)
|
|
|
|
{
|
|
|
|
qputenv("QT_DESKTOP_STYLE_KEY", "customstyle");
|
|
|
|
QApplication app(argc, &argv0);
|
|
|
|
QVERIFY(CustomStyle::polished);
|
2020-08-19 09:52:07 +00:00
|
|
|
QVERIFY(!app.palette().resolveMask());
|
2020-07-13 12:45:41 +00:00
|
|
|
QCOMPARE(app.palette().color(QPalette::Link), Qt::red);
|
|
|
|
qunsetenv("QT_DESKTOP_STYLE_KEY");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
{
|
|
|
|
QApplication::setStyle(new CustomStyle);
|
|
|
|
QApplication app(argc, &argv0);
|
|
|
|
QVERIFY(CustomStyle::polished);
|
2020-08-19 09:52:07 +00:00
|
|
|
QVERIFY(!app.palette().resolveMask());
|
2020-07-13 12:45:41 +00:00
|
|
|
QCOMPARE(app.palette().color(QPalette::Link), Qt::red);
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
QApplication app(argc, &argv0);
|
|
|
|
app.setStyle(new CustomStyle);
|
|
|
|
QVERIFY(CustomStyle::polished);
|
2020-08-19 09:52:07 +00:00
|
|
|
QVERIFY(!app.palette().resolveMask());
|
2020-07-13 12:45:41 +00:00
|
|
|
QCOMPARE(app.palette().color(QPalette::Link), Qt::red);
|
|
|
|
|
|
|
|
CustomStyle::polished = 0;
|
|
|
|
app.setPalette(QPalette());
|
|
|
|
QVERIFY(CustomStyle::polished);
|
2020-08-19 09:52:07 +00:00
|
|
|
QVERIFY(!app.palette().resolveMask());
|
2020-07-13 12:45:41 +00:00
|
|
|
QCOMPARE(app.palette().color(QPalette::Link), Qt::red);
|
|
|
|
|
|
|
|
CustomStyle::polished = 0;
|
|
|
|
QPalette palette;
|
|
|
|
palette.setColor(QPalette::Active, QPalette::Highlight, Qt::green);
|
|
|
|
app.setPalette(palette);
|
|
|
|
QVERIFY(CustomStyle::polished);
|
2020-08-19 09:52:07 +00:00
|
|
|
QVERIFY(app.palette().resolveMask());
|
2020-07-13 12:45:41 +00:00
|
|
|
QCOMPARE(app.palette().color(QPalette::Link), Qt::red);
|
|
|
|
QCOMPARE(app.palette().color(QPalette::Highlight), Qt::green);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
void tst_QApplication::allWidgets()
|
|
|
|
{
|
|
|
|
int argc = 1;
|
2012-11-23 14:02:46 +00:00
|
|
|
QApplication app(argc, &argv0);
|
2011-04-27 10:05:43 +00:00
|
|
|
QWidget *w = new QWidget;
|
2019-05-10 09:08:11 +00:00
|
|
|
QVERIFY(QApplication::allWidgets().contains(w)); // uncreate widget test
|
2011-04-27 10:05:43 +00:00
|
|
|
delete w;
|
2019-05-10 09:08:11 +00:00
|
|
|
QVERIFY(!QApplication::allWidgets().contains(w)); // removal test
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void tst_QApplication::topLevelWidgets()
|
|
|
|
{
|
|
|
|
int argc = 1;
|
2012-11-23 14:02:46 +00:00
|
|
|
QApplication app(argc, &argv0);
|
2011-04-27 10:05:43 +00:00
|
|
|
QWidget *w = new QWidget;
|
|
|
|
w->show();
|
|
|
|
#ifndef QT_NO_CLIPBOARD
|
2019-05-10 09:08:11 +00:00
|
|
|
QClipboard *clipboard = QGuiApplication::clipboard();
|
|
|
|
clipboard->setText(QLatin1String("newText"));
|
2011-04-27 10:05:43 +00:00
|
|
|
#endif
|
2019-05-10 09:08:11 +00:00
|
|
|
QCoreApplication::processEvents();
|
2011-04-27 10:05:43 +00:00
|
|
|
QVERIFY(QApplication::topLevelWidgets().contains(w));
|
|
|
|
QCOMPARE(QApplication::topLevelWidgets().count(), 1);
|
|
|
|
delete w;
|
2019-05-10 09:08:11 +00:00
|
|
|
w = nullptr;
|
|
|
|
QCoreApplication::processEvents();
|
2011-04-27 10:05:43 +00:00
|
|
|
QCOMPARE(QApplication::topLevelWidgets().count(), 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void tst_QApplication::setAttribute()
|
|
|
|
{
|
|
|
|
int argc = 1;
|
2012-11-23 14:02:46 +00:00
|
|
|
QApplication app(argc, &argv0);
|
2020-04-17 14:48:51 +00:00
|
|
|
QVERIFY(!QApplication::testAttribute(Qt::AA_NativeWindows));
|
2011-04-27 10:05:43 +00:00
|
|
|
QWidget *w = new QWidget;
|
2020-04-17 14:48:51 +00:00
|
|
|
w->show(); // trigger creation;
|
|
|
|
QVERIFY(!w->testAttribute(Qt::WA_NativeWindow));
|
2011-04-27 10:05:43 +00:00
|
|
|
delete w;
|
|
|
|
|
2020-04-17 14:48:51 +00:00
|
|
|
QApplication::setAttribute(Qt::AA_NativeWindows);
|
|
|
|
QVERIFY(QApplication::testAttribute(Qt::AA_NativeWindows));
|
2011-04-27 10:05:43 +00:00
|
|
|
w = new QWidget;
|
2020-04-17 14:48:51 +00:00
|
|
|
w->show(); // trigger creation
|
|
|
|
QVERIFY(w->testAttribute(Qt::WA_NativeWindow));
|
2011-04-27 10:05:43 +00:00
|
|
|
delete w;
|
|
|
|
|
2020-04-17 14:48:51 +00:00
|
|
|
QApplication::setAttribute(Qt::AA_NativeWindows, false);
|
|
|
|
QVERIFY(!QApplication::testAttribute(Qt::AA_NativeWindows));
|
2011-04-27 10:05:43 +00:00
|
|
|
w = new QWidget;
|
2020-04-17 14:48:51 +00:00
|
|
|
w->show(); // trigger creation;
|
|
|
|
QVERIFY(!w->testAttribute(Qt::WA_NativeWindow));
|
2011-04-27 10:05:43 +00:00
|
|
|
delete w;
|
|
|
|
}
|
|
|
|
|
|
|
|
class TouchEventPropagationTestWidget : public QWidget
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
2019-05-10 09:08:11 +00:00
|
|
|
bool seenTouchEvent = false, acceptTouchEvent = false, seenMouseEvent = false, acceptMouseEvent = false;
|
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2019-05-10 09:08:11 +00:00
|
|
|
explicit TouchEventPropagationTestWidget(QWidget *parent = nullptr) : QWidget(parent)
|
2014-03-12 12:47:26 +00:00
|
|
|
{
|
|
|
|
setAttribute(Qt::WA_TouchPadAcceptSingleTouchEvents);
|
|
|
|
}
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
void reset()
|
|
|
|
{
|
|
|
|
seenTouchEvent = acceptTouchEvent = seenMouseEvent = acceptMouseEvent = false;
|
|
|
|
}
|
|
|
|
|
2019-05-10 09:08:11 +00:00
|
|
|
bool event(QEvent *event) override
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
|
|
|
switch (event->type()) {
|
|
|
|
case QEvent::MouseButtonPress:
|
|
|
|
case QEvent::MouseMove:
|
|
|
|
case QEvent::MouseButtonRelease:
|
|
|
|
// qDebug() << objectName() << "seenMouseEvent = true";
|
|
|
|
seenMouseEvent = true;
|
|
|
|
event->setAccepted(acceptMouseEvent);
|
|
|
|
break;
|
|
|
|
case QEvent::TouchBegin:
|
|
|
|
case QEvent::TouchUpdate:
|
|
|
|
case QEvent::TouchEnd:
|
|
|
|
// qDebug() << objectName() << "seenTouchEvent = true";
|
|
|
|
seenTouchEvent = true;
|
|
|
|
event->setAccepted(acceptTouchEvent);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return QWidget::event(event);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
void tst_QApplication::touchEventPropagation()
|
|
|
|
{
|
|
|
|
int argc = 1;
|
2012-11-23 14:02:46 +00:00
|
|
|
QApplication app(argc, &argv0);
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
|
Introduce QInputDevice hierarchy; replace QTouchDevice
We have seen during the Qt 5 series that QMouseEvent::source() does
not provide enough information: if it is synthesized, it could have
come from any device for which mouse events are synthesized, not only
from a touchscreen. By providing in every QInputEvent as complete
information about the actual source device as possible, we will enable
very fine-tuned behavior in the object that handles each event.
Further, we would like to support multiple keyboards, pointing devices,
and named groups of devices that are known as "seats" in Wayland.
In Qt 5, QPA plugins registered each touchscreen as it was discovered.
Now we extend this pattern to all input devices. This new requirement
can be implemented gradually; for now, if a QTWSI input event is
received wtihout a device pointer, a default "core" device will be
created on-the-fly, and a warning emitted.
In Qt 5, QTouchEvent::TouchPoint::id() was forced to be unique even when
multiple devices were in use simultaneously. Now that each event
identifies the device it came from, this hack is no longer needed.
A stub of the new QPointerEvent is added; it will be developed further
in subsequent patches.
[ChangeLog][QtGui][QInputEvent] Every QInputEvent now carries a pointer
to an instance of QInputDevice, or the subclass QPointingDevice in case
of mouse, touch and tablet events. Each platform plugin is expected to
create the device instances, register them, and provide valid pointers
with all input events. If this is not done, warnings are emitted and
default devices are created as necessary. When the device has accurate
information, it provides the opportunity to fine-tune behavior depending
on device type and capabilities: for example if a QMouseEvent is
synthesized from a touchscreen, the recipient can see which touchscreen
it came from. Each device also has a seatName to distinguish users on
multi-user windowing systems. Touchpoint IDs are no longer unique on
their own, but the combination of ID and device is.
Fixes: QTBUG-46412
Fixes: QTBUG-72167
Task-number: QTBUG-69433
Task-number: QTBUG-52430
Change-Id: I933fb2b86182efa722037b7a33e404c5daf5292a
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
2019-05-31 06:38:16 +00:00
|
|
|
QPointingDevice *device = QTest::createTouchDevice();
|
2011-11-27 15:42:23 +00:00
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
|
|
|
// touch event behavior on a window
|
|
|
|
TouchEventPropagationTestWidget window;
|
2019-05-10 09:08:11 +00:00
|
|
|
window.setWindowTitle(QLatin1String(QTest::currentTestFunction()));
|
2012-12-28 16:35:54 +00:00
|
|
|
window.resize(200, 200);
|
2011-04-27 10:05:43 +00:00
|
|
|
window.setObjectName("1. window");
|
2011-12-10 14:30:18 +00:00
|
|
|
window.show(); // Must have an explicitly specified QWindow for handleTouchEvent,
|
|
|
|
// passing 0 would result in using topLevelAt() which is not ok in this case
|
|
|
|
// as the screen position in the point is bogus.
|
2019-05-10 09:08:11 +00:00
|
|
|
auto handle = window.windowHandle();
|
2012-07-30 10:36:02 +00:00
|
|
|
QVERIFY(QTest::qWaitForWindowExposed(&window));
|
2011-12-10 14:30:18 +00:00
|
|
|
// QPA always takes screen positions and since we map the TouchPoint back to QPA's structure first,
|
|
|
|
// we must ensure there is a screen position in the TouchPoint that maps to a local 0, 0.
|
2015-06-18 15:01:01 +00:00
|
|
|
const QPoint deviceGlobalPos =
|
|
|
|
QHighDpi::toNativePixels(window.mapToGlobal(QPoint(0, 0)), window.windowHandle()->screen());
|
2020-03-27 16:06:11 +00:00
|
|
|
auto pressedTouchPoints = QList<QEventPoint>() <<
|
|
|
|
QEventPoint(0, QEventPoint::State::Pressed, QPointF(), deviceGlobalPos);
|
|
|
|
auto releasedTouchPoints = QList<QEventPoint>() <<
|
|
|
|
QEventPoint(0, QEventPoint::State::Released, QPointF(), deviceGlobalPos);
|
2011-12-10 14:30:18 +00:00
|
|
|
|
2019-05-10 09:08:11 +00:00
|
|
|
QWindowSystemInterface::handleTouchEvent(handle,
|
2011-12-10 14:30:18 +00:00
|
|
|
0,
|
|
|
|
device,
|
2019-05-10 09:08:11 +00:00
|
|
|
QWindowSystemInterfacePrivate::toNativeTouchPoints(pressedTouchPoints, handle));
|
|
|
|
QWindowSystemInterface::handleTouchEvent(handle,
|
2011-12-10 14:30:18 +00:00
|
|
|
0,
|
|
|
|
device,
|
2019-05-10 09:08:11 +00:00
|
|
|
QWindowSystemInterfacePrivate::toNativeTouchPoints(releasedTouchPoints, handle));
|
2011-12-10 14:30:18 +00:00
|
|
|
QCoreApplication::processEvents();
|
2011-04-27 10:05:43 +00:00
|
|
|
QVERIFY(!window.seenTouchEvent);
|
2014-12-09 15:52:24 +00:00
|
|
|
QVERIFY(window.seenMouseEvent); // QApplication may transform ignored touch events in mouse events
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
window.reset();
|
|
|
|
window.setAttribute(Qt::WA_AcceptTouchEvents);
|
2019-05-10 09:08:11 +00:00
|
|
|
QWindowSystemInterface::handleTouchEvent(handle,
|
2011-12-10 14:30:18 +00:00
|
|
|
0,
|
|
|
|
device,
|
2019-05-10 09:08:11 +00:00
|
|
|
QWindowSystemInterfacePrivate::toNativeTouchPoints(pressedTouchPoints, handle));
|
|
|
|
QWindowSystemInterface::handleTouchEvent(handle,
|
2011-12-10 14:30:18 +00:00
|
|
|
0,
|
|
|
|
device,
|
2019-05-10 09:08:11 +00:00
|
|
|
QWindowSystemInterfacePrivate::toNativeTouchPoints(releasedTouchPoints, handle));
|
2011-12-10 14:30:18 +00:00
|
|
|
QCoreApplication::processEvents();
|
2011-04-27 10:05:43 +00:00
|
|
|
QVERIFY(window.seenTouchEvent);
|
2014-12-09 15:52:24 +00:00
|
|
|
QVERIFY(window.seenMouseEvent);
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
window.reset();
|
|
|
|
window.acceptTouchEvent = true;
|
2019-05-10 09:08:11 +00:00
|
|
|
QWindowSystemInterface::handleTouchEvent(handle,
|
2011-12-10 14:30:18 +00:00
|
|
|
0,
|
|
|
|
device,
|
2019-05-10 09:08:11 +00:00
|
|
|
QWindowSystemInterfacePrivate::toNativeTouchPoints(pressedTouchPoints, handle));
|
|
|
|
QWindowSystemInterface::handleTouchEvent(handle,
|
2011-12-10 14:30:18 +00:00
|
|
|
0,
|
|
|
|
device,
|
2019-05-10 09:08:11 +00:00
|
|
|
QWindowSystemInterfacePrivate::toNativeTouchPoints(releasedTouchPoints, handle));
|
2011-12-10 14:30:18 +00:00
|
|
|
QCoreApplication::processEvents();
|
2011-04-27 10:05:43 +00:00
|
|
|
QVERIFY(window.seenTouchEvent);
|
|
|
|
QVERIFY(!window.seenMouseEvent);
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
// touch event behavior on a window with a child widget
|
|
|
|
TouchEventPropagationTestWidget window;
|
2019-05-10 09:08:11 +00:00
|
|
|
window.setWindowTitle(QLatin1String(QTest::currentTestFunction()));
|
2012-12-28 16:35:54 +00:00
|
|
|
window.resize(200, 200);
|
2011-04-27 10:05:43 +00:00
|
|
|
window.setObjectName("2. window");
|
|
|
|
TouchEventPropagationTestWidget widget(&window);
|
2015-07-10 13:27:27 +00:00
|
|
|
widget.resize(200, 200);
|
2011-04-27 10:05:43 +00:00
|
|
|
widget.setObjectName("2. widget");
|
2011-12-10 14:30:18 +00:00
|
|
|
window.show();
|
2019-05-10 09:08:11 +00:00
|
|
|
auto handle = window.windowHandle();
|
2012-07-30 10:36:02 +00:00
|
|
|
QVERIFY(QTest::qWaitForWindowExposed(&window));
|
2015-06-18 15:01:01 +00:00
|
|
|
const QPoint deviceGlobalPos =
|
2017-05-08 17:13:08 +00:00
|
|
|
QHighDpi::toNativePixels(window.mapToGlobal(QPoint(50, 150)), window.windowHandle()->screen());
|
2020-03-27 16:06:11 +00:00
|
|
|
auto pressedTouchPoints = QList<QEventPoint>() <<
|
|
|
|
QEventPoint(0, QEventPoint::State::Pressed, QPointF(), deviceGlobalPos);
|
|
|
|
auto releasedTouchPoints = QList<QEventPoint>() <<
|
|
|
|
QEventPoint(0, QEventPoint::State::Released, QPointF(), deviceGlobalPos);
|
2011-12-10 14:30:18 +00:00
|
|
|
|
2019-05-10 09:08:11 +00:00
|
|
|
QWindowSystemInterface::handleTouchEvent(handle,
|
2011-12-10 14:30:18 +00:00
|
|
|
0,
|
|
|
|
device,
|
2019-05-10 09:08:11 +00:00
|
|
|
QWindowSystemInterfacePrivate::toNativeTouchPoints(pressedTouchPoints, handle));
|
|
|
|
QWindowSystemInterface::handleTouchEvent(handle,
|
2011-12-10 14:30:18 +00:00
|
|
|
0,
|
|
|
|
device,
|
2019-05-10 09:08:11 +00:00
|
|
|
QWindowSystemInterfacePrivate::toNativeTouchPoints(releasedTouchPoints, handle));
|
2015-07-10 13:27:27 +00:00
|
|
|
QTRY_VERIFY(widget.seenMouseEvent);
|
2011-04-27 10:05:43 +00:00
|
|
|
QVERIFY(!widget.seenTouchEvent);
|
|
|
|
QVERIFY(!window.seenTouchEvent);
|
2014-12-09 15:52:24 +00:00
|
|
|
QVERIFY(window.seenMouseEvent);
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
window.reset();
|
|
|
|
widget.reset();
|
|
|
|
widget.setAttribute(Qt::WA_AcceptTouchEvents);
|
2019-05-10 09:08:11 +00:00
|
|
|
QWindowSystemInterface::handleTouchEvent(handle,
|
2011-12-10 14:30:18 +00:00
|
|
|
0,
|
|
|
|
device,
|
2019-05-10 09:08:11 +00:00
|
|
|
QWindowSystemInterfacePrivate::toNativeTouchPoints(pressedTouchPoints, handle));
|
|
|
|
QWindowSystemInterface::handleTouchEvent(handle,
|
2011-12-10 14:30:18 +00:00
|
|
|
0,
|
|
|
|
device,
|
2019-05-10 09:08:11 +00:00
|
|
|
QWindowSystemInterfacePrivate::toNativeTouchPoints(releasedTouchPoints, handle));
|
2011-12-10 14:30:18 +00:00
|
|
|
QCoreApplication::processEvents();
|
2011-04-27 10:05:43 +00:00
|
|
|
QVERIFY(widget.seenTouchEvent);
|
2014-12-09 15:52:24 +00:00
|
|
|
QVERIFY(widget.seenMouseEvent);
|
2011-04-27 10:05:43 +00:00
|
|
|
QVERIFY(!window.seenTouchEvent);
|
2014-12-09 15:52:24 +00:00
|
|
|
QVERIFY(window.seenMouseEvent);
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
window.reset();
|
|
|
|
widget.reset();
|
|
|
|
widget.acceptMouseEvent = true;
|
2019-05-10 09:08:11 +00:00
|
|
|
QWindowSystemInterface::handleTouchEvent(handle,
|
2011-12-10 14:30:18 +00:00
|
|
|
0,
|
|
|
|
device,
|
2019-05-10 09:08:11 +00:00
|
|
|
QWindowSystemInterfacePrivate::toNativeTouchPoints(pressedTouchPoints, handle));
|
|
|
|
QWindowSystemInterface::handleTouchEvent(handle,
|
2011-12-10 14:30:18 +00:00
|
|
|
0,
|
|
|
|
device,
|
2019-05-10 09:08:11 +00:00
|
|
|
QWindowSystemInterfacePrivate::toNativeTouchPoints(releasedTouchPoints, handle));
|
2011-12-10 14:30:18 +00:00
|
|
|
QCoreApplication::processEvents();
|
2011-04-27 10:05:43 +00:00
|
|
|
QVERIFY(widget.seenTouchEvent);
|
2014-12-09 15:52:24 +00:00
|
|
|
QVERIFY(widget.seenMouseEvent);
|
2011-04-27 10:05:43 +00:00
|
|
|
QVERIFY(!window.seenTouchEvent);
|
|
|
|
QVERIFY(!window.seenMouseEvent);
|
|
|
|
|
|
|
|
window.reset();
|
|
|
|
widget.reset();
|
|
|
|
widget.acceptTouchEvent = true;
|
2019-05-10 09:08:11 +00:00
|
|
|
QWindowSystemInterface::handleTouchEvent(handle,
|
2011-12-10 14:30:18 +00:00
|
|
|
0,
|
|
|
|
device,
|
2019-05-10 09:08:11 +00:00
|
|
|
QWindowSystemInterfacePrivate::toNativeTouchPoints(pressedTouchPoints, handle));
|
|
|
|
QWindowSystemInterface::handleTouchEvent(handle,
|
2011-12-10 14:30:18 +00:00
|
|
|
0,
|
|
|
|
device,
|
2019-05-10 09:08:11 +00:00
|
|
|
QWindowSystemInterfacePrivate::toNativeTouchPoints(releasedTouchPoints, handle));
|
2011-12-10 14:30:18 +00:00
|
|
|
QCoreApplication::processEvents();
|
2011-04-27 10:05:43 +00:00
|
|
|
QVERIFY(widget.seenTouchEvent);
|
|
|
|
QVERIFY(!widget.seenMouseEvent);
|
|
|
|
QVERIFY(!window.seenTouchEvent);
|
|
|
|
QVERIFY(!window.seenMouseEvent);
|
|
|
|
|
|
|
|
window.reset();
|
|
|
|
widget.reset();
|
|
|
|
widget.setAttribute(Qt::WA_AcceptTouchEvents, false);
|
|
|
|
window.setAttribute(Qt::WA_AcceptTouchEvents);
|
2019-05-10 09:08:11 +00:00
|
|
|
QWindowSystemInterface::handleTouchEvent(handle,
|
2011-12-10 14:30:18 +00:00
|
|
|
0,
|
|
|
|
device,
|
2019-05-10 09:08:11 +00:00
|
|
|
QWindowSystemInterfacePrivate::toNativeTouchPoints(pressedTouchPoints, handle));
|
|
|
|
QWindowSystemInterface::handleTouchEvent(handle,
|
2011-12-10 14:30:18 +00:00
|
|
|
0,
|
|
|
|
device,
|
2019-05-10 09:08:11 +00:00
|
|
|
QWindowSystemInterfacePrivate::toNativeTouchPoints(releasedTouchPoints, handle));
|
2011-12-10 14:30:18 +00:00
|
|
|
QCoreApplication::processEvents();
|
2011-04-27 10:05:43 +00:00
|
|
|
QVERIFY(!widget.seenTouchEvent);
|
2014-12-09 15:52:24 +00:00
|
|
|
QVERIFY(widget.seenMouseEvent);
|
2011-04-27 10:05:43 +00:00
|
|
|
QVERIFY(window.seenTouchEvent);
|
2014-12-09 15:52:24 +00:00
|
|
|
QVERIFY(window.seenMouseEvent);
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
window.reset();
|
|
|
|
widget.reset();
|
|
|
|
window.acceptTouchEvent = true;
|
2019-05-10 09:08:11 +00:00
|
|
|
QWindowSystemInterface::handleTouchEvent(handle,
|
2011-12-10 14:30:18 +00:00
|
|
|
0,
|
|
|
|
device,
|
2019-05-10 09:08:11 +00:00
|
|
|
QWindowSystemInterfacePrivate::toNativeTouchPoints(pressedTouchPoints, handle));
|
|
|
|
QWindowSystemInterface::handleTouchEvent(handle,
|
2011-12-10 14:30:18 +00:00
|
|
|
0,
|
|
|
|
device,
|
2019-05-10 09:08:11 +00:00
|
|
|
QWindowSystemInterfacePrivate::toNativeTouchPoints(releasedTouchPoints, handle));
|
2011-12-10 14:30:18 +00:00
|
|
|
QCoreApplication::processEvents();
|
2011-04-27 10:05:43 +00:00
|
|
|
QVERIFY(!widget.seenTouchEvent);
|
2014-12-09 15:52:24 +00:00
|
|
|
QVERIFY(!widget.seenMouseEvent);
|
2011-04-27 10:05:43 +00:00
|
|
|
QVERIFY(window.seenTouchEvent);
|
|
|
|
QVERIFY(!window.seenMouseEvent);
|
|
|
|
|
|
|
|
window.reset();
|
|
|
|
widget.reset();
|
2014-12-09 15:52:24 +00:00
|
|
|
widget.acceptMouseEvent = true; // doesn't matter, touch events are propagated first
|
2011-04-27 10:05:43 +00:00
|
|
|
window.acceptTouchEvent = true;
|
2019-05-10 09:08:11 +00:00
|
|
|
QWindowSystemInterface::handleTouchEvent(handle,
|
2011-12-10 14:30:18 +00:00
|
|
|
0,
|
|
|
|
device,
|
2019-05-10 09:08:11 +00:00
|
|
|
QWindowSystemInterfacePrivate::toNativeTouchPoints(pressedTouchPoints, handle));
|
|
|
|
QWindowSystemInterface::handleTouchEvent(handle,
|
2011-12-10 14:30:18 +00:00
|
|
|
0,
|
|
|
|
device,
|
2019-05-10 09:08:11 +00:00
|
|
|
QWindowSystemInterfacePrivate::toNativeTouchPoints(releasedTouchPoints, handle));
|
2011-12-10 14:30:18 +00:00
|
|
|
QCoreApplication::processEvents();
|
2011-04-27 10:05:43 +00:00
|
|
|
QVERIFY(!widget.seenTouchEvent);
|
2014-12-09 15:52:24 +00:00
|
|
|
QVERIFY(!widget.seenMouseEvent);
|
|
|
|
QVERIFY(window.seenTouchEvent);
|
2011-04-27 10:05:43 +00:00
|
|
|
QVERIFY(!window.seenMouseEvent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
QApplication: deliver all wheel events to widget that accepts the first
For kinetic wheel events, Qt tries to make sure that all events in the
stream go to the widget that accepted the first wheel event.
It did so by directing all events from the stream to the widget from
which the spontaneous event was returned as accepted.
However, that widget might have passed the event on to some other
widgets; e.g QScrollArea forwards wheel events from the viewport to the
relevant scroll bar. The event might then have come back accepted only
because parent propagation kicked in (the scrollbar might not accept
the event, so the parents get a chance, and some parent's scrollbar
ultimately accepts the event).
In this scenario, the wheel widget would be the viewport under the
mouse, when it should have been the scrollbar of the parent. The
next events from the stream were then delivered to a widget that didn't
scroll; and parent propagation is not (and should not be) implemented
for the case where Qt has a wheel widget.
Instead, make the first widget that accepts any initial wheel event
the wheel widget, even if the event was not spontaneous. With this
change, all events from the stream are delivered to the widget that
actually handled the event. That has the effect that ie. a viewport
of a scroll area only gets the first event; all following events are
delivered directly to the scrollbar.
The test case added simulates the different scenarios - nesting of
scroll areas, classic wheel events and a stream of kinetic wheel
events.
[ChangeLog][QtWidgets][QApplication] Wheel events from a device that
creates an event stream are correctly delivered to the widget that
accepts the first wheel event in the stream.
Change-Id: I5ebfc7789b5c32ebc8d881686f450fa05ec92cfe
Fixes: QTBUG-79102
Pick-to: 5.15
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
2020-04-21 11:39:59 +00:00
|
|
|
/*!
|
|
|
|
Test that wheel events are propagated correctly.
|
|
|
|
|
|
|
|
The event propagation of wheel events is complex: generally, they are propagated
|
|
|
|
up the parent tree like other input events, until a widget accepts the event. However,
|
|
|
|
wheel events are ignored by default (unlike mouse events, which are accepted by default,
|
|
|
|
and ignored in the default implementation of the event handler of QWidget).
|
|
|
|
|
|
|
|
And Qt tries to make sure that wheel events that "belong together" are going to the same
|
|
|
|
widget. However, for low-precision events as generated by an old-fashioned
|
|
|
|
mouse wheel, each event is a distinct event, so Qt has no choice than to deliver the event
|
|
|
|
to the widget under the mouse.
|
|
|
|
High-precision events, as generated by track pads or other kinetic scrolling devices, come
|
|
|
|
in a continuous stream, with different phases. Qt tries to make sure that all events in the
|
|
|
|
same stream go to the widget that accepted the first event.
|
|
|
|
|
|
|
|
Also, QAbstractScrollArea forwards wheel events from the viewport to the relevant scrollbar,
|
|
|
|
which adds more complexity to the handling.
|
|
|
|
|
|
|
|
This tests two scenarios:
|
|
|
|
1) a large widget inside a scrollarea that scrolls, inside a scrollarea that also scrolls
|
|
|
|
2) a large widget inside a scrollarea that doesn't scroll, within a scrollarea that does
|
|
|
|
|
|
|
|
For scenario 1 "inner", the expectation is that the inner scrollarea handles all wheel
|
|
|
|
events.
|
|
|
|
For scenario 2 "outer", the expectation is that the outer scrollarea handles all wheel
|
|
|
|
events.
|
|
|
|
*/
|
2020-04-22 08:53:04 +00:00
|
|
|
struct WheelEvent
|
|
|
|
{
|
|
|
|
WheelEvent(Qt::ScrollPhase p = Qt::NoScrollPhase, Qt::Orientation o = Qt::Vertical)
|
|
|
|
: phase(p), orientation(o)
|
|
|
|
{}
|
|
|
|
Qt::ScrollPhase phase = Qt::NoScrollPhase;
|
|
|
|
Qt::Orientation orientation = Qt::Vertical;
|
|
|
|
};
|
|
|
|
using WheelEventList = QList<WheelEvent>;
|
QApplication: deliver all wheel events to widget that accepts the first
For kinetic wheel events, Qt tries to make sure that all events in the
stream go to the widget that accepted the first wheel event.
It did so by directing all events from the stream to the widget from
which the spontaneous event was returned as accepted.
However, that widget might have passed the event on to some other
widgets; e.g QScrollArea forwards wheel events from the viewport to the
relevant scroll bar. The event might then have come back accepted only
because parent propagation kicked in (the scrollbar might not accept
the event, so the parents get a chance, and some parent's scrollbar
ultimately accepts the event).
In this scenario, the wheel widget would be the viewport under the
mouse, when it should have been the scrollbar of the parent. The
next events from the stream were then delivered to a widget that didn't
scroll; and parent propagation is not (and should not be) implemented
for the case where Qt has a wheel widget.
Instead, make the first widget that accepts any initial wheel event
the wheel widget, even if the event was not spontaneous. With this
change, all events from the stream are delivered to the widget that
actually handled the event. That has the effect that ie. a viewport
of a scroll area only gets the first event; all following events are
delivered directly to the scrollbar.
The test case added simulates the different scenarios - nesting of
scroll areas, classic wheel events and a stream of kinetic wheel
events.
[ChangeLog][QtWidgets][QApplication] Wheel events from a device that
creates an event stream are correctly delivered to the widget that
accepts the first wheel event in the stream.
Change-Id: I5ebfc7789b5c32ebc8d881686f450fa05ec92cfe
Fixes: QTBUG-79102
Pick-to: 5.15
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
2020-04-21 11:39:59 +00:00
|
|
|
|
|
|
|
void tst_QApplication::wheelEventPropagation_data()
|
|
|
|
{
|
2020-04-22 08:53:04 +00:00
|
|
|
qRegisterMetaType<WheelEventList>();
|
QApplication: deliver all wheel events to widget that accepts the first
For kinetic wheel events, Qt tries to make sure that all events in the
stream go to the widget that accepted the first wheel event.
It did so by directing all events from the stream to the widget from
which the spontaneous event was returned as accepted.
However, that widget might have passed the event on to some other
widgets; e.g QScrollArea forwards wheel events from the viewport to the
relevant scroll bar. The event might then have come back accepted only
because parent propagation kicked in (the scrollbar might not accept
the event, so the parents get a chance, and some parent's scrollbar
ultimately accepts the event).
In this scenario, the wheel widget would be the viewport under the
mouse, when it should have been the scrollbar of the parent. The
next events from the stream were then delivered to a widget that didn't
scroll; and parent propagation is not (and should not be) implemented
for the case where Qt has a wheel widget.
Instead, make the first widget that accepts any initial wheel event
the wheel widget, even if the event was not spontaneous. With this
change, all events from the stream are delivered to the widget that
actually handled the event. That has the effect that ie. a viewport
of a scroll area only gets the first event; all following events are
delivered directly to the scrollbar.
The test case added simulates the different scenarios - nesting of
scroll areas, classic wheel events and a stream of kinetic wheel
events.
[ChangeLog][QtWidgets][QApplication] Wheel events from a device that
creates an event stream are correctly delivered to the widget that
accepts the first wheel event in the stream.
Change-Id: I5ebfc7789b5c32ebc8d881686f450fa05ec92cfe
Fixes: QTBUG-79102
Pick-to: 5.15
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
2020-04-21 11:39:59 +00:00
|
|
|
|
|
|
|
QTest::addColumn<bool>("innerScrolls");
|
2020-04-22 08:53:04 +00:00
|
|
|
QTest::addColumn<WheelEventList>("events");
|
QApplication: deliver all wheel events to widget that accepts the first
For kinetic wheel events, Qt tries to make sure that all events in the
stream go to the widget that accepted the first wheel event.
It did so by directing all events from the stream to the widget from
which the spontaneous event was returned as accepted.
However, that widget might have passed the event on to some other
widgets; e.g QScrollArea forwards wheel events from the viewport to the
relevant scroll bar. The event might then have come back accepted only
because parent propagation kicked in (the scrollbar might not accept
the event, so the parents get a chance, and some parent's scrollbar
ultimately accepts the event).
In this scenario, the wheel widget would be the viewport under the
mouse, when it should have been the scrollbar of the parent. The
next events from the stream were then delivered to a widget that didn't
scroll; and parent propagation is not (and should not be) implemented
for the case where Qt has a wheel widget.
Instead, make the first widget that accepts any initial wheel event
the wheel widget, even if the event was not spontaneous. With this
change, all events from the stream are delivered to the widget that
actually handled the event. That has the effect that ie. a viewport
of a scroll area only gets the first event; all following events are
delivered directly to the scrollbar.
The test case added simulates the different scenarios - nesting of
scroll areas, classic wheel events and a stream of kinetic wheel
events.
[ChangeLog][QtWidgets][QApplication] Wheel events from a device that
creates an event stream are correctly delivered to the widget that
accepts the first wheel event in the stream.
Change-Id: I5ebfc7789b5c32ebc8d881686f450fa05ec92cfe
Fixes: QTBUG-79102
Pick-to: 5.15
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
2020-04-21 11:39:59 +00:00
|
|
|
|
|
|
|
QTest::addRow("inner, classic")
|
|
|
|
<< true
|
2020-04-22 08:53:04 +00:00
|
|
|
<< WheelEventList{{}, {}, {}};
|
QApplication: deliver all wheel events to widget that accepts the first
For kinetic wheel events, Qt tries to make sure that all events in the
stream go to the widget that accepted the first wheel event.
It did so by directing all events from the stream to the widget from
which the spontaneous event was returned as accepted.
However, that widget might have passed the event on to some other
widgets; e.g QScrollArea forwards wheel events from the viewport to the
relevant scroll bar. The event might then have come back accepted only
because parent propagation kicked in (the scrollbar might not accept
the event, so the parents get a chance, and some parent's scrollbar
ultimately accepts the event).
In this scenario, the wheel widget would be the viewport under the
mouse, when it should have been the scrollbar of the parent. The
next events from the stream were then delivered to a widget that didn't
scroll; and parent propagation is not (and should not be) implemented
for the case where Qt has a wheel widget.
Instead, make the first widget that accepts any initial wheel event
the wheel widget, even if the event was not spontaneous. With this
change, all events from the stream are delivered to the widget that
actually handled the event. That has the effect that ie. a viewport
of a scroll area only gets the first event; all following events are
delivered directly to the scrollbar.
The test case added simulates the different scenarios - nesting of
scroll areas, classic wheel events and a stream of kinetic wheel
events.
[ChangeLog][QtWidgets][QApplication] Wheel events from a device that
creates an event stream are correctly delivered to the widget that
accepts the first wheel event in the stream.
Change-Id: I5ebfc7789b5c32ebc8d881686f450fa05ec92cfe
Fixes: QTBUG-79102
Pick-to: 5.15
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
2020-04-21 11:39:59 +00:00
|
|
|
QTest::addRow("outer, classic")
|
|
|
|
<< false
|
2020-04-22 08:53:04 +00:00
|
|
|
<< WheelEventList{{}, {}, {}};
|
QApplication: deliver all wheel events to widget that accepts the first
For kinetic wheel events, Qt tries to make sure that all events in the
stream go to the widget that accepted the first wheel event.
It did so by directing all events from the stream to the widget from
which the spontaneous event was returned as accepted.
However, that widget might have passed the event on to some other
widgets; e.g QScrollArea forwards wheel events from the viewport to the
relevant scroll bar. The event might then have come back accepted only
because parent propagation kicked in (the scrollbar might not accept
the event, so the parents get a chance, and some parent's scrollbar
ultimately accepts the event).
In this scenario, the wheel widget would be the viewport under the
mouse, when it should have been the scrollbar of the parent. The
next events from the stream were then delivered to a widget that didn't
scroll; and parent propagation is not (and should not be) implemented
for the case where Qt has a wheel widget.
Instead, make the first widget that accepts any initial wheel event
the wheel widget, even if the event was not spontaneous. With this
change, all events from the stream are delivered to the widget that
actually handled the event. That has the effect that ie. a viewport
of a scroll area only gets the first event; all following events are
delivered directly to the scrollbar.
The test case added simulates the different scenarios - nesting of
scroll areas, classic wheel events and a stream of kinetic wheel
events.
[ChangeLog][QtWidgets][QApplication] Wheel events from a device that
creates an event stream are correctly delivered to the widget that
accepts the first wheel event in the stream.
Change-Id: I5ebfc7789b5c32ebc8d881686f450fa05ec92cfe
Fixes: QTBUG-79102
Pick-to: 5.15
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
2020-04-21 11:39:59 +00:00
|
|
|
QTest::addRow("inner, kinetic")
|
|
|
|
<< true
|
2020-04-22 08:53:04 +00:00
|
|
|
<< WheelEventList{Qt::ScrollBegin, Qt::ScrollUpdate, Qt::ScrollMomentum, Qt::ScrollEnd};
|
QApplication: deliver all wheel events to widget that accepts the first
For kinetic wheel events, Qt tries to make sure that all events in the
stream go to the widget that accepted the first wheel event.
It did so by directing all events from the stream to the widget from
which the spontaneous event was returned as accepted.
However, that widget might have passed the event on to some other
widgets; e.g QScrollArea forwards wheel events from the viewport to the
relevant scroll bar. The event might then have come back accepted only
because parent propagation kicked in (the scrollbar might not accept
the event, so the parents get a chance, and some parent's scrollbar
ultimately accepts the event).
In this scenario, the wheel widget would be the viewport under the
mouse, when it should have been the scrollbar of the parent. The
next events from the stream were then delivered to a widget that didn't
scroll; and parent propagation is not (and should not be) implemented
for the case where Qt has a wheel widget.
Instead, make the first widget that accepts any initial wheel event
the wheel widget, even if the event was not spontaneous. With this
change, all events from the stream are delivered to the widget that
actually handled the event. That has the effect that ie. a viewport
of a scroll area only gets the first event; all following events are
delivered directly to the scrollbar.
The test case added simulates the different scenarios - nesting of
scroll areas, classic wheel events and a stream of kinetic wheel
events.
[ChangeLog][QtWidgets][QApplication] Wheel events from a device that
creates an event stream are correctly delivered to the widget that
accepts the first wheel event in the stream.
Change-Id: I5ebfc7789b5c32ebc8d881686f450fa05ec92cfe
Fixes: QTBUG-79102
Pick-to: 5.15
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
2020-04-21 11:39:59 +00:00
|
|
|
QTest::addRow("outer, kinetic")
|
|
|
|
<< false
|
2020-04-22 08:53:04 +00:00
|
|
|
<< WheelEventList{Qt::ScrollBegin, Qt::ScrollUpdate, Qt::ScrollMomentum, Qt::ScrollEnd};
|
|
|
|
QTest::addRow("inner, partial kinetic")
|
|
|
|
<< true
|
|
|
|
<< WheelEventList{Qt::ScrollUpdate, Qt::ScrollMomentum, Qt::ScrollEnd};
|
|
|
|
QTest::addRow("outer, partial kinetic")
|
|
|
|
<< false
|
|
|
|
<< WheelEventList{Qt::ScrollUpdate, Qt::ScrollMomentum, Qt::ScrollEnd};
|
|
|
|
QTest::addRow("inner, changing direction")
|
|
|
|
<< true
|
|
|
|
<< WheelEventList{Qt::ScrollUpdate, {Qt::ScrollUpdate, Qt::Horizontal}, Qt::ScrollMomentum, Qt::ScrollEnd};
|
|
|
|
QTest::addRow("outer, changing direction")
|
|
|
|
<< false
|
|
|
|
<< WheelEventList{Qt::ScrollUpdate, {Qt::ScrollUpdate, Qt::Horizontal}, Qt::ScrollMomentum, Qt::ScrollEnd};
|
QApplication: deliver all wheel events to widget that accepts the first
For kinetic wheel events, Qt tries to make sure that all events in the
stream go to the widget that accepted the first wheel event.
It did so by directing all events from the stream to the widget from
which the spontaneous event was returned as accepted.
However, that widget might have passed the event on to some other
widgets; e.g QScrollArea forwards wheel events from the viewport to the
relevant scroll bar. The event might then have come back accepted only
because parent propagation kicked in (the scrollbar might not accept
the event, so the parents get a chance, and some parent's scrollbar
ultimately accepts the event).
In this scenario, the wheel widget would be the viewport under the
mouse, when it should have been the scrollbar of the parent. The
next events from the stream were then delivered to a widget that didn't
scroll; and parent propagation is not (and should not be) implemented
for the case where Qt has a wheel widget.
Instead, make the first widget that accepts any initial wheel event
the wheel widget, even if the event was not spontaneous. With this
change, all events from the stream are delivered to the widget that
actually handled the event. That has the effect that ie. a viewport
of a scroll area only gets the first event; all following events are
delivered directly to the scrollbar.
The test case added simulates the different scenarios - nesting of
scroll areas, classic wheel events and a stream of kinetic wheel
events.
[ChangeLog][QtWidgets][QApplication] Wheel events from a device that
creates an event stream are correctly delivered to the widget that
accepts the first wheel event in the stream.
Change-Id: I5ebfc7789b5c32ebc8d881686f450fa05ec92cfe
Fixes: QTBUG-79102
Pick-to: 5.15
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
2020-04-21 11:39:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void tst_QApplication::wheelEventPropagation()
|
|
|
|
{
|
|
|
|
QFETCH(bool, innerScrolls);
|
2020-04-22 08:53:04 +00:00
|
|
|
QFETCH(WheelEventList, events);
|
QApplication: deliver all wheel events to widget that accepts the first
For kinetic wheel events, Qt tries to make sure that all events in the
stream go to the widget that accepted the first wheel event.
It did so by directing all events from the stream to the widget from
which the spontaneous event was returned as accepted.
However, that widget might have passed the event on to some other
widgets; e.g QScrollArea forwards wheel events from the viewport to the
relevant scroll bar. The event might then have come back accepted only
because parent propagation kicked in (the scrollbar might not accept
the event, so the parents get a chance, and some parent's scrollbar
ultimately accepts the event).
In this scenario, the wheel widget would be the viewport under the
mouse, when it should have been the scrollbar of the parent. The
next events from the stream were then delivered to a widget that didn't
scroll; and parent propagation is not (and should not be) implemented
for the case where Qt has a wheel widget.
Instead, make the first widget that accepts any initial wheel event
the wheel widget, even if the event was not spontaneous. With this
change, all events from the stream are delivered to the widget that
actually handled the event. That has the effect that ie. a viewport
of a scroll area only gets the first event; all following events are
delivered directly to the scrollbar.
The test case added simulates the different scenarios - nesting of
scroll areas, classic wheel events and a stream of kinetic wheel
events.
[ChangeLog][QtWidgets][QApplication] Wheel events from a device that
creates an event stream are correctly delivered to the widget that
accepts the first wheel event in the stream.
Change-Id: I5ebfc7789b5c32ebc8d881686f450fa05ec92cfe
Fixes: QTBUG-79102
Pick-to: 5.15
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
2020-04-21 11:39:59 +00:00
|
|
|
|
|
|
|
const QSize baseSize(500, 500);
|
|
|
|
const QPointF center(baseSize.width() / 2, baseSize.height() / 2);
|
|
|
|
int scrollStep = 50;
|
|
|
|
|
|
|
|
int argc = 1;
|
|
|
|
QApplication app(argc, &argv0);
|
|
|
|
|
|
|
|
QScrollArea outerArea;
|
|
|
|
outerArea.setObjectName("outerArea");
|
|
|
|
outerArea.viewport()->setObjectName("outerArea_viewport");
|
|
|
|
QScrollArea innerArea;
|
|
|
|
innerArea.setObjectName("innerArea");
|
|
|
|
innerArea.viewport()->setObjectName("innerArea_viewport");
|
|
|
|
QWidget largeWidget;
|
|
|
|
largeWidget.setObjectName("largeWidget");
|
|
|
|
QScrollBar trap(Qt::Vertical, &largeWidget);
|
|
|
|
trap.setObjectName("It's a trap!");
|
|
|
|
|
|
|
|
largeWidget.setFixedSize(baseSize * 8);
|
|
|
|
|
|
|
|
// classic wheel events will be grabbed by the widget under the mouse, so don't place a trap
|
2020-04-22 08:53:04 +00:00
|
|
|
if (events.at(0).phase == Qt::NoScrollPhase)
|
QApplication: deliver all wheel events to widget that accepts the first
For kinetic wheel events, Qt tries to make sure that all events in the
stream go to the widget that accepted the first wheel event.
It did so by directing all events from the stream to the widget from
which the spontaneous event was returned as accepted.
However, that widget might have passed the event on to some other
widgets; e.g QScrollArea forwards wheel events from the viewport to the
relevant scroll bar. The event might then have come back accepted only
because parent propagation kicked in (the scrollbar might not accept
the event, so the parents get a chance, and some parent's scrollbar
ultimately accepts the event).
In this scenario, the wheel widget would be the viewport under the
mouse, when it should have been the scrollbar of the parent. The
next events from the stream were then delivered to a widget that didn't
scroll; and parent propagation is not (and should not be) implemented
for the case where Qt has a wheel widget.
Instead, make the first widget that accepts any initial wheel event
the wheel widget, even if the event was not spontaneous. With this
change, all events from the stream are delivered to the widget that
actually handled the event. That has the effect that ie. a viewport
of a scroll area only gets the first event; all following events are
delivered directly to the scrollbar.
The test case added simulates the different scenarios - nesting of
scroll areas, classic wheel events and a stream of kinetic wheel
events.
[ChangeLog][QtWidgets][QApplication] Wheel events from a device that
creates an event stream are correctly delivered to the widget that
accepts the first wheel event in the stream.
Change-Id: I5ebfc7789b5c32ebc8d881686f450fa05ec92cfe
Fixes: QTBUG-79102
Pick-to: 5.15
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
2020-04-21 11:39:59 +00:00
|
|
|
trap.hide();
|
|
|
|
// kinetic wheel events should all go to the first widget; place a trap
|
|
|
|
else
|
|
|
|
trap.setGeometry(center.x() - 50, center.y() + scrollStep, 100, baseSize.height());
|
|
|
|
|
|
|
|
// if the inner area is large enough to host the widget, then it won't scroll
|
|
|
|
innerArea.setWidget(&largeWidget);
|
|
|
|
innerArea.setFixedSize(innerScrolls ? baseSize * 4
|
|
|
|
: largeWidget.minimumSize() + QSize(100, 100));
|
|
|
|
// the outer area always scrolls
|
|
|
|
outerArea.setFixedSize(baseSize);
|
|
|
|
outerArea.setWidget(&innerArea);
|
|
|
|
outerArea.show();
|
|
|
|
|
|
|
|
if (!QTest::qWaitForWindowExposed(&outerArea))
|
|
|
|
QSKIP("Window failed to show, can't run test");
|
|
|
|
|
|
|
|
auto innerVBar = innerArea.verticalScrollBar();
|
|
|
|
innerVBar->setObjectName("innerArea_vbar");
|
|
|
|
QCOMPARE(innerVBar->isVisible(), innerScrolls);
|
2020-04-22 08:53:04 +00:00
|
|
|
auto innerHBar = innerArea.horizontalScrollBar();
|
|
|
|
innerHBar->setObjectName("innerArea_hbar");
|
|
|
|
QCOMPARE(innerHBar->isVisible(), innerScrolls);
|
QApplication: deliver all wheel events to widget that accepts the first
For kinetic wheel events, Qt tries to make sure that all events in the
stream go to the widget that accepted the first wheel event.
It did so by directing all events from the stream to the widget from
which the spontaneous event was returned as accepted.
However, that widget might have passed the event on to some other
widgets; e.g QScrollArea forwards wheel events from the viewport to the
relevant scroll bar. The event might then have come back accepted only
because parent propagation kicked in (the scrollbar might not accept
the event, so the parents get a chance, and some parent's scrollbar
ultimately accepts the event).
In this scenario, the wheel widget would be the viewport under the
mouse, when it should have been the scrollbar of the parent. The
next events from the stream were then delivered to a widget that didn't
scroll; and parent propagation is not (and should not be) implemented
for the case where Qt has a wheel widget.
Instead, make the first widget that accepts any initial wheel event
the wheel widget, even if the event was not spontaneous. With this
change, all events from the stream are delivered to the widget that
actually handled the event. That has the effect that ie. a viewport
of a scroll area only gets the first event; all following events are
delivered directly to the scrollbar.
The test case added simulates the different scenarios - nesting of
scroll areas, classic wheel events and a stream of kinetic wheel
events.
[ChangeLog][QtWidgets][QApplication] Wheel events from a device that
creates an event stream are correctly delivered to the widget that
accepts the first wheel event in the stream.
Change-Id: I5ebfc7789b5c32ebc8d881686f450fa05ec92cfe
Fixes: QTBUG-79102
Pick-to: 5.15
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
2020-04-21 11:39:59 +00:00
|
|
|
auto outerVBar = outerArea.verticalScrollBar();
|
|
|
|
outerVBar->setObjectName("outerArea_vbar");
|
|
|
|
QVERIFY(outerVBar->isVisible());
|
2020-04-22 08:53:04 +00:00
|
|
|
auto outerHBar = outerArea.horizontalScrollBar();
|
|
|
|
outerHBar->setObjectName("outerArea_hbar");
|
|
|
|
QVERIFY(outerHBar->isVisible());
|
QApplication: deliver all wheel events to widget that accepts the first
For kinetic wheel events, Qt tries to make sure that all events in the
stream go to the widget that accepted the first wheel event.
It did so by directing all events from the stream to the widget from
which the spontaneous event was returned as accepted.
However, that widget might have passed the event on to some other
widgets; e.g QScrollArea forwards wheel events from the viewport to the
relevant scroll bar. The event might then have come back accepted only
because parent propagation kicked in (the scrollbar might not accept
the event, so the parents get a chance, and some parent's scrollbar
ultimately accepts the event).
In this scenario, the wheel widget would be the viewport under the
mouse, when it should have been the scrollbar of the parent. The
next events from the stream were then delivered to a widget that didn't
scroll; and parent propagation is not (and should not be) implemented
for the case where Qt has a wheel widget.
Instead, make the first widget that accepts any initial wheel event
the wheel widget, even if the event was not spontaneous. With this
change, all events from the stream are delivered to the widget that
actually handled the event. That has the effect that ie. a viewport
of a scroll area only gets the first event; all following events are
delivered directly to the scrollbar.
The test case added simulates the different scenarios - nesting of
scroll areas, classic wheel events and a stream of kinetic wheel
events.
[ChangeLog][QtWidgets][QApplication] Wheel events from a device that
creates an event stream are correctly delivered to the widget that
accepts the first wheel event in the stream.
Change-Id: I5ebfc7789b5c32ebc8d881686f450fa05ec92cfe
Fixes: QTBUG-79102
Pick-to: 5.15
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
2020-04-21 11:39:59 +00:00
|
|
|
|
|
|
|
const QPointF global(outerArea.mapToGlobal(center.toPoint()));
|
|
|
|
|
2020-04-22 08:53:04 +00:00
|
|
|
QSignalSpy innerVSpy(innerVBar, &QAbstractSlider::valueChanged);
|
|
|
|
QSignalSpy innerHSpy(innerHBar, &QAbstractSlider::valueChanged);
|
|
|
|
QSignalSpy outerVSpy(outerVBar, &QAbstractSlider::valueChanged);
|
|
|
|
QSignalSpy outerHSpy(outerHBar, &QAbstractSlider::valueChanged);
|
QApplication: deliver all wheel events to widget that accepts the first
For kinetic wheel events, Qt tries to make sure that all events in the
stream go to the widget that accepted the first wheel event.
It did so by directing all events from the stream to the widget from
which the spontaneous event was returned as accepted.
However, that widget might have passed the event on to some other
widgets; e.g QScrollArea forwards wheel events from the viewport to the
relevant scroll bar. The event might then have come back accepted only
because parent propagation kicked in (the scrollbar might not accept
the event, so the parents get a chance, and some parent's scrollbar
ultimately accepts the event).
In this scenario, the wheel widget would be the viewport under the
mouse, when it should have been the scrollbar of the parent. The
next events from the stream were then delivered to a widget that didn't
scroll; and parent propagation is not (and should not be) implemented
for the case where Qt has a wheel widget.
Instead, make the first widget that accepts any initial wheel event
the wheel widget, even if the event was not spontaneous. With this
change, all events from the stream are delivered to the widget that
actually handled the event. That has the effect that ie. a viewport
of a scroll area only gets the first event; all following events are
delivered directly to the scrollbar.
The test case added simulates the different scenarios - nesting of
scroll areas, classic wheel events and a stream of kinetic wheel
events.
[ChangeLog][QtWidgets][QApplication] Wheel events from a device that
creates an event stream are correctly delivered to the widget that
accepts the first wheel event in the stream.
Change-Id: I5ebfc7789b5c32ebc8d881686f450fa05ec92cfe
Fixes: QTBUG-79102
Pick-to: 5.15
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
2020-04-21 11:39:59 +00:00
|
|
|
|
2020-04-22 08:53:04 +00:00
|
|
|
int vcount = 0;
|
|
|
|
int hcount = 0;
|
|
|
|
|
|
|
|
for (const auto &event : qAsConst(events)) {
|
|
|
|
const QPoint pixelDelta = event.orientation == Qt::Vertical ? QPoint(0, -scrollStep) : QPoint(-scrollStep, 0);
|
|
|
|
const QPoint angleDelta = event.orientation == Qt::Vertical ? QPoint(0, -120) : QPoint(-120, 0);
|
QApplication: deliver all wheel events to widget that accepts the first
For kinetic wheel events, Qt tries to make sure that all events in the
stream go to the widget that accepted the first wheel event.
It did so by directing all events from the stream to the widget from
which the spontaneous event was returned as accepted.
However, that widget might have passed the event on to some other
widgets; e.g QScrollArea forwards wheel events from the viewport to the
relevant scroll bar. The event might then have come back accepted only
because parent propagation kicked in (the scrollbar might not accept
the event, so the parents get a chance, and some parent's scrollbar
ultimately accepts the event).
In this scenario, the wheel widget would be the viewport under the
mouse, when it should have been the scrollbar of the parent. The
next events from the stream were then delivered to a widget that didn't
scroll; and parent propagation is not (and should not be) implemented
for the case where Qt has a wheel widget.
Instead, make the first widget that accepts any initial wheel event
the wheel widget, even if the event was not spontaneous. With this
change, all events from the stream are delivered to the widget that
actually handled the event. That has the effect that ie. a viewport
of a scroll area only gets the first event; all following events are
delivered directly to the scrollbar.
The test case added simulates the different scenarios - nesting of
scroll areas, classic wheel events and a stream of kinetic wheel
events.
[ChangeLog][QtWidgets][QApplication] Wheel events from a device that
creates an event stream are correctly delivered to the widget that
accepts the first wheel event in the stream.
Change-Id: I5ebfc7789b5c32ebc8d881686f450fa05ec92cfe
Fixes: QTBUG-79102
Pick-to: 5.15
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
2020-04-21 11:39:59 +00:00
|
|
|
QWindowSystemInterface::handleWheelEvent(outerArea.windowHandle(), center, global,
|
2020-04-22 08:53:04 +00:00
|
|
|
pixelDelta, angleDelta, Qt::NoModifier,
|
|
|
|
event.phase);
|
|
|
|
if (event.orientation == Qt::Vertical)
|
|
|
|
++vcount;
|
|
|
|
else
|
|
|
|
++hcount;
|
QApplication: deliver all wheel events to widget that accepts the first
For kinetic wheel events, Qt tries to make sure that all events in the
stream go to the widget that accepted the first wheel event.
It did so by directing all events from the stream to the widget from
which the spontaneous event was returned as accepted.
However, that widget might have passed the event on to some other
widgets; e.g QScrollArea forwards wheel events from the viewport to the
relevant scroll bar. The event might then have come back accepted only
because parent propagation kicked in (the scrollbar might not accept
the event, so the parents get a chance, and some parent's scrollbar
ultimately accepts the event).
In this scenario, the wheel widget would be the viewport under the
mouse, when it should have been the scrollbar of the parent. The
next events from the stream were then delivered to a widget that didn't
scroll; and parent propagation is not (and should not be) implemented
for the case where Qt has a wheel widget.
Instead, make the first widget that accepts any initial wheel event
the wheel widget, even if the event was not spontaneous. With this
change, all events from the stream are delivered to the widget that
actually handled the event. That has the effect that ie. a viewport
of a scroll area only gets the first event; all following events are
delivered directly to the scrollbar.
The test case added simulates the different scenarios - nesting of
scroll areas, classic wheel events and a stream of kinetic wheel
events.
[ChangeLog][QtWidgets][QApplication] Wheel events from a device that
creates an event stream are correctly delivered to the widget that
accepts the first wheel event in the stream.
Change-Id: I5ebfc7789b5c32ebc8d881686f450fa05ec92cfe
Fixes: QTBUG-79102
Pick-to: 5.15
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
2020-04-21 11:39:59 +00:00
|
|
|
QCoreApplication::processEvents();
|
2020-04-22 08:53:04 +00:00
|
|
|
QCOMPARE(innerVSpy.count(), innerScrolls ? vcount : 0);
|
|
|
|
QCOMPARE(innerHSpy.count(), innerScrolls ? hcount : 0);
|
|
|
|
QCOMPARE(outerVSpy.count(), innerScrolls ? 0 : vcount);
|
|
|
|
QCOMPARE(outerHSpy.count(), innerScrolls ? 0 : hcount);
|
QApplication: deliver all wheel events to widget that accepts the first
For kinetic wheel events, Qt tries to make sure that all events in the
stream go to the widget that accepted the first wheel event.
It did so by directing all events from the stream to the widget from
which the spontaneous event was returned as accepted.
However, that widget might have passed the event on to some other
widgets; e.g QScrollArea forwards wheel events from the viewport to the
relevant scroll bar. The event might then have come back accepted only
because parent propagation kicked in (the scrollbar might not accept
the event, so the parents get a chance, and some parent's scrollbar
ultimately accepts the event).
In this scenario, the wheel widget would be the viewport under the
mouse, when it should have been the scrollbar of the parent. The
next events from the stream were then delivered to a widget that didn't
scroll; and parent propagation is not (and should not be) implemented
for the case where Qt has a wheel widget.
Instead, make the first widget that accepts any initial wheel event
the wheel widget, even if the event was not spontaneous. With this
change, all events from the stream are delivered to the widget that
actually handled the event. That has the effect that ie. a viewport
of a scroll area only gets the first event; all following events are
delivered directly to the scrollbar.
The test case added simulates the different scenarios - nesting of
scroll areas, classic wheel events and a stream of kinetic wheel
events.
[ChangeLog][QtWidgets][QApplication] Wheel events from a device that
creates an event stream are correctly delivered to the widget that
accepts the first wheel event in the stream.
Change-Id: I5ebfc7789b5c32ebc8d881686f450fa05ec92cfe
Fixes: QTBUG-79102
Pick-to: 5.15
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
2020-04-21 11:39:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
void tst_QApplication::qtbug_12673()
|
|
|
|
{
|
2016-11-23 11:25:17 +00:00
|
|
|
#if QT_CONFIG(process)
|
2011-04-27 10:05:43 +00:00
|
|
|
QProcess testProcess;
|
|
|
|
QStringList arguments;
|
2018-06-28 06:43:42 +00:00
|
|
|
testProcess.start("modal_helper", arguments);
|
2011-12-14 08:27:33 +00:00
|
|
|
QVERIFY2(testProcess.waitForStarted(),
|
2018-06-28 06:43:42 +00:00
|
|
|
qPrintable(QString::fromLatin1("Cannot start 'modal_helper': %1").arg(testProcess.errorString())));
|
2011-04-27 10:05:43 +00:00
|
|
|
QVERIFY(testProcess.waitForFinished(20000));
|
|
|
|
QCOMPARE(testProcess.exitStatus(), QProcess::NormalExit);
|
2013-01-16 12:34:35 +00:00
|
|
|
#else
|
|
|
|
QSKIP( "No QProcess support", SkipAll);
|
|
|
|
#endif
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
2012-02-11 00:33:55 +00:00
|
|
|
class NoQuitOnHideWidget : public QWidget
|
2011-10-26 11:29:51 +00:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
2019-05-10 09:08:11 +00:00
|
|
|
explicit NoQuitOnHideWidget(QWidget *parent = nullptr)
|
2012-02-11 00:33:55 +00:00
|
|
|
: QWidget(parent)
|
2011-10-26 11:29:51 +00:00
|
|
|
{
|
2019-05-10 09:08:11 +00:00
|
|
|
QTimer::singleShot(0, this, &QWidget::hide);
|
|
|
|
QTimer::singleShot(500, this, [] () { QCoreApplication::exit(1); });
|
2011-10-26 11:29:51 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-02-11 00:33:55 +00:00
|
|
|
void tst_QApplication::noQuitOnHide()
|
2011-10-26 11:29:51 +00:00
|
|
|
{
|
2012-02-11 00:33:55 +00:00
|
|
|
int argc = 0;
|
2019-05-10 09:08:11 +00:00
|
|
|
QApplication app(argc, nullptr);
|
2016-09-28 08:49:57 +00:00
|
|
|
NoQuitOnHideWidget window1;
|
2019-05-10 09:08:11 +00:00
|
|
|
window1.setWindowTitle(QLatin1String(QTest::currentTestFunction()));
|
2016-09-28 08:49:57 +00:00
|
|
|
window1.show();
|
2019-05-10 09:08:11 +00:00
|
|
|
QCOMPARE(QCoreApplication::exec(), 1);
|
2011-10-26 11:29:51 +00:00
|
|
|
}
|
|
|
|
|
2012-02-11 00:10:07 +00:00
|
|
|
class ShowCloseShowWidget : public QWidget
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
2019-05-10 09:08:11 +00:00
|
|
|
explicit ShowCloseShowWidget(bool showAgain, QWidget *parent = nullptr)
|
|
|
|
: QWidget(parent), showAgain(showAgain)
|
2012-02-11 00:10:07 +00:00
|
|
|
{
|
2019-05-10 09:08:11 +00:00
|
|
|
QTimer::singleShot(0, this, &ShowCloseShowWidget::doClose);
|
|
|
|
QTimer::singleShot(500, this, [] () { QCoreApplication::exit(1); });
|
2012-02-11 00:10:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private slots:
|
|
|
|
void doClose() {
|
|
|
|
close();
|
|
|
|
if (showAgain)
|
|
|
|
show();
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2019-05-10 09:08:11 +00:00
|
|
|
const bool showAgain;
|
2012-02-11 00:10:07 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
void tst_QApplication::abortQuitOnShow()
|
|
|
|
{
|
|
|
|
int argc = 0;
|
2019-05-10 09:08:11 +00:00
|
|
|
QApplication app(argc, nullptr);
|
2016-09-28 08:49:57 +00:00
|
|
|
ShowCloseShowWidget window1(false);
|
2019-05-10 09:08:11 +00:00
|
|
|
window1.setWindowTitle(QLatin1String(QTest::currentTestFunction()));
|
2016-09-28 08:49:57 +00:00
|
|
|
window1.show();
|
2019-05-10 09:08:11 +00:00
|
|
|
QCOMPARE(QCoreApplication::exec(), 0);
|
2012-02-11 00:10:07 +00:00
|
|
|
|
2016-09-28 08:49:57 +00:00
|
|
|
ShowCloseShowWidget window2(true);
|
2019-05-10 09:08:11 +00:00
|
|
|
window2.setWindowTitle(QLatin1String(QTest::currentTestFunction()));
|
2016-09-28 08:49:57 +00:00
|
|
|
window2.show();
|
2019-05-10 09:08:11 +00:00
|
|
|
QCOMPARE(QCoreApplication::exec(), 1);
|
2012-02-11 00:10:07 +00:00
|
|
|
}
|
2011-10-26 11:29:51 +00:00
|
|
|
|
2015-02-24 08:35:56 +00:00
|
|
|
// Test that static functions do not crash if there is no application instance.
|
|
|
|
void tst_QApplication::staticFunctions()
|
|
|
|
{
|
|
|
|
QApplication::setStyle(QStringLiteral("blub"));
|
|
|
|
QApplication::allWidgets();
|
|
|
|
QApplication::topLevelWidgets();
|
|
|
|
QApplication::activePopupWidget();
|
2020-10-16 11:39:26 +00:00
|
|
|
QTest::ignoreMessage(QtWarningMsg, "Must construct a QGuiApplication first.");
|
2015-02-24 08:35:56 +00:00
|
|
|
QApplication::activeModalWidget();
|
|
|
|
QApplication::focusWidget();
|
|
|
|
QApplication::activeWindow();
|
2017-09-18 09:49:52 +00:00
|
|
|
QApplication::setActiveWindow(nullptr);
|
2015-02-24 08:35:56 +00:00
|
|
|
QApplication::widgetAt(QPoint(0, 0));
|
|
|
|
QApplication::topLevelAt(QPoint(0, 0));
|
2020-10-16 11:39:26 +00:00
|
|
|
QTest::ignoreMessage(QtWarningMsg, "Must construct a QApplication first.");
|
2015-02-24 08:35:56 +00:00
|
|
|
QApplication::isEffectEnabled(Qt::UI_General);
|
|
|
|
QApplication::setEffectEnabled(Qt::UI_General, false);
|
|
|
|
}
|
|
|
|
|
2015-02-23 16:01:24 +00:00
|
|
|
void tst_QApplication::settableStyleHints_data()
|
|
|
|
{
|
|
|
|
QTest::addColumn<bool>("appInstance");
|
|
|
|
QTest::newRow("app") << true;
|
|
|
|
QTest::newRow("no-app") << false;
|
|
|
|
}
|
|
|
|
|
2013-10-15 12:12:34 +00:00
|
|
|
void tst_QApplication::settableStyleHints()
|
|
|
|
{
|
2015-02-23 16:01:24 +00:00
|
|
|
QFETCH(bool, appInstance);
|
2013-10-15 12:12:34 +00:00
|
|
|
int argc = 0;
|
2015-02-23 16:01:24 +00:00
|
|
|
QScopedPointer<QApplication> app;
|
|
|
|
if (appInstance)
|
2019-05-10 09:08:11 +00:00
|
|
|
app.reset(new QApplication(argc, nullptr));
|
2015-02-23 16:01:24 +00:00
|
|
|
|
2013-10-15 12:12:34 +00:00
|
|
|
QApplication::setCursorFlashTime(437);
|
|
|
|
QCOMPARE(QApplication::cursorFlashTime(), 437);
|
|
|
|
QApplication::setDoubleClickInterval(128);
|
|
|
|
QCOMPARE(QApplication::doubleClickInterval(), 128);
|
|
|
|
QApplication::setStartDragDistance(122000);
|
|
|
|
QCOMPARE(QApplication::startDragDistance(), 122000);
|
|
|
|
QApplication::setStartDragTime(834);
|
|
|
|
QCOMPARE(QApplication::startDragTime(), 834);
|
|
|
|
QApplication::setKeyboardInputInterval(309);
|
|
|
|
QCOMPARE(QApplication::keyboardInputInterval(), 309);
|
|
|
|
}
|
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
/*
|
|
|
|
This test is meant to ensure that certain objects (public & commonly used)
|
|
|
|
can safely be used in a Q_GLOBAL_STATIC such that their destructors are
|
|
|
|
executed *after* the destruction of QApplication.
|
|
|
|
*/
|
|
|
|
Q_GLOBAL_STATIC(QLocale, tst_qapp_locale);
|
2016-11-23 11:25:17 +00:00
|
|
|
#if QT_CONFIG(process)
|
2011-04-27 10:05:43 +00:00
|
|
|
Q_GLOBAL_STATIC(QProcess, tst_qapp_process);
|
2013-01-16 12:34:35 +00:00
|
|
|
#endif
|
2018-09-26 06:56:36 +00:00
|
|
|
#if QT_CONFIG(filesystemwatcher)
|
2011-04-27 10:05:43 +00:00
|
|
|
Q_GLOBAL_STATIC(QFileSystemWatcher, tst_qapp_fileSystemWatcher);
|
2013-11-07 08:50:44 +00:00
|
|
|
#endif
|
2012-03-09 11:56:41 +00:00
|
|
|
#ifndef QT_NO_SHAREDMEMORY
|
2011-04-27 10:05:43 +00:00
|
|
|
Q_GLOBAL_STATIC(QSharedMemory, tst_qapp_sharedMemory);
|
2012-03-09 11:56:41 +00:00
|
|
|
#endif
|
2011-04-27 10:05:43 +00:00
|
|
|
Q_GLOBAL_STATIC(QElapsedTimer, tst_qapp_elapsedTimer);
|
|
|
|
Q_GLOBAL_STATIC(QMutex, tst_qapp_mutex);
|
|
|
|
Q_GLOBAL_STATIC(QWidget, tst_qapp_widget);
|
|
|
|
Q_GLOBAL_STATIC(QPixmap, tst_qapp_pixmap);
|
|
|
|
Q_GLOBAL_STATIC(QFont, tst_qapp_font);
|
|
|
|
Q_GLOBAL_STATIC(QRegion, tst_qapp_region);
|
2016-04-11 08:56:36 +00:00
|
|
|
#ifndef QT_NO_CURSOR
|
2011-04-27 10:05:43 +00:00
|
|
|
Q_GLOBAL_STATIC(QCursor, tst_qapp_cursor);
|
2012-09-20 13:35:21 +00:00
|
|
|
#endif
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
void tst_QApplication::globalStaticObjectDestruction()
|
|
|
|
{
|
|
|
|
int argc = 1;
|
2012-11-23 14:02:46 +00:00
|
|
|
QApplication app(argc, &argv0);
|
2011-04-27 10:05:43 +00:00
|
|
|
QVERIFY(tst_qapp_locale());
|
2016-11-23 11:25:17 +00:00
|
|
|
#if QT_CONFIG(process)
|
2011-04-27 10:05:43 +00:00
|
|
|
QVERIFY(tst_qapp_process());
|
2013-01-16 12:34:35 +00:00
|
|
|
#endif
|
2018-09-26 06:56:36 +00:00
|
|
|
#if QT_CONFIG(filesystemwatcher)
|
2011-04-27 10:05:43 +00:00
|
|
|
QVERIFY(tst_qapp_fileSystemWatcher());
|
2013-11-07 08:50:44 +00:00
|
|
|
#endif
|
2012-03-09 11:56:41 +00:00
|
|
|
#ifndef QT_NO_SHAREDMEMORY
|
2011-04-27 10:05:43 +00:00
|
|
|
QVERIFY(tst_qapp_sharedMemory());
|
2012-03-09 11:56:41 +00:00
|
|
|
#endif
|
2011-04-27 10:05:43 +00:00
|
|
|
QVERIFY(tst_qapp_elapsedTimer());
|
|
|
|
QVERIFY(tst_qapp_mutex());
|
|
|
|
QVERIFY(tst_qapp_widget());
|
|
|
|
QVERIFY(tst_qapp_pixmap());
|
|
|
|
QVERIFY(tst_qapp_font());
|
|
|
|
QVERIFY(tst_qapp_region());
|
2016-04-11 08:56:36 +00:00
|
|
|
#ifndef QT_NO_CURSOR
|
2011-04-27 10:05:43 +00:00
|
|
|
QVERIFY(tst_qapp_cursor());
|
2012-09-20 13:35:21 +00:00
|
|
|
#endif
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//QTEST_APPLESS_MAIN(tst_QApplication)
|
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
tst_QApplication tc;
|
|
|
|
argv0 = argv[0];
|
2020-10-30 15:03:47 +00:00
|
|
|
QTEST_SET_MAIN_SOURCE_PATH
|
2011-04-27 10:05:43 +00:00
|
|
|
return QTest::qExec(&tc, argc, argv);
|
|
|
|
}
|
|
|
|
|
|
|
|
#include "tst_qapplication.moc"
|