QQmlSA::PassManager Class

class QQmlSA ::PassManager

Can analyze an element and its children with static analysis passes. 更多...

頭: #include <PassManager>
CMake: find_package(Qt6 REQUIRED COMPONENTS QmlCompiler)
target_link_libraries(mytarget PRIVATE Qt6::QmlCompiler)
狀態: 技術預覽

公共函數

void analyze (const QQmlSA::Element & root )
std::unordered_map<quint32, QQmlSA::Binding> bindingsByLocation () const
bool hasImportedModule (QAnyStringView 模塊 ) const
bool isCategoryEnabled (QQmlSA::LoggerWarningId category ) const
void registerElementPass (std::unique_ptr<QQmlSA::ElementPass> pass )
bool registerPropertyPass (std::shared_ptr<QQmlSA::PropertyPass> pass , QAnyStringView moduleName , QAnyStringView typeName , QAnyStringView propertyName = QAnyStringView(), bool allowInheritance = true)

詳細描述

成員函數文檔編製

void PassManager:: analyze (const QQmlSA::Element & root )

Runs the element passes over root and all its children.

std::unordered_map < quint32 , QQmlSA::Binding > PassManager:: bindingsByLocation () const

Returns bindings by their source location.

bool PassManager:: hasImportedModule ( QAnyStringView 模塊 ) const

返迴 true if the module named module has been imported by the QML to be analyzed, false 否則。

This can be used to skip registering a pass which is specific to a specific module.

if (passManager->hasImportedModule("QtPositioning"))
    passManager->registerElementPass(
       std::make_unique<PositioningPass>(passManager)
    );
					

另請參閱 registerPropertyPass () 和 registerElementPass ().

bool PassManager:: isCategoryEnabled ( QQmlSA::LoggerWarningId category ) const

返迴 true if warnings of category are enabled, false 否則。

void PassManager:: registerElementPass ( std::unique_ptr < QQmlSA::ElementPass > pass )

Registers a static analysis pass to be run on all elements.

bool PassManager:: registerPropertyPass ( std::shared_ptr < QQmlSA::PropertyPass > pass , QAnyStringView moduleName , QAnyStringView typeName , QAnyStringView propertyName = QAnyStringView(), bool allowInheritance = true)

Registers a static analysis pass for properties. The pass will be run on every property matching the moduleName , typeName and propertyName .

省略 propertyName will register this pass for all properties matching the typeName and moduleName .

設置 allowInheritance to true means that the filtering on the type also accepts types deriving from typeName .

pass is passed as a std::shared_ptr to allow reusing the same pass on multiple elements:

auto titleValiadorPass = std::make_shared<TitleValidatorPass>(manager);
manager->registerPropertyPass(titleValidatorPass,
                              "QtQuick", "Window", "title");
manager->registerPropertyPass(titleValidatorPass,
                              "QtQuick.Controls", "Dialog", "title");
					

注意: Running analysis passes on too many items can be expensive. This is why it is generally good to filter down the set of properties of a pass using the moduleName , typeName and propertyName .

返迴 true if the pass was successfully added, false otherwise. Adding a pass fails when the Element 指定通過 moduleName and typeName does not exist.

另請參閱 PropertyPass .