![]() |
Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
|
Represents an immutable JsonPath like path in the Qml code model (from a DomItem to another DomItem). More...
#include <qqmldompath_p.h>
Public Types | |
| using | Kind = PathEls::Kind |
| using | Component = PathEls::PathComponent |
Public Member Functions | |
| Path ()=default | |
| int | length () const |
| Path | operator[] (int i) const |
| operator bool () const | |
| PathIterator | begin () const |
| PathSentinel | end () const |
| std::optional< PathRoot > | headRoot () const |
| std::optional< PathCurrent > | headCurrent () const |
| Kind | headKind () const |
| QString | headName () const |
| std::optional< FieldName > | headField () const |
| std::optional< index_type > | headIndex () const |
| Path | head () const |
| Path | last () const |
| Source | split () const |
| Splits the path at the last field or current component, or right after a root anchor. | |
| void | dump (const Sink &sinksink) const |
| QString | toString () const |
| Path | dropFront (int nn=1) const |
| Path | dropTail (int nn=1) const |
| Path | mid (int offsetoffset, int lengthlength) const |
| Path | mid (int offsetoffset) const |
| Path | withComponent (PathEls::PathComponent cc) const |
| Path | withEmpty () const |
| Path | withField (FieldName namename) const |
| Path | withKey (const QString &namename) const |
| Path | withKey (QStringView namename) const |
| Path | withIndex (index_type i) const |
| Path | withCurrent (PathCurrent ss) const |
| Path | withPath (const Path &toAdd) const |
Returns a copy of this with toAdd appended to it. | |
Static Public Member Functions | |
| static Path | fromRoot (PathRoot rr) |
| static Path | fromIndex (index_type i) |
| static Path | fromField (FieldName namename) |
| static Path | fromKey (QStringView ss) |
| static Path | fromKey (const QString &ss) |
| static Path | fromCurrent (PathCurrent cc) |
| static Path | fromComponent (Component cc) |
| static int | cmp (const Path &p1, const Path &p2) |
| Compares p1 and p2 lexicographically. | |
Friends | |
| class | QQmlJS::Dom::PathEls::TestPaths |
| class | FieldFilter |
| class | PathIterator |
| QMLDOM_EXPORT size_t | qHash (const Path &pathpath, size_t seed=0) |
Represents an immutable JsonPath like path in the Qml code model (from a DomItem to another DomItem).
A Path is a pointer to the node holding its last component, plus the path length. Each node (PathEls::PathNode) holds one PathComponent and a pointer to the node of the component before it:
\badcode
__[.e] a.e (node e, length 2)
/
[$root] <- [.a] <- [.b] <- [.c] $root.a.b.c: (node c, length 4) ^ ___ [.d] $root.a.d: (node d, length 3)
Nodes are immutable and reference counted.
The path consists of the m_length nodes ending in m_lastNode. Ancestors beyond that are not part of the path, which makes dropFront() O(1). dropTail(n) and mid() walk up from the tail, which is O(n) in the number of dropped components. That's often cheap, as they mostly drop the last one or two components.
As the links point backwards, accessing the front of a path is O(length). Operations that traverse the components in order therefore first collect the nodes into an array.
Each PathComponent owns the data it stores, there are no references to outside data strutures.
It can be created with the path static functions or by modifying an existing path. To parse a Path from its textual form, use parsePath() from qqmldompathparser_p.h.
This is a way to refer to elements in the Dom models that is not dependent from the source location, and thus can also be used in visual tools. A Path is quite stable toward reallocations or changes in the Dom model, and accessing it is safe even when "dangling", thus it is a good long term reference to an element in the Dom model.
Path objects are a value type that have a shared pointer to extra data if needed, thus one should use them as value objects. The implementation has still optimization potential, but the behavior for the user should be already the final one.
Path is both a range, and a single element (a bit like strings and characters in python).
The root contexts are: \list
The current contexts are: \list
Definition at line 576 of file qqmldompath_p.h.
| using QQmlJS::Dom::Path::Kind = PathEls::Kind |
Definition at line 575 of file qqmldompath_p.h.
|
default |
Referenced by QQmlJS::Dom::Component::Component(), QQmlJS::Dom::DomItem::DomItem(), QQmlJS::Dom::DomItem::DomItem(), QQmlJS::Dom::DomEnvironment::addAllLoadedCallback(), QQmlJS::Dom::Empty::canonicalPath(), QQmlJS::Dom::CommentCollector::collectComments(), QQmlJS::Dom::MutableDomItem::containingObject(), dropFront(), dropTail(), fromComponent(), mid(), QQmlJS::Dom::Empty::pathFromOwner(), QQmlJS::Dom::OwningItem::pathFromOwner(), split(), and QQmlJS::Dom::DomItem::top().
| PathIterator QQmlJS::Dom::Path::begin | ( | ) | const |
Definition at line 251 of file qqmldompath.cpp.
References QQmlJS::Dom::PathIterator::PathIterator().
Referenced by QQmlJS::Dom::DomItem::resolve().
Compares p1 and p2 lexicographically.
Definition at line 389 of file qqmldompath.cpp.
References QQmlJS::Dom::PathEls::PathComponent::cmp().
Referenced by QQmlJS::Dom::ErrorMessage::compare, QQmlJS::Dom::operator!=(), QQmlJS::Dom::operator<(), QQmlJS::Dom::operator<=(), QQmlJS::Dom::operator==(), QQmlJS::Dom::operator>(), and QQmlJS::Dom::operator>=().
| Path QQmlJS::Dom::Path::dropFront | ( | int | n = 1 | ) | const |
Definition at line 438 of file qqmldompath.cpp.
References Path().
| Path QQmlJS::Dom::Path::dropTail | ( | int | n = 1 | ) | const |
Definition at line 445 of file qqmldompath.cpp.
References Path().
Referenced by QQmlJS::Dom::DomItem::goUp(), QQmlJS::Dom::DomItem::isCanonicalChild(), mid(), QQmlJS::Dom::DomItem::visitScopeChain(), and QQmlJS::Dom::DomItem::visitUp().
Definition at line 414 of file qqmldompath.cpp.
| PathSentinel QQmlJS::Dom::Path::end | ( | ) | const |
Definition at line 256 of file qqmldompath.cpp.
Definition at line 343 of file qqmldompath.cpp.
References Path(), and withComponent().
Referenced by fromCurrent(), fromField(), fromIndex(), fromKey(), and fromRoot().
|
static |
Definition at line 353 of file qqmldompath.cpp.
References fromComponent().
Referenced by QQmlJS::Dom::Paths::lookupCppTypePath(), QQmlJS::Dom::Paths::lookupPropertyPath(), QQmlJS::Dom::Paths::lookupSymbolPath(), and QQmlJS::Dom::Paths::lookupTypePath().
Definition at line 350 of file qqmldompath.cpp.
References fromComponent().
Referenced by QQmlJS::Dom::QmlObject::addPrototypePath(), QQmlJS::Dom::EnumDecl::addValue(), and QQmlJS::Dom::QmlObject::writeOut().
|
static |
Definition at line 349 of file qqmldompath.cpp.
References fromComponent().
Definition at line 351 of file qqmldompath.cpp.
References fromComponent().
|
static |
Definition at line 352 of file qqmldompath.cpp.
Definition at line 348 of file qqmldompath.cpp.
References fromComponent().
Referenced by QQmlJS::Dom::DomEnvironment::canonicalPath(), QQmlJS::Dom::DomUniverse::canonicalPath(), QQmlJS::Dom::LoadInfo::canonicalPath(), QQmlJS::Dom::Paths::jsFileInfoPath(), QQmlJS::Dom::Paths::loadInfoPath(), QQmlJS::Dom::Paths::moduleIndexPath(), QQmlJS::Dom::Paths::moduleScopePath(), and QQmlJS::Dom::Paths::qmlFileInfoPath().
| Path QQmlJS::Dom::Path::head | ( | ) | const |
Definition at line 305 of file qqmldompath.cpp.
References mid().
| std::optional< PathCurrent > QQmlJS::Dom::Path::headCurrent | ( | ) | const |
Definition at line 269 of file qqmldompath.cpp.
References QQmlJS::Dom::PathEls::PathComponent::asCurrent(), and QQmlJS::Dom::PathEls::Current::contextKind.
Referenced by QQmlJS::Dom::DomItem::resolve().
| std::optional< FieldName > QQmlJS::Dom::Path::headField | ( | ) | const |
Definition at line 277 of file qqmldompath.cpp.
References QQmlJS::Dom::PathEls::PathComponent::asField(), and QQmlJS::Dom::PathEls::Field::fieldName.
Referenced by QQmlJS::Dom::DomItem::resolve().
| std::optional< index_type > QQmlJS::Dom::Path::headIndex | ( | ) | const |
Definition at line 297 of file qqmldompath.cpp.
References QQmlJS::Dom::PathEls::PathComponent::asIndex().
| Path::Kind QQmlJS::Dom::Path::headKind | ( | ) | const |
Definition at line 285 of file qqmldompath.cpp.
References QQmlJS::Dom::PathEls::Empty, and QQmlJS::Dom::PathEls::PathComponent::kind().
Referenced by QQmlJS::Dom::DomItem::canonicalPath(), and QQmlJS::Dom::DomItem::resolve().
| QString QQmlJS::Dom::Path::headName | ( | ) | const |
Definition at line 292 of file qqmldompath.cpp.
| std::optional< PathRoot > QQmlJS::Dom::Path::headRoot | ( | ) | const |
Definition at line 261 of file qqmldompath.cpp.
References QQmlJS::Dom::PathEls::PathComponent::asRoot(), and QQmlJS::Dom::PathEls::Root::contextKind.
Referenced by QQmlJS::Dom::DomItem::resolve().
| Path QQmlJS::Dom::Path::last | ( | ) | const |
Definition at line 310 of file qqmldompath.cpp.
Referenced by QQmlJS::Dom::QmlObject::addBinding(), QQmlJS::Dom::QmlObject::addMethod(), QQmlJS::Dom::QmlObject::addPropertyDef(), QQmlJS::Dom::QmlObject::orderOfAttributes(), QQmlJS::Dom::FileLocations::treeOf(), and QQmlJS::Dom::EnumItem::writeOut().
|
inline |
Definition at line 580 of file qqmldompath_p.h.
Referenced by QQmlJS::Dom::ErrorGroups::fatal(), QQmlJS::Dom::DomItem::goUp(), QQmlJS::Dom::OwningItem::iterateErrors(), QQmlJS::Dom::ExternalItemInfoBase::lastRevision(), QQmlJS::Dom::ExternalItemInfoBase::lastValidRevision(), operator bool(), QQmlJS::Dom::operator!=(), QQmlJS::Dom::operator==(), qHash, QQmlJS::Dom::DomItem::resolve(), split(), and QQmlJS::Dom::DomItem::visitUp().
| Path QQmlJS::Dom::Path::mid | ( | int | offset | ) | const |
Definition at line 464 of file qqmldompath.cpp.
Referenced by split().
| Path QQmlJS::Dom::Path::mid | ( | int | offset, |
| int | length ) const |
Definition at line 456 of file qqmldompath.cpp.
References Path(), and dropTail().
Referenced by head(), QQmlJS::Dom::ExternalItemInfoBase::lastRevision(), QQmlJS::Dom::ExternalItemInfoBase::lastValidRevision(), operator[](), and split().
|
explicit |
Definition at line 246 of file qqmldompath.cpp.
References length().
| Path QQmlJS::Dom::Path::operator[] | ( | int | i | ) | const |
Definition at line 241 of file qqmldompath.cpp.
References mid().
Referenced by QQmlJS::Dom::QmlComponent::subComponentsNames().
| Source QQmlJS::Dom::Path::split | ( | ) | const |
Splits the path at the last field or current component, or right after a root anchor.
Field and Current introduce a new logical "starting point" inside the path, so split puts everything before them into pathToSource and the component itself (plus any tail) into pathFromSource. A Root, in contrast, is an anchor: pathToSource includes the Root and pathFromSource is what follows it. If neither is present, the entire path is pathFromSource.
Definition at line 326 of file qqmldompath.cpp.
References Path(), QQmlJS::Dom::PathEls::Current, QQmlJS::Dom::PathEls::Field, QQmlJS::Dom::PathEls::PathComponent::kind(), length(), mid(), mid(), and QQmlJS::Dom::PathEls::Root.
Referenced by QQmlJS::Dom::DomItem::container(), QQmlJS::Dom::DomBase::containingObject(), and QQmlJS::Dom::OwningItem::containingObject().
| QString QQmlJS::Dom::Path::toString | ( | ) | const |
Definition at line 429 of file qqmldompath.cpp.
| Path QQmlJS::Dom::Path::withComponent | ( | PathEls::PathComponent | c | ) | const |
Definition at line 355 of file qqmldompath.cpp.
Referenced by fromComponent(), QQmlJS::Dom::keyMultiMapHelper(), withCurrent(), withEmpty(), withField(), withIndex(), and withKey().
| Path QQmlJS::Dom::Path::withCurrent | ( | PathCurrent | s | ) | const |
Definition at line 366 of file qqmldompath.cpp.
References withComponent().
| Path QQmlJS::Dom::Path::withEmpty | ( | ) | const |
Definition at line 361 of file qqmldompath.cpp.
References QQmlJS::Dom::PathEls::PathComponent::PathComponent(), and withComponent().
Definition at line 362 of file qqmldompath.cpp.
References withComponent().
Referenced by QQmlJS::Dom::AttributeInfo::addAnnotation(), QQmlJS::Dom::Binding::addAnnotation(), QQmlJS::Dom::Id::addAnnotation(), QQmlJS::Dom::LoadInfo::canonicalPath(), QQmlJS::Dom::domCompare(), QQmlJS::Dom::FileLocations::Info::iterateDirectSubpaths(), QQmlJS::Dom::RegionComments::iterateDirectSubpaths(), QQmlJS::Dom::Paths::jsFileInfoPath(), QQmlJS::Dom::Paths::loadInfoPath(), QQmlJS::Dom::Paths::lookupCppTypePath(), QQmlJS::Dom::Paths::lookupPropertyPath(), QQmlJS::Dom::Paths::lookupSymbolPath(), QQmlJS::Dom::Paths::lookupTypePath(), QQmlJS::Dom::Paths::moduleIndexPath(), QQmlJS::Dom::Paths::moduleScopePath(), QQmlJS::Dom::Paths::qmlFileInfoPath(), QQmlJS::Dom::AttributeInfo::updatePathFromOwner(), QQmlJS::Dom::Binding::updatePathFromOwner(), QQmlJS::Dom::Component::updatePathFromOwner(), QQmlJS::Dom::EnumDecl::updatePathFromOwner(), QQmlJS::Dom::Id::updatePathFromOwner(), QQmlJS::Dom::QmlComponent::updatePathFromOwner(), QQmlJS::Dom::QmlObject::updatePathFromOwner(), wrap(), and wrap().
| Path QQmlJS::Dom::Path::withIndex | ( | index_type | i | ) | const |
Definition at line 365 of file qqmldompath.cpp.
References withComponent().
Definition at line 363 of file qqmldompath.cpp.
References withComponent().
| Path QQmlJS::Dom::Path::withKey | ( | QStringView | name | ) | const |
Definition at line 364 of file qqmldompath.cpp.
Returns a copy of this with toAdd appended to it.
This allocates one node per component of toAdd. If this path is empty, toAdd is returned as is.
Definition at line 375 of file qqmldompath.cpp.
Referenced by QQmlJS::Dom::AstRangesVisitor::addItemRanges(), QQmlJS::Dom::DomElement::canonicalPath(), QQmlJS::Dom::FileLocations::treeOf(), and QQmlJS::Dom::FileLocations::visitTree().
|
friend |
Definition at line 637 of file qqmldompath_p.h.
|
friend |
Definition at line 638 of file qqmldompath_p.h.
|
friend |
Definition at line 469 of file qqmldompath.cpp.
References length().
|
friend |
Definition at line 636 of file qqmldompath_p.h.