QList<QmlJSEditor::FindReferences::Usage> FindImplementation::run(const QString &fileName,
                                                                  const QString &typeName,
                                                                  const QString &itemName)
{
    QList<QmlJSEditor::FindReferences::Usage> usages;

    QmlJS::ModelManagerInterface *modelManager = ModelManagerInterface::instance();

    //Parse always the latest version of document
    QmlJS::Dialect dialect = QmlJS::ModelManagerInterface::guessLanguageOfFile(fileName);
    QmlJS::Document::MutablePtr documentUpdate = QmlJS::Document::create(fileName, dialect);
    documentUpdate->setSource(modelManager->workingCopy().source(fileName));
    if (documentUpdate->parseQml())
        modelManager->updateDocument(documentUpdate);

    Document::Ptr document = modelManager->snapshot().document(fileName);
    if (!document)
        return usages;

    QmlJS::Link link(modelManager->snapshot(),
                     modelManager->defaultVContext(document->language(), document),
                     modelManager->builtins(document));
    ContextPtr context = link();
    ScopeChain scopeChain(document, context);

    const ObjectValue *targetValue = scopeChain.context()->lookupType(document.data(), QStringList(typeName));

    FindImplementationVisitor visitor(document, context);

    FindImplementationVisitor::Results results = visitor(typeName, itemName, targetValue);
    foreach (const AST::SourceLocation &location, results) {
        usages.append(QmlJSEditor::FindReferences::Usage(fileName,
                                                         matchingLine(location.offset, document->source()),
                                                         location.startLine, location.startColumn - 1, location.length));
    }
 void forgetDocument()
 {
     // Forget about the document. Keeping a reference to it would prevent it
     // from being garbage collected.
     QObject::disconnect(mDocument.data(), 0, q, 0);
     mDocument = 0;
 }
Exemple #3
0
void SvgImageView::loadFromDocument()
{
    Document::Ptr doc = document();
    GV_RETURN_IF_FAIL(doc);

    if (doc->loadingState() < Document::Loaded) {
        connect(doc.data(), SIGNAL(loaded(KUrl)),
            SLOT(finishLoadFromDocument()));
    } else {
        QMetaObject::invokeMethod(this, "finishLoadFromDocument", Qt::QueuedConnection);
    }
}
void TransformImageOperationTest::testRotate90()
{
    KUrl url = urlForTestFile("test.png");
    QImage image;

    bool ok = image.load(url.toLocalFile());
    QVERIFY2(ok, "Could not load 'test.png'");
    QMatrix matrix = ImageUtils::transformMatrix(ROT_90);
    image = image.transformed(matrix);

    Document::Ptr doc = DocumentFactory::instance()->load(url);

    TransformImageOperation* op = new TransformImageOperation(ROT_90);
    QEventLoop loop;
    connect(doc.data(), SIGNAL(allTasksDone()), &loop, SLOT(quit()));
    op->applyToDocument(doc);
    loop.exec();

    QCOMPARE(image, doc->image());
}