forked from qt-creator/qt-creator
QmlJsEditor: navigate from QML code to C++ code
Fixes: QTCREATORBUG-28086 Change-Id: I00acfe49b8e74aa057cb59d8c951d477f8ad487e Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
This commit is contained in:
committed by
Xavier BESSON (Personal)
parent
42c1b15874
commit
90368e2bba
@@ -269,6 +269,11 @@ QString FakeMetaObject::className() const
|
|||||||
void FakeMetaObject::setClassName(const QString &name)
|
void FakeMetaObject::setClassName(const QString &name)
|
||||||
{ m_className = name; }
|
{ m_className = name; }
|
||||||
|
|
||||||
|
QString FakeMetaObject::filePath() const
|
||||||
|
{ return m_filePath; }
|
||||||
|
void FakeMetaObject::setFilePath(const QString &path)
|
||||||
|
{ m_filePath = path; }
|
||||||
|
|
||||||
void FakeMetaObject::addExport(const QString &name, const QString &package, ComponentVersion version)
|
void FakeMetaObject::addExport(const QString &name, const QString &package, ComponentVersion version)
|
||||||
{
|
{
|
||||||
Export exp;
|
Export exp;
|
||||||
|
|||||||
@@ -139,6 +139,7 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
QString m_className;
|
QString m_className;
|
||||||
|
QString m_filePath;
|
||||||
QList<Export> m_exports;
|
QList<Export> m_exports;
|
||||||
QString m_superName;
|
QString m_superName;
|
||||||
QList<FakeMetaEnum> m_enums;
|
QList<FakeMetaEnum> m_enums;
|
||||||
@@ -160,6 +161,9 @@ public:
|
|||||||
QString className() const;
|
QString className() const;
|
||||||
void setClassName(const QString &name);
|
void setClassName(const QString &name);
|
||||||
|
|
||||||
|
QString filePath() const;
|
||||||
|
void setFilePath(const QString &path);
|
||||||
|
|
||||||
void addExport(const QString &name, const QString &package, ComponentVersion version);
|
void addExport(const QString &name, const QString &package, ComponentVersion version);
|
||||||
void setExportMetaObjectRevision(int exportIndex, int metaObjectRevision);
|
void setExportMetaObjectRevision(int exportIndex, int metaObjectRevision);
|
||||||
const QList<Export> exports() const;
|
const QList<Export> exports() const;
|
||||||
|
|||||||
@@ -251,6 +251,14 @@ const CppComponentValue *CppComponentValue::asCppComponentValue() const
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool CppComponentValue::getSourceLocation(Utils::FilePath *fileName, int *line, int *column) const
|
||||||
|
{
|
||||||
|
*fileName = Utils::FilePath::fromString(m_metaObject->filePath());
|
||||||
|
*line = 0;
|
||||||
|
*column = 0;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
void CppComponentValue::processMembers(MemberProcessor *processor) const
|
void CppComponentValue::processMembers(MemberProcessor *processor) const
|
||||||
{
|
{
|
||||||
// process the meta enums
|
// process the meta enums
|
||||||
|
|||||||
@@ -573,6 +573,8 @@ public:
|
|||||||
|
|
||||||
const CppComponentValue *asCppComponentValue() const override;
|
const CppComponentValue *asCppComponentValue() const override;
|
||||||
|
|
||||||
|
bool getSourceLocation(Utils::FilePath *fileName, int *line, int *column) const override;
|
||||||
|
|
||||||
void processMembers(MemberProcessor *processor) const override;
|
void processMembers(MemberProcessor *processor) const override;
|
||||||
const Value *valueForCppName(const QString &typeName) const;
|
const Value *valueForCppName(const QString &typeName) const;
|
||||||
|
|
||||||
|
|||||||
@@ -197,6 +197,8 @@ void TypeDescriptionReader::readComponent(UiObjectDefinition *ast)
|
|||||||
QString name = toString(script->qualifiedId);
|
QString name = toString(script->qualifiedId);
|
||||||
if (name == QLatin1String("name")) {
|
if (name == QLatin1String("name")) {
|
||||||
fmo->setClassName(readStringBinding(script));
|
fmo->setClassName(readStringBinding(script));
|
||||||
|
} else if (name == QLatin1String("file")) {
|
||||||
|
fmo->setFilePath(readStringBinding(script));
|
||||||
} else if (name == QLatin1String("prototype")) {
|
} else if (name == QLatin1String("prototype")) {
|
||||||
fmo->setSuperclassName(readStringBinding(script));
|
fmo->setSuperclassName(readStringBinding(script));
|
||||||
} else if (name == QLatin1String("defaultProperty")) {
|
} else if (name == QLatin1String("defaultProperty")) {
|
||||||
|
|||||||
@@ -789,13 +789,18 @@ void QmlJSEditorWidget::findLinkAt(const QTextCursor &cursor,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const ProjectExplorer::Project * const project = ProjectExplorer::ProjectTree::currentProject();
|
||||||
|
ProjectExplorer::ProjectNode* projectRootNode = nullptr;
|
||||||
|
if (project) {
|
||||||
|
projectRootNode = project->rootProjectNode();
|
||||||
|
}
|
||||||
|
|
||||||
// string literals that could refer to a file link to them
|
// string literals that could refer to a file link to them
|
||||||
if (auto literal = cast<const StringLiteral *>(node)) {
|
if (auto literal = cast<const StringLiteral *>(node)) {
|
||||||
const QString &text = literal->value.toString();
|
const QString &text = literal->value.toString();
|
||||||
if (text.startsWith("qrc:/")) {
|
if (text.startsWith("qrc:/")) {
|
||||||
const ProjectExplorer::Project * const project = ProjectExplorer::ProjectTree::currentProject();
|
if (projectRootNode) {
|
||||||
if (project && project->rootProjectNode()) {
|
const ProjectExplorer::Node * const nodeForPath = projectRootNode->findNode(
|
||||||
const ProjectExplorer::Node * const nodeForPath = project->rootProjectNode()->findNode(
|
|
||||||
[qrcPath = text.mid(text.indexOf(':') + 1)](ProjectExplorer::Node *n) {
|
[qrcPath = text.mid(text.indexOf(':') + 1)](ProjectExplorer::Node *n) {
|
||||||
if (!n->asFileNode())
|
if (!n->asFileNode())
|
||||||
return false;
|
return false;
|
||||||
@@ -854,14 +859,33 @@ void QmlJSEditorWidget::findLinkAt(const QTextCursor &cursor,
|
|||||||
|
|
||||||
if (auto q = AST::cast<const AST::UiQualifiedId *>(node)) {
|
if (auto q = AST::cast<const AST::UiQualifiedId *>(node)) {
|
||||||
for (const AST::UiQualifiedId *tail = q; tail; tail = tail->next) {
|
for (const AST::UiQualifiedId *tail = q; tail; tail = tail->next) {
|
||||||
if (! tail->next && cursorPosition <= tail->identifierToken.end()) {
|
if (tail->next || !(cursorPosition <= tail->identifierToken.end())) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
link.linkTextStart = tail->identifierToken.begin();
|
link.linkTextStart = tail->identifierToken.begin();
|
||||||
link.linkTextEnd = tail->identifierToken.end();
|
link.linkTextEnd = tail->identifierToken.end();
|
||||||
|
|
||||||
|
if (!value->asCppComponentValue() || !projectRootNode) {
|
||||||
processLinkCallback(link);
|
processLinkCallback(link);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
const ProjectExplorer::Node * const nodeForPath = projectRootNode->findNode(
|
||||||
|
[&fileName](ProjectExplorer::Node *n) {
|
||||||
|
const auto fileNode = n->asFileNode();
|
||||||
|
if (!fileNode)
|
||||||
|
return false;
|
||||||
|
Utils::FilePath filePath = n->filePath();
|
||||||
|
return filePath.endsWith(fileName.toUserOutput());
|
||||||
|
});
|
||||||
|
if (nodeForPath) {
|
||||||
|
link.targetFilePath = nodeForPath->filePath();
|
||||||
|
processLinkCallback(link);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// else we will process an empty link below to avoid an error dialog
|
||||||
|
}
|
||||||
} else if (auto id = AST::cast<const AST::IdentifierExpression *>(node)) {
|
} else if (auto id = AST::cast<const AST::IdentifierExpression *>(node)) {
|
||||||
link.linkTextStart = id->firstSourceLocation().begin();
|
link.linkTextStart = id->firstSourceLocation().begin();
|
||||||
link.linkTextEnd = id->lastSourceLocation().end();
|
link.linkTextEnd = id->lastSourceLocation().end();
|
||||||
|
|||||||
Reference in New Issue
Block a user