diff options
author | Jarek Kobus <jaroslaw.kobus@qt.io> | 2017-03-16 14:37:26 +0100 |
---|---|---|
committer | Jarek Kobus <jaroslaw.kobus@qt.io> | 2017-05-02 13:56:49 +0000 |
commit | b46a5297a55c1547e3d9015e199e967276ad79c5 (patch) | |
tree | 91607bce0700df3e82b2a2ba64144efab941671a /src | |
parent | 63bee398b5db72fdb40d039d8e01223992655403 (diff) | |
download | qttools-b46a5297a55c1547e3d9015e199e967276ad79c5.tar.gz |
Refactor help lib
Fix const correctness.
Use default member initializers.
Fix some coding style issues.
Change-Id: Ib89a2840648dcacc518cda4eb0ffce97ee8444cc
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
Reviewed-by: Karsten Heimrich <karsten.heimrich@qt.io>
Diffstat (limited to 'src')
26 files changed, 304 insertions, 417 deletions
diff --git a/src/assistant/assistant/helpenginewrapper.cpp b/src/assistant/assistant/helpenginewrapper.cpp index a6e8936f2..20e6ff7ff 100644 --- a/src/assistant/assistant/helpenginewrapper.cpp +++ b/src/assistant/assistant/helpenginewrapper.cpp @@ -121,7 +121,7 @@ HelpEngineWrapper &HelpEngineWrapper::instance(const QString &collectionFile) * Note that this Singleton cannot be static, because it has to be * deleted before the QApplication. */ - if (helpEngineWrapper == 0) + if (!helpEngineWrapper) helpEngineWrapper = new HelpEngineWrapper(collectionFile); return *helpEngineWrapper; } @@ -817,7 +817,7 @@ void HelpEngineWrapperPrivate::qchFileChanged(const QString &fileName, * was sent. */ - const auto it = m_recentQchUpdates.find(fileName); + const auto &it = m_recentQchUpdates.find(fileName); const QDateTime &now = QDateTime::currentDateTime(); // Case 1: This is the first recent signal for the file. diff --git a/src/assistant/assistant/indexwindow.cpp b/src/assistant/assistant/indexwindow.cpp index b735c130b..44ad56fad 100644 --- a/src/assistant/assistant/indexwindow.cpp +++ b/src/assistant/assistant/indexwindow.cpp @@ -111,7 +111,7 @@ bool IndexWindow::eventFilter(QObject *obj, QEvent *e) } break; case Qt::Key_Down: - idx = m_indexWidget->model()->index(idx.row()+1, + idx = m_indexWidget->model()->index(idx.row() + 1, idx.column(), idx.parent()); if (idx.isValid()) { m_indexWidget->setCurrentIndex(idx); diff --git a/src/assistant/assistant/mainwindow.cpp b/src/assistant/assistant/mainwindow.cpp index 46f68bcd0..dba6b724e 100644 --- a/src/assistant/assistant/mainwindow.cpp +++ b/src/assistant/assistant/mainwindow.cpp @@ -297,8 +297,7 @@ MainWindow::MainWindow(CmdLineParser *cmdLine, QWidget *parent) MainWindow::~MainWindow() { TRACE_OBJ - if (m_qtDocInstaller) - delete m_qtDocInstaller; + delete m_qtDocInstaller; } bool MainWindow::usesDefaultCollection() const diff --git a/src/assistant/assistant/remotecontrol.cpp b/src/assistant/assistant/remotecontrol.cpp index 61f8b0282..1c16ac104 100644 --- a/src/assistant/assistant/remotecontrol.cpp +++ b/src/assistant/assistant/remotecontrol.cpp @@ -121,7 +121,7 @@ void RemoteControl::splitInputString(const QString &input, QString &cmd, QString cmdLine = input.trimmed(); int i = cmdLine.indexOf(QLatin1Char(' ')); cmd = cmdLine.left(i); - arg = cmdLine.mid(i+1); + arg = cmdLine.mid(i + 1); cmd = cmd.toLower(); } diff --git a/src/assistant/help/qhelp_global.cpp b/src/assistant/help/qhelp_global.cpp index 37a41cd3b..6316aa494 100644 --- a/src/assistant/help/qhelp_global.cpp +++ b/src/assistant/help/qhelp_global.cpp @@ -59,8 +59,8 @@ QString QHelpGlobal::documentTitle(const QString &content) { QString title = QCoreApplication::translate("QHelp", "Untitled"); if (!content.isEmpty()) { - int start = content.indexOf(QLatin1String("<title>"), 0, Qt::CaseInsensitive) + 7; - int end = content.indexOf(QLatin1String("</title>"), 0, Qt::CaseInsensitive); + const int start = content.indexOf(QLatin1String("<title>"), 0, Qt::CaseInsensitive) + 7; + const int end = content.indexOf(QLatin1String("</title>"), 0, Qt::CaseInsensitive); if ((end - start) > 0) { title = content.mid(start, end - start); if (Qt::mightBeRichText(title) || title.contains(QLatin1Char('&'))) { @@ -83,10 +83,10 @@ QString QHelpGlobal::codecFromData(const QByteArray &data) QString QHelpGlobal::codecFromHtmlData(const QByteArray &data) { - QString head = QString::fromUtf8(data.constData(), qMin(1000, data.size())); + const QString &head = QString::fromUtf8(data.constData(), qMin(1000, data.size())); int start = head.indexOf(QLatin1String("<meta"), 0, Qt::CaseInsensitive); if (start > 0) { - QRegExp r(QLatin1String("charset=([^\"\\s]+)")); + const QRegExp r(QLatin1String("charset=([^\"\\s]+)")); while (start != -1) { const int end = head.indexOf(QLatin1Char('>'), start) + 1; if (end <= start) @@ -103,8 +103,8 @@ QString QHelpGlobal::codecFromHtmlData(const QByteArray &data) QString QHelpGlobal::codecFromXmlData(const QByteArray &data) { - QString head = QString::fromUtf8(data.constData(), qMin(1000, data.size())); - QRegExp encodingExp(QLatin1String("^\\s*<\\?xml version=" - "\"\\d\\.\\d\" encoding=\"([^\"]+)\"\\?>.*")); + const QString head = QString::fromUtf8(data.constData(), qMin(1000, data.size())); + const QRegExp encodingExp(QLatin1String("^\\s*<\\?xml version=" + "\"\\d\\.\\d\" encoding=\"([^\"]+)\"\\?>.*")); return encodingExp.exactMatch(head) ? encodingExp.cap(1) : QString(); } diff --git a/src/assistant/help/qhelpcollectionhandler.cpp b/src/assistant/help/qhelpcollectionhandler.cpp index ec49d045a..e6e5ce41e 100644 --- a/src/assistant/help/qhelpcollectionhandler.cpp +++ b/src/assistant/help/qhelpcollectionhandler.cpp @@ -55,12 +55,10 @@ QHelpCollectionHandler::QHelpCollectionHandler(const QString &collectionFile, QO : QObject(parent) , m_dbOpened(false) , m_collectionFile(collectionFile) - , m_connectionName(QString()) { - QFileInfo fi(m_collectionFile); + const QFileInfo fi(m_collectionFile); if (!fi.isAbsolute()) m_collectionFile = fi.absoluteFilePath(); - m_query.clear(); } QHelpCollectionHandler::~QHelpCollectionHandler() @@ -134,7 +132,7 @@ bool QHelpCollectionHandler::copyCollectionFile(const QString &fileName) if (!m_dbOpened) return false; - QFileInfo fi(fileName); + const QFileInfo fi(fileName); if (fi.exists()) { emit error(tr("The collection file '%1' already exists."). arg(fileName)); @@ -146,9 +144,9 @@ bool QHelpCollectionHandler::copyCollectionFile(const QString &fileName) return false; } - QString colFile = fi.absoluteFilePath(); - QString connectionName = QHelpGlobal::uniquifyConnectionName( - QLatin1String("QHelpCollectionHandlerCopy"), this); + const QString &colFile = fi.absoluteFilePath(); + const QString &connectionName = QHelpGlobal::uniquifyConnectionName( + QLatin1String("QHelpCollectionHandlerCopy"), this); QSqlQuery *copyQuery = 0; bool openingOk = true; { @@ -172,14 +170,13 @@ bool QHelpCollectionHandler::copyCollectionFile(const QString &fileName) return false; } - QString oldBaseDir = QFileInfo(collectionFile()).absolutePath(); - QString oldFilePath; - QFileInfo newColFi(colFile); + const QString &oldBaseDir = QFileInfo(collectionFile()).absolutePath(); + const QFileInfo newColFi(colFile); m_query.exec(QLatin1String("SELECT Name, FilePath FROM NamespaceTable")); while (m_query.next()) { copyQuery->prepare(QLatin1String("INSERT INTO NamespaceTable VALUES(NULL, ?, ?)")); copyQuery->bindValue(0, m_query.value(0).toString()); - oldFilePath = m_query.value(1).toString(); + QString oldFilePath = m_query.value(1).toString(); if (!QDir::isAbsolutePath(oldFilePath)) oldFilePath = oldBaseDir + QDir::separator() + oldFilePath; copyQuery->bindValue(1, newColFi.absoluteDir().relativeFilePath(oldFilePath)); @@ -234,29 +231,29 @@ bool QHelpCollectionHandler::copyCollectionFile(const QString &fileName) bool QHelpCollectionHandler::createTables(QSqlQuery *query) { - QStringList tables; - tables << QLatin1String("CREATE TABLE NamespaceTable (" - "Id INTEGER PRIMARY KEY, " - "Name TEXT, " - "FilePath TEXT )") - << QLatin1String("CREATE TABLE FolderTable (" - "Id INTEGER PRIMARY KEY, " - "NamespaceId INTEGER, " - "Name TEXT )") - << QLatin1String("CREATE TABLE FilterAttributeTable (" - "Id INTEGER PRIMARY KEY, " - "Name TEXT )") - << QLatin1String("CREATE TABLE FilterNameTable (" - "Id INTEGER PRIMARY KEY, " - "Name TEXT )") - << QLatin1String("CREATE TABLE FilterTable (" - "NameId INTEGER, " - "FilterAttributeId INTEGER )") - << QLatin1String("CREATE TABLE SettingsTable (" - "Key TEXT PRIMARY KEY, " - "Value BLOB )"); - - for (const QString &q : qAsConst(tables)) { + const QStringList tables = QStringList() + << QLatin1String("CREATE TABLE NamespaceTable (" + "Id INTEGER PRIMARY KEY, " + "Name TEXT, " + "FilePath TEXT )") + << QLatin1String("CREATE TABLE FolderTable (" + "Id INTEGER PRIMARY KEY, " + "NamespaceId INTEGER, " + "Name TEXT )") + << QLatin1String("CREATE TABLE FilterAttributeTable (" + "Id INTEGER PRIMARY KEY, " + "Name TEXT )") + << QLatin1String("CREATE TABLE FilterNameTable (" + "Id INTEGER PRIMARY KEY, " + "Name TEXT )") + << QLatin1String("CREATE TABLE FilterTable (" + "NameId INTEGER, " + "FilterAttributeId INTEGER )") + << QLatin1String("CREATE TABLE SettingsTable (" + "Key TEXT PRIMARY KEY, " + "Value BLOB )"); + + for (const QString &q : tables) { if (!query->exec(q)) return false; } @@ -388,13 +385,13 @@ bool QHelpCollectionHandler::registerDocumentation(const QString &fileName) return false; } - QString ns = reader.namespaceName(); + const QString &ns = reader.namespaceName(); if (ns.isEmpty()) { emit error(tr("Invalid documentation file '%1'.").arg(fileName)); return false; } - int nsId = registerNamespace(ns, fileName); + const int nsId = registerNamespace(ns, fileName); if (nsId < 1) return false; @@ -419,15 +416,13 @@ bool QHelpCollectionHandler::unregisterDocumentation(const QString &namespaceNam m_query.bindValue(0, namespaceName); m_query.exec(); - int nsId = -1; - if (m_query.next()) - nsId = m_query.value(0).toInt(); - - if (nsId < 0) { + if (!m_query.next()) { emit error(tr("The namespace %1 was not registered.").arg(namespaceName)); return false; } + const int nsId = m_query.value(0).toInt(); + m_query.prepare(QLatin1String("DELETE FROM NamespaceTable WHERE Id=?")); m_query.bindValue(0, nsId); m_query.exec(); @@ -450,23 +445,26 @@ bool QHelpCollectionHandler::removeCustomValue(const QString &key) QVariant QHelpCollectionHandler::customValue(const QString &key, const QVariant &defaultValue) const { - QVariant value = defaultValue; - if (m_dbOpened) { - m_query.prepare(QLatin1String("SELECT COUNT(Key) FROM SettingsTable WHERE Key=?")); - m_query.bindValue(0, key); - if (!m_query.exec() || !m_query.next() || !m_query.value(0).toInt()) { - m_query.clear(); - return defaultValue; - } + if (!m_dbOpened) + return defaultValue; + m_query.prepare(QLatin1String("SELECT COUNT(Key) FROM SettingsTable WHERE Key=?")); + m_query.bindValue(0, key); + if (!m_query.exec() || !m_query.next() || !m_query.value(0).toInt()) { m_query.clear(); - m_query.prepare(QLatin1String("SELECT Value FROM SettingsTable WHERE Key=?")); - m_query.bindValue(0, key); - if (m_query.exec() && m_query.next()) - value = m_query.value(0); + return defaultValue; + } + + m_query.clear(); + m_query.prepare(QLatin1String("SELECT Value FROM SettingsTable WHERE Key=?")); + m_query.bindValue(0, key); + if (m_query.exec() && m_query.next()) { + const QVariant &value = m_query.value(0); m_query.clear(); + return value; } - return value; + + return defaultValue; } bool QHelpCollectionHandler::setCustomValue(const QString &key, @@ -482,8 +480,7 @@ bool QHelpCollectionHandler::setCustomValue(const QString &key, m_query.prepare(QLatin1String("UPDATE SettingsTable SET Value=? where Key=?")); m_query.bindValue(0, value); m_query.bindValue(1, key); - } - else { + } else { m_query.prepare(QLatin1String("INSERT INTO SettingsTable VALUES(?, ?)")); m_query.bindValue(0, key); m_query.bindValue(1, value); @@ -585,7 +582,6 @@ void QHelpCollectionHandler::optimizeDatabase(const QString &fileName) return; } - QSqlQuery query(db); db.exec(QLatin1String("PRAGMA synchronous=OFF")); db.exec(QLatin1String("PRAGMA cache_size=3000")); db.exec(QLatin1String("CREATE INDEX IF NOT EXISTS NameIndex ON IndexTable(Name)")); diff --git a/src/assistant/help/qhelpcontentwidget.cpp b/src/assistant/help/qhelpcontentwidget.cpp index 57dfff591..5d57f1d04 100644 --- a/src/assistant/help/qhelpcontentwidget.cpp +++ b/src/assistant/help/qhelpcontentwidget.cpp @@ -55,13 +55,15 @@ class QHelpContentItemPrivate public: QHelpContentItemPrivate(const QString &t, const QString &l, QHelpDBReader *r, QHelpContentItem *p) + : parent(p), + title(t), + link(l), + helpDBReader(r) { - parent = p; - title = t; - link = l; - helpDBReader = r; } + void appendChild(QHelpContentItem *item) { childItems.append(item); } + QList<QHelpContentItem*> childItems; QHelpContentItem *parent; QString title; @@ -95,7 +97,7 @@ private: class QHelpContentModelPrivate { public: - QHelpContentItem *rootItem; + QHelpContentItem *rootItem = nullptr; QHelpContentProvider *qhelpContentProvider; }; @@ -123,11 +125,6 @@ QHelpContentItem::~QHelpContentItem() delete d; } -void QHelpContentItem::appendChild(QHelpContentItem *item) -{ - d->childItems.append(item); -} - /*! Returns the child of the content item in the give \a row. @@ -135,8 +132,6 @@ void QHelpContentItem::appendChild(QHelpContentItem *item) */ QHelpContentItem *QHelpContentItem::child(int row) const { - if (row >= childCount()) - return 0; return d->childItems.value(row); } @@ -290,7 +285,7 @@ CHECK_DEPTH: m_mutex.lock(); item = new QHelpContentItem(title, link, m_helpEngine->fileNameReaderMap.value(dbFileName), rootItem); - rootItem->appendChild(item); + rootItem->d->appendChild(item); m_mutex.unlock(); stack.push(item); _depth = 1; @@ -303,7 +298,7 @@ CHECK_DEPTH: if (depth == _depth) { item = new QHelpContentItem(title, link, m_helpEngine->fileNameReaderMap.value(dbFileName), stack.top()); - stack.top()->appendChild(item); + stack.top()->d->appendChild(item); } else if (depth < _depth) { stack.pop(); --_depth; @@ -349,7 +344,6 @@ QHelpContentModel::QHelpContentModel(QHelpEnginePrivate *helpEngine) : QAbstractItemModel(helpEngine) { d = new QHelpContentModelPrivate(); - d->rootItem = 0; d->qhelpContentProvider = new QHelpContentProvider(helpEngine); connect(d->qhelpContentProvider, &QHelpContentProvider::finishedSuccessFully, @@ -400,8 +394,7 @@ void QHelpContentModel::insertContents() if (!newRootItem) return; beginResetModel(); - if (d->rootItem) - delete d->rootItem; + delete d->rootItem; d->rootItem = newRootItem; endResetModel(); emit contentsCreated(); diff --git a/src/assistant/help/qhelpcontentwidget.h b/src/assistant/help/qhelpcontentwidget.h index a4b0ce273..ff5961e98 100644 --- a/src/assistant/help/qhelpcontentwidget.h +++ b/src/assistant/help/qhelpcontentwidget.h @@ -72,7 +72,6 @@ public: private: QHelpContentItem(const QString &name, const QString &link, QHelpDBReader *reader, QHelpContentItem *parent = Q_NULLPTR); - void appendChild(QHelpContentItem *child); QHelpContentItemPrivate *d; friend class QHelpContentProvider; diff --git a/src/assistant/help/qhelpdatainterface.cpp b/src/assistant/help/qhelpdatainterface.cpp index d082029fd..fade438e1 100644 --- a/src/assistant/help/qhelpdatainterface.cpp +++ b/src/assistant/help/qhelpdatainterface.cpp @@ -99,14 +99,11 @@ QList<QHelpDataContentItem*> QHelpDataContentItem::children() const return m_children; } -bool QHelpDataIndexItem::operator==(const QHelpDataIndexItem & other) const +bool QHelpDataIndexItem::operator==(const QHelpDataIndexItem &other) const { - return (other.name == name) - && (other.reference == reference); + return (other.name == name) && (other.reference == reference); } - - /*! \internal \class QHelpDataFilterSection diff --git a/src/assistant/help/qhelpdbreader.cpp b/src/assistant/help/qhelpdbreader.cpp index ea190d0e1..3b364dfb1 100644 --- a/src/assistant/help/qhelpdbreader.cpp +++ b/src/assistant/help/qhelpdbreader.cpp @@ -48,27 +48,19 @@ QT_BEGIN_NAMESPACE QHelpDBReader::QHelpDBReader(const QString &dbName) - : QObject(0) + : QObject(0), + m_dbName(dbName), + m_uniqueId(QHelpGlobal::uniquifyConnectionName(QLatin1String("QHelpDBReader"), + this)) { - initObject(dbName, - QHelpGlobal::uniquifyConnectionName(QLatin1String("QHelpDBReader"), - this)); } QHelpDBReader::QHelpDBReader(const QString &dbName, const QString &uniqueId, QObject *parent) - : QObject(parent) + : QObject(parent), + m_dbName(dbName), + m_uniqueId(uniqueId) { - initObject(dbName, uniqueId); -} - -void QHelpDBReader::initObject(const QString &dbName, const QString &uniqueId) -{ - m_dbName = dbName; - m_uniqueId = uniqueId; - m_initDone = false; - m_query = 0; - m_useAttributesCache = false; } QHelpDBReader::~QHelpDBReader() @@ -145,7 +137,7 @@ QList<QStringList> QHelpDBReader::filterAttributeSets() const "FilterAttributeTable b WHERE a.FilterAttributeId=b.Id ORDER BY a.Id")); int oldId = -1; while (m_query->next()) { - int id = m_query->value(0).toInt(); + const int id = m_query->value(0).toInt(); if (id != oldId) { result.append(QStringList()); oldId = id; @@ -274,8 +266,9 @@ QStringList QHelpDBReader::indicesForFilter(const QStringList &filterAttributes) return indices; } -void QHelpDBReader::linksForKeyword(const QString &keyword, const QStringList &filterAttributes, - QMap<QString, QUrl> &linkMap) const +void QHelpDBReader::linksForKeyword(const QString &keyword, + const QStringList &filterAttributes, + QMap<QString, QUrl> *linkMap) const { if (!m_query) return; @@ -297,7 +290,7 @@ void QHelpDBReader::linksForKeyword(const QString &keyword, const QStringList &f m_query->exec(query); while (m_query->next()) { if (m_indicesCache.contains(m_query->value(5).toInt())) { - linkMap.insertMulti(m_query->value(0).toString(), buildQUrl(m_query->value(1).toString(), + linkMap->insertMulti(m_query->value(0).toString(), buildQUrl(m_query->value(1).toString(), m_query->value(2).toString(), m_query->value(3).toString(), m_query->value(4).toString())); } @@ -328,7 +321,7 @@ void QHelpDBReader::linksForKeyword(const QString &keyword, const QStringList &f title = m_query->value(0).toString(); if (title.isEmpty()) // generate a title + corresponding path title = keyword + QLatin1String(" : ") + m_query->value(3).toString(); - linkMap.insertMulti(title, buildQUrl(m_query->value(1).toString(), + linkMap->insertMulti(title, buildQUrl(m_query->value(1).toString(), m_query->value(2).toString(), m_query->value(3).toString(), m_query->value(4).toString())); } @@ -336,7 +329,7 @@ void QHelpDBReader::linksForKeyword(const QString &keyword, const QStringList &f void QHelpDBReader::linksForIdentifier(const QString &id, const QStringList &filterAttributes, - QMap<QString, QUrl> &linkMap) const + QMap<QString, QUrl> *linkMap) const { if (!m_query) return; @@ -358,7 +351,7 @@ void QHelpDBReader::linksForIdentifier(const QString &id, m_query->exec(query); while (m_query->next()) { if (m_indicesCache.contains(m_query->value(5).toInt())) { - linkMap.insertMulti(m_query->value(0).toString(), buildQUrl(m_query->value(1).toString(), + linkMap->insertMulti(m_query->value(0).toString(), buildQUrl(m_query->value(1).toString(), m_query->value(2).toString(), m_query->value(3).toString(), m_query->value(4).toString())); } @@ -386,7 +379,7 @@ void QHelpDBReader::linksForIdentifier(const QString &id, m_query->exec(query); while (m_query->next()) { - linkMap.insertMulti(m_query->value(0).toString(), buildQUrl(m_query->value(1).toString(), + linkMap->insertMulti(m_query->value(0).toString(), buildQUrl(m_query->value(1).toString(), m_query->value(2).toString(), m_query->value(3).toString(), m_query->value(4).toString())); } @@ -428,32 +421,26 @@ QList<QByteArray> QHelpDBReader::contentsForFilter(const QStringList &filterAttr } m_query->exec(query); - while (m_query->next()) { + while (m_query->next()) contents.append(m_query->value(0).toByteArray()); - } return contents; } QUrl QHelpDBReader::urlOfPath(const QString &relativePath) const { - QUrl url; if (!m_query) - return url; + return QUrl(); m_query->exec(QLatin1String("SELECT a.Name, b.Name FROM NamespaceTable a, " "FolderTable b WHERE a.id=b.NamespaceId and a.Id=1")); - if (m_query->next()) { - QString rp = relativePath; - QString anchor; - int i = rp.indexOf(QLatin1Char('#')); - if (i > -1) { - rp = relativePath.left(i); - anchor = relativePath.mid(i+1); - } - url = buildQUrl(m_query->value(0).toString(), - m_query->value(1).toString(), rp, anchor); - } - return url; + if (!m_query->next()) + return QUrl(); + + const int idx = relativePath.indexOf(QLatin1Char('#')); + const QString &rp = idx < 0 ? relativePath : relativePath.left(idx); + const QString anchor = idx < 0 ? QString() : relativePath.mid(idx + 1); + return buildQUrl(m_query->value(0).toString(), + m_query->value(1).toString(), rp, anchor); } QStringList QHelpDBReader::files(const QStringList &filterAttributes, @@ -517,7 +504,7 @@ QString QHelpDBReader::mergeList(const QStringList &list) const for (const QString &s : list) str.append(QLatin1Char('\'') + quote(s) + QLatin1String("\', ")); if (str.endsWith(QLatin1String(", "))) - str = str.left(str.length()-2); + str.chop(2); return str; } @@ -564,7 +551,7 @@ bool QHelpDBReader::createAttributesCache(const QStringList &attributes, return true; } - bool needUpdate = !m_viewAttributes.count(); + const bool needUpdate = !m_viewAttributes.count(); for (const QString &s : attributes) m_viewAttributes.remove(s); diff --git a/src/assistant/help/qhelpdbreader_p.h b/src/assistant/help/qhelpdbreader_p.h index 7245c3941..48005d35e 100644 --- a/src/assistant/help/qhelpdbreader_p.h +++ b/src/assistant/help/qhelpdbreader_p.h @@ -90,10 +90,10 @@ public: QStringList filterAttributes(const QString &filterName = QString()) const; QStringList indicesForFilter(const QStringList &filterAttributes) const; void linksForKeyword(const QString &keyword, const QStringList &filterAttributes, - QMap<QString, QUrl> &linkMap) const; + QMap<QString, QUrl> *linkMap) const; void linksForIdentifier(const QString &id, const QStringList &filterAttributes, - QMap<QString, QUrl> &linkMap) const; + QMap<QString, QUrl> *linkMap) const; QList<QByteArray> contentsForFilter(const QStringList &filterAttributes) const; QUrl urlOfPath(const QString &relativePath) const; @@ -104,20 +104,19 @@ public: QVariant metaData(const QString &name) const; private: - void initObject(const QString &dbName, const QString &uniqueId); QUrl buildQUrl(const QString &ns, const QString &folder, const QString &relFileName, const QString &anchor) const; QString mergeList(const QStringList &list) const; QString quote(const QString &string) const; - bool m_initDone; + bool m_initDone = false; QString m_dbName; QString m_uniqueId; QString m_error; - QSqlQuery *m_query; + QSqlQuery *m_query = nullptr; mutable QString m_namespace; QSet<QString> m_viewAttributes; - bool m_useAttributesCache; + bool m_useAttributesCache = false; QSet<int> m_indicesCache; }; diff --git a/src/assistant/help/qhelpengine.cpp b/src/assistant/help/qhelpengine.cpp index 6562d69a3..41ded85ee 100644 --- a/src/assistant/help/qhelpengine.cpp +++ b/src/assistant/help/qhelpengine.cpp @@ -53,20 +53,6 @@ QT_BEGIN_NAMESPACE -QHelpEnginePrivate::QHelpEnginePrivate() - : QHelpEngineCorePrivate() - , contentModel(0) - , contentWidget(0) - , indexModel(0) - , indexWidget(0) - , searchEngine(0) -{ -} - -QHelpEnginePrivate::~QHelpEnginePrivate() -{ -} - void QHelpEnginePrivate::init(const QString &collectionFile, QHelpEngineCore *helpEngineCore) { diff --git a/src/assistant/help/qhelpengine_p.h b/src/assistant/help/qhelpengine_p.h index a38cc1b7a..d56b51178 100644 --- a/src/assistant/help/qhelpengine_p.h +++ b/src/assistant/help/qhelpengine_p.h @@ -74,7 +74,6 @@ class QHelpEngineCorePrivate : public QObject Q_OBJECT public: - QHelpEngineCorePrivate(); virtual ~QHelpEngineCorePrivate(); virtual void init(const QString &collectionFile, @@ -88,11 +87,11 @@ public: QMultiMap<QString, QHelpDBReader*> virtualFolderMap; QStringList orderedFileNameList; - QHelpCollectionHandler *collectionHandler; + QHelpCollectionHandler *collectionHandler = nullptr; QString currentFilter; QString error; - bool needsSetup; - bool autoSaveFilter; + bool needsSetup = true; + bool autoSaveFilter = true; protected: QHelpEngineCore *q; @@ -107,19 +106,16 @@ class QHelpEnginePrivate : public QHelpEngineCorePrivate Q_OBJECT public: - QHelpEnginePrivate(); - ~QHelpEnginePrivate(); - void init(const QString &collectionFile, QHelpEngineCore *helpEngineCore) override; - QHelpContentModel *contentModel; - QHelpContentWidget *contentWidget; + QHelpContentModel *contentModel = nullptr; + QHelpContentWidget *contentWidget = nullptr; - QHelpIndexModel *indexModel; - QHelpIndexWidget *indexWidget; + QHelpIndexModel *indexModel = nullptr; + QHelpIndexWidget *indexWidget = nullptr; - QHelpSearchEngine *searchEngine; + QHelpSearchEngine *searchEngine = nullptr; void stopDataCollection(); diff --git a/src/assistant/help/qhelpenginecore.cpp b/src/assistant/help/qhelpenginecore.cpp index 539198c54..4debf8247 100644 --- a/src/assistant/help/qhelpenginecore.cpp +++ b/src/assistant/help/qhelpenginecore.cpp @@ -52,12 +52,6 @@ QT_BEGIN_NAMESPACE -QHelpEngineCorePrivate::QHelpEngineCorePrivate() -{ - QHelpGlobal::uniquifyConnectionName(QString(), this); - autoSaveFilter = true; -} - void QHelpEngineCorePrivate::init(const QString &collectionFile, QHelpEngineCore *helpEngineCore) { @@ -103,21 +97,20 @@ bool QHelpEngineCorePrivate::setup() } const QHelpCollectionHandler::DocInfoList &docList = - collectionHandler->registeredDocumentations(); - QFileInfo fi(collectionHandler->collectionFile()); - QString absFileName; + collectionHandler->registeredDocumentations(); + const QFileInfo fi(collectionHandler->collectionFile()); + for (const QHelpCollectionHandler::DocInfo &info : docList) { - if (QDir::isAbsolutePath(info.fileName)) { - absFileName = info.fileName; - } else { - absFileName = QFileInfo(fi.absolutePath() + QDir::separator() + info.fileName) - .absoluteFilePath(); - } + const QString &absFileName = QDir::isAbsolutePath(info.fileName) + ? info.fileName + : QFileInfo(fi.absolutePath() + QDir::separator() + info.fileName) + .absoluteFilePath(); + QHelpDBReader *reader = new QHelpDBReader(absFileName, QHelpGlobal::uniquifyConnectionName(info.fileName, this), this); if (!reader->init()) { emit q->warning(QHelpEngineCore::tr("Cannot open documentation file %1: %2.") - .arg(absFileName, reader->errorMessage())); + .arg(absFileName, reader->errorMessage())); continue; } @@ -364,9 +357,8 @@ QString QHelpEngineCore::documentationFileName(const QString &namespaceName) if (QDir::isAbsolutePath(info.fileName)) return info.fileName; - QFileInfo fi(d->collectionHandler->collectionFile()); - fi.setFile(fi.absolutePath() + QDir::separator() + info.fileName); - return fi.absoluteFilePath(); + return QFileInfo(QFileInfo(d->collectionHandler->collectionFile()).absolutePath() + + QDir::separator() + info.fileName).absoluteFilePath(); } } } @@ -383,9 +375,8 @@ QStringList QHelpEngineCore::registeredDocumentations() const if (!d->setup()) return list; const QHelpCollectionHandler::DocInfoList &docList = d->collectionHandler->registeredDocumentations(); - for (const QHelpCollectionHandler::DocInfo &info : docList) { + for (const QHelpCollectionHandler::DocInfo &info : docList) list.append(info.namespaceName); - } return list; } @@ -414,8 +405,7 @@ bool QHelpEngineCore::addCustomFilter(const QString &filterName, { d->error.clear(); d->needsSetup = true; - return d->collectionHandler->addCustomFilter(filterName, - attributes); + return d->collectionHandler->addCustomFilter(filterName, attributes); } /*! @@ -469,7 +459,7 @@ QString QHelpEngineCore::currentFilter() const return QString(); if (d->currentFilter.isEmpty()) { - QString filter = + const QString &filter = d->collectionHandler->customValue(QLatin1String("CurrentFilter"), QString()).toString(); if (!filter.isEmpty() @@ -549,15 +539,16 @@ QUrl QHelpEngineCore::findFile(const QUrl &url) const { QUrl res; if (!d->setup() || !url.isValid() || url.toString().count(QLatin1Char('/')) < 4 - || url.scheme() != QLatin1String("qthelp")) + || url.scheme() != QLatin1String("qthelp")) { return res; + } - QString ns = url.authority(); + const QString &ns = url.authority(); QString filePath = url.path(); if (filePath.startsWith(QLatin1Char('/'))) filePath = filePath.mid(1); - QString virtualFolder = filePath.mid(0, filePath.indexOf(QLatin1Char('/'), 1)); - filePath = filePath.mid(virtualFolder.length()+1); + const QString &virtualFolder = filePath.mid(0, filePath.indexOf(QLatin1Char('/'), 1)); + filePath.remove(0, virtualFolder.length() + 1); QHelpDBReader *defaultReader = 0; if (d->readerMap.contains(ns)) { @@ -566,11 +557,11 @@ QUrl QHelpEngineCore::findFile(const QUrl &url) const return url; } - QStringList filterAtts = filterAttributes(currentFilter()); + const QStringList &attributes = filterAttributes(currentFilter()); for (const QHelpDBReader *reader : d->virtualFolderMap.values(virtualFolder)) { if (reader == defaultReader) continue; - if (reader->fileExists(virtualFolder, filePath, filterAtts)) { + if (reader->fileExists(virtualFolder, filePath, attributes)) { res = url; res.setAuthority(reader->namespaceName()); return res; @@ -599,15 +590,16 @@ QUrl QHelpEngineCore::findFile(const QUrl &url) const QByteArray QHelpEngineCore::fileData(const QUrl &url) const { if (!d->setup() || !url.isValid() || url.toString().count(QLatin1Char('/')) < 4 - || url.scheme() != QLatin1String("qthelp")) + || url.scheme() != QLatin1String("qthelp")) { return QByteArray(); + } - QString ns = url.authority(); + const QString &ns = url.authority(); QString filePath = url.path(); if (filePath.startsWith(QLatin1Char('/'))) filePath = filePath.mid(1); - QString virtualFolder = filePath.mid(0, filePath.indexOf(QLatin1Char('/'), 1)); - filePath = filePath.mid(virtualFolder.length()+1); + const QString &virtualFolder = filePath.mid(0, filePath.indexOf(QLatin1Char('/'), 1)); + filePath.remove(0, virtualFolder.length() + 1); QByteArray ba; QHelpDBReader *defaultReader = 0; @@ -640,9 +632,9 @@ QMap<QString, QUrl> QHelpEngineCore::linksForIdentifier(const QString &id) const if (!d->setup()) return linkMap; - QStringList atts = filterAttributes(d->currentFilter); + const QStringList &attributes = filterAttributes(d->currentFilter); for (const QHelpDBReader *reader : qAsConst(d->readerMap)) - reader->linksForIdentifier(id, atts, linkMap); + reader->linksForIdentifier(id, attributes, &linkMap); return linkMap; } diff --git a/src/assistant/help/qhelpgenerator.cpp b/src/assistant/help/qhelpgenerator.cpp index ea080adad..c8722499e 100644 --- a/src/assistant/help/qhelpgenerator.cpp +++ b/src/assistant/help/qhelpgenerator.cpp @@ -40,7 +40,7 @@ #include "qhelpgenerator_p.h" #include "qhelpdatainterface_p.h" -#include <math.h> +#include <QtCore/QtMath> #include <QtCore/QFile> #include <QtCore/QFileInfo> #include <QtCore/QDir> @@ -57,14 +57,11 @@ QT_BEGIN_NAMESPACE class QHelpGeneratorPrivate { public: - QHelpGeneratorPrivate(); - ~QHelpGeneratorPrivate(); - QString error; - QSqlQuery *query; + QSqlQuery *query = nullptr; - int namespaceId; - int virtualFolderId; + int namespaceId = -1; + int virtualFolderId = -1; QMap<QString, int> fileMap; QMap<int, QSet<int> > fileFilterMap; @@ -76,19 +73,6 @@ public: double indexStep; }; -QHelpGeneratorPrivate::QHelpGeneratorPrivate() -{ - query = 0; - namespaceId = -1; - virtualFolderId = -1; -} - -QHelpGeneratorPrivate::~QHelpGeneratorPrivate() -{ -} - - - /*! \internal \class QHelpGenerator @@ -261,9 +245,9 @@ void QHelpGenerator::setupProgress(QHelpDataInterface *helpData) void QHelpGenerator::addProgress(double step) { d->progress += step; - if ((d->progress-d->oldProgress) >= 1.0 && d->progress <= 100.0) { + if ((d->progress - d->oldProgress) >= 1.0 && d->progress <= 100.0) { d->oldProgress = d->progress; - emit progressChanged(ceil(d->progress)); + emit progressChanged(qCeil(d->progress)); } } @@ -307,62 +291,62 @@ bool QHelpGenerator::createTables() return false; } - QStringList tables; - tables << QLatin1String("CREATE TABLE NamespaceTable (" - "Id INTEGER PRIMARY KEY," - "Name TEXT )") - << QLatin1String("CREATE TABLE FilterAttributeTable (" - "Id INTEGER PRIMARY KEY, " - "Name TEXT )") - << QLatin1String("CREATE TABLE FilterNameTable (" - "Id INTEGER PRIMARY KEY, " - "Name TEXT )") - << QLatin1String("CREATE TABLE FilterTable (" - "NameId INTEGER, " - "FilterAttributeId INTEGER )") - << QLatin1String("CREATE TABLE IndexTable (" - "Id INTEGER PRIMARY KEY, " - "Name TEXT, " - "Identifier TEXT, " - "NamespaceId INTEGER, " - "FileId INTEGER, " - "Anchor TEXT )") - << QLatin1String("CREATE TABLE IndexItemTable (" - "Id INTEGER, " - "IndexId INTEGER )") - << QLatin1String("CREATE TABLE IndexFilterTable (" - "FilterAttributeId INTEGER, " - "IndexId INTEGER )") - << QLatin1String("CREATE TABLE ContentsTable (" - "Id INTEGER PRIMARY KEY, " - "NamespaceId INTEGER, " - "Data BLOB )") - << QLatin1String("CREATE TABLE ContentsFilterTable (" - "FilterAttributeId INTEGER, " - "ContentsId INTEGER )") - << QLatin1String("CREATE TABLE FileAttributeSetTable (" - "Id INTEGER, " - "FilterAttributeId INTEGER )") - << QLatin1String("CREATE TABLE FileDataTable (" - "Id INTEGER PRIMARY KEY, " - "Data BLOB )") - << QLatin1String("CREATE TABLE FileFilterTable (" - "FilterAttributeId INTEGER, " - "FileId INTEGER )") - << QLatin1String("CREATE TABLE FileNameTable (" - "FolderId INTEGER, " - "Name TEXT, " - "FileId INTEGER, " - "Title TEXT )") - << QLatin1String("CREATE TABLE FolderTable(" - "Id INTEGER PRIMARY KEY, " - "Name Text, " - "NamespaceID INTEGER )") - << QLatin1String("CREATE TABLE MetaDataTable(" - "Name Text, " - "Value BLOB )"); - - for (const QString &q : qAsConst(tables)) { + const QStringList tables = QStringList() + << QLatin1String("CREATE TABLE NamespaceTable (" + "Id INTEGER PRIMARY KEY," + "Name TEXT )") + << QLatin1String("CREATE TABLE FilterAttributeTable (" + "Id INTEGER PRIMARY KEY, " + "Name TEXT )") + << QLatin1String("CREATE TABLE FilterNameTable (" + "Id INTEGER PRIMARY KEY, " + "Name TEXT )") + << QLatin1String("CREATE TABLE FilterTable (" + "NameId INTEGER, " + "FilterAttributeId INTEGER )") + << QLatin1String("CREATE TABLE IndexTable (" + "Id INTEGER PRIMARY KEY, " + "Name TEXT, " + "Identifier TEXT, " + "NamespaceId INTEGER, " + "FileId INTEGER, " + "Anchor TEXT )") + << QLatin1String("CREATE TABLE IndexItemTable (" + "Id INTEGER, " + "IndexId INTEGER )") + << QLatin1String("CREATE TABLE IndexFilterTable (" + "FilterAttributeId INTEGER, " + "IndexId INTEGER )") + << QLatin1String("CREATE TABLE ContentsTable (" + "Id INTEGER PRIMARY KEY, " + "NamespaceId INTEGER, " + "Data BLOB )") + << QLatin1String("CREATE TABLE ContentsFilterTable (" + "FilterAttributeId INTEGER, " + "ContentsId INTEGER )") + << QLatin1String("CREATE TABLE FileAttributeSetTable (" + "Id INTEGER, " + "FilterAttributeId INTEGER )") + << QLatin1String("CREATE TABLE FileDataTable (" + "Id INTEGER PRIMARY KEY, " + "Data BLOB )") + << QLatin1String("CREATE TABLE FileFilterTable (" + "FilterAttributeId INTEGER, " + "FileId INTEGER )") + << QLatin1String("CREATE TABLE FileNameTable (" + "FolderId INTEGER, " + "Name TEXT, " + "FileId INTEGER, " + "Title TEXT )") + << QLatin1String("CREATE TABLE FolderTable(" + "Id INTEGER PRIMARY KEY, " + "Name Text, " + "NamespaceID INTEGER )") + << QLatin1String("CREATE TABLE MetaDataTable(" + "Name Text, " + "Value BLOB )"); + + for (const QString &q : tables) { if (!d->query->exec(q)) { d->error = tr("Cannot create tables."); return false; @@ -390,7 +374,7 @@ bool QHelpGenerator::insertFileNotFoundFile() if (!d->query->exec()) return false; - int fileId = d->query->lastInsertId().toInt(); + const int fileId = d->query->lastInsertId().toInt(); d->query->prepare(QLatin1String("INSERT INTO FileNameTable (FolderId, Name, FileId, Title) " " VALUES (0, '', ?, '')")); d->query->bindValue(0, fileId); @@ -525,7 +509,7 @@ bool QHelpGenerator::insertFiles(const QStringList &files, const QString &rootPa } int fileId = -1; - const auto it = d->fileMap.constFind(fileName); + const auto &it = d->fileMap.constFind(fileName); if (it == d->fileMap.cend()) { fileDataList.append(qCompress(data)); @@ -590,8 +574,8 @@ bool QHelpGenerator::insertFiles(const QStringList &files, const QString &rootPa d->query->exec(QLatin1String("SELECT MAX(Id) FROM FileDataTable")); if (d->query->next() - && d->query->value(0).toInt() == tableFileId-1) { - addProgress(d->fileStep*(i%20)); + && d->query->value(0).toInt() == tableFileId - 1) { + addProgress(d->fileStep*(i % 20)); return true; } return false; @@ -678,10 +662,6 @@ bool QHelpGenerator::insertKeywords(const QList<QHelpDataIndexItem> &keywords, filterAtts.append(d->query->value(0).toInt()); } - int pos = -1; - QString fileName; - QString anchor; - QString fName; QList<int> indexFilterTable; int i = 0; @@ -698,18 +678,13 @@ bool QHelpGenerator::insertKeywords(const QList<QHelpDataIndexItem> &keywords, if (!itm.identifier.isEmpty()) indices.insert(itm.identifier); - pos = itm.reference.indexOf(QLatin1Char('#')); - fileName = itm.reference.left(pos); - if (pos > -1) - anchor = itm.reference.mid(pos+1); - else - anchor.clear(); + const int pos = itm.reference.indexOf(QLatin1Char('#')); + const QString &fileName = itm.reference.left(pos); + const QString anchor = pos < 0 ? QString() : itm.reference.mid(pos + 1); - fName = QDir::cleanPath(fileName); - if (fName.startsWith(QLatin1String("./"))) - fName = fName.mid(2); + const QString &fName = QDir::cleanPath(fileName); - auto it = d->fileMap.constFind(fName); + const auto &it = d->fileMap.constFind(fName); const int fileId = it == d->fileMap.cend() ? 1 : it.value(); d->query->prepare(QLatin1String("INSERT INTO IndexTable (Name, Identifier, NamespaceId, FileId, Anchor) " @@ -722,8 +697,8 @@ bool QHelpGenerator::insertKeywords(const QList<QHelpDataIndexItem> &keywords, d->query->exec(); indexFilterTable.append(indexId++); - if (++i%100 == 0) - addProgress(d->indexStep*100.0); + if (++i % 100 == 0) + addProgress(d->indexStep * 100.0); } d->query->exec(QLatin1String("COMMIT")); @@ -822,7 +797,7 @@ bool QHelpGenerator::checkLinks(const QHelpDataInterface &helpData) QSet<QString> files; for (const QHelpDataFilterSection &filterSection : helpData.filterSections()) { for (const QString &file : filterSection.files()) { - QFileInfo fileInfo(helpData.rootPath() + QDir::separator() + file); + const QFileInfo fileInfo(helpData.rootPath() + QDir::separator() + file); const QString &canonicalFileName = fileInfo.canonicalFilePath(); if (!fileInfo.exists()) emit warning(tr("File '%1' does not exist.").arg(file)); @@ -847,7 +822,7 @@ bool QHelpGenerator::checkLinks(const QHelpDataInterface &helpData) emit warning(tr("File '%1' cannot be opened.").arg(fileName)); continue; } - QRegExp linkPattern(QLatin1String("<(?:a href|img src)=\"?([^#\">]+)[#\">]")); + const QRegExp linkPattern(QLatin1String("<(?:a href|img src)=\"?([^#\">]+)[#\">]")); QTextStream stream(&htmlFile); const QString codec = QHelpGlobal::codecFromData(htmlFile.read(1000)); stream.setCodec(QTextCodec::codecForName(codec.toLatin1().constData())); @@ -855,10 +830,10 @@ bool QHelpGenerator::checkLinks(const QHelpDataInterface &helpData) QStringList invalidLinks; for (int pos = linkPattern.indexIn(content); pos != -1; pos = linkPattern.indexIn(content, pos + 1)) { - const QString& linkedFileName = linkPattern.cap(1); + const QString &linkedFileName = linkPattern.cap(1); if (linkedFileName.contains(QLatin1String("://"))) continue; - const QString curDir = QFileInfo(fileName).dir().path(); + const QString &curDir = QFileInfo(fileName).dir().path(); const QString &canonicalLinkedFileName = QFileInfo(curDir + QDir::separator() + linkedFileName).canonicalFilePath(); if (!files.contains(canonicalLinkedFileName) diff --git a/src/assistant/help/qhelpindexwidget.cpp b/src/assistant/help/qhelpindexwidget.cpp index e31f8b30e..5cb4a56d4 100644 --- a/src/assistant/help/qhelpindexwidget.cpp +++ b/src/assistant/help/qhelpindexwidget.cpp @@ -71,37 +71,30 @@ private: QMap<QHelpDBReader*, QSet<int> > m_indexIds; QStringList m_filterAttributes; mutable QMutex m_mutex; - bool m_abort; + bool m_abort = false; }; class QHelpIndexModelPrivate { public: QHelpIndexModelPrivate(QHelpEnginePrivate *hE) + : helpEngine(hE), + indexProvider(new QHelpIndexProvider(helpEngine)) { - helpEngine = hE; - indexProvider = new QHelpIndexProvider(helpEngine); - insertedRows = 0; } QHelpEnginePrivate *helpEngine; QHelpIndexProvider *indexProvider; QStringList indices; - int insertedRows; + int insertedRows = 0; QString currentFilter; QList<QHelpDBReader*> activeReaders; }; -static bool caseInsensitiveLessThan(const QString &as, const QString &bs) -{ - return QString::compare(as, bs, Qt::CaseInsensitive) < 0; -} - QHelpIndexProvider::QHelpIndexProvider(QHelpEnginePrivate *helpEngine) - : QThread(helpEngine) + : QThread(helpEngine), + m_helpEngine(helpEngine) { - m_helpEngine = helpEngine; - m_abort = false; } QHelpIndexProvider::~QHelpIndexProvider() @@ -148,9 +141,7 @@ QList<QHelpDBReader*> QHelpIndexProvider::activeReaders() const QSet<int> QHelpIndexProvider::indexIds(QHelpDBReader *reader) const { QMutexLocker lck(&m_mutex); - if (m_indexIds.contains(reader)) - return m_indexIds.value(reader); - return QSet<int>(); + return m_indexIds.value(reader); } void QHelpIndexProvider::run() @@ -192,7 +183,7 @@ void QHelpIndexProvider::run() } m_mutex.lock(); m_indices = indicesSet.values(); - std::sort(m_indices.begin(), m_indices.end(), caseInsensitiveLessThan); + m_indices.sort(Qt::CaseInsensitive); m_mutex.unlock(); } @@ -267,7 +258,7 @@ void QHelpIndexModel::insertIndices() { d->indices = d->indexProvider->indices(); d->activeReaders = d->indexProvider->activeReaders(); - QStringList attributes = d->helpEngine->q->filterAttributes(d->currentFilter); + const QStringList &attributes = d->helpEngine->q->filterAttributes(d->currentFilter); if (attributes.count() > 1) { for (QHelpDBReader *r : qAsConst(d->activeReaders)) r->createAttributesCache(attributes, d->indexProvider->indexIds(r)); @@ -292,9 +283,9 @@ bool QHelpIndexModel::isCreatingIndex() const QMap<QString, QUrl> QHelpIndexModel::linksForKeyword(const QString &keyword) const { QMap<QString, QUrl> linkMap; - QStringList filterAttributes = d->helpEngine->q->filterAttributes(d->currentFilter); - for (const QHelpDBReader *reader : qAsConst(d->activeReaders)) - reader->linksForKeyword(keyword, filterAttributes, linkMap); + const QStringList &attributes = d->helpEngine->q->filterAttributes(d->currentFilter); + for (const QHelpDBReader *reader : d->activeReaders) + reader->linksForKeyword(keyword, attributes, &linkMap); return linkMap; } @@ -320,19 +311,18 @@ QModelIndex QHelpIndexModel::filter(const QString &filter, const QString &wildca int perfectMatch = -1; if (!wildcard.isEmpty()) { - QRegExp regExp(wildcard, Qt::CaseInsensitive); - regExp.setPatternSyntax(QRegExp::Wildcard); + const QRegExp regExp(wildcard, Qt::CaseInsensitive, QRegExp::Wildcard); for (const QString &index : qAsConst(d->indices)) { if (index.contains(regExp)) { lst.append(index); if (perfectMatch == -1 && index.startsWith(filter, Qt::CaseInsensitive)) { if (goodMatch == -1) - goodMatch = lst.count()-1; + goodMatch = lst.count() - 1; if (filter.length() == index.length()){ - perfectMatch = lst.count()-1; + perfectMatch = lst.count() - 1; } } else if (perfectMatch > -1 && index == filter) { - perfectMatch = lst.count()-1; + perfectMatch = lst.count() - 1; } } } @@ -342,12 +332,12 @@ QModelIndex QHelpIndexModel::filter(const QString &filter, const QString &wildca lst.append(index); if (perfectMatch == -1 && index.startsWith(filter, Qt::CaseInsensitive)) { if (goodMatch == -1) - goodMatch = lst.count()-1; + goodMatch = lst.count() - 1; if (filter.length() == index.length()){ - perfectMatch = lst.count()-1; + perfectMatch = lst.count() - 1; } } else if (perfectMatch > -1 && index == filter) { - perfectMatch = lst.count()-1; + perfectMatch = lst.count() - 1; } } } @@ -407,17 +397,14 @@ void QHelpIndexWidget::showLink(const QModelIndex &index) if (!indexModel) return; - const QVariant v = indexModel->data(index, Qt::DisplayRole); - QString name; - if (v.isValid()) - name = v.toString(); + const QVariant &v = indexModel->data(index, Qt::DisplayRole); + const QString name = v.isValid() ? v.toString() : QString(); - const QMap<QString, QUrl> links = indexModel->linksForKeyword(name); - if (links.count() > 1) { + const QMap<QString, QUrl> &links = indexModel->linksForKeyword(name); + if (links.count() > 1) emit linksActivated(links, name); - } else if (!links.isEmpty()) { + else if (!links.isEmpty()) emit linkActivated(links.first(), name); - } } /*! @@ -441,7 +428,7 @@ void QHelpIndexWidget::filterIndices(const QString &filter, const QString &wildc QHelpIndexModel *indexModel = qobject_cast<QHelpIndexModel*>(model()); if (!indexModel) return; - QModelIndex idx = indexModel->filter(filter, wildcard); + const QModelIndex &idx = indexModel->filter(filter, wildcard); if (idx.isValid()) setCurrentIndex(idx); } diff --git a/src/assistant/help/qhelpprojectdata.cpp b/src/assistant/help/qhelpprojectdata.cpp index 925e2d48f..1fd600fd9 100644 --- a/src/assistant/help/qhelpprojectdata.cpp +++ b/src/assistant/help/qhelpprojectdata.cpp @@ -94,18 +94,20 @@ void QHelpProjectDataPrivate::readData(const QByteArray &contents) readNext(); if (isStartElement()) { if (name() == QLatin1String("QtHelpProject") - && attributes().value(QLatin1String("version")) == QLatin1String("1.0")) + && attributes().value(QLatin1String("version")) + == QLatin1String("1.0")) { readProject(); - else + } else { raiseError(QCoreApplication::translate("QHelpProject", "Unknown token. Expected \"QtHelpProject\".")); + } } } if (hasError()) { raiseError(QCoreApplication::translate("QHelpProject", - "Error in line %1: %2").arg(lineNumber()) - .arg(errorString())); + "Error in line %1: %2").arg(lineNumber()) + .arg(errorString())); } } @@ -199,8 +201,8 @@ void QHelpProjectDataPrivate::readTOC() readNext(); if (isStartElement()) { if (name() == QLatin1String("section")) { - QString title = attributes().value(QLatin1String("title")).toString(); - QString ref = attributes().value(QLatin1String("ref")).toString(); + const QString &title = attributes().value(QLatin1String("title")).toString(); + const QString &ref = attributes().value(QLatin1String("ref")).toString(); if (contentStack.isEmpty()) { itm = new QHelpDataContentItem(0, title, ref); filterSectionList.last().addContent(itm); @@ -216,7 +218,7 @@ void QHelpProjectDataPrivate::readTOC() contentStack.pop(); continue; } else if (name() == QLatin1String("toc") && contentStack.isEmpty()) { - break; + return; } else { raiseUnknownTokenError(); } @@ -258,7 +260,7 @@ void QHelpProjectDataPrivate::readKeywords() if (name() == QLatin1String("keyword")) continue; else if (name() == QLatin1String("keywords")) - break; + return; else raiseUnknownTokenError(); } @@ -278,7 +280,7 @@ void QHelpProjectDataPrivate::readFiles() if (name() == QLatin1String("file")) continue; else if (name() == QLatin1String("files")) - break; + return; else raiseUnknownTokenError(); } @@ -298,12 +300,12 @@ void QHelpProjectDataPrivate::addMatchingFiles(const QString &pattern) return; } - QFileInfo fileInfo(rootPath + QLatin1Char('/') + pattern); + const QFileInfo fileInfo(rootPath + QLatin1Char('/') + pattern); const QDir &dir = fileInfo.dir(); const QString &path = dir.canonicalPath(); // QDir::entryList() is expensive, so we cache the results. - auto it = dirEntriesCache.constFind(path); + const auto &it = dirEntriesCache.constFind(path); const QStringList &entries = it != dirEntriesCache.cend() ? it.value() : dir.entryList(QDir::Files); if (it == dirEntriesCache.cend()) @@ -315,7 +317,7 @@ void QHelpProjectDataPrivate::addMatchingFiles(const QString &pattern) #else Qt::CaseSensitivity cs = Qt::CaseSensitive; #endif - QRegExp regExp(fileInfo.fileName(), cs, QRegExp::Wildcard); + const QRegExp regExp(fileInfo.fileName(), cs, QRegExp::Wildcard); for (const QString &file : entries) { if (regExp.exactMatch(file)) { matchFound = true; @@ -336,7 +338,7 @@ bool QHelpProjectDataPrivate::hasValidSyntax(const QString &nameSpace, QUrl url; const QLatin1String scheme("qthelp"); url.setScheme(scheme); - const QString canonicalNamespace = nameSpace.toLower(); + const QString &canonicalNamespace = nameSpace.toLower(); url.setHost(canonicalNamespace); url.setPath(slash + vFolder); diff --git a/src/assistant/help/qhelpsearchengine.cpp b/src/assistant/help/qhelpsearchengine.cpp index a62d4e977..6e6f8b777 100644 --- a/src/assistant/help/qhelpsearchengine.cpp +++ b/src/assistant/help/qhelpsearchengine.cpp @@ -150,7 +150,6 @@ QString QHelpSearchResult::snippet() const } - class QHelpSearchEnginePrivate : public QObject { Q_OBJECT @@ -164,12 +163,8 @@ signals: private: QHelpSearchEnginePrivate(QHelpEngineCore *helpEngine) - : queryWidget(0) - , resultWidget(0) - , helpEngine(helpEngine) + : helpEngine(helpEngine) { - indexReader = 0; - indexWriter = 0; } ~QHelpSearchEnginePrivate() @@ -262,11 +257,11 @@ private: bool m_isIndexingScheduled = false; - QHelpSearchQueryWidget *queryWidget; - QHelpSearchResultWidget *resultWidget; + QHelpSearchQueryWidget *queryWidget = nullptr; + QHelpSearchResultWidget *resultWidget = nullptr; - fulltextsearch::QHelpSearchIndexReader *indexReader; - QHelpSearchIndexWriter *indexWriter; + fulltextsearch::QHelpSearchIndexReader *indexReader = nullptr; + QHelpSearchIndexWriter *indexWriter = nullptr; QPointer<QHelpEngineCore> helpEngine; @@ -543,7 +538,6 @@ void QHelpSearchEngine::cancelSearching() d->cancelSearching(); } - /*! \since 5.9 Starts the search process using the given search phrase \a searchInput. @@ -578,6 +572,9 @@ void QHelpSearchEngine::search(const QList<QHelpSearchQuery> &queryList) d->search(queryList.first().wordList.join(QChar::Space)); } +/*! + \internal +*/ void QHelpSearchEngine::scheduleIndexDocumentation() { if (d->m_isIndexingScheduled) diff --git a/src/assistant/help/qhelpsearchengine.h b/src/assistant/help/qhelpsearchengine.h index 02cdbab9a..c5defb610 100644 --- a/src/assistant/help/qhelpsearchengine.h +++ b/src/assistant/help/qhelpsearchengine.h @@ -51,7 +51,6 @@ QT_BEGIN_NAMESPACE - class QHelpEngineCore; class QHelpSearchQueryWidget; class QHelpSearchEnginePrivate; diff --git a/src/assistant/help/qhelpsearchindexreader_default.cpp b/src/assistant/help/qhelpsearchindexreader_default.cpp index 86945bfb1..7f8c1bbf8 100644 --- a/src/assistant/help/qhelpsearchindexreader_default.cpp +++ b/src/assistant/help/qhelpsearchindexreader_default.cpp @@ -63,7 +63,7 @@ void Reader::addNamespace(const QString &namespaceName, const QStringList &attri static QString namespacePlaceholders(const QMultiMap<QString, QStringList> &namespaces) { QString placeholders; - const auto namespaceList = namespaces.uniqueKeys(); + const auto &namespaceList = namespaces.uniqueKeys(); bool firstNS = true; for (const QString &ns : namespaceList) { if (firstNS) @@ -95,7 +95,7 @@ static QString namespacePlaceholders(const QMultiMap<QString, QStringList> &name static void bindNamespacesAndAttributes(QSqlQuery *query, const QMultiMap<QString, QStringList> &namespaces) { QString placeholders; - const auto namespaceList = namespaces.uniqueKeys(); + const auto &namespaceList = namespaces.uniqueKeys(); for (const QString &ns : namespaceList) { query->addBindValue(ns); @@ -111,7 +111,7 @@ QVector<QHelpSearchResult> Reader::queryTable(const QSqlDatabase &db, const QString &tableName, const QString &searchInput) const { - const QString nsPlaceholders = namespacePlaceholders(m_namespaces); + const QString &nsPlaceholders = namespacePlaceholders(m_namespaces); QSqlQuery query(db); query.prepare(QLatin1String("SELECT url, title, snippet(") + tableName + QLatin1String(", -1, '<b>', '</b>', '...', '10') FROM ") + tableName + @@ -125,9 +125,9 @@ QVector<QHelpSearchResult> Reader::queryTable(const QSqlDatabase &db, QVector<QHelpSearchResult> results; while (query.next()) { - const QString url = query.value(QLatin1String("url")).toString(); - const QString title = query.value(QLatin1String("title")).toString(); - const QString snippet = query.value(2).toString(); + const QString &url = query.value(QLatin1String("url")).toString(); + const QString &title = query.value(QLatin1String("title")).toString(); + const QString &snippet = query.value(2).toString(); results.append(QHelpSearchResult(url, title, snippet)); } diff --git a/src/assistant/help/qhelpsearchindexreader_p.h b/src/assistant/help/qhelpsearchindexreader_p.h index 924f3e4ec..476f3d077 100644 --- a/src/assistant/help/qhelpsearchindexreader_p.h +++ b/src/assistant/help/qhelpsearchindexreader_p.h @@ -69,13 +69,12 @@ class QHelpSearchIndexReader : public QThread Q_OBJECT public: - QHelpSearchIndexReader() = default; ~QHelpSearchIndexReader(); void cancelSearching(); void search(const QString &collectionFile, - const QString &indexFilesFolder, - const QString &searchInput); + const QString &indexFilesFolder, + const QString &searchInput); int searchResultCount() const; QVector<QHelpSearchResult> searchResults(int start, int end) const; diff --git a/src/assistant/help/qhelpsearchindexwriter_default.cpp b/src/assistant/help/qhelpsearchindexwriter_default.cpp index 1bd518c97..2dbbb30d2 100644 --- a/src/assistant/help/qhelpsearchindexwriter_default.cpp +++ b/src/assistant/help/qhelpsearchindexwriter_default.cpp @@ -74,7 +74,7 @@ Writer::Writer(const QString &path) const QString dbPath = m_dbDir + QLatin1Char('/') + QLatin1String(FTS_DB_NAME); m_db->setDatabaseName(dbPath); if (!m_db->open()) { - const QString error = QHelpSearchIndexWriter::tr("Cannot open database \"%1\" using connection \"%2\": %3") + const QString &error = QHelpSearchIndexWriter::tr("Cannot open database \"%1\" using connection \"%2\": %3") .arg(dbPath, m_uniqueId, m_db->lastError().text()); qWarning("%s", qUtf8Printable(error)); delete m_db; diff --git a/src/assistant/help/qhelpsearchquerywidget.cpp b/src/assistant/help/qhelpsearchquerywidget.cpp index bddb0c321..7364c7cae 100644 --- a/src/assistant/help/qhelpsearchquerywidget.cpp +++ b/src/assistant/help/qhelpsearchquerywidget.cpp @@ -99,11 +99,8 @@ private: QHelpSearchQueryWidgetPrivate() : QObject() - , m_compactMode(false) , m_searchCompleter(new CompleterModel(this), this) { - m_searchButton = 0; - m_lineEdit = 0; } ~QHelpSearchQueryWidgetPrivate() @@ -196,12 +193,12 @@ private slots: private: friend class QHelpSearchQueryWidget; - bool m_compactMode; - QLabel *m_searchLabel; - QPushButton *m_searchButton; - QLineEdit *m_lineEdit; - QToolButton *m_nextQueryButton; - QToolButton *m_prevQueryButton; + bool m_compactMode = false; + QLabel *m_searchLabel = nullptr; + QPushButton *m_searchButton = nullptr; + QLineEdit *m_lineEdit = nullptr; + QToolButton *m_nextQueryButton = nullptr; + QToolButton *m_prevQueryButton = nullptr; QueryHistory m_queries; QCompleter m_searchCompleter; }; diff --git a/src/assistant/help/qhelpsearchresultwidget.cpp b/src/assistant/help/qhelpsearchresultwidget.cpp index 2e4eaee68..4d975e38b 100644 --- a/src/assistant/help/qhelpsearchresultwidget.cpp +++ b/src/assistant/help/qhelpsearchresultwidget.cpp @@ -74,7 +74,7 @@ public: QString htmlFile = QString(QLatin1String("<html><head><title>%1" "</title></head><body>")).arg(tr("Search Results")); - int count = results.count(); + const int count = results.count(); if (count != 0) { if (isIndexing) htmlFile += QString(QLatin1String("<div style=\"text-align:left;" @@ -125,7 +125,7 @@ private slots: { if (!searchEngine.isNull()) { showFirstResultPage(); - updateNextButtonState(((hitsCount > 20) ? true : false)); + updateNextButtonState((hitsCount > 20) ? true : false); } } @@ -181,7 +181,7 @@ private slots: count = 20; resultLastToShow -= count; - resultFirstToShow = resultLastToShow -20; + resultFirstToShow = resultLastToShow - 20; resultTextBrowser->showResultPage(searchEngine->searchResults(resultFirstToShow, resultLastToShow), isIndexing); @@ -217,19 +217,7 @@ private: QHelpSearchResultWidgetPrivate(QHelpSearchEngine *engine) : QObject() , searchEngine(engine) - , isIndexing(false) { - resultTextBrowser = 0; - - resultLastToShow = 20; - resultFirstToShow = 0; - - firstResultPage = 0; - previousResultPage = 0; - hitsLabel = 0; - nextResultPage = 0; - lastResultPage = 0; - connect(searchEngine.data(), &QHelpSearchEngine::indexingStarted, this, &QHelpSearchResultWidgetPrivate::indexingStarted); connect(searchEngine.data(), &QHelpSearchEngine::indexingFinished, @@ -274,17 +262,17 @@ private: QPointer<QHelpSearchEngine> searchEngine; - QResultWidget *resultTextBrowser; + QResultWidget *resultTextBrowser = nullptr; - int resultLastToShow; - int resultFirstToShow; - bool isIndexing; + int resultLastToShow = 20; + int resultFirstToShow = 0; + bool isIndexing = false; - QToolButton *firstResultPage; - QToolButton *previousResultPage; - QLabel *hitsLabel; - QToolButton *nextResultPage; - QToolButton *lastResultPage; + QToolButton *firstResultPage = nullptr; + QToolButton *previousResultPage = nullptr; + QLabel *hitsLabel = nullptr; + QToolButton *nextResultPage = nullptr; + QToolButton *lastResultPage = nullptr; }; #include "qhelpsearchresultwidget.moc" @@ -391,10 +379,9 @@ QHelpSearchResultWidget::~QHelpSearchResultWidget() */ QUrl QHelpSearchResultWidget::linkAt(const QPoint &point) { - QUrl url; if (d->resultTextBrowser) - url = d->resultTextBrowser->anchorAt(point); - return url; + return d->resultTextBrowser->anchorAt(point); + return QUrl(); } QT_END_NAMESPACE diff --git a/src/assistant/qcollectiongenerator/main.cpp b/src/assistant/qcollectiongenerator/main.cpp index 8d5ada7db..f95b1cc44 100644 --- a/src/assistant/qcollectiongenerator/main.cpp +++ b/src/assistant/qcollectiongenerator/main.cpp @@ -437,7 +437,7 @@ int main(int argc, char *argv[]) return -1; } - const auto filesToGenerate = config.filesToGenerate(); + const QMap<QString, QString> &filesToGenerate = config.filesToGenerate(); for (auto it = filesToGenerate.cbegin(), end = filesToGenerate.cend(); it != end; ++it) { fputs(qPrintable(QCG::tr("Generating help for %1...\n").arg(it.key())), stdout); QHelpProjectData helpData; @@ -528,7 +528,7 @@ int main(int argc, char *argv[]) if (config.aboutMenuTexts().count()) { QByteArray ba; QDataStream s(&ba, QIODevice::WriteOnly); - const auto aboutMenuTexts = config.aboutMenuTexts(); + const QMap<QString, QString> &aboutMenuTexts = config.aboutMenuTexts(); for (auto it = aboutMenuTexts.cbegin(), end = aboutMenuTexts.cend(); it != end; ++it) s << it.key() << it.value(); CollectionConfiguration::setAboutMenuTexts(helpEngine, ba); @@ -553,7 +553,7 @@ int main(int argc, char *argv[]) QRegExp imgRegExp(QLatin1String("(<img[^>]+>)")); imgRegExp.setMinimal(true); - const auto aboutMenuTexts = config.aboutTextFiles(); + const QMap<QString, QString> &aboutMenuTexts = config.aboutTextFiles(); for (auto it = aboutMenuTexts.cbegin(), end = aboutMenuTexts.cend(); it != end; ++it) { s << it.key(); QFileInfo fi(absoluteFileName(basePath, it.value())); diff --git a/src/assistant/qhelpconverter/qhpwriter.cpp b/src/assistant/qhelpconverter/qhpwriter.cpp index 09dcaf70f..446d7d7ce 100644 --- a/src/assistant/qhelpconverter/qhpwriter.cpp +++ b/src/assistant/qhelpconverter/qhpwriter.cpp @@ -147,7 +147,7 @@ void QhpWriter::writeKeywords() writeAttribute(QLatin1String("ref"), i.reference); if (m_prefix == FilePrefix) { QString str = i.reference.mid( - i.reference.lastIndexOf(QLatin1Char('/'))+1); + i.reference.lastIndexOf(QLatin1Char('/')) + 1); str = str.left(str.lastIndexOf(QLatin1Char('.'))); writeAttribute(QLatin1String("id"), str + QLatin1String("::") + i.keyword); } else if (m_prefix == GlobalPrefix) { |