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:
Tor Arne Vestbø 2013-11-18 11:32:32 +01:00 committed by The Qt Project
parent 49a3fe0cf8
commit 837228151d
7 changed files with 20 additions and 20 deletions

View File

@ -47,6 +47,5 @@
@interface QIOSApplicationDelegate : UIResponder <UIApplicationDelegate>
@property (strong, nonatomic) UIWindow *window;
@property (strong, nonatomic) QIOSViewController *qiosViewController;
@end

View File

@ -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];
}

View File

@ -52,7 +52,6 @@ QT_BEGIN_NAMESPACE
class QPlatformScreen;
bool isQtApplication();
QIOSViewController *qiosViewController();
CGRect toCGRect(const QRect &rect);
QRect fromCGRect(const CGRect &rect);

View File

@ -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());

View File

@ -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)));
}
}

View File

@ -52,6 +52,7 @@ class QIOSWindow;
@interface UIView (QIOS)
@property(readonly) QWindow *qwindow;
@property(readonly) UIViewController *viewController;
@end
QT_BEGIN_NAMESPACE

View File

@ -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;
}
}
}
}