aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml
diff options
context:
space:
mode:
authorAlan Alpert <aalpert@rim.com>2013-02-18 21:07:15 -0800
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-03-05 22:37:25 +0100
commitdfefcba06efc0ad239cb7f9ad5d9a5f9540841db (patch)
tree5e0bd8c615d672a2bac10a3dc22c970d5f1e3215 /src/qml
parent23b7579e4d82e2c0a840b55adf7817ffb6b4389c (diff)
Add core application functionality to Qt.application in QML
This exposes some information to QML which is available on the QCoreApplication instance. A future change should make it possible to restrict this for use in scripting environments (which should not have access to the QCoreApplication). That has been left out of this change because proper support for such restrictions is not yet in place. Change-Id: Ica144fcfb0b42fa6df8d0cb1c7c03eb97282b489 Reviewed-by: Lars Knoll <lars.knoll@digia.com> Reviewed-by: Kai Koehne <kai.koehne@digia.com>
Diffstat (limited to 'src/qml')
-rw-r--r--src/qml/qml/qqmlengine.cpp20
-rw-r--r--src/qml/qml/qqmlglobal.cpp53
-rw-r--r--src/qml/qml/qqmlglobal_p.h47
3 files changed, 116 insertions, 4 deletions
diff --git a/src/qml/qml/qqmlengine.cpp b/src/qml/qml/qqmlengine.cpp
index b0b6f45fa9..ddc6f0e9b9 100644
--- a/src/qml/qml/qqmlengine.cpp
+++ b/src/qml/qml/qqmlengine.cpp
@@ -437,13 +437,31 @@ The following functions are also on the Qt object.
\li Qt.RightToLeft - Text and graphics elements should be positioned
from right to left.
\endlist
-
+ \row
+ \li \c application.arguments
+ \li This is a string list of the arguments the executable was invoked with.
+ \row
+ \li \c application.name
+ \li This is the application name set on the QCoreApplication instance. This property can be written
+ to in order to set the application name.
+ \row
+ \li \c application.version
+ \li This is the application version set on the QCoreApplication instance. This property can be written
+ to in order to set the application name.
\endtable
+ The object also has one signal, aboutToQuit(), which is the same as \l QCoreApplication::aboutToQuit().
+
The following example uses the \c application object to indicate
whether the application is currently active:
\snippet qml/application.qml document
+
+ Note that when using QML without a QGuiApplication, the following properties will be undefined:
+ \list
+ \li application.active
+ \li application.layoutDirection
+ \endlist
*/
/*!
diff --git a/src/qml/qml/qqmlglobal.cpp b/src/qml/qml/qqmlglobal.cpp
index 379a168110..607ee4d0ac 100644
--- a/src/qml/qml/qqmlglobal.cpp
+++ b/src/qml/qml/qqmlglobal.cpp
@@ -44,6 +44,7 @@
#include <QtCore/qvariant.h>
#include <QtCore/qstringlist.h>
#include <QtCore/qdebug.h>
+#include <QtCore/QCoreApplication>
QT_BEGIN_NAMESPACE
@@ -357,7 +358,7 @@ Q_AUTOTEST_EXPORT QQmlColorProvider *QQml_colorProvider(void)
QQmlGuiProvider::~QQmlGuiProvider() {}
-QObject *QQmlGuiProvider::application(QObject *) { return 0; }
+QObject *QQmlGuiProvider::application(QObject *) { return new QQmlApplication(); }
QStringList QQmlGuiProvider::fontFamilies() { return QStringList(); }
bool QQmlGuiProvider::openUrlExternally(QUrl &) { return false; }
@@ -383,8 +384,7 @@ Q_QML_PRIVATE_EXPORT QQmlGuiProvider *QQml_setGuiProvider(QQmlGuiProvider *newPr
static QQmlGuiProvider **getGuiProvider(void)
{
if (guiProvider == 0) {
- qWarning() << "Warning: QQml_guiProvider: no GUI provider has been set!";
- static QQmlGuiProvider nullGuiProvider;
+ static QQmlGuiProvider nullGuiProvider; //Still provides an application with no GUI support
guiProvider = &nullGuiProvider;
}
@@ -397,4 +397,51 @@ Q_AUTOTEST_EXPORT QQmlGuiProvider *QQml_guiProvider(void)
return *providerPtr;
}
+//Docs in qqmlengine.cpp
+QQmlApplication::QQmlApplication(QObject *parent)
+ : QObject(*(new QQmlApplicationPrivate),parent)
+{
+ connect(QCoreApplication::instance(), SIGNAL(aboutToQuit()),
+ this, SIGNAL(aboutToQuit()));
+}
+
+QQmlApplication::QQmlApplication(QQmlApplicationPrivate &dd, QObject *parent)
+ : QObject(dd, parent)
+{
+ connect(QCoreApplication::instance(), SIGNAL(aboutToQuit()),
+ this, SIGNAL(aboutToQuit()));
+}
+
+QStringList QQmlApplication::args()
+{
+ Q_D(QQmlApplication);
+ if (!d->argsInit) {
+ d->argsInit = true;
+ d->args = QCoreApplication::arguments();
+ }
+ return d->args;
+}
+
+QString QQmlApplication::name() const
+{
+ return QCoreApplication::instance()->applicationName();
+}
+
+QString QQmlApplication::version() const
+{
+ return QCoreApplication::instance()->applicationVersion();
+}
+
+void QQmlApplication::setName(const QString &arg)
+{
+ QCoreApplication::instance()->setApplicationName(arg);
+ emit nameChanged(); //Note that we don't get notified if it's changed from C++
+}
+
+void QQmlApplication::setVersion(const QString &arg)
+{
+ QCoreApplication::instance()->setApplicationVersion(arg);
+ emit versionChanged(); //Note that we don't get notified if it's changed from C++
+}
+
QT_END_NAMESPACE
diff --git a/src/qml/qml/qqmlglobal_p.h b/src/qml/qml/qqmlglobal_p.h
index f6b2c81536..6ca54f65cd 100644
--- a/src/qml/qml/qqmlglobal_p.h
+++ b/src/qml/qml/qqmlglobal_p.h
@@ -313,6 +313,53 @@ public:
Q_QML_PRIVATE_EXPORT QQmlGuiProvider *QQml_setGuiProvider(QQmlGuiProvider *);
Q_AUTOTEST_EXPORT QQmlGuiProvider *QQml_guiProvider();
+class QQmlApplicationPrivate;
+
+class Q_QML_PRIVATE_EXPORT QQmlApplication : public QObject
+{
+ //Application level logic, subclassed by QtQuick if available via QQmlGuiProvider
+ Q_OBJECT
+ Q_PROPERTY(QStringList arguments READ args CONSTANT)
+ Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged)
+ Q_PROPERTY(QString version READ version WRITE setVersion NOTIFY versionChanged)
+public:
+ QQmlApplication(QObject* parent=0);
+
+ QStringList args();
+
+ QString name() const;
+ QString version() const;
+
+public Q_SLOTS:
+ void setName(const QString &arg);
+ void setVersion(const QString &arg);
+
+Q_SIGNALS:
+ void aboutToQuit();
+
+ void nameChanged();
+ void versionChanged();
+
+protected:
+ QQmlApplication(QQmlApplicationPrivate &dd, QObject* parent=0);
+
+private:
+ Q_DISABLE_COPY(QQmlApplication);
+ Q_DECLARE_PRIVATE(QQmlApplication);
+};
+
+class QQmlApplicationPrivate : public QObjectPrivate
+{
+ Q_DECLARE_PUBLIC(QQmlApplication)
+public:
+ QQmlApplicationPrivate() {
+ argsInit = false;
+ }
+
+ bool argsInit;
+ QStringList args;
+};
+
QT_END_NAMESPACE
#endif // QQMLGLOBAL_H