diff --git a/plugin/src/Caelestia/Internal/cachingimagemanager.cpp b/plugin/src/Caelestia/Internal/cachingimagemanager.cpp index 1c15cd20..9f63f99a 100644 --- a/plugin/src/Caelestia/Internal/cachingimagemanager.cpp +++ b/plugin/src/Caelestia/Internal/cachingimagemanager.cpp @@ -105,34 +105,26 @@ void CachingImageManager::updateSource(const QString& path) { m_shaPath = path; - const auto future = QtConcurrent::run(&CachingImageManager::sha256sum, path); - - const auto watcher = new QFutureWatcher(this); - - connect(watcher, &QFutureWatcher::finished, this, [watcher, path, this]() { + QtConcurrent::run(&CachingImageManager::sha256sum, path).then(this, [path, this](const QString& sha) { if (m_path != path) { - // Object is destroyed or path has changed, ignore - watcher->deleteLater(); return; } const QSize size = effectiveSize(); if (!m_item || !size.width() || !size.height()) { - watcher->deleteLater(); return; } const QString fillMode = m_item->property("fillMode").toString(); // clang-format off const QString filename = QString("%1@%2x%3-%4.png") - .arg(watcher->result()).arg(size.width()).arg(size.height()) + .arg(sha).arg(size.width()).arg(size.height()) .arg(fillMode == "PreserveAspectCrop" ? "crop" : fillMode == "PreserveAspectFit" ? "fit" : "stretch"); // clang-format on const QUrl cache = m_cacheDir.resolved(QUrl(filename)); if (m_cachePath == cache) { - watcher->deleteLater(); return; } @@ -141,7 +133,6 @@ void CachingImageManager::updateSource(const QString& path) { if (!cache.isLocalFile()) { qWarning() << "CachingImageManager::updateSource: cachePath" << cache << "is not a local file"; - watcher->deleteLater(); return; } @@ -157,11 +148,7 @@ void CachingImageManager::updateSource(const QString& path) { if (m_shaPath == path) { m_shaPath = QString(); } - - watcher->deleteLater(); }); - - watcher->setFuture(future); } QUrl CachingImageManager::cachePath() const { diff --git a/plugin/src/Caelestia/Models/filesystemmodel.cpp b/plugin/src/Caelestia/Models/filesystemmodel.cpp index 4eb94cd4..267a4394 100644 --- a/plugin/src/Caelestia/Models/filesystemmodel.cpp +++ b/plugin/src/Caelestia/Models/filesystemmodel.cpp @@ -219,7 +219,7 @@ void FileSystemModel::watchDirIfRecursive(const QString& path) { if (m_recursive && m_watchChanges) { const auto currentDir = m_dir; const bool showHidden = m_showHidden; - const auto future = QtConcurrent::run([showHidden, path]() { + auto future = QtConcurrent::run([showHidden, path]() { QDir::Filters filters = QDir::Dirs | QDir::NoDotAndDotDot; if (showHidden) { filters |= QDir::Hidden; @@ -232,16 +232,12 @@ void FileSystemModel::watchDirIfRecursive(const QString& path) { } return dirs; }); - const auto watcher = new QFutureWatcher(this); - connect(watcher, &QFutureWatcher::finished, this, [currentDir, showHidden, watcher, this]() { - const auto paths = watcher->result(); + future.then(this, [currentDir, showHidden, this](const QStringList& paths) { if (currentDir == m_dir && showHidden == m_showHidden && !paths.isEmpty()) { // Ignore if dir or showHidden has changed m_watcher.addPaths(paths); } - watcher->deleteLater(); }); - watcher->setFuture(future); } } @@ -295,7 +291,7 @@ void FileSystemModel::updateEntriesForDir(const QString& dir) { oldPaths << entry->path(); } - const auto future = QtConcurrent::run([=](QPromise, QSet>>& promise) { + auto future = QtConcurrent::run([=](QPromise, QSet>>& promise) { const auto flags = recursive ? QDirIterator::Subdirectories : QDirIterator::NoIteratorFlags; std::optional iter; @@ -353,7 +349,7 @@ void FileSystemModel::updateEntriesForDir(const QString& dir) { newPaths.insert(path); } - if (promise.isCanceled() || newPaths == oldPaths) { + if (promise.isCanceled()) { return; } @@ -365,23 +361,17 @@ void FileSystemModel::updateEntriesForDir(const QString& dir) { } m_futures.insert(dir, future); - const auto watcher = new QFutureWatcher, QSet>>(this); - - connect(watcher, &QFutureWatcher, QSet>>::finished, this, [dir, watcher, this]() { - m_futures.remove(dir); - - if (!watcher->future().isResultReadyAt(0)) { - watcher->deleteLater(); - return; - } - - const auto result = watcher->result(); - applyChanges(result.first, result.second); - - watcher->deleteLater(); - }); - - watcher->setFuture(future); + future + .then(this, + [dir, this](QPair, QSet> result) { + m_futures.remove(dir); + if (!result.first.isEmpty() || !result.second.isEmpty()) { + applyChanges(result.first, result.second); + } + }) + .onCanceled(this, [dir, this]() { + m_futures.remove(dir); + }); } void FileSystemModel::applyChanges(const QSet& removedPaths, const QSet& addedPaths) { diff --git a/plugin/src/Caelestia/Services/audiocollector.cpp b/plugin/src/Caelestia/Services/audiocollector.cpp index 15634059..fb051ccb 100644 --- a/plugin/src/Caelestia/Services/audiocollector.cpp +++ b/plugin/src/Caelestia/Services/audiocollector.cpp @@ -221,7 +221,7 @@ AudioCollector::AudioCollector(QObject* parent) , m_writeBuffer(&m_buffer2) {} AudioCollector::~AudioCollector() { - stop(); + AudioCollector::stop(); } void AudioCollector::start() { diff --git a/plugin/src/Caelestia/appdb.cpp b/plugin/src/Caelestia/appdb.cpp index 5dc4d724..1e33990d 100644 --- a/plugin/src/Caelestia/appdb.cpp +++ b/plugin/src/Caelestia/appdb.cpp @@ -11,7 +11,7 @@ AppEntry::AppEntry(QObject* entry, unsigned int frequency, QObject* parent) , m_entry(entry) , m_frequency(frequency) { const auto mo = m_entry->metaObject(); - const auto tmo = metaObject(); + const auto tmo = &AppEntry::staticMetaObject; for (const auto& prop : { "name", "comment", "execString", "startupClass", "genericName", "categories", "keywords" }) { diff --git a/plugin/src/Caelestia/qalculator.cpp b/plugin/src/Caelestia/qalculator.cpp index bfc977e8..c7242179 100644 --- a/plugin/src/Caelestia/qalculator.cpp +++ b/plugin/src/Caelestia/qalculator.cpp @@ -1,7 +1,6 @@ #include "qalculator.hpp" #include -#include #include namespace caelestia { @@ -11,7 +10,10 @@ QMutex Qalculator::s_calculatorMutex; Qalculator::Qalculator(QObject* parent) : QObject(parent) { if (!CALCULATOR) { - new Calculator(); + // Calculator constructor sets the global `calculator` pointer (CALCULATOR macro), + // but we need to assign it to a var so compiler doesn't flag it as a leak + static const auto* const instance = new Calculator(); + Q_UNUSED(instance) CALCULATOR->loadExchangeRates(); CALCULATOR->loadGlobalDefinitions(); CALCULATOR->loadLocalDefinitions(); @@ -79,7 +81,7 @@ void Qalculator::evalAsync(const QString& expr) { emit busyChanged(); } - const auto future = QtConcurrent::run([expr]() -> QPair { + QtConcurrent::run([expr]() -> QPair { QMutexLocker locker(&s_calculatorMutex); EvaluationOptions eo; @@ -109,18 +111,12 @@ void Qalculator::evalAsync(const QString& expr) { const QString rawStr = QString::fromStdString(result); return { QString("%1 = %2").arg(parsed).arg(result), rawStr }; - }); - - auto* watcher = new QFutureWatcher>(this); - - connect(watcher, &QFutureWatcher>::finished, this, [this, watcher, gen]() { - watcher->deleteLater(); - + }).then(this, [this, gen](QPair result) { if (gen != m_generation) { return; } - const auto [formatted, raw] = watcher->result(); + const auto& [formatted, raw] = result; if (m_result != formatted) { m_result = formatted; @@ -135,8 +131,6 @@ void Qalculator::evalAsync(const QString& expr) { emit busyChanged(); } }); - - watcher->setFuture(future); } QString Qalculator::result() const {