Remove QApplication::type() and make QCoreApplication::Type internal
authorJ-P Nurmi <jpnurmi@digia.com>
Thu, 22 Nov 2012 13:29:07 +0000 (14:29 +0100)
committerThe Qt Project <gerrit-noreply@qt-project.org>
Fri, 23 Nov 2012 19:40:02 +0000 (20:40 +0100)
These Qt3 legacy application types do not match the application types
available in Qt5. Thus, the decision was to kill the confusing and
mostly useless type enum. Use for example qobject_cast instead to find
out the application type.

Task-number: QTBUG-28093
Change-Id: Ia8cf7c3ea98a3cea27f74760d62e519ea10bce9f
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
dist/changes-5.0.0
src/corelib/kernel/qcoreapplication.h
src/corelib/kernel/qcoreapplication_p.h
src/gui/kernel/qguiapplication.cpp
src/widgets/kernel/qapplication.cpp
src/widgets/kernel/qapplication.h
src/widgets/kernel/qapplication_p.h

index d64d46e..4160d9b 100644 (file)
@@ -327,6 +327,11 @@ information about a particular change.
 
 - QPrintEngine - Removed the PPK_SuppressSystemPrintStatus key as no longer used.
 
+- QCoreApplication::Type and QApplication::type() have been removed. These
+  Qt3 legacy application types did not match the application types
+  available in Qt5. Use for example qobject_cast instead to dynamically
+  find out the exact application type.
+
 ****************************************************************************
 *                           General                                        *
 ****************************************************************************
index 94b0566..83f444c 100644 (file)
@@ -79,12 +79,6 @@ public:
     enum { ApplicationFlags = QT_VERSION
     };
 
-    enum Type {
-        Tty,
-        GuiClient,
-        GuiServer // # deprecated
-    };
-
     QCoreApplication(int &argc, char **argv
 #ifndef Q_QDOC
                      , int = ApplicationFlags
index 321f690..8d5eeff 100644 (file)
@@ -69,6 +69,11 @@ class Q_CORE_EXPORT QCoreApplicationPrivate : public QObjectPrivate
     Q_DECLARE_PUBLIC(QCoreApplication)
 
 public:
+    enum Type {
+        Tty,
+        Gui
+    };
+
     QCoreApplicationPrivate(int &aargc,  char **aargv, uint flags);
     ~QCoreApplicationPrivate();
 
index 949c963..61c733b 100644 (file)
@@ -391,7 +391,7 @@ QGuiApplicationPrivate::QGuiApplicationPrivate(int &argc, char **argv, int flags
       lastTouchType(QEvent::TouchEnd)
 {
     self = this;
-    application_type = QCoreApplication::GuiClient;
+    application_type = QCoreApplicationPrivate::Gui;
 }
 
 /*!
index ae426fd..faf68cb 100644 (file)
@@ -155,10 +155,10 @@ bool QApplicationPrivate::autoSipEnabled = false;
 bool QApplicationPrivate::autoSipEnabled = true;
 #endif
 
-QApplicationPrivate::QApplicationPrivate(int &argc, char **argv, QApplication::Type type, int flags)
+QApplicationPrivate::QApplicationPrivate(int &argc, char **argv, int flags)
     : QApplicationPrivateBase(argc, argv, flags)
 {
-    application_type = type;
+    application_type = QApplicationPrivate::Gui;
 
 #ifndef QT_NO_SESSIONMANAGER
     is_session_restored = false;
@@ -560,44 +560,7 @@ QApplication::QApplication(int &argc, char **argv)
 #else
 QApplication::QApplication(int &argc, char **argv, int _internal)
 #endif
-    : QGuiApplication(*new QApplicationPrivate(argc, argv, GuiClient, _internal))
-{ Q_D(QApplication); d->construct(); }
-
-
-/*!
-    Constructs an application object with \a argc command line arguments in
-    \a argv.
-
-    \warning The data referred to by \a argc and \a argv must stay valid for
-    the entire lifetime of the QApplication object. In addition, \a argc must
-    be greater than zero and \a argv must contain at least one valid character
-    string.
-
-    The following example shows how to create an application that uses a
-    graphical interface when available.
-
-    \obsolete
-
-    \snippet code/src_gui_kernel_qapplication.cpp 0
-*/
-
-QApplication::QApplication(int &argc, char **argv, bool GUIenabled , int _internal)
-    : QGuiApplication(*new QApplicationPrivate(argc, argv, GUIenabled ? GuiClient : Tty, _internal))
-{ Q_D(QApplication); d->construct();}
-
-
-
-/*!
-    Constructs an application object with \a argc command line arguments in
-    \a argv.
-
-    \warning The data referred to by \a argc and \a argv must stay valid for
-    the entire lifetime of the QApplication object. In addition, \a argc must
-    be greater than zero and \a argv must contain at least one valid character
-    string.
-*/
-QApplication::QApplication(int &argc, char **argv, Type type , int _internal)
-    : QGuiApplication(*new QApplicationPrivate(argc, argv, type, _internal))
+    : QGuiApplication(*new QApplicationPrivate(argc, argv, _internal))
 { Q_D(QApplication); d->construct(); }
 
 /*!
@@ -607,7 +570,7 @@ void QApplicationPrivate::construct()
 {
     initResources();
 
-    qt_is_gui_used = (application_type != QApplication::Tty);
+    qt_is_gui_used = (application_type != QApplicationPrivate::Tty);
     process_cmdline();
 
     // Must be called before initialize()
@@ -653,7 +616,7 @@ void QApplicationPrivate::initialize()
     QWidgetPrivate::mapper = new QWidgetMapper;
     QWidgetPrivate::allWidgets = new QWidgetSet;
 
-    if (application_type != QApplication::Tty)
+    if (application_type != QApplicationPrivate::Tty)
         (void) QApplication::style();  // trigger creation of application style
 #ifndef QT_NO_STATEMACHINE
     // trigger registering of QStateMachine's GUI types
@@ -694,18 +657,6 @@ void QApplicationPrivate::initialize()
             QApplicationPrivate::enabledAnimations = theme->themeHint(QPlatformTheme::UiEffects).toInt();
 }
 
-/*!
-    Returns the type of application (\l Tty, GuiClient, or
-    GuiServer). The type is set when constructing the QApplication
-    object.
-*/
-QApplication::Type QApplication::type()
-{
-    if (QApplicationPrivate::instance())
-        return (QCoreApplication::Type)QApplicationPrivate::instance()->application_type;
-    return Tty;
-}
-
 /*****************************************************************************
   Functions returning the active popup and modal widgets.
  *****************************************************************************/
@@ -1037,8 +988,8 @@ QStyle *QApplication::style()
 {
     if (QApplicationPrivate::app_style)
         return QApplicationPrivate::app_style;
-    if (qApp->type() == QApplication::Tty) {
-        Q_ASSERT(!"No style available in non-gui applications!");
+    if (!qobject_cast<QApplication *>(QCoreApplication::instance())) {
+        Q_ASSERT(!"No style available without QApplication!");
         return 0;
     }
 
index 3c61ffe..86e9638 100644 (file)
@@ -95,16 +95,13 @@ class Q_WIDGETS_EXPORT QApplication : public QGuiApplication
     Q_PROPERTY(bool autoSipEnabled READ autoSipEnabled WRITE setAutoSipEnabled)
 
 public:
-
+#ifdef Q_QDOC
+    QApplication(int &argc, char **argv);
+#else
     QApplication(int &argc, char **argv, int = ApplicationFlags);
-#ifdef QT_DEPRECATED
-    QT_DEPRECATED QApplication(int &argc, char **argv, bool GUIenabled, int = ApplicationFlags);
 #endif
-    QApplication(int &argc, char **argv, Type, int = ApplicationFlags);
     virtual ~QApplication();
 
-    static Type type();
-
     static QStyle *style();
     static void setStyle(QStyle*);
     static QStyle *setStyle(const QString&);
index 5b3493f..bba20bc 100644 (file)
@@ -113,7 +113,7 @@ class Q_WIDGETS_EXPORT QApplicationPrivate : public QApplicationPrivateBase
 {
     Q_DECLARE_PUBLIC(QApplication)
 public:
-    QApplicationPrivate(int &argc, char **argv, QApplication::Type type, int flags);
+    QApplicationPrivate(int &argc, char **argv, int flags);
     ~QApplicationPrivate();
 
     virtual void notifyLayoutDirectionChange();