fix QWidget::setWindowFilePath on Mac OS
authorJoerg Bornemann <joerg.bornemann@digia.com>
Mon, 1 Oct 2012 10:56:28 +0000 (12:56 +0200)
committerThe Qt Project <gerrit-noreply@qt-project.org>
Tue, 2 Oct 2012 06:06:24 +0000 (08:06 +0200)
Task-number: QTBUG-27299

Change-Id: I4dddbb9690aac327ad33477d8cea9afa84d10eb3
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@digia.com>
Reviewed-by: Morten Johan Sørvig <morten.sorvig@digia.com>
src/plugins/platforms/cocoa/qcocoawindow.h
src/plugins/platforms/cocoa/qcocoawindow.mm
src/widgets/kernel/qwidget.cpp
src/widgets/kernel/qwidget_p.h
src/widgets/kernel/qwidget_qpa.cpp

index 5358a39..20648e8 100644 (file)
@@ -101,6 +101,7 @@ public:
     Qt::WindowFlags setWindowFlags(Qt::WindowFlags flags);
     Qt::WindowState setWindowState(Qt::WindowState state);
     void setWindowTitle(const QString &title);
+    void setWindowFilePath(const QString &filePath);
     void raise();
     void lower();
     void propagateSizeHints();
index 7cebf51..daed7c3 100644 (file)
@@ -45,6 +45,7 @@
 #include "qcocoaglcontext.h"
 #include "qcocoahelpers.h"
 #include "qnsview.h"
+#include <QtCore/qfileinfo.h>
 #include <QtCore/private/qcore_mac_p.h>
 #include <qwindow.h>
 #include <qpa/qwindowsysteminterface.h>
@@ -409,6 +410,16 @@ void QCocoaWindow::setWindowTitle(const QString &title)
     CFRelease(windowTitle);
 }
 
+void QCocoaWindow::setWindowFilePath(const QString &filePath)
+{
+    QCocoaAutoReleasePool pool;
+    if (!m_nsWindow)
+        return;
+
+    QFileInfo fi(filePath);
+    [m_nsWindow setRepresentedFilename: fi.exists() ? QCFString::toNSString(filePath) : @""];
+}
+
 void QCocoaWindow::raise()
 {
     //qDebug() << "raise" << this;
index 84bb5a6..ffcaa15 100644 (file)
@@ -5725,7 +5725,7 @@ void QWidget::setWindowFilePath(const QString &filePath)
 void QWidgetPrivate::setWindowFilePath_helper(const QString &filePath)
 {
     if (extra->topextra && extra->topextra->caption.isEmpty()) {
-#ifdef Q_WS_MAC
+#ifdef Q_OS_MAC
         setWindowTitle_helper(QFileInfo(filePath).fileName());
 #else
         Q_Q(QWidget);
@@ -5733,7 +5733,7 @@ void QWidgetPrivate::setWindowFilePath_helper(const QString &filePath)
         setWindowTitle_helper(q->windowTitle());
 #endif
     }
-#ifdef Q_WS_MAC
+#ifdef Q_OS_MAC
     setWindowFilePath_sys(filePath);
 #endif
 }
index 84785da..eb67f75 100644 (file)
@@ -477,6 +477,7 @@ public:
     void setWindowIconText_sys(const QString &cap);
     void setWindowIconText_helper(const QString &cap);
     void setWindowTitle_sys(const QString &cap);
+    void setWindowFilePath_sys(const QString &filePath);
 
 #ifndef QT_NO_CURSOR
     void setCursor_sys(const QCursor &cursor);
@@ -766,7 +767,6 @@ public:
     void update_sys(const QRegion &rgn);
     void setGeometry_sys_helper(int, int, int, int, bool);
     void updateMaximizeButton_sys();
-    void setWindowFilePath_sys(const QString &filePath);
     void createWindow_sys();
     void recreateMacWindow();
     void setSubWindowStacking(bool set);
index 7c84c7f..c6680ea 100644 (file)
@@ -346,6 +346,16 @@ void QWidgetPrivate::setWindowTitle_sys(const QString &caption)
 
 }
 
+void QWidgetPrivate::setWindowFilePath_sys(const QString &filePath)
+{
+    Q_Q(QWidget);
+    if (!q->isWindow())
+        return;
+
+    if (QWindow *window = q->windowHandle())
+        window->setWindowFilePath(filePath);
+}
+
 void QWidgetPrivate::setWindowIcon_sys()
 {
     Q_Q(QWidget);