Ask the HelpEngine for documentation about builtin QML components.

Done with: Erik
This commit is contained in:
Roberto Raggi
2010-01-27 14:56:22 +01:00
parent 39c2575ab3
commit a658ee55f2
3 changed files with 45 additions and 34 deletions

View File

@@ -193,7 +193,12 @@ bool Bind::visit(UiImport *ast)
} }
} }
namespaceObject->setProperty(userComponent->componentName(), objectValue); const QString componentName = userComponent->componentName();
if (! componentName.isEmpty()) {
objectValue->setClassName(componentName);
namespaceObject->setProperty(componentName, objectValue);
}
} }
} }
} }

View File

@@ -146,6 +146,11 @@ void QmlHoverHandler::updateHelpIdAndTooltip(TextEditor::ITextEditor *editor, in
if (qmlDocument.isNull()) if (qmlDocument.isNull())
return; return;
if (m_helpEngineNeedsSetup && m_helpEngine->registeredDocumentations().count() > 0) {
m_helpEngine->setupData();
m_helpEngineNeedsSetup = false;
}
QTextCursor tc(edit->document()); QTextCursor tc(edit->document());
tc.setPosition(pos); tc.setPosition(pos);
@@ -165,7 +170,7 @@ void QmlHoverHandler::updateHelpIdAndTooltip(TextEditor::ITextEditor *editor, in
bool stop = false; bool stop = false;
while (!stop) { while (!stop) {
const QChar ch = editor->characterAt(tc.position()); const QChar ch = editor->characterAt(tc.position());
if (ch.isLetterOrNumber() || ch == QLatin1Char('_') || ch == QLatin1Char('.')) { if (ch.isLetterOrNumber() || ch == QLatin1Char('_')) {
tc.setPosition(tc.position() + 1); tc.setPosition(tc.position() + 1);
} else { } else {
stop = true; stop = true;
@@ -189,61 +194,60 @@ void QmlHoverHandler::updateHelpIdAndTooltip(TextEditor::ITextEditor *editor, in
Interpreter::ObjectValue *scope = bind(declaringMember); Interpreter::ObjectValue *scope = bind(declaringMember);
Check check(&interp); Check check(&interp);
const Interpreter::Value *value = check(expression, scope); const Interpreter::Value *value = check(expression, scope);
m_toolTip = prettyPrint(value, &interp); QStringList baseClasses;
m_toolTip = prettyPrint(value, &interp, &baseClasses);
foreach (const QString &baseClass, baseClasses) {
QString helpId = QLatin1String("QML.");
helpId += baseClass;
#if 0 if (! m_helpEngine->linksForIdentifier(helpId).isEmpty()) {
QmlLookupContext context(expressionUnderCursor.expressionScopes(), doc, m_modelManager->snapshot(), typeSystem); m_helpId = helpId;
QmlResolveExpression resolver(context); break;
Symbol *resolvedSymbol = resolver.typeOf(expressionUnderCursor.expressionNode());
if (resolvedSymbol) {
symbolName = resolvedSymbol->name();
if (resolvedSymbol->isBuildInSymbol())
m_helpId = buildHelpId(resolvedSymbol);
else if (SymbolFromFile *symbolFromFile = resolvedSymbol->asSymbolFromFile())
m_toolTip = symbolFromFile->fileName();
} }
#endif
} }
if (m_helpEngineNeedsSetup && m_helpEngine->registeredDocumentations().count() > 0) {
m_helpEngine->setupData();
m_helpEngineNeedsSetup = false;
} }
if (!m_toolTip.isEmpty()) if (!m_toolTip.isEmpty())
m_toolTip = Qt::escape(m_toolTip); m_toolTip = Qt::escape(m_toolTip);
if (!m_helpId.isEmpty() && !m_helpEngine->linksForIdentifier(m_helpId).isEmpty()) { if (!m_helpId.isEmpty()) {
if (showF1) { if (showF1) {
m_toolTip = QString(QLatin1String("<table><tr><td valign=middle><nobr>%1</td>" m_toolTip = QString::fromUtf8("<table><tr><td valign=middle><nobr>%1</td>"
"<td><img src=\":/cppeditor/images/f1.svg\"></td></tr></table>")) "<td><img src=\":/cppeditor/images/f1.svg\"></td></tr></table>")
.arg(m_toolTip); .arg(m_toolTip);
} }
editor->setContextHelpId(m_helpId); editor->setContextHelpId(m_helpId);
} else if (!m_toolTip.isEmpty()) { } else if (!m_toolTip.isEmpty()) {
m_toolTip = QString(QLatin1String("<nobr>%1")).arg(m_toolTip); m_toolTip = QString::fromUtf8("<nobr>%1").arg(m_toolTip);
} else if (!m_helpId.isEmpty()) { } else if (!m_helpId.isEmpty()) {
m_toolTip = QString(QLatin1String("<nobr>No help available for \"%1\"")).arg(symbolName); m_toolTip = QString::fromUtf8("<nobr>No help available for \"%1\"").arg(symbolName);
} }
} }
QString QmlHoverHandler::prettyPrint(const QmlJS::Interpreter::Value *value, QmlJS::Interpreter::Engine *interp) const QString QmlHoverHandler::prettyPrint(const QmlJS::Interpreter::Value *value, QmlJS::Interpreter::Engine *interp,
QStringList *baseClasses) const
{ {
if (!value) if (!value)
return QString(); return QString();
if (const Interpreter::ObjectValue *objectValue = value->asObjectValue()) { if (const Interpreter::ObjectValue *objectValue = value->asObjectValue()) {
QString className = objectValue->className(); do {
const QString className = objectValue->className();
if (! className.isEmpty())
baseClasses->append(className);
while (objectValue && objectValue->prototype() && className.isEmpty()) {
objectValue = objectValue->prototype(); objectValue = objectValue->prototype();
className = objectValue->className(); } while (objectValue);
if (! baseClasses->isEmpty())
return baseClasses->first();
} }
return className; QString typeId = interp->typeId(value);
}
return interp->typeId(value); if (typeId.isEmpty() || typeId == QLatin1String("undefined"))
typeId = QLatin1String("Unknown");
return typeId;
} }

View File

@@ -37,6 +37,7 @@
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
class QHelpEngineCore; class QHelpEngineCore;
class QPoint; class QPoint;
class QStringList;
QT_END_NAMESPACE QT_END_NAMESPACE
namespace Core { namespace Core {
@@ -73,7 +74,8 @@ private slots:
private: private:
void updateHelpIdAndTooltip(TextEditor::ITextEditor *editor, int pos); void updateHelpIdAndTooltip(TextEditor::ITextEditor *editor, int pos);
QString prettyPrint(const QmlJS::Interpreter::Value *value, QmlJS::Interpreter::Engine *interp) const; QString prettyPrint(const QmlJS::Interpreter::Value *value, QmlJS::Interpreter::Engine *interp,
QStringList *baseClasses) const;
private: private:
QmlModelManagerInterface *m_modelManager; QmlModelManagerInterface *m_modelManager;