Qt-creator-qmljslib

From Qt Wiki
Jump to navigation Jump to search

QML Code Model Components

The code model is made of several components.

ModelManager

The ModelManager class is a singleton class that drives the building of the code model and provides to the other tools the information they need.

Snapshot

The Snapshot class holds and offer access to a set of DocumentPtr and LibraryInfo instances.

Usually snapshots are copies of the snapshot maintained and updated by the ModelManagerInterface that update its instance as parsing threads finish and new information becomes available.

LibraryInfo

The LibraryInfo class creates a QML library.

A LibraryInfo instance is created when the ModelManagerInterface finds a QML library and parses the qmldir file.

The instance hold information about which components the library provides and which plugin to load..

The model manager will try to extract detailed information about the types defined in the plugins this library loads. Such information are available by metaObject() method.

Document

Documents are usually created by the model manager and stored in a snapshot.

They allow access to data such as the file path, source code, abstract syntax tree and the Bind instance for the Document. To make sure unused and outdated documents are removed correctly, Document instances are usually accessed through a shared pointer, see Document:Ptr Documents in a snapshot are immutable.

Bind

The Bind class collects information about a single document.

Each document owns an instance of Bind. It provides access to data that can be derived by looking at the document in isolation. Information beyond that can be found in the Context class. The documentÔÇÖs imports are available through imports() method.

This class makes the structural information found in the abstract syntax tree available for analysis through Value instances.

See also: findQmlObject(), idEnvironment(), rootObjectValue() and findAttachedJSScope().

Context

The Context class holds information about relationships between documents in a snapshot.

Context are usually created through instances of the Link class. Once created, a context is immutable and can be freely shared between threads. The main purpose is to allow look-up of types with lookupType() and resolving of references through lookupReference(). As such, they form the basis for creating instances of ScopeChain.

Information about the imports of a document can be accessed with imports().

When dealing with a QmlJSEditorDocument it is unnecessary to construct a new context manually. Instead, QmlJSEditorDocument::semanticInfo()::context can be used.

Link

The link class create a Context for a Snapshot.

It initializes a context by resolving imports. This is an expensive operation. Instead of making a fresh context, it is better to use the one maintained in QmlJSEditor::SemanticInfo of a QmlJSEditor::QmlJSEditorDocument.