diff options
Diffstat (limited to 'src/qdoc/generator.cpp')
-rw-r--r-- | src/qdoc/generator.cpp | 128 |
1 files changed, 83 insertions, 45 deletions
diff --git a/src/qdoc/generator.cpp b/src/qdoc/generator.cpp index 19af09209..dde1de496 100644 --- a/src/qdoc/generator.cpp +++ b/src/qdoc/generator.cpp @@ -251,30 +251,49 @@ void Generator::writeOutFileNames() } /*! - Creates the file named \a fileName in the output directory. - Attaches a QTextStream to the created file, which is written - to all over the place using out(). This function does not - store the \a fileName in the \a node as the output file name. + Creates the file named \a fileName in the output directory + and returns a QFile pointing to this file. In particular, + this method deals with errors when opening the file: + the returned QFile is always valid and can be written to. - \sa beginSubPage() + \sa beginFilePage() */ -void Generator::beginFilePage(const Node *node, const QString &fileName) +QFile *Generator::openSubPageFile(const Node *node, const QString &fileName) { QString path = outputDir() + QLatin1Char('/'); if (Generator::useOutputSubdirs() && !node->outputSubdirectory().isEmpty() && - !outputDir().endsWith(node->outputSubdirectory())) + !outputDir().endsWith(node->outputSubdirectory())) { path += node->outputSubdirectory() + QLatin1Char('/'); + } path += fileName; - QFile* outFile = new QFile(redirectDocumentationToDevNull_ ? QStringLiteral("/dev/null") : path); - if (!redirectDocumentationToDevNull_ && outFile->exists()) - node->location().error(tr("Output file already exists; overwriting %1").arg(outFile->fileName())); - if (!outFile->open(QFile::WriteOnly)) - node->location().fatal(tr("Cannot open output file '%1'").arg(outFile->fileName())); + auto outPath = redirectDocumentationToDevNull_ ? QStringLiteral("/dev/null") : path; + auto outFile = new QFile(outPath); + if (!redirectDocumentationToDevNull_ && outFile->exists()) { + node->location().error( + tr("Output file already exists; overwriting %1").arg(outFile->fileName())); + } + if (!outFile->open(QFile::WriteOnly)) { + node->location().fatal( + tr("Cannot open output file '%1'").arg(outFile->fileName())); + } qCDebug(lcQdoc, "Writing: %s", qPrintable(path)); outFileNames_ << fileName; - QTextStream* out = new QTextStream(outFile); + return outFile; +} +/*! + Creates the file named \a fileName in the output directory. + Attaches a QTextStream to the created file, which is written + to all over the place using out(). This function does not + store the \a fileName in the \a node as the output file name. + + \sa beginSubPage() + */ +void Generator::beginFilePage(const Node *node, const QString &fileName) +{ + QFile *outFile = openSubPageFile(node, fileName); + QTextStream* out = new QTextStream(outFile); #ifndef QT_NO_TEXTCODEC if (outputCodec) out->setCodec(outputCodec); @@ -1014,6 +1033,25 @@ void Generator::generateLinkToExample(const ExampleNode *en, generateText(text, nullptr, marker); } +void Generator::addImageToCopy(const ExampleNode *en, const QString &file) +{ + QDir dirInfo; + QString userFriendlyFilePath; + const QString prefix("/images/used-in-examples/"); + QString srcPath = Config::findFile(en->location(), + QStringList(), + exampleDirs, + file, + exampleImgExts, + &userFriendlyFilePath); + outFileNames_ << prefix.mid(1) + userFriendlyFilePath; + userFriendlyFilePath.truncate(userFriendlyFilePath.lastIndexOf('/')); + QString imgOutDir = outDir_ + prefix + userFriendlyFilePath; + if (!dirInfo.mkpath(imgOutDir)) + en->location().fatal(tr("Cannot create output directory '%1'").arg(imgOutDir)); + Config::copyFile(en->location(), srcPath, file, imgOutDir); +} + /*! This function is called when the documentation for an example is being formatted. It outputs a list of files for the example, which @@ -1045,26 +1083,9 @@ void Generator::generateFileList(const ExampleNode *en, CodeMarker *marker, bool QString path; for (const auto &file : qAsConst(paths)) { if (images) { - if (!file.isEmpty()) { - QDir dirInfo; - QString userFriendlyFilePath; - const QString prefix("/images/used-in-examples/"); - QString srcPath = Config::findFile(en->location(), - QStringList(), - exampleDirs, - file, - exampleImgExts, - &userFriendlyFilePath); - outFileNames_ << prefix.mid(1) + userFriendlyFilePath; - userFriendlyFilePath.truncate(userFriendlyFilePath.lastIndexOf('/')); - QString imgOutDir = outDir_ + prefix + userFriendlyFilePath; - if (!dirInfo.mkpath(imgOutDir)) - en->location().fatal(tr("Cannot create output directory '%1'").arg(imgOutDir)); - Config::copyFile(en->location(), srcPath, file, imgOutDir); - } - - } - else { + if (!file.isEmpty()) + addImageToCopy(en, file); + } else { generateExampleFilePage(en, file, marker); } @@ -1476,15 +1497,15 @@ bool Generator::generateText(const Text &text, nonreentrant, and true is returned. If there are no exceptions, the three node lists remain empty and false is returned. */ -static bool hasExceptions(const Node *node, - NodeList &reentrant, - NodeList &threadsafe, - NodeList &nonreentrant) +bool Generator::hasExceptions(const Node *node, + NodeList &reentrant, + NodeList &threadsafe, + NodeList &nonreentrant) { bool result = false; Node::ThreadSafeness ts = node->threadSafeness(); const NodeList &children = static_cast<const Aggregate *>(node)->childNodes(); - for (auto *child : children) { + for (auto child : children) { if (!child->isObsolete()){ switch (child->threadSafeness()) { case Node::Reentrant: @@ -1632,15 +1653,16 @@ void Generator::generateThreadSafeness(const Node *node, CodeMarker *marker) } /*! - If the node is an overloaded signal, add a node with an example on how to connect to it + Returns the string containing an example code of the input node, + if it is an overloaded signal. Otherwise, returns an empty string. */ -void Generator::generateOverloadedSignal(const Node *node, CodeMarker *marker) +QString Generator::getOverloadedSignalCode(const Node *node) { if (!node->isFunction()) - return; - const FunctionNode *func = static_cast<const FunctionNode *>(node); + return QString(); + const auto func = static_cast<const FunctionNode *>(node); if (!func->isSignal() || !func->hasOverloads()) - return; + return QString(); // Compute a friendly name for the object of that instance. // e.g: "QAbstractSocket" -> "abstractSocket" @@ -1661,6 +1683,22 @@ void Generator::generateOverloadedSignal(const Node *node, CodeMarker *marker) code += func->parameters().generateTypeAndNameList(); code += "){ /* ... */ });"; + return code; +} + +/*! + If the node is an overloaded signal, and a node with an example on how to connect to it + + Someone didn't finish writing this comment, and I don't know what this + function is supposed to do, so I have not tried to complete the comment + yet. + */ +void Generator::generateOverloadedSignal(const Node *node, CodeMarker *marker) +{ + QString code = getOverloadedSignalCode(node); + if (code.isEmpty()) + return; + Text text; text << Atom::ParaLeft << Atom(Atom::FormattingLeft, ATOM_FORMATTING_BOLD) @@ -1674,7 +1712,7 @@ void Generator::generateOverloadedSignal(const Node *node, CodeMarker *marker) "To connect to this signal by using the function pointer syntax, Qt " "provides a convenient helper for obtaining the function pointer as " "shown in this example:" - << Atom(Atom::Code, marker->markedUpCode(code, node, func->location())); + << Atom(Atom::Code, marker->markedUpCode(code, node, node->location())); generateText(text, node, marker); } @@ -2261,7 +2299,7 @@ QString Generator::typeString(const Node *node) case Node::Typedef: return "typedef"; case Node::Function: { - const FunctionNode *fn = static_cast<const FunctionNode *>(node); + const auto fn = static_cast<const FunctionNode *>(node); switch (fn->metaness()) { case FunctionNode::JsSignal: case FunctionNode::QmlSignal: |