Exemplo n.º 1
0
void QDeclarativeLoaderPrivate::_q_sourceLoaded()
{
    Q_Q(QDeclarativeLoader);

    if (component) {
        if (!component->errors().isEmpty()) {
            QDeclarativeEnginePrivate::warning(qmlEngine(q), component->errors());
            emit q->sourceChanged();
            emit q->statusChanged();
            emit q->progressChanged();
            return;
        }

        QDeclarativeContext *creationContext = component->creationContext();
        if (!creationContext) creationContext = qmlContext(q);
        QDeclarativeContext *ctxt = new QDeclarativeContext(creationContext);
        ctxt->setContextObject(q);

        QDeclarativeGuard<QDeclarativeComponent> c = component;
        QObject *obj = component->beginCreate(ctxt);
        if (component != c) {
            // component->create could trigger a change in source that causes
            // component to be set to something else. In that case we just
            // need to cleanup.
            if (c)
                c->completeCreate();
            delete obj;
            delete ctxt;
            return;
        }
        if (obj) {
            item = qobject_cast<QGraphicsObject *>(obj);
            if (item) {
                QDeclarative_setParent_noEvent(ctxt, obj);
                QDeclarative_setParent_noEvent(item, q);
                item->setParentItem(q);
//                item->setFocus(true);
                initResize();
            } else {
                qmlInfo(q) << QDeclarativeLoader::tr("Loader does not support loading non-visual elements.");
                delete obj;
                delete ctxt;
            }
        } else {
            if (!component->errors().isEmpty())
                QDeclarativeEnginePrivate::warning(qmlEngine(q), component->errors());
            delete obj;
            delete ctxt;
            source = QUrl();
        }
        component->completeCreate();
        emit q->sourceChanged();
        emit q->statusChanged();
        emit q->progressChanged();
        emit q->itemChanged();
        emit q->loaded();
    }
}
Exemplo n.º 2
0
//! [3]
void Loader::sourceLoaded()
{
    if (m_component) { // Sanity check

        /**
         * If an error occured during loading, just emit the change notification
         * signals, the 'status' property will reflect that error state.
         */
        if (!m_component->errors().isEmpty()) {
            emit statusChanged();
            emit progressChanged();
            emit sourceChanged();
            emit controlChanged();
            return;
        }

        // Get the declarative context of the declarative component
        QDeclarativeContext *creationContext = m_component->creationContext();

        // If it has not been set, use the declarative context of the Loader element as fallback
        if (!creationContext)
            creationContext = QDeclarativeEngine::contextForObject(this);

        // Create a new child context that will be used as declarative context for the Cascades object
        QDeclarativeContext *ctxt = new QDeclarativeContext(creationContext);
        ctxt->setContextObject(this);

        // Load the Cascades object
        QObject *object = m_component->create(ctxt);
        if (object) {
            m_control = qobject_cast<bb::cascades::Control*>(object);
            if (m_control) {
                // If the loaded Cascades object is a Control, we use it as root element for the Loader and make it visible
                setRoot(m_control);
                setVisible(true);
            } else {
                // Otherwise report an error
                qmlInfo(this) << tr("Loader does not support loading non-visual elements.");
                delete object;
                delete ctxt;
            }
        } else {
            // Cleanup if the loading failed
            delete object;
            delete ctxt;
            m_source = QUrl();
        }

        emit sourceChanged();
        emit statusChanged();
        emit progressChanged();
        emit controlChanged();
        emit loaded();
    }
}
Exemplo n.º 3
0
PropertyEditor::NodeType::NodeType(PropertyEditor *propertyEditor) :
        m_view(new DeclarativeWidgetView), m_propertyEditorTransaction(new PropertyEditorTransaction(propertyEditor)), m_dummyPropertyEditorValue(new PropertyEditorValue()),
        m_contextObject(new PropertyEditorContextObject())
{
    Q_ASSERT(QFileInfo(":/images/button_normal.png").exists());

    QDeclarativeContext *ctxt = m_view->rootContext();
    m_view->engine()->setOutputWarningsToStandardError(debug);
    m_dummyPropertyEditorValue->setValue("#000000");
    ctxt->setContextProperty("dummyBackendValue", m_dummyPropertyEditorValue.data());
    m_contextObject->setBackendValues(&m_backendValuesPropertyMap);
    ctxt->setContextObject(m_contextObject.data());

    connect(&m_backendValuesPropertyMap, SIGNAL(valueChanged(QString,QVariant)), propertyEditor, SLOT(changeValue(QString)));
}
Exemplo n.º 4
0
void AbstractDataPlugin::handleViewportChange( const ViewportParams *viewport )
{
    QList<AbstractDataPluginItem*> orphane = d->m_delegateInstances.keys();
    QList<AbstractDataPluginItem*> const items = d->m_model->items( viewport, numberOfItems() );
    foreach( AbstractDataPluginItem* item, items ) {
        qreal x, y;
        Marble::GeoDataCoordinates const coordinates = item->coordinate();
        bool const visible = viewport->screenCoordinates( coordinates.longitude(), coordinates.latitude(), x, y );

        if ( !d->m_delegateInstances.contains( item ) ) {
            if ( !visible ) {
                // We don't have, but don't need it either. Shouldn't happen though as the model checks for it already.
                continue;
            }

            // Create a new QML object instance using the delegate as the factory. The original
            // data plugin item is set as the context object, i.e. all its properties are available
            // to QML directly with their names
            QDeclarativeContext *context = new QDeclarativeContext( qmlContext( d->m_delegate ) );
            context->setContextObject( item );
            QList<QByteArray> const dynamicProperties = item->dynamicPropertyNames();
            foreach( const QByteArray &property, dynamicProperties ) {
                context->setContextProperty( property, item->property( property ) );
            }

            QObject* component = d->m_delegate->create( context );
            QDeclarativeItem* newItem = qobject_cast<QDeclarativeItem*>( component );
            QGraphicsItem* graphicsItem = qobject_cast<QGraphicsItem*>( component );
            if ( graphicsItem && newItem ) {
                graphicsItem->setParentItem( d->m_delegateParent );
            }

            if ( newItem ) {
                d->m_delegateInstances[item] = newItem;
            } else {
                mDebug() << "Failed to create delegate";
                continue;
            }
        } else if ( !visible ) {
Exemplo n.º 5
0
Q_DECL_EXPORT int main(int argc, char *argv[])
{
    qmlRegisterType<Dict>("Vortaro", 1, 0, "Dict");
    qmlRegisterType<Word>("Vortaro", 1, 0, "Word");

    QScopedPointer<QApplication> app(createApplication(argc, argv));
    QmlApplicationViewer viewer;
    QDeclarativeEngine *engine = viewer.engine();
    QDeclarativeContext *rootContext = engine->rootContext();

    // engine->addImportPath(QString("/opt/nokia/qtsdk/Simulator/Qt/gcc/imports"));

    Session session;
    session.load();
    rootContext->setContextObject(&session);

    viewer.setOrientation(QmlApplicationViewer::ScreenOrientationLockPortrait);
    viewer.setSource(QUrl("qrc:///qml/main.qml"));
    // viewer.setMainQmlFile(QString("qml/main.qml"));
    viewer.showExpanded();

    return app->exec();
}