diff options
author | Tor Arne Vestbø <tor.arne.vestbo@qt.io> | 2016-10-05 21:56:58 +0200 |
---|---|---|
committer | Tor Arne Vestbø <tor.arne.vestbo@qt.io> | 2016-10-10 16:06:41 +0000 |
commit | f835b5aa9cba2665423e6e96a45d97c3c80296a5 (patch) | |
tree | 32f35432d9046302b799cb55a067195059e40580 /src/plugins/platforms/cocoa/qcocoahelpers.mm | |
parent | 1df4b2a3609d977cc8123f1f82e454d0333287d4 (diff) |
macOS: Get rid of m_qtView member in QCocoaWindow that aliased m_view
The member was mirroring m_view in all cases except for foreign windows.
Instead of a member we now check window()->type() != Qt::ForeignWindow,
which is more explicit, especially for people not normally working on
the macOS platform.
To call methods that are only implemented for our QNSView subclass,
a new qnsview_cast() function has been introduced.
Change-Id: I0a2cfe1a5e4502250c17e1c3ebdce19e9ee5e572
Reviewed-by: Erik Verbruggen <erik.verbruggen@qt.io>
Diffstat (limited to 'src/plugins/platforms/cocoa/qcocoahelpers.mm')
-rw-r--r-- | src/plugins/platforms/cocoa/qcocoahelpers.mm | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/src/plugins/platforms/cocoa/qcocoahelpers.mm b/src/plugins/platforms/cocoa/qcocoahelpers.mm index 1dee11678e..c57567bdd6 100644 --- a/src/plugins/platforms/cocoa/qcocoahelpers.mm +++ b/src/plugins/platforms/cocoa/qcocoahelpers.mm @@ -40,7 +40,7 @@ #include <qpa/qplatformtheme.h> #include "qcocoahelpers.h" - +#include "qnsview.h" #include <QtCore> #include <QtGui> @@ -143,7 +143,30 @@ Qt::DropActions qt_mac_mapNSDragOperations(NSDragOperation nsActions) return actions; } +/*! + Returns the view cast to a QNSview if possible. + + If the view is not a QNSView, nil is returned, which is safe to + send messages to, effectivly making [qnsview_cast(view) message] + a no-op. + For extra verbosity and clearer code, please consider checking + that window()->type() != Qt::ForeignWindow before using this cast. + + Do not use this method soley to check for foreign windows, as + that will make the code harder to read for people not working + primarily on macOS, who do not know the difference between the + NSView and QNSView cases. +*/ +QNSView *qnsview_cast(NSView *view) +{ + if (![view isKindOfClass:[QNSView class]]) { + qCWarning(lcQpaCocoaWindow) << "NSView is not QNSView, consider checking for Qt::ForeignWindow"; + return nil; + } + + return static_cast<QNSView *>(view); +} // // Misc |