summaryrefslogtreecommitdiffstats
path: root/src/plugins/platforms/cocoa/qcocoahelpers.h
diff options
context:
space:
mode:
authorGabriel de Dietrich <gabriel.dedietrich@qt.io>2018-04-19 14:39:54 -0700
committerGabriel de Dietrich <gabriel.dedietrich@qt.io>2018-04-20 17:45:23 +0000
commitf35f282c4f0ef11dc35bc9120852ff9e77f85297 (patch)
tree6203befe295a22bb927c5526fcd0cf8dbba4b83f /src/plugins/platforms/cocoa/qcocoahelpers.h
parent2b40af71770e3c330cf5fd028c8c4fd2ec724eb2 (diff)
Cocoa Helpers: Add qt_objc_cast() function
This generalizes what qnsview_cast() does to any Objective-C class. Notice that this is a loose cast, using isKindOfClass: instead of isMemberOfClass:. Change-Id: I745f548e474f2f9eef89f370d7d45496f0c51434 Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Diffstat (limited to 'src/plugins/platforms/cocoa/qcocoahelpers.h')
-rw-r--r--src/plugins/platforms/cocoa/qcocoahelpers.h10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/plugins/platforms/cocoa/qcocoahelpers.h b/src/plugins/platforms/cocoa/qcocoahelpers.h
index 1bead3304a..516eac0503 100644
--- a/src/plugins/platforms/cocoa/qcocoahelpers.h
+++ b/src/plugins/platforms/cocoa/qcocoahelpers.h
@@ -78,6 +78,16 @@ NSDragOperation qt_mac_mapDropActions(Qt::DropActions actions);
Qt::DropAction qt_mac_mapNSDragOperation(NSDragOperation nsActions);
Qt::DropActions qt_mac_mapNSDragOperations(NSDragOperation nsActions);
+template <typename T>
+typename std::enable_if<std::is_pointer<T>::value, T>::type
+qt_objc_cast(id object)
+{
+ if ([object isKindOfClass:[typename std::remove_pointer<T>::type class]])
+ return static_cast<T>(object);
+
+ return nil;
+}
+
QT_MANGLE_NAMESPACE(QNSView) *qnsview_cast(NSView *view);
// Misc