Skip to content

Commit 1b6e824

Browse files
authored
Merge pull request #3604 from aTTocs/master
Fix plugin manual generator 'inherits {class}' for final classes
2 parents ea4fde0 + 7553ffd commit 1b6e824

File tree

1 file changed

+34
-21
lines changed

1 file changed

+34
-21
lines changed

manual/genManual.cpp

Lines changed: 34 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,8 @@ static void parseClass(const QString& name, const QString& in)
102102
QRegExp re3("Q_INVOKABLE +([^ ]+) +(\\w+\\([^\\)]*\\))\\s+const\\s*([^\\{]*)\\{");
103103

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

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

@@ -212,6 +212,35 @@ static void scanFile(const QString& in)
212212
}
213213
}
214214

215+
//---------------------------------------------------------
216+
// linkClass
217+
//
218+
// Given something like "array[Note]", will return "array[<a href="note.html">Note</a>]"
219+
//---------------------------------------------------------
220+
static QRegExp reClasses("");
221+
222+
static QString linkClass(const QString& in)
223+
{
224+
if (reClasses.pattern().isEmpty()) {
225+
QStringList classNames;
226+
foreach(const Class& cl, classes)
227+
classNames.append(cl.name);
228+
229+
reClasses.setPattern("\\b(" + classNames.join('|') + ")\\b");
230+
Q_ASSERT(reClasses.isValid());
231+
}
232+
233+
int pos = reClasses.indexIn(in);
234+
if (pos != -1) {
235+
QString out(in);
236+
out.insert(pos + reClasses.matchedLength(), "</a>");
237+
out.insert(pos, "<a href=\"" + in.mid(pos, reClasses.matchedLength()).toLower() + ".html\">");
238+
239+
return out;
240+
}
241+
return in;
242+
}
243+
215244
//---------------------------------------------------------
216245
// writeOutput
217246
//---------------------------------------------------------
@@ -249,27 +278,11 @@ static void writeOutput()
249278
out += "<div class=\"methods\">\n";
250279
foreach(const Proc& p, cl.procs) {
251280
out += "<div class=\"method\">\n";
252-
253-
QString type(p.type);
254-
bool found = false;
255-
if (type.endsWith("*")) {
256-
type = type.left(type.size()-1);
257-
foreach(const Class& cl, classes) {
258-
if (cl.name == type) {
259-
found = true;
260-
break;
261-
}
262-
}
263-
}
264-
if (found)
265-
out += QString("<a href=\"%1.html\">%2</a> ")
266-
.arg(type.toLower()).arg(type);
267-
else
268-
out += QString("%1 ").arg(type);
281+
out += linkClass(p.type) + " ";
269282

270283
QRegExp re("([^(]+)\\(([^)]*)\\)");
271284
if (re.indexIn(p.name, 0) != -1) {
272-
out += QString("<b>%2</b>(%3)\n") .arg(re.cap(1)).arg(re.cap(2));
285+
out += QString("<b>%2</b>(%3)\n") .arg(re.cap(1)).arg(linkClass(re.cap(2)));
273286
}
274287
else {
275288
out += QString("<b>%2</b>\n").arg(p.name);
@@ -296,7 +309,7 @@ static void writeOutput()
296309
out += QString("<td class=\"prop-name\">%1</td>"
297310
"<td class=\"prop-type\">%2</td>"
298311
"<td class=\"prop-desc\">%3</td>")
299-
.arg(m.name).arg(m.type).arg(m.description);
312+
.arg(m.name).arg(linkClass(m.type)).arg(m.description);
300313
out += "</tr>\n";
301314
count++;
302315
}

0 commit comments

Comments
 (0)