Skip to content

Commit

Permalink
Merge pull request #3604 from aTTocs/master
Browse files Browse the repository at this point in the history
Fix plugin manual generator 'inherits {class}' for final classes
  • Loading branch information
lasconic committed Apr 5, 2018
2 parents ea4fde0 + 7553ffd commit 1b6e824
Showing 1 changed file with 34 additions and 21 deletions.
55 changes: 34 additions & 21 deletions manual/genManual.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ static void parseClass(const QString& name, const QString& in)
QRegExp re3("Q_INVOKABLE +([^ ]+) +(\\w+\\([^\\)]*\\))\\s+const\\s*([^\\{]*)\\{");

QRegExp reD("//@ (.*)");
QRegExp re4 ("class +(\\w+) *: *public +(\\w+) *\\{");
QRegExp re4b("class +(\\w+) *: *public +(\\w+), *public");
QRegExp re4 ("class +(\\w+) *(?:final)* *: *public +(\\w+) *\\{");
QRegExp re4b("class +(\\w+) *(?:final)* *: *public +(\\w+), *public");

Q_ASSERT(re1.isValid() && re2.isValid() && re3.isValid());

Expand Down Expand Up @@ -212,6 +212,35 @@ static void scanFile(const QString& in)
}
}

//---------------------------------------------------------
// linkClass
//
// Given something like "array[Note]", will return "array[<a href="note.html">Note</a>]"
//---------------------------------------------------------
static QRegExp reClasses("");

static QString linkClass(const QString& in)
{
if (reClasses.pattern().isEmpty()) {
QStringList classNames;
foreach(const Class& cl, classes)
classNames.append(cl.name);

reClasses.setPattern("\\b(" + classNames.join('|') + ")\\b");
Q_ASSERT(reClasses.isValid());
}

int pos = reClasses.indexIn(in);
if (pos != -1) {
QString out(in);
out.insert(pos + reClasses.matchedLength(), "</a>");
out.insert(pos, "<a href=\"" + in.mid(pos, reClasses.matchedLength()).toLower() + ".html\">");

return out;
}
return in;
}

//---------------------------------------------------------
// writeOutput
//---------------------------------------------------------
Expand Down Expand Up @@ -249,27 +278,11 @@ static void writeOutput()
out += "<div class=\"methods\">\n";
foreach(const Proc& p, cl.procs) {
out += "<div class=\"method\">\n";

QString type(p.type);
bool found = false;
if (type.endsWith("*")) {
type = type.left(type.size()-1);
foreach(const Class& cl, classes) {
if (cl.name == type) {
found = true;
break;
}
}
}
if (found)
out += QString("<a href=\"%1.html\">%2</a> ")
.arg(type.toLower()).arg(type);
else
out += QString("%1 ").arg(type);
out += linkClass(p.type) + " ";

QRegExp re("([^(]+)\\(([^)]*)\\)");
if (re.indexIn(p.name, 0) != -1) {
out += QString("<b>%2</b>(%3)\n") .arg(re.cap(1)).arg(re.cap(2));
out += QString("<b>%2</b>(%3)\n") .arg(re.cap(1)).arg(linkClass(re.cap(2)));
}
else {
out += QString("<b>%2</b>\n").arg(p.name);
Expand All @@ -296,7 +309,7 @@ static void writeOutput()
out += QString("<td class=\"prop-name\">%1</td>"
"<td class=\"prop-type\">%2</td>"
"<td class=\"prop-desc\">%3</td>")
.arg(m.name).arg(m.type).arg(m.description);
.arg(m.name).arg(linkClass(m.type)).arg(m.description);
out += "</tr>\n";
count++;
}
Expand Down

0 comments on commit 1b6e824

Please sign in to comment.