tree: Resolve clang-tidy, clazy, compiler warnings

This commit is contained in:
Albert S. 2023-03-12 16:41:31 +01:00
parent 3d0c236cb3
commit 566c4a8c58
14 changed files with 48 additions and 51 deletions

View File

@ -23,7 +23,7 @@ void CommandAdd::indexerFinished()
if(failedPathsCount > 0) if(failedPathsCount > 0)
{ {
Logger::info() << "Failed paths: " << Qt::endl; Logger::info() << "Failed paths: " << Qt::endl;
for(QString paths : result.failedPaths()) for(const QString &paths : result.failedPaths())
{ {
Logger::info() << paths << Qt::endl; Logger::info() << paths << Qt::endl;
} }
@ -95,8 +95,8 @@ int CommandAdd::handle(QStringList arguments)
connect(indexer, &Indexer::pathsCountChanged, this, connect(indexer, &Indexer::pathsCountChanged, this,
[](int pathsCount) { Logger::info() << "Found paths: " << pathsCount << Qt::endl; }); [](int pathsCount) { Logger::info() << "Found paths: " << pathsCount << Qt::endl; });
connect(indexer, &Indexer::indexProgress, this, connect(indexer, &Indexer::indexProgress, this,
[](int pathsCount, unsigned int added, unsigned int skipped, unsigned int failed, unsigned int totalCount) [](int pathsCount, unsigned int /*added*/, unsigned int /*skipped*/, unsigned int /*failed*/,
{ Logger::info() << "Processed files: " << pathsCount << Qt::endl; }); unsigned int /*totalCount*/) { Logger::info() << "Processed files: " << pathsCount << Qt::endl; });
connect(indexer, &Indexer::finished, this, &CommandAdd::indexerFinished); connect(indexer, &Indexer::finished, this, &CommandAdd::indexerFinished);
this->autoFinish = false; this->autoFinish = false;

View File

@ -1,6 +1,5 @@
#include <QCommandLineParser> #include <QCommandLineParser>
#include "commandlist.h" #include "commandlist.h"
#include "databasefactory.h"
#include "logger.h" #include "logger.h"
int CommandList::handle(QStringList arguments) int CommandList::handle(QStringList arguments)

View File

@ -38,7 +38,6 @@ int CommandUpdate::handle(QStringList arguments)
QThreadPool::globalInstance()->setMaxThreadCount(threadsCount.toInt()); QThreadPool::globalInstance()->setMaxThreadCount(threadsCount.toInt());
} }
bool hasErrors = false;
IndexSyncer *syncer = new IndexSyncer(*this->dbService); IndexSyncer *syncer = new IndexSyncer(*this->dbService);
FileSaverOptions fileOptions; 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 */ /* TODO: updated not printed, handled be verbose in FileSaver, but this can be improved */
} }
connect(syncer, &IndexSyncer::finished, this, 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; Logger::info() << "Syncing finished" << Qt::endl;
@ -76,7 +75,7 @@ int CommandUpdate::handle(QStringList arguments)
} }
int retval = 0; int retval = 0;
if(hasErrors && !keepGoing) if(this->hasErrors && !keepGoing)
{ {
retval = 1; retval = 1;
} }
@ -86,7 +85,7 @@ int CommandUpdate::handle(QStringList arguments)
[&](QString error) [&](QString error)
{ {
Logger::error() << error << Qt::endl; Logger::error() << error << Qt::endl;
hasErrors = true; this->hasErrors = true;
}); });
this->autoFinish = false; this->autoFinish = false;

View File

@ -4,6 +4,9 @@
#include "filesaver.h" #include "filesaver.h"
class CommandUpdate : public Command class CommandUpdate : public Command
{ {
protected:
bool hasErrors = false;
public: public:
using Command::Command; using Command::Command;
int handle(QStringList arguments) override; int handle(QStringList arguments) override;

View File

@ -22,7 +22,6 @@
#include "../shared/sqlitesearch.h" #include "../shared/sqlitesearch.h"
#include "../shared/looqsgeneralexception.h" #include "../shared/looqsgeneralexception.h"
#include "../shared/common.h" #include "../shared/common.h"
#include "previewgenerator.h"
#include "aboutdialog.h" #include "aboutdialog.h"
MainWindow::MainWindow(QWidget *parent, QString socketPath) MainWindow::MainWindow(QWidget *parent, QString socketPath)
@ -148,7 +147,7 @@ void MainWindow::connectSignals()
connect(this->indexer, &Indexer::finished, this, &MainWindow::finishIndexing); connect(this->indexer, &Indexer::finished, this, &MainWindow::finishIndexing);
connect(ui->lstPaths->selectionModel(), &QItemSelectionModel::selectionChanged, this, 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); }); { ui->btnDeletePath->setEnabled(this->ui->lstPaths->selectedItems().count() > 0); });
connect(ui->btnDeletePath, &QPushButton::clicked, this, [&] { qDeleteAll(ui->lstPaths->selectedItems()); }); connect(ui->btnDeletePath, &QPushButton::clicked, this, [&] { qDeleteAll(ui->lstPaths->selectedItems()); });
@ -168,30 +167,29 @@ void MainWindow::connectSignals()
} }
}); });
connect(ui->menuAboutAction, &QAction::triggered, this, connect(ui->menuAboutAction, &QAction::triggered, this,
[this](bool checked) [this](bool /*checked*/)
{ {
AboutDialog aboutDialog(this); AboutDialog aboutDialog(this);
aboutDialog.exec(); aboutDialog.exec();
}); });
connect(ui->menuAboutQtAction, &QAction::triggered, this, 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->menuSyncIndexAction, &QAction::triggered, this, &MainWindow::startIndexSync);
connect(ui->menuOpenUserManualAction, &QAction::triggered, this, connect(ui->menuOpenUserManualAction, &QAction::triggered, this,
[this]() { QDesktopServices::openUrl(Common::userManualUrl()); }); []() { QDesktopServices::openUrl(Common::userManualUrl()); });
connect(indexSyncer, &IndexSyncer::finished, this, connect(
[&](unsigned int totalUpdated, unsigned int totalDeleted, unsigned int totalErrored) indexSyncer, &IndexSyncer::finished, this,
{ [&](unsigned int totalUpdated, unsigned int totalDeleted, unsigned int totalErrored)
this->progressDialog.cancel(); {
this->progressDialog.cancel();
QMessageBox::information( QMessageBox::information(
this, "Syncing finished", this, "Syncing finished",
QString("Syncing finished\n\nTotal updated: %1\nTotal deleted: %2\nTotal errors: %3\n") QString("Syncing finished\n\nTotal updated: %1\nTotal deleted: %2\nTotal errors: %3\n")
.arg(QString::number(totalUpdated)) .arg(QString::number(totalUpdated), QString::number(totalDeleted), QString::number(totalErrored)));
.arg(QString::number(totalDeleted)) });
.arg(QString::number(totalErrored)));
});
connect(this, &MainWindow::beginIndexSync, indexSyncer, &IndexSyncer::sync); connect(this, &MainWindow::beginIndexSync, indexSyncer, &IndexSyncer::sync);
connect(&this->progressDialog, &QProgressDialog::canceled, indexSyncer, &IndexSyncer::cancel); connect(&this->progressDialog, &QProgressDialog::canceled, indexSyncer, &IndexSyncer::cancel);
connect(ui->btnSaveSettings, &QPushButton::clicked, this, &MainWindow::saveSettings); 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; QSettings scaleSetting;
scaleSetting.setValue("currentScale", ui->comboScale->currentText()); scaleSetting.setValue("currentScale", ui->comboScale->currentText());
@ -398,7 +396,8 @@ void MainWindow::processShortcut(int key)
{ {
ui->txtSearch->setFocus(); ui->txtSearch->setFocus();
QString currentText = ui->txtSearch->text().trimmed(); QString currentText = ui->txtSearch->text().trimmed();
int index = currentText.lastIndexOf(QRegularExpression("[\\s\\)]")); static QRegularExpression separatorRegex("[\\s\\)]");
int index = currentText.lastIndexOf(separatorRegex);
if(index != -1) if(index != -1)
{ {
bool isFilter = (index == currentText.length() - 1); bool isFilter = (index == currentText.length() - 1);
@ -678,7 +677,7 @@ void MainWindow::previewReceived()
QFileInfo fileInfo{docPath}; QFileInfo fileInfo{docPath};
QMenu menu("labeRightClick", this); QMenu menu("labeRightClick", this);
createSearchResultMenu(menu, fileInfo); createSearchResultMenu(menu, fileInfo);
menu.addAction("Copy page number", menu.addAction("Copy page number", this,
[previewPage] { QGuiApplication::clipboard()->setText(QString::number(previewPage)); }); [previewPage] { QGuiApplication::clipboard()->setText(QString::number(previewPage)); });
menu.exec(QCursor::pos()); menu.exec(QCursor::pos());
}; };
@ -916,7 +915,7 @@ void MainWindow::makePreviews(int page)
ui->previewProcessBar->setMaximum(this->previewCoordinator.previewableCount()); ui->previewProcessBar->setMaximum(this->previewCoordinator.previewableCount());
QVector<QString> wordsToHighlight; QVector<QString> wordsToHighlight;
QRegularExpression extractor(R"#("([^"]*)"|([^\s]+))#"); static QRegularExpression extractor(R"#("([^"]*)"|([^\s]+))#");
for(const Token &token : this->contentSearchQuery.getTokens()) for(const Token &token : this->contentSearchQuery.getTokens())
{ {
if(token.type == FILTER_CONTENT_CONTAINS) if(token.type == FILTER_CONTENT_CONTAINS)
@ -948,7 +947,6 @@ void MainWindow::makePreviews(int page)
renderConfig.scaleY = QGuiApplication::primaryScreen()->physicalDotsPerInchY() * (currentScale / 100.); renderConfig.scaleY = QGuiApplication::primaryScreen()->physicalDotsPerInchY() * (currentScale / 100.);
renderConfig.wordsToHighlight = wordsToHighlight; renderConfig.wordsToHighlight = wordsToHighlight;
int previewPos = 0;
QVector<RenderTarget> targets; QVector<RenderTarget> targets;
for(const SearchResult &sr : this->previewCoordinator.getPreviewableSearchResults()) for(const SearchResult &sr : this->previewCoordinator.getPreviewableSearchResults())
{ {
@ -988,20 +986,20 @@ void MainWindow::handleSearchError(QString error)
void MainWindow::createSearchResultMenu(QMenu &menu, const QFileInfo &fileInfo) 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()); }); [&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()); }); [&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 previewables = this->previewCoordinator.getPreviewableSearchResults();
auto result = auto result =
std::find_if(previewables.begin(), previewables.end(), 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()) if(result != previewables.end())
{ {
menu.addAction("Show previews for this file", menu.addAction("Show previews for this file", this,
[this, &fileInfo] [this, &fileInfo]
{ {
ui->tabWidget->setCurrentIndex(1); ui->tabWidget->setCurrentIndex(1);
@ -1037,7 +1035,7 @@ void MainWindow::openFile(QString path)
QDesktopServices::openUrl(QUrl::fromLocalFile(path)); QDesktopServices::openUrl(QUrl::fromLocalFile(path));
} }
void MainWindow::treeSearchItemActivated(QTreeWidgetItem *item, int i) void MainWindow::treeSearchItemActivated(QTreeWidgetItem *item, int /*i*/)
{ {
openFile(item->text(1)); openFile(item->text(1));
} }
@ -1065,7 +1063,7 @@ MainWindow::~MainWindow()
delete ui; delete ui;
} }
void MainWindow::closeEvent(QCloseEvent *event) void MainWindow::closeEvent(QCloseEvent * /*event*/)
{ {
QStringList list = this->searchHistory.toList(); QStringList list = this->searchHistory.toList();
QSettings settings; QSettings settings;

View File

@ -57,7 +57,7 @@ class MainWindow : public QMainWindow
void initSettingsTabs(); void initSettingsTabs();
int currentSelectedScale(); int currentSelectedScale();
void processShortcut(int key); void processShortcut(int key);
bool eventFilter(QObject *object, QEvent *event); bool eventFilter(QObject *object, QEvent *event) override;
private slots: private slots:
void lineEditReturnPressed(); void lineEditReturnPressed();

View File

@ -24,7 +24,7 @@ QSharedPointer<PreviewResult> PreviewGeneratorOdt::generate(RenderConfig config,
throw LooqsGeneralException("Error while reading content.xml of " + documentPath); throw LooqsGeneralException("Error while reading content.xml of " + documentPath);
} }
TagStripperProcessor tsp; TagStripperProcessor tsp;
QString content = tsp.process(entireContent).first().content; QString content = tsp.process(entireContent).constFirst().content;
PreviewGeneratorPlainText plainTextGenerator; PreviewGeneratorPlainText plainTextGenerator;
result->setText(plainTextGenerator.generatePreviewText(content, config, info.fileName())); result->setText(plainTextGenerator.generatePreviewText(content, config, info.fileName()));

View File

@ -195,7 +195,7 @@ QString PreviewGeneratorPlainText::generateLineBasedPreviewText(QTextStream &in,
int totalWordsA = 0; int totalWordsA = 0;
int differentWordsB = 0; int differentWordsB = 0;
int totalWordsB = 0; int totalWordsB = 0;
for(int count : a.wordCountMap.values()) for(int count : qAsConst(a.wordCountMap))
{ {
if(count > 0) if(count > 0)
{ {
@ -203,7 +203,7 @@ QString PreviewGeneratorPlainText::generateLineBasedPreviewText(QTextStream &in,
} }
totalWordsA += count; totalWordsA += count;
} }
for(int count : b.wordCountMap.values()) for(int count : qAsConst(b.wordCountMap))
{ {
if(count > 0) if(count > 0)
{ {

View File

@ -7,6 +7,7 @@
#include <optional> #include <optional>
#include <algorithm> #include <algorithm>
#include "looqsquery.h" #include "looqsquery.h"
#include "looqsgeneralexception.h"
const QVector<Token> &LooqsQuery::getTokens() const const QVector<Token> &LooqsQuery::getTokens() const
{ {
@ -180,8 +181,9 @@ LooqsQuery LooqsQuery::build(QString expression, TokenType loneWordsTokenType, b
QStringList loneWords; QStringList loneWords;
LooqsQuery result; LooqsQuery result;
QRegularExpression rx("((?<filtername>(\\.|\\w)+):(?<args>\\((?<innerargs>[^\\)]+)\\)|([^\\s])+)|(?<boolean>AND|OR)" static QRegularExpression rx(
"|(?<negation>!)|(?<bracket>\\(|\\))|(?<loneword>[^\\s]+))"); "((?<filtername>(\\.|\\w)+):(?<args>\\((?<innerargs>[^\\)]+)\\)|([^\\s])+)|(?<boolean>AND|OR)"
"|(?<negation>!)|(?<bracket>\\(|\\))|(?<loneword>[^\\s]+))");
QRegularExpressionMatchIterator i = rx.globalMatch(expression); QRegularExpressionMatchIterator i = rx.globalMatch(expression);
auto previousWasBool = [&result] { return !result.tokens.empty() && ((result.tokens.last().type & BOOL) == BOOL); }; 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); }; auto previousWas = [&result](TokenType t) { return !result.tokens.empty() && (result.tokens.last().type == t); };

View File

@ -2,7 +2,6 @@
#define LOOQSQUERY_H #define LOOQSQUERY_H
#include <QString> #include <QString>
#include <QVector> #include <QVector>
#include "looqsgeneralexception.h"
#include "token.h" #include "token.h"
/* Fields that can be queried or sorted */ /* Fields that can be queried or sorted */
enum QueryField enum QueryField
@ -46,7 +45,7 @@ class LooqsQuery
void addToken(Token t); void addToken(Token t);
void updateTokensMask() void updateTokensMask()
{ {
for(const Token &t : tokens) for(const Token &t : qAsConst(tokens))
{ {
this->tokensMask |= t.type; this->tokensMask |= t.type;
} }

View File

@ -10,7 +10,7 @@ class NothingProcessor : public Processor
NothingProcessor(); NothingProcessor();
public: public:
QVector<PageData> process(const QByteArray &data) const override QVector<PageData> process(const QByteArray & /*data*/) const override
{ {
return {}; return {};
} }

View File

@ -3,7 +3,7 @@
#include "odtprocessor.h" #include "odtprocessor.h"
#include "tagstripperprocessor.h" #include "tagstripperprocessor.h"
QVector<PageData> OdtProcessor::process(const QByteArray &data) const QVector<PageData> OdtProcessor::process(const QByteArray & /*data*/) const
{ {
throw LooqsGeneralException("Not implemented yet"); throw LooqsGeneralException("Not implemented yet");
} }

View File

@ -1,5 +1,3 @@
#include "paralleldirscanner.h"
#include <QRunnable> #include <QRunnable>
#include <QMutex> #include <QMutex>
#include <QDirIterator> #include <QDirIterator>
@ -7,7 +5,7 @@
#include <QThreadPool> #include <QThreadPool>
#include <functional> #include <functional>
#include "dirscanworker.h" #include "dirscanworker.h"
#include "logger.h" #include "paralleldirscanner.h"
ParallelDirScanner::ParallelDirScanner() ParallelDirScanner::ParallelDirScanner()
{ {

View File

@ -69,7 +69,7 @@ QString SqliteSearch::createSortSql(const QVector<SortCondition> sortConditions)
QString SqliteSearch::escapeFtsArgument(QString ftsArg) QString SqliteSearch::escapeFtsArgument(QString ftsArg)
{ {
QString result; QString result;
QRegularExpression extractor(R"#("([^"]*)"|([^\s]+))#"); static QRegularExpression extractor(R"#("([^"]*)"|([^\s]+))#");
QRegularExpressionMatchIterator i = extractor.globalMatch(ftsArg); QRegularExpressionMatchIterator i = extractor.globalMatch(ftsArg);
while(i.hasNext()) while(i.hasNext())
{ {
@ -149,7 +149,6 @@ QPair<QString, QVector<QString>> SqliteSearch::createSql(const Token &token)
QSqlQuery SqliteSearch::makeSqlQuery(const LooqsQuery &query) QSqlQuery SqliteSearch::makeSqlQuery(const LooqsQuery &query)
{ {
QString whereSql; QString whereSql;
QString joinSql;
QVector<QString> bindValues; QVector<QString> bindValues;
bool isContentSearch = (query.getTokensMask() & FILTER_CONTENT) == FILTER_CONTENT; bool isContentSearch = (query.getTokensMask() & FILTER_CONTENT) == FILTER_CONTENT;
if(query.getTokens().isEmpty()) if(query.getTokens().isEmpty())