Changeset 846 for trunk/tools/assistant/lib/qhelpgenerator.cpp
- Timestamp:
- May 5, 2011, 5:36:53 AM (14 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
- Property svn:mergeinfo changed
/branches/vendor/nokia/qt/4.7.2 (added) merged: 845 /branches/vendor/nokia/qt/current merged: 844 /branches/vendor/nokia/qt/4.6.3 removed
- Property svn:mergeinfo changed
-
trunk/tools/assistant/lib/qhelpgenerator.cpp
r769 r846 1 1 /**************************************************************************** 2 2 ** 3 ** Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). 4 4 ** All rights reserved. 5 5 ** Contact: Nokia Corporation (qt-info@nokia.com) … … 48 48 #include <QtCore/QDir> 49 49 #include <QtCore/QDebug> 50 #include <QtCore/QSet> 50 51 #include <QtCore/QVariant> 51 52 #include <QtCore/QDateTime> … … 190 191 return false; 191 192 } 193 194 d->query->exec(QLatin1String("PRAGMA synchronous=OFF")); 195 d->query->exec(QLatin1String("PRAGMA cache_size=3000")); 192 196 193 197 addProgress(1.0); … … 538 542 539 543 int fileId = -1; 540 if (!d->fileMap.contains(fileName)) { 544 QMap<QString, int>::Iterator fileMapIt = d->fileMap.find(fileName); 545 if (fileMapIt == d->fileMap.end()) { 541 546 fileDataList.append(qCompress(data)); 542 547 … … 552 557 ++tableFileId; 553 558 } else { 554 fileId = d->fileMap.value(fileName); 559 fileId = fileMapIt.value(); 560 QSet<int> &fileFilterSet = d->fileFilterMap[fileId]; 561 QSet<int> &tmpFileFilterSet = tmpFileFilterMap[fileId]; 555 562 foreach (const int &filter, filterAtts) { 556 if (! d->fileFilterMap.value(fileId).contains(filter)557 && !tmpFileFilter Map.value(fileId).contains(filter)) {558 d->fileFilterMap[fileId].insert(filter);559 tmpFileFilterMap[fileId].insert(filter);563 if (!fileFilterSet.contains(filter) 564 && !tmpFileFilterSet.contains(filter)) { 565 fileFilterSet.insert(filter); 566 tmpFileFilterSet.insert(filter); 560 567 } 561 568 } … … 563 570 } 564 571 565 if ( tmpFileFilterMap.count()) {572 if (!tmpFileFilterMap.isEmpty()) { 566 573 d->query->exec(QLatin1String("BEGIN")); 567 574 QMap<int, QSet<int> >::const_iterator it = tmpFileFilterMap.constBegin(); … … 626 633 attributeMap.insert(d->query->value(1).toString(), 627 634 d->query->value(0).toInt()); 628 if (idsToInsert.contains(d->query->value(1).toString())) 629 idsToInsert.removeAll(d->query->value(1).toString()); 635 idsToInsert.removeAll(d->query->value(1).toString()); 630 636 } 631 637 … … 675 681 } 676 682 677 bool QHelpGenerator::insertKeywords(const QList<QHelpDataIndexItem> keywords,683 bool QHelpGenerator::insertKeywords(const QList<QHelpDataIndexItem> &keywords, 678 684 const QStringList &filterAttributes) 679 685 { … … 705 711 int i = 0; 706 712 d->query->exec(QLatin1String("BEGIN")); 713 QSet<QString> indices; 707 714 foreach (const QHelpDataIndexItem &itm, keywords) { 715 // Identical ids make no sense and just confuse the Assistant user, 716 // so we ignore all repetitions. 717 if (indices.contains(itm.identifier)) 718 continue; 719 720 // Still empty ids should be ignored, as otherwise we will include only 721 // the first keyword with an empty id. 722 if (!itm.identifier.isEmpty()) 723 indices.insert(itm.identifier); 724 708 725 pos = itm.reference.indexOf(QLatin1Char('#')); 709 726 fileName = itm.reference.left(pos); … … 717 734 fName = fName.mid(2); 718 735 719 if (d->fileMap.contains(fName)) 720 fileId = d->fileMap.value(fName); 736 QMap<QString, int>::ConstIterator it = d->fileMap.find(fName); 737 if (it != d->fileMap.end()) 738 fileId = it.value(); 721 739 else 722 740 fileId = 1; … … 750 768 751 769 d->query->exec(QLatin1String("SELECT COUNT(Id) FROM IndexTable")); 752 if (d->query->next() && d->query->value(0).toInt() >= keywords.count())770 if (d->query->next() && d->query->value(0).toInt() >= indices.count()) 753 771 return true; 754 772 return false; … … 825 843 } 826 844 845 bool QHelpGenerator::checkLinks(const QHelpDataInterface &helpData) 846 { 847 /* 848 * Step 1: Gather the canoncal file paths of all files in the project. 849 * We use a set, because there will be a lot of look-ups. 850 */ 851 QSet<QString> files; 852 foreach (const QHelpDataFilterSection &filterSection, helpData.filterSections()) { 853 foreach (const QString &file, filterSection.files()) { 854 QFileInfo fileInfo(helpData.rootPath() + QDir::separator() + file); 855 const QString &canonicalFileName = fileInfo.canonicalFilePath(); 856 if (!fileInfo.exists()) 857 emit warning(tr("File '%1' does not exist.").arg(file)); 858 else 859 files.insert(canonicalFileName); 860 } 861 } 862 863 /* 864 * Step 2: Check the hypertext and image references of all HTML files. 865 * Note that we don't parse the files, but simply grep for the 866 * respective HTML elements. Therefore. contents that are e.g. 867 * commented out can cause false warning. 868 */ 869 bool allLinksOk = true; 870 foreach (const QString &fileName, files) { 871 if (!fileName.endsWith(QLatin1String("html")) 872 && !fileName.endsWith(QLatin1String("htm"))) 873 continue; 874 QFile htmlFile(fileName); 875 if (!htmlFile.open(QIODevice::ReadOnly)) { 876 emit warning(tr("File '%1' cannot be opened.").arg(fileName)); 877 continue; 878 } 879 const QRegExp linkPattern(QLatin1String("<(?:a href|img src)=\"?([^#\">]+)[#\">]")); 880 QTextStream stream(&htmlFile); 881 const QString codec = QHelpGlobal::codecFromData(htmlFile.read(1000)); 882 stream.setCodec(QTextCodec::codecForName(codec.toLatin1().constData())); 883 const QString &content = stream.readAll(); 884 QStringList invalidLinks; 885 for (int pos = linkPattern.indexIn(content); pos != -1; 886 pos = linkPattern.indexIn(content, pos + 1)) { 887 const QString& linkedFileName = linkPattern.cap(1); 888 if (linkedFileName.contains(QLatin1String("://"))) 889 continue; 890 const QString curDir = QFileInfo(fileName).dir().path(); 891 const QString &canonicalLinkedFileName = 892 QFileInfo(curDir + QDir::separator() + linkedFileName).canonicalFilePath(); 893 if (!files.contains(canonicalLinkedFileName) 894 && !invalidLinks.contains(canonicalLinkedFileName)) { 895 emit warning(tr("File '%1' contains an invalid link to file '%2'"). 896 arg(fileName).arg(linkedFileName)); 897 allLinksOk = false; 898 invalidLinks.append(canonicalLinkedFileName); 899 } 900 } 901 } 902 903 if (!allLinksOk) 904 d->error = tr("Invalid links in HTML files."); 905 return allLinksOk; 906 } 907 827 908 QT_END_NAMESPACE 909
Note:
See TracChangeset
for help on using the changeset viewer.