Rename QMacScopedObserver to the more fittingly QMacNotificationObserver

Change-Id: I1d8280fe88871572a3a27e612de49717b3b9ef77
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
This commit is contained in:
Tor Arne Vestbø 2019-05-27 18:36:13 +02:00
parent c3571d2922
commit a67b25067e
5 changed files with 15 additions and 15 deletions

View File

@ -295,13 +295,13 @@ QT_MAC_WEAK_IMPORT(_os_activity_current);
// -------------------------------------------------------------------------
#if defined( __OBJC__)
class QMacScopedObserver
class QMacNotificationObserver
{
public:
QMacScopedObserver() {}
QMacNotificationObserver() {}
template<typename Functor>
QMacScopedObserver(id object, NSNotificationName name, Functor callback) {
QMacNotificationObserver(id object, NSNotificationName name, Functor callback) {
observer = [[NSNotificationCenter defaultCenter] addObserverForName:name
object:object queue:nil usingBlock:^(NSNotification *) {
callback();
@ -309,13 +309,13 @@ public:
];
}
QMacScopedObserver(const QMacScopedObserver& other) = delete;
QMacScopedObserver(QMacScopedObserver&& other) : observer(other.observer) {
QMacNotificationObserver(const QMacNotificationObserver& other) = delete;
QMacNotificationObserver(QMacNotificationObserver&& other) : observer(other.observer) {
other.observer = nil;
}
QMacScopedObserver &operator=(const QMacScopedObserver& other) = delete;
QMacScopedObserver &operator=(QMacScopedObserver&& other) {
QMacNotificationObserver &operator=(const QMacNotificationObserver& other) = delete;
QMacNotificationObserver &operator=(QMacNotificationObserver&& other) {
if (this != &other) {
remove();
observer = other.observer;
@ -329,7 +329,7 @@ public:
[[NSNotificationCenter defaultCenter] removeObserver:observer];
observer = nil;
}
~QMacScopedObserver() { remove(); }
~QMacNotificationObserver() { remove(); }
private:
id observer = nil;

View File

@ -80,7 +80,7 @@ private:
NSOpenGLContext *m_shareContext = nil;
QSurfaceFormat m_format;
bool m_didCheckForSoftwareContext = false;
QVarLengthArray<QMacScopedObserver, 3> m_updateObservers;
QVarLengthArray<QMacNotificationObserver, 3> m_updateObservers;
QAtomicInt m_needsUpdate = false;
};

View File

@ -404,13 +404,13 @@ bool QCocoaGLContext::setDrawable(QPlatformSurface *surface)
m_updateObservers.clear();
if (view.layer) {
m_updateObservers.append(QMacScopedObserver(view, NSViewFrameDidChangeNotification, updateCallback));
m_updateObservers.append(QMacScopedObserver(view.window, NSWindowDidChangeScreenNotification, updateCallback));
m_updateObservers.append(QMacNotificationObserver(view, NSViewFrameDidChangeNotification, updateCallback));
m_updateObservers.append(QMacNotificationObserver(view.window, NSWindowDidChangeScreenNotification, updateCallback));
} else {
m_updateObservers.append(QMacScopedObserver(view, NSViewGlobalFrameDidChangeNotification, updateCallback));
m_updateObservers.append(QMacNotificationObserver(view, NSViewGlobalFrameDidChangeNotification, updateCallback));
}
m_updateObservers.append(QMacScopedObserver([NSApplication sharedApplication],
m_updateObservers.append(QMacNotificationObserver([NSApplication sharedApplication],
NSApplicationDidChangeScreenParametersNotification, updateCallback));
// If any of the observers fire at this point it's fine. We check the

View File

@ -144,7 +144,7 @@ private:
#endif
QScopedPointer<QPlatformTheme> mPlatformTheme;
QList<QCocoaScreen *> mScreens;
QMacScopedObserver m_screensObserver;
QMacNotificationObserver m_screensObserver;
#ifndef QT_NO_CLIPBOARD
QCocoaClipboard *mCocoaClipboard;
#endif

View File

@ -207,7 +207,7 @@ QCocoaIntegration::QCocoaIntegration(const QStringList &paramList)
// which will resolve to an actual value and result in screen invalidation.
cocoaApplication.presentationOptions = NSApplicationPresentationDefault;
m_screensObserver = QMacScopedObserver([NSApplication sharedApplication],
m_screensObserver = QMacNotificationObserver([NSApplication sharedApplication],
NSApplicationDidChangeScreenParametersNotification, [&]() { updateScreens(); });
updateScreens();