コード例 #1
0
ファイル: qmlbeam.cpp プロジェクト: matusfaro/actiontrigger
void QmlBeam::reloadQML(QUrl mainFile)
{
    // The mainFile parameter is ignored, instead a property is used to cover non-default asset names.
    Q_UNUSED(mainFile);

    // Get the context of the first scene root to keep the contextProperties.
    QDeclarativeContext* context = QDeclarativeEngine::contextForObject(mRoot);

    // Clear the QML cache.
    QDeclarativeEngine* appEngine = context->engine();
    appEngine->clearComponentCache();

    // Reload all QML.
    QmlDocument* qml = QmlDocument::create(mMainFile);
    AbstractPane *root = qml->createRootObject < AbstractPane > (context);
//    qml->setParent(root);
    Application::instance()->setScene(root);
}
コード例 #2
0
ファイル: main.cpp プロジェクト: ajalkane/profilematic
// IMPROVE: Too long and messy main function. Should chop it up in logical pieces.
Q_DECL_EXPORT int main(int argc, char *argv[])
{
    QString mainQmlFile(QLatin1String("qml/main.qml"));
    if (argc >= 2) {
        if (QLatin1String("-conversionWarning") == argv[1]) {
            qDebug("Displaying conversion warning");
            mainQmlFile = QLatin1String("qml/mainConversionWarning.qml");
        } else if (QLatin1String("-multiRuleWarning") == argv[1]) {
            qDebug("Displaying multi-rule warning");
            mainQmlFile = QLatin1String("qml/mainMultiRuleWarning.qml");
        } else if (QLatin1String("-credentialWarning") == argv[1]) {
            qDebug("Displaying credential warning");
            mainQmlFile = QLatin1String("qml/mainCredentialWarning.qml");
        }
    }

    QScopedPointer<QApplication> app(createApplication(argc, argv));

    QTranslator translator;
    setupTranslations(app.data(), &translator);

    QScopedPointer<QmlApplicationViewer> viewer(QmlApplicationViewer::create());

    // Reduce flicker - maybe. I couldn't see any difference, but it didn't hurt
    // either. See http://blog.rburchell.com/2011/11/avoiding-graphics-flicker-in-qt-qml.html
    viewer->setAttribute(Qt::WA_OpaquePaintEvent);
    viewer->setAttribute(Qt::WA_NoSystemBackground);
    viewer->viewport()->setAttribute(Qt::WA_OpaquePaintEvent);
    viewer->viewport()->setAttribute(Qt::WA_NoSystemBackground);

    ProfileClient profileClient;
    ProfileMaticClient profileMaticClient;

    QmlProfilesModel qmlProfilesModel(&profileClient, QmlProfilesModel::ProfileType);
    QmlRuleUtil::initialize(&qmlProfilesModel);
    QmlDaysModel qmlDaysModel;
    QmlRulesModel qmlRulesModel(&profileMaticClient, &qmlProfilesModel);

    QmlBoolFilterModel qmlConditionEditVisibleModel(qmlRulesModel.getConditionEditModel(), QmlConditionEditModel::VisibleRole, false);
    QmlBoolFilterModel qmlConditionEditNonVisibleModel(qmlRulesModel.getConditionEditModel(), QmlConditionEditModel::VisibleRole, true);
    setupEditModel(qmlRulesModel.getConditionEditModel(), &qmlConditionEditVisibleModel);
    setupEditModel(qmlRulesModel.getConditionEditModel(), &qmlConditionEditNonVisibleModel);

    QmlBoolFilterModel qmlActionEditVisibleModel(qmlRulesModel.getActionEditModel(), QmlConditionEditModel::VisibleRole, false);
    QmlBoolFilterModel qmlActionEditNonVisibleModel(qmlRulesModel.getActionEditModel(), QmlConditionEditModel::VisibleRole, true);
    setupEditModel(qmlRulesModel.getActionEditModel(), &qmlActionEditVisibleModel);
    setupEditModel(qmlRulesModel.getActionEditModel(), &qmlActionEditNonVisibleModel);

    QmlBackend qmlBackend;
    QScopedPointer<QmlLocation> qmlLocation(QmlLocation::create());
    QmlNfcMobility qmlNfc;

    QmlApplicationsScanner qmlApplicationsScanner;
    QmlSelectedApplicationsModel qmlSelectedApplicationsModel(qmlRulesModel.getEditRule(), &qmlApplicationsScanner);
    QmlSortProxyModel qmlSelectedApplicationsSortedModel(&qmlSelectedApplicationsModel, QmlSelectedApplicationsModel::ApplicationName);
    QmlApplicationsModel qmlApplicationsModel;
    QmlApplicationScannerToModelAdapter qmlApplicationScannerToModelAdapter(&qmlApplicationsModel, &qmlApplicationsScanner);
    QmlSortProxyModel qmlApplicationsSortedModel(&qmlApplicationsModel, QmlApplicationsModel::ApplicationName);

    QDeclarativeContext *ctxt = viewer->rootContext();
    QDeclarativeEngine *engine = ctxt->engine();
    engine->connect(engine, SIGNAL(quit()), app.data(), SLOT(quit()));

    qmlRegisterType<Rule>("Rule", 1, 0, "Rule");
    qmlRegisterType<RuleCondition>("Rule", 1, 0, "RuleCondition");
    qmlRegisterType<RuleAction>("Rule", 1, 0, "RuleAction");
    qmlRegisterType<RuleActionApplication>("Rule", 1, 0, "RuleActionApplication");
    qmlRegisterType<RuleActionAlarm>("Rule", 1, 0, "RuleActionAlarm");
    qmlRegisterType<RuleConditionNFC>("Rule", 1, 0, "RuleConditionNFC");
    qmlRegisterType<RuleConditionBatteryLevel>("Rule", 1, 0, "RuleConditionBatteryLevel");
    qmlRegisterType<RuleConditionCalendar>("Rule", 1, 0, "RuleConditionCalendar");
    qmlRegisterType<RuleConditionTimeInterval>("Rule", 1, 0, "RuleConditionTimeInterval");
    qmlRegisterType<PresenceRule>("profilematic", 1, 0, "PresenceRule");
    qmlRegisterType<QmlNetworkInfo>("profilematic", 1, 0, "NetworkInfo");
    qmlRegisterType<QmlChoiseModel>("profilematic", 1, 0, "ChoiseModel");
#ifdef MEEGO_EDITION_HARMATTAN
    qmlRegisterType<QmlPresenceModelImpl>("profilematic", 1, 0, "AccountsModel");
#else
    qmlRegisterType<QmlPresenceModelStub>("profilematic", 1, 0, "AccountsModel");
#endif
    ctxt->setContextProperty("profileClient", &profileClient);
    ctxt->setContextProperty("backend", &qmlBackend);
    ctxt->setContextProperty("backendDaysModel", &qmlDaysModel);
    ctxt->setContextProperty("backendRulesModel", &qmlRulesModel);
    ctxt->setContextProperty("backendProfilesModel", &qmlProfilesModel);
    ctxt->setContextProperty("backendConditionEditModel", qmlRulesModel.getConditionEditModel());
    ctxt->setContextProperty("backendConditionEditVisibleModel", &qmlConditionEditVisibleModel);
    ctxt->setContextProperty("backendConditionEditNonVisibleModel", &qmlConditionEditNonVisibleModel);
    ctxt->setContextProperty("backendActionEditModel", qmlRulesModel.getActionEditModel());
    ctxt->setContextProperty("backendActionEditVisibleModel", &qmlActionEditVisibleModel);
    ctxt->setContextProperty("backendActionEditNonVisibleModel", &qmlActionEditNonVisibleModel);
    ctxt->setContextProperty("backendLocation", qmlLocation.data());
    ctxt->setContextProperty("backendNfc", &qmlNfc);
    ctxt->setContextProperty("backendRuleUtil", QmlRuleUtil::instance());
    ctxt->setContextProperty("backendApplicationsModel", &qmlApplicationsModel);
    ctxt->setContextProperty("backendApplicationsSortedModel", &qmlApplicationsSortedModel);
    ctxt->setContextProperty("backendApplicationsScanner", &qmlApplicationScannerToModelAdapter);
    ctxt->setContextProperty("backendSelectedApplicationsModel", &qmlSelectedApplicationsModel);
    ctxt->setContextProperty("backendSelectedApplicationsSortedModel", &qmlSelectedApplicationsSortedModel);

    viewer->setOrientation(QmlApplicationViewer::ScreenOrientationAuto);
    viewer->setMainQmlFile(mainQmlFile);
    viewer->showExpanded();

    int retVal = app->exec();
    qDebug("Exiting with return value %d", retVal);
    QmlRuleUtil::deinitialize();

    return retVal;
}
コード例 #3
0
ファイル: Loader.cpp プロジェクト: 13natty/Cascades-Samples
// A helper method to retrieve the declarative engine that manages a declarative object
static QDeclarativeEngine* qmlEngine(QObject *object)
{
    QDeclarativeContext *context = QDeclarativeEngine::contextForObject(object);
    return (context ? context->engine() : 0);
}