From 36a7262f8ab56c7790afd0eb43f3b07413c8bc08 Mon Sep 17 00:00:00 2001 From: Jarek Kobus Date: Tue, 19 Feb 2019 14:00:39 +0100 Subject: Create default version filter This mimics the behavior of old filters, where in 98% of use cases the qch file provided a separate filter for its module. Change-Id: I537d8336ea3cc0c6c894b494d7f2346df7499572 Reviewed-by: Friedemann Kleint --- src/assistant/help/qhelpcollectionhandler.cpp | 22 ++++++++++++++++++++-- src/assistant/help/qhelpcollectionhandler_p.h | 4 +++- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/src/assistant/help/qhelpcollectionhandler.cpp b/src/assistant/help/qhelpcollectionhandler.cpp index 375edd8d3..483ab968e 100644 --- a/src/assistant/help/qhelpcollectionhandler.cpp +++ b/src/assistant/help/qhelpcollectionhandler.cpp @@ -214,7 +214,7 @@ bool QHelpCollectionHandler::openCollectionFile() const FileInfoList &docList = registeredDocumentations(); if (indexAndNamespaceFilterTablesMissing) { for (const QHelpCollectionHandler::FileInfo &info : docList) { - if (!registerIndexAndNamespaceFilterTables(info.namespaceName)) { + if (!registerIndexAndNamespaceFilterTables(info.namespaceName, true)) { emit error(tr("Cannot register index tables in file %1.").arg(collectionFile())); return false; } @@ -1915,7 +1915,8 @@ bool QHelpCollectionHandler::registerVersion(const QString &version, int namespa return m_query->exec(); } -bool QHelpCollectionHandler::registerIndexAndNamespaceFilterTables(const QString &nameSpace) +bool QHelpCollectionHandler::registerIndexAndNamespaceFilterTables( + const QString &nameSpace, bool createDefaultVersionFilter) { if (!isDBOpened()) return false; @@ -1952,9 +1953,26 @@ bool QHelpCollectionHandler::registerIndexAndNamespaceFilterTables(const QString if (!registerIndexTable(reader.indexTable(), nsId, vfId, fileName)) return false; + if (createDefaultVersionFilter) + createVersionFilter(reader.version()); + return true; } +void QHelpCollectionHandler::createVersionFilter(const QString &version) +{ + if (version.isEmpty()) + return; + + const QString filterName = tr("Version %1").arg(version); + if (filters().contains(filterName)) + return; + + QHelpFilterData filterData; + filterData.setVersions(QStringList() << version); + setFilterData(filterName, filterData); +} + bool QHelpCollectionHandler::registerIndexTable(const QHelpDBReader::IndexTable &indexTable, int nsId, int vfId, const QString &fileName) { diff --git a/src/assistant/help/qhelpcollectionhandler_p.h b/src/assistant/help/qhelpcollectionhandler_p.h index c52498f4e..223f66012 100644 --- a/src/assistant/help/qhelpcollectionhandler_p.h +++ b/src/assistant/help/qhelpcollectionhandler_p.h @@ -220,7 +220,9 @@ private: bool createTables(QSqlQuery *query); void closeDB(); bool recreateIndexAndNamespaceFilterTables(QSqlQuery *query); - bool registerIndexAndNamespaceFilterTables(const QString &nameSpace); + bool registerIndexAndNamespaceFilterTables(const QString &nameSpace, + bool createDefaultVersionFilter = false); + void createVersionFilter(const QString &version); bool registerFilterAttributes(const QList &attributeSets, int nsId); bool registerFileAttributeSets(const QList &attributeSets, int nsId); bool registerIndexTable(const QHelpDBReader::IndexTable &indexTable, -- cgit v1.2.1