From e98c0f42cc2fa22936ec962d38001cb61d367abb Mon Sep 17 00:00:00 2001 From: Uyanide Date: Thu, 15 Jan 2026 00:30:51 +0100 Subject: [PATCH] style: format --- .clang-format | 61 +++++++++++++++++++++++++++++++++++++++ src/config.cpp | 58 ++++++++++++++++++------------------- src/loading_indicator.cpp | 2 +- src/loading_indicator.h | 4 +-- src/logger.cpp | 2 +- src/logger.h | 2 +- src/utils.h | 2 +- 7 files changed, 96 insertions(+), 35 deletions(-) create mode 100644 .clang-format diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..fa6d735 --- /dev/null +++ b/.clang-format @@ -0,0 +1,61 @@ +BasedOnStyle: Google + +AccessModifierOffset: -2 + +AlignConsecutiveAssignments: true + +AllowAllArgumentsOnNextLine: false + +AllowAllParametersOfDeclarationOnNextLine: false + +AllowShortBlocksOnASingleLine: Empty + +AllowShortCaseLabelsOnASingleLine: true + +AllowShortFunctionsOnASingleLine: Inline + +AllowShortLambdasOnASingleLine: All + +BinPackArguments: false + +BinPackParameters: false + +ColumnLimit: 0 + +CompactNamespaces: false + +ContinuationIndentWidth: 4 + +Cpp11BracedListStyle: true + +EmptyLineBeforeAccessModifier: LogicalBlock + +FixNamespaceComments: true + +IncludeBlocks: Regroup +SortIncludes: true +IncludeCategories: + - Regex: '^' + Priority: 2 + - Regex: '^<.*\.h>' + Priority: 1 + - Regex: '^<.*' + Priority: 2 + - Regex: '.*' + Priority: 3 + +IndentWidth: 4 + +KeepEmptyLinesAtTheStartOfBlocks: true + +InsertNewlineAtEOF: true + +MaxEmptyLinesToKeep: 1 + +TabWidth: 4 + +UseTab: Never + +SeparateDefinitionBlocks: Always + +QualifierAlignment: Left diff --git a/src/config.cpp b/src/config.cpp index 9949628..05acbe5 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -17,11 +17,11 @@ #include "logger.h" using namespace GeneralLogger; -static QString expandPath(const QString &path); +static QString expandPath(const QString& path); const QString Config::s_DefaultConfigFileName = "config.json"; -Config::Config(const QString &configDir, const QStringList &searchDirs, QObject *parent) +Config::Config(const QString& configDir, const QStringList& searchDirs, QObject* parent) : QObject(parent), m_configDir(configDir) { info(QString("Loading configuration from: %1").arg(configDir)); _loadConfig(configDir + QDir::separator() + s_DefaultConfigFileName); @@ -36,7 +36,7 @@ Config::Config(const QString &configDir, const QStringList &searchDirs, QObject Config::~Config() { } -void Config::_loadConfig(const QString &configPath) { +void Config::_loadConfig(const QString& configPath) { QFile configFile(configPath); if (!configFile.open(QIODevice::ReadOnly)) { error(QString("Failed to open config file: %1").arg(configPath)); @@ -56,12 +56,12 @@ void Config::_loadConfig(const QString &configPath) { struct ConfigMapping { QString path; QString key; - std::function parser; + std::function parser; }; - static const auto parseJsonArray = [](const QJsonValue &val, QStringList &list) { + static const auto parseJsonArray = [](const QJsonValue& val, QStringList& list) { if (val.isArray()) { - for (const auto &item : val.toArray()) { + for (const auto& item : val.toArray()) { if (item.isString()) { list.append(::expandPath(item.toString())); } @@ -71,58 +71,58 @@ void Config::_loadConfig(const QString &configPath) { std::vector mappings = { - {"wallpaper.paths", "paths", [this](const QJsonValue &val) { + {"wallpaper.paths", "paths", [this](const QJsonValue& val) { parseJsonArray(val, m_wallpaperConfig.paths); }}, - {"wallpaper.dirs", "dirs", [this](const QJsonValue &val) { + {"wallpaper.dirs", "dirs", [this](const QJsonValue& val) { parseJsonArray(val, m_wallpaperConfig.dirs); }}, - {"wallpaper.excludes", "excludes", [this](const QJsonValue &val) { + {"wallpaper.excludes", "excludes", [this](const QJsonValue& val) { parseJsonArray(val, m_wallpaperConfig.excludes); }}, - {"action.confirm", "confirm", [this](const QJsonValue &val) { + {"action.confirm", "confirm", [this](const QJsonValue& val) { if (val.isString()) { m_actionConfig.confirm = ::expandPath(val.toString()); info(QString("Action confirm: %1").arg(m_actionConfig.confirm), GeneralLogger::STEP); } }}, - {"style.aspect_ratio", "aspect_ratio", [this](const QJsonValue &val) { + {"style.aspect_ratio", "aspect_ratio", [this](const QJsonValue& val) { if (val.isDouble() && val.toDouble() > 0) { m_styleConfig.aspectRatio = val.toDouble(); info(QString("Aspect ratio: %1").arg(m_styleConfig.aspectRatio), GeneralLogger::STEP); } }}, - {"style.image_width", "image_width", [this](const QJsonValue &val) { + {"style.image_width", "image_width", [this](const QJsonValue& val) { if (val.isDouble() && val.toDouble() > 0) { m_styleConfig.imageWidth = val.toInt(); info(QString("Image width: %1").arg(m_styleConfig.imageWidth), GeneralLogger::STEP); } }}, - {"style.image_focus_width", "image_focus_width", [this](const QJsonValue &val) { + {"style.image_focus_width", "image_focus_width", [this](const QJsonValue& val) { if (val.isDouble() && val.toDouble() > 0) { m_styleConfig.imageFocusWidth = val.toInt(); info(QString("Image focus width: %1").arg(m_styleConfig.imageFocusWidth), GeneralLogger::STEP); } }}, - {"style.window_width", "window_width", [this](const QJsonValue &val) { + {"style.window_width", "window_width", [this](const QJsonValue& val) { if (val.isDouble() && val.toDouble() > 0) { m_styleConfig.windowWidth = val.toInt(); info(QString("Window width: %1").arg(m_styleConfig.windowWidth), GeneralLogger::STEP); } }}, - {"style.window_height", "window_height", [this](const QJsonValue &val) { + {"style.window_height", "window_height", [this](const QJsonValue& val) { if (val.isDouble() && val.toDouble() > 0) { m_styleConfig.windowHeight = val.toInt(); info(QString("Window height: %1").arg(m_styleConfig.windowHeight), GeneralLogger::STEP); } }}, - {"style.no_loading_screen", "no_loading_screen", [this](const QJsonValue &val) { + {"style.no_loading_screen", "no_loading_screen", [this](const QJsonValue& val) { if (val.isBool()) { m_styleConfig.noLoadingScreen = val.toBool(); info(QString("No loading screen: %1").arg(m_styleConfig.noLoadingScreen), GeneralLogger::STEP); } }}, - {"sort.type", "type", [this](const QJsonValue &val) { + {"sort.type", "type", [this](const QJsonValue& val) { if (val.isString()) { QString type = val.toString().toLower(); if (type == "none") { @@ -139,7 +139,7 @@ void Config::_loadConfig(const QString &configPath) { } info(QString("Sort type: %1").arg(static_cast(m_sortConfig.type)), GeneralLogger::STEP); }}, - {"sort.reverse", "reverse", [this](const QJsonValue &val) { + {"sort.reverse", "reverse", [this](const QJsonValue& val) { if (val.isBool()) { m_sortConfig.reverse = val.toBool(); info(QString("Sort reverse: %1").arg(m_sortConfig.reverse), GeneralLogger::STEP); @@ -148,7 +148,7 @@ void Config::_loadConfig(const QString &configPath) { }; // 统一解析 - for (const auto &mapping : mappings) { + for (const auto& mapping : mappings) { ([&mapping, &jsonObj]() { auto pathParts = mapping.path.split('.'); @@ -165,7 +165,7 @@ void Config::_loadConfig(const QString &configPath) { } // 获取目标值 - const QString &finalKey = pathParts.last(); + const QString& finalKey = pathParts.last(); if (currentObj.contains(finalKey)) { mapping.parser(currentObj[finalKey]); } else { @@ -181,16 +181,16 @@ void Config::_loadWallpapers() { QSet paths; info(QString("Loading wallpapers from %1 specified paths").arg(m_wallpaperConfig.paths.size()), LogIndent::STEP); - for (const QString &path : m_wallpaperConfig.paths) { + for (const QString& path : m_wallpaperConfig.paths) { paths.insert(path); } info(QString("Loading wallpapers from %1 specified directories").arg(m_wallpaperConfig.dirs.size()), LogIndent::STEP); - for (const QString &dirPath : m_wallpaperConfig.dirs) { + for (const QString& dirPath : m_wallpaperConfig.dirs) { QDir dir(dirPath); if (dir.exists()) { QStringList files = dir.entryList(QDir::Files | QDir::NoDotAndDotDot); - for (const QString &file : files) { + for (const QString& file : files) { QString filePath = dir.filePath(file); paths.insert(filePath); } @@ -200,12 +200,12 @@ void Config::_loadWallpapers() { } info(QString("Excluding %1 specified paths").arg(m_wallpaperConfig.excludes.size()), LogIndent::STEP); - for (const QString &exclude : m_wallpaperConfig.excludes) { + for (const QString& exclude : m_wallpaperConfig.excludes) { paths.remove(exclude); } m_wallpapers.reserve(paths.size()); - for (const QString &path : paths) { + for (const QString& path : paths) { if (isValidImageFile(path)) { m_wallpapers.append(path); } @@ -214,7 +214,7 @@ void Config::_loadWallpapers() { info(QString("Found %1 wallpapers").arg(paths.size())); } -bool Config::isValidImageFile(const QString &filePath) { +bool Config::isValidImageFile(const QString& filePath) { static const QStringList validExtensions = { ".jpg", ".jpeg", @@ -240,7 +240,7 @@ bool Config::isValidImageFile(const QString &filePath) { return false; } // check if valid extension - for (const QString &ext : validExtensions) { + for (const QString& ext : validExtensions) { if (filePath.endsWith(ext, Qt::CaseInsensitive)) { return true; } @@ -249,7 +249,7 @@ bool Config::isValidImageFile(const QString &filePath) { return false; } -static QString expandPath(const QString &path) { +static QString expandPath(const QString& path) { QString expandedPath = path; if (expandedPath.startsWith("~/")) { @@ -272,4 +272,4 @@ static QString expandPath(const QString &path) { } return QDir::cleanPath(expandedPath); -} \ No newline at end of file +} diff --git a/src/loading_indicator.cpp b/src/loading_indicator.cpp index 556964f..fe2bae4 100644 --- a/src/loading_indicator.cpp +++ b/src/loading_indicator.cpp @@ -6,7 +6,7 @@ */ #include "loading_indicator.h" -LoadingIndicator::LoadingIndicator(QWidget *parent) : QWidget(parent), +LoadingIndicator::LoadingIndicator(QWidget* parent) : QWidget(parent), ui(new Ui::LoadingIndicator) { ui->setupUi(this); } diff --git a/src/loading_indicator.h b/src/loading_indicator.h index 0177f22..1a7addb 100644 --- a/src/loading_indicator.h +++ b/src/loading_indicator.h @@ -19,7 +19,7 @@ class LoadingIndicator : public QWidget { Q_OBJECT public: - explicit LoadingIndicator(QWidget *parent = nullptr); + explicit LoadingIndicator(QWidget* parent = nullptr); ~LoadingIndicator(); void setMaximum(int max) { ui->progressBar->setMaximum(max); } @@ -27,7 +27,7 @@ class LoadingIndicator : public QWidget { void setValue(int value) { ui->progressBar->setValue(value); } private: - Ui::LoadingIndicator *ui; + Ui::LoadingIndicator* ui; }; #endif // LOADING_INDICATOR_H diff --git a/src/logger.cpp b/src/logger.cpp index 66e7d93..a92170f 100644 --- a/src/logger.cpp +++ b/src/logger.cpp @@ -109,4 +109,4 @@ void GeneralLogger::warn(const QString& msg, const GeneralLogger::LogIndent inde void GeneralLogger::error(const QString& msg, const GeneralLogger::LogIndent indent) { QString indentedMsg = QString(" ").repeated(indent) + msg; qCCritical(logMain).noquote() << indentedMsg; -} \ No newline at end of file +} diff --git a/src/logger.h b/src/logger.h index de422cd..98c69a2 100644 --- a/src/logger.h +++ b/src/logger.h @@ -40,4 +40,4 @@ class Logger { static GeneralLogger::LogIndent maxIndent(); }; -#endif // GENERAL_LOGGER_H \ No newline at end of file +#endif // GENERAL_LOGGER_H diff --git a/src/utils.h b/src/utils.h index 3e7757a..31cc92e 100644 --- a/src/utils.h +++ b/src/utils.h @@ -26,4 +26,4 @@ class Defer { } }; -#endif // UTILS_H \ No newline at end of file +#endif // UTILS_H