StampCollectorApp::StampCollectorApp() { // The entire UI is a drill down list, which means that when an item is selected // a navigation takes place to a Content View with a large stamp image and a descriptive text. // The main.qml contain the navigation pane and the first page (the list). QmlDocument *qml = QmlDocument::create().load("main.qml"); qml->setParent(this); mNav = qml->createRootNode<NavigationPane>(); // We get the ListView from QML, so that we can connect to the selctionChange signal and set // up a DataModel for JSON data. ListView *stampList = mNav->findChild<ListView*>("stampList"); setUpStampListModel(stampList); QObject::connect(stampList, SIGNAL(selectionChanged(const QVariantList, bool)), this, SLOT(onSelectionChanged(const QVariantList, bool))); // The second page, with a detailed description and large stamp image is set up in QML // Navigation to this page is handled in the onSelectionChanged Slot function. QmlDocument *contentQml = QmlDocument::create().load("ContentPage.qml"); contentQml->setParent(this); mQmlContext = contentQml->documentContext(); // Set up a context property to the navigation pane so that it is possible to navigate back to the list // and create the content page. mQmlContext->setContextProperty("_nav", mNav); mContentPage = contentQml->createRootNode<Page>(); // Create the application scene and we are done. Application::setScene(mNav); }
ApplicationUI::ApplicationUI(bb::cascades::Application *app) : QObject(app), m_appInvoker(new AppInvoker(this)) { // prepare the localization m_pTranslator = new QTranslator(this); m_pLocaleHandler = new LocaleHandler(this); if(!QObject::connect(m_pLocaleHandler, SIGNAL(systemLanguageChanged()), this, SLOT(onSystemLanguageChanged()))) { // This is an abnormal situation! Something went wrong! // Add own code to recover here qWarning() << "Recovering from a failed connect()"; } // initial load onSystemLanguageChanged(); // Create scene document from main.qml asset, the parent is set // to ensure the document gets destroyed properly at shut down. QmlDocument *qml = QmlDocument::create("asset:///main.qml").parent(this); qml->documentContext()->setContextProperty("invoker",m_appInvoker); // Create root object for the UI AbstractPane *root = qml->createRootObject<AbstractPane>(); // Set created root object as the application scene app->setScene(root); }
void WeatherGuesserApp::createWeatherPage() { QmlDocument *qml = QmlDocument::create().load("WeatherPage.qml"); if (!qml->hasErrors()) { mWeatherPage = qml->createRootNode<Page>(); if (mWeatherPage) { // Set up a weather model the list, the model will load weather data ListView *weatherList = mWeatherPage->findChild<ListView*>("weatherList"); WeatherModel *weatherModel = new WeatherModel(this); weatherList->setDataModel(weatherModel); // Connect the weather model to page signals that updates city for which model should be shown. connect(mContinentCitiesPage, SIGNAL(showWeather(QString)), weatherModel, SLOT(onUpdateWeatherCity(QString))); Page *favorites = mNavigation->findChild<Page*>("favorites"); connect(favorites, SIGNAL(showWeather(QString)), weatherModel, SLOT(onUpdateWeatherCity(QString))); qml->documentContext()->setContextProperty("_navigation", mNavigation); } } }
void WeatherGuesserApp::createCitiesPage() { QmlDocument *qml = QmlDocument::create().load("ContinentCitiesPage.qml"); if (!qml->hasErrors()) { mContinentCitiesPage = qml->createRootNode<Page>(); if (mContinentCitiesPage) { // Set up a cities model for the page, this model will load different cities depending // on which continent is selected. ListView *citiesList = mContinentCitiesPage->findChild<ListView*>("citiesList"); CityModel *cityModel = new CityModel(QStringList() << "name", "continents_connection", this); citiesList->setDataModel(cityModel); // Connect to the continents page custom signal. Page *continents = mNavigation->findChild<Page*>("continents"); connect(continents, SIGNAL(showContinentCities(QString)), cityModel, SLOT(onChangeContinent(QString))); qml->documentContext()->setContextProperty("_navigation", mNavigation); } } }
/** * This sample applications shows how to access remote data via the FTP protocol. * It implements a simple browser to view the content of an FTP server and allows * the user to download files to the local disk. */ Q_DECL_EXPORT int main(int argc, char **argv) { Application app(argc, argv); // Creates the FtpDownloader object that contains the business logic FtpDownloader downloader; // Creates the FtpItemProvider for the ListView FtpItemProvider itemProvider; // Load the UI description from main.qml QmlDocument *qml = QmlDocument::create("asset:///main.qml"); // Make all the business logic objects available to the UI as context properties qml->setContextProperty("_model", downloader.model()); qml->setContextProperty("_itemProvider", &itemProvider); qml->setContextProperty("_downloader", &downloader); qml->setContextProperty("_messageBox", downloader.messageBoxController()); qml->setContextProperty("_progressDialog", downloader.progressDialogController()); // Create the application scene AbstractPane *appPage = qml->createRootObject<AbstractPane>(); Application::instance()->setScene(appPage); // Quit the application if 'Qt.quit()' is called in the UI QObject::connect(qml->documentContext()->engine(), SIGNAL(quit()), &app, SLOT(quit())); return Application::exec(); }
void AlternatingListItem::setup(const QString& qmlFile) { QmlDocument* document = QmlDocument::create(qmlFile); QDeclarativeContext *derivedContext = new QDeclarativeContext( document->documentContext(), this); derivedContext->setContextProperty("_item", this); setRoot(document->createRootObject<Control>(derivedContext)); }
bool QuotesApp::loadQMLScene() { // Here we create a QML object and load it, we are using build patterns. QmlDocument *qmlDocument = QmlDocument::create().load("main.qml"); if (!qmlDocument->hasErrors()) { // In order to call invokable function in this object it is set as a context property. qmlDocument->setContextProperty("_quoteApp", this); // The root Container is created from QML. mNav = qmlDocument->createRootNode<NavigationPane>(); if (mNav) { // The list containing a bunch of people that have expressed clever things // when it comes to programming is set up. mListView = setUpQuotesList(); // Load the document for the Quotes page where content will be presented. QmlDocument *contentQML = QmlDocument::create().load("QuotePage/QuotePage.qml"); if (!contentQML->hasErrors()) { // Get the document context, it is used to bind a property for the ContentPane. // and make the navigation pane and application available for QML. mQmlContext = contentQML->documentContext(); mQmlContext->setContextProperty("_navPane", mNav); mQmlContext->setContextProperty("_quoteApp", this); // Initialization of the bound context properties of the content to empty strings. clearContentPaneData(); mContentPage = contentQML->createRootNode<Page>(); // Finally the main scene for the application is set to this Control. Application::setScene(mNav); return true; } } } return false; }
ApplicationUI::ApplicationUI(bb::cascades::Application *app) : QObject(app) { DataBaseController *dataBaseController = DataBaseController::getInstance( this); QmlDocument::defaultDeclarativeEngine()->rootContext()->setContextProperty( "_db", dataBaseController); ApplicationInfo::registerQmlTypes(); SqlDataModel::registerQmlTypes(); // prepare the localization m_pTranslator = new QTranslator(this); m_pLocaleHandler = new LocaleHandler(this); DataBaseController::createDB(); DataBaseController::createTables(); bool res = QObject::connect(m_pLocaleHandler, SIGNAL(systemLanguageChanged()), this, SLOT(onSystemLanguageChanged())); // This is only available in Debug builds Q_ASSERT(res); // Since the variable is not used in the app, this is added to avoid a // compiler warning Q_UNUSED(res); // initial load onSystemLanguageChanged(); // Create scene document from main.qml asset, the parent is set // to ensure the document gets destroyed properly at shut down. QmlDocument *qml = QmlDocument::create("asset:///main.qml").parent(this); // const QString uuid(QLatin1String("76a353d0-bd9c-11e3-b1b6-0800200c9a66")); // full version const QString uuid(QLatin1String("f0af2ec0-bd9b-11e3-b1b6-0800200c9a66")); // free version RegistrationHandler *registrationHandler = new RegistrationHandler(uuid, app); m_inviteToDownload = new InviteToDownload(registrationHandler->context(), app); res = connect(registrationHandler, SIGNAL(registered()), m_inviteToDownload, SLOT(show())); Q_ASSERT(res); Q_UNUSED(res); ActiveFrameQML *activeFrame = new ActiveFrameQML(this); Application::instance()->setCover(activeFrame); // Create root object for the UI AbstractPane *root = qml->createRootObject<AbstractPane>(); qml->setContextProperty("_app", this); qml->documentContext()->setContextProperty("_settings", Settings::getInstance(this)); qml->documentContext()->setContextProperty("_notification", new Notification(this)); qml->documentContext()->setContextProperty("_packageCtrl", PackagesController::getInstance(this)); Settings::getInstance(this)->setParent(this); Settings::getInstance(this)->emitObjectName("last_update_date"); registrationHandler->registerApplication(); // Set created root object as the application scene app->setScene(root); }