tree: Resolve clang-tidy, clazy, compiler warnings

This commit is contained in:
Albert S. 2023-03-12 16:41:31 +01:00
rodzic 3d0c236cb3
commit 566c4a8c58
14 zmienionych plików z 48 dodań i 51 usunięć

Wyświetl plik

@ -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;

Wyświetl plik

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

Wyświetl plik

@ -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;

Wyświetl plik

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

Wyświetl plik

@ -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<QString> 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<RenderTarget> 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;

Wyświetl plik

@ -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();

Wyświetl plik

@ -24,7 +24,7 @@ QSharedPointer<PreviewResult> 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()));

Wyświetl plik

@ -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)
{

Wyświetl plik

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

Wyświetl plik

@ -2,7 +2,6 @@
#define LOOQSQUERY_H
#include <QString>
#include <QVector>
#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;
}

Wyświetl plik

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

Wyświetl plik

@ -3,7 +3,7 @@
#include "odtprocessor.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");
}

Wyświetl plik

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

Wyświetl plik

@ -69,7 +69,7 @@ QString SqliteSearch::createSortSql(const QVector<SortCondition> 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<QString, QVector<QString>> SqliteSearch::createSql(const Token &token)
QSqlQuery SqliteSearch::makeSqlQuery(const LooqsQuery &query)
{
QString whereSql;
QString joinSql;
QVector<QString> bindValues;
bool isContentSearch = (query.getTokensMask() & FILTER_CONTENT) == FILTER_CONTENT;
if(query.getTokens().isEmpty())