qdoc: fix inheritance information for some QML types

This update fixes a bug introduced by the extensive changes
for QTBUG-35377. For a QML base type loaded from an index file,
its QML base type was not being resolved. This resulted in the
"All members" page for some QML types to be incomplete because
the pointer to the base type was 0 when it should have been set.
This change also introduces the concept of "just in time"
resolution for base type pointers, which appears to speed up
qdoc a little.

Task-number: QTBUG-37326
Change-Id: I5f09336ec70ba84029b44b245c56f7f8fe349757
Reviewed-by: Martin Smith <martin.smith@digia.com>
This commit is contained in:
Martin Smith 2014-03-12 10:09:49 +01:00 committed by The Qt Project
parent c55d437d29
commit 900c150a07
16 changed files with 100 additions and 72 deletions

View File

@ -648,7 +648,7 @@ QString CodeMarker::macName(const Node *node, const QString &name)
/*!
Returns an empty list of documentation sections.
*/
QList<Section> CodeMarker::qmlSections(const QmlClassNode* , SynopsisStyle )
QList<Section> CodeMarker::qmlSections(QmlClassNode* , SynopsisStyle )
{
return QList<Section>();
}

View File

@ -154,7 +154,7 @@ public:
virtual QList<Section> sections(const InnerNode *inner,
SynopsisStyle style,
Status status) = 0;
virtual QList<Section> qmlSections(const QmlClassNode* qmlClassNode, SynopsisStyle style);
virtual QList<Section> qmlSections(QmlClassNode* qmlClassNode, SynopsisStyle style);
virtual QStringList macRefsForNode(Node* node);
static void initialize(const Config& config);

View File

@ -1068,7 +1068,7 @@ QString CppCodeMarker::addMarkUp(const QString &in,
the list of documentation sections for the children of the
\a qmlClassNode.
*/
QList<Section> CppCodeMarker::qmlSections(const QmlClassNode* qmlClassNode, SynopsisStyle style)
QList<Section> CppCodeMarker::qmlSections(QmlClassNode* qmlClassNode, SynopsisStyle style)
{
QList<Section> sections;
if (qmlClassNode) {
@ -1109,7 +1109,7 @@ QList<Section> CppCodeMarker::qmlSections(const QmlClassNode* qmlClassNode, Syno
"method",
"methods");
const QmlClassNode* qcn = qmlClassNode;
QmlClassNode* qcn = qmlClassNode;
while (qcn != 0) {
NodeList::ConstIterator c = qcn->childNodes().constBegin();
while (c != qcn->childNodes().constEnd()) {
@ -1148,7 +1148,7 @@ QList<Section> CppCodeMarker::qmlSections(const QmlClassNode* qmlClassNode, Syno
++c;
}
if (qcn->qmlBaseNode() != 0) {
qcn = static_cast<const QmlClassNode*>(qcn->qmlBaseNode());
qcn = static_cast<QmlClassNode*>(qcn->qmlBaseNode());
if (!qcn->isAbstract())
qcn = 0;
}
@ -1174,7 +1174,7 @@ QList<Section> CppCodeMarker::qmlSections(const QmlClassNode* qmlClassNode, Syno
FastSection qmlmethods(qmlClassNode,"Method Documentation","qmlmeth","member","members");
FastSection qmlattachedmethods(qmlClassNode,"Attached Method Documentation","qmlattmeth",
"member","members");
const QmlClassNode* qcn = qmlClassNode;
QmlClassNode* qcn = qmlClassNode;
while (qcn != 0) {
NodeList::ConstIterator c = qcn->childNodes().constBegin();
while (c != qcn->childNodes().constEnd()) {
@ -1212,7 +1212,7 @@ QList<Section> CppCodeMarker::qmlSections(const QmlClassNode* qmlClassNode, Syno
++c;
}
if (qcn->qmlBaseNode() != 0) {
qcn = static_cast<const QmlClassNode*>(qcn->qmlBaseNode());
qcn = static_cast<QmlClassNode*>(qcn->qmlBaseNode());
if (!qcn->isAbstract())
qcn = 0;
}
@ -1234,7 +1234,7 @@ QList<Section> CppCodeMarker::qmlSections(const QmlClassNode* qmlClassNode, Syno
*/
ClassMap* classMap = 0;
FastSection all(qmlClassNode,QString(),QString(),"member","members");
const QmlClassNode* current = qmlClassNode;
QmlClassNode* current = qmlClassNode;
while (current != 0) {
/*
If the QML type is abstract, do not create

View File

@ -78,7 +78,7 @@ public:
virtual QList<Section> sections(const InnerNode *innerNode,
SynopsisStyle style,
Status status);
virtual QList<Section> qmlSections(const QmlClassNode* qmlClassNode, SynopsisStyle style);
virtual QList<Section> qmlSections(QmlClassNode* qmlClassNode, SynopsisStyle style);
private:
QString addMarkUp(const QString& protectedCode,

View File

@ -4026,7 +4026,7 @@ void DitaXmlGenerator::startQmlProperty(QmlPropertyNode* qpn,
writeStartTag(DT_qmlPropertyDetail);
writeStartTag(DT_qmlPropertyDef);
if (!qpn->isReadOnlySet())
qpn->setReadOnly(!qpn->isWritable(qdb_));
qpn->setReadOnly(!qpn->isWritable());
if (qpn->isReadOnly()) {
writeStartTag(DT_qmlQualifier);
xmlWriter().writeAttribute("name","read-only");
@ -4163,11 +4163,11 @@ void DitaXmlGenerator::generateQmlModuleDef(QmlClassNode* qcn)
Output the "Inherits" line for the QML element,
if there should be one.
*/
void DitaXmlGenerator::generateQmlInherits(const QmlClassNode* qcn, CodeMarker* marker)
void DitaXmlGenerator::generateQmlInherits(QmlClassNode* qcn, CodeMarker* marker)
{
if (!qcn)
return;
const QmlClassNode* base = qcn->qmlBaseNode();
QmlClassNode* base = qcn->qmlBaseNode();
while (base && base->isInternal()) {
base = base->qmlBaseNode();
}

View File

@ -402,7 +402,7 @@ private:
void generateDetailedQmlMember(Node* node,
const InnerNode* relative,
CodeMarker* marker);
void generateQmlInherits(const QmlClassNode* qcn, CodeMarker* marker);
void generateQmlInherits(QmlClassNode* qcn, CodeMarker* marker);
void generateQmlInheritedBy(const QmlClassNode* qcn, CodeMarker* marker);
void generateQmlInstantiates(QmlClassNode* qcn, CodeMarker* marker);
void generateInstantiatedBy(ClassNode* cn, CodeMarker* marker);

View File

@ -312,8 +312,8 @@ QString Generator::fileBase(const Node *node) const
node = node->parent();
}
if (node->hasBaseName())
return node->baseName();
if (node->hasFileNameBase())
return node->fileNameBase();
QString base;
if (node->isDocNode()) {
@ -402,7 +402,7 @@ QString Generator::fileBase(const Node *node) const
while (res.endsWith(QLatin1Char('-')))
res.chop(1);
Node* n = const_cast<Node*>(node);
n->setBaseName(res);
n->setFileNameBase(res);
return res;
}
@ -1103,7 +1103,7 @@ void Generator::generateQmlInheritedBy(const QmlClassNode* qcn,
/*!
*/
void Generator::generateQmlInherits(const QmlClassNode* , CodeMarker* )
void Generator::generateQmlInherits(QmlClassNode* , CodeMarker* )
{
// stub.
}

View File

@ -120,7 +120,7 @@ protected:
virtual void generateInnerNode(InnerNode* node);
virtual void generateMaintainerList(const InnerNode* node, CodeMarker* marker);
virtual void generateQmlInheritedBy(const QmlClassNode* qcn, CodeMarker* marker);
virtual void generateQmlInherits(const QmlClassNode* qcn, CodeMarker* marker);
virtual void generateQmlInherits(QmlClassNode* qcn, CodeMarker* marker);
virtual bool generateQmlText(const Text& text,
const Node *relative,
CodeMarker *marker,

View File

@ -2104,7 +2104,7 @@ void HtmlGenerator::generateQmlRequisites(QmlClassNode *qcn, CodeMarker *marker)
}
//add the inherits to the map
const QmlClassNode* base = qcn->qmlBaseNode();
QmlClassNode* base = qcn->qmlBaseNode();
while (base && base->isInternal()) {
base = base->qmlBaseNode();
}
@ -2336,8 +2336,7 @@ QString HtmlGenerator::generateListOfAllMemberFile(const InnerNode *inner,
the members of QML class \a qml_cn, including the inherited
members. The \a marker is used for formatting stuff.
*/
QString HtmlGenerator::generateAllQmlMembersFile(const QmlClassNode* qml_cn,
CodeMarker* marker)
QString HtmlGenerator::generateAllQmlMembersFile(QmlClassNode* qml_cn, CodeMarker* marker)
{
QList<Section> sections;
QList<Section>::ConstIterator s;
@ -4055,7 +4054,7 @@ void HtmlGenerator::generateDetailedQmlMember(Node *node,
out() << "<td class=\"tblQmlPropNode\"><p>";
out() << "<a name=\"" + refForNode(qpn) + "\"></a>";
if (!qpn->isWritable(qdb_))
if (!qpn->isWritable())
out() << "<span class=\"qmlreadonly\">read-only</span>";
if (qpn->isDefault())
out() << "<span class=\"qmldefault\">default</span>";
@ -4076,7 +4075,7 @@ void HtmlGenerator::generateDetailedQmlMember(Node *node,
out() << "<a name=\"" + refForNode(qpn) + "\"></a>";
if (!qpn->isReadOnlySet()) {
if (qpn->declarativeCppNode())
qpn->setReadOnly(!qpn->isWritable(qdb_));
qpn->setReadOnly(!qpn->isWritable());
}
if (qpn->isReadOnly())
out() << "<span class=\"qmlreadonly\">read-only</span>";
@ -4138,11 +4137,11 @@ void HtmlGenerator::generateDetailedQmlMember(Node *node,
Output the "Inherits" line for the QML element,
if there should be one.
*/
void HtmlGenerator::generateQmlInherits(const QmlClassNode* qcn, CodeMarker* marker)
void HtmlGenerator::generateQmlInherits(QmlClassNode* qcn, CodeMarker* marker)
{
if (!qcn)
return;
const QmlClassNode* base = qcn->qmlBaseNode();
QmlClassNode* base = qcn->qmlBaseNode();
while (base && base->isInternal()) {
base = base->qmlBaseNode();
}

View File

@ -153,8 +153,7 @@ private:
QList<Section>* sections = 0);
QString generateListOfAllMemberFile(const InnerNode *inner,
CodeMarker *marker);
QString generateAllQmlMembersFile(const QmlClassNode* qml_cn,
CodeMarker* marker);
QString generateAllQmlMembersFile(QmlClassNode* qml_cn, CodeMarker* marker);
QString generateLowStatusMemberFile(InnerNode *inner,
CodeMarker *marker,
CodeMarker::Status status);
@ -183,7 +182,7 @@ private:
void generateDetailedQmlMember(Node *node,
const InnerNode *relative,
CodeMarker *marker);
void generateQmlInherits(const QmlClassNode* qcn, CodeMarker* marker);
void generateQmlInherits(QmlClassNode* qcn, CodeMarker* marker);
void generateQmlInstantiates(QmlClassNode* qcn, CodeMarker* marker);
void generateInstantiatedBy(ClassNode* cn, CodeMarker* marker);

View File

@ -2062,7 +2062,7 @@ QmlClassNode::QmlClassNode(InnerNode *parent, const QString& name)
wrapper_(false),
cnode_(0),
qmlModule_(0),
baseNode_(0)
qmlBaseNode_(0)
{
int i = 0;
if (name.startsWith("QML:")) {
@ -2134,6 +2134,14 @@ void QmlModuleNode::setQmlModuleInfo(const QString& arg)
}
}
QmlClassNode* QmlClassNode::qmlBaseNode()
{
if (!qmlBaseNode_ && !qmlBaseName_.isEmpty()) {
qmlBaseNode_ = QDocDatabase::qdocDB()->findQmlType(qmlBaseName_);
}
return qmlBaseNode_;
}
/*!
If this QML type node has a base type node,
return the fully qualified name of that QML
@ -2142,8 +2150,8 @@ void QmlModuleNode::setQmlModuleInfo(const QString& arg)
QString QmlClassNode::qmlFullBaseName() const
{
QString result;
if (baseNode_) {
result = baseNode_->qmlModuleName() + "::" + baseNode_->name();
if (qmlBaseNode_) {
result = qmlBaseNode_->qmlModuleName() + "::" + qmlBaseNode_->name();
}
return result;
}
@ -2249,7 +2257,7 @@ QmlPropertyNode::QmlPropertyNode(InnerNode* parent,
...because the tokenizer gets confused on \e{explicit}.
*/
bool QmlPropertyNode::isWritable(QDocDatabase* qdb)
bool QmlPropertyNode::isWritable()
{
if (readOnly_ != FlagValueDefault)
return !fromFlagValue(readOnly_, false);
@ -2258,7 +2266,7 @@ bool QmlPropertyNode::isWritable(QDocDatabase* qdb)
if (qcn) {
if (qcn->cppClassRequired()) {
if (qcn->classNode()) {
PropertyNode* pn = findCorrespondingCppProperty(qdb);
PropertyNode* pn = findCorrespondingCppProperty();
if (pn)
return pn->isWritable();
else
@ -2281,7 +2289,7 @@ bool QmlPropertyNode::isWritable(QDocDatabase* qdb)
Returns a pointer this QML property's corresponding C++
property, if it has one.
*/
PropertyNode* QmlPropertyNode::findCorrespondingCppProperty(QDocDatabase* qdb)
PropertyNode* QmlPropertyNode::findCorrespondingCppProperty()
{
PropertyNode* pn;
Node* n = parent();
@ -2306,7 +2314,7 @@ PropertyNode* QmlPropertyNode::findCorrespondingCppProperty(QDocDatabase* qdb)
*/
if (dotSplit.size() > 1) {
QStringList path(extractClassName(pn->qualifiedDataType()));
Node* nn = qdb->findClassNode(path);
Node* nn = QDocDatabase::qdocDB()->findClassNode(path);
if (nn) {
ClassNode* cn = static_cast<ClassNode*>(nn);
PropertyNode *pn2 = cn->findPropertyNode(dotSplit[1]);

View File

@ -174,10 +174,11 @@ public:
QString plainName() const;
QString plainFullName(const Node* relative = 0) const;
QString fullName(const Node* relative=0) const;
const QString& baseName() const { return baseName_; }
bool hasBaseName() const { return !baseName_.isEmpty(); }
void setBaseName(const QString& bn) { baseName_ = bn; }
const QString& fileNameBase() const { return fileNameBase_; }
bool hasFileNameBase() const { return !fileNameBase_.isEmpty(); }
void setFileNameBase(const QString& t) { fileNameBase_ = t; }
void setAccess(Access access) { access_ = access; }
void setLocation(const Location& location) { loc_ = location; }
void setDoc(const Doc& doc, bool replace = false);
@ -334,7 +335,7 @@ private:
Location loc_;
Doc doc_;
QMap<LinkType, QPair<QString, QString> > linkMap_;
QString baseName_;
QString fileNameBase_;
QString moduleName_;
QString url_;
QString since_;
@ -605,10 +606,11 @@ public:
virtual void setQmlModule(QmlModuleNode* t) { qmlModule_ = t; }
const ImportList& importList() const { return importList_; }
void setImportList(const ImportList& il) { importList_ = il; }
const QString& qmlBaseName() const { return baseName_; }
void setQmlBaseName(const QString& name) { baseName_ = name; }
const QmlClassNode* qmlBaseNode() const { return baseNode_; }
void setQmlBaseNode(QmlClassNode* b) { baseNode_ = b; }
const QString& qmlBaseName() const { return qmlBaseName_; }
void setQmlBaseName(const QString& name) { qmlBaseName_ = name; }
bool qmlBaseNodeNotSet() const { return (qmlBaseNode_ == 0); }
QmlClassNode* qmlBaseNode();
void setQmlBaseNode(QmlClassNode* b) { qmlBaseNode_ = b; }
void requireCppClass() { cnodeRequired_ = true; }
bool cppClassRequired() const { return cnodeRequired_; }
static void addInheritedBy(const QString& base, Node* sub);
@ -624,10 +626,10 @@ private:
bool cnodeRequired_;
bool wrapper_;
ClassNode* cnode_;
QString baseName_;
QString qmlBaseName_;
QString obsoleteLink_;
QmlModuleNode* qmlModule_;
QmlClassNode* baseNode_;
QmlClassNode* qmlBaseNode_;
ImportList importList_;
};
@ -682,7 +684,7 @@ public:
bool isReadOnlySet() const { return (readOnly_ != FlagValueDefault); }
bool isStored() const { return fromFlagValue(stored_,true); }
bool isDesignable() const { return fromFlagValue(designable_,false); }
bool isWritable(QDocDatabase* qdb);
bool isWritable();
virtual bool isDefault() const { return isdefault_; }
virtual bool isReadOnly() const { return fromFlagValue(readOnly_,false); }
virtual bool isAlias() const { return isAlias_; }
@ -697,7 +699,7 @@ public:
const QString& element() const { return static_cast<QmlPropertyGroupNode*>(parent())->element(); }
private:
PropertyNode* findCorrespondingCppProperty(QDocDatabase* qdb);
PropertyNode* findCorrespondingCppProperty();
private:
QString type_;

View File

@ -753,6 +753,18 @@ void QDocDatabase::initializeDB()
list. The parent of \a node is not changed by this function.
*/
/*!
Looks up the QML type node identified by the qualified Qml
type \a name and returns a pointer to the QML type node.
*/
QmlClassNode* QDocDatabase::findQmlType(const QString& name)
{
QmlClassNode* qcn = forest_.lookupQmlType(name);
if (qcn)
return qcn;
return 0;
}
/*!
Looks up the QML type node identified by the Qml module id
\a qmid and QML type \a name and returns a pointer to the
@ -1358,35 +1370,38 @@ const Node* QDocDatabase::findNodeForTarget(const QString& target, const Node* r
*/
void QDocDatabase::resolveQmlInheritance(InnerNode* root)
{
NodeMap previousSearches;
// Do we need recursion?
foreach (Node* child, root->childNodes()) {
if (child->type() == Node::Document && child->subType() == Node::QmlClass) {
QmlClassNode* qcn = static_cast<QmlClassNode*>(child);
if ((qcn->qmlBaseNode() == 0) && !qcn->qmlBaseName().isEmpty()) {
QmlClassNode* bqcn = 0;
if (qcn->qmlBaseName().contains("::")) {
bqcn = forest_.lookupQmlType(qcn->qmlBaseName());
}
else {
const ImportList& imports = qcn->importList();
for (int i=0; i<imports.size(); ++i) {
bqcn = findQmlType(imports[i], qcn->qmlBaseName());
if (bqcn)
break;
}
}
if (bqcn == 0) {
bqcn = findQmlType(QString(), qcn->qmlBaseName());
}
if (bqcn) {
if (qcn->qmlBaseNodeNotSet() && !qcn->qmlBaseName().isEmpty()) {
QmlClassNode* bqcn = static_cast<QmlClassNode*>(previousSearches.value(qcn->qmlBaseName()));
if (bqcn)
qcn->setQmlBaseNode(bqcn);
}
#if 0
else {
qDebug() << "Temporary error message (ignore): UNABLE to resolve QML base type:"
<< qcn->qmlBaseName() << "for QML type:" << qcn->name();
}
if (!qcn->importList().isEmpty()) {
const ImportList& imports = qcn->importList();
for (int i=0; i<imports.size(); ++i) {
bqcn = findQmlType(imports[i], qcn->qmlBaseName());
if (bqcn)
break;
}
}
if (bqcn == 0) {
bqcn = findQmlType(QString(), qcn->qmlBaseName());
}
if (bqcn) {
qcn->setQmlBaseNode(bqcn);
previousSearches.insert(qcn->qmlBaseName(), bqcn);
}
#if 0
else {
qDebug() << "Temporary error message (ignore): UNABLE to resolve QML base type:"
<< qcn->qmlBaseName() << "for QML type:" << qcn->name();
}
#endif
}
}
}
}

View File

@ -256,6 +256,7 @@ class QDocDatabase
void addExampleNode(ExampleNode* n) { primaryTree()->addExampleNode(n); }
ExampleNodeMap& exampleNodeMap() { return primaryTree()->exampleNodeMap(); }
QmlClassNode* findQmlType(const QString& name);
QmlClassNode* findQmlType(const QString& qmid, const QString& name);
QmlClassNode* findQmlType(const ImportRec& import, const QString& name);

View File

@ -218,8 +218,9 @@ void QDocIndexFiles::readIndexSection(const QDomElement& element,
abstract = true;
qcn->setAbstract(abstract);
QString qmlFullBaseName = element.attribute("qml-base-type");
if (!qmlFullBaseName.isEmpty())
if (!qmlFullBaseName.isEmpty()) {
qcn->setQmlBaseName(qmlFullBaseName);
}
if (element.hasAttribute("location"))
name = element.attribute("location", QString());
if (!indexUrl.isEmpty())
@ -628,6 +629,10 @@ void QDocIndexFiles::resolveIndex()
if (n)
relatedPair.first->setRelates(static_cast<ClassNode*>(n));
}
// No longer needed.
basesList_.clear();
relatedList_.clear();
}
/*!
@ -1080,7 +1085,7 @@ bool QDocIndexFiles::generateIndexSection(QXmlStreamWriter& writer,
QmlPropertyNode* qpn = static_cast<QmlPropertyNode*>(node);
writer.writeAttribute("type", qpn->dataType());
writer.writeAttribute("attached", qpn->isAttached() ? "true" : "false");
writer.writeAttribute("writable", qpn->isWritable(qdb_) ? "true" : "false");
writer.writeAttribute("writable", qpn->isWritable() ? "true" : "false");
if (!brief.isEmpty())
writer.writeAttribute("brief", brief);
}

View File

@ -84,7 +84,6 @@ class QDocIndexFiles
QString project_;
QList<QPair<ClassNode*,QString> > basesList_;
QList<QPair<FunctionNode*,QString> > relatedList_;
};
QT_END_NAMESPACE