plugin: format + refactor
This commit is contained in:
parent
44c0e1b116
commit
b87d5bf20e
6 changed files with 87 additions and 49 deletions
|
|
@ -19,4 +19,7 @@ EmptyLineAfterAccessModifier: Never
|
||||||
EmptyLineBeforeAccessModifier: Always
|
EmptyLineBeforeAccessModifier: Always
|
||||||
IndentAccessModifiers: false
|
IndentAccessModifiers: false
|
||||||
IndentCaseLabels: false
|
IndentCaseLabels: false
|
||||||
|
InsertNewlineAtEOF: true
|
||||||
|
SeparateDefinitionBlocks: Always
|
||||||
|
WrapNamespaceBodyWithEmptyLines: Always
|
||||||
...
|
...
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@ qt_standard_project_setup(REQUIRES 6.9)
|
||||||
|
|
||||||
qt_add_qml_module(caelestia
|
qt_add_qml_module(caelestia
|
||||||
URI Caelestia
|
URI Caelestia
|
||||||
|
VERSION ${VERSION}
|
||||||
SOURCES
|
SOURCES
|
||||||
cutils.hpp cutils.cpp
|
cutils.hpp cutils.cpp
|
||||||
cachingimagemanager.hpp cachingimagemanager.cpp
|
cachingimagemanager.hpp cachingimagemanager.cpp
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,70 @@
|
||||||
|
|
||||||
namespace caelestia {
|
namespace caelestia {
|
||||||
|
|
||||||
|
FileSystemEntry::FileSystemEntry(const QString& path, const QString& relativePath, QObject* parent)
|
||||||
|
: QObject(parent)
|
||||||
|
, m_fileInfo(QFileInfo(path))
|
||||||
|
, m_path(path)
|
||||||
|
, m_relativePath(relativePath)
|
||||||
|
, m_isImageInitialised(false)
|
||||||
|
, m_mimeTypeInitialised(false) {}
|
||||||
|
|
||||||
|
QString FileSystemEntry::path() const {
|
||||||
|
return m_path;
|
||||||
|
};
|
||||||
|
|
||||||
|
QString FileSystemEntry::relativePath() const {
|
||||||
|
return m_relativePath;
|
||||||
|
};
|
||||||
|
|
||||||
|
QString FileSystemEntry::name() const {
|
||||||
|
return m_fileInfo.fileName();
|
||||||
|
};
|
||||||
|
|
||||||
|
QString FileSystemEntry::parentDir() const {
|
||||||
|
return m_fileInfo.absolutePath();
|
||||||
|
};
|
||||||
|
|
||||||
|
QString FileSystemEntry::suffix() const {
|
||||||
|
return m_fileInfo.completeSuffix();
|
||||||
|
};
|
||||||
|
|
||||||
|
qint64 FileSystemEntry::size() const {
|
||||||
|
return m_fileInfo.size();
|
||||||
|
};
|
||||||
|
|
||||||
|
bool FileSystemEntry::isDir() const {
|
||||||
|
return m_fileInfo.isDir();
|
||||||
|
};
|
||||||
|
|
||||||
|
bool FileSystemEntry::isImage() const {
|
||||||
|
if (!m_isImageInitialised) {
|
||||||
|
QImageReader reader(m_path);
|
||||||
|
m_isImage = reader.canRead();
|
||||||
|
m_isImageInitialised = true;
|
||||||
|
}
|
||||||
|
return m_isImage;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString FileSystemEntry::mimeType() const {
|
||||||
|
if (!m_mimeTypeInitialised) {
|
||||||
|
const QMimeDatabase db;
|
||||||
|
m_mimeType = db.mimeTypeForFile(m_path).name();
|
||||||
|
m_mimeTypeInitialised = true;
|
||||||
|
}
|
||||||
|
return m_mimeType;
|
||||||
|
}
|
||||||
|
|
||||||
|
FileSystemModel::FileSystemModel(QObject* parent)
|
||||||
|
: QAbstractListModel(parent)
|
||||||
|
, m_recursive(false)
|
||||||
|
, m_watchChanges(true)
|
||||||
|
, m_showHidden(false)
|
||||||
|
, m_filter(NoFilter) {
|
||||||
|
connect(&m_watcher, &QFileSystemWatcher::directoryChanged, this, &FileSystemModel::watchDirIfRecursive);
|
||||||
|
connect(&m_watcher, &QFileSystemWatcher::directoryChanged, this, &FileSystemModel::updateEntriesForDir);
|
||||||
|
}
|
||||||
|
|
||||||
int FileSystemModel::rowCount(const QModelIndex& parent) const {
|
int FileSystemModel::rowCount(const QModelIndex& parent) const {
|
||||||
if (parent != QModelIndex()) {
|
if (parent != QModelIndex()) {
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
||||||
|
|
@ -27,40 +27,17 @@ class FileSystemEntry : public QObject {
|
||||||
Q_PROPERTY(QString mimeType READ mimeType CONSTANT)
|
Q_PROPERTY(QString mimeType READ mimeType CONSTANT)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit FileSystemEntry(const QString& path, const QString& relativePath, QObject* parent = nullptr)
|
explicit FileSystemEntry(const QString& path, const QString& relativePath, QObject* parent = nullptr);
|
||||||
: QObject(parent)
|
|
||||||
, m_fileInfo(QFileInfo(path))
|
|
||||||
, m_path(path)
|
|
||||||
, m_relativePath(relativePath)
|
|
||||||
, m_isImageInitialised(false)
|
|
||||||
, m_mimeTypeInitialised(false) {}
|
|
||||||
|
|
||||||
[[nodiscard]] QString path() const { return m_path; };
|
[[nodiscard]] QString path() const;
|
||||||
[[nodiscard]] QString relativePath() const { return m_relativePath; };
|
[[nodiscard]] QString relativePath() const;
|
||||||
|
[[nodiscard]] QString name() const;
|
||||||
[[nodiscard]] QString name() const { return m_fileInfo.fileName(); };
|
[[nodiscard]] QString parentDir() const;
|
||||||
[[nodiscard]] QString parentDir() const { return m_fileInfo.absolutePath(); };
|
[[nodiscard]] QString suffix() const;
|
||||||
[[nodiscard]] QString suffix() const { return m_fileInfo.completeSuffix(); };
|
[[nodiscard]] qint64 size() const;
|
||||||
[[nodiscard]] qint64 size() const { return m_fileInfo.size(); };
|
[[nodiscard]] bool isDir() const;
|
||||||
[[nodiscard]] bool isDir() const { return m_fileInfo.isDir(); };
|
[[nodiscard]] bool isImage() const;
|
||||||
|
[[nodiscard]] QString mimeType() const;
|
||||||
[[nodiscard]] bool isImage() {
|
|
||||||
if (!m_isImageInitialised) {
|
|
||||||
QImageReader reader(m_path);
|
|
||||||
m_isImage = reader.canRead();
|
|
||||||
m_isImageInitialised = true;
|
|
||||||
}
|
|
||||||
return m_isImage;
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]] QString mimeType() {
|
|
||||||
if (!m_mimeTypeInitialised) {
|
|
||||||
const QMimeDatabase db;
|
|
||||||
m_mimeType = db.mimeTypeForFile(m_path).name();
|
|
||||||
m_mimeTypeInitialised = true;
|
|
||||||
}
|
|
||||||
return m_mimeType;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const QFileInfo m_fileInfo;
|
const QFileInfo m_fileInfo;
|
||||||
|
|
@ -68,11 +45,11 @@ private:
|
||||||
const QString m_path;
|
const QString m_path;
|
||||||
const QString m_relativePath;
|
const QString m_relativePath;
|
||||||
|
|
||||||
bool m_isImage;
|
mutable bool m_isImage;
|
||||||
bool m_isImageInitialised;
|
mutable bool m_isImageInitialised;
|
||||||
|
|
||||||
QString m_mimeType;
|
mutable QString m_mimeType;
|
||||||
bool m_mimeTypeInitialised;
|
mutable bool m_mimeTypeInitialised;
|
||||||
};
|
};
|
||||||
|
|
||||||
class FileSystemModel : public QAbstractListModel {
|
class FileSystemModel : public QAbstractListModel {
|
||||||
|
|
@ -96,15 +73,7 @@ public:
|
||||||
};
|
};
|
||||||
Q_ENUM(Filter)
|
Q_ENUM(Filter)
|
||||||
|
|
||||||
explicit FileSystemModel(QObject* parent = nullptr)
|
explicit FileSystemModel(QObject* parent = nullptr);
|
||||||
: QAbstractListModel(parent)
|
|
||||||
, m_recursive(false)
|
|
||||||
, m_watchChanges(true)
|
|
||||||
, m_showHidden(false)
|
|
||||||
, m_filter(NoFilter) {
|
|
||||||
connect(&m_watcher, &QFileSystemWatcher::directoryChanged, this, &FileSystemModel::watchDirIfRecursive);
|
|
||||||
connect(&m_watcher, &QFileSystemWatcher::directoryChanged, this, &FileSystemModel::updateEntriesForDir);
|
|
||||||
}
|
|
||||||
|
|
||||||
int rowCount(const QModelIndex& parent = QModelIndex()) const override;
|
int rowCount(const QModelIndex& parent = QModelIndex()) const override;
|
||||||
QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
|
QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ Service::Service(QObject* parent)
|
||||||
: QObject(parent)
|
: QObject(parent)
|
||||||
, m_refCount(0) {}
|
, m_refCount(0) {}
|
||||||
|
|
||||||
int Service::refCount() {
|
int Service::refCount() const {
|
||||||
QMutexLocker locker(&m_mutex);
|
QMutexLocker locker(&m_mutex);
|
||||||
return m_refCount;
|
return m_refCount;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
#include <qmutex.h>
|
#include <qmutex.h>
|
||||||
#include <qobject.h>
|
#include <qobject.h>
|
||||||
|
|
||||||
namespace caelestia {
|
namespace caelestia {
|
||||||
|
|
||||||
class Service : public QObject {
|
class Service : public QObject {
|
||||||
|
|
@ -12,7 +13,7 @@ class Service : public QObject {
|
||||||
public:
|
public:
|
||||||
explicit Service(QObject* parent = nullptr);
|
explicit Service(QObject* parent = nullptr);
|
||||||
|
|
||||||
[[nodiscard]] int refCount();
|
[[nodiscard]] int refCount() const;
|
||||||
|
|
||||||
void ref();
|
void ref();
|
||||||
void unref();
|
void unref();
|
||||||
|
|
@ -22,7 +23,7 @@ signals:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int m_refCount;
|
int m_refCount;
|
||||||
QMutex m_mutex;
|
mutable QMutex m_mutex;
|
||||||
|
|
||||||
virtual void start() = 0;
|
virtual void start() = 0;
|
||||||
virtual void stop() = 0;
|
virtual void stop() = 0;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue