plugin: fix warnings + const stuff

This commit is contained in:
2 * r + 2 * t 2025-09-01 15:31:27 +10:00
parent 7e5e19b6a5
commit d76c799dd2
6 changed files with 62 additions and 62 deletions

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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