QDesktopServices: clean up pre-Qt-6.6 code
Remove the code that was already commented out by 37a25fce94976ab2a0f94abe43f1ed6ad950672f for Qt versions ≥ 6.6. Change-Id: I40a3e974430add17b52307781d092bd4f58c0c35 Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io> Reviewed-by: Juha Vuolle <juha.vuolle@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io> (cherry picked from commit bf96c45f94d840f15c71e0630f9f9c3f8ef8bc6a) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
a85c3939df
commit
e85a0951dd
@ -18,8 +18,6 @@
|
|||||||
#include <qpa/qplatformintegration.h>
|
#include <qpa/qplatformintegration.h>
|
||||||
#include <qdir.h>
|
#include <qdir.h>
|
||||||
|
|
||||||
#include <QtCore/private/qlocking_p.h>
|
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
|
|
||||||
class QOpenUrlHandlerRegistry
|
class QOpenUrlHandlerRegistry
|
||||||
@ -36,36 +34,10 @@ public:
|
|||||||
};
|
};
|
||||||
typedef QHash<QString, Handler> HandlerHash;
|
typedef QHash<QString, Handler> HandlerHash;
|
||||||
HandlerHash handlers;
|
HandlerHash handlers;
|
||||||
|
|
||||||
#if QT_VERSION < QT_VERSION_CHECK(6, 6, 0)
|
|
||||||
QObject context;
|
|
||||||
|
|
||||||
void handlerDestroyed(QObject *handler);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Q_GLOBAL_STATIC(QOpenUrlHandlerRegistry, handlerRegistry)
|
Q_GLOBAL_STATIC(QOpenUrlHandlerRegistry, handlerRegistry)
|
||||||
|
|
||||||
#if QT_VERSION < QT_VERSION_CHECK(6, 6, 0)
|
|
||||||
void QOpenUrlHandlerRegistry::handlerDestroyed(QObject *handler)
|
|
||||||
{
|
|
||||||
const auto lock = qt_scoped_lock(mutex);
|
|
||||||
HandlerHash::Iterator it = handlers.begin();
|
|
||||||
while (it != handlers.end()) {
|
|
||||||
if (it->receiver == handler) {
|
|
||||||
it = handlers.erase(it);
|
|
||||||
qWarning("Please call QDesktopServices::unsetUrlHandler() before destroying a "
|
|
||||||
"registered URL handler object.\n"
|
|
||||||
"Support for destroying a registered URL handler object is deprecated, "
|
|
||||||
"and will be removed in Qt 6.6.");
|
|
||||||
} else {
|
|
||||||
++it;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\class QDesktopServices
|
\class QDesktopServices
|
||||||
\brief The QDesktopServices class provides methods for accessing common desktop services.
|
\brief The QDesktopServices class provides methods for accessing common desktop services.
|
||||||
@ -306,11 +278,6 @@ void QDesktopServices::setUrlHandler(const QString &scheme, QObject *receiver, c
|
|||||||
h.receiver = receiver;
|
h.receiver = receiver;
|
||||||
h.name = method;
|
h.name = method;
|
||||||
registry->handlers.insert(scheme.toLower(), h);
|
registry->handlers.insert(scheme.toLower(), h);
|
||||||
#if QT_VERSION < QT_VERSION_CHECK(6, 6, 0)
|
|
||||||
QObject::connect(receiver, &QObject::destroyed, ®istry->context,
|
|
||||||
[registry](QObject *obj) { registry->handlerDestroyed(obj); },
|
|
||||||
Qt::DirectConnection);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
@ -42,10 +42,6 @@ public slots:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
#if QT_VERSION < QT_VERSION_CHECK(6, 6, 0)
|
|
||||||
# define CAN_IMPLICITLY_UNSET
|
|
||||||
#endif
|
|
||||||
|
|
||||||
void tst_qdesktopservices::handlers()
|
void tst_qdesktopservices::handlers()
|
||||||
{
|
{
|
||||||
MyUrlHandler fooHandler;
|
MyUrlHandler fooHandler;
|
||||||
@ -53,12 +49,10 @@ void tst_qdesktopservices::handlers()
|
|||||||
|
|
||||||
QDesktopServices::setUrlHandler(QString("foo"), &fooHandler, "handle");
|
QDesktopServices::setUrlHandler(QString("foo"), &fooHandler, "handle");
|
||||||
QDesktopServices::setUrlHandler(QString("bar"), &barHandler, "handle");
|
QDesktopServices::setUrlHandler(QString("bar"), &barHandler, "handle");
|
||||||
#ifndef CAN_IMPLICITLY_UNSET
|
|
||||||
const auto unsetHandlers = qScopeGuard([] {
|
const auto unsetHandlers = qScopeGuard([] {
|
||||||
QDesktopServices::unsetUrlHandler(u"bar"_s);
|
QDesktopServices::unsetUrlHandler(u"bar"_s);
|
||||||
QDesktopServices::unsetUrlHandler(u"foo"_s);
|
QDesktopServices::unsetUrlHandler(u"foo"_s);
|
||||||
});
|
});
|
||||||
#endif
|
|
||||||
|
|
||||||
QUrl fooUrl("foo://blub/meh");
|
QUrl fooUrl("foo://blub/meh");
|
||||||
QUrl barUrl("bar://hmm/hmmmm");
|
QUrl barUrl("bar://hmm/hmmmm");
|
||||||
@ -68,15 +62,6 @@ void tst_qdesktopservices::handlers()
|
|||||||
|
|
||||||
QCOMPARE(fooHandler.lastHandledUrl.toString(), fooUrl.toString());
|
QCOMPARE(fooHandler.lastHandledUrl.toString(), fooUrl.toString());
|
||||||
QCOMPARE(barHandler.lastHandledUrl.toString(), barUrl.toString());
|
QCOMPARE(barHandler.lastHandledUrl.toString(), barUrl.toString());
|
||||||
|
|
||||||
#ifdef CAN_IMPLICITLY_UNSET
|
|
||||||
for (int i = 0; i < 2; ++i)
|
|
||||||
QTest::ignoreMessage(QtWarningMsg,
|
|
||||||
"Please call QDesktopServices::unsetUrlHandler() before destroying a "
|
|
||||||
"registered URL handler object.\n"
|
|
||||||
"Support for destroying a registered URL handler object is deprecated, "
|
|
||||||
"and will be removed in Qt 6.6.");
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QTEST_MAIN(tst_qdesktopservices)
|
QTEST_MAIN(tst_qdesktopservices)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user