From f75966aadcd660fb209a913001d59342c02b8ecf Mon Sep 17 00:00:00 2001 From: Martchus Date: Sat, 20 Mar 2021 22:39:40 +0100 Subject: [PATCH] Fix warnings --- CMakeLists.txt | 2 +- cli/application.cpp | 10 +++++----- cli/helper.h | 2 +- cli/tests/application.cpp | 2 +- connector/syncthingcompletion.h | 2 +- connector/syncthingconnection.h | 4 ++-- connector/syncthingconnection_requests.cpp | 22 +++++++++++----------- connector/utils.h | 2 +- model/syncthingdevicemodel.cpp | 1 + model/syncthingdirectorymodel.cpp | 2 -- model/syncthingicons.cpp | 2 +- tray/gui/traywidget.cpp | 6 +++--- widgets/misc/direrrorsdialog.cpp | 6 +++--- widgets/misc/statusinfo.cpp | 10 +++++----- widgets/settings/settingsdialog.cpp | 4 ++-- 15 files changed, 38 insertions(+), 39 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6f02c07..bb94a02 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,7 +11,7 @@ set(META_APP_CATEGORIES "Network;FileTransfer") set(META_GUI_OPTIONAL false) set(META_VERSION_MAJOR 1) set(META_VERSION_MINOR 1) -set(META_VERSION_PATCH 3) +set(META_VERSION_PATCH 4) set(META_VERSION_EXACT_SONAME ON) set(META_ADD_DEFAULT_CPP_UNIT_TEST_APPLICATION ON) diff --git a/cli/application.cpp b/cli/application.cpp index e3f21ea..18a91cd 100644 --- a/cli/application.cpp +++ b/cli/application.cpp @@ -47,7 +47,7 @@ static int statusCode = 0; void exitApplication(int statusCode) { - statusCode = ::Cli::statusCode; + ::Cli::statusCode = statusCode; terminated = true; } @@ -825,13 +825,13 @@ QByteArray Application::editConfigViaScript() const } } else if (m_args.jsLines.isPresent()) { // construct script from CLI arguments - int requiredSize = 0; - for (const auto *line : m_args.jsLines.values()) { - requiredSize += strlen(line); + auto requiredSize = QString::size_type(0); + for (const auto *const line : m_args.jsLines.values()) { + requiredSize += static_cast(std::strlen(line)); requiredSize += 1; } script.reserve(requiredSize); - for (const auto *line : m_args.jsLines.values()) { + for (const auto *const line : m_args.jsLines.values()) { script += line; script += '\n'; } diff --git a/cli/helper.h b/cli/helper.h index 06ea53f..d25421d 100644 --- a/cli/helper.h +++ b/cli/helper.h @@ -18,7 +18,7 @@ namespace Cli { inline void printProperty(const char *propName, const char *value, const char *suffix = nullptr, CppUtilities::Indentation indentation = 3) { if (*value) { - std::cout << indentation << propName << CppUtilities::Indentation(30 - strlen(propName)) << value; + std::cout << indentation << propName << CppUtilities::Indentation(static_cast(30 - strlen(propName))) << value; if (suffix) { std::cout << ' ' << suffix; } diff --git a/cli/tests/application.cpp b/cli/tests/application.cpp index 4f7be4d..dc89397 100644 --- a/cli/tests/application.cpp +++ b/cli/tests/application.cpp @@ -184,7 +184,7 @@ void ApplicationTests::test() TESTUTILS_ASSERT_EXEC(catArgs); cout << stdout; QJsonParseError error; - const auto doc(QJsonDocument::fromJson(QByteArray(stdout.data(), stdout.size()), &error)); + const auto doc(QJsonDocument::fromJson(QByteArray(stdout.data(), static_cast(stdout.size())), &error)); CPPUNIT_ASSERT_EQUAL(QJsonParseError::NoError, error.error); const auto object(doc.object()); CPPUNIT_ASSERT(object.value(QLatin1String("options")).isObject()); diff --git a/connector/syncthingcompletion.h b/connector/syncthingcompletion.h index 87c7fbb..d0deb1f 100644 --- a/connector/syncthingcompletion.h +++ b/connector/syncthingcompletion.h @@ -77,7 +77,7 @@ constexpr SyncthingCompletion &SyncthingCompletion::operator-=(const SyncthingCo inline void SyncthingCompletion::recomputePercentage() { - percentage = (static_cast(globalBytes - needed.bytes) / globalBytes) * 100.0; + percentage = (static_cast(globalBytes - needed.bytes) / static_cast(globalBytes)) * 100.0; } } // namespace Data diff --git a/connector/syncthingconnection.h b/connector/syncthingconnection.h index e2f84ae..f73f764 100644 --- a/connector/syncthingconnection.h +++ b/connector/syncthingconnection.h @@ -73,8 +73,8 @@ class LIB_SYNCTHING_CONNECTOR_EXPORT SyncthingConnection : public QObject { Q_PROPERTY(bool recordFileChanges READ recordFileChanges WRITE setRecordFileChanges) Q_PROPERTY(QString myId READ myId NOTIFY myIdChanged) Q_PROPERTY(QString configDir READ configDir NOTIFY configDirChanged) - Q_PROPERTY(int totalIncomingTraffic READ totalIncomingTraffic NOTIFY trafficChanged) - Q_PROPERTY(int totalOutgoingTraffic READ totalOutgoingTraffic NOTIFY trafficChanged) + Q_PROPERTY(quint64 totalIncomingTraffic READ totalIncomingTraffic NOTIFY trafficChanged) + Q_PROPERTY(quint64 totalOutgoingTraffic READ totalOutgoingTraffic NOTIFY trafficChanged) Q_PROPERTY(double totalIncomingRate READ totalIncomingRate NOTIFY trafficChanged) Q_PROPERTY(double totalOutgoingRate READ totalOutgoingRate NOTIFY trafficChanged) Q_PROPERTY(QString lastSyncedFile READ lastSyncedFile) diff --git a/connector/syncthingconnection_requests.cpp b/connector/syncthingconnection_requests.cpp index 37b43b6..434cf76 100644 --- a/connector/syncthingconnection_requests.cpp +++ b/connector/syncthingconnection_requests.cpp @@ -580,8 +580,8 @@ void SyncthingConnection::readDirs(const QJsonArray &dirs) dirItem->path = dirObj.value(QLatin1String("path")).toString(); dirItem->deviceIds.clear(); dirItem->deviceNames.clear(); - for (const QJsonValueRef dev : dirObj.value(QLatin1String("devices")).toArray()) { - const QString devId = dev.toObject().value(QLatin1String("deviceID")).toString(); + for (const QJsonValueRef devObj : dirObj.value(QLatin1String("devices")).toArray()) { + const QString devId = devObj.toObject().value(QLatin1String("deviceID")).toString(); if (devId.isEmpty() || devId == m_myId) { continue; } @@ -753,10 +753,10 @@ void SyncthingConnection::readConnections() const bool hasDelta = !m_lastConnectionsUpdate.isNull() && ((transferTime = (DateTime::gmtNow() - m_lastConnectionsUpdate).totalSeconds()) != 0.0); m_totalIncomingRate = (hasDelta && totalIncomingTraffic != unknownTraffic && m_totalIncomingTraffic != unknownTraffic) - ? (totalIncomingTraffic - m_totalIncomingTraffic) * 0.008 / transferTime + ? static_cast(totalIncomingTraffic - m_totalIncomingTraffic) * 0.008 / transferTime : 0.0; m_totalOutgoingRate = (hasDelta && totalOutgoingTraffic != unknownTraffic && m_totalOutgoingTraffic != unknownTraffic) - ? (totalOutgoingTraffic - m_totalOutgoingTraffic) * 0.008 / transferTime + ? static_cast(totalOutgoingTraffic - m_totalOutgoingTraffic) * 0.008 / transferTime : 0.0; emit trafficChanged(m_totalIncomingTraffic = totalIncomingTraffic, m_totalOutgoingTraffic = totalOutgoingTraffic); @@ -1990,10 +1990,10 @@ void SyncthingConnection::readLocalFolderCompletion(DateTime eventTime, const QJ const auto previouslyNeeded(neededStats); const auto previouslyGlobal(globalStats); // read values from event data - globalStats.bytes = jsonValueToInt(eventData.value(QLatin1String("globalBytes")), globalStats.bytes); - neededStats.bytes = jsonValueToInt(eventData.value(QLatin1String("needBytes")), neededStats.bytes); - neededStats.deletes = jsonValueToInt(eventData.value(QLatin1String("needDeletes")), neededStats.deletes); - neededStats.deletes = jsonValueToInt(eventData.value(QLatin1String("needItems")), neededStats.files); + globalStats.bytes = jsonValueToInt(eventData.value(QLatin1String("globalBytes")), static_cast(globalStats.bytes)); + neededStats.bytes = jsonValueToInt(eventData.value(QLatin1String("needBytes")), static_cast(neededStats.bytes)); + neededStats.deletes = jsonValueToInt(eventData.value(QLatin1String("needDeletes")), static_cast(neededStats.deletes)); + neededStats.deletes = jsonValueToInt(eventData.value(QLatin1String("needItems")), static_cast(neededStats.files)); dirInfo.lastStatisticsUpdate = eventTime; dirInfo.completionPercentage = globalStats.bytes ? static_cast((globalStats.bytes - neededStats.bytes) * 100 / globalStats.bytes) : 100; emit dirStatusChanged(dirInfo, index); @@ -2015,9 +2015,9 @@ void SyncthingConnection::readRemoteFolderCompletion(DateTime eventTime, const Q completion.lastUpdate = eventTime; completion.percentage = eventData.value(QLatin1String("completion")).toDouble(); completion.globalBytes = jsonValueToInt(eventData.value(QLatin1String("globalBytes"))); - needed.bytes = jsonValueToInt(eventData.value(QLatin1String("needBytes")), needed.bytes); - needed.items = jsonValueToInt(eventData.value(QLatin1String("needItems")), needed.items); - needed.deletes = jsonValueToInt(eventData.value(QLatin1String("needDeletes")), needed.deletes); + needed.bytes = jsonValueToInt(eventData.value(QLatin1String("needBytes")), static_cast(needed.bytes)); + needed.items = jsonValueToInt(eventData.value(QLatin1String("needItems")), static_cast(needed.items)); + needed.deletes = jsonValueToInt(eventData.value(QLatin1String("needDeletes")), static_cast(needed.deletes)); // update dir info if (dirInfo) { diff --git a/connector/utils.h b/connector/utils.h index ce06751..2388dc9 100644 --- a/connector/utils.h +++ b/connector/utils.h @@ -60,7 +60,7 @@ constexpr LIB_SYNCTHING_CONNECTOR_EXPORT int trQuandity(quint64 quandity) template LIB_SYNCTHING_CONNECTOR_EXPORT QStringList things(const Objects &objects, Accessor accessor) { QStringList things; - things.reserve(objects.size()); + things.reserve(static_cast(objects.size())); for (const auto &object : objects) { things << accessor(object); } diff --git a/model/syncthingdevicemodel.cpp b/model/syncthingdevicemodel.cpp index 08f7f96..4236575 100644 --- a/model/syncthingdevicemodel.cpp +++ b/model/syncthingdevicemodel.cpp @@ -248,6 +248,7 @@ QVariant SyncthingDeviceModel::data(const QModelIndex &index, int role) const case 1: return devStatusString(dev); } + break; case Qt::DecorationRole: switch (index.column()) { case 0: diff --git a/model/syncthingdirectorymodel.cpp b/model/syncthingdirectorymodel.cpp index 4610206..51de6c3 100644 --- a/model/syncthingdirectorymodel.cpp +++ b/model/syncthingdirectorymodel.cpp @@ -219,7 +219,6 @@ QVariant SyncthingDirectoryModel::data(const QModelIndex &index, int role) const case Qt::ForegroundRole: switch (index.column()) { case 1: - const SyncthingDir &dir = m_dirs[static_cast(index.parent().row())]; switch (row) { case 4: if (dir.deviceIds.isEmpty()) { @@ -242,7 +241,6 @@ QVariant SyncthingDirectoryModel::data(const QModelIndex &index, int role) const case Qt::ToolTipRole: switch (index.column()) { case 1: - const SyncthingDir &dir = m_dirs[static_cast(index.parent().row())]; switch (row) { case 3: if (dir.deviceNames.isEmpty()) { diff --git a/model/syncthingicons.cpp b/model/syncthingicons.cpp index 68ae96e..5eab967 100644 --- a/model/syncthingicons.cpp +++ b/model/syncthingicons.cpp @@ -123,7 +123,7 @@ template QPixmap renderSvgImage(const SourceType &source, #endif qGuiApp->devicePixelRatio(); QSvgRenderer renderer(source); - QSize scaledSize(givenSize.width() * scaleFactor, givenSize.height() * scaleFactor); + QSize scaledSize(static_cast(givenSize.width() * scaleFactor), static_cast(givenSize.height() * scaleFactor)); QSize renderSize(renderer.defaultSize()); renderSize.scale(scaledSize.width() - margin, scaledSize.height() - margin, Qt::KeepAspectRatio); QRect renderBounds(QPoint(), scaledSize); diff --git a/tray/gui/traywidget.cpp b/tray/gui/traywidget.cpp index 9b3fa16..2160fd7 100644 --- a/tray/gui/traywidget.cpp +++ b/tray/gui/traywidget.cpp @@ -582,9 +582,9 @@ void TrayWidget::showRecentChangesContextMenu(const QPoint &position) } const auto copyRole = [this](SyncthingRecentChangesModel::SyncthingRecentChangesModelRole role) { return [this, role] { - const auto *const selectionModel = m_ui->recentChangesTreeView->selectionModel(); - if (selectionModel && selectionModel->selectedRows().size() == 1) { - QGuiApplication::clipboard()->setText(m_recentChangesModel.data(selectionModel->selectedRows().at(0), role).toString()); + const auto *const selectionModelToCopy = m_ui->recentChangesTreeView->selectionModel(); + if (selectionModelToCopy && selectionModelToCopy->selectedRows().size() == 1) { + QGuiApplication::clipboard()->setText(m_recentChangesModel.data(selectionModelToCopy->selectedRows().at(0), role).toString()); } }; }; diff --git a/widgets/misc/direrrorsdialog.cpp b/widgets/misc/direrrorsdialog.cpp index d058af3..757aa3f 100644 --- a/widgets/misc/direrrorsdialog.cpp +++ b/widgets/misc/direrrorsdialog.cpp @@ -118,9 +118,9 @@ void DirectoryErrorsDialog::removeNonEmptyDirs() } QStringList removedDirs, failedDirs; for (const QString &dirPath : m_nonEmptyDirs) { - bool ok = false; - QDir dir(dirPath); - if (!dir.exists() || !dir.removeRecursively()) { + auto ok = false; + auto dirObj = QDir(dirPath); + if (!dirObj.exists() || !dirObj.removeRecursively()) { // check whether dir has already been removed by removing its parent for (const QString &removedDir : removedDirs) { if (dirPath.startsWith(removedDir)) { diff --git a/widgets/misc/statusinfo.cpp b/widgets/misc/statusinfo.cpp index 0c34599..e561448 100644 --- a/widgets/misc/statusinfo.cpp +++ b/widgets/misc/statusinfo.cpp @@ -120,18 +120,18 @@ void StatusInfo::updateConnectedDevices(const SyncthingConnection &connection) // get up to 2 device names const auto deviceCount = trQuandity(connectedDevices.size()); const auto deviceNames = [&] { - QStringList deviceNames; - deviceNames.reserve(2); + QStringList names; + names.reserve(2); for (const auto *dev : connectedDevices) { if (dev->name.isEmpty()) { continue; } - deviceNames << dev->name; - if (deviceNames.size() > 2) { + names << dev->name; + if (names.size() > 2) { break; } } - return deviceNames; + return names; }(); // update status text diff --git a/widgets/settings/settingsdialog.cpp b/widgets/settings/settingsdialog.cpp index 54b6884..79bcf37 100644 --- a/widgets/settings/settingsdialog.cpp +++ b/widgets/settings/settingsdialog.cpp @@ -911,9 +911,9 @@ QWidget *LauncherOptionPage::setupWidget() } // hide libsyncthing-controls by default (as the checkbox is unchecked by default) - for (auto *const widget : std::initializer_list{ ui()->configDirLabel, ui()->configDirPathSelection, ui()->dataDirLabel, + for (auto *const lstWidget : std::initializer_list{ ui()->configDirLabel, ui()->configDirPathSelection, ui()->dataDirLabel, ui()->dataDirPathSelection, ui()->logLevelLabel, ui()->logLevelComboBox }) { - widget->setVisible(false); + lstWidget->setVisible(false); } // add "restore to defaults" action for Syncthing arguments