From 566c4a8c58c8202d6f05638ccdcc6de398dd43f9 Mon Sep 17 00:00:00 2001 From: Albert S Date: Sun, 12 Mar 2023 16:41:31 +0100 Subject: [PATCH] tree: Resolve clang-tidy, clazy, compiler warnings --- cli/commandadd.cpp | 6 ++-- cli/commandlist.cpp | 1 - cli/commandupdate.cpp | 7 ++-- cli/commandupdate.h | 3 ++ gui/mainwindow.cpp | 54 +++++++++++++++---------------- gui/mainwindow.h | 2 +- gui/previewgeneratorodt.cpp | 2 +- gui/previewgeneratorplaintext.cpp | 4 +-- shared/looqsquery.cpp | 6 ++-- shared/looqsquery.h | 3 +- shared/nothingprocessor.h | 2 +- shared/odtprocessor.cpp | 2 +- shared/paralleldirscanner.cpp | 4 +-- shared/sqlitesearch.cpp | 3 +- 14 files changed, 48 insertions(+), 51 deletions(-) diff --git a/cli/commandadd.cpp b/cli/commandadd.cpp index 690495c..53ee2d6 100644 --- a/cli/commandadd.cpp +++ b/cli/commandadd.cpp @@ -23,7 +23,7 @@ void CommandAdd::indexerFinished() if(failedPathsCount > 0) { Logger::info() << "Failed paths: " << Qt::endl; - for(QString paths : result.failedPaths()) + for(const QString &paths : result.failedPaths()) { Logger::info() << paths << Qt::endl; } @@ -95,8 +95,8 @@ int CommandAdd::handle(QStringList arguments) connect(indexer, &Indexer::pathsCountChanged, this, [](int pathsCount) { Logger::info() << "Found paths: " << pathsCount << Qt::endl; }); connect(indexer, &Indexer::indexProgress, this, - [](int pathsCount, unsigned int added, unsigned int skipped, unsigned int failed, unsigned int totalCount) - { Logger::info() << "Processed files: " << pathsCount << Qt::endl; }); + [](int pathsCount, unsigned int /*added*/, unsigned int /*skipped*/, unsigned int /*failed*/, + unsigned int /*totalCount*/) { Logger::info() << "Processed files: " << pathsCount << Qt::endl; }); connect(indexer, &Indexer::finished, this, &CommandAdd::indexerFinished); this->autoFinish = false; diff --git a/cli/commandlist.cpp b/cli/commandlist.cpp index 51ba681..93112a0 100644 --- a/cli/commandlist.cpp +++ b/cli/commandlist.cpp @@ -1,6 +1,5 @@ #include #include "commandlist.h" -#include "databasefactory.h" #include "logger.h" int CommandList::handle(QStringList arguments) diff --git a/cli/commandupdate.cpp b/cli/commandupdate.cpp index 71a1a3f..f0e4caa 100644 --- a/cli/commandupdate.cpp +++ b/cli/commandupdate.cpp @@ -38,7 +38,6 @@ int CommandUpdate::handle(QStringList arguments) QThreadPool::globalInstance()->setMaxThreadCount(threadsCount.toInt()); } - bool hasErrors = false; IndexSyncer *syncer = new IndexSyncer(*this->dbService); FileSaverOptions fileOptions; @@ -64,7 +63,7 @@ int CommandUpdate::handle(QStringList arguments) /* TODO: updated not printed, handled be verbose in FileSaver, but this can be improved */ } connect(syncer, &IndexSyncer::finished, this, - [&](unsigned int totalUpdated, unsigned int totalRemoved, unsigned int totalErrors) + [this, dryRun, keepGoing](unsigned int totalUpdated, unsigned int totalRemoved, unsigned int totalErrors) { Logger::info() << "Syncing finished" << Qt::endl; @@ -76,7 +75,7 @@ int CommandUpdate::handle(QStringList arguments) } int retval = 0; - if(hasErrors && !keepGoing) + if(this->hasErrors && !keepGoing) { retval = 1; } @@ -86,7 +85,7 @@ int CommandUpdate::handle(QStringList arguments) [&](QString error) { Logger::error() << error << Qt::endl; - hasErrors = true; + this->hasErrors = true; }); this->autoFinish = false; diff --git a/cli/commandupdate.h b/cli/commandupdate.h index 730b9e4..a76b6b1 100644 --- a/cli/commandupdate.h +++ b/cli/commandupdate.h @@ -4,6 +4,9 @@ #include "filesaver.h" class CommandUpdate : public Command { + protected: + bool hasErrors = false; + public: using Command::Command; int handle(QStringList arguments) override; diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp index 74d53bf..a0e4cfe 100644 --- a/gui/mainwindow.cpp +++ b/gui/mainwindow.cpp @@ -22,7 +22,6 @@ #include "../shared/sqlitesearch.h" #include "../shared/looqsgeneralexception.h" #include "../shared/common.h" -#include "previewgenerator.h" #include "aboutdialog.h" MainWindow::MainWindow(QWidget *parent, QString socketPath) @@ -148,7 +147,7 @@ void MainWindow::connectSignals() connect(this->indexer, &Indexer::finished, this, &MainWindow::finishIndexing); connect(ui->lstPaths->selectionModel(), &QItemSelectionModel::selectionChanged, this, - [&](const QItemSelection &selected, const QItemSelection &deselected) + [&](const QItemSelection & /*selected*/, const QItemSelection & /*deselected*/) { ui->btnDeletePath->setEnabled(this->ui->lstPaths->selectedItems().count() > 0); }); connect(ui->btnDeletePath, &QPushButton::clicked, this, [&] { qDeleteAll(ui->lstPaths->selectedItems()); }); @@ -168,30 +167,29 @@ void MainWindow::connectSignals() } }); connect(ui->menuAboutAction, &QAction::triggered, this, - [this](bool checked) + [this](bool /*checked*/) { AboutDialog aboutDialog(this); aboutDialog.exec(); }); connect(ui->menuAboutQtAction, &QAction::triggered, this, - [this](bool checked) { QMessageBox::aboutQt(this, "About Qt"); }); + [this](bool /*checked*/) { QMessageBox::aboutQt(this, "About Qt"); }); connect(ui->menuSyncIndexAction, &QAction::triggered, this, &MainWindow::startIndexSync); connect(ui->menuOpenUserManualAction, &QAction::triggered, this, - [this]() { QDesktopServices::openUrl(Common::userManualUrl()); }); + []() { QDesktopServices::openUrl(Common::userManualUrl()); }); - connect(indexSyncer, &IndexSyncer::finished, this, - [&](unsigned int totalUpdated, unsigned int totalDeleted, unsigned int totalErrored) - { - this->progressDialog.cancel(); + connect( + indexSyncer, &IndexSyncer::finished, this, + [&](unsigned int totalUpdated, unsigned int totalDeleted, unsigned int totalErrored) + { + this->progressDialog.cancel(); - QMessageBox::information( - this, "Syncing finished", - QString("Syncing finished\n\nTotal updated: %1\nTotal deleted: %2\nTotal errors: %3\n") - .arg(QString::number(totalUpdated)) - .arg(QString::number(totalDeleted)) - .arg(QString::number(totalErrored))); - }); + QMessageBox::information( + this, "Syncing finished", + QString("Syncing finished\n\nTotal updated: %1\nTotal deleted: %2\nTotal errors: %3\n") + .arg(QString::number(totalUpdated), QString::number(totalDeleted), QString::number(totalErrored))); + }); connect(this, &MainWindow::beginIndexSync, indexSyncer, &IndexSyncer::sync); connect(&this->progressDialog, &QProgressDialog::canceled, indexSyncer, &IndexSyncer::cancel); connect(ui->btnSaveSettings, &QPushButton::clicked, this, &MainWindow::saveSettings); @@ -352,7 +350,7 @@ void MainWindow::finishIndexing() } } -void MainWindow::comboScaleChanged(int i) +void MainWindow::comboScaleChanged(int /*i*/) { QSettings scaleSetting; scaleSetting.setValue("currentScale", ui->comboScale->currentText()); @@ -398,7 +396,8 @@ void MainWindow::processShortcut(int key) { ui->txtSearch->setFocus(); QString currentText = ui->txtSearch->text().trimmed(); - int index = currentText.lastIndexOf(QRegularExpression("[\\s\\)]")); + static QRegularExpression separatorRegex("[\\s\\)]"); + int index = currentText.lastIndexOf(separatorRegex); if(index != -1) { bool isFilter = (index == currentText.length() - 1); @@ -678,7 +677,7 @@ void MainWindow::previewReceived() QFileInfo fileInfo{docPath}; QMenu menu("labeRightClick", this); createSearchResultMenu(menu, fileInfo); - menu.addAction("Copy page number", + menu.addAction("Copy page number", this, [previewPage] { QGuiApplication::clipboard()->setText(QString::number(previewPage)); }); menu.exec(QCursor::pos()); }; @@ -916,7 +915,7 @@ void MainWindow::makePreviews(int page) ui->previewProcessBar->setMaximum(this->previewCoordinator.previewableCount()); QVector wordsToHighlight; - QRegularExpression extractor(R"#("([^"]*)"|([^\s]+))#"); + static QRegularExpression extractor(R"#("([^"]*)"|([^\s]+))#"); for(const Token &token : this->contentSearchQuery.getTokens()) { if(token.type == FILTER_CONTENT_CONTAINS) @@ -948,7 +947,6 @@ void MainWindow::makePreviews(int page) renderConfig.scaleY = QGuiApplication::primaryScreen()->physicalDotsPerInchY() * (currentScale / 100.); renderConfig.wordsToHighlight = wordsToHighlight; - int previewPos = 0; QVector targets; for(const SearchResult &sr : this->previewCoordinator.getPreviewableSearchResults()) { @@ -988,20 +986,20 @@ void MainWindow::handleSearchError(QString error) void MainWindow::createSearchResultMenu(QMenu &menu, const QFileInfo &fileInfo) { - menu.addAction("Copy filename to clipboard", + menu.addAction("Copy filename to clipboard", this, [&fileInfo] { QGuiApplication::clipboard()->setText(fileInfo.fileName()); }); - menu.addAction("Copy full path to clipboard", + menu.addAction("Copy full path to clipboard", this, [&fileInfo] { QGuiApplication::clipboard()->setText(fileInfo.absoluteFilePath()); }); - menu.addAction("Open containing folder", [this, &fileInfo] { this->openFile(fileInfo.absolutePath()); }); + menu.addAction("Open containing folder", this, [this, &fileInfo] { this->openFile(fileInfo.absolutePath()); }); auto previewables = this->previewCoordinator.getPreviewableSearchResults(); auto result = std::find_if(previewables.begin(), previewables.end(), - [this, &fileInfo](SearchResult &a) { return fileInfo.absoluteFilePath() == a.fileData.absPath; }); + [&fileInfo](SearchResult &a) { return fileInfo.absoluteFilePath() == a.fileData.absPath; }); if(result != previewables.end()) { - menu.addAction("Show previews for this file", + menu.addAction("Show previews for this file", this, [this, &fileInfo] { ui->tabWidget->setCurrentIndex(1); @@ -1037,7 +1035,7 @@ void MainWindow::openFile(QString path) QDesktopServices::openUrl(QUrl::fromLocalFile(path)); } -void MainWindow::treeSearchItemActivated(QTreeWidgetItem *item, int i) +void MainWindow::treeSearchItemActivated(QTreeWidgetItem *item, int /*i*/) { openFile(item->text(1)); } @@ -1065,7 +1063,7 @@ MainWindow::~MainWindow() delete ui; } -void MainWindow::closeEvent(QCloseEvent *event) +void MainWindow::closeEvent(QCloseEvent * /*event*/) { QStringList list = this->searchHistory.toList(); QSettings settings; diff --git a/gui/mainwindow.h b/gui/mainwindow.h index 2053cfa..805a3f2 100644 --- a/gui/mainwindow.h +++ b/gui/mainwindow.h @@ -57,7 +57,7 @@ class MainWindow : public QMainWindow void initSettingsTabs(); int currentSelectedScale(); void processShortcut(int key); - bool eventFilter(QObject *object, QEvent *event); + bool eventFilter(QObject *object, QEvent *event) override; private slots: void lineEditReturnPressed(); diff --git a/gui/previewgeneratorodt.cpp b/gui/previewgeneratorodt.cpp index de5b64a..bc3d035 100644 --- a/gui/previewgeneratorodt.cpp +++ b/gui/previewgeneratorodt.cpp @@ -24,7 +24,7 @@ QSharedPointer PreviewGeneratorOdt::generate(RenderConfig config, throw LooqsGeneralException("Error while reading content.xml of " + documentPath); } TagStripperProcessor tsp; - QString content = tsp.process(entireContent).first().content; + QString content = tsp.process(entireContent).constFirst().content; PreviewGeneratorPlainText plainTextGenerator; result->setText(plainTextGenerator.generatePreviewText(content, config, info.fileName())); diff --git a/gui/previewgeneratorplaintext.cpp b/gui/previewgeneratorplaintext.cpp index c5b944a..0ce36ae 100644 --- a/gui/previewgeneratorplaintext.cpp +++ b/gui/previewgeneratorplaintext.cpp @@ -195,7 +195,7 @@ QString PreviewGeneratorPlainText::generateLineBasedPreviewText(QTextStream &in, int totalWordsA = 0; int differentWordsB = 0; int totalWordsB = 0; - for(int count : a.wordCountMap.values()) + for(int count : qAsConst(a.wordCountMap)) { if(count > 0) { @@ -203,7 +203,7 @@ QString PreviewGeneratorPlainText::generateLineBasedPreviewText(QTextStream &in, } totalWordsA += count; } - for(int count : b.wordCountMap.values()) + for(int count : qAsConst(b.wordCountMap)) { if(count > 0) { diff --git a/shared/looqsquery.cpp b/shared/looqsquery.cpp index 29fc187..730bf47 100644 --- a/shared/looqsquery.cpp +++ b/shared/looqsquery.cpp @@ -7,6 +7,7 @@ #include #include #include "looqsquery.h" +#include "looqsgeneralexception.h" const QVector &LooqsQuery::getTokens() const { @@ -180,8 +181,9 @@ LooqsQuery LooqsQuery::build(QString expression, TokenType loneWordsTokenType, b QStringList loneWords; LooqsQuery result; - QRegularExpression rx("((?(\\.|\\w)+):(?\\((?[^\\)]+)\\)|([^\\s])+)|(?AND|OR)" - "|(?!)|(?\\(|\\))|(?[^\\s]+))"); + static QRegularExpression rx( + "((?(\\.|\\w)+):(?\\((?[^\\)]+)\\)|([^\\s])+)|(?AND|OR)" + "|(?!)|(?\\(|\\))|(?[^\\s]+))"); QRegularExpressionMatchIterator i = rx.globalMatch(expression); auto previousWasBool = [&result] { return !result.tokens.empty() && ((result.tokens.last().type & BOOL) == BOOL); }; auto previousWas = [&result](TokenType t) { return !result.tokens.empty() && (result.tokens.last().type == t); }; diff --git a/shared/looqsquery.h b/shared/looqsquery.h index ea6dc37..912ff50 100644 --- a/shared/looqsquery.h +++ b/shared/looqsquery.h @@ -2,7 +2,6 @@ #define LOOQSQUERY_H #include #include -#include "looqsgeneralexception.h" #include "token.h" /* Fields that can be queried or sorted */ enum QueryField @@ -46,7 +45,7 @@ class LooqsQuery void addToken(Token t); void updateTokensMask() { - for(const Token &t : tokens) + for(const Token &t : qAsConst(tokens)) { this->tokensMask |= t.type; } diff --git a/shared/nothingprocessor.h b/shared/nothingprocessor.h index 0a1d4c0..47a5c7f 100644 --- a/shared/nothingprocessor.h +++ b/shared/nothingprocessor.h @@ -10,7 +10,7 @@ class NothingProcessor : public Processor NothingProcessor(); public: - QVector process(const QByteArray &data) const override + QVector process(const QByteArray & /*data*/) const override { return {}; } diff --git a/shared/odtprocessor.cpp b/shared/odtprocessor.cpp index fc2b0f4..a72e91a 100644 --- a/shared/odtprocessor.cpp +++ b/shared/odtprocessor.cpp @@ -3,7 +3,7 @@ #include "odtprocessor.h" #include "tagstripperprocessor.h" -QVector OdtProcessor::process(const QByteArray &data) const +QVector OdtProcessor::process(const QByteArray & /*data*/) const { throw LooqsGeneralException("Not implemented yet"); } diff --git a/shared/paralleldirscanner.cpp b/shared/paralleldirscanner.cpp index 8d740fb..1a21cee 100644 --- a/shared/paralleldirscanner.cpp +++ b/shared/paralleldirscanner.cpp @@ -1,5 +1,3 @@ -#include "paralleldirscanner.h" - #include #include #include @@ -7,7 +5,7 @@ #include #include #include "dirscanworker.h" -#include "logger.h" +#include "paralleldirscanner.h" ParallelDirScanner::ParallelDirScanner() { diff --git a/shared/sqlitesearch.cpp b/shared/sqlitesearch.cpp index e56f014..0731a61 100644 --- a/shared/sqlitesearch.cpp +++ b/shared/sqlitesearch.cpp @@ -69,7 +69,7 @@ QString SqliteSearch::createSortSql(const QVector sortConditions) QString SqliteSearch::escapeFtsArgument(QString ftsArg) { QString result; - QRegularExpression extractor(R"#("([^"]*)"|([^\s]+))#"); + static QRegularExpression extractor(R"#("([^"]*)"|([^\s]+))#"); QRegularExpressionMatchIterator i = extractor.globalMatch(ftsArg); while(i.hasNext()) { @@ -149,7 +149,6 @@ QPair> SqliteSearch::createSql(const Token &token) QSqlQuery SqliteSearch::makeSqlQuery(const LooqsQuery &query) { QString whereSql; - QString joinSql; QVector bindValues; bool isContentSearch = (query.getTokensMask() & FILTER_CONTENT) == FILTER_CONTENT; if(query.getTokens().isEmpty())