summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJarek Kobus <jaroslaw.kobus@qt.io>2024-02-08 00:23:51 +0100
committerJarek Kobus <jaroslaw.kobus@qt.io>2024-02-13 22:24:11 +0100
commit25a36bca696023c9fe8ea7514a074df360660473 (patch)
tree5a1dc79622e3a77b94875d9d90ca6d7e0c988eac
parent9f125e0dff3f6e7b4d4079218db459ee328af46c (diff)
QtHelp: Bit more cleanup in cpp files
Inline some short methods in private API. Use more {} for default constructed values. Fix indentations. Add some TODOs. Task-number: QTBUG-122025 Change-Id: I29062709f6d302a8768ead1c20eda3af5c256c74 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
-rw-r--r--src/assistant/help/qcompressedhelpinfo.cpp8
-rw-r--r--src/assistant/help/qfilternamedialog.cpp11
-rw-r--r--src/assistant/help/qfilternamedialog_p.h2
-rw-r--r--src/assistant/help/qhelp_global.cpp8
-rw-r--r--src/assistant/help/qhelp_global.h5
-rw-r--r--src/assistant/help/qhelpcollectionhandler.cpp178
-rw-r--r--src/assistant/help/qhelpcollectionhandler_p.h4
-rw-r--r--src/assistant/help/qhelpcontentitem.cpp1
-rw-r--r--src/assistant/help/qhelpdbreader.cpp36
-rw-r--r--src/assistant/help/qhelpengine.cpp6
-rw-r--r--src/assistant/help/qhelpenginecore.cpp74
-rw-r--r--src/assistant/help/qhelpfilterdata.cpp12
-rw-r--r--src/assistant/help/qhelpfilterengine.cpp22
-rw-r--r--src/assistant/help/qhelpfiltersettingswidget.cpp79
-rw-r--r--src/assistant/help/qhelpindexwidget.cpp21
-rw-r--r--src/assistant/help/qhelplink.h1
-rw-r--r--src/assistant/help/qhelpsearchengine.cpp15
-rw-r--r--src/assistant/help/qhelpsearchindexreader.cpp48
-rw-r--r--src/assistant/help/qhelpsearchindexreader_p.h1
-rw-r--r--src/assistant/help/qhelpsearchindexwriter.cpp30
-rw-r--r--src/assistant/help/qhelpsearchindexwriter_p.h4
-rw-r--r--src/assistant/help/qhelpsearchquerywidget.cpp38
-rw-r--r--src/assistant/help/qhelpsearchresult.cpp4
-rw-r--r--src/assistant/help/qhelpsearchresultwidget.cpp38
-rw-r--r--src/assistant/help/qoptionswidget.cpp43
-rw-r--r--src/assistant/help/qoptionswidget_p.h8
-rw-r--r--src/assistant/qhelpgenerator/helpgenerator.cpp2
27 files changed, 249 insertions, 450 deletions
diff --git a/src/assistant/help/qcompressedhelpinfo.cpp b/src/assistant/help/qcompressedhelpinfo.cpp
index b88a6faf2..5841424b8 100644
--- a/src/assistant/help/qcompressedhelpinfo.cpp
+++ b/src/assistant/help/qcompressedhelpinfo.cpp
@@ -21,7 +21,6 @@ public:
, m_version(other.m_version)
, m_isNull(other.m_isNull)
{ }
- ~QCompressedHelpInfoPrivate() = default;
QString m_namespaceName;
QString m_component;
@@ -54,8 +53,7 @@ public:
*/
QCompressedHelpInfo::QCompressedHelpInfo()
: d(new QCompressedHelpInfoPrivate)
-{
-}
+{}
/*!
Constructs a copy of \a other.
@@ -133,7 +131,7 @@ QCompressedHelpInfo QCompressedHelpInfo::fromCompressedHelpFile(const QString &d
{
QHelpDBReader reader(documentationFileName,
QHelpGlobal::uniquifyConnectionName(QLatin1String("GetCompressedHelpInfo"),
- QThread::currentThread()), nullptr);
+ QThread::currentThread()), nullptr); // TODO: Replace QThread with *this
if (reader.init()) {
QCompressedHelpInfo info;
info.d->m_namespaceName = reader.namespaceName();
@@ -142,7 +140,7 @@ QCompressedHelpInfo QCompressedHelpInfo::fromCompressedHelpFile(const QString &d
info.d->m_isNull = false;
return info;
}
- return QCompressedHelpInfo();
+ return {};
}
QT_END_NAMESPACE
diff --git a/src/assistant/help/qfilternamedialog.cpp b/src/assistant/help/qfilternamedialog.cpp
index 7b060e5b4..63232fc45 100644
--- a/src/assistant/help/qfilternamedialog.cpp
+++ b/src/assistant/help/qfilternamedialog.cpp
@@ -15,8 +15,7 @@ QFilterNameDialog::QFilterNameDialog(QWidget *parent)
this, &QDialog::accept);
connect(m_ui.buttonBox->button(QDialogButtonBox::Cancel), &QAbstractButton::clicked,
this, &QDialog::reject);
- connect(m_ui.lineEdit, &QLineEdit::textChanged,
- this, &QFilterNameDialog::updateOkButton);
+ connect(m_ui.lineEdit, &QLineEdit::textChanged, this, &QFilterNameDialog::updateOkButton);
m_ui.buttonBox->button(QDialogButtonBox::Ok)->setDisabled(true);
}
@@ -26,15 +25,9 @@ void QFilterNameDialog::setFilterName(const QString &filter)
m_ui.lineEdit->selectAll();
}
-QString QFilterNameDialog::filterName() const
-{
- return m_ui.lineEdit->text();
-}
-
void QFilterNameDialog::updateOkButton()
{
- m_ui.buttonBox->button(QDialogButtonBox::Ok)
- ->setDisabled(m_ui.lineEdit->text().isEmpty());
+ m_ui.buttonBox->button(QDialogButtonBox::Ok)->setDisabled(m_ui.lineEdit->text().isEmpty());
}
QT_END_NAMESPACE
diff --git a/src/assistant/help/qfilternamedialog_p.h b/src/assistant/help/qfilternamedialog_p.h
index 024bd4c21..3fd9ba304 100644
--- a/src/assistant/help/qfilternamedialog_p.h
+++ b/src/assistant/help/qfilternamedialog_p.h
@@ -29,7 +29,7 @@ public:
QFilterNameDialog(QWidget *parent = nullptr);
void setFilterName(const QString &filter);
- QString filterName() const;
+ QString filterName() const { return m_ui.lineEdit->text(); }
private slots:
void updateOkButton();
diff --git a/src/assistant/help/qhelp_global.cpp b/src/assistant/help/qhelp_global.cpp
index f4b8ac01c..3eb964766 100644
--- a/src/assistant/help/qhelp_global.cpp
+++ b/src/assistant/help/qhelp_global.cpp
@@ -6,18 +6,14 @@
#include <QtCore/qcoreapplication.h>
#include <QtCore/qhash.h>
#include <QtCore/qmutex.h>
-#include <QtCore/qregularexpression.h>
#include <QtGui/qtextdocument.h>
QString QHelpGlobal::uniquifyConnectionName(const QString &name, void *pointer)
{
static QMutex mutex;
QMutexLocker locker(&mutex);
-
- static QHash<QString,quint16> idHash;
-
- return QString::fromLatin1("%1-%2-%3").
- arg(name).arg(quintptr(pointer)).arg(++idHash[name]);
+ static QHash<QString, quint16> idHash;
+ return QString::asprintf("%ls-%p-%d", qUtf16Printable(name), pointer, ++idHash[name]);
}
QString QHelpGlobal::documentTitle(const QString &content)
diff --git a/src/assistant/help/qhelp_global.h b/src/assistant/help/qhelp_global.h
index 64c158e78..b7367ee37 100644
--- a/src/assistant/help/qhelp_global.h
+++ b/src/assistant/help/qhelp_global.h
@@ -18,7 +18,10 @@ class QString;
# define QHELP_EXPORT Q_DECL_IMPORT
#endif
-class QHELP_EXPORT QHelpGlobal {
+// TODO Qt 7.0: Remove the class and make it a namespace with a collection of functions.
+// Review, if they are still need to be public.
+class QHELP_EXPORT QHelpGlobal
+{
public:
static QString uniquifyConnectionName(const QString &name, void *pointer);
static QString documentTitle(const QString &content);
diff --git a/src/assistant/help/qhelpcollectionhandler.cpp b/src/assistant/help/qhelpcollectionhandler.cpp
index 4d0d5d679..5f0649edc 100644
--- a/src/assistant/help/qhelpcollectionhandler.cpp
+++ b/src/assistant/help/qhelpcollectionhandler.cpp
@@ -74,8 +74,7 @@ bool QHelpCollectionHandler::isDBOpened() const
if (m_query)
return true;
auto *that = const_cast<QHelpCollectionHandler *>(this);
- emit that->error(tr("The collection file \"%1\" is not set up yet.").
- arg(m_collectionFile));
+ emit that->error(tr("The collection file \"%1\" is not set up yet.").arg(m_collectionFile));
return false;
}
@@ -87,12 +86,7 @@ void QHelpCollectionHandler::closeDB()
delete m_query;
m_query = nullptr;
QSqlDatabase::removeDatabase(m_connectionName);
- m_connectionName = QString();
-}
-
-QString QHelpCollectionHandler::collectionFile() const
-{
- return m_collectionFile;
+ m_connectionName.clear();
}
bool QHelpCollectionHandler::openCollectionFile()
@@ -229,7 +223,6 @@ bool QHelpCollectionHandler::openCollectionFile()
unregisterDocumentation(info.namespaceName);
}
}
-
return true;
}
@@ -238,8 +231,7 @@ QString QHelpCollectionHandler::absoluteDocPath(const QString &fileName) const
const QFileInfo fi(collectionFile());
return QDir::isAbsolutePath(fileName)
? fileName
- : QFileInfo(fi.absolutePath() + QLatin1Char('/') + fileName)
- .absoluteFilePath();
+ : QFileInfo(fi.absolutePath() + QLatin1Char('/') + fileName).absoluteFilePath();
}
bool QHelpCollectionHandler::isTimeStampCorrect(const TimeStamp &timeStamp) const
@@ -256,8 +248,8 @@ bool QHelpCollectionHandler::isTimeStampCorrect(const TimeStamp &timeStamp) cons
return false;
m_query->prepare(QLatin1String("SELECT FilePath "
- "FROM NamespaceTable "
- "WHERE Id = ?"));
+ "FROM NamespaceTable "
+ "WHERE Id = ?"));
m_query->bindValue(0, timeStamp.namespaceId);
if (!m_query->exec() || !m_query->next())
return false;
@@ -273,12 +265,12 @@ bool QHelpCollectionHandler::isTimeStampCorrect(const TimeStamp &timeStamp) cons
bool QHelpCollectionHandler::hasTimeStampInfo(const QString &nameSpace) const
{
m_query->prepare(QLatin1String("SELECT "
- "TimeStampTable.NamespaceId "
- "FROM "
- "NamespaceTable, "
- "TimeStampTable "
- "WHERE NamespaceTable.Id = TimeStampTable.NamespaceId "
- "AND NamespaceTable.Name = ? LIMIT 1"));
+ "TimeStampTable.NamespaceId "
+ "FROM "
+ "NamespaceTable, "
+ "TimeStampTable "
+ "WHERE NamespaceTable.Id = TimeStampTable.NamespaceId "
+ "AND NamespaceTable.Name = ? LIMIT 1"));
m_query->bindValue(0, nameSpace);
if (!m_query->exec())
return false;
@@ -315,8 +307,7 @@ bool QHelpCollectionHandler::copyCollectionFile(const QString &fileName)
const QFileInfo fi(fileName);
if (fi.exists()) {
- emit error(tr("The collection file \"%1\" already exists.").
- arg(fileName));
+ emit error(tr("The collection file \"%1\" already exists.").arg(fileName));
return false;
}
@@ -537,7 +528,6 @@ QStringList QHelpCollectionHandler::customFilters() const
return list;
}
-
QStringList QHelpCollectionHandler::filters() const
{
QStringList list;
@@ -999,7 +989,7 @@ bool QHelpCollectionHandler::fileExists(const QUrl &url) const
static QString prepareFilterQuery(const QString &filterName)
{
if (filterName.isEmpty())
- return QString();
+ return {};
return QString::fromLatin1(" AND EXISTS(SELECT * FROM Filter WHERE Filter.Name = ?) "
"AND ("
@@ -1066,7 +1056,7 @@ static QString prepareFilterQuery(int attributesCount,
const QString &filterColumnName)
{
if (!attributesCount)
- return QString();
+ return {};
QString filterQuery = QString::fromLatin1(" AND (%1.%2 IN (").arg(idTableName, idColumnName);
@@ -1116,11 +1106,11 @@ QString QHelpCollectionHandler::namespaceForFile(const QUrl &url,
const QStringList &filterAttributes) const
{
if (!isDBOpened())
- return QString();
+ return {};
const FileInfo fileInfo = extractFileInfo(url);
if (fileInfo.namespaceName.isEmpty())
- return QString();
+ return {};
const QString filterlessQuery = QLatin1String(
"SELECT DISTINCT "
@@ -1147,14 +1137,14 @@ QString QHelpCollectionHandler::namespaceForFile(const QUrl &url,
bindFilterQuery(m_query, 2, filterAttributes);
if (!m_query->exec())
- return QString();
+ return {};
- QList<QString> namespaceList;
+ QStringList namespaceList;
while (m_query->next())
namespaceList.append(m_query->value(0).toString());
if (namespaceList.isEmpty())
- return QString();
+ return {};
if (namespaceList.contains(fileInfo.namespaceName))
return fileInfo.namespaceName;
@@ -1175,11 +1165,11 @@ QString QHelpCollectionHandler::namespaceForFile(const QUrl &url,
const QString &filterName) const
{
if (!isDBOpened())
- return QString();
+ return {};
const FileInfo fileInfo = extractFileInfo(url);
if (fileInfo.namespaceName.isEmpty())
- return QString();
+ return {};
const QString filterlessQuery = QLatin1String(
"SELECT DISTINCT "
@@ -1202,14 +1192,14 @@ QString QHelpCollectionHandler::namespaceForFile(const QUrl &url,
bindFilterQuery(m_query, 2, filterName);
if (!m_query->exec())
- return QString();
+ return {};
- QList<QString> namespaceList;
+ QStringList namespaceList;
while (m_query->next())
namespaceList.append(m_query->value(0).toString());
if (namespaceList.isEmpty())
- return QString();
+ return {};
if (namespaceList.contains(fileInfo.namespaceName))
return fileInfo.namespaceName;
@@ -1231,7 +1221,7 @@ QStringList QHelpCollectionHandler::files(const QString &namespaceName,
const QString &extensionFilter) const
{
if (!isDBOpened())
- return QStringList();
+ return {};
const QString extensionQuery = extensionFilter.isEmpty()
? QString() : QLatin1String(" AND FileNameTable.Name LIKE ?");
@@ -1264,7 +1254,7 @@ QStringList QHelpCollectionHandler::files(const QString &namespaceName,
bindFilterQuery(m_query, bindCount, filterAttributes);
if (!m_query->exec())
- return QStringList();
+ return {};
QStringList fileNames;
while (m_query->next()) {
@@ -1281,7 +1271,7 @@ QStringList QHelpCollectionHandler::files(const QString &namespaceName,
const QString &extensionFilter) const
{
if (!isDBOpened())
- return QStringList();
+ return {};
const QString extensionQuery = extensionFilter.isEmpty()
? QString() : QLatin1String(" AND FileNameTable.Name LIKE ?");
@@ -1311,7 +1301,7 @@ QStringList QHelpCollectionHandler::files(const QString &namespaceName,
bindFilterQuery(m_query, bindCount, filterName);
if (!m_query->exec())
- return QStringList();
+ return{};
QStringList fileNames;
while (m_query->next()) {
@@ -1319,18 +1309,17 @@ QStringList QHelpCollectionHandler::files(const QString &namespaceName,
+ QLatin1Char('/')
+ m_query->value(1).toString());
}
-
return fileNames;
}
QUrl QHelpCollectionHandler::findFile(const QUrl &url, const QStringList &filterAttributes) const
{
if (!isDBOpened())
- return QUrl();
+ return {};
const QString namespaceName = namespaceForFile(url, filterAttributes);
if (namespaceName.isEmpty())
- return QUrl();
+ return {};
QUrl result = url;
result.setAuthority(namespaceName);
@@ -1340,11 +1329,11 @@ QUrl QHelpCollectionHandler::findFile(const QUrl &url, const QStringList &filter
QUrl QHelpCollectionHandler::findFile(const QUrl &url, const QString &filterName) const
{
if (!isDBOpened())
- return QUrl();
+ return {};
const QString namespaceName = namespaceForFile(url, filterName);
if (namespaceName.isEmpty())
- return QUrl();
+ return {};
QUrl result = url;
result.setAuthority(namespaceName);
@@ -1354,11 +1343,11 @@ QUrl QHelpCollectionHandler::findFile(const QUrl &url, const QString &filterName
QByteArray QHelpCollectionHandler::fileData(const QUrl &url) const
{
if (!isDBOpened())
- return QByteArray();
+ return {};
const QString namespaceName = namespaceForFile(url, QString());
if (namespaceName.isEmpty())
- return QByteArray();
+ return {};
const FileInfo fileInfo = extractFileInfo(url);
@@ -1366,9 +1355,9 @@ QByteArray QHelpCollectionHandler::fileData(const QUrl &url) const
const QString absFileName = absoluteDocPath(docInfo.fileName);
QHelpDBReader reader(absFileName, QHelpGlobal::uniquifyConnectionName(
- docInfo.fileName, const_cast<QHelpCollectionHandler *>(this)), nullptr);
+ docInfo.fileName, const_cast<QHelpCollectionHandler *>(this)), nullptr);
if (!reader.init())
- return QByteArray();
+ return {};
return reader.fileData(fileInfo.folderName, fileInfo.fileName);
}
@@ -1412,7 +1401,6 @@ QStringList QHelpCollectionHandler::indicesForFilter(const QStringList &filterAt
return indices;
}
-
QStringList QHelpCollectionHandler::indicesForFilter(const QString &filterName) const
{
QStringList indices;
@@ -1450,7 +1438,7 @@ QStringList QHelpCollectionHandler::indicesForFilter(const QString &filterName)
static QString getTitle(const QByteArray &contents)
{
if (!contents.size())
- return QString();
+ return {};
int depth = 0;
QString link;
@@ -1468,7 +1456,7 @@ QList<QHelpCollectionHandler::ContentsData> QHelpCollectionHandler::contentsForF
const QStringList &filterAttributes) const
{
if (!isDBOpened())
- return QList<ContentsData>();
+ return {};
const QString filterlessQuery = QString::fromLatin1(
"SELECT DISTINCT "
@@ -1524,14 +1512,13 @@ QList<QHelpCollectionHandler::ContentsData> QHelpCollectionHandler::contentsForF
result.append(it.value());
}
}
-
return result;
}
QList<QHelpCollectionHandler::ContentsData> QHelpCollectionHandler::contentsForFilter(const QString &filterName) const
{
if (!isDBOpened())
- return QList<ContentsData>();
+ return {};
const QString filterlessQuery = QString::fromLatin1(
"SELECT DISTINCT "
@@ -1549,8 +1536,7 @@ QList<QHelpCollectionHandler::ContentsData> QHelpCollectionHandler::contentsForF
"AND ContentsTable.NamespaceId = NamespaceTable.Id "
"AND VersionTable.NamespaceId = NamespaceTable.Id");
- const QString filterQuery = filterlessQuery
- + prepareFilterQuery(filterName);
+ const QString filterQuery = filterlessQuery + prepareFilterQuery(filterName);
m_query->prepare(filterQuery);
bindFilterQuery(m_query, 0, filterName);
@@ -1583,7 +1569,6 @@ QList<QHelpCollectionHandler::ContentsData> QHelpCollectionHandler::contentsForF
result.append(it.value());
}
}
-
return result;
}
@@ -1618,7 +1603,6 @@ QVariant QHelpCollectionHandler::customValue(const QString &key,
m_query->clear();
return value;
}
-
return defaultValue;
}
@@ -1690,7 +1674,6 @@ bool QHelpCollectionHandler::registerFileAttributeSets(const QList<QStringList>
++attributeSetId;
for (const QString &attribute : attributeSet) {
-
m_query->prepare(QLatin1String("SELECT Id FROM FilterAttributeTable WHERE Name=?"));
m_query->bindValue(0, attribute);
@@ -1747,9 +1730,8 @@ QStringList QHelpCollectionHandler::filterAttributes(const QString &filterName)
QList<QStringList> QHelpCollectionHandler::filterAttributeSets(const QString &namespaceName) const
{
- QList<QStringList> result;
if (!isDBOpened())
- return result;
+ return {};
m_query->prepare(QLatin1String(
"SELECT "
@@ -1766,6 +1748,7 @@ QList<QStringList> QHelpCollectionHandler::filterAttributeSets(const QString &na
m_query->bindValue(0, namespaceName);
m_query->exec();
int oldId = -1;
+ QList<QStringList> result;
while (m_query->next()) {
const int id = m_query->value(0).toInt();
if (id != oldId) {
@@ -1777,14 +1760,13 @@ QList<QStringList> QHelpCollectionHandler::filterAttributeSets(const QString &na
if (result.isEmpty())
result.append(QStringList());
-
return result;
}
QString QHelpCollectionHandler::namespaceVersion(const QString &namespaceName) const
{
if (!m_query)
- return QString();
+ return {};
m_query->prepare(QLatin1String("SELECT "
"VersionTable.Version "
@@ -1795,11 +1777,10 @@ QString QHelpCollectionHandler::namespaceVersion(const QString &namespaceName) c
"AND NamespaceTable.Id = VersionTable.NamespaceId"));
m_query->bindValue(0, namespaceName);
if (!m_query->exec() || !m_query->next())
- return QString();
+ return {};
const QString ret = m_query->value(0).toString();
m_query->clear();
-
return ret;
}
@@ -1853,10 +1834,8 @@ int QHelpCollectionHandler::registerVirtualFolder(const QString &folderName, int
emit error(tr("Cannot register virtual folder '%1'.").arg(folderName));
return -1;
}
-
if (registerComponent(folderName, namespaceId) < 0)
return -1;
-
return virtualId;
}
@@ -1943,7 +1922,6 @@ bool QHelpCollectionHandler::registerIndexAndNamespaceFilterTables(
if (createDefaultVersionFilter)
createVersionFilter(reader.version());
-
return true;
}
@@ -1961,7 +1939,7 @@ void QHelpCollectionHandler::createVersionFilter(const QString &version)
return;
QHelpFilterData filterData;
- filterData.setVersions(QList<QVersionNumber>() << versionNumber);
+ filterData.setVersions({versionNumber});
setFilterData(filterName, filterData);
}
@@ -2279,55 +2257,44 @@ QUrl QHelpCollectionHandler::buildQUrl(const QString &ns, const QString &folder,
}
QMultiMap<QString, QUrl> QHelpCollectionHandler::linksForIdentifier(
- const QString &id,
- const QStringList &filterAttributes) const
+ const QString &id, const QStringList &filterAttributes) const
{
return linksForField(QLatin1String("Identifier"), id, filterAttributes);
}
QMultiMap<QString, QUrl> QHelpCollectionHandler::linksForKeyword(
- const QString &keyword,
- const QStringList &filterAttributes) const
+ const QString &keyword, const QStringList &filterAttributes) const
{
return linksForField(QLatin1String("Name"), keyword, filterAttributes);
}
QList<QHelpLink> QHelpCollectionHandler::documentsForIdentifier(
- const QString &id,
- const QStringList &filterAttributes) const
+ const QString &id, const QStringList &filterAttributes) const
{
return documentsForField(QLatin1String("Identifier"), id, filterAttributes);
}
QList<QHelpLink> QHelpCollectionHandler::documentsForKeyword(
- const QString &keyword,
- const QStringList &filterAttributes) const
+ const QString &keyword, const QStringList &filterAttributes) const
{
return documentsForField(QLatin1String("Name"), keyword, filterAttributes);
}
-QMultiMap<QString, QUrl> QHelpCollectionHandler::linksForField(
- const QString &fieldName,
- const QString &fieldValue,
- const QStringList &filterAttributes) const
+QMultiMap<QString, QUrl> QHelpCollectionHandler::linksForField(const QString &fieldName,
+ const QString &fieldValue, const QStringList &filterAttributes) const
{
QMultiMap<QString, QUrl> linkMap;
const auto documents = documentsForField(fieldName, fieldValue, filterAttributes);
for (const auto &document : documents)
linkMap.insert(document.title, document.url);
-
return linkMap;
}
-QList<QHelpLink> QHelpCollectionHandler::documentsForField(
- const QString &fieldName,
- const QString &fieldValue,
- const QStringList &filterAttributes) const
+QList<QHelpLink> QHelpCollectionHandler::documentsForField(const QString &fieldName,
+ const QString &fieldValue, const QStringList &filterAttributes) const
{
- QList<QHelpLink> docList;
-
if (!isDBOpened())
- return docList;
+ return {};
const QString filterlessQuery = QString::fromLatin1(
"SELECT "
@@ -2359,6 +2326,7 @@ QList<QHelpLink> QHelpCollectionHandler::documentsForField(
m_query->exec();
+ QList<QHelpLink> docList;
while (m_query->next()) {
QString title = m_query->value(0).toString();
if (title.isEmpty()) // generate a title + corresponding path
@@ -2374,55 +2342,44 @@ QList<QHelpLink> QHelpCollectionHandler::documentsForField(
}
QMultiMap<QString, QUrl> QHelpCollectionHandler::linksForIdentifier(
- const QString &id,
- const QString &filterName) const
+ const QString &id, const QString &filterName) const
{
return linksForField(QLatin1String("Identifier"), id, filterName);
}
QMultiMap<QString, QUrl> QHelpCollectionHandler::linksForKeyword(
- const QString &keyword,
- const QString &filterName) const
+ const QString &keyword, const QString &filterName) const
{
return linksForField(QLatin1String("Name"), keyword, filterName);
}
QList<QHelpLink> QHelpCollectionHandler::documentsForIdentifier(
- const QString &id,
- const QString &filterName) const
+ const QString &id, const QString &filterName) const
{
return documentsForField(QLatin1String("Identifier"), id, filterName);
}
QList<QHelpLink> QHelpCollectionHandler::documentsForKeyword(
- const QString &keyword,
- const QString &filterName) const
+ const QString &keyword, const QString &filterName) const
{
return documentsForField(QLatin1String("Name"), keyword, filterName);
}
-QMultiMap<QString, QUrl> QHelpCollectionHandler::linksForField(
- const QString &fieldName,
- const QString &fieldValue,
- const QString &filterName) const
+QMultiMap<QString, QUrl> QHelpCollectionHandler::linksForField(const QString &fieldName,
+ const QString &fieldValue, const QString &filterName) const
{
QMultiMap<QString, QUrl> linkMap;
const auto documents = documentsForField(fieldName, fieldValue, filterName);
for (const auto &document : documents)
linkMap.insert(document.title, document.url);
-
return linkMap;
}
-QList<QHelpLink> QHelpCollectionHandler::documentsForField(
- const QString &fieldName,
- const QString &fieldValue,
- const QString &filterName) const
+QList<QHelpLink> QHelpCollectionHandler::documentsForField(const QString &fieldName,
+ const QString &fieldValue, const QString &filterName) const
{
- QList<QHelpLink> docList;
-
if (!isDBOpened())
- return docList;
+ return {};
const QString filterlessQuery = QString::fromLatin1(
"SELECT "
@@ -2451,6 +2408,7 @@ QList<QHelpLink> QHelpCollectionHandler::documentsForField(
m_query->exec();
+ QList<QHelpLink> docList;
while (m_query->next()) {
QString title = m_query->value(0).toString();
if (title.isEmpty()) // generate a title + corresponding path
@@ -2489,13 +2447,7 @@ QStringList QHelpCollectionHandler::namespacesForFilter(const QString &filterNam
while (m_query->next())
namespaceList.append(m_query->value(0).toString());
-
return namespaceList;
}
-void QHelpCollectionHandler::setReadOnly(bool readOnly)
-{
- m_readOnly = readOnly;
-}
-
QT_END_NAMESPACE
diff --git a/src/assistant/help/qhelpcollectionhandler_p.h b/src/assistant/help/qhelpcollectionhandler_p.h
index 28221f444..6afe36533 100644
--- a/src/assistant/help/qhelpcollectionhandler_p.h
+++ b/src/assistant/help/qhelpcollectionhandler_p.h
@@ -60,7 +60,7 @@ public:
explicit QHelpCollectionHandler(const QString &collectionFile, QObject *parent = nullptr);
~QHelpCollectionHandler();
- QString collectionFile() const;
+ QString collectionFile() const { return m_collectionFile; }
bool openCollectionFile();
bool copyCollectionFile(const QString &fileName);
@@ -163,7 +163,7 @@ public:
QStringList namespacesForFilter(const QString &filterName) const;
- void setReadOnly(bool readOnly);
+ void setReadOnly(bool readOnly) { m_readOnly = readOnly; }
static QUrl buildQUrl(const QString &ns, const QString &folder,
const QString &relFileName, const QString &anchor);
diff --git a/src/assistant/help/qhelpcontentitem.cpp b/src/assistant/help/qhelpcontentitem.cpp
index fbb4c5580..3c437efe0 100644
--- a/src/assistant/help/qhelpcontentitem.cpp
+++ b/src/assistant/help/qhelpcontentitem.cpp
@@ -63,6 +63,7 @@ int QHelpContentItem::childCount() const
*/
int QHelpContentItem::row() const
{
+ // TODO: Optimize by keeping the index internally.
return d->parent ? d->parent->d->childItems.indexOf(const_cast<QHelpContentItem*>(this)) : 0;
}
diff --git a/src/assistant/help/qhelpdbreader.cpp b/src/assistant/help/qhelpdbreader.cpp
index 39ad7dc26..a936340b0 100644
--- a/src/assistant/help/qhelpdbreader.cpp
+++ b/src/assistant/help/qhelpdbreader.cpp
@@ -14,8 +14,7 @@
QT_BEGIN_NAMESPACE
QHelpDBReader::QHelpDBReader(const QString &dbName)
- : QObject(nullptr)
- , m_dbName(dbName)
+ : m_dbName(dbName)
, m_uniqueId(QHelpGlobal::uniquifyConnectionName(QLatin1String("QHelpDBReader"), this))
{}
@@ -48,7 +47,6 @@ bool QHelpDBReader::init()
m_initDone = true;
m_query = new QSqlQuery(QSqlDatabase::database(m_uniqueId));
-
return true;
}
@@ -86,7 +84,7 @@ QString QHelpDBReader::virtualFolder() const
if (m_query->next())
return m_query->value(0).toString();
}
- return QString();
+ return {};
}
QString QHelpDBReader::version() const
@@ -101,7 +99,7 @@ QString QHelpDBReader::qtVersionHeuristic() const
{
const QString nameSpace = namespaceName();
if (!nameSpace.startsWith(QLatin1String("org.qt-project.")))
- return QString();
+ return {};
// We take the namespace tail, starting from the last letter in namespace name.
// We drop any non digit characters.
@@ -147,16 +145,15 @@ QString QHelpDBReader::qtVersionHeuristic() const
return QString::fromUtf8("%1.%2.%3").arg(major).arg(minor).arg(patch);
}
-
return tail;
}
static bool isAttributeUsed(QSqlQuery *query, const QString &tableName, int attributeId)
{
query->prepare(QString::fromLatin1("SELECT FilterAttributeId "
- "FROM %1 "
- "WHERE FilterAttributeId = ? "
- "LIMIT 1").arg(tableName));
+ "FROM %1 "
+ "WHERE FilterAttributeId = ? "
+ "LIMIT 1").arg(tableName));
query->bindValue(0, attributeId);
query->exec();
return query->next(); // if we got a result it means it was used
@@ -165,7 +162,7 @@ static bool isAttributeUsed(QSqlQuery *query, const QString &tableName, int attr
static int filterDataCount(QSqlQuery *query, const QString &tableName)
{
query->exec(QString::fromLatin1("SELECT COUNT(*) FROM"
- "(SELECT DISTINCT * FROM %1)").arg(tableName));
+ "(SELECT DISTINCT * FROM %1)").arg(tableName));
query->next();
return query->value(0).toInt();
}
@@ -343,7 +340,6 @@ QHelpDBReader::IndexTable QHelpDBReader::indexTable() const
for (int attributeId : usedAttributeIds)
table.usedFilterAttributes.append(attributeIds.value(attributeId));
}
-
return table;
}
@@ -445,9 +441,8 @@ QStringList QHelpDBReader::filterAttributes(const QString &filterName) const
QMultiMap<QString, QByteArray> QHelpDBReader::filesData(const QStringList &filterAttributes,
const QString &extensionFilter) const
{
- QMultiMap<QString, QByteArray> result;
if (!m_query)
- return result;
+ return {};
QString query;
QString extension;
@@ -489,25 +484,22 @@ QMultiMap<QString, QByteArray> QHelpDBReader::filesData(const QStringList &filte
}
}
m_query->exec(query);
+ QMultiMap<QString, QByteArray> result;
while (m_query->next())
result.insert(m_query->value(0).toString(), qUncompress(m_query->value(1).toByteArray()));
-
return result;
}
QVariant QHelpDBReader::metaData(const QString &name) const
{
- QVariant v;
if (!m_query)
- return v;
+ return {};
- m_query->prepare(QLatin1String("SELECT COUNT(Value), Value FROM MetaDataTable "
- "WHERE Name=?"));
+ m_query->prepare(QLatin1String("SELECT COUNT(Value), Value FROM MetaDataTable WHERE Name=?"));
m_query->bindValue(0, name);
- if (m_query->exec() && m_query->next()
- && m_query->value(0).toInt() == 1)
- v = m_query->value(1);
- return v;
+ if (m_query->exec() && m_query->next() && m_query->value(0).toInt() == 1)
+ return m_query->value(1);
+ return {};
}
QString QHelpDBReader::quote(const QString &string) const
diff --git a/src/assistant/help/qhelpengine.cpp b/src/assistant/help/qhelpengine.cpp
index 88ca829e7..e773018e5 100644
--- a/src/assistant/help/qhelpengine.cpp
+++ b/src/assistant/help/qhelpengine.cpp
@@ -25,7 +25,7 @@ public:
QHelpSearchEngine *searchEngine = nullptr;
bool m_isApplyCurrentFilterScheduled = false;
- QHelpEngineCore *m_helpEngineCore;
+ QHelpEngineCore *m_helpEngineCore = nullptr;
};
QHelpEnginePrivate::QHelpEnginePrivate(QHelpEngineCore *helpEngineCore)
@@ -110,7 +110,7 @@ QHelpIndexModel *QHelpEngine::indexModel() const
QHelpContentWidget *QHelpEngine::contentWidget()
{
if (!d->contentWidget) {
- d->contentWidget = new QHelpContentWidget();
+ d->contentWidget = new QHelpContentWidget;
d->contentWidget->setModel(d->contentModel);
#if QT_CONFIG(cursor)
connect(d->contentModel, &QHelpContentModel::contentsCreationStarted, this, [this] {
@@ -130,7 +130,7 @@ QHelpContentWidget *QHelpEngine::contentWidget()
QHelpIndexWidget *QHelpEngine::indexWidget()
{
if (!d->indexWidget) {
- d->indexWidget = new QHelpIndexWidget();
+ d->indexWidget = new QHelpIndexWidget;
d->indexWidget->setModel(d->indexModel);
#if QT_CONFIG(cursor)
connect(d->indexModel, &QHelpIndexModel::indexCreationStarted, this, [this] {
diff --git a/src/assistant/help/qhelpenginecore.cpp b/src/assistant/help/qhelpenginecore.cpp
index 372c86b25..acc890727 100644
--- a/src/assistant/help/qhelpenginecore.cpp
+++ b/src/assistant/help/qhelpenginecore.cpp
@@ -17,7 +17,7 @@ class QHelpEngineCorePrivate
{
public:
QHelpEngineCorePrivate(const QString &collectionFile, QHelpEngineCore *helpEngineCore);
- ~QHelpEngineCorePrivate();
+ ~QHelpEngineCorePrivate() { delete collectionHandler; }
void init(const QString &collectionFile);
bool setup();
@@ -42,11 +42,6 @@ QHelpEngineCorePrivate::QHelpEngineCorePrivate(const QString &collectionFile,
init(collectionFile);
}
-QHelpEngineCorePrivate::~QHelpEngineCorePrivate()
-{
- delete collectionHandler;
-}
-
void QHelpEngineCorePrivate::init(const QString &collectionFile)
{
if (collectionHandler)
@@ -68,15 +63,13 @@ bool QHelpEngineCorePrivate::setup()
emit q->setupStarted();
const QVariant readOnlyVariant = q->property("_q_readonly");
- const bool readOnly = readOnlyVariant.isValid()
- ? readOnlyVariant.toBool() : q->isReadOnly();
+ const bool readOnly = readOnlyVariant.isValid() ? readOnlyVariant.toBool() : q->isReadOnly();
collectionHandler->setReadOnly(readOnly);
const bool opened = collectionHandler->openCollectionFile();
if (opened)
q->currentFilter();
emit q->setupFinished();
-
return opened;
}
@@ -301,10 +294,10 @@ QString QHelpEngineCore::namespaceName(const QString &documentationFileName)
{
QHelpDBReader reader(documentationFileName,
QHelpGlobal::uniquifyConnectionName(QLatin1String("GetNamespaceName"),
- QThread::currentThread()), nullptr);
+ QThread::currentThread()), nullptr); // TODO: Replace QThread with *this
if (reader.init())
return reader.namespaceName();
- return QString();
+ return {};
}
/*!
@@ -347,13 +340,13 @@ bool QHelpEngineCore::unregisterDocumentation(const QString &namespaceName)
QString QHelpEngineCore::documentationFileName(const QString &namespaceName)
{
if (!d->setup())
- return QString();
+ return {};
const QHelpCollectionHandler::FileInfo fileInfo =
d->collectionHandler->registeredDocumentation(namespaceName);
if (fileInfo.namespaceName.isEmpty())
- return QString();
+ return {};
if (QDir::isAbsolutePath(fileInfo.fileName))
return fileInfo.fileName;
@@ -368,11 +361,10 @@ QString QHelpEngineCore::documentationFileName(const QString &namespaceName)
*/
QStringList QHelpEngineCore::registeredDocumentations() const
{
- QStringList list;
if (!d->setup())
- return list;
- const QHelpCollectionHandler::FileInfoList &docList
- = d->collectionHandler->registeredDocumentations();
+ return {};
+ const auto &docList = d->collectionHandler->registeredDocumentations();
+ QStringList list;
for (const QHelpCollectionHandler::FileInfo &info : docList)
list.append(info.namespaceName);
return list;
@@ -390,7 +382,7 @@ QStringList QHelpEngineCore::registeredDocumentations() const
QStringList QHelpEngineCore::customFilters() const
{
if (!d->setup())
- return QStringList();
+ return {};
return d->collectionHandler->customFilters();
}
@@ -441,7 +433,7 @@ bool QHelpEngineCore::removeCustomFilter(const QString &filterName)
QStringList QHelpEngineCore::filterAttributes() const
{
if (!d->setup())
- return QStringList();
+ return {};
return d->collectionHandler->filterAttributes();
}
@@ -456,7 +448,7 @@ QStringList QHelpEngineCore::filterAttributes() const
QStringList QHelpEngineCore::filterAttributes(const QString &filterName) const
{
if (!d->setup())
- return QStringList();
+ return {};
return d->collectionHandler->filterAttributes(filterName);
}
@@ -477,14 +469,12 @@ QStringList QHelpEngineCore::filterAttributes(const QString &filterName) const
QString QHelpEngineCore::currentFilter() const
{
if (!d->setup())
- return QString();
+ return {};
if (d->currentFilter.isEmpty()) {
- const QString &filter =
- d->collectionHandler->customValue(QLatin1String("CurrentFilter"),
- QString()).toString();
- if (!filter.isEmpty()
- && d->collectionHandler->customFilters().contains(filter))
+ const QString &filter = d->collectionHandler->customValue(
+ QLatin1String("CurrentFilter"), QString()).toString();
+ if (!filter.isEmpty() && d->collectionHandler->customFilters().contains(filter))
d->currentFilter = filter;
}
return d->currentFilter;
@@ -495,10 +485,8 @@ void QHelpEngineCore::setCurrentFilter(const QString &filterName)
if (!d->setup() || filterName == d->currentFilter)
return;
d->currentFilter = filterName;
- if (d->autoSaveFilter) {
- d->collectionHandler->setCustomValue(QLatin1String("CurrentFilter"),
- d->currentFilter);
- }
+ if (d->autoSaveFilter)
+ d->collectionHandler->setCustomValue(QLatin1String("CurrentFilter"), d->currentFilter);
emit currentFilterChanged(d->currentFilter);
}
@@ -514,8 +502,7 @@ void QHelpEngineCore::setCurrentFilter(const QString &filterName)
QList<QStringList> QHelpEngineCore::filterAttributeSets(const QString &namespaceName) const
{
if (!d->setup())
- return QList<QStringList>();
-
+ return {};
return d->collectionHandler->filterAttributeSets(namespaceName);
}
@@ -614,8 +601,7 @@ QUrl QHelpEngineCore::findFile(const QUrl &url) const
QByteArray QHelpEngineCore::fileData(const QUrl &url) const
{
if (!d->setup())
- return QByteArray();
-
+ return {};
return d->collectionHandler->fileData(url);
}
@@ -628,9 +614,8 @@ QByteArray QHelpEngineCore::fileData(const QUrl &url) const
*/
QList<QHelpLink> QHelpEngineCore::documentsForIdentifier(const QString &id) const
{
- return documentsForIdentifier(id, d->usesFilterEngine
- ? d->filterEngine->activeFilter()
- : d->currentFilter);
+ return documentsForIdentifier(
+ id, d->usesFilterEngine ? d->filterEngine->activeFilter() : d->currentFilter);
}
/*!
@@ -644,11 +629,10 @@ QList<QHelpLink> QHelpEngineCore::documentsForIdentifier(const QString &id) cons
QList<QHelpLink> QHelpEngineCore::documentsForIdentifier(const QString &id, const QString &filterName) const
{
if (!d->setup())
- return QList<QHelpLink>();
+ return {};
if (d->usesFilterEngine)
return d->collectionHandler->documentsForIdentifier(id, filterName);
-
return d->collectionHandler->documentsForIdentifier(id, filterAttributes(filterName));
}
@@ -661,9 +645,8 @@ QList<QHelpLink> QHelpEngineCore::documentsForIdentifier(const QString &id, cons
*/
QList<QHelpLink> QHelpEngineCore::documentsForKeyword(const QString &keyword) const
{
- return documentsForKeyword(keyword, d->usesFilterEngine
- ? d->filterEngine->activeFilter()
- : d->currentFilter);
+ return documentsForKeyword(
+ keyword, d->usesFilterEngine ? d->filterEngine->activeFilter() : d->currentFilter);
}
/*!
@@ -677,11 +660,10 @@ QList<QHelpLink> QHelpEngineCore::documentsForKeyword(const QString &keyword) co
QList<QHelpLink> QHelpEngineCore::documentsForKeyword(const QString &keyword, const QString &filterName) const
{
if (!d->setup())
- return QList<QHelpLink>();
+ return {};
if (d->usesFilterEngine)
return d->collectionHandler->documentsForKeyword(keyword, filterName);
-
return d->collectionHandler->documentsForKeyword(keyword, filterAttributes(filterName));
}
@@ -708,7 +690,7 @@ bool QHelpEngineCore::removeCustomValue(const QString &key)
QVariant QHelpEngineCore::customValue(const QString &key, const QVariant &defaultValue) const
{
if (!d->setup())
- return QVariant();
+ return {};
return d->collectionHandler->customValue(key, defaultValue);
}
@@ -740,7 +722,7 @@ QVariant QHelpEngineCore::metaData(const QString &documentationFileName,
if (reader.init())
return reader.metaData(name);
- return QVariant();
+ return {};
}
/*!
diff --git a/src/assistant/help/qhelpfilterdata.cpp b/src/assistant/help/qhelpfilterdata.cpp
index ed6d3e78a..2baa7ce3c 100644
--- a/src/assistant/help/qhelpfilterdata.cpp
+++ b/src/assistant/help/qhelpfilterdata.cpp
@@ -15,8 +15,7 @@ public:
: QSharedData(other)
, m_components(other.m_components)
, m_versions(other.m_versions)
- { }
- ~QHelpFilterDataPrivate() = default;
+ {}
QStringList m_components;
QList<QVersionNumber> m_versions;
@@ -40,10 +39,7 @@ public:
/*!
Constructs the empty filter.
*/
-QHelpFilterData::QHelpFilterData()
- : d(new QHelpFilterDataPrivate)
-{
-}
+QHelpFilterData::QHelpFilterData() : d(new QHelpFilterDataPrivate) { }
/*!
Constructs a copy of \a other.
@@ -65,7 +61,6 @@ QHelpFilterData::~QHelpFilterData() = default;
*/
QHelpFilterData &QHelpFilterData::operator=(const QHelpFilterData &) = default;
-
/*!
Move-assigns \a other to this QHelpFilterData instance.
*/
@@ -80,8 +75,7 @@ QHelpFilterData &QHelpFilterData::operator=(QHelpFilterData &&) = default;
bool QHelpFilterData::operator==(const QHelpFilterData &other) const
{
- return (d->m_components == other.d->m_components &&
- d->m_versions == other.d->m_versions);
+ return (d->m_components == other.d->m_components && d->m_versions == other.d->m_versions);
}
/*!
diff --git a/src/assistant/help/qhelpfilterengine.cpp b/src/assistant/help/qhelpfilterengine.cpp
index bb6df822d..0253e7af0 100644
--- a/src/assistant/help/qhelpfilterengine.cpp
+++ b/src/assistant/help/qhelpfilterengine.cpp
@@ -123,7 +123,7 @@ QHelpFilterEngine::~QHelpFilterEngine()
void QHelpFilterEngine::setCollectionHandler(QHelpCollectionHandler *collectionHandler)
{
d->m_collectionHandler = collectionHandler;
- d->m_currentFilter = QString();
+ d->m_currentFilter.clear();
d->m_needsSetup = true;
}
@@ -134,7 +134,7 @@ void QHelpFilterEngine::setCollectionHandler(QHelpCollectionHandler *collectionH
QMap<QString, QString> QHelpFilterEngine::namespaceToComponent() const
{
if (!d->setup())
- return QMap<QString, QString>();
+ return {};
return d->m_collectionHandler->namespaceToComponent();
}
@@ -145,8 +145,7 @@ QMap<QString, QString> QHelpFilterEngine::namespaceToComponent() const
QMap<QString, QVersionNumber> QHelpFilterEngine::namespaceToVersion() const
{
if (!d->setup())
- return QMap<QString, QVersionNumber>();
-
+ return {};
return d->m_collectionHandler->namespaceToVersion();
}
@@ -156,7 +155,7 @@ QMap<QString, QVersionNumber> QHelpFilterEngine::namespaceToVersion() const
QStringList QHelpFilterEngine::filters() const
{
if (!d->setup())
- return QStringList();
+ return {};
return d->m_collectionHandler->filters();
}
@@ -167,7 +166,7 @@ QStringList QHelpFilterEngine::filters() const
QStringList QHelpFilterEngine::availableComponents() const
{
if (!d->setup())
- return QStringList();
+ return {};
return d->m_collectionHandler->availableComponents();
}
@@ -180,7 +179,7 @@ QStringList QHelpFilterEngine::availableComponents() const
QList<QVersionNumber> QHelpFilterEngine::availableVersions() const
{
if (!d->setup())
- return QList<QVersionNumber>();
+ return {};
return d->m_collectionHandler->availableVersions();
}
@@ -190,7 +189,7 @@ QList<QVersionNumber> QHelpFilterEngine::availableVersions() const
QHelpFilterData QHelpFilterEngine::filterData(const QString &filterName) const
{
if (!d->setup())
- return QHelpFilterData();
+ return {};
return d->m_collectionHandler->filterData(filterName);
}
@@ -227,7 +226,7 @@ bool QHelpFilterEngine::removeFilter(const QString &filterName)
QString QHelpFilterEngine::activeFilter() const
{
if (!d->setup())
- return QString();
+ return {};
return d->m_currentFilter;
}
@@ -253,7 +252,6 @@ bool QHelpFilterEngine::setActiveFilter(const QString &filterName)
d->m_currentFilter);
emit filterActivated(d->m_currentFilter);
-
return true;
}
@@ -264,7 +262,7 @@ bool QHelpFilterEngine::setActiveFilter(const QString &filterName)
QStringList QHelpFilterEngine::namespacesForFilter(const QString &filterName) const
{
if (!d->setup())
- return QStringList();
+ return {};
return d->m_collectionHandler->namespacesForFilter(filterName);
}
@@ -292,7 +290,7 @@ QStringList QHelpFilterEngine::indices() const
QStringList QHelpFilterEngine::indices(const QString &filterName) const
{
if (!d->setup())
- return QStringList();
+ return {};
return d->m_collectionHandler->indicesForFilter(filterName);
}
diff --git a/src/assistant/help/qhelpfiltersettingswidget.cpp b/src/assistant/help/qhelpfiltersettingswidget.cpp
index cd4f2b47c..af0db2632 100644
--- a/src/assistant/help/qhelpfiltersettingswidget.cpp
+++ b/src/assistant/help/qhelpfiltersettingswidget.cpp
@@ -45,7 +45,6 @@ static QHelpFilterSettings readSettingsHelper(const QHelpFilterEngine *filterEng
filterSettings.setFilter(filter, filterEngine->filterData(filter));
filterSettings.setCurrentFilter(filterEngine->activeFilter());
-
return filterSettings;
}
@@ -59,7 +58,6 @@ static QMap<QString, QHelpFilterData> subtract(const QMap<QString, QHelpFilterDa
if (itResult != result.end() && itSubtrahend.value() == itResult.value())
result.erase(itResult);
}
-
return result;
}
@@ -68,19 +66,15 @@ static bool applySettingsHelper(QHelpFilterEngine *filterEngine, const QHelpFilt
bool changed = false;
const QHelpFilterSettings oldSettings = readSettingsHelper(filterEngine);
- const QMap<QString, QHelpFilterData> filtersToRemove = subtract(
- oldSettings.filters(),
- settings.filters());
- const QMap<QString, QHelpFilterData> filtersToAdd = subtract(
- settings.filters(),
- oldSettings.filters());
+ const auto filtersToRemove = subtract(oldSettings.filters(), settings.filters());
+ const auto filtersToAdd = subtract(settings.filters(), oldSettings.filters());
const QString &currentFilter = filterEngine->activeFilter();
for (const QString &filter : filtersToRemove.keys()) {
filterEngine->removeFilter(filter);
if (currentFilter == filter && !filtersToAdd.contains(filter))
- filterEngine->setActiveFilter(QString());
+ filterEngine->setActiveFilter({});
changed = true;
}
@@ -91,7 +85,6 @@ static bool applySettingsHelper(QHelpFilterEngine *filterEngine, const QHelpFilt
if (changed)
filterEngine->setActiveFilter(settings.currentFilter());
-
return changed;
}
@@ -114,11 +107,11 @@ static QList<QVersionNumber> stringListToVersions(const QStringList &versionList
class QHelpFilterSettingsWidgetPrivate
{
QHelpFilterSettingsWidget *q_ptr;
- Q_DECLARE_PUBLIC(QHelpFilterSettingsWidget)
+ Q_DECLARE_PUBLIC(QHelpFilterSettingsWidget) // TODO: remove Q_DECLARE_PUBLIC
public:
QHelpFilterSettingsWidgetPrivate() = default;
- QHelpFilterSettings filterSettings() const;
+ QHelpFilterSettings filterSettings() const { return m_filterSettings; }
void setFilterSettings(const QHelpFilterSettings &settings);
void updateCurrentFilter();
@@ -127,11 +120,9 @@ public:
void addFilterClicked();
void renameFilterClicked();
void removeFilterClicked();
- void addFilter(const QString &filterName,
- const QHelpFilterData &filterData = QHelpFilterData());
+ void addFilter(const QString &filterName, const QHelpFilterData &filterData = {});
void removeFilter(const QString &filterName);
- QString getUniqueFilterName(const QString &windowTitle,
- const QString &initialFilterName);
+ QString getUniqueFilterName(const QString &windowTitle, const QString &initialFilterName);
QString suggestedNewFilterName(const QString &initialFilterName) const;
QMap<QString, QListWidgetItem *> m_filterToItem;
@@ -176,11 +167,6 @@ void QHelpFilterSettingsWidgetPrivate::setFilterSettings(const QHelpFilterSettin
updateCurrentFilter();
}
-QHelpFilterSettings QHelpFilterSettingsWidgetPrivate::filterSettings() const
-{
- return m_filterSettings;
-}
-
void QHelpFilterSettingsWidgetPrivate::updateCurrentFilter()
{
const QString &currentFilter = m_itemToFilter.value(m_ui.filterWidget->currentItem());
@@ -256,17 +242,15 @@ void QHelpFilterSettingsWidgetPrivate::removeFilterClicked()
return;
if (QMessageBox::question(q, QHelpFilterSettingsWidget::tr("Remove Filter"),
- QHelpFilterSettingsWidget::tr("Are you sure you want to remove the \"%1\" filter?")
- .arg(currentFilter),
- QMessageBox::Yes | QMessageBox::No)
- != QMessageBox::Yes) {
+ QHelpFilterSettingsWidget::tr("Are you sure you want to remove the \"%1\" filter?")
+ .arg(currentFilter), QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes) {
return;
}
removeFilter(currentFilter);
if (m_filterSettings.currentFilter() == currentFilter)
- m_filterSettings.setCurrentFilter(QString());
+ m_filterSettings.setCurrentFilter({});
}
void QHelpFilterSettingsWidgetPrivate::addFilter(const QString &filterName,
@@ -288,7 +272,6 @@ void QHelpFilterSettingsWidgetPrivate::removeFilter(const QString &filterName)
m_itemToFilter.remove(item);
m_filterToItem.remove(filterName);
delete item;
-
m_filterSettings.removeFilter(filterName);
}
@@ -298,39 +281,32 @@ QString QHelpFilterSettingsWidgetPrivate::getUniqueFilterName(const QString &win
Q_Q(QHelpFilterSettingsWidget);
QString newFilterName = initialFilterName;
- while (1) {
+ while (true) {
QFilterNameDialog dialog(q);
dialog.setWindowTitle(windowTitle);
dialog.setFilterName(newFilterName);
if (dialog.exec() == QDialog::Rejected)
- return QString();
+ return {};
newFilterName = dialog.filterName();
if (!m_filterToItem.contains(newFilterName))
break;
if (QMessageBox::warning(q, QHelpFilterSettingsWidget::tr("Filter Exists"),
- QHelpFilterSettingsWidget::tr("The filter \"%1\" already exists.")
- .arg(newFilterName),
- QMessageBox::Retry | QMessageBox::Cancel)
- == QMessageBox::Cancel) {
- return QString();
+ QHelpFilterSettingsWidget::tr("The filter \"%1\" already exists.").arg(newFilterName),
+ QMessageBox::Retry | QMessageBox::Cancel) == QMessageBox::Cancel) {
+ return {};
}
}
-
return newFilterName;
}
QString QHelpFilterSettingsWidgetPrivate::suggestedNewFilterName(const QString &initialFilterName) const
{
QString newFilterName = initialFilterName;
-
int counter = 1;
- while (m_filterToItem.contains(newFilterName)) {
- newFilterName = initialFilterName + QLatin1Char(' ')
- + QString::number(++counter);
- }
-
+ while (m_filterToItem.contains(newFilterName))
+ newFilterName = initialFilterName + QLatin1Char(' ') + QString::number(++counter);
return newFilterName;
}
@@ -375,13 +351,13 @@ QHelpFilterSettingsWidget::QHelpFilterSettingsWidget(QWidget *parent)
d->m_ui.addButton->setIcon(QIcon(resourcePath + QLatin1String("/plus.png")));
d->m_ui.removeButton->setIcon(QIcon(resourcePath + QLatin1String("/minus.png")));
- connect(d->m_ui.componentWidget, &QOptionsWidget::optionSelectionChanged, this,
- [this](const QStringList &options) {
+ connect(d->m_ui.componentWidget, &QOptionsWidget::optionSelectionChanged,
+ this, [this](const QStringList &options) {
Q_D(QHelpFilterSettingsWidget);
d->componentsChanged(options);
});
- connect(d->m_ui.versionWidget, &QOptionsWidget::optionSelectionChanged, this,
- [this](const QStringList &options) {
+ connect(d->m_ui.versionWidget, &QOptionsWidget::optionSelectionChanged,
+ this, [this](const QStringList &options) {
Q_D(QHelpFilterSettingsWidget);
d->versionsChanged(options);
});
@@ -390,25 +366,22 @@ QHelpFilterSettingsWidget::QHelpFilterSettingsWidget(QWidget *parent)
Q_D(QHelpFilterSettingsWidget);
d->updateCurrentFilter();
});
- connect(d->m_ui.filterWidget, &QListWidget::itemDoubleClicked, this,
- [this](QListWidgetItem *) {
+ connect(d->m_ui.filterWidget, &QListWidget::itemDoubleClicked,
+ this, [this](QListWidgetItem *) {
Q_D(QHelpFilterSettingsWidget);
d->renameFilterClicked();
});
// TODO: repeat these actions on context menu
- connect(d->m_ui.addButton, &QAbstractButton::clicked, this,
- [this]() {
+ connect(d->m_ui.addButton, &QAbstractButton::clicked, this, [this] {
Q_D(QHelpFilterSettingsWidget);
d->addFilterClicked();
});
- connect(d->m_ui.renameButton, &QAbstractButton::clicked, this,
- [this]() {
+ connect(d->m_ui.renameButton, &QAbstractButton::clicked, this, [this] {
Q_D(QHelpFilterSettingsWidget);
d->renameFilterClicked();
});
- connect(d->m_ui.removeButton, &QAbstractButton::clicked, this,
- [this]() {
+ connect(d->m_ui.removeButton, &QAbstractButton::clicked, this, [this] {
Q_D(QHelpFilterSettingsWidget);
d->removeFilterClicked();
});
diff --git a/src/assistant/help/qhelpindexwidget.cpp b/src/assistant/help/qhelpindexwidget.cpp
index 9d1df93f0..77b2ba9b5 100644
--- a/src/assistant/help/qhelpindexwidget.cpp
+++ b/src/assistant/help/qhelpindexwidget.cpp
@@ -231,7 +231,7 @@ QModelIndex QHelpIndexModel::filter(const QString &filter, const QString &wildca
{
if (filter.isEmpty()) {
setStringList(d->indices);
- return index(-1, 0, QModelIndex());
+ return index(-1, 0, {});
}
QStringList lst;
@@ -240,17 +240,17 @@ QModelIndex QHelpIndexModel::filter(const QString &filter, const QString &wildca
if (!wildcard.isEmpty()) {
auto re = QRegularExpression::wildcardToRegularExpression(wildcard,
- QRegularExpression::UnanchoredWildcardConversion);
+ QRegularExpression::UnanchoredWildcardConversion);
const QRegularExpression regExp(re, QRegularExpression::CaseInsensitiveOption);
+ // TODO: Limit code repetition, see next loop in this body
for (const QString &index : std::as_const(d->indices)) {
if (index.contains(regExp)) {
lst.append(index);
if (perfectMatch == -1 && index.startsWith(filter, Qt::CaseInsensitive)) {
if (goodMatch == -1)
goodMatch = lst.size() - 1;
- if (filter.size() == index.size()){
+ if (filter.size() == index.size())
perfectMatch = lst.size() - 1;
- }
} else if (perfectMatch > -1 && index == filter) {
perfectMatch = lst.size() - 1;
}
@@ -263,26 +263,22 @@ QModelIndex QHelpIndexModel::filter(const QString &filter, const QString &wildca
if (perfectMatch == -1 && index.startsWith(filter, Qt::CaseInsensitive)) {
if (goodMatch == -1)
goodMatch = lst.size() - 1;
- if (filter.size() == index.size()){
+ if (filter.size() == index.size())
perfectMatch = lst.size() - 1;
- }
} else if (perfectMatch > -1 && index == filter) {
perfectMatch = lst.size() - 1;
}
}
}
-
}
if (perfectMatch == -1)
perfectMatch = qMax(0, goodMatch);
setStringList(lst);
- return index(perfectMatch, 0, QModelIndex());
+ return index(perfectMatch, 0, {});
}
-
-
/*!
\class QHelpIndexWidget
\inmodule QtHelp
@@ -330,8 +326,7 @@ QHelpIndexWidget::QHelpIndexWidget()
{
setEditTriggers(QAbstractItemView::NoEditTriggers);
setUniformItemSizes(true);
- connect(this, &QAbstractItemView::activated,
- this, &QHelpIndexWidget::showLink);
+ connect(this, &QAbstractItemView::activated, this, &QHelpIndexWidget::showLink);
}
void QHelpIndexWidget::showLink(const QModelIndex &index)
@@ -387,7 +382,7 @@ void QHelpIndexWidget::activateCurrentItem()
*/
void QHelpIndexWidget::filterIndices(const QString &filter, const QString &wildcard)
{
- QHelpIndexModel *indexModel = qobject_cast<QHelpIndexModel*>(model());
+ QHelpIndexModel *indexModel = qobject_cast<QHelpIndexModel *>(model());
if (!indexModel)
return;
const QModelIndex &idx = indexModel->filter(filter, wildcard);
diff --git a/src/assistant/help/qhelplink.h b/src/assistant/help/qhelplink.h
index 831c4a3dd..5c359188e 100644
--- a/src/assistant/help/qhelplink.h
+++ b/src/assistant/help/qhelplink.h
@@ -10,6 +10,7 @@
QT_BEGIN_NAMESPACE
+// TODO: Qt 7.0 - pimpl or replace with std::pair? Replace struct with class.
struct QHELP_EXPORT QHelpLink final
{
QUrl url;
diff --git a/src/assistant/help/qhelpsearchengine.cpp b/src/assistant/help/qhelpsearchengine.cpp
index a0a69865a..412eec457 100644
--- a/src/assistant/help/qhelpsearchengine.cpp
+++ b/src/assistant/help/qhelpsearchengine.cpp
@@ -48,9 +48,7 @@ public:
QList<QHelpSearchResult> searchResults(int start, int end) const
{
- return indexReader ?
- indexReader->searchResults(start, end) :
- QList<QHelpSearchResult>();
+ return indexReader ? indexReader->searchResults(start, end) : QList<QHelpSearchResult>();
}
void updateIndex(bool reindex = false)
@@ -71,8 +69,7 @@ public:
}
indexWriter->cancelIndexing();
- indexWriter->updateIndex(helpEngine->collectionFile(),
- indexFilesFolder(), reindex);
+ indexWriter->updateIndex(helpEngine->collectionFile(), indexFilesFolder(), reindex);
}
void cancelIndexing()
@@ -114,8 +111,7 @@ public:
QString indexFilesFolder = QLatin1String(".fulltextsearch");
if (helpEngine && !helpEngine->collectionFile().isEmpty()) {
QFileInfo fi(helpEngine->collectionFile());
- indexFilesFolder = fi.absolutePath() + QDir::separator()
- + QLatin1Char('.')
+ indexFilesFolder = fi.absolutePath() + QDir::separator() + QLatin1Char('.')
+ fi.fileName().left(fi.fileName().lastIndexOf(QLatin1String(".qhc")));
}
return indexFilesFolder;
@@ -281,7 +277,6 @@ QHelpSearchQueryWidget* QHelpSearchEngine::queryWidget()
{
if (!d->queryWidget)
d->queryWidget = new QHelpSearchQueryWidget();
-
return d->queryWidget;
}
@@ -292,7 +287,6 @@ QHelpSearchResultWidget* QHelpSearchEngine::resultWidget()
{
if (!d->resultWidget)
d->resultWidget = new QHelpSearchResultWidget(this);
-
return d->resultWidget;
}
@@ -381,8 +375,7 @@ QT_WARNING_DISABLE_DEPRECATED
*/
QList<QHelpSearchQuery> QHelpSearchEngine::query() const
{
- return QList<QHelpSearchQuery>() << QHelpSearchQuery(QHelpSearchQuery::DEFAULT,
- d->m_searchInput.split(QChar::Space));
+ return {{QHelpSearchQuery::DEFAULT, d->m_searchInput.split(QChar::Space)}};
}
QT_WARNING_POP
#endif // QT_DEPRECATED_SINCE(5, 9)
diff --git a/src/assistant/help/qhelpsearchindexreader.cpp b/src/assistant/help/qhelpsearchindexreader.cpp
index 381bf4a3c..75e578324 100644
--- a/src/assistant/help/qhelpsearchindexreader.cpp
+++ b/src/assistant/help/qhelpsearchindexreader.cpp
@@ -17,12 +17,25 @@ namespace fulltextsearch {
class Reader
{
public:
- void setIndexPath(const QString &path);
- void addNamespaceAttributes(const QString &namespaceName, const QStringList &attributes);
- void setFilterEngineNamespaceList(const QStringList &namespaceList);
+ void setIndexPath(const QString &path)
+ {
+ m_indexPath = path;
+ m_namespaceAttributes.clear();
+ m_filterEngineNamespaceList.clear();
+ m_useFilterEngine = false;
+ }
+ void addNamespaceAttributes(const QString &namespaceName, const QStringList &attributes)
+ {
+ m_namespaceAttributes.insert(namespaceName, attributes);
+ }
+ void setFilterEngineNamespaceList(const QStringList &namespaceList)
+ {
+ m_useFilterEngine = true;
+ m_filterEngineNamespaceList = namespaceList;
+ }
void searchInDB(const QString &term);
- QList<QHelpSearchResult> searchResults() const;
+ QList<QHelpSearchResult> searchResults() const { return m_searchResults; }
private:
QList<QHelpSearchResult> queryTable(const QSqlDatabase &db, const QString &tableName,
@@ -35,25 +48,6 @@ private:
bool m_useFilterEngine = false;
};
-void Reader::setIndexPath(const QString &path)
-{
- m_indexPath = path;
- m_namespaceAttributes.clear();
- m_filterEngineNamespaceList.clear();
- m_useFilterEngine = false;
-}
-
-void Reader::addNamespaceAttributes(const QString &namespaceName, const QStringList &attributes)
-{
- m_namespaceAttributes.insert(namespaceName, attributes);
-}
-
-void Reader::setFilterEngineNamespaceList(const QStringList &namespaceList)
-{
- m_useFilterEngine = true;
- m_filterEngineNamespaceList = namespaceList;
-}
-
static QString namespacePlaceholders(const QMultiMap<QString, QStringList> &namespaces)
{
QString placeholders;
@@ -147,7 +141,6 @@ QList<QHelpSearchResult> Reader::queryTable(const QSqlDatabase &db, const QStrin
const QString &snippet = query.value(2).toString();
results.append(QHelpSearchResult(url, title, snippet));
}
-
return results;
}
@@ -167,7 +160,7 @@ void Reader::searchInDB(const QString &searchInput)
queryTable(db, QLatin1String("contents"), searchInput);
// merge results form title and contents searches
- m_searchResults = QList<QHelpSearchResult>();
+ m_searchResults.clear();
QSet<QUrl> urls;
@@ -191,11 +184,6 @@ void Reader::searchInDB(const QString &searchInput)
QSqlDatabase::removeDatabase(uniqueId);
}
-QList<QHelpSearchResult> Reader::searchResults() const
-{
- return m_searchResults;
-}
-
static bool attributesMatchFilter(const QStringList &attributes, const QStringList &filter)
{
for (const QString &attribute : filter) {
diff --git a/src/assistant/help/qhelpsearchindexreader_p.h b/src/assistant/help/qhelpsearchindexreader_p.h
index 52e22ad35..a54df4ded 100644
--- a/src/assistant/help/qhelpsearchindexreader_p.h
+++ b/src/assistant/help/qhelpsearchindexreader_p.h
@@ -25,6 +25,7 @@ QT_BEGIN_NAMESPACE
namespace fulltextsearch {
+// TODO: Employ QFuture / QtConcurrent::run() ?
class QHelpSearchIndexReader : public QThread
{
Q_OBJECT
diff --git a/src/assistant/help/qhelpsearchindexwriter.cpp b/src/assistant/help/qhelpsearchindexwriter.cpp
index f63b11260..ba2619f8c 100644
--- a/src/assistant/help/qhelpsearchindexwriter.cpp
+++ b/src/assistant/help/qhelpsearchindexwriter.cpp
@@ -72,13 +72,14 @@ 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")
- .arg(dbPath, m_uniqueId, m_db->lastError().text());
+ 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;
m_db = nullptr;
QSqlDatabase::removeDatabase(m_uniqueId);
- m_uniqueId = QString();
+ m_uniqueId.clear();
} else {
startTransaction();
}
@@ -112,7 +113,6 @@ bool Writer::hasDB()
query.prepare(QLatin1String("SELECT id FROM info LIMIT 1"));
query.exec();
-
return query.next();
}
@@ -248,7 +248,6 @@ bool Writer::hasNamespace(const QString &namespaceName)
query.prepare(QLatin1String("SELECT id FROM info WHERE namespace = ? LIMIT 1"));
query.addBindValue(namespaceName);
query.exec();
-
return query.next();
}
@@ -294,18 +293,11 @@ void Writer::endTransaction()
query.exec(QLatin1String("VACUUM"));
}
-QHelpSearchIndexWriter::QHelpSearchIndexWriter()
- : QThread()
- , m_cancel(false)
-{
-}
-
QHelpSearchIndexWriter::~QHelpSearchIndexWriter()
{
m_mutex.lock();
this->m_cancel = true;
m_mutex.unlock();
-
wait();
}
@@ -316,8 +308,7 @@ void QHelpSearchIndexWriter::cancelIndexing()
}
void QHelpSearchIndexWriter::updateIndex(const QString &collectionFile,
- const QString &indexFilesFolder,
- bool reindex)
+ const QString &indexFilesFolder, bool reindex)
{
wait();
QMutexLocker lock(&m_mutex);
@@ -337,22 +328,19 @@ static const char IndexedNamespacesKey[] = "FTS5IndexedNamespaces";
static QMap<QString, QDateTime> readIndexMap(const QHelpEngineCore &engine)
{
QMap<QString, QDateTime> indexMap;
- QDataStream dataStream(engine.customValue(
- QLatin1String(IndexedNamespacesKey)).toByteArray());
+ QDataStream dataStream(engine.customValue(QLatin1String(IndexedNamespacesKey)).toByteArray());
dataStream >> indexMap;
return indexMap;
}
-static bool writeIndexMap(QHelpEngineCore *engine,
- const QMap<QString, QDateTime> &indexMap)
+static bool writeIndexMap(QHelpEngineCore *engine, const QMap<QString, QDateTime> &indexMap)
{
QByteArray data;
QDataStream dataStream(&data, QIODevice::ReadWrite);
dataStream << indexMap;
- return engine->setCustomValue(
- QLatin1String(IndexedNamespacesKey), data);
+ return engine->setCustomValue(QLatin1String(IndexedNamespacesKey), data);
}
static bool clearIndexMap(QHelpEngineCore *engine)
@@ -489,7 +477,7 @@ void QHelpSearchIndexWriter::run()
url.setPath(QLatin1Char('/') + virtualFolder + QLatin1Char('/') + file);
if (url.hasFragment())
- url.setFragment(QString());
+ url.setFragment({});
const QString &fullFileName = url.toString();
if (!fullFileName.endsWith(QLatin1String(".html"))
diff --git a/src/assistant/help/qhelpsearchindexwriter_p.h b/src/assistant/help/qhelpsearchindexwriter_p.h
index af6ed3085..0e3b17451 100644
--- a/src/assistant/help/qhelpsearchindexwriter_p.h
+++ b/src/assistant/help/qhelpsearchindexwriter_p.h
@@ -24,12 +24,12 @@ class QSqlDatabase;
namespace fulltextsearch {
+// TODO: Employ QFuture / QtConcurrent::run() ?
class QHelpSearchIndexWriter : public QThread
{
Q_OBJECT
public:
- QHelpSearchIndexWriter();
~QHelpSearchIndexWriter() override;
void cancelIndexing();
@@ -45,7 +45,7 @@ private:
private:
QMutex m_mutex;
- bool m_cancel;
+ bool m_cancel = false;
bool m_reindex;
QString m_collectionFile;
QString m_indexFilesFolder;
diff --git a/src/assistant/help/qhelpsearchquerywidget.cpp b/src/assistant/help/qhelpsearchquerywidget.cpp
index 4fb350ee9..d831370b9 100644
--- a/src/assistant/help/qhelpsearchquerywidget.cpp
+++ b/src/assistant/help/qhelpsearchquerywidget.cpp
@@ -23,7 +23,7 @@ private:
struct QueryHistory {
explicit QueryHistory() : curQuery(-1) {}
QStringList queries;
- int curQuery;
+ int curQuery = 0;
};
class CompleterModel : public QAbstractListModel
@@ -41,7 +41,7 @@ private:
{
if (!index.isValid() || index.row() >= termList.size()||
(role != Qt::EditRole && role != Qt::DisplayRole))
- return QVariant();
+ return {};
return termList.at(index.row());
}
@@ -58,16 +58,7 @@ private:
QStringList termList;
};
- QHelpSearchQueryWidgetPrivate()
- : QObject()
- , m_searchCompleter(new CompleterModel(this), this)
- {
- }
-
- ~QHelpSearchQueryWidgetPrivate() override
- {
- // nothing todo
- }
+ QHelpSearchQueryWidgetPrivate() : m_searchCompleter(new CompleterModel(this), this) {}
void retranslate()
{
@@ -128,7 +119,6 @@ private slots:
prevQuery();
return true;
}
-
}
return QObject::eventFilter(ob, event);
}
@@ -144,14 +134,10 @@ private slots:
void nextQuery()
{
- nextOrPrevQuery(m_queries.queries.size() - 1, 1, m_nextQueryButton,
- m_prevQueryButton);
+ nextOrPrevQuery(m_queries.queries.size() - 1, 1, m_nextQueryButton, m_prevQueryButton);
}
- void prevQuery()
- {
- nextOrPrevQuery(0, -1, m_prevQueryButton, m_nextQueryButton);
- }
+ void prevQuery() { nextOrPrevQuery(0, -1, m_prevQueryButton, m_nextQueryButton); }
private:
friend class QHelpSearchQueryWidget;
@@ -188,13 +174,12 @@ private:
*/
QHelpSearchQueryWidget::QHelpSearchQueryWidget(QWidget *parent)
: QWidget(parent)
+ , d(new QHelpSearchQueryWidgetPrivate)
{
- d = new QHelpSearchQueryWidgetPrivate();
-
QVBoxLayout *vLayout = new QVBoxLayout(this);
- vLayout->setContentsMargins(QMargins());
+ vLayout->setContentsMargins({});
- QHBoxLayout* hBoxLayout = new QHBoxLayout();
+ QHBoxLayout* hBoxLayout = new QHBoxLayout;
d->m_searchLabel = new QLabel(this);
d->m_lineEdit = new QLineEdit(this);
d->m_lineEdit->setClearButtonEnabled(true);
@@ -265,8 +250,7 @@ QT_WARNING_DISABLE_DEPRECATED
*/
QList<QHelpSearchQuery> QHelpSearchQueryWidget::query() const
{
- return QList<QHelpSearchQuery>() << QHelpSearchQuery(QHelpSearchQuery::DEFAULT,
- searchInput().split(QChar::Space, Qt::SkipEmptyParts));
+ return {{QHelpSearchQuery::DEFAULT, searchInput().split(QChar::Space, Qt::SkipEmptyParts)}};
}
/*!
@@ -293,7 +277,7 @@ QT_WARNING_POP
QString QHelpSearchQueryWidget::searchInput() const
{
if (d->m_queries.queries.isEmpty())
- return QString();
+ return {};
return d->m_queries.queries.last();
}
@@ -309,9 +293,7 @@ QString QHelpSearchQueryWidget::searchInput() const
void QHelpSearchQueryWidget::setSearchInput(const QString &searchInput)
{
d->m_lineEdit->clear();
-
d->m_lineEdit->setText(searchInput);
-
d->searchRequested();
}
diff --git a/src/assistant/help/qhelpsearchresult.cpp b/src/assistant/help/qhelpsearchresult.cpp
index 736c169b0..a813249d7 100644
--- a/src/assistant/help/qhelpsearchresult.cpp
+++ b/src/assistant/help/qhelpsearchresult.cpp
@@ -34,9 +34,7 @@ public:
/*!
Constructs a new empty QHelpSearchResult.
*/
-QHelpSearchResult::QHelpSearchResult()
- : d(new QHelpSearchResultData)
-{}
+QHelpSearchResult::QHelpSearchResult() : d(new QHelpSearchResultData) { }
/*!
Constructs a copy of \a other.
diff --git a/src/assistant/help/qhelpsearchresultwidget.cpp b/src/assistant/help/qhelpsearchresultwidget.cpp
index 6c655b1a9..4fcc2d222 100644
--- a/src/assistant/help/qhelpsearchresultwidget.cpp
+++ b/src/assistant/help/qhelpsearchresultwidget.cpp
@@ -24,8 +24,7 @@ public:
QResultWidget(QWidget *parent = nullptr)
: QTextBrowser(parent)
{
- connect(this, &QTextBrowser::anchorClicked,
- this, &QResultWidget::requestShowLink);
+ connect(this, &QTextBrowser::anchorClicked, this, &QResultWidget::requestShowLink);
setContextMenuPolicy(Qt::NoContextMenu);
setLinkColor(palette().color(QPalette::Link));
}
@@ -34,7 +33,8 @@ public:
void setLinkColor(const QColor &color)
{
m_linkColor = color;
- const QString sheet = QString::fromLatin1("a { text-decoration: underline; color: %1 }").arg(m_linkColor.name());
+ const QString sheet = QString::fromLatin1("a { text-decoration: underline; color: %1 }")
+ .arg(m_linkColor.name());
document()->setDefaultStyleSheet(sheet);
}
@@ -73,7 +73,6 @@ public:
}
str << "</body></html>";
-
setHtml(htmlFile);
}
@@ -87,7 +86,6 @@ private:
QColor m_linkColor;
};
-
class QHelpSearchResultWidgetPrivate : public QObject
{
Q_OBJECT
@@ -126,20 +124,12 @@ private slots:
updateHitRange();
}
- void indexingStarted()
- {
- isIndexing = true;
- }
-
- void indexingFinished()
- {
- isIndexing = false;
- }
+ void indexingStarted() { isIndexing = true; }
+ void indexingFinished() { isIndexing = false; }
private:
QHelpSearchResultWidgetPrivate(QHelpSearchEngine *engine)
- : QObject()
- , searchEngine(engine)
+ : searchEngine(engine)
{
connect(searchEngine.data(), &QHelpSearchEngine::indexingStarted,
this, &QHelpSearchResultWidgetPrivate::indexingStarted);
@@ -154,13 +144,12 @@ private:
QToolButton* setupToolButton(const QString &iconPath)
{
- QToolButton *button = new QToolButton();
+ QToolButton *button = new QToolButton;
button->setEnabled(false);
button->setAutoRaise(true);
button->setIcon(QIcon(iconPath));
button->setIconSize(QSize(12, 12));
button->setMaximumSize(QSize(16, 16));
-
return button;
}
@@ -176,11 +165,12 @@ private:
last = qMin(resultFirstToShow + ResultsRange, count);
first = resultFirstToShow + 1;
}
- resultTextBrowser->showResultPage(searchEngine->searchResults(resultFirstToShow,
- last), isIndexing);
+ resultTextBrowser->showResultPage(searchEngine->searchResults(resultFirstToShow, last),
+ isIndexing);
}
- hitsLabel->setText(QHelpSearchResultWidget::tr("%1 - %2 of %n Hits", nullptr, count).arg(first).arg(last));
+ hitsLabel->setText(QHelpSearchResultWidget::tr("%1 - %2 of %n Hits", nullptr, count)
+ .arg(first).arg(last));
firstResultPage->setEnabled(resultFirstToShow);
previousResultPage->setEnabled(resultFirstToShow);
lastResultPage->setEnabled(count - last);
@@ -225,12 +215,12 @@ QHelpSearchResultWidget::QHelpSearchResultWidget(QHelpSearchEngine *engine)
, d(new QHelpSearchResultWidgetPrivate(engine))
{
QVBoxLayout *vLayout = new QVBoxLayout(this);
- vLayout->setContentsMargins(QMargins());
+ vLayout->setContentsMargins({});
vLayout->setSpacing(0);
QHBoxLayout *hBoxLayout = new QHBoxLayout();
#ifndef Q_OS_MAC
- hBoxLayout->setContentsMargins(QMargins());
+ hBoxLayout->setContentsMargins({});
hBoxLayout->setSpacing(0);
#endif
hBoxLayout->addWidget(d->firstResultPage = d->setupToolButton(
@@ -298,7 +288,7 @@ QUrl QHelpSearchResultWidget::linkAt(const QPoint &point)
{
if (d->resultTextBrowser)
return d->resultTextBrowser->anchorAt(point);
- return QUrl();
+ return {};
}
QT_END_NAMESPACE
diff --git a/src/assistant/help/qoptionswidget.cpp b/src/assistant/help/qoptionswidget.cpp
index ee4bedb04..e42f852ad 100644
--- a/src/assistant/help/qoptionswidget.cpp
+++ b/src/assistant/help/qoptionswidget.cpp
@@ -23,29 +23,31 @@ public:
}
protected:
- void paint(QPainter *painter,
- const QStyleOptionViewItem &option,
- const QModelIndex &index) const override {
+ void paint(QPainter *painter, const QStyleOptionViewItem &option,
+ const QModelIndex &index) const override
+ {
if (isSeparator(index)) {
QRect rect = option.rect;
if (const QAbstractItemView *view = qobject_cast<const QAbstractItemView*>(option.widget))
rect.setWidth(view->viewport()->width());
QStyleOption opt;
opt.rect = rect;
- m_widget->style()->drawPrimitive(QStyle::PE_IndicatorToolBarSeparator, &opt, painter, m_widget);
+ m_widget->style()->drawPrimitive(QStyle::PE_IndicatorToolBarSeparator, &opt, painter,
+ m_widget);
} else {
QItemDelegate::paint(painter, option, index);
}
}
- QSize sizeHint(const QStyleOptionViewItem &option,
- const QModelIndex &index) const override {
+ QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const override
+ {
if (isSeparator(index)) {
int pm = m_widget->style()->pixelMetric(QStyle::PM_DefaultFrameWidth, nullptr, m_widget);
- return QSize(pm, pm);
+ return {pm, pm};
}
return QItemDelegate::sizeHint(option, index);
}
+
private:
QWidget *m_widget;
};
@@ -67,18 +69,11 @@ QOptionsWidget::QOptionsWidget(QWidget *parent)
m_listWidget->setItemDelegate(new ListWidgetDelegate(m_listWidget));
QVBoxLayout *layout = new QVBoxLayout(this);
layout->addWidget(m_listWidget);
- layout->setContentsMargins(QMargins());
-
+ layout->setContentsMargins({});
connect(m_listWidget, &QListWidget::itemChanged, this, &QOptionsWidget::itemChanged);
}
-void QOptionsWidget::clear()
-{
- setOptions(QStringList(), QStringList());
-}
-
-void QOptionsWidget::setOptions(const QStringList &validOptions,
- const QStringList &selectedOptions)
+void QOptionsWidget::setOptions(const QStringList &validOptions, const QStringList &selectedOptions)
{
m_listWidget->clear();
m_optionToItem.clear();
@@ -102,10 +97,8 @@ void QOptionsWidget::setOptions(const QStringList &validOptions,
for (const QString &option : m_invalidOptions)
appendItem(option, false, true);
- if ((validSelectedOptions.size() + m_invalidOptions.size())
- && validUnselectedOptions.size()) {
+ if ((validSelectedOptions.size() + m_invalidOptions.size()) && validUnselectedOptions.size())
appendSeparator();
- }
for (const QString &option : validUnselectedOptions) {
appendItem(option, true, false);
@@ -114,16 +107,6 @@ void QOptionsWidget::setOptions(const QStringList &validOptions,
}
}
-QStringList QOptionsWidget::validOptions() const
-{
- return m_validOptions;
-}
-
-QStringList QOptionsWidget::selectedOptions() const
-{
- return m_selectedOptions;
-}
-
void QOptionsWidget::setNoOptionText(const QString &text)
{
if (m_noOptionText == text)
@@ -195,9 +178,7 @@ void QOptionsWidget::itemChanged(QListWidgetItem *item)
} else {
return;
}
-
emit optionSelectionChanged(m_selectedOptions);
}
-
QT_END_NAMESPACE
diff --git a/src/assistant/help/qoptionswidget_p.h b/src/assistant/help/qoptionswidget_p.h
index b293311b9..0aef8bb7a 100644
--- a/src/assistant/help/qoptionswidget_p.h
+++ b/src/assistant/help/qoptionswidget_p.h
@@ -29,10 +29,10 @@ class QOptionsWidget : public QWidget
public:
QOptionsWidget(QWidget *parent = nullptr);
- void clear();
+ void clear() { setOptions({}, {}); }
void setOptions(const QStringList &validOptions, const QStringList &selectedOptions);
- QStringList validOptions() const;
- QStringList selectedOptions() const;
+ QStringList validOptions() const { return m_validOptions; }
+ QStringList selectedOptions() const { return m_selectedOptions; }
void setNoOptionText(const QString &text);
void setInvalidOptionText(const QString &text);
@@ -53,7 +53,7 @@ private:
QStringList m_invalidOptions;
QStringList m_selectedOptions;
QMap<QString, QListWidgetItem *> m_optionToItem;
- QMap<QListWidgetItem *, QString> m_itemToOption;
+ QMap<QListWidgetItem *, QString> m_itemToOption; // TODO: Replace with QHash
};
QT_END_NAMESPACE
diff --git a/src/assistant/qhelpgenerator/helpgenerator.cpp b/src/assistant/qhelpgenerator/helpgenerator.cpp
index df6b5e49e..6061b3460 100644
--- a/src/assistant/qhelpgenerator/helpgenerator.cpp
+++ b/src/assistant/qhelpgenerator/helpgenerator.cpp
@@ -330,7 +330,7 @@ bool HelpGeneratorPrivate::insertFileNotFoundFile()
" VALUES (0, '', ?, '')"));
m_query->bindValue(0, fileId);
if (fileId > -1 && m_query->exec()) {
- m_fileMap.insert(QString(), fileId);
+ m_fileMap.insert({}, fileId);
return true;
}
return false;