cleanup: more Coverity silencing

Mostly irrelevant std::move() stuff of copy-on-write Qt objects,
a few real bugs, a timestamp_t downconversion and some codingsyle
adaptation.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2024-01-16 17:39:19 +01:00 committed by Dirk Hohndel
parent 35ff6eea35
commit 91e4fb4769
27 changed files with 47 additions and 47 deletions

View file

@ -350,8 +350,8 @@ std::vector<const dive_site *> getDiveSitesToExport(bool selectedOnly)
return res;
}
QFuture<int> exportUsingStyleSheet(QString filename, bool doExport, int units,
QString stylesheet, bool anonymize)
QFuture<int> exportUsingStyleSheet(const QString &filename, bool doExport, int units,
const QString &stylesheet, bool anonymize)
{
return QtConcurrent::run(export_dives_xslt, filename.toUtf8(), doExport, units, stylesheet.toUtf8(), anonymize);
}

View file

@ -17,7 +17,7 @@ void exportProfile(QString filename, bool selected_only, ExportCallback &cb);
void export_TeX(const char *filename, bool selected_only, bool plain, ExportCallback &cb);
void export_depths(const char *filename, bool selected_only);
std::vector<const dive_site *> getDiveSitesToExport(bool selectedOnly);
QFuture<int> exportUsingStyleSheet(QString filename, bool doExport, int units, QString stylesheet, bool anonymize);
QFuture<int> exportUsingStyleSheet(const QString &filename, bool doExport, int units, const QString &stylesheet, bool anonymize);
// prepareDivesForUploadDiveLog
// prepareDivesForUploadDiveShare

View file

@ -113,7 +113,7 @@ static std::vector<PictureListForDeletion> addPictures(std::vector<PictureListFo
if (!toRemove.filenames.empty())
res.push_back(toRemove);
invalidate_dive_cache(list.d);
emit diveListNotifier.picturesAdded(list.d, picsForSignal);
emit diveListNotifier.picturesAdded(list.d, std::move(picsForSignal));
}
picturesToAdd.clear();
return res;

View file

@ -530,7 +530,7 @@ void ConfigureDiveComputer::setState(ConfigureDiveComputer::states newState)
void ConfigureDiveComputer::setError(QString err)
{
lastError = err;
emit error(err);
emit error(std::move(err));
}
void ConfigureDiveComputer::readThreadFinished()

View file

@ -81,7 +81,7 @@ static int addDC(std::vector<device> &dcs, const std::string &m, const std::stri
return it - dcs.begin();
} else {
dev.deviceId = calculate_string_hash(s.c_str());
dcs.insert(it, dev);
it = dcs.insert(it, dev);
return it - dcs.begin();
}
}

View file

@ -275,7 +275,7 @@ FullTextResult FullText::find(const FullTextQuery &q, StringFilterMode mode) con
[&res2] (dive *d) { return std::find(res2.begin(), res2.end(), d) == res2.end(); }), res.end());
}
return { res };
return { std::move(res) };
}
FullTextQuery &FullTextQuery::operator=(const QString &s)

View file

@ -42,11 +42,11 @@ void ImageDownloader::saveImage(QNetworkReply *reply)
QString filename = reply->request().attribute(QNetworkRequest::User).toString();
if (reply->error() != QNetworkReply::NoError) {
emit failed(filename);
emit failed(std::move(filename));
} else {
QByteArray imageData = reply->readAll();
if (imageData.isEmpty()) {
emit failed(filename);
emit failed(std::move(filename));
} else {
QString path = QStandardPaths::standardLocations(QStandardPaths::CacheLocation).first();
QDir dir(path);
@ -63,7 +63,7 @@ void ImageDownloader::saveImage(QNetworkReply *reply)
imageFile.close();
learnPictureFilename(filename, imageFile.fileName());
}
emit loaded(filename);
emit loaded(std::move(filename));
}
}
@ -353,7 +353,7 @@ Thumbnailer::Thumbnail Thumbnailer::addUnknownThumbnailToCache(const QString &pi
void Thumbnailer::frameExtracted(QString filename, QImage thumbnail, duration_t duration, duration_t offset)
{
if (thumbnail.isNull()) {
frameExtractionFailed(filename, duration);
frameExtractionFailed(std::move(filename), duration);
return;
} else {
int size = maxThumbnailSize();

View file

@ -8,7 +8,7 @@
// Find the coordinates at the time specified in coords.start_dive
// by searching the gpx file "fileName". Here is a typical trkpt element in GPX:
// <trkpt lat="-26.84" lon="32.88"><ele>-53.7</ele><time>2017-08-06T04:56:42Z</time></trkpt>
int getCoordsFromGPXFile(struct dive_coords *coords, QString fileName)
int getCoordsFromGPXFile(struct dive_coords *coords, const QString &fileName)
{
struct tm tm1;
time_t trkpt_time = 0;

View file

@ -15,6 +15,6 @@ struct dive_coords { // This structure holds important information after
int64_t timeZone_offset; // UTC international time zone offset of dive site
};
int getCoordsFromGPXFile(dive_coords *coords, QString fileName);
int getCoordsFromGPXFile(dive_coords *coords, const QString &fileName);
#endif

View file

@ -777,8 +777,8 @@ int parseDurationToSeconds(const QString &text)
seconds = numOnly.right(numOnly.length() - minutes.length() - 1);
}
} else {
hours = "0";
minutes = numOnly;
hours = QStringLiteral("0");
minutes = std::move(numOnly);
}
secs = lrint(hours.toDouble() * 3600 + minutes.toDouble() * 60 + seconds.toDouble());
return secs;

View file

@ -112,7 +112,7 @@ void VideoFrameExtractor::processItem(QString originalFilename, QString filename
return fail(originalFilename, duration, true);
}
emit extracted(originalFilename, img, duration, position);
emit extracted(originalFilename, std::move(img), duration, position);
QMutexLocker l(&lock);
workingOn.remove(originalFilename);
}

View file

@ -938,11 +938,12 @@ int DiveListView::lastImageTimeOffset()
return offset;
}
void DiveListView::updateLastImageTimeOffset(const int offset)
void DiveListView::updateLastImageTimeOffset(timestamp_t offset)
{
QSettings s;
s.beginGroup("MainWindow");
s.setValue("LastImageTimeOffset", offset);
// Can't create a QVariant from int64_t, for whatever reason.
s.setValue("LastImageTimeOffset", static_cast<long long>(offset));
}
void DiveListView::mouseDoubleClickEvent(QMouseEvent*)

View file

@ -73,7 +73,7 @@ private:
void restoreExpandedRows(const std::vector<int> &);
int lastVisibleColumn();
void selectTrip(dive_trip *trip);
void updateLastImageTimeOffset(int offset);
void updateLastImageTimeOffset(timestamp_t offset);
int lastImageTimeOffset();
void addToTrip(int delta);
void matchImagesToDives(const QStringList &fileNames);

View file

@ -326,7 +326,7 @@ void ColumnNameResult::setColumnValues(QList<QStringList> columns)
endInsertColumns();
beginInsertRows(QModelIndex(), 0, columns.count()-1);
columnValues = columns;
columnValues = std::move(columns);
endInsertRows();
}
@ -799,10 +799,11 @@ void DiveLogImportDialog::loadFileContents(int value, whatChanged triggeredBy)
}
if (rows > 0)
resultModel->setColumnValues(fileColumns);
for (int i = 0; i < headers.count(); i++)
resultModel->setColumnValues(std::move(fileColumns));
for (int i = 0; i < headers.count(); i++) {
if (!headers.at(i).isEmpty())
resultModel->setData(resultModel->index(0, i),headers.at(i),Qt::EditRole);
}
}
void DiveLogImportDialog::setup_csv_params(QStringList r, xml_params &params)

View file

@ -13,7 +13,7 @@
// Caller keeps ownership of "imported". The contents of "imported" will be consumed on execution of the dialog.
// On return, it will be empty.
DivesiteImportDialog::DivesiteImportDialog(struct dive_site_table &imported, QString source, QWidget *parent) : QDialog(parent),
importedSource(source)
importedSource(std::move(source))
{
QShortcut *close = new QShortcut(QKeySequence(Qt::CTRL | Qt::Key_W), this);
QShortcut *quit = new QShortcut(QKeySequence(Qt::CTRL | Qt::Key_Q), this);

View file

@ -1354,9 +1354,8 @@ void MainWindow::on_actionImportDiveLog_triggered()
logFiles.append(fn);
}
if (logFiles.size()) {
if (logFiles.size())
importFiles(logFiles);
}
if (csvFiles.size()) {
DiveLogImportDialog diveLogImport(std::move(csvFiles), this);
@ -1553,9 +1552,8 @@ void MainWindow::hideProgressBar()
}
}
void MainWindow::divesChanged(const QVector<dive *> &dives, DiveField field)
void MainWindow::divesChanged(const QVector<dive *> &dives, DiveField)
{
Q_UNUSED(field)
for (struct dive *d: dives) {
qDebug() << "dive #" << d->number << "changed, cache is" << (dive_cache_is_valid(d) ? "valid" : "invalidated");
// a brute force way to deal with that would of course be to call

View file

@ -155,7 +155,7 @@ void TabDiveInformation::updateProfile()
ui->diveTimeText->setText(get_dive_duration_string(currentDive->duration.seconds, tr("h"), tr("min"), tr("sec"),
" ", currentDive->dc.divemode == FREEDIVE));
ui->sacText->setText(currentDive->cylinders.nr > 0 && mean[0] && currentDive->dc.divemode != CCR ? SACs : QString());
ui->sacText->setText(currentDive->cylinders.nr > 0 && mean[0] && currentDive->dc.divemode != CCR ? std::move(SACs) : QString());
if (currentDive->surface_pressure.mbar == 0) {
ui->atmPressVal->clear(); // If no atm pressure for dive then clear text box

View file

@ -404,7 +404,7 @@ void TabDiveNotes::on_notes_editingFinished()
return;
QString html = ui.notes->toHtml();
QString notes = isHtml(html) ? html : ui.notes->toPlainText();
QString notes = isHtml(html) ? std::move(html) : ui.notes->toPlainText();
if (currentTrip)
Command::editTripNotes(currentTrip, notes);

View file

@ -15,6 +15,7 @@
CylindersModel::CylindersModel(bool planner, QObject *parent) : CleanerTableModel(parent),
d(nullptr),
dcNr(-1),
inPlanner(planner),
numRows(0),
tempRow(-1),

View file

@ -281,7 +281,7 @@ void DivePictureModel::updateThumbnail(QString filename, QImage thumbnail, durat
addDurationToThumbnail(thumbnail, duration); // If we know the duration paint it on top of the thumbnail
pictures[i].length = duration;
}
pictures[i].image = thumbnail;
pictures[i].image = std::move(thumbnail);
emit dataChanged(createIndex(i, 0), createIndex(i, 1));
}
}
@ -295,7 +295,7 @@ void DivePictureModel::pictureOffsetChanged(dive *d, const QString filenameIn, o
auto to = std::find_if(from, pictures.end(), [d](const PictureEntry &e) { return e.d != d; });
// Find picture with the given filename
auto oldPos = std::find_if(from, to, [filename](const PictureEntry &e) { return e.filename == filename; });
auto oldPos = std::find_if(from, to, [&filename](const PictureEntry &e) { return e.filename == filename; });
if (oldPos == to)
return;

View file

@ -1312,7 +1312,7 @@ void DivePlannerPointsModel::createPlan(bool replanCopy)
disclaimerBegin = disclaimer.left(disclaimerMid);
disclaimerEnd = disclaimer.mid(disclaimerMid + 2);
} else {
disclaimerBegin = disclaimer;
disclaimerBegin = std::move(disclaimer);
}
int disclaimerPositionStart = oldnotes.indexOf(disclaimerBegin);
if (disclaimerPositionStart >= 0) {

View file

@ -1386,7 +1386,7 @@ void DiveTripModelTree::divesSelectedSlot(const QVector<dive *> &divesIn, dive *
QVector<QModelIndex> indices;
indices.reserve(dives.count());
processByTrip(dives, [this, &indices] (dive_trip *trip, const QVector<dive *> &divesInTrip)
processByTrip(std::move(dives), [this, &indices] (dive_trip *trip, const QVector<dive *> &divesInTrip)
{ divesSelectedTrip(trip, divesInTrip, indices); });
emit divesSelected(indices, diveToIdx(currentDive), currentDC);

View file

@ -22,14 +22,12 @@ static QString siteMapDisplayName(const char *sitename)
const char Separator = '/';
QString fullname(sitename);
if (!qPrefDisplay::map_short_names() ) {
if (!qPrefDisplay::map_short_names() )
return fullname;
}
QString name = fullname.section(Separator, -1).trimmed();
if (name.isEmpty()) {
name = fullname;
}
if (name.isEmpty())
name = std::move(fullname);
return name;
}

View file

@ -279,7 +279,7 @@ void ValueAxis::updateLabels()
{
QLocale loc;
auto [minString, maxString] = getFirstLastLabel();
int numTicks = guessNumTicks({ minString, maxString});
int numTicks = guessNumTicks({ std::move(minString), std::move(maxString)});
// Use full decimal increments
double height = max - min;

View file

@ -537,8 +537,9 @@ void StatsState::featureChanged(int id, bool state)
// Creates the new chart-type from the current chart-type and a list of possible chart types.
// If the flag "varChanged" is true, the current chart-type will be changed if the
// current chart-type is undesired.
const ChartTypeDesc &newChartType(ChartType type, std::vector<std::pair<const ChartTypeDesc &, bool>> charts,
bool varChanged)
static const ChartTypeDesc &newChartType(ChartType type,
const std::vector<std::pair<const ChartTypeDesc &, bool>> &charts,
bool varChanged)
{
for (auto [desc, warn]: charts) {
// Found it, but if the axis was changed, we change anyway if the chart is "undesired"

View file

@ -329,14 +329,14 @@ QString StatsVariable::nameWithUnit() const
{
QString s = name();
QString symb = unitSymbol();
return symb.isEmpty() ? s : QStringLiteral("%1 [%2]").arg(s, symb);
return symb.isEmpty() ? std::move(s) : QStringLiteral("%1 [%2]").arg(s, symb);
}
QString StatsVariable::nameWithBinnerUnit(const StatsBinner &binner) const
{
QString s = name();
QString symb = binner.unitSymbol();
return symb.isEmpty() ? s : QStringLiteral("%1 [%2]").arg(s, symb);
return symb.isEmpty() ? std::move(s) : QStringLiteral("%1 [%2]").arg(s, symb);
}
const StatsBinner *StatsVariable::getBinner(int idx) const
@ -551,7 +551,7 @@ std::vector<StatsBinValue<T>> bin_convert(const StatsVariable &variable, const S
T v = func(dives);
if (is_invalid_value(v) && (res.empty() || !fill_empty))
continue;
res.push_back({ std::move(bin), v });
res.push_back({ std::move(bin), std::move(v) });
}
if (res.empty())
return res;

View file

@ -892,7 +892,7 @@ void StatsView::plotValueChart(const std::vector<dive *> &dives,
if (res.isValid()) {
double height = res.get(valueAxisOperation);
QString value = QString("%L1").arg(height, 0, 'f', decimals);
std::vector<QString> label = std::vector<QString> { value };
std::vector<QString> label = std::vector<QString> { std::move(value) };
items.push_back({ pos - 0.5, pos + 0.5, height, label,
categoryBinner->formatWithUnit(*bin), res });
}
@ -1080,7 +1080,7 @@ HistogramAxis *StatsView::createHistogramAxis(const QString &name, const StatsBi
QString label = binner.formatLowerBound(*bin);
double lowerBound = binner.lowerBoundToFloat(*bin);
bool prefer = binner.preferBin(*bin);
labels.push_back({ label, lowerBound, prefer });
labels.push_back({ std::move(label), lowerBound, prefer });
}
const StatsBin &lastBin = *bins.back().bin;
@ -1129,7 +1129,7 @@ void StatsView::plotHistogramCountChart(const std::vector<dive *> &dives,
double upperBound = categoryBinner->upperBoundToFloat(*bin);
std::vector<QString> label = makePercentageLabels((int)dives.size(), total, isHorizontal);
items.push_back({ lowerBound, upperBound, std::move(dives), label,
items.push_back({ lowerBound, upperBound, std::move(dives), std::move(label),
categoryBinner->formatWithUnit(*bin), total });
}