demos/qtdemo/examplecontent.cpp
changeset 33 3e2da88830cd
parent 18 2f34d5167611
child 37 758a864f9613
equal deleted inserted replaced
30:5dc02b23752f 33:3e2da88830cd
    77 }
    77 }
    78 
    78 
    79 QString ExampleContent::loadDescription()
    79 QString ExampleContent::loadDescription()
    80 {
    80 {
    81     QByteArray ba = MenuManager::instance()->getHtml(this->name);
    81     QByteArray ba = MenuManager::instance()->getHtml(this->name);
       
    82     QString errorMsg;
       
    83     int errorLine, errorColumn;
    82 
    84 
    83     QDomDocument exampleDoc;
    85     QDomDocument exampleDoc;
    84     exampleDoc.setContent(ba, false);
    86     if (!exampleDoc.setContent(ba, false, &errorMsg, &errorLine, &errorColumn)) {
       
    87         qDebug() << errorMsg << errorLine << errorColumn;
       
    88     }
    85 
    89 
    86     QDomNodeList paragraphs = exampleDoc.elementsByTagName("p");
    90     QDomNodeList paragraphs = exampleDoc.elementsByTagName("p");
    87     if (paragraphs.length() < 1 && Colors::verbose)
    91     if (paragraphs.length() < 1 && Colors::verbose)
    88         qDebug() << "- ExampleContent::loadDescription(): Could not load description:" << MenuManager::instance()->info[this->name]["docfile"];
    92         qDebug() << "- ExampleContent::loadDescription(): Could not load description:"
    89     QString description = Colors::contentColor + QLatin1String("Could not load description. Ensure that the documentation for Qt is built.");
    93                  << MenuManager::instance()->info[this->name]["docfile"];
       
    94     QString description = Colors::contentColor +
       
    95         QLatin1String("Could not load description. Ensure that the documentation for Qt is built.");
    90     for (int p = 0; p < int(paragraphs.length()); ++p) {
    96     for (int p = 0; p < int(paragraphs.length()); ++p) {
    91         description = this->extractTextFromParagraph(paragraphs.item(p));
    97         description = this->extractTextFromParagraph(paragraphs.item(p));
    92         if (this->isSummary(description)) {
    98         if (this->isSummary(description)) {
    93             break;
    99             break;
    94         }
   100         }
    97 }
   103 }
    98 
   104 
    99 bool ExampleContent::isSummary(const QString &text)
   105 bool ExampleContent::isSummary(const QString &text)
   100 {
   106 {
   101     return (!text.contains("[") &&
   107     return (!text.contains("[") &&
   102         text.indexOf(QRegExp(QString("(In )?((The|This) )?(%1 )?.*(tutorial|example|demo|application)").arg(this->name), Qt::CaseInsensitive)) != -1);
   108         text.indexOf(QRegExp(QString("(In )?((The|This) )?(%1 )?.*(tutorial|example|demo|application)").arg(this->name),
       
   109                              Qt::CaseInsensitive)) != -1);
   103 }
   110 }
   104 
   111 
   105 QString ExampleContent::extractTextFromParagraph(const QDomNode &parentNode)
   112 QString ExampleContent::extractTextFromParagraph(const QDomNode &parentNode)
   106 {
   113 {
   107     QString description;
   114     QString description;