Remove namespace, fold I/O into structs.

Took 33 seconds
This commit is contained in:
Lukas Brübach 2026-05-17 09:27:24 +02:00
parent a39e133351
commit 64a5b36e88
4 changed files with 16 additions and 38 deletions

View file

@ -257,9 +257,8 @@ void PaletteEditorDialog::onSave()
PaletteConfig cfg = paletteGrid->currentPaletteConfig();
if (!ThemeManager::savePaletteConfig(themeDirPath, loadedScheme, cfg)) {
QMessageBox::warning(
this, tr("Save failed"),
tr("Could not write %1 to:\n%2").arg(PaletteConfig::fileName(loadedScheme), themeDirPath));
QMessageBox::warning(this, tr("Save failed"),
tr("Could not write %1 to:\n%2").arg(PaletteConfig::fileName(loadedScheme), themeDirPath));
return;
}

View file

@ -127,9 +127,7 @@ QString PaletteConfig::toToml() const
continue;
}
out += QString("%1 = %2\n")
.arg(QString(roleName), -20)
.arg(it.value().name(QColor::HexArgb));
out += QString("%1 = %2\n").arg(QString(roleName), -20).arg(it.value().name(QColor::HexArgb));
}
out += "\n";
@ -140,9 +138,7 @@ QString PaletteConfig::toToml() const
QString PaletteConfig::fileName(const QString &colorScheme)
{
return colorScheme.compare("Dark", Qt::CaseInsensitive) == 0
? "palette-dark.toml"
: "palette-light.toml";
return colorScheme.compare("Dark", Qt::CaseInsensitive) == 0 ? "palette-dark.toml" : "palette-light.toml";
}
PaletteConfig PaletteConfig::fromFile(const QString &filePath)
@ -175,9 +171,7 @@ PaletteConfig PaletteConfig::fromFile(const QString &filePath)
if (currentSection.startsWith("Palette", Qt::CaseInsensitive)) {
int dot = currentSection.indexOf('.');
QString groupStr = (dot >= 0)
? currentSection.mid(dot + 1)
: "Active";
QString groupStr = (dot >= 0) ? currentSection.mid(dot + 1) : "Active";
if (groupStr.compare("Disabled", Qt::CaseInsensitive) == 0) {
currentGroup = QPalette::Disabled;
@ -232,19 +226,16 @@ PaletteConfig PaletteConfig::fromFile(const QString &filePath)
return cfg;
}
PaletteConfig PaletteConfig::fromScheme(const QString &themeDirPath,
const QString &colorScheme)
PaletteConfig PaletteConfig::fromScheme(const QString &themeDirPath, const QString &colorScheme)
{
if (themeDirPath.isEmpty()) {
return {};
}
return fromFile(
QDir(themeDirPath).absoluteFilePath(fileName(colorScheme)));
return fromFile(QDir(themeDirPath).absoluteFilePath(fileName(colorScheme)));
}
PaletteConfig PaletteConfig::fromDefault(const QString &themeDirPath,
const QString &colorScheme)
PaletteConfig PaletteConfig::fromDefault(const QString &themeDirPath, const QString &colorScheme)
{
if (themeDirPath.isEmpty()) {
return {};
@ -252,21 +243,13 @@ PaletteConfig PaletteConfig::fromDefault(const QString &themeDirPath,
QDir dir(themeDirPath);
bool wantDark =
colorScheme.compare("Dark", Qt::CaseInsensitive) == 0;
bool wantDark = colorScheme.compare("Dark", Qt::CaseInsensitive) == 0;
PaletteConfig cfg = fromFile(
dir.absoluteFilePath(
wantDark
? "palette-default-dark.toml"
: "palette-default-light.toml"));
PaletteConfig cfg =
fromFile(dir.absoluteFilePath(wantDark ? "palette-default-dark.toml" : "palette-default-light.toml"));
if (!cfg.hasPalette()) {
cfg = fromFile(
dir.absoluteFilePath(
wantDark
? "palette-default-light.toml"
: "palette-default-dark.toml"));
cfg = fromFile(dir.absoluteFilePath(wantDark ? "palette-default-light.toml" : "palette-default-dark.toml"));
}
return cfg;
@ -275,9 +258,7 @@ PaletteConfig PaletteConfig::fromDefault(const QString &themeDirPath,
QPalette PaletteConfig::apply(QPalette base) const
{
for (auto git = colors.cbegin(); git != colors.cend(); ++git) {
for (auto rit = git.value().cbegin();
rit != git.value().cend();
++rit) {
for (auto rit = git.value().cbegin(); rit != git.value().cend(); ++rit) {
base.setColor(git.key(), rit.key(), rit.value());
}
}

View file

@ -28,10 +28,8 @@ struct PaletteConfig
static QString fileName(const QString &colorScheme);
static PaletteConfig fromFile(const QString &filePath);
static PaletteConfig fromScheme(const QString &themeDirPath,
const QString &colorScheme);
static PaletteConfig fromDefault(const QString &themeDirPath,
const QString &colorScheme);
static PaletteConfig fromScheme(const QString &themeDirPath, const QString &colorScheme);
static PaletteConfig fromDefault(const QString &themeDirPath, const QString &colorScheme);
QPalette apply(QPalette base) const;
};

View file

@ -288,7 +288,7 @@ void ThemeManager::applyStyleAndPalette(const QString &themeName,
// Overlay custom palette colours
if (palCfg.hasPalette()) {
base = palCfg.apply( base);
base = palCfg.apply(base);
}
// Palette BEFORE style — setStyle() triggers a synchronous repolish of all