Add QGuiApplication::setApplicationDisplayName.
authorDavid Faure <faure@kde.org>
Sat, 23 Jun 2012 12:08:25 +0000 (14:08 +0200)
committerQt by Nokia <qt-info@nokia.com>
Wed, 27 Jun 2012 07:23:15 +0000 (09:23 +0200)
This is for use in window titles.

Change-Id: I0070a08abd379ae2edcfab4413c182bd9e840678
Reviewed-by: Gunnar Sletta <gunnar.sletta@nokia.com>
src/gui/kernel/qguiapplication.cpp
src/gui/kernel/qguiapplication.h
src/gui/kernel/qguiapplication_p.h
tests/auto/gui/kernel/qguiapplication/tst_qguiapplication.cpp

index dbee892..a3d9c1f 100644 (file)
@@ -119,6 +119,7 @@ enum ApplicationResourceFlags
 static unsigned applicationResourceFlags = 0;
 
 QString *QGuiApplicationPrivate::platform_name = 0;
+QString *QGuiApplicationPrivate::displayName = 0;
 
 QPalette *QGuiApplicationPrivate::app_pal = 0;        // default application palette
 
@@ -369,6 +370,8 @@ QGuiApplication::~QGuiApplication()
 
     delete QGuiApplicationPrivate::platform_name;
     QGuiApplicationPrivate::platform_name = 0;
+    delete QGuiApplicationPrivate::displayName;
+    QGuiApplicationPrivate::displayName = 0;
 }
 
 QGuiApplicationPrivate::QGuiApplicationPrivate(int &argc, char **argv, int flags)
@@ -382,6 +385,30 @@ QGuiApplicationPrivate::QGuiApplicationPrivate(int &argc, char **argv, int flags
 }
 
 /*!
+    \property QGuiApplication::applicationDisplayName
+    \brief the user-visible name of this application
+    \since 5.0
+
+    This name is shown to the user, for instance in window titles.
+    It can be translated, if necessary.
+
+    If not set, the application display name defaults to the application name.
+
+    \sa applicationName
+*/
+void QGuiApplication::setApplicationDisplayName(const QString &name)
+{
+    if (!QGuiApplicationPrivate::displayName)
+        QGuiApplicationPrivate::displayName = new QString;
+    *QGuiApplicationPrivate::displayName = name;
+}
+
+QString QGuiApplication::applicationDisplayName()
+{
+    return QGuiApplicationPrivate::displayName ? *QGuiApplicationPrivate::displayName : applicationName();
+}
+
+/*!
     Returns the most recently shown modal window. If no modal windows are
     visible, this function returns zero.
 
index a366826..b84d731 100644 (file)
@@ -74,6 +74,7 @@ class QStyleHints;
 class Q_GUI_EXPORT QGuiApplication : public QCoreApplication
 {
     Q_OBJECT
+    Q_PROPERTY(QString applicationDisplayName READ applicationDisplayName WRITE setApplicationDisplayName)
     Q_PROPERTY(Qt::LayoutDirection layoutDirection READ layoutDirection WRITE setLayoutDirection)
     Q_PROPERTY(QString platformName READ platformName STORED false)
     Q_PROPERTY(bool quitOnLastWindowClosed  READ quitOnLastWindowClosed WRITE setQuitOnLastWindowClosed)
@@ -82,6 +83,9 @@ public:
     QGuiApplication(int &argc, char **argv, int = ApplicationFlags);
     virtual ~QGuiApplication();
 
+    static void setApplicationDisplayName(const QString &name);
+    static QString applicationDisplayName();
+
     static QWindowList allWindows();
     static QWindowList topLevelWindows();
     static QWindow *topLevelAt(const QPoint &pos);
index a564120..a9fe118 100644 (file)
@@ -164,6 +164,7 @@ public:
     static QGuiApplicationPrivate *instance() { return self; }
 
     static QString *platform_name;
+    static QString *displayName;
 
     QWindowList modalWindowList;
     static void showModalWindow(QWindow *window);
index 372dd65..dda810a 100644 (file)
@@ -50,6 +50,7 @@ class tst_QGuiApplication: public QObject
     Q_OBJECT
 
 private slots:
+    void displayName();
     void focusObject();
     void allWindows();
     void topLevelWindows();
@@ -60,6 +61,18 @@ private slots:
     void quitOnLastWindowClosed();
 };
 
+void tst_QGuiApplication::displayName()
+{
+    int argc = 1;
+    char *argv[] = { const_cast<char*>("tst_qguiapplication") };
+    QGuiApplication app(argc, argv);
+    QCOMPARE(::qAppName(), QString::fromLatin1("tst_qguiapplication"));
+    QCOMPARE(QGuiApplication::applicationName(), QString::fromLatin1("tst_qguiapplication"));
+    QCOMPARE(QGuiApplication::applicationDisplayName(), QString::fromLatin1("tst_qguiapplication"));
+    QGuiApplication::setApplicationDisplayName("The GUI Application");
+    QCOMPARE(QGuiApplication::applicationDisplayName(), QString::fromLatin1("The GUI Application"));
+}
+
 class DummyWindow : public QWindow
 {
 public: