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

View File

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

View File

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

View File

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

View File

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