iOS: Don't keep around reference to a single QIOSViewController
We might have more of them in a multi-screen setup or when implementing support for modal windows using sub-viewcontrollers. Change-Id: Ibe98273a13af981fffe2704a2c05bfd9d3f3e9e0 Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@digia.com>
This commit is contained in:
parent
49a3fe0cf8
commit
837228151d
@ -47,6 +47,5 @@
|
||||
@interface QIOSApplicationDelegate : UIResponder <UIApplicationDelegate>
|
||||
|
||||
@property (strong, nonatomic) UIWindow *window;
|
||||
@property (strong, nonatomic) QIOSViewController *qiosViewController;
|
||||
|
||||
@end
|
||||
|
@ -49,7 +49,6 @@
|
||||
@implementation QIOSApplicationDelegate
|
||||
|
||||
@synthesize window;
|
||||
@synthesize qiosViewController;
|
||||
|
||||
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
|
||||
{
|
||||
@ -57,8 +56,7 @@
|
||||
Q_UNUSED(launchOptions);
|
||||
|
||||
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
|
||||
self.qiosViewController = [[[QIOSViewController alloc] init] autorelease];
|
||||
self.window.rootViewController = self.qiosViewController;
|
||||
self.window.rootViewController = [[[QIOSViewController alloc] init] autorelease];
|
||||
|
||||
self.window.hidden = NO;
|
||||
|
||||
@ -67,7 +65,6 @@
|
||||
|
||||
- (void)dealloc
|
||||
{
|
||||
[qiosViewController release];
|
||||
[window release];
|
||||
[super dealloc];
|
||||
}
|
||||
|
@ -52,7 +52,6 @@ QT_BEGIN_NAMESPACE
|
||||
class QPlatformScreen;
|
||||
|
||||
bool isQtApplication();
|
||||
QIOSViewController *qiosViewController();
|
||||
|
||||
CGRect toCGRect(const QRect &rect);
|
||||
QRect fromCGRect(const CGRect &rect);
|
||||
|
@ -58,17 +58,6 @@ bool isQtApplication()
|
||||
return isQt;
|
||||
}
|
||||
|
||||
QIOSViewController *qiosViewController()
|
||||
{
|
||||
// If Qt controls the application, we have created a root view controller were we place top-level
|
||||
// QWindows. Note that in a mixed native application, our view controller might later be removed or
|
||||
// added as a child of another controller. To protect against that, we keep an explicit pointer to the
|
||||
// view controller in cases where this is the controller we need to access.
|
||||
static QIOSViewController *c = isQtApplication() ?
|
||||
static_cast<QIOSApplicationDelegate *>([UIApplication sharedApplication].delegate).qiosViewController : nil;
|
||||
return c;
|
||||
}
|
||||
|
||||
CGRect toCGRect(const QRect &rect)
|
||||
{
|
||||
return CGRectMake(rect.x(), rect.y(), rect.width(), rect.height());
|
||||
|
@ -149,7 +149,7 @@ QIOSScreen::QIOSScreen(unsigned int screenIndex)
|
||||
|
||||
if (isQtApplication()) {
|
||||
// When in a non-mixed environment, let QScreen follow the current interface orientation:
|
||||
setPrimaryOrientation(toQtScreenOrientation(UIDeviceOrientation(qiosViewController().interfaceOrientation)));
|
||||
setPrimaryOrientation(toQtScreenOrientation(UIDeviceOrientation([UIApplication sharedApplication].statusBarOrientation)));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -52,6 +52,7 @@ class QIOSWindow;
|
||||
|
||||
@interface UIView (QIOS)
|
||||
@property(readonly) QWindow *qwindow;
|
||||
@property(readonly) UIViewController *viewController;
|
||||
@end
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
@ -348,6 +348,16 @@
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (UIViewController *)viewController
|
||||
{
|
||||
id responder = self;
|
||||
while ((responder = [responder nextResponder])) {
|
||||
if ([responder isKindOfClass:UIViewController.class])
|
||||
return responder;
|
||||
}
|
||||
return nil;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
@ -404,7 +414,7 @@ void QIOSWindow::setVisible(bool visible)
|
||||
requestActivateWindow();
|
||||
} else {
|
||||
// Activate top-most visible QWindow:
|
||||
NSArray *subviews = qiosViewController().view.subviews;
|
||||
NSArray *subviews = m_view.viewController.view.subviews;
|
||||
for (int i = int(subviews.count) - 1; i >= 0; --i) {
|
||||
UIView *view = [subviews objectAtIndex:i];
|
||||
if (!view.hidden) {
|
||||
@ -460,7 +470,12 @@ void QIOSWindow::setParent(const QPlatformWindow *parentWindow)
|
||||
UIView *parentView = reinterpret_cast<UIView *>(parentWindow->winId());
|
||||
[parentView addSubview:m_view];
|
||||
} else if (isQtApplication()) {
|
||||
[qiosViewController().view addSubview:m_view];
|
||||
for (UIWindow *uiWindow in [[UIApplication sharedApplication] windows]) {
|
||||
if (uiWindow.screen == static_cast<QIOSScreen *>(screen())->uiScreen()) {
|
||||
[uiWindow.rootViewController.view addSubview:m_view];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user