From 101a5185138f4eb4d1ed0e69065d8e4c30a7fff7 Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Fri, 21 Jun 2013 15:08:43 +0200 Subject: [PATCH] Add Qt.application.organization/domain Change-Id: Ic4a161b59d51e621e13c960f104d1a3be2ee64f8 Reviewed-by: Alan Alpert Reviewed-by: Gabriel de Dietrich --- src/qml/qml/qqmlengine.cpp | 10 +++++++++- src/qml/qml/qqmlglobal.cpp | 22 ++++++++++++++++++++++ src/qml/qml/qqmlglobal_p.h | 8 ++++++++ .../qqmlapplicationengine/data/applicationTest.qml | 8 ++++++++ .../tst_qqmlapplicationengine.cpp | 16 ++++++++++++++++ 5 files changed, 63 insertions(+), 1 deletion(-) diff --git a/src/qml/qml/qqmlengine.cpp b/src/qml/qml/qqmlengine.cpp index 71fea41..a7fff20 100644 --- a/src/qml/qml/qqmlengine.cpp +++ b/src/qml/qml/qqmlengine.cpp @@ -451,7 +451,15 @@ The following functions are also on the Qt object. \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. + to in order to set the application version. + \row + \li \c application.organization + \li This is the organization name set on the QCoreApplication instance. This property can be written + to in order to set the organization name. + \row + \li \c application.domain + \li This is the organization domain set on the QCoreApplication instance. This property can be written + to in order to set the organization domain. \endtable The object also has one signal, aboutToQuit(), which is the same as \l QCoreApplication::aboutToQuit(). diff --git a/src/qml/qml/qqmlglobal.cpp b/src/qml/qml/qqmlglobal.cpp index 607ee4d..78d2f5a 100644 --- a/src/qml/qml/qqmlglobal.cpp +++ b/src/qml/qml/qqmlglobal.cpp @@ -432,6 +432,16 @@ QString QQmlApplication::version() const return QCoreApplication::instance()->applicationVersion(); } +QString QQmlApplication::organization() const +{ + return QCoreApplication::instance()->organizationName(); +} + +QString QQmlApplication::domain() const +{ + return QCoreApplication::instance()->organizationDomain(); +} + void QQmlApplication::setName(const QString &arg) { QCoreApplication::instance()->setApplicationName(arg); @@ -444,4 +454,16 @@ void QQmlApplication::setVersion(const QString &arg) emit versionChanged(); //Note that we don't get notified if it's changed from C++ } +void QQmlApplication::setOrganization(const QString &arg) +{ + QCoreApplication::instance()->setOrganizationName(arg); + emit organizationChanged(); //Note that we don't get notified if it's changed from C++ +} + +void QQmlApplication::setDomain(const QString &arg) +{ + QCoreApplication::instance()->setOrganizationDomain(arg); + emit domainChanged(); //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 114c076..d0f408d 100644 --- a/src/qml/qml/qqmlglobal_p.h +++ b/src/qml/qml/qqmlglobal_p.h @@ -322,6 +322,8 @@ class Q_QML_PRIVATE_EXPORT QQmlApplication : public QObject 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) + Q_PROPERTY(QString organization READ organization WRITE setOrganization NOTIFY organizationChanged) + Q_PROPERTY(QString domain READ domain WRITE setDomain NOTIFY domainChanged) public: QQmlApplication(QObject* parent=0); @@ -329,16 +331,22 @@ public: QString name() const; QString version() const; + QString organization() const; + QString domain() const; public Q_SLOTS: void setName(const QString &arg); void setVersion(const QString &arg); + void setOrganization(const QString &arg); + void setDomain(const QString &arg); Q_SIGNALS: void aboutToQuit(); void nameChanged(); void versionChanged(); + void organizationChanged(); + void domainChanged(); protected: QQmlApplication(QQmlApplicationPrivate &dd, QObject* parent=0); diff --git a/tests/auto/qml/qqmlapplicationengine/data/applicationTest.qml b/tests/auto/qml/qqmlapplicationengine/data/applicationTest.qml index 2a1b4fb..1957eda 100644 --- a/tests/auto/qml/qqmlapplicationengine/data/applicationTest.qml +++ b/tests/auto/qml/qqmlapplicationengine/data/applicationTest.qml @@ -3,12 +3,20 @@ import QtQml 2.0 QtObject { property string originalName property string originalVersion + property string originalOrganization + property string originalDomain property string currentName: Qt.application.name property string currentVersion: Qt.application.version + property string currentOrganization: Qt.application.organization + property string currentDomain: Qt.application.domain Component.onCompleted: { originalName = Qt.application.name originalVersion = Qt.application.version + originalOrganization = Qt.application.organization + originalDomain = Qt.application.domain Qt.application.name = "Test B" Qt.application.version = "0.0B" + Qt.application.organization = "Org B" + Qt.application.domain = "b.org" } } diff --git a/tests/auto/qml/qqmlapplicationengine/tst_qqmlapplicationengine.cpp b/tests/auto/qml/qqmlapplicationengine/tst_qqmlapplicationengine.cpp index 4780ee0..c0c3f73 100644 --- a/tests/auto/qml/qqmlapplicationengine/tst_qqmlapplicationengine.cpp +++ b/tests/auto/qml/qqmlapplicationengine/tst_qqmlapplicationengine.cpp @@ -132,26 +132,42 @@ void tst_qqmlapplicationengine::applicationProperties() QCoreApplication* coreApp = QCoreApplication::instance(); QString originalName = coreApp->applicationName(); QString originalVersion = coreApp->applicationVersion(); + QString originalOrganization = coreApp->organizationName(); + QString originalDomain = coreApp->organizationDomain(); QString firstName = QLatin1String("Test A"); QString firstVersion = QLatin1String("0.0A"); + QString firstOrganization = QLatin1String("Org A"); + QString firstDomain = QLatin1String("a.org"); QString secondName = QLatin1String("Test B"); QString secondVersion = QLatin1String("0.0B"); + QString secondOrganization = QLatin1String("Org B"); + QString secondDomain = QLatin1String("b.org"); coreApp->setApplicationName(firstName); coreApp->setApplicationVersion(firstVersion); + coreApp->setOrganizationName(firstOrganization); + coreApp->setOrganizationDomain(firstDomain); QQmlApplicationEngine *test = new QQmlApplicationEngine(testFileUrl("applicationTest.qml")); QObject* root = test->rootObjects().at(0); QVERIFY(root); QCOMPARE(root->property("originalName").toString(), firstName); QCOMPARE(root->property("originalVersion").toString(), firstVersion); + QCOMPARE(root->property("originalOrganization").toString(), firstOrganization); + QCOMPARE(root->property("originalDomain").toString(), firstDomain); QCOMPARE(root->property("currentName").toString(), secondName); QCOMPARE(root->property("currentVersion").toString(), secondVersion); + QCOMPARE(root->property("currentOrganization").toString(), secondOrganization); + QCOMPARE(root->property("currentDomain").toString(), secondDomain); QCOMPARE(coreApp->applicationName(), secondName); QCOMPARE(coreApp->applicationVersion(), secondVersion); + QCOMPARE(coreApp->organizationName(), secondOrganization); + QCOMPARE(coreApp->organizationDomain(), secondDomain); coreApp->setApplicationName(originalName); coreApp->setApplicationVersion(originalVersion); + coreApp->setOrganizationName(originalOrganization); + coreApp->setOrganizationDomain(originalDomain); delete test; } -- 2.7.4