diff options
| author | 2 * r + 2 * t <61896496+soramanew@users.noreply.github.com> | 2025-09-01 15:31:27 +1000 |
|---|---|---|
| committer | 2 * r + 2 * t <61896496+soramanew@users.noreply.github.com> | 2025-09-01 15:31:27 +1000 |
| commit | d76c799dd22a44621b557564ed9606e04ba40e34 (patch) | |
| tree | ea9dc55c4ef52a94e34f818003727b4170b9103b /plugin/src/Caelestia | |
| parent | cmake: more compiler warnings (diff) | |
| download | caelestia-shell-d76c799dd22a44621b557564ed9606e04ba40e34.tar.gz caelestia-shell-d76c799dd22a44621b557564ed9606e04ba40e34.tar.bz2 caelestia-shell-d76c799dd22a44621b557564ed9606e04ba40e34.zip | |
plugin: fix warnings + const stuff
Diffstat (limited to 'plugin/src/Caelestia')
| -rw-r--r-- | plugin/src/Caelestia/cachingimagemanager.cpp | 12 | ||||
| -rw-r--r-- | plugin/src/Caelestia/cachingimagemanager.hpp | 14 | ||||
| -rw-r--r-- | plugin/src/Caelestia/cutils.cpp | 60 | ||||
| -rw-r--r-- | plugin/src/Caelestia/cutils.hpp | 6 | ||||
| -rw-r--r-- | plugin/src/Caelestia/filesystemmodel.cpp | 2 | ||||
| -rw-r--r-- | plugin/src/Caelestia/filesystemmodel.hpp | 30 |
6 files changed, 62 insertions, 62 deletions
diff --git a/plugin/src/Caelestia/cachingimagemanager.cpp b/plugin/src/Caelestia/cachingimagemanager.cpp index 63826ea..4f37171 100644 --- a/plugin/src/Caelestia/cachingimagemanager.cpp +++ b/plugin/src/Caelestia/cachingimagemanager.cpp @@ -23,7 +23,7 @@ int CachingImageManager::effectiveWidth() const { return 0; } - int width = std::ceil(m_item->width() * effectiveScale()); + int width = static_cast<int>(std::ceil(m_item->width() * effectiveScale())); m_item->setProperty("sourceWidth", width); return width; } @@ -33,7 +33,7 @@ int CachingImageManager::effectiveHeight() const { return 0; } - int height = std::ceil(m_item->height() * effectiveScale()); + int height = static_cast<int>(std::ceil(m_item->height() * effectiveScale())); m_item->setProperty("sourceHeight", height); return height; } @@ -109,7 +109,7 @@ void CachingImageManager::updateSource(const QString& path) { m_shaPath = path; - QPointer<CachingImageManager> self(this); + const QPointer<CachingImageManager> self(this); QThreadPool::globalInstance()->start([path, self] { const QString sha = self->sha256sum(path); @@ -119,8 +119,8 @@ void CachingImageManager::updateSource(const QString& path) { return; } - int width = self->effectiveWidth(); - int height = self->effectiveHeight(); + const int width = self->effectiveWidth(); + const int height = self->effectiveHeight(); if (!self->m_item || !width || !height) { return; @@ -144,7 +144,7 @@ void CachingImageManager::updateSource(const QString& path) { return; } - QImageReader reader(cache.toLocalFile()); + const QImageReader reader(cache.toLocalFile()); if (reader.canRead()) { self->m_item->setProperty("source", cache); } else { diff --git a/plugin/src/Caelestia/cachingimagemanager.hpp b/plugin/src/Caelestia/cachingimagemanager.hpp index ddb14d0..5c758dc 100644 --- a/plugin/src/Caelestia/cachingimagemanager.hpp +++ b/plugin/src/Caelestia/cachingimagemanager.hpp @@ -5,17 +5,17 @@ #include <QtQuick/QQuickItem> class CachingImageManager : public QObject { - Q_OBJECT; - QML_ELEMENT; + Q_OBJECT + QML_ELEMENT - Q_PROPERTY(QQuickItem* item READ item WRITE setItem NOTIFY itemChanged REQUIRED); - Q_PROPERTY(QUrl cacheDir READ cacheDir WRITE setCacheDir NOTIFY cacheDirChanged REQUIRED); + Q_PROPERTY(QQuickItem* item READ item WRITE setItem NOTIFY itemChanged REQUIRED) + Q_PROPERTY(QUrl cacheDir READ cacheDir WRITE setCacheDir NOTIFY cacheDirChanged REQUIRED) - Q_PROPERTY(QString path READ path WRITE setPath NOTIFY pathChanged); - Q_PROPERTY(QUrl cachePath READ cachePath NOTIFY cachePathChanged); + Q_PROPERTY(QString path READ path WRITE setPath NOTIFY pathChanged) + Q_PROPERTY(QUrl cachePath READ cachePath NOTIFY cachePathChanged) public: - explicit CachingImageManager(QObject* parent = nullptr): QObject(parent) {}; + explicit CachingImageManager(QObject* parent = nullptr): QObject(parent) {} [[nodiscard]] QQuickItem* item() const; void setItem(QQuickItem* item); diff --git a/plugin/src/Caelestia/cutils.cpp b/plugin/src/Caelestia/cutils.cpp index c849a4b..6ba4807 100644 --- a/plugin/src/Caelestia/cutils.cpp +++ b/plugin/src/Caelestia/cutils.cpp @@ -45,12 +45,12 @@ void CUtils::saveItem(QQuickItem* target, const QUrl& path, const QRect& rect, Q } auto scaledRect = rect; - if (rect.isValid()) { - qreal scale = target->window()->devicePixelRatio(); - scaledRect = QRect(rect.left() * scale, rect.top() * scale, rect.width() * scale, rect.height() * scale); + const qreal scale = target->window()->devicePixelRatio(); + if (rect.isValid() && scale != 1.0) { + scaledRect = QRectF(rect.left() * scale, rect.top() * scale, rect.width() * scale, rect.height() * scale).toRect(); } - QSharedPointer<QQuickItemGrabResult> grabResult = target->grabToImage(); + const QSharedPointer<const QQuickItemGrabResult> grabResult = target->grabToImage(); QObject::connect(grabResult.data(), &QQuickItemGrabResult::ready, this, [grabResult, scaledRect, path, onSaved, onFailed, this]() { @@ -63,7 +63,7 @@ void CUtils::saveItem(QQuickItem* target, const QUrl& path, const QRect& rect, Q const QString file = path.toLocalFile(); const QString parent = QFileInfo(file).absolutePath(); - bool success = QDir().mkpath(parent) && image.save(file); + const bool success = QDir().mkpath(parent) && image.save(file); QMetaObject::invokeMethod(this, [file, success, path, onSaved, onFailed, this]() { if (success) { @@ -118,14 +118,14 @@ void CUtils::getDominantColour(QQuickItem* item, int rescaleSize, QJSValue callb return; } - QSharedPointer<QQuickItemGrabResult> grabResult = item->grabToImage(); + const QSharedPointer<const QQuickItemGrabResult> grabResult = item->grabToImage(); QObject::connect(grabResult.data(), &QQuickItemGrabResult::ready, this, [grabResult, rescaleSize, callback, this]() { - QImage image = grabResult->image(); + const QImage image = grabResult->image(); QThreadPool::globalInstance()->start([grabResult, image, rescaleSize, callback, this]() { - QColor color = this->findDominantColour(image, rescaleSize); + const QColor color = this->findDominantColour(image, rescaleSize); if (callback.isCallable()) { QMetaObject::invokeMethod(this, [color, callback, this]() { @@ -148,14 +148,14 @@ void CUtils::getDominantColour(const QString& path, int rescaleSize, QJSValue ca } QThreadPool::globalInstance()->start([path, rescaleSize, callback, this]() { - QImage image(path); + const QImage image(path); if (image.isNull()) { qWarning() << "CUtils::getDominantColour: failed to load image" << path; return; } - QColor color = this->findDominantColour(image, rescaleSize); + const QColor color = this->findDominantColour(image, rescaleSize); if (callback.isCallable()) { QMetaObject::invokeMethod(this, [color, callback, this]() { @@ -183,9 +183,9 @@ QColor CUtils::findDominantColour(const QImage& image, int rescaleSize) const { std::unordered_map<uint32_t, int> colours; const uchar* data = img.bits(); - int width = img.width(); - int height = img.height(); - int bytesPerLine = img.bytesPerLine(); + const int width = img.width(); + const int height = img.height(); + const qsizetype bytesPerLine = img.bytesPerLine(); for (int y = 0; y < height; ++y) { const uchar* line = data + y * bytesPerLine; @@ -196,9 +196,9 @@ QColor CUtils::findDominantColour(const QImage& image, int rescaleSize) const { continue; } - uchar r = pixel[0] & 0xF8; - uchar g = pixel[1] & 0xF8; - uchar b = pixel[2] & 0xF8; + uint32_t r = static_cast<uint32_t>(pixel[0] & 0xF8); + uint32_t g = static_cast<uint32_t>(pixel[1] & 0xF8); + uint32_t b = static_cast<uint32_t>(pixel[2] & 0xF8); uint32_t colour = (r << 16) | (g << 8) | b; ++colours[colour]; @@ -214,7 +214,7 @@ QColor CUtils::findDominantColour(const QImage& image, int rescaleSize) const { } } - return QColor((0xFF << 24) | dominantColour); + return QColor((0xFFu << 24) | dominantColour); } void CUtils::getAverageLuminance(QQuickItem* item, QJSValue callback) { @@ -232,17 +232,17 @@ void CUtils::getAverageLuminance(QQuickItem* item, int rescaleSize, QJSValue cal return; } - QSharedPointer<QQuickItemGrabResult> grabResult = item->grabToImage(); + const QSharedPointer<const QQuickItemGrabResult> grabResult = item->grabToImage(); QObject::connect(grabResult.data(), &QQuickItemGrabResult::ready, this, [grabResult, rescaleSize, callback, this]() { - QImage image = grabResult->image(); + const QImage image = grabResult->image(); QThreadPool::globalInstance()->start([grabResult, image, rescaleSize, callback, this]() { - qreal luminance = this->findAverageLuminance(image, rescaleSize); + const qreal luminance = this->findAverageLuminance(image, rescaleSize); if (callback.isCallable()) { - QMetaObject::invokeMethod(this, [luminance, callback, this]() { + QMetaObject::invokeMethod(this, [luminance, callback]() { callback.call({ QJSValue(luminance) }); }, Qt::QueuedConnection); } @@ -262,17 +262,17 @@ void CUtils::getAverageLuminance(const QString& path, int rescaleSize, QJSValue } QThreadPool::globalInstance()->start([path, rescaleSize, callback, this]() { - QImage image(path); + const QImage image(path); if (image.isNull()) { qWarning() << "CUtils::getAverageLuminance: failed to load image" << path; return; } - qreal luminance = this->findAverageLuminance(image, rescaleSize); + const qreal luminance = this->findAverageLuminance(image, rescaleSize); if (callback.isCallable()) { - QMetaObject::invokeMethod(this, [luminance, callback, this]() { + QMetaObject::invokeMethod(this, [luminance, callback]() { callback.call({ QJSValue(luminance) }); }, Qt::QueuedConnection); } @@ -296,9 +296,9 @@ qreal CUtils::findAverageLuminance(const QImage& image, int rescaleSize) const { } const uchar* data = img.bits(); - int width = img.width(); - int height = img.height(); - int bytesPerLine = img.bytesPerLine(); + const int width = img.width(); + const int height = img.height(); + const qsizetype bytesPerLine = img.bytesPerLine(); qreal totalLuminance = 0.0; int count = 0; @@ -312,9 +312,9 @@ qreal CUtils::findAverageLuminance(const QImage& image, int rescaleSize) const { continue; } - qreal r = pixel[0] / 255.0; - qreal g = pixel[1] / 255.0; - qreal b = pixel[2] / 255.0; + const qreal r = pixel[0] / 255.0; + const qreal g = pixel[1] / 255.0; + const qreal b = pixel[2] / 255.0; totalLuminance += std::sqrt(0.299 * r * r + 0.587 * g * g + 0.114 * b * b); ++count; diff --git a/plugin/src/Caelestia/cutils.hpp b/plugin/src/Caelestia/cutils.hpp index 048a2ff..ef758f2 100644 --- a/plugin/src/Caelestia/cutils.hpp +++ b/plugin/src/Caelestia/cutils.hpp @@ -5,9 +5,9 @@ #include <QtQuick/QQuickItem> class CUtils : public QObject { - Q_OBJECT; - QML_ELEMENT; - QML_SINGLETON; + Q_OBJECT + QML_ELEMENT + QML_SINGLETON public: Q_INVOKABLE void saveItem(QQuickItem* target, const QUrl& path); diff --git a/plugin/src/Caelestia/filesystemmodel.cpp b/plugin/src/Caelestia/filesystemmodel.cpp index 3fb20d9..a1b35d3 100644 --- a/plugin/src/Caelestia/filesystemmodel.cpp +++ b/plugin/src/Caelestia/filesystemmodel.cpp @@ -10,7 +10,7 @@ int FileSystemModel::rowCount(const QModelIndex& parent) const { Q_UNUSED(parent); - return m_entries.size(); + return static_cast<int>(m_entries.size()); } QVariant FileSystemModel::data(const QModelIndex& index, int role) const { diff --git a/plugin/src/Caelestia/filesystemmodel.hpp b/plugin/src/Caelestia/filesystemmodel.hpp index 42027e7..9667beb 100644 --- a/plugin/src/Caelestia/filesystemmodel.hpp +++ b/plugin/src/Caelestia/filesystemmodel.hpp @@ -10,16 +10,16 @@ class FileSystemEntry : public QObject { Q_OBJECT - QML_ELEMENT; - QML_UNCREATABLE("FileSystemEntry instances can only be retrieved from a FileSystemModel"); + QML_ELEMENT + QML_UNCREATABLE("FileSystemEntry instances can only be retrieved from a FileSystemModel") - Q_PROPERTY(QString path READ path CONSTANT); - Q_PROPERTY(QString relativePath READ relativePath CONSTANT); - Q_PROPERTY(QString name READ name CONSTANT); - Q_PROPERTY(QString parentDir READ parentDir CONSTANT); - Q_PROPERTY(qint64 size READ size CONSTANT); - Q_PROPERTY(bool isDir READ isDir CONSTANT); - Q_PROPERTY(bool isImage READ isImage CONSTANT); + Q_PROPERTY(QString path READ path CONSTANT) + Q_PROPERTY(QString relativePath READ relativePath CONSTANT) + Q_PROPERTY(QString name READ name CONSTANT) + Q_PROPERTY(QString parentDir READ parentDir CONSTANT) + Q_PROPERTY(qint64 size READ size CONSTANT) + Q_PROPERTY(bool isDir READ isDir CONSTANT) + Q_PROPERTY(bool isImage READ isImage CONSTANT) public: explicit FileSystemEntry(const QString& path, const QString& relativePath, QObject* parent = nullptr) @@ -53,14 +53,14 @@ private: }; class FileSystemModel : public QAbstractListModel { - Q_OBJECT; - QML_ELEMENT; + Q_OBJECT + QML_ELEMENT - Q_PROPERTY(QString path READ path WRITE setPath NOTIFY pathChanged); - Q_PROPERTY(bool recursive READ recursive WRITE setRecursive NOTIFY recursiveChanged); - Q_PROPERTY(Filter filter READ filter WRITE setFilter NOTIFY filterChanged); + Q_PROPERTY(QString path READ path WRITE setPath NOTIFY pathChanged) + Q_PROPERTY(bool recursive READ recursive WRITE setRecursive NOTIFY recursiveChanged) + Q_PROPERTY(Filter filter READ filter WRITE setFilter NOTIFY filterChanged) - Q_PROPERTY(QList<FileSystemEntry*> entries READ entries NOTIFY entriesChanged); + Q_PROPERTY(QList<FileSystemEntry*> entries READ entries NOTIFY entriesChanged) public: enum Roles { |