Make QApplication::type() set by QGuiApplication.
authorFrederik Gladhorn <frederik.gladhorn@nokia.com>
Mon, 12 Dec 2011 13:12:15 +0000 (14:12 +0100)
committerQt by Nokia <qt-info@nokia.com>
Mon, 12 Dec 2011 16:28:24 +0000 (17:28 +0100)
QApplication::type used to be static and set by the
QApplicationPrivate constructors.

In QCoreApplication we have the new application_type that should take its place.
QApplication::GuiServer is deprecated (since it doesn't have any functionallity
any more with QWS being removed).

This change prepares QStyle to be called from a QQuickCanvase based application
that does not inherit the QWidget version of QApplication.

Change-Id: Ifbe992e25f1e5821fa047b6eb915f75fa675ab97
Reviewed-by: Paul Olav Tvete <paul.tvete@nokia.com>
src/corelib/kernel/qcoreapplication.cpp
src/corelib/kernel/qcoreapplication.h
src/gui/kernel/qguiapplication.cpp
src/widgets/kernel/qapplication.cpp
src/widgets/kernel/qapplication.h

index 7ff82b1..7523963 100644 (file)
@@ -2587,6 +2587,14 @@ void QCoreApplication::setEventDispatcher(QAbstractEventDispatcher *eventDispatc
     \sa Q_OBJECT, QObject::tr(), QObject::trUtf8()
 */
 
+/*!
+    \enum QCoreApplication::Type
+
+    \value Tty a console application
+    \value GuiClient a GUI application
+    \value GuiServer \e{Deprecated.} this value is only left for compatibility.
+*/
+
 QT_END_NAMESPACE
 
 #include "moc_qcoreapplication.cpp"
index 3d6aa17..0135d88 100644 (file)
@@ -78,6 +78,12 @@ public:
     enum { ApplicationFlags = QT_VERSION
     };
 
+    enum Type {
+        Tty,
+        GuiClient,
+        GuiServer // # deprecated
+    };
+
     QCoreApplication(int &argc, char **argv, int = ApplicationFlags);
 
     ~QCoreApplication();
index 28ce2e5..dc8e5ed 100644 (file)
@@ -186,6 +186,7 @@ QGuiApplicationPrivate::QGuiApplicationPrivate(int &argc, char **argv, int flags
       inputPanel(0)
 {
     self = this;
+    application_type = QCoreApplication::GuiClient;
 }
 
 QWindow *QGuiApplication::focusWindow()
index c94c48e..4c4cb40 100644 (file)
@@ -139,7 +139,6 @@ QT_BEGIN_NAMESPACE
 
 Q_CORE_EXPORT void qt_call_post_routines();
 
-QApplication::Type qt_appType=QApplication::Tty;
 QApplicationPrivate *QApplicationPrivate::self = 0;
 
 QInputContext *QApplicationPrivate::inputContext = 0;
@@ -157,7 +156,6 @@ QApplicationPrivate::QApplicationPrivate(int &argc, char **argv, QApplication::T
     : QApplicationPrivateBase(argc, argv, flags)
 {
     application_type = type;
-    qt_appType = type;
 
 #ifndef QT_NO_SESSIONMANAGER
     is_session_restored = false;
@@ -366,14 +364,6 @@ QApplicationPrivate::~QApplicationPrivate()
 */
 
 /*!
-    \enum QApplication::Type
-
-    \value Tty a console application
-    \value GuiClient a GUI client application
-    \value GuiServer a GUI server application (for Qt for Embedded Linux)
-*/
-
-/*!
     \enum QApplication::ColorSpec
 
     \value NormalColor the default color allocation policy
@@ -743,11 +733,11 @@ void QApplicationPrivate::construct(
 {
     initResources();
 
-    qt_is_gui_used = (qt_appType != QApplication::Tty);
+    qt_is_gui_used = (application_type != QApplication::Tty);
     process_cmdline();
 
     // Must be called before initialize()
-    qt_init(this, qt_appType
+    qt_init(this, application_type
 #ifdef Q_WS_X11
             , dpy, visual, cmap
 #endif
@@ -873,7 +863,7 @@ void QApplicationPrivate::initialize()
     QWidgetPrivate::mapper = new QWidgetMapper;
     QWidgetPrivate::allWidgets = new QWidgetSet;
 
-    if (qt_appType != QApplication::Tty)
+    if (application_type != QApplication::Tty)
         (void) QApplication::style();  // trigger creation of application style
 #ifndef QT_NO_STATEMACHINE
     // trigger registering of QStateMachine's GUI types
@@ -917,7 +907,9 @@ void QApplicationPrivate::initialize()
 */
 QApplication::Type QApplication::type()
 {
-    return qt_appType;
+    if (QApplicationPrivate::instance())
+        return (QCoreApplication::Type)QApplicationPrivate::instance()->application_type;
+    return Tty;
 }
 
 /*****************************************************************************
@@ -1275,7 +1267,7 @@ QStyle *QApplication::style()
 {
     if (QApplicationPrivate::app_style)
         return QApplicationPrivate::app_style;
-    if (!qt_is_gui_used) {
+    if (qApp->type() == QApplication::Tty) {
         Q_ASSERT(!"No style available in non-gui applications!");
         return 0;
     }
index 1792d2f..4883ece 100644 (file)
@@ -98,7 +98,6 @@ class Q_WIDGETS_EXPORT QApplication : public QGuiApplication
     Q_PROPERTY(bool autoSipEnabled READ autoSipEnabled WRITE setAutoSipEnabled)
 
 public:
-    enum Type { Tty, GuiClient, GuiServer };
 
 #ifndef qdoc
     QApplication(int &argc, char **argv, int = ApplicationFlags);