tools/assistant/lib/qhelpgenerator.cpp
changeset 18 2f34d5167611
parent 3 41300fa6a67c
child 30 5dc02b23752f
equal deleted inserted replaced
3:41300fa6a67c 18:2f34d5167611
     1 /****************************************************************************
     1 /****************************************************************************
     2 **
     2 **
     3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
     3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     4 ** All rights reserved.
     4 ** All rights reserved.
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
     6 **
     6 **
     7 ** This file is part of the Qt Assistant of the Qt Toolkit.
     7 ** This file is part of the Qt Assistant of the Qt Toolkit.
     8 **
     8 **
   201         return false;
   201         return false;
   202     }
   202     }
   203     addProgress(1.0);
   203     addProgress(1.0);
   204 
   204 
   205     emit statusChanged(tr("Insert custom filters..."));
   205     emit statusChanged(tr("Insert custom filters..."));
   206     foreach (QHelpDataCustomFilter f, helpData->customFilters()) {
   206     foreach (const QHelpDataCustomFilter &f, helpData->customFilters()) {
   207         if (!registerCustomFilter(f.name, f.filterAttributes, true)) {
   207         if (!registerCustomFilter(f.name, f.filterAttributes, true)) {
   208             cleanupDB();
   208             cleanupDB();
   209             return false;
   209             return false;
   210         }
   210         }
   211     }
   211     }
   365             "NamespaceID INTEGER )")
   365             "NamespaceID INTEGER )")
   366         << QLatin1String("CREATE TABLE MetaDataTable("
   366         << QLatin1String("CREATE TABLE MetaDataTable("
   367             "Name Text, "
   367             "Name Text, "
   368             "Value BLOB )");
   368             "Value BLOB )");
   369 
   369 
   370     foreach (QString q, tables) {
   370     foreach (const QString &q, tables) {
   371         if (!d->query->exec(q)) {
   371         if (!d->query->exec(q)) {
   372             d->error = tr("Cannot create tables!");
   372             d->error = tr("Cannot create tables!");
   373             return false;
   373             return false;
   374         }
   374         }
   375     }
   375     }
   627             d->query->value(0).toInt());
   627             d->query->value(0).toInt());
   628         if (idsToInsert.contains(d->query->value(1).toString()))
   628         if (idsToInsert.contains(d->query->value(1).toString()))
   629             idsToInsert.removeAll(d->query->value(1).toString());
   629             idsToInsert.removeAll(d->query->value(1).toString());
   630     }
   630     }
   631 
   631 
   632     foreach (QString id, idsToInsert) {
   632     foreach (const QString &id, idsToInsert) {
   633         d->query->prepare(QLatin1String("INSERT INTO FilterAttributeTable VALUES(NULL, ?)"));
   633         d->query->prepare(QLatin1String("INSERT INTO FilterAttributeTable VALUES(NULL, ?)"));
   634         d->query->bindValue(0, id);
   634         d->query->bindValue(0, id);
   635         d->query->exec();
   635         d->query->exec();
   636         attributeMap.insert(id, d->query->lastInsertId().toInt());
   636         attributeMap.insert(id, d->query->lastInsertId().toInt());
   637     }
   637     }
   662 
   662 
   663     d->query->prepare(QLatin1String("DELETE FROM FilterTable WHERE NameId=?"));
   663     d->query->prepare(QLatin1String("DELETE FROM FilterTable WHERE NameId=?"));
   664     d->query->bindValue(0, nameId);
   664     d->query->bindValue(0, nameId);
   665     d->query->exec();
   665     d->query->exec();
   666 
   666 
   667     foreach (QString att, filterAttribs) {
   667     foreach (const QString &att, filterAttribs) {
   668         d->query->prepare(QLatin1String("INSERT INTO FilterTable VALUES(?, ?)"));
   668         d->query->prepare(QLatin1String("INSERT INTO FilterTable VALUES(?, ?)"));
   669         d->query->bindValue(0, nameId);
   669         d->query->bindValue(0, nameId);
   670         d->query->bindValue(1, attributeMap[att]);
   670         d->query->bindValue(1, attributeMap[att]);
   671         if (!d->query->exec())
   671         if (!d->query->exec())
   672             return false;
   672             return false;
   685     d->query->exec(QLatin1String("SELECT MAX(Id) FROM IndexTable"));
   685     d->query->exec(QLatin1String("SELECT MAX(Id) FROM IndexTable"));
   686     if (d->query->next())
   686     if (d->query->next())
   687         indexId = d->query->value(0).toInt() + 1;
   687         indexId = d->query->value(0).toInt() + 1;
   688 
   688 
   689     QList<int> filterAtts;
   689     QList<int> filterAtts;
   690     foreach (QString filterAtt, filterAttributes) {
   690     foreach (const QString &filterAtt, filterAttributes) {
   691         d->query->prepare(QLatin1String("SELECT Id FROM FilterAttributeTable WHERE Name=?"));
   691         d->query->prepare(QLatin1String("SELECT Id FROM FilterAttributeTable WHERE Name=?"));
   692         d->query->bindValue(0, filterAtt);
   692         d->query->bindValue(0, filterAtt);
   693         d->query->exec();
   693         d->query->exec();
   694         if (d->query->next())
   694         if (d->query->next())
   695             filterAtts.append(d->query->value(0).toInt());
   695             filterAtts.append(d->query->value(0).toInt());
   702     int fileId = 1;
   702     int fileId = 1;
   703     QList<int> indexFilterTable;
   703     QList<int> indexFilterTable;
   704 
   704 
   705     int i = 0;
   705     int i = 0;
   706     d->query->exec(QLatin1String("BEGIN"));
   706     d->query->exec(QLatin1String("BEGIN"));
   707     foreach (QHelpDataIndexItem itm, keywords) {
   707     foreach (const QHelpDataIndexItem &itm, keywords) {
   708         pos = itm.reference.indexOf(QLatin1Char('#'));
   708         pos = itm.reference.indexOf(QLatin1Char('#'));
   709         fileName = itm.reference.left(pos);
   709         fileName = itm.reference.left(pos);
   710         if (pos > -1)
   710         if (pos > -1)
   711             anchor = itm.reference.mid(pos+1);
   711             anchor = itm.reference.mid(pos+1);
   712         else
   712         else
   771         d->error = tr("Cannot insert contents!");
   771         d->error = tr("Cannot insert contents!");
   772         return false;
   772         return false;
   773     }
   773     }
   774 
   774 
   775     // associate the filter attributes
   775     // associate the filter attributes
   776     foreach (QString filterAtt, filterAttributes) {
   776     foreach (const QString &filterAtt, filterAttributes) {
   777         d->query->prepare(QLatin1String("INSERT INTO ContentsFilterTable (FilterAttributeId, ContentsId) "
   777         d->query->prepare(QLatin1String("INSERT INTO ContentsFilterTable (FilterAttributeId, ContentsId) "
   778             "SELECT Id, ? FROM FilterAttributeTable WHERE Name=?"));
   778             "SELECT Id, ? FROM FilterAttributeTable WHERE Name=?"));
   779         d->query->bindValue(0, contentId);
   779         d->query->bindValue(0, contentId);
   780         d->query->bindValue(1, filterAtt);
   780         d->query->bindValue(1, filterAtt);
   781         d->query->exec();
   781         d->query->exec();
   796     d->query->exec(QLatin1String("SELECT Name FROM FilterAttributeTable"));
   796     d->query->exec(QLatin1String("SELECT Name FROM FilterAttributeTable"));
   797     QSet<QString> atts;
   797     QSet<QString> atts;
   798     while (d->query->next())
   798     while (d->query->next())
   799         atts.insert(d->query->value(0).toString());
   799         atts.insert(d->query->value(0).toString());
   800 
   800 
   801     foreach (QString s, attributes) {
   801     foreach (const QString &s, attributes) {
   802         if (!atts.contains(s)) {
   802         if (!atts.contains(s)) {
   803             d->query->prepare(QLatin1String("INSERT INTO FilterAttributeTable VALUES(NULL, ?)"));
   803             d->query->prepare(QLatin1String("INSERT INTO FilterAttributeTable VALUES(NULL, ?)"));
   804             d->query->bindValue(0, s);
   804             d->query->bindValue(0, s);
   805             d->query->exec();
   805             d->query->exec();
   806         }
   806         }